aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMarc Zyngier <marc.zyngier@arm.com>2013-03-04 22:18:00 -0500
committerChristoffer Dall <cdall@cs.columbia.edu>2013-04-29 00:44:01 -0400
commit210552c1bfe83122a480673660d5ca9821c944ae (patch)
tree713137a46a8d462e107e56ecf767773f15d37903 /arch
parent5a2892ce72e010e3cb96b438d7cdddce0c88e0e6 (diff)
ARM: KVM: add support for minimal host vs guest profiling
In order to be able to correctly profile what is happening on the host, we need to be able to identify when we're running on the guest, and log these events differently. Perf offers a simple way to register callbacks into KVM. Mimic what x86 does and enjoy being able to profile your KVM host. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/kvm_host.h3
-rw-r--r--arch/arm/kvm/Makefile2
-rw-r--r--arch/arm/kvm/arm.c4
-rw-r--r--arch/arm/kvm/perf.c68
4 files changed, 76 insertions, 1 deletions
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 0c4e643d939e..78813b8fad32 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -207,4 +207,7 @@ static inline void __cpu_init_hyp_mode(unsigned long long pgd_ptr,
207 kvm_call_hyp((void *)pgd_low, pgd_high, hyp_stack_ptr, vector_ptr); 207 kvm_call_hyp((void *)pgd_low, pgd_high, hyp_stack_ptr, vector_ptr);
208} 208}
209 209
210int kvm_perf_init(void);
211int kvm_perf_teardown(void);
212
210#endif /* __ARM_KVM_HOST_H__ */ 213#endif /* __ARM_KVM_HOST_H__ */
diff --git a/arch/arm/kvm/Makefile b/arch/arm/kvm/Makefile
index 8dc5e76cb789..53c5ed83d16f 100644
--- a/arch/arm/kvm/Makefile
+++ b/arch/arm/kvm/Makefile
@@ -18,6 +18,6 @@ kvm-arm-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o)
18 18
19obj-y += kvm-arm.o init.o interrupts.o 19obj-y += kvm-arm.o init.o interrupts.o
20obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o 20obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o
21obj-y += coproc.o coproc_a15.o mmio.o psci.o 21obj-y += coproc.o coproc_a15.o mmio.o psci.o perf.o
22obj-$(CONFIG_KVM_ARM_VGIC) += vgic.o 22obj-$(CONFIG_KVM_ARM_VGIC) += vgic.o
23obj-$(CONFIG_KVM_ARM_TIMER) += arch_timer.o 23obj-$(CONFIG_KVM_ARM_TIMER) += arch_timer.o
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 1497e18a9e2a..7403f884a545 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -920,7 +920,10 @@ static int init_hyp_mode(void)
920 if (err) 920 if (err)
921 goto out_free_mappings; 921 goto out_free_mappings;
922 922
923 kvm_perf_init();
924
923 kvm_info("Hyp mode initialized successfully\n"); 925 kvm_info("Hyp mode initialized successfully\n");
926
924 return 0; 927 return 0;
925out_free_vfp: 928out_free_vfp:
926 free_percpu(kvm_host_vfp_state); 929 free_percpu(kvm_host_vfp_state);
@@ -964,6 +967,7 @@ out_err:
964/* NOP: Compiling as a module not supported */ 967/* NOP: Compiling as a module not supported */
965void kvm_arch_exit(void) 968void kvm_arch_exit(void)
966{ 969{
970 kvm_perf_teardown();
967} 971}
968 972
969static int arm_init(void) 973static int arm_init(void)
diff --git a/arch/arm/kvm/perf.c b/arch/arm/kvm/perf.c
new file mode 100644
index 000000000000..1a3849da0b4b
--- /dev/null
+++ b/arch/arm/kvm/perf.c
@@ -0,0 +1,68 @@
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
20#include <linux/perf_event.h>
21#include <linux/kvm_host.h>
22
23#include <asm/kvm_emulate.h>
24
25static int kvm_is_in_guest(void)
26{
27 return kvm_arm_get_running_vcpu() != NULL;
28}
29
30static int kvm_is_user_mode(void)
31{
32 struct kvm_vcpu *vcpu;
33
34 vcpu = kvm_arm_get_running_vcpu();
35
36 if (vcpu)
37 return !vcpu_mode_priv(vcpu);
38
39 return 0;
40}
41
42static unsigned long kvm_get_guest_ip(void)
43{
44 struct kvm_vcpu *vcpu;
45
46 vcpu = kvm_arm_get_running_vcpu();
47
48 if (vcpu)
49 return *vcpu_pc(vcpu);
50
51 return 0;
52}
53
54static 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,
58};
59
60int kvm_perf_init(void)
61{
62 return perf_register_guest_info_callbacks(&kvm_guest_cbs);
63}
64
65int kvm_perf_teardown(void)
66{
67 return perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
68}