Skip to contentSkip to conversation

Hypervisor profiling using GCOV

RFC PATCH Tej 2 participants 3 messages Feb 18, 2009 – Feb 19, 2009 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): C5C17211.2D71%[email protected]

Tej

author
#2 lore raw
Quoted 4 lines · Keir Fraser
Quoted 2 lines · Tej

hey keir

Quoted 8 lines
Quoted 4 lines

i need some input from you, regarding this tool.. It is worth investigating further in hypervisor profiling.
or anything like this tool need a better design/coding/new features anything of this sort.

Does it get us significantly more than the existing xentrace and xenoprofile tools? Especially the latter, which already does program-counter tracing and generation of stats from that, via the oprofile tool.

thanks for our feedback
i agree xenoprofile is advanced proffiling tool in xen since ages, but GCOV could be useful tool to naive tester/programmer on XEN who really don't understand xenoprofile stats....

e.g If i start with any hypervisor subsystem (scheduler), i will run xm test suite for scheduler and see what all code is getting affected over a period of time and proceed with it...

Quoted 3 lines

George Dunlap does most of our profiling internally. You might ask him what he thinks compared with these existing supported tools.

George, Do you have any comments on this

Quoted 5 lines

-- Keir

thanks
-tej

#3 lore raw
Quoted 10 lines · Tej
Quoted 4 lines

Does it get us significantly more than the existing xentrace and xenoprofile tools? Especially the latter, which already does program-counter tracing and generation of stats from that, via the oprofile tool.

thanks for our feedback
i agree xenoprofile is advanced proffiling tool in xen since ages, but GCOV could be useful tool to naive tester/programmer on XEN who really don't understand xenoprofile stats....

Don't undersell gcov; its purpose is slightly different from either xentrace or xenoprofile. Xentrace can be used to get information about what paths or reasons caused vmexits (as well as just seeing specific patterns that happen). xenoprofile is a relatively low-overhead way of just profiling (which unfortuantely doesn't work properly in 32-on-64 mode ATM). gcov's main purpose is to tell you code coverage; profiling is just a side-effect.

I looked at the LTP page about lcov, and it looks like it was pretty useful for them. It has graphical output with the number of times / percentage a given path was taken. It probably is worth porting to Xen for the same reason -- to see how well given paths in Xen actually get exercised.

Quoted 4 lines

e.g If i start with any hypervisor subsystem (scheduler), i will run xm test suite for scheduler and see what all code is getting affected over a period of time and proceed with it...

It sounds like the main problem with xenoprofile is that it's hard to set up and use ATM: it could use some attention to the code, and some well-worded HOWTOs. The fact that 32-on-64 doesn't work properly (truncates the long EIPs) doesn't help. :-)

So I think that it probably would be useful. Unfortunately, I don't have time in the near future to look at either of these (new "xcov" functionality, or fixing xenoprofile). Gianluca's been doing some interesting work with testing. I'll ask him if he's interested in looking at it.

Thanks for your work though, Tej!

-George

author
#4 lore raw
Quoted 38 lines · George Dunlap
Quoted 8 lines · Tej
Quoted 7 lines

Does it get us significantly more than the existing xentrace and xenoprofile
tools? Especially the latter, which already does program-counter tracing and
generation of stats from that, via the oprofile tool.

Quoted 5 lines

thanks for our feedback
i agree xenoprofile is advanced proffiling tool in xen since ages, but GCOV could be useful tool to naive tester/programmer on XEN who really don't understand xenoprofile stats....

Don't undersell gcov; its purpose is slightly different from either xentrace or xenoprofile. Xentrace can be used to get information about what paths or reasons caused vmexits (as well as just seeing specific patterns that happen). xenoprofile is a relatively low-overhead way of just profiling
(which unfortuantely doesn't work properly in 32-on-64 mode ATM). gcov's
main purpose is to tell you code coverage; profiling is just a side-effect.

I looked at the LTP page about lcov, and it looks like it was pretty useful for them. It has graphical output with the number of times / percentage a given path was taken. It probably is worth porting to Xen for the same reason -- to see how well given paths in Xen actually get exercised.

Quoted 5 lines

e.g If i start with any hypervisor subsystem (scheduler), i will run xm test suite for scheduler and see what all code is getting affected over a period of time and proceed with it...

It sounds like the main problem with xenoprofile is that it's hard to set up and use ATM: it could use some attention to the code, and some well-worded HOWTOs. The fact that 32-on-64 doesn't work properly (truncates the long EIPs) doesn't help. :-)

Quoted 5 lines

So I think that it probably would be useful. Unfortunately, I don't have time in the near future to look at either of these (new "xcov" functionality, or fixing xenoprofile). Gianluca's been doing some interesting work with testing. I'll ask him if he's interested in looking at it.

thanks for your valuable feedback....
I need some comments from you or Gianluca regarding the basic design and coding standard, or any other way it can be improved. Patches are mainly to show the design and approach we have followed to produce code coverage.

I am planning to change code of lcov to support xen code coverage out of box rather than changing lcov config file.
any comments on this?

Anyway here are the patches for xen-3.2 and xen-3.1.* in Xen-3.2 previous linux patches will do.

Quoted 2 lines

Thanks for your work though, Tej!

thanks
-tej

Quoted 3 lines

-George

linux-2.6-xen-sparse/drivers/xen/Kconfig +6 -0
diff -r 0ca89fa82946 linux-2.6-xen-sparse/drivers/xen/Kconfig
@@ -237,6 +237,12 @@
 	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"
 	default XEN_COMPAT_030002_AND_LATER
linux-2.6-xen-sparse/drivers/xen/Makefile +1 -0
diff -r 0ca89fa82946 linux-2.6-xen-sparse/drivers/xen/Makefile
@@ -6,6 +6,7 @@
 obj-y	+= gntdev/
 obj-y	+= balloon/
 obj-y	+= char/
+obj-y   += gcov/
 
 obj-y	+= util.o
 obj-$(CONFIG_XEN_BLKDEV_BACKEND)	+= blkback/
linux-2.6-xen-sparse/drivers/xen/core/xen_proc.c +2 -1
diff -r 0ca89fa82946 linux-2.6-xen-sparse/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); 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h +7 -0
diff -r 0ca89fa82946 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h
@@ -395,6 +395,13 @@
 	return _hypercall2(int, xenoprof_op, op, arg);
 }
 
+static inline int 
+HYPERVISOR_gcovprof_op(
+                int cmd, void *arg, int val)
+{
+        return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 static inline int
 HYPERVISOR_kexec_op(
 	unsigned long op, void *args)
linux-2.6-xen-sparse/include/xen/xen_proc.h +2 -0
diff -r 0ca89fa82946 linux-2.6-xen-sparse/include/xen/xen_proc.h
@@ -3,6 +3,8 @@
 #define __ASM_XEN_PROC_H__
 
 #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);
linux-2.6.18.8-xen/drivers/xen/gcov/Makefile new file +1 -0
diff -r 0ca89fa82946 linux-2.6.18.8-xen/drivers/xen/gcov/Makefile
@@ -0,0 +1,1 @@
+obj-$(CONFIG_XEN_GCOV_PROC) := xen-gcov-proc.o
linux-2.6.18.8-xen/drivers/xen/gcov/xen-gcov-proc.c new file +1054 -0

1,054 lines not on this page · raw message

linux-2.6.18.8-xen/include/xen/interface/xen-gcov.h new file +123 -0

123 lines not on this page · raw message

xen/Rules.mk +8 -1
diff -r 0ca89fa82946 xen/Rules.mk
@@ -8,6 +8,11 @@
 perfc_arrays  ?= n
 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 +61,7 @@
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 
 CFLAGS-y                += -g -D__XEN__
+CFLAGS-y                += -fprofile-arcs -ftest-coverage
 CFLAGS-$(ACM_SECURITY)  += -DACM_SECURITY
 CFLAGS-$(verbose)       += -DVERBOSE
 CFLAGS-$(crash_debug)   += -DCRASH_DEBUG
@@ -114,7 +120,8 @@
 	$(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/shadow/Makefile +6 -1
diff -r 0ca89fa82946 xen/arch/x86/mm/shadow/Makefile
@@ -6,10 +6,15 @@
 
 obj-$(x86_64) += common.o g4_on_s4.o g3_on_s3.o g2_on_s3.o
 
+LN = /bin/ln
+num=$*.c
+
 guest_levels  = $(subst g,,$(filter g%,$(subst ., ,$(subst _, ,$(1)))))
 shadow_levels = $(subst s,,$(filter s%,$(subst ., ,$(subst _, ,$(1)))))
 shadow_defns  = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1)) \
                 -DSHADOW_PAGING_LEVELS=$(call shadow_levels,$(1))
 
 g%.o: multi.c $(HDRS) Makefile
-	$(CC) $(CFLAGS) $(call shadow_defns,$(@F)) -c $< -o $@
+	$(CC) $(CFLAGS) $(call shadow_defns,$(@F)) -c -o $@ \
+		 $(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s multi.c g$(num) 
xen/arch/x86/x86_32/entry.S +2 -0
diff -r 0ca89fa82946 xen/arch/x86/x86_32/entry.S
@@ -676,6 +676,7 @@
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+        .long do_gcovprof_op
         .rept NR_hypercalls-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -719,6 +720,7 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+	.byte 3 /* do_gcovprof_op       */
         .rept NR_hypercalls-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/Makefile +3 -0
diff -r 0ca89fa82946 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
@@ -38,6 +39,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 +241 -0

241 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/public/xen.h +1 -0
diff -r 0ca89fa82946 xen/include/public/xen.h
@@ -80,6 +80,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
xen/include/xen/config.h +17 -0
diff -r 0ca89fa82946 xen/include/xen/config.h
@@ -95,4 +95,21 @@
 #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/Rules.mk +8 -1
diff -r 8610d3bf7b25 xen/Rules.mk
@@ -8,6 +8,10 @@
 perfc_arrays  ?= n
 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
@@ -59,6 +63,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
@@ -120,7 +125,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 8610d3bf7b25 xen/arch/x86/mm/hap/Makefile
@@ -3,8 +3,17 @@
 obj-y += guest_walk_3level.o
 obj-y += guest_walk_4level.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_$(exp)
+
xen/arch/x86/mm/shadow/Makefile +7 -1
diff -r 8610d3bf7b25 xen/arch/x86/mm/shadow/Makefile
@@ -6,10 +6,16 @@
 
 obj-$(x86_64) += common.o g4_on_s4.o g3_on_s3.o g2_on_s3.o
 
+LN = /bin/ln
+num=$*.c
+
 guest_levels  = $(subst g,,$(filter g%,$(subst ., ,$(subst _, ,$(1)))))
 shadow_levels = $(subst s,,$(filter s%,$(subst ., ,$(subst _, ,$(1)))))
 shadow_defns  = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1)) \
                 -DSHADOW_PAGING_LEVELS=$(call shadow_levels,$(1))
 
 g%.o: multi.c $(HDRS) Makefile
-	$(CC) $(CFLAGS) $(call shadow_defns,$(@F)) -c $< -o $@
+	$(CC) $(CFLAGS) $(call shadow_defns,$(@F)) -c -o $@ \
+		$(if $(filter-out /%,$@),$(xentree)/$<,$<)
+	$(LN) -f -s multi.c g$(num) 
+
xen/arch/x86/x86_32/entry.S +2 -0
diff -r 8610d3bf7b25 xen/arch/x86/x86_32/entry.S
@@ -682,6 +682,7 @@
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+        .long do_gcovprof_op
         .rept NR_hypercalls-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -725,6 +726,7 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+        .byte 3 /* do_gcovprof_op       */
         .rept NR_hypercalls-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/Makefile +3 -0
diff -r 8610d3bf7b25 xen/common/Makefile
@@ -26,6 +26,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
@@ -41,6 +42,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 8610d3bf7b25 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