Re: [PATCH V4 1/2] perf & kvm: Enhance perf to collect KVM guest os statistics from host side

Previous thread: [PATCH V4 0/2] perf & kvm: Enhance perf to collect KVM guest os statistics from host side by Zhang, Yanmin on Friday, April 16, 2010 - 12:34 am. (1 message)

Next thread: [PATCH V4 2/2] perf & kvm: Enhance perf to collect KVM guest os statistics from host side by Zhang, Yanmin on Friday, April 16, 2010 - 12:34 am. (1 message)
From: Zhang, Yanmin
Date: Friday, April 16, 2010 - 12:34 am

Below is the kernel patch to enable perf to collect guest os statistics.

Joerg,

Would you like to add support on svm? I don't know the exact point to trigger
NMI to host with svm.

See below code with vmx:
 
+		kvm_before_handle_nmi(&vmx->vcpu);
 		asm("int $2");
+		kvm_after_handle_nmi(&vmx->vcpu);

Signed-off-by: Zhang Yanmin <yanmin_zhang@linux.intel.com>

---

diff -Nraup --exclude=tools linux-2.6_tip0413/arch/x86/include/asm/perf_event.h linux-2.6_tip0413_perfkvm/arch/x86/include/asm/perf_event.h
--- linux-2.6_tip0413/arch/x86/include/asm/perf_event.h	2010-04-14 11:11:03.992966568 +0800
+++ linux-2.6_tip0413_perfkvm/arch/x86/include/asm/perf_event.h	2010-04-14 11:13:17.261881591 +0800
@@ -135,17 +135,10 @@ extern void perf_events_lapic_init(void)
  */
 #define PERF_EFLAGS_EXACT	(1UL << 3)
 
-#define perf_misc_flags(regs)				\
-({	int misc = 0;					\
-	if (user_mode(regs))				\
-		misc |= PERF_RECORD_MISC_USER;		\
-	else						\
-		misc |= PERF_RECORD_MISC_KERNEL;	\
-	if (regs->flags & PERF_EFLAGS_EXACT)		\
-		misc |= PERF_RECORD_MISC_EXACT;		\
-	misc; })
-
-#define perf_instruction_pointer(regs)	((regs)->ip)
+struct pt_regs;
+extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
+extern unsigned long perf_misc_flags(struct pt_regs *regs);
+#define perf_misc_flags(regs)	perf_misc_flags(regs)
 
 #else
 static inline void init_hw_perf_events(void)		{ }
diff -Nraup --exclude=tools linux-2.6_tip0413/arch/x86/kernel/cpu/perf_event.c linux-2.6_tip0413_perfkvm/arch/x86/kernel/cpu/perf_event.c
--- linux-2.6_tip0413/arch/x86/kernel/cpu/perf_event.c	2010-04-14 11:11:04.825028810 +0800
+++ linux-2.6_tip0413_perfkvm/arch/x86/kernel/cpu/perf_event.c	2010-04-14 17:02:12.198063684 +0800
@@ -1720,6 +1720,11 @@ struct perf_callchain_entry *perf_callch
 {
 	struct perf_callchain_entry *entry;
 
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+		/* TODO: We don't support guest os callchain now */
+		return NULL;
+	}
+
 	if (in_nmi())
 		entry = ...
From: Joerg Roedel
Date: Saturday, April 17, 2010 - 3:49 am

Hi Yanmin,


Yes I will do that, thanks for all the work you have already done :-) Do
we have a branch for that work somewhere? Probably in the -tip tree? 

	Joerg

--

From: Avi Kivity
Date: Saturday, April 17, 2010 - 11:23 am

Can you please split it further?

Patch 1 introduces perf_register_guest_info_callbacks() and related.  
Ingo can merge this into a branch in tip.git.
Patch 2 is just the kvm bits, I'll apply that after merging the branch 
with patch 1.
Patch 3 adds the tools/perf changes.

This way perf development can continue on tip.git, and kvm development 
can continue on kvm.git, without the code bases diverging and requiring 
a merge later.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--

From: Ingo Molnar
Date: Saturday, April 17, 2010 - 12:13 pm

I'd like to pull the KVM bits from you into perf - so that there's a testable 
form of the changes. We can do that via a branch that has 1-2 changes, plus 
minimal conflicts down the line, right?

	Ingo
--

From: Avi Kivity
Date: Saturday, April 17, 2010 - 12:16 pm

We can try doing this (currently we don't, but this is simple enough 
that we could).  I'd still like 1-2 in two patches.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--

Previous thread: [PATCH V4 0/2] perf & kvm: Enhance perf to collect KVM guest os statistics from host side by Zhang, Yanmin on Friday, April 16, 2010 - 12:34 am. (1 message)

Next thread: [PATCH V4 2/2] perf & kvm: Enhance perf to collect KVM guest os statistics from host side by Zhang, Yanmin on Friday, April 16, 2010 - 12:34 am. (1 message)