Skip to contentSkip to conversation

gcov: add gcov profiling infrastructure

PATCH In review Peter Oberparleiter 1 participant 1 message Jun 2, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 4/6 gcov: add gcov profiling infrastructure

From: Peter Oberparleiter <[email protected]>

gcov profiling infrastructure:

* change kbuild to include profiling flags
* provide functions needed by profiling code
* present profiling data as files in debugfs

---
 Documentation/gcov.txt              |  136 +++++++
 Documentation/kernel-parameters.txt |    7 
 Makefile                            |   10 
 arch/Kconfig                        |    2 
 init/main.c                         |    8 
 kernel/Makefile                     |    1 
 kernel/gcov/Kconfig                 |   45 ++
 kernel/gcov/Makefile                |    1 
 kernel/gcov/base.c                  |  145 +++++++
 kernel/gcov/fs.c                    |  501 ++++++++++++++++++++++++++
 kernel/gcov/gcc_3_4.c               |  413 +++++++++++++++++++++
 kernel/gcov/gcov.h                  |  119 ++++++
 scripts/Makefile.lib                |    8 
 13 files changed, 1392 insertions(+), 4 deletions(-)
Makefile +6 -4
Index: linux-2.6.26-rc4/Makefile
===================================================================
@@ -320,6 +320,7 @@ AFLAGS_MODULE   = $(MODFLAGS)
 LDFLAGS_MODULE  =
 CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
+CFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
 
 
 # Use LINUXINCLUDE when you must reference the include/ directory.
@@ -345,7 +346,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP M
 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
 
 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 
 # When compiling out-of-tree modules, put MODVERDIR in the module
@@ -1133,7 +1134,8 @@ clean: archclean $(clean-dirs)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-		-o -name '*.symtypes' -o -name 'modules.order' \) \
+		-o -name '*.symtypes' -o -name 'modules.order' \
+		-o -name '*.gcno' \) \
 		-type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
@@ -1337,8 +1339,8 @@ clean: $(clean-dirs)
 	$(call cmd,rmfiles)
 	@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-		-type f -print | xargs rm -f
+		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
+		-o -name '*.gcno' \) -type f -print | xargs rm -f
 
 help:
 	@echo  '  Building external modules.'
scripts/Makefile.lib +8 -0
Index: linux-2.6.26-rc4/scripts/Makefile.lib
===================================================================
@@ -100,6 +100,14 @@ _c_flags       = $(KBUILD_CFLAGS) $(ccfl
 _a_flags       = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
 
+# Enable profiling flags for a file, directory or for all files depending on
+# variables GCOV_obj.o, GCOV and CONFIG_GCOV_PROFILE_ALL (in this order)
+ifeq ($(CONFIG_GCOV_PROFILE),y)
+_c_flags += $(if $(patsubst n%,, \
+		$(GCOV_$(basetarget).o)$(GCOV)$(CONFIG_GCOV_PROFILE_ALL)), \
+		$(CFLAGS_GCOV))
+endif
+
 # If building the kernel in a separate objtree expand all occurrences
 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
 
kernel/gcov/Kconfig new file +45 -0

45 lines not on this page · raw message

kernel/gcov/base.c new file +145 -0

145 lines not on this page · raw message

kernel/gcov/gcov.h new file +119 -0

119 lines not on this page · raw message

kernel/Makefile +1 -0
Index: linux-2.6.26-rc4/kernel/Makefile
===================================================================
@@ -69,6 +69,7 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayac
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
 obj-$(CONFIG_MARKERS) += marker.o
 obj-$(CONFIG_LATENCYTOP) += latencytop.o
+obj-$(CONFIG_GCOV_PROFILE) += gcov/
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/gcov/Makefile new file +1 -0
Index: linux-2.6.26-rc4/kernel/gcov/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-$(CONFIG_GCOV_PROFILE) := base.o fs.o gcc_3_4.o
kernel/gcov/fs.c new file +501 -0

501 lines not on this page · raw message

kernel/gcov/gcc_3_4.c new file +413 -0

413 lines not on this page · raw message

init/main.c +8 -0
Index: linux-2.6.26-rc4/init/main.c
===================================================================
@@ -80,6 +80,14 @@
 #warning gcc-4.1.0 is known to miscompile the kernel.  A different compiler version is recommended.
 #endif
 
+#ifdef CONFIG_GCOV_PROFILE
+
+#if GCC_VERSION_LOWER(3, 4)
+#error "GCOV profiling support for gcc versions below 3.4 not included"
+#endif /* GCC_VERSION_LOWER */
+
+#endif /* CONFIG_GCOV_PROFILE */
+
 static int kernel_init(void *);
 
 extern void init_IRQ(void);
Documentation/kernel-parameters.txt +7 -0
Index: linux-2.6.26-rc4/Documentation/kernel-parameters.txt
===================================================================
@@ -42,6 +42,7 @@ parameter is applicable:
 	EFI	EFI Partitioning (GPT) is enabled
 	EIDE	EIDE/ATAPI support is enabled.
 	FB	The frame buffer device is enabled.
+	GCOV	GCOV profiling is enabled.
 	HW	Appropriate hardware is enabled.
 	IA-64	IA-64 architecture is enabled.
 	IOSCHED	More than one I/O scheduler is enabled.
@@ -704,6 +705,12 @@ and is between 256 and 4096 characters. 
 			Format: off | on
 			default: on
 
+	gcov_persist=	[GCOV] When non-zero (default), profiling data for
+			kernel modules is saved and remains accessible via
+			debugfs, even when the module is unloaded/reloaded.
+			When zero, profiling data is discarded and associated
+			debugfs files are removed at module unload time.
+
 	gdth=		[HW,SCSI]
 			See header of drivers/scsi/gdth.c.
 
Documentation/gcov.txt new file +136 -0

136 lines not on this page · raw message

arch/Kconfig +2 -0
Index: linux-2.6.26-rc4/arch/Kconfig
===================================================================
@@ -39,3 +39,5 @@ config HAVE_KRETPROBES
 
 config HAVE_DMA_ATTRS
 	def_bool n
+
+source "kernel/gcov/Kconfig"