Skip to contentSkip to conversation

ara virt interface of perf to support kvm guest os statistics collection in guest os

PATCH In review Zhang, Yanmin 2 participants 3 messages Jun 21, 2010 – Jun 22, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 4/5 ara virt interface of perf to support kvm guest os statistics collection in guest os

The 4th patch is to implement para virt perf at guest side.

---

arch/x86/Kconfig +8 -0
@@ -552,6 +552,14 @@ config KVM_GUEST
 	  This option enables various optimizations for running under the KVM
 	  hypervisor.
 
+config KVM_PERF
+	bool "KVM Guest perf support"
+	select PARAVIRT
+	select PERF_EVENT
+	---help---
+	  This option enables various optimizations for running perf in
+	  guest os under the KVM hypervisor.
+
 source "arch/x86/lguest/Kconfig"
 
 config PARAVIRT
arch/x86/kernel/cpu/perf_event.c +29 -0
@@ -25,6 +25,7 @@
 #include <linux/highmem.h>
 #include <linux/cpu.h>
 #include <linux/bitops.h>
+#include <linux/kvm_para.h>
 
 #include <asm/apic.h>
 #include <asm/stacktrace.h>
@@ -583,10 +584,20 @@ static void x86_pmu_disable_all(void)
 	}
 }
 
+#ifdef CONFIG_KVM_PERF
+static int kvm_hw_perf_enable(void);
+static int kvm_hw_perf_disable(void);
+#endif
+
 void hw_perf_disable(void)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_disable())
+		return;
+#endif
+
 	if (!x86_pmu_initialized())
 		return;
 
@@ -810,6 +821,11 @@ void hw_perf_enable(void)
 	struct hw_perf_event *hwc;
 	int i, added = cpuc->n_added;
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_enable())
+		return;
+#endif
+
 	if (!x86_pmu_initialized())
 		return;
 
@@ -1264,6 +1280,7 @@ x86_get_event_constraints(struct cpu_hw_
 #include "perf_event_intel_lbr.c"
 #include "perf_event_intel_ds.c"
 #include "perf_event_intel.c"
+#include "perf_event_kvm.c"
 
 static int __cpuinit
 x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
@@ -1317,6 +1334,11 @@ void __init init_hw_perf_events(void)
 
 	pr_info("Performance Events: ");
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_init_hw_perf_events())
+		return;
+#endif
+
 	switch (boot_cpu_data.x86_vendor) {
 	case X86_VENDOR_INTEL:
 		err = intel_pmu_init();
@@ -1541,6 +1563,13 @@ const struct pmu *hw_perf_event_init(str
 	const struct pmu *tmp;
 	int err;
 
+#ifdef CONFIG_KVM_PERF
+	if (kvm_para_available()) {
+		tmp = kvm_hw_perf_event_init(event);
+		return tmp;
+	}
+#endif
+
 	err = __hw_perf_event_init(event);
 	if (!err) {
 		/*
arch/x86/kernel/cpu/perf_event_kvm.c +426 -0

426 lines not on this page · raw message

Documentation/kvm/cpuid.txt +3 -0
@@ -36,6 +36,9 @@ KVM_FEATURE_MMU_OP                 ||   
 KVM_FEATURE_CLOCKSOURCE2           ||     3 || kvmclock available at msrs
                                    ||       || 0x4b564d00 and 0x4b564d01
 ------------------------------------------------------------------------------
+KVM_FEATURE_PV_PERF                ||     4 || kvm paravirt perf event
+                                   ||       || available
+------------------------------------------------------------------------------
 KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ||    24 || host will warn if no guest-side
                                    ||       || per-cpu warps are expected in
                                    ||       || kvmclock.
#1 lore raw

arch/x86/kernel/cpu/perf_event.c static void x86_pmu_disable_all(void) · line 590

Quoted 8 lines · Yanmin
arch/x86/kernel/cpu/perf_event.c +4 -0
@@ -583,10 +584,20 @@ static void x86_pmu_disable_all(void)
 	}
 }
 
+#ifdef CONFIG_KVM_PERF
+static int kvm_hw_perf_enable(void);
+static int kvm_hw_perf_disable(void);
+#endif

Please put these prototypes into a header ... and create dummy stubs for them when CONFIG_KVM_PERF is not set.

arch/x86/kernel/cpu/perf_event.c static void x86_pmu_disable_all(void) · line 599

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
 void hw_perf_disable(void)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_disable())
+		return;
+#endif

If you stub them out we can avoid all the ugly #ifdefs

arch/x86/kernel/cpu/perf_event.c void hw_perf_enable(void) · line 827

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
@@ -810,6 +821,11 @@ void hw_perf_enable(void)
 	struct hw_perf_event *hwc;
 	int i, added = cpuc->n_added;
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_enable())
+		return;
+#endif

and here....

arch/x86/kernel/cpu/perf_event.c void __init init_hw_perf_events(void) · line 1340

Quoted 8 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
@@ -1317,6 +1334,11 @@ void __init init_hw_perf_events(void)
 
 	pr_info("Performance Events: ");
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_init_hw_perf_events())
+		return;
+#endif

and again here :)

Cheers,
Jes

#2 lore raw
Quoted 5 lines · Jes Sorensen
Quoted 4 lines · Yanmin
(quoted diff) +0 -0
@@ -583,10 +584,20 @@ static void x86_pmu_disable_all(void)
 	}
 }
 
Quoted 7 lines

arch/x86/kernel/cpu/perf_event.c static void x86_pmu_disable_all(void) · line 590

Quoted 4 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
+#ifdef CONFIG_KVM_PERF
+static int kvm_hw_perf_enable(void);
+static int kvm_hw_perf_disable(void);
+#endif

Please put these prototypes into a header ... and create dummy stubs for them when CONFIG_KVM_PERF is not set.

Ok. I just didn't want to touch too much generic codes of perf.

Quoted 11 lines

arch/x86/kernel/cpu/perf_event.c static void x86_pmu_disable_all(void) · line 599

Quoted 9 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
 void hw_perf_disable(void)
 {
 	struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_disable())
+		return;
+#endif

If you stub them out we can avoid all the ugly #ifdefs

Ok.

Quoted 11 lines

arch/x86/kernel/cpu/perf_event.c void hw_perf_enable(void) · line 827

Quoted 9 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
@@ -810,6 +821,11 @@ void hw_perf_enable(void)
 	struct hw_perf_event *hwc;
 	int i, added = cpuc->n_added;
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_hw_perf_enable())
+		return;
+#endif

and here....

Ok.

Quoted 11 lines

arch/x86/kernel/cpu/perf_event.c void __init init_hw_perf_events(void) · line 1340

Quoted 9 lines
arch/x86/kernel/cpu/perf_event.c +4 -0
@@ -1317,6 +1334,11 @@ void __init init_hw_perf_events(void)
 
 	pr_info("Performance Events: ");
 
+#ifdef CONFIG_KVM_PERF
+	if (!kvm_init_hw_perf_events())
+		return;
+#endif

and again here :)

Ok. Peter is working out a couple of patches to support multiple PMU. His patches change pmu difition and we might move some into the callbacks. That will become much clearer.

Yanmin