perf.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Based on the x86 implementation.
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Marc Zyngier <marc.zyngier@arm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/perf_event.h>
  20. #include <linux/kvm_host.h>
  21. #include <asm/kvm_emulate.h>
  22. static int kvm_is_in_guest(void)
  23. {
  24. return kvm_arm_get_running_vcpu() != NULL;
  25. }
  26. static int kvm_is_user_mode(void)
  27. {
  28. struct kvm_vcpu *vcpu;
  29. vcpu = kvm_arm_get_running_vcpu();
  30. if (vcpu)
  31. return !vcpu_mode_priv(vcpu);
  32. return 0;
  33. }
  34. static unsigned long kvm_get_guest_ip(void)
  35. {
  36. struct kvm_vcpu *vcpu;
  37. vcpu = kvm_arm_get_running_vcpu();
  38. if (vcpu)
  39. return *vcpu_pc(vcpu);
  40. return 0;
  41. }
  42. static struct perf_guest_info_callbacks kvm_guest_cbs = {
  43. .is_in_guest = kvm_is_in_guest,
  44. .is_user_mode = kvm_is_user_mode,
  45. .get_guest_ip = kvm_get_guest_ip,
  46. };
  47. int kvm_perf_init(void)
  48. {
  49. return perf_register_guest_info_callbacks(&kvm_guest_cbs);
  50. }
  51. int kvm_perf_teardown(void)
  52. {
  53. return perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
  54. }