Skip to contentSkip to conversation

NEW xmstat xen performance tool

PATCH Mukesh Rathor 1 participant 1 message Aug 26, 2010 perf events

lore
Share & tools
lore
#0 lore raw

Hi all,

Here's a first attempt at writing a perf tool that gives per cpu information. Please let me know if there's any general interest. Make sure to cc me.

Attaching unofficial patch and screenshot. One good thing is it creates an infrastructure to add more perf tools easily (just add to union).

cpu usg intrps pflts hypercls evntc hyp Guests ------------------>
0 93 199 330 32698 492 2 1:000:19 1:001:46 2:001:4 2:002:22

Says that : cpu 0 was 93% utilized. There were 199 interrupts on this cpu, 330 page faults, 32698 hcalls, 492 event channels. The hyp used 2% of the cpu. Guest domid 1 had vcpu 0 use 19% of cpu, and vcpu 1 use 46%. Domid 2 had vcpu 1 use 4% and vcpu 2 use 22%

Hope you guys like it.

thanks,
Mukesh

tools/include/Makefile +3 -1
diff -r 52f536cda4ba tools/include/Makefile
@@ -13,7 +13,7 @@ xen/.dir:
 	mkdir -p xen/libelf
 	ln -sf ../$(XEN_ROOT)/xen/include/public/COPYING xen
 	ln -sf $(addprefix ../,$(wildcard $(XEN_ROOT)/xen/include/public/*.h)) xen
-	ln -sf $(addprefix ../$(XEN_ROOT)/xen/include/public/,arch-ia64 arch-x86 hvm io xsm) xen
+	ln -sf $(addprefix ../$(XEN_ROOT)/xen/include/public/,arch-ia64 arch-x86 hvm io xsm perf) xen
 	ln -sf ../xen-sys/$(XEN_OS) xen/sys
 	ln -sf $(addprefix ../../$(XEN_ROOT)/xen/include/xen/,libelf.h elfstructs.h) xen/libelf/
 	ln -s ../xen-foreign xen/foreign
@@ -30,6 +30,7 @@ install: all
 	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/io
 	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/sys
 	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/xsm
+	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/perf
 	$(INSTALL_DATA) xen/COPYING $(DESTDIR)$(INCLUDEDIR)/xen
 	$(INSTALL_DATA) xen/*.h $(DESTDIR)$(INCLUDEDIR)/xen
 	$(INSTALL_DATA) xen/arch-ia64/*.h $(DESTDIR)$(INCLUDEDIR)/xen/arch-ia64
@@ -41,6 +42,7 @@ install: all
 	$(INSTALL_DATA) xen/io/*.h $(DESTDIR)$(INCLUDEDIR)/xen/io
 	$(INSTALL_DATA) xen/sys/*.h $(DESTDIR)$(INCLUDEDIR)/xen/sys
 	$(INSTALL_DATA) xen/xsm/*.h $(DESTDIR)$(INCLUDEDIR)/xen/xsm
+	$(INSTALL_DATA) xen/perf/*.h $(DESTDIR)$(INCLUDEDIR)/xen/perf
 
 .PHONY: clean
 clean:
tools/perf/xmstat/Makefile new file +52 -0

52 lines not on this page · raw message

tools/perf/xmstat/xmstat.c new file +401 -0

401 lines not on this page · raw message

xen/Rules.mk +2 -0
diff -r 52f536cda4ba xen/Rules.mk
@@ -10,6 +10,7 @@ lock_profile  ?= n
 crash_debug   ?= n
 frame_pointer ?= n
 kdb           ?= n
+xmstat        ?= y
 
 XEN_ROOT=$(BASEDIR)/..
 include $(XEN_ROOT)/Config.mk
@@ -55,6 +56,7 @@ CFLAGS-$(perfc_arrays)  += -DPERF_ARRAYS
 CFLAGS-$(lock_profile)  += -DLOCK_PROFILE
 CFLAGS-$(frame_pointer) += -fno-omit-frame-pointer -DCONFIG_FRAME_POINTER
 CFLAGS-$(kdb)           += -DXEN_KDB_CONFIG
+CFLAGS-$(xmstat)        += -DXEN_PERF_XMSTAT
 
 ifneq ($(max_phys_cpus),)
 CFLAGS-y                += -DMAX_PHYS_CPUS=$(max_phys_cpus)
xen/arch/x86/irq.c +9 -1
diff -r 52f536cda4ba xen/arch/x86/irq.c
@@ -23,6 +23,9 @@
 #include <asm/flushtlb.h>
 #include <asm/mach-generic/mach_apic.h>
 #include <public/physdev.h>
+#ifdef XEN_PERF_XMSTAT
+#include <public/perf/xmstat.h>
+#endif
 
 /* opt_noirqbalance: If true, software IRQ balancing/affinity is disabled. */
 int __read_mostly opt_noirqbalance = 0;
@@ -527,7 +530,12 @@ asmlinkage void do_IRQ(struct cpu_user_r
     unsigned int      vector = regs->entry_vector;
     int irq = __get_cpu_var(vector_irq[vector]);
     struct cpu_user_regs *old_regs = set_irq_regs(regs);
-    
+
+#ifdef XEN_PERF_XMSTAT
+    if (xperf_active)
+        (this_cpu(xmst_pcpu_mp))->xmst_interrupts++;
+#endif
+
     perfc_incr(irqs);
 
     this_cpu(irq_count)++;
xen/arch/x86/traps.c +12 -5
diff -r 52f536cda4ba xen/arch/x86/traps.c
@@ -67,6 +67,9 @@
 #include <asm/hypercall.h>
 #include <public/arch-x86/cpuid.h>
 
+#ifdef XEN_PERF_XMSTAT
+#include <public/perf/xmstat.h>
+#endif
 /*
  * opt_nmi: one of 'ignore', 'dom0', or 'fatal'.
  *  fatal:  Xen prints diagnostic message and then hangs.
@@ -1281,6 +1284,10 @@ asmlinkage void do_page_fault(struct cpu
     unsigned long addr, fixup;
     unsigned int error_code;
 
+#ifdef XEN_PERF_XMSTAT
+    if (xperf_active) 
+        (this_cpu(xmst_pcpu_mp))->xmst_pfaults++;
+#endif
     addr = read_cr2();
 
     /* fixup_page_fault() might change regs->error_code, so cache it here. */
@@ -3068,16 +3075,16 @@ asmlinkage void do_nmi(struct cpu_user_r
     unsigned int cpu = smp_processor_id();
     unsigned char reason;
 
+    ++nmi_count(cpu);
+
+    if ( nmi_callback(regs, cpu) )
+        return;
+
 #ifdef XEN_KDB_CONFIG
     if (kdb_enabled && kdb_handle_trap_entry(TRAP_nmi, regs))
         return;
 #endif
 
-    ++nmi_count(cpu);
-
-    if ( nmi_callback(regs, cpu) )
-        return;
-
     if ( nmi_watchdog )
         nmi_watchdog_tick(regs);
 
xen/arch/x86/x86_64/Makefile +1 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/Makefile
@@ -1,4 +1,5 @@
 subdir-y += compat
+subdir-y += perf
 
 obj-y += entry.o
 obj-y += gpr_switch.o
xen/arch/x86/x86_64/compat/entry.S +2 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/compat/entry.S
@@ -415,6 +415,7 @@ ENTRY(compat_hypercall_table)
         .quad do_domctl
         .quad compat_kexec_op
         .quad do_tmem_op
+        .quad do_perf_op
         .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8)
         .quad compat_ni_hypercall
         .endr
@@ -463,6 +464,7 @@ ENTRY(compat_hypercall_args_table)
         .byte 1 /* do_domctl                */
         .byte 2 /* compat_kexec_op          */
         .byte 1 /* do_tmem_op               */
+        .byte 1 /* do_perf_op               */
         .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table)
         .byte 0 /* compat_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +4 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/entry.S
@@ -188,6 +188,7 @@ ENTRY(syscall_enter)
 #undef SHADOW_BYTES
 1:      leaq  hypercall_table(%rip),%r10
         PERFC_INCR(PERFC_hypercalls, %rax, %rbx)
+        PERF_HCALL_ACCT(%rax, %rbx)
         callq *(%r10,%rax,8)
 #ifndef NDEBUG
         /* Deliberately corrupt parameter regs used by this hypercall. */
@@ -233,6 +234,7 @@ test_guest_events:
         jz    restore_all_guest
 /*process_guest_events:*/
         sti
+        PERF_EVENTS_ACCT(%rbx)
         leaq  VCPU_trap_bounce(%rbx),%rdx
         movq  VCPU_event_addr(%rbx),%rax
         movq  %rax,TRAPBOUNCE_eip(%rdx)
@@ -717,6 +719,7 @@ ENTRY(hypercall_table)
         .quad do_domctl
         .quad do_kexec_op
         .quad do_tmem_op
+        .quad do_perf_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -765,6 +768,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
         .byte 1 /* do_tmem_op           */
+        .byte 1 /* do_perf_op           */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/perf/Makefile new file +3 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/perf/Makefile
@@ -0,0 +1,3 @@
+subdir-y += xmstat
+
+obj-y += xenperf.o
xen/arch/x86/x86_64/perf/xenperf.c new file +34 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/perf/xenperf.c
@@ -0,0 +1,34 @@
+#include <xen/config.h>
+#include <asm/processor.h>
+#include <xen/errno.h>
+#include <public/xenperf.h>
+#include <xen/guest_access.h>
+
+extern int xmstat_op(struct xen_perfop_xmstat *);
+
+
+long do_perf_op(XEN_GUEST_HANDLE(xen_perfop_t) u_perfop)
+{
+    int rc;
+    struct xen_perfop perfop;
+
+    if (copy_from_guest(&perfop, u_perfop, 1))
+        return -EFAULT;
+
+    switch (perfop.cmd) 
+    {
+        case XEN_PERFOP_XMSTAT:
+            rc = xmstat_op(&perfop.u.perf_xmstat);
+            if (copy_to_guest(u_perfop, &perfop, 1))
+                rc = -EFAULT;
+
+            break;
+
+        default:
+            rc = -ENOSYS;
+            break;
+    }
+
+    return rc;
+}
+
xen/arch/x86/x86_64/perf/xmstat/Makefile new file +2 -0
diff -r 52f536cda4ba xen/arch/x86/x86_64/perf/xmstat/Makefile
@@ -0,0 +1,2 @@
+obj-y += xmstat.o
+obj-y += hwctrs.o
xen/arch/x86/x86_64/perf/xmstat/hwctrs.c new file +252 -0

252 lines not on this page · raw message

xen/arch/x86/x86_64/perf/xmstat/xmstat.c new file +192 -0

192 lines not on this page · raw message

xen/include/asm-x86/x86_64/asm_defns.h +32 -0
diff -r 52f536cda4ba xen/include/asm-x86/x86_64/asm_defns.h
@@ -62,6 +62,38 @@ 1:      addq  $8,%rsp;
         popq  %rsi;                             \
         popq  %rdi;
 
+#ifdef XEN_PERF_XMSTAT
+#define PERF_EVENTS_ACCT(rbx_cur)                \
+        testl $1, xperf_active(%rip);            \
+        jz  2f;                                  \
+        pushq rbx_cur;                           \
+        pushq %rdx;                              \
+        movslq VCPU_processor(rbx_cur), rbx_cur; \
+        lea  per_cpu__xmst_pcpu_mp(%rip), %rdx;  \
+        shl  $PERCPU_SHIFT, rbx_cur;             \
+        mov (%rdx,rbx_cur), %rdx;                \
+        incl 0x14(%rdx);                         \
+        popq %rdx;                               \
+        popq rbx_cur;                            \
+2:
+#define PERF_HCALL_ACCT(rax_notused, rbx_cur)    \
+        testl $1, xperf_active(%rip);            \
+        jz  2f;                                  \
+        pushq rbx_cur;                           \
+        pushq %rdx;                              \
+        movslq VCPU_processor(rbx_cur), rbx_cur; \
+        lea  per_cpu__xmst_pcpu_mp(%rip), %rdx;  \
+        shl  $PERCPU_SHIFT, rbx_cur;             \
+        mov (%rdx,rbx_cur), %rdx;                \
+        incl 0x10(%rdx);                         \
+        popq %rdx;                               \
+        popq rbx_cur;                            \
+2:
+#else
+#define PERF_HCALL_ACCT(rax_arg, rbx_cur)
+#define PERF_EVENTS_ACCT(rbx_cur)
+#endif
+
 #ifdef PERF_COUNTERS
 #define PERFC_INCR(_name,_idx,_cur)             \
         pushq _cur;                             \
xen/include/public/perf/xmstat.h new file +73 -0

73 lines not on this page · raw message

xen/include/public/xen.h +1 -0
diff -r 52f536cda4ba xen/include/public/xen.h
@@ -93,6 +93,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
 #define __HYPERVISOR_domctl               36
 #define __HYPERVISOR_kexec_op             37
 #define __HYPERVISOR_tmem_op              38
+#define __HYPERVISOR_perf_op              39
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/public/xenperf.h new file +35 -0
diff -r 52f536cda4ba xen/include/public/xenperf.h
@@ -0,0 +1,35 @@
+#ifndef __XEN_PUBLIC_XENPERF_H__
+#define __XEN_PUBLIC_XENPERF_H__
+
+#include "xen.h"
+#include "perf/xmstat.h"
+
+#define XENPERF_INTERFACE_VERSION 0x00000001
+
+enum {
+    XEN_PERFOP_XMSTAT=1,
+};
+
+struct xen_perfop_xmstat;
+struct xen_perfop {
+    uint32_t cmd;
+    uint32_t interface_version;                 /* XENPERF_INTERFACE_VERSION */
+    union {
+        struct xen_perfop_xmstat perf_xmstat;
+    } u;
+};
+
+typedef struct xen_perfop xen_perfop_t;
+DEFINE_XEN_GUEST_HANDLE(xen_perfop_t);
+
+#endif   /* __XEN_PUBLIC_XENPERF_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/xen/hypercall.h +4 -0
diff -r 52f536cda4ba xen/include/xen/hypercall.h
@@ -16,6 +16,7 @@
 #include <public/tmem.h>
 #include <asm/hypercall.h>
 #include <xsm/xsm.h>
+#include <public/xenperf.h>
 
 extern long
 do_ni_hypercall(
@@ -124,6 +125,9 @@ do_tmem_op(
 extern int
 do_xenoprof_op(int op, XEN_GUEST_HANDLE(void) arg);
 
+extern long
+do_perf_op(int op, XEN_GUEST_HANDLE(void) arg);
+
 #ifdef CONFIG_COMPAT
 
 extern int

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel