Skip to contentSkip to conversation

Hypervisor profiling using GCOV (64bit Hypervisor)

PATCH-0/2 Tej 2 participants 8 messages Feb 26, 2009 – Apr 29, 2009 1 message not in the archive Xen hypervisor interface

lore
Share & tools
lore

Tej

author
#0 lore raw
Quoted 9 lines · Gianluca Guida
Quoted 5 lines · George Dunlap

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.

Quoted 8 lines

Definitely. Getting code coverage reports, whatever the tools, may help a lot when trying to debug a bizarre memory corruption or even just to check that a test you're writing does what you actually want.

Keep me in the loop and feel free to ask questions, I'll start reading patches and experimenting with it. IMHO, I think that 64bit hypervisor support will be by far more useful, since it's the most used version of the hypervisor, nowadays.

Sending Patches for the 64 bit Hypervisor, We have tested patches on AMD-64 (Athlon(tm) 64 X2 Dual Core Processor 4600+) machine with gcc-4.2 & gcc-3.4. Please refer the previous GCOV RFC in same mail for more info on Hypervisor profiling.
We have added support to 32bit and 64bit Kernel.

In addition to patches for hypervisor profiling, we did a little work on *lcov* to work with hypervisor.
README could be useful, for naive lcov user. locv-diff.patch show our change in lcov scripts.

any comments, feedback and suggestion are more than welcome

P.S. a lcov screenshot with hypervisor profling has been attached.

thanks
-tej & team

Quoted 5 lines

Thanks,
Gianluca

xen/Rules.mk +8 -1
diff -r 5dbe4ef883fa 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
@@ -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 5dbe4ef883fa 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 5dbe4ef883fa 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 5dbe4ef883fa 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/arch/x86/x86_64/entry.S +2 -0
diff -r 5dbe4ef883fa xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,7 @@
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+        .quad do_gcovprof_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,6 +740,7 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
+        .byte 3 /* do_gcovprof_op       */
         .byte 1 /* do_xsm_op            */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
xen/common/Makefile +3 -0
diff -r 5dbe4ef883fa 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 5dbe4ef883fa 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__ */
drivers/xen/Kconfig +5 -0
diff -r 51decc39e5e7 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 51decc39e5e7 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 51decc39e5e7 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 51decc39e5e7 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 51decc39e5e7 include/asm-i386/mach-xen/asm/hypercall.h
@@ -404,6 +404,13 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 
 
 #endif /* __HYPERCALL_H__ */
include/asm-x86_64/mach-xen/asm/hypercall.h +7 -0
diff -r 51decc39e5e7 include/asm-x86_64/mach-xen/asm/hypercall.h
@@ -405,4 +405,11 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 #endif /* __HYPERCALL_H__ */
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 51decc39e5e7 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 51decc39e5e7 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);
lcov-mod renamed from lcov +13 -6
@@ -67,9 +67,11 @@
 our $lcov_version	= "LTP GCOV extension version 1.6";
 our $lcov_url		= "http://ltp.sourceforge.net/coverage/lcov.php";
 
-# Names of the GCOV kernel module
-our @gcovmod = ("gcov-prof", "gcov-proc");
-
+# Hash Table which contains gcov module name as well as directory path
+our %gcov_module_dir = ( "gcov-prof"     => "/proc/gcov",
+                         "gcov-proc"     => "/proc/gcov",
+                         "xen-gcov-proc" => "/proc/xen/gcov" );
+                                                   
 # Directory containing gcov kernel files
 our $gcov_dir = "/proc/gcov";
 
@@ -736,7 +738,7 @@
 
 sub check_and_load_kernel_module()
 {
-	my $module_name;
+	my $module_name="";
 
 	# Is it loaded already?
 	stat("$gcov_dir");
@@ -759,9 +761,14 @@
 		    "kernel coverage data!\n");
 	}
 
-	# Try some possibilities of where the gcov kernel module may be found
-	foreach $module_name (@gcovmod)
+	# Try some possibilities of where the gcov module may be found.
+	# And there is a hash table called %gcov_module_dir which has the module name
+	# associated with directory path. Based on the $gcov_dir select the 
+	# particular module to load.
+	while ((my $mod_name, my $gcov_path) = each (%gcov_module_dir))
 	{
+		$module_name = $mod_name if($gcov_path eq $gcov_dir);
+
 		# Try to load module from system wide module directory
 		# /lib/modules
 		if (system_no_output(3, $modprobe_tool, $module_name) == 0)

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

#1 lore raw

Hi,

Quoted 6 lines · Tej

Sending Patches for the 64 bit Hypervisor, We have tested patches on AMD-64 (Athlon(tm) 64 X2 Dual Core Processor 4600+) machine with gcc-4.2 & gcc-3.4. Please refer the previous GCOV RFC in same mail for more info on Hypervisor profiling.
We have added support to 32bit and 64bit Kernel.

Quoted 6 lines

In addition to patches for hypervisor profiling, we did a little work on *lcov* to work with hypervisor.
README could be useful, for naive lcov user. locv-diff.patch show our change in lcov scripts.

any comments, feedback and suggestion are more than welcome

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also I do prefer to have brackets that start code blocks on a new line aligned to the previous line, but that's not followed everywhere in the code.

- Makefiles: while the num=$*.c is still a mystery to me, my question is: do you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'. Also, it would be useful to make this feature enabled with a compile-time option.

More comments to follow as I test it.

Thanks,
Gianluca

author
#2 lore raw
Quoted 17 lines · Gianluca Guida

Hi,

Quoted 7 lines · Tej

Sending Patches for the 64 bit Hypervisor, We have tested patches on AMD-64 (Athlon(tm) 64 X2 Dual Core Processor 4600+) machine with gcc-4.2 & gcc-3.4. Please refer the previous GCOV RFC in same mail for more info on Hypervisor profiling.
We have added support to 32bit and 64bit Kernel.

Quoted 6 lines

In addition to patches for hypervisor profiling, we did a little work on *lcov* to work with hypervisor.
README could be useful, for naive lcov user. locv-diff.patch show our change in lcov scripts.

any comments, feedback and suggestion are more than welcome

Quoted 7 lines

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also I do prefer to have brackets that start code blocks on a new line aligned to the previous line, but that's not followed everywhere in the code.

thanks for your comments and general feedback
Generally we uses Lindent script for tab/alignment problem... i will incorporate above said coding styles and resubmit

Quoted 3 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question is: do you really need to make links with different names to files compiled

num=$*.c changes mainly added to run lcov smoothly... Let me take an example

in hap directory Makefile generate guest_walk_%level.o and gcov option generates guest_walk_%level.gcno... but there is no guest_walk_%level.c files , so lcov script give me warning/error saying guest_walk_%level.gcno file does not have correspoding *.c.. so we have added some Makefile trick to generate *.c link at compile time.

Quoted 1 line

multiple times? If so, it would be useful to remove them on 'make clean'.

nice point
thats absolutely needed, so i will incorporated the changes

Quoted 2 lines

Also, it would be useful to make this feature enabled with a compile-time option.

i will look into this also and resubmit the patches on Monday...

Quoted 2 lines

More comments to follow as I test it.

thanks for your review and comments

Quoted 4 lines

Thanks,
Gianluca

author
#3 lore raw
In reply to Gianluca Guida
Quoted 25 lines · Gianluca Guida

Hi,

Quoted 7 lines · Tej

Sending Patches for the 64 bit Hypervisor, We have tested patches on AMD-64 (Athlon(tm) 64 X2 Dual Core Processor 4600+) machine with gcc-4.2 & gcc-3.4. Please refer the previous GCOV RFC in same mail for more info on Hypervisor profiling.
We have added support to 32bit and 64bit Kernel.

Quoted 6 lines

In addition to patches for hypervisor profiling, we did a little work on *lcov* to work with hypervisor.
README could be useful, for naive lcov user. locv-diff.patch show our change in lcov scripts.

any comments, feedback and suggestion are more than welcome

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also I do prefer to have brackets that start code blocks on a new line aligned to the previous line, but that's not followed everywhere in the code.

Quoted 5 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question is: do you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'. Also, it would be useful to make this feature enabled with a compile-time option.

Attached patches address the four-spaces tabs and make clean issues. Hope the code is more clean and readable

Quoted 6 lines

More comments to follow as I test it.

Thanks,
Gianluca

drivers/xen/Kconfig +5 -0
diff -r 51decc39e5e7 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 51decc39e5e7 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 51decc39e5e7 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 51decc39e5e7 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 +1134 -0

1,134 lines not on this page · raw message

include/asm-i386/mach-xen/asm/hypercall.h +7 -0
diff -r 51decc39e5e7 include/asm-i386/mach-xen/asm/hypercall.h
@@ -404,6 +404,13 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 
 
 #endif /* __HYPERCALL_H__ */
include/asm-x86_64/mach-xen/asm/hypercall.h +7 -0
diff -r 51decc39e5e7 include/asm-x86_64/mach-xen/asm/hypercall.h
@@ -405,4 +405,11 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 #endif /* __HYPERCALL_H__ */
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 51decc39e5e7 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 51decc39e5e7 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);
xen/Rules.mk +9 -2
diff -r a3675bed9c21 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
@@ -112,12 +117,14 @@
 
 .PHONY: clean
 clean:: $(addprefix _clean_, $(subdir-all))
-	rm -f *.o *~ core
+	rm -f *.o *.gcno *~ core
 _clean_%/: FORCE
 	$(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 +11 -1
diff -r a3675bed9c21 xen/arch/x86/mm/hap/Makefile
@@ -4,8 +4,18 @@
 obj-y += guest_walk_4level.o
 obj-y += p2m-ept.o
 
+LN = /bin/ln
+
 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)
+	
+.PHONY: clean
+clean::
+	rm -f guest_walk_*.c
xen/arch/x86/mm/shadow/Makefile +10 -1
diff -r a3675bed9c21 xen/arch/x86/mm/shadow/Makefile
@@ -1,5 +1,14 @@
 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)
+
+.PHONY: clean
+clean::
+	rm -f guest_*.c
xen/arch/x86/x86_32/entry.S +2 -0
diff -r a3675bed9c21 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/arch/x86/x86_64/entry.S +2 -0
diff -r a3675bed9c21 xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,7 @@
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+        .quad do_gcovprof_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,6 +740,7 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
+        .byte 3 /* do_gcovprof_op       */
         .byte 1 /* do_xsm_op            */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
xen/common/Makefile +3 -0
diff -r a3675bed9c21 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 +255 -0

255 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 a3675bed9c21 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

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

#5 lore raw

Hi,

Sorry for the late reply.

Quoted 22 lines · Tej
Quoted 18 lines · Tej
Quoted 9 lines · Gianluca Guida

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also
I do prefer to have brackets that start code blocks on a new line aligned to the previous line, but that's not followed everywhere in the code.

Quoted 6 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question is: do
you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'. Also, it would be useful to make this feature enabled with a compile-time option.

Quoted 2 lines

Attached patches address the four-spaces tabs and make clean issues. Hope the code is more clean and readable

Quoted 6 lines

Hi

Sorry for interrupting you guys from your busy schedule, as i just want to know the current status for GCOV patches i submitted early this month.
any feedback on "testing/coding/design/feature" will be appreciated.

I've been testing it for a while, and it seems an useful and interesting feature.

A few comments, though:

- As I said, while the patch is minimal enough, the feature requires some intrusive changes in Xen, like changing the linker script (via the definition of CONSTRUCTORS) and in general it changes the compiler behavior, so I think it should be mandatory to make this feature explicitely enabled at compile time, e.g. gcov=y.
- I am talking about Xen code only, but I think a few part of the codes should be more clear. I find very confusing the difference between xen_gcov_info and gcov_info, and all the instructions that uses them. A better naming scheme for the variables and more comments would be appreciated.

Thanks!
Gianluca

author
#6 lore raw
Quoted 36 lines · Gianluca Guida

Hi,

Sorry for the late reply.

Quoted 30 lines · Tej
Quoted 24 lines · Tej
Quoted 12 lines · Gianluca Guida

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly
aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also
I do prefer to have brackets that start code blocks on a new line aligned to
the previous line, but that's not followed everywhere in the code.

Quoted 8 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question
is: do
you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'.
Also, it would be useful to make this feature enabled with a compile-time
option.

Quoted 2 lines

Attached patches address the four-spaces tabs and make clean issues. Hope the code is more clean and readable

Hi

Quoted 7 lines
Quoted 4 lines

Sorry for interrupting you guys from your busy schedule, as i just want to know the current status for GCOV patches i submitted early this month.
any feedback on "testing/coding/design/feature" will be appreciated.

I've been testing it for a while, and it seems an useful and interesting feature.

glad to hear this

Quoted 9 lines

A few comments, though:

- As I said, while the patch is minimal enough, the feature requires some intrusive changes in Xen, like changing the linker script (via the definition of CONSTRUCTORS) and in general it changes the compiler behavior, so I think it should be mandatory to make this feature explicitely enabled at compile time, e.g.  gcov=y.

Quoted 5 lines

- I am talking about Xen code only, but I think a few part of the codes should be more clear. I find very confusing the difference between xen_gcov_info and gcov_info, and all the instructions that uses them. A better naming scheme for the variables and more comments would be appreciated.

basically there should not be no difference between xen_gcov_info and gcov_info, but due to some earlier implementation difficulties we kept
two different structure. In final implementation those difference
narrow down drastically but we kept the both structures. I will look back into this.

and All comments will be addressed asap.

thanks
-tej

Quoted 4 lines

Thanks!
Gianluca

author
#7 lore raw
In reply to Gianluca Guida
Quoted 44 lines · Gianluca Guida

Hi,

Sorry for the late reply.

Quoted 28 lines · Tej
Quoted 24 lines · Tej
Quoted 12 lines · Gianluca Guida

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly
aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also
I do prefer to have brackets that start code blocks on a new line aligned to
the previous line, but that's not followed everywhere in the code.

Quoted 8 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question
is: do
you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'.
Also, it would be useful to make this feature enabled with a compile-time
option.

Quoted 2 lines

Attached patches address the four-spaces tabs and make clean issues. Hope the code is more clean and readable

Quoted 6 lines

Hi

Sorry for interrupting you guys from your busy schedule, as i just want to know the current status for GCOV patches i submitted early this month.
any feedback on "testing/coding/design/feature" will be appreciated.

I've been testing it for a while, and it seems an useful and interesting feature.

Quoted 7 lines

A few comments, though:

- As I said, while the patch is minimal enough, the feature requires some intrusive changes in Xen, like changing the linker script (via the definition of CONSTRUCTORS) and in general it changes the compiler behavior, so I think it should be mandatory to make this feature explicitely enabled at compile time, e.g.  gcov=y.

patches attached added the compile time options gcov=y
a small readme is attached, which can be probably help in compiling correctly at first time

gcov=n (default) disable every code part added by xen-gcov-core patch (entry.S, core module, gcov constructor etc.)

Now in case, we have configured proc module (y || m) but did not use gcov=y option during compilation then proc module refuses to insert as there is no hypercall added for gcov and we return -ENOENT (insmod error type). Better suggestion are more than welcome

(i really don't know if we can make Kernel configuration and xen configuration in sync e.g gcov=y depends on Kconfig "xen-gcov-proc" or vice versa)

Quoted 5 lines

- I am talking about Xen code only, but I think a few part of the codes should be more clear. I find very confusing the difference between xen_gcov_info and gcov_info, and all the instructions that uses them. A better naming scheme for the variables and more comments would be appreciated.

this issue still we are working on it. But if we keep two structure as it is then we will have less complex core and proc implementation.

comments??????

Sorry for some delay.

Quoted 4 lines

Thanks!
Gianluca

drivers/xen/Kconfig +6 -0
diff -r 67a7ffcc5067 drivers/xen/Kconfig
@@ -287,6 +287,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
drivers/xen/Makefile +1 -0
diff -r 67a7ffcc5067 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 67a7ffcc5067 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 67a7ffcc5067 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 +1132 -0

1,132 lines not on this page · raw message

include/asm-i386/mach-xen/asm/hypercall.h +7 -0
diff -r 67a7ffcc5067 include/asm-i386/mach-xen/asm/hypercall.h
@@ -404,6 +404,13 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 
 
 #endif /* __HYPERCALL_H__ */
include/asm-x86_64/mach-xen/asm/hypercall.h +7 -0
diff -r 67a7ffcc5067 include/asm-x86_64/mach-xen/asm/hypercall.h
@@ -405,4 +405,11 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 #endif /* __HYPERCALL_H__ */
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 67a7ffcc5067 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 67a7ffcc5067 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);
xen/Rules.mk +17 -1
diff -r d89eaa22b5b9 xen/Rules.mk
@@ -8,6 +8,15 @@
 perfc_arrays  ?= n
 crash_debug   ?= n
 frame_pointer ?= n
+
+# gcov profiler build for xen hypervisor only
+gcov          ?= n
+
+# xen source path to get update in .gcno files
+ifeq ($(gcov),y)
+xen_src := $(CURDIR)
+xentree := $(if $(xen_src),$(xen_src),$(CURDIR))
+endif
 
 XEN_ROOT=$(BASEDIR)/..
 include $(XEN_ROOT)/Config.mk
@@ -56,6 +65,7 @@
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 
 CFLAGS-y                += -g -D__XEN__
+CFLAGS-$(gcov)          += -fprofile-arcs -ftest-coverage -DCONFIG_XEN_GCOV
 CFLAGS-$(XSM_ENABLE)    += -DXSM_ENABLE
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_ENABLE -DXSM_MAGIC=0xf97cff8c
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_DEVELOP -DFLASK_BOOTPARAM -DFLASK_AVC_STATS
@@ -112,12 +122,18 @@
 
 .PHONY: clean
 clean:: $(addprefix _clean_, $(subdir-all))
-	rm -f *.o *~ core
+	rm -f *.o *.gcno *~ core
 _clean_%/: FORCE
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
 
 %.o: %.c $(HDRS) Makefile
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+else
 	$(CC) $(CFLAGS) -c $< -o $@
+endif
+
 
 %.o: %.S $(AHDRS) Makefile
 	$(CC) $(AFLAGS) -c $< -o $@
xen/arch/x86/mm/hap/Makefile +14 -0
diff -r d89eaa22b5b9 xen/arch/x86/mm/hap/Makefile
@@ -4,8 +4,22 @@
 obj-y += guest_walk_4level.o
 obj-y += p2m-ept.o
 
+LN = /bin/ln
+
 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
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s guest_walk.c guest_walk_$(num)
+else
 	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c $< -o $@
+endif
+	
+.PHONY: clean
+clean::
+	rm -f guest_walk_*.c
xen/arch/x86/mm/shadow/Makefile +13 -0
diff -r d89eaa22b5b9 xen/arch/x86/mm/shadow/Makefile
@@ -1,5 +1,18 @@
 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
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s multi.c guest_$(num)
+else
 	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+endif
+
+.PHONY: clean
+clean::
+	rm -f guest_*.c
xen/arch/x86/x86_32/entry.S +6 -0
diff -r d89eaa22b5b9 xen/arch/x86/x86_32/entry.S
@@ -703,6 +703,9 @@
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+#ifdef CONFIG_XEN_GCOV
+        .long do_gcovprof_op
+#endif
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -750,6 +753,9 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+#ifdef CONFIG_XEN_GCOV
+        .byte 3 /* do_gcovprof_op	*/
+#endif
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +6 -0
diff -r d89eaa22b5b9 xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,9 @@
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+#ifdef CONFIG_XEN_GCOV
+        .quad do_gcovprof_op
+#endif
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,6 +742,9 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
+#ifdef CONFIG_XEN_GCOV
+        .byte 3 /* do_gcovprof_op       */
+#endif
         .byte 1 /* do_xsm_op            */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
xen/common/Makefile +3 -0
diff -r d89eaa22b5b9 xen/common/Makefile
@@ -28,6 +28,7 @@
 obj-y += xmalloc.o
 obj-y += rcupdate.o
 
+obj-$(gcov)        += xen-gcov-core.o
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
 obj-$(xenoprof)    += xenoprof.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 +255 -0

255 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 +18 -0
diff -r d89eaa22b5b9 xen/include/xen/config.h
@@ -96,4 +96,22 @@
 #define __cpuinitdata
 #define __cpuinit
 
+#ifdef CONFIG_XEN_GCOV
+#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 /* CONFIG_XEN_GCOV */
 #endif /* __XEN_CONFIG_H__ */

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

author
#8 lore raw
In reply to Gianluca Guida
Quoted 46 lines · Gianluca Guida

Hi,

Sorry for the late reply.

Quoted 28 lines · Tej
Quoted 24 lines · Tej
Quoted 12 lines · Gianluca Guida

While I still need to test the patch (building 3.3 right now) and to understand gcov internals, I think that a few comments can be done, mostly
aestethicals.

- xen coding style: Using four-spaces tabs is generally the tradition. Also
I do prefer to have brackets that start code blocks on a new line aligned to
the previous line, but that's not followed everywhere in the code.

Quoted 8 lines

- Makefiles: while the num=$*.c is still a mystery to me, my question
is: do
you really need to make links with different names to files compiled multiple times? If so, it would be useful to remove them on 'make clean'.
Also, it would be useful to make this feature enabled with a compile-time
option.

Quoted 2 lines

Attached patches address the four-spaces tabs and make clean issues. Hope the code is more clean and readable

Quoted 6 lines

Hi

Sorry for interrupting you guys from your busy schedule, as i just want to know the current status for GCOV patches i submitted early this month.
any feedback on "testing/coding/design/feature" will be appreciated.

I've been testing it for a while, and it seems an useful and interesting feature.

A few comments, though:

Quoted 10 lines

- As I said, while the patch is minimal enough, the feature requires some intrusive changes in Xen, like changing the linker script (via the definition of CONSTRUCTORS) and in general it changes the compiler behavior, so I think it should be mandatory to make this feature explicitely enabled at compile time, e.g.  gcov=y.
- I am talking about Xen code only, but I think a few part of the codes should be more clear. I find very confusing the difference between xen_gcov_info and gcov_info, and all the instructions that uses them. A better naming scheme for the variables and more comments would be appreciated.

Removed xen_gcov_info dependency all together. Complete implementation is based on gcc "gcov_info" struct only.
We have also included some meaningful names and comments. I hope that these changes makes code more clear/clean and readable.

I have tested code in amd-64 with gcov=y and gcov=n, all worked fine,

Are you looking for any other other specific feature to be included in this? We are missing only modules implementation of gcov which is not required for xen hypervisor.

Any further comments/suggestion are more than welcome.

thanks
-tej & team

Quoted 4 lines

Thanks!
Gianluca

drivers/xen/Kconfig +6 -0
diff -r f85259abcddf drivers/xen/Kconfig
@@ -231,6 +231,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
drivers/xen/Makefile +1 -0
diff -r f85259abcddf 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 f85259abcddf 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 f85259abcddf 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 +1235 -0

1,235 lines not on this page · raw message

include/asm-i386/mach-xen/asm/hypercall.h +7 -0
diff -r f85259abcddf include/asm-i386/mach-xen/asm/hypercall.h
@@ -411,6 +411,13 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 
 
 #endif /* __HYPERCALL_H__ */
include/asm-x86_64/mach-xen/asm/hypercall.h +7 -0
diff -r f85259abcddf include/asm-x86_64/mach-xen/asm/hypercall.h
@@ -412,4 +412,11 @@
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_gcovprof_op(
+	int cmd, void *arg, int val)
+{
+	return _hypercall3(int, gcovprof_op, cmd, arg, val);
+}
+
 #endif /* __HYPERCALL_H__ */
include/xen/interface/xen-gcov.h new file +126 -0

126 lines not on this page · raw message

include/xen/interface/xen.h +1 -0
diff -r f85259abcddf include/xen/interface/xen.h
@@ -93,6 +93,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 f85259abcddf 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);
xen/Rules.mk +17 -1
diff -r 99c6de6e02f6 xen/Rules.mk
@@ -8,6 +8,15 @@
 perfc_arrays  ?= n
 crash_debug   ?= n
 frame_pointer ?= n
+
+# gcov profiler build for xen hypervisor only
+gcov          ?= n
+
+# xen source path to get update in .gcno files
+ifeq ($(gcov),y)
+xen_src := $(CURDIR)
+xentree := $(if $(xen_src),$(xen_src),$(CURDIR))
+endif
 
 XEN_ROOT=$(BASEDIR)/..
 include $(XEN_ROOT)/Config.mk
@@ -56,6 +65,7 @@
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 
 CFLAGS-y                += -g -D__XEN__
+CFLAGS-$(gcov)          += -fprofile-arcs -ftest-coverage -DCONFIG_XEN_GCOV
 CFLAGS-$(XSM_ENABLE)    += -DXSM_ENABLE
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_ENABLE -DXSM_MAGIC=0xf97cff8c
 CFLAGS-$(FLASK_ENABLE)  += -DFLASK_DEVELOP -DFLASK_BOOTPARAM -DFLASK_AVC_STATS
@@ -112,12 +122,18 @@
 
 .PHONY: clean
 clean:: $(addprefix _clean_, $(subdir-all))
-	rm -f *.o *~ core
+	rm -f *.o *.gcno *~ core
 _clean_%/: FORCE
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
 
 %.o: %.c $(HDRS) Makefile
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+else
 	$(CC) $(CFLAGS) -c $< -o $@
+endif
+
 
 %.o: %.S $(AHDRS) Makefile
 	$(CC) $(AFLAGS) -c $< -o $@
xen/arch/x86/mm/hap/Makefile +14 -0
diff -r 99c6de6e02f6 xen/arch/x86/mm/hap/Makefile
@@ -4,8 +4,22 @@
 obj-y += guest_walk_4level.o
 obj-y += p2m-ept.o
 
+LN = /bin/ln
+
 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
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s guest_walk.c guest_walk_$(num)
+else
 	$(CC) $(CFLAGS) $(call guest_walk_defns,$(@F)) -c $< -o $@
+endif
+	
+.PHONY: clean
+clean::
+	rm -f guest_walk_*.c
xen/arch/x86/mm/shadow/Makefile +13 -0
diff -r 99c6de6e02f6 xen/arch/x86/mm/shadow/Makefile
@@ -1,5 +1,18 @@
 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
+ifeq ($(gcov),y)
+	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c -o $@ \
+		$(if $(filter-out /%,$<),$(xentree)/$<,$<)
+	$(LN) -f -s multi.c guest_$(num)
+else
 	$(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=$* -c $< -o $@
+endif
+
+.PHONY: clean
+clean::
+	rm -f guest_*.c
xen/arch/x86/x86_32/entry.S +6 -0
diff -r 99c6de6e02f6 xen/arch/x86/x86_32/entry.S
@@ -703,6 +703,9 @@
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+#ifdef CONFIG_XEN_GCOV
+        .long do_gcovprof_op
+#endif
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -750,6 +753,9 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+#ifdef CONFIG_XEN_GCOV
+        .byte 3 /* do_gcovprof_op	*/
+#endif
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +6 -0
diff -r 99c6de6e02f6 xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,9 @@
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+#ifdef CONFIG_XEN_GCOV
+        .quad do_gcovprof_op
+#endif
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,6 +742,9 @@
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
+#ifdef CONFIG_XEN_GCOV
+        .byte 3 /* do_gcovprof_op       */
+#endif
         .byte 1 /* do_xsm_op            */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
xen/common/Makefile +3 -0
diff -r 99c6de6e02f6 xen/common/Makefile
@@ -28,6 +28,7 @@
 obj-y += xmalloc.o
 obj-y += rcupdate.o
 
+obj-$(gcov)        += xen-gcov-core.o
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
 obj-$(xenoprof)    += xenoprof.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 +332 -0

332 lines not on this page · raw message

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

109 lines not on this page · raw message

xen/include/xen/config.h +18 -0
diff -r 99c6de6e02f6 xen/include/xen/config.h
@@ -96,4 +96,22 @@
 #define __cpuinitdata
 #define __cpuinit
 
+#ifdef CONFIG_XEN_GCOV
+#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 /* CONFIG_XEN_GCOV */
 #endif /* __XEN_CONFIG_H__ */

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