Skip to contentSkip to conversation

Hypervisor profiling using GCOV

RFC PATCH New Tej 1 participant 1 message Feb 16, 2009 Xen hypervisor interface

lore
Share & tools
lore

Tej

author
#0 lore raw

RFC PATCH 1/1 Hypervisor profiling using GCOV

gcov is a test coverage program. generally used with GCC to analyze programs to help create more efficient, faster running code and to discover untested parts of your program. Software developers also use coverage testing in concert with testsuites, to make sure software is actually good enough for a release

Our efforts on the same line added the gcov(gcc) profiling support for hypervisor only.
Current code base support xen-3.3.onwards, x86_32 and gcc 3.4 to 4.3.

xen-patch: code for hypervisor which populate the gcov_info (gcc 3.4 onward) with data file information, base code is taken from
http://ltp.sourceforge.net/coverage/gcov.php. added xen support and a way to interact with linux since hypervisor itself cannot populate the /proc filesystem.

linux-patch: code for linux kernel basically enquire the hypervisor part to revert all data file information and populate the /proc/xen/gcov with data and graph file (optional)

command-line/modules parameter:
1. xen-gcov-link: if set, it creates the *.c and *.gcno linking under /proc/xen/gcov, else to run gcov/lcov we have to create manually linking.
2. xen-gcov-update: update the data files after xen-gcov-update secs, default value is 5sec... e.g while running a test suite, requires lower value of xen-gcov-update.
tunable xen-gcov-update exist at /proc/sys/xen
usage: echo <num> >/proc/sys/xen/xen-gcov-update

Running lcov straight-a-way could be problematic because lcov is written to see profiling info @/proc/gcov. To accomodate /proc/xen/gcov edit the config file /etc/lcovrc parameter as lcov_gcov_dir = /proc/gcov to /proc/xen/gcov and perform modprobe xen-gcov-proc.
We are having patches to accomodate both but changing config file could be a better options. Still if someone need patch please free to mail me @[email protected]

YES, We are aware that gcov profiling is quite basic profiling concept, but its a begning from our end to make xen hypervisor best and robust, in future we will be working on changes required for 64bit hypervisor, older xen versions (if required), PERFMON features of Modern CPU's.

Comments, reports, suggestions, and any other types of feedback is more than welcome

-tej & team

drivers/xen/Kconfig +5 -0
diff -r 3aa9b8a7876b drivers/xen/Kconfig
@@ -263,6 +263,11 @@
 	default y
 	help
 	  Xen hypervisor attributes will show up under /sys/hypervisor/.
+config XEN_GCOV_PROC
+        tristate "Code covarage for hypervisor"
+        help
+         Select to profile Xen Hypervisor only. Create /proc/xen/gcov entry
+         which provides access to the current code coverage state of xen hypervisor
 
 choice
 	prompt "Xen version compatibility"
drivers/xen/Makefile +1 -0
diff -r 3aa9b8a7876b drivers/xen/Makefile
@@ -3,6 +3,7 @@
 obj-y	+= evtchn/
 obj-y	+= xenbus/
 obj-y	+= char/
+obj-y   += gcov/
 
 obj-y	+= util.o
 obj-$(CONFIG_XEN_BALLOON)		+= balloon/
drivers/xen/core/xen_proc.c +2 -1
diff -r 3aa9b8a7876b drivers/xen/core/xen_proc.c
@@ -3,7 +3,7 @@
 #include <linux/proc_fs.h>
 #include <xen/xen_proc.h>
 
-static struct proc_dir_entry *xen_base;
+struct proc_dir_entry *xen_base;
 
 struct proc_dir_entry *create_xen_proc_entry(const char *name, mode_t mode)
 {
@@ -20,4 +20,5 @@
 	remove_proc_entry(name, xen_base);
 }
 
+EXPORT_SYMBOL(xen_base);
 EXPORT_SYMBOL_GPL(remove_xen_proc_entry); 
drivers/xen/gcov/Makefile new file +1 -0
diff -r 3aa9b8a7876b drivers/xen/gcov/Makefile
@@ -0,0 +1,1 @@
+obj-$(CONFIG_XEN_GCOV_PROC) := xen-gcov-proc.o
drivers/xen/gcov/xen-gcov-proc.c new file +1054 -0

1,054 lines not on this page · raw message

include/asm-i386/mach-xen/asm/hypercall.h +7 -0
diff -r 3aa9b8a7876b include/asm-i386/mach-xen/asm/hypercall.h
@@ -398,6 +398,13 @@
 }
 
 static inline int __must_check
+HYPERVISOR_gcovprof_op(
+                int cmd, void *arg, int val)
+{
+        return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
+static inline int __must_check
 HYPERVISOR_kexec_op(
 	unsigned long op, void *args)
 {
include/xen/interface/xen-gcov.h new file +123 -0

123 lines not on this page · raw message

include/xen/interface/xen.h +1 -0
diff -r 3aa9b8a7876b include/xen/interface/xen.h
@@ -91,6 +91,7 @@
 #define __HYPERVISOR_sysctl               35
 #define __HYPERVISOR_domctl               36
 #define __HYPERVISOR_kexec_op             37
+#define __HYPERVISOR_gcovprof_op          38
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
include/xen/xen_proc.h +2 -0
diff -r 3aa9b8a7876b include/xen/xen_proc.h
@@ -4,6 +4,8 @@
 
 #include <linux/proc_fs.h>
 
+extern struct proc_dir_entry *xen_base;
+
 extern struct proc_dir_entry *create_xen_proc_entry(
 	const char *name, mode_t mode);
 extern void remove_xen_proc_entry(
xen/Rules.mk +8 -1
diff -r b1ab0c6c6019 xen/Rules.mk
@@ -9,6 +9,10 @@
 crash_debug   ?= n
 frame_pointer ?= n
 
+# xen source path to get update in .gcno files
+xen_src := $(CURDIR)
+xentree := $(if $(xen_src),$(xen_src),$(CURDIR))
+
 XEN_ROOT=$(BASEDIR)/..
 include $(XEN_ROOT)/Config.mk
 
@@ -56,6 +60,7 @@
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 
 CFLAGS-y                += -g -D__XEN__
+CFLAGS-y                += -fprofile-arcs -ftest-coverage
 CFLAGS-$(XSM_ENABLE)    += -DXSM_ENABLE
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_ENABLE -DXSM_MAGIC=0xf97cff8c
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_DEVELOP -DFLASK_BOOTPARAM -DFLASK_AVC_STATS
@@ -117,7 +122,9 @@
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
 
 %.o: %.c $(HDRS) Makefile
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(CFLAGS) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+
 
 %.o: %.S $(AHDRS) Makefile
 	$(CC) $(AFLAGS) -c $< -o $@
xen/arch/x86/mm/hap/Makefile +10 -1
diff -r b1ab0c6c6019 xen/arch/x86/mm/hap/Makefile
@@ -4,8 +4,17 @@
 obj-y += guest_walk_4level.o
 obj-y += p2m-ept.o
 
+LN = /bin/ln
+xen_src := $(CURDIR)
+xentree := $(if $(xen_src),$(xen_src),$(CURDIR))
+
 guest_levels  = $(subst level,,$(filter %level,$(subst ., ,$(subst _, ,$(1)))))
 guest_walk_defns = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1))
 
+num = $(call guest_levels,$(@F))level.c
+
 guest_walk_%level.o: guest_walk.c $(HDRS) Makefile
-	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c $< -o $@
+	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s guest_walk.c guest_walk_$(num)
+
xen/arch/x86/mm/shadow/Makefile +6 -1
diff -r b1ab0c6c6019 xen/arch/x86/mm/shadow/Makefile
@@ -1,5 +1,10 @@
 obj-$(x86_32) += common.o guest_2.o guest_3.o
 obj-$(x86_64) += common.o guest_2.o guest_3.o guest_4.o
 
+LN = /bin/ln
+num=$*.c
+
 guest_%.o: multi.c $(HDRS) Makefile
-	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s multi.c guest_$(num)
xen/arch/x86/x86_32/entry.S +2 -0
diff -r b1ab0c6c6019 xen/arch/x86/x86_32/entry.S
@@ -703,6 +703,7 @@
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+        .long do_gcovprof_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -750,6 +751,7 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+        .byte 3 /* do_gcovprof_op       */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/Makefile +3 -0
diff -r b1ab0c6c6019 xen/common/Makefile
@@ -27,6 +27,7 @@
 obj-y += vsprintf.o
 obj-y += xmalloc.o
 obj-y += rcupdate.o
+obj-y += xen-gcov-core.o
 
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
@@ -42,6 +43,8 @@
 
 subdir-y += libelf
 
+CFLAGS += -DSRC_PATH='"$(BASEDIR)"'
+
 # Object file contains changeset and compiler information.
 version.o: $(BASEDIR)/include/xen/compile.h
 
xen/common/xen-gcov-core.c new file +242 -0

242 lines not on this page · raw message

xen/include/public/xen-gcov.h new file +139 -0

139 lines not on this page · raw message

xen/include/xen/config.h +16 -0
diff -r b1ab0c6c6019 xen/include/xen/config.h
@@ -96,4 +96,20 @@
 #define __cpuinitdata
 #define __cpuinit
 
+#define SORT(x)        x
+#define CONSTRUCTORS                           \
+       __CTOR_LIST__ = .;                  \
+       LONG((__CTOR_END__ - __CTOR_LIST__) /           \
+           (__CTOR_LIST2__ - __CTOR_LIST__) - 2)       \
+       __CTOR_LIST2__ = .;                 \
+       *(SORT(.ctors))                     \
+       LONG(0)                         \
+       __CTOR_END__ = .;                   \
+       __DTOR_LIST__ = .;                  \
+       LONG((__DTOR_END__ - __DTOR_LIST__) /           \
+           (__CTOR_LIST2__ - __CTOR_LIST__) - 2)       \
+       *(SORT(.dtors))                     \
+       LONG(0)                         \
+       __DTOR_END__ = .;
+
 #endif /* __XEN_CONFIG_H__ */

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