2 * Based on the x86 implementation.
4 * Copyright (C) 2012 ARM Ltd.
5 * Author: Marc Zyngier <marc.zyngier@arm.com>
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.
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.
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/>.
20 #include <linux/perf_event.h>
21 #include <linux/kvm_host.h>
23 #include <asm/kvm_emulate.h>
25 static int kvm_is_in_guest(void)
27 return kvm_arm_get_running_vcpu() != NULL;
30 static int kvm_is_user_mode(void)
32 struct kvm_vcpu *vcpu;
34 vcpu = kvm_arm_get_running_vcpu();
37 return !vcpu_mode_priv(vcpu);
42 static unsigned long kvm_get_guest_ip(void)
44 struct kvm_vcpu *vcpu;
46 vcpu = kvm_arm_get_running_vcpu();
49 return *vcpu_pc(vcpu);
54 static struct perf_guest_info_callbacks kvm_guest_cbs = {
55 .is_in_guest = kvm_is_in_guest,
56 .is_user_mode = kvm_is_user_mode,
57 .get_guest_ip = kvm_get_guest_ip,
60 int kvm_perf_init(void)
62 return perf_register_guest_info_callbacks(&kvm_guest_cbs);
65 int kvm_perf_teardown(void)
67 return perf_unregister_guest_info_callbacks(&kvm_guest_cbs);