Skip to contentSkip to conversation

GCOV: profile by modules

RFC PATCH In review [email protected] 2 participants 3 messages May 25, 2020 – Jun 1, 2020

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

RFC PATCH v4 1/1 GCOV: profile by modules

From: Cixi Geng <[email protected]>

The CONFIG_GCOV_PROFILE_ALL will compile kernel by profiling entire kernel which will lead to kernel run slower.Use GCOV_PROFILE_PREREQS to control part of the kernel modules to open gcov.

Only add SERIAL_GCOV for an example.

---
 drivers/tty/serial/Kconfig  |  7 +++++++
 drivers/tty/serial/Makefile |  1 +
 kernel/gcov/Kconfig         | 14 ++++++++++++++
 3 files changed, 22 insertions(+)
drivers/tty/serial/Kconfig +7 -0
index adf9e80e7dc9..6df002370f18 100644
@@ -1566,3 +1566,10 @@ endmenu
 
 config SERIAL_MCTRL_GPIO
 	tristate
+
+config SERIAL_GCOV
+	bool "Enable profile gcov for serial directory"
+	depends on GCOV_PROFILE_PREREQS
+	help
+	  The SERIAL_GCOV will add Gcov profiling flags when kernel compiles.
+	  Say 'Y' here if you want the gcov data for the serial directory,
drivers/tty/serial/Makefile +1 -0
index d056ee6cca33..17272733db95 100644
@@ -3,6 +3,7 @@
 # Makefile for the kernel serial device drivers.
 #
 
+GCOV_PROFILE := $(CONFIG_SERIAL_GCOV)
 obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
kernel/gcov/Kconfig +14 -0
index 3941a9c48f83..ea8b514f5676 100644
@@ -51,6 +51,20 @@ config GCOV_PROFILE_ALL
 	larger and run slower. Also be sure to exclude files from profiling
 	which are not linked to the kernel image to prevent linker errors.
 
+config GCOV_PROFILE_PREREQS
+	bool "Profile Kernel subsytem"
+	depends on !COMPILE_TEST
+	depends on GCOV_KERNEL
+	depends on !GCOV_PROFILE_ALL
+	help
+	  This options activates profiling for the specified kernel modules.
+
+	  When some modules need Gcov data, enable this config, then configure
+	  with gcov on the corresponding modules,The directories or files of
+	  these modules will be added profiling flags after kernel compile.
+
+	  If unsure, say N.
+
 choice
 	prompt "Specify GCOV format"
 	depends on GCOV_KERNEL
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · On 25.05.2020 12:00, [email protected] wrote:

From: Cixi Geng <[email protected]>

The CONFIG_GCOV_PROFILE_ALL will compile kernel by profiling entire kernel which will lead to kernel run slower.Use GCOV_PROFILE_PREREQS to control part of the kernel modules to open gcov.

Maybe rephrase the commit message to make the intention more obvious:

Introduce new configuration option GCOV_PROFILE_PREREQS that can be used to check whether the prerequisites for enabling gcov profiling for specific files and directories are met.

Quoted 48 lines

Only add SERIAL_GCOV for an example.

---
 drivers/tty/serial/Kconfig  |  7 +++++++
 drivers/tty/serial/Makefile |  1 +
 kernel/gcov/Kconfig         | 14 ++++++++++++++
 3 files changed, 22 insertions(+)
drivers/tty/serial/Kconfig +7 -0
index adf9e80e7dc9..6df002370f18 100644
@@ -1566,3 +1566,10 @@ endmenu
 
 config SERIAL_MCTRL_GPIO
 	tristate
+
+config SERIAL_GCOV
+	bool "Enable profile gcov for serial directory"
+	depends on GCOV_PROFILE_PREREQS
+	help
+	  The SERIAL_GCOV will add Gcov profiling flags when kernel compiles.
+	  Say 'Y' here if you want the gcov data for the serial directory,
drivers/tty/serial/Makefile +1 -0
index d056ee6cca33..17272733db95 100644
@@ -3,6 +3,7 @@
 # Makefile for the kernel serial device drivers.
 #
 
+GCOV_PROFILE := $(CONFIG_SERIAL_GCOV)
 obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
kernel/gcov/Kconfig +3 -0
index 3941a9c48f83..ea8b514f5676 100644
@@ -51,6 +51,20 @@ config GCOV_PROFILE_ALL
 	larger and run slower. Also be sure to exclude files from profiling
 	which are not linked to the kernel image to prevent linker errors.
 
+config GCOV_PROFILE_PREREQS
+	bool "Profile Kernel subsytem"
+	depends on !COMPILE_TEST

kernel/gcov/Kconfig config GCOV_PROFILE_ALL · line 66

Quoted 10 lines
kernel/gcov/Kconfig +10 -0
+	depends on GCOV_KERNEL
+	depends on !GCOV_PROFILE_ALL
+	help
+	  This options activates profiling for the specified kernel modules.
+
+	  When some modules need Gcov data, enable this config, then configure
+	  with gcov on the corresponding modules,The directories or files of
+	  these modules will be added profiling flags after kernel compile.
+
+	  If unsure, say N.

This is not quite what I had in mind. A user still needs to manually select GCOV_PROFILE, then GCOV_PROFILE_PREREQS, then SERIAL_GCOV.

My though was that you could provide an automatic config option that is invisible in the configuration dialog, and that is automatically selected when all prereqs for enabling GCOV in a module directory are met.

Something like the following:

config GCOV_PROFILE_PREREQS

        bool
        default y if GCOV_KERNEL && !COMPILE_TEST
        default n

There's no need to add GCOV_KERNEL_ALL here since that is about a user choice ("I want all code compiled with profiling") vs. this new symbol which is about an ability ("all prereqs for enabling profiling in specific directories are met).

Quoted 5 lines
kernel/gcov/Kconfig +1 -0
+
 choice
 	prompt "Specify GCOV format"
 	depends on GCOV_KERNEL
Signature · 2 lines
Peter Oberparleiter
Linux on Z Development - IBM Germany
author
#2 lore raw
Quoted 83 lines · Peter Oberparleiter <[email protected]> 于2020年5月28日周四 下午10:47写道:
Quoted 5 lines · On 25.05.2020 12:00, [email protected] wrote:

From: Cixi Geng <[email protected]>

The CONFIG_GCOV_PROFILE_ALL will compile kernel by profiling entire kernel which will lead to kernel run slower.Use GCOV_PROFILE_PREREQS to control part of the kernel modules to open gcov.

Maybe rephrase the commit message to make the intention more obvious:

Introduce new configuration option GCOV_PROFILE_PREREQS that can be used to check whether the prerequisites for enabling gcov profiling for specific files and directories are met.

Quoted 48 lines

Only add SERIAL_GCOV for an example.

---
 drivers/tty/serial/Kconfig  |  7 +++++++
 drivers/tty/serial/Makefile |  1 +
 kernel/gcov/Kconfig         | 14 ++++++++++++++
 3 files changed, 22 insertions(+)
drivers/tty/serial/Kconfig +7 -0
index adf9e80e7dc9..6df002370f18 100644
@@ -1566,3 +1566,10 @@ endmenu
 
 config SERIAL_MCTRL_GPIO
      tristate
+
+config SERIAL_GCOV
+     bool "Enable profile gcov for serial directory"
+     depends on GCOV_PROFILE_PREREQS
+     help
+       The SERIAL_GCOV will add Gcov profiling flags when kernel compiles.
+       Say 'Y' here if you want the gcov data for the serial directory,
drivers/tty/serial/Makefile +1 -0
index d056ee6cca33..17272733db95 100644
@@ -3,6 +3,7 @@
 # Makefile for the kernel serial device drivers.
 #
 
+GCOV_PROFILE := $(CONFIG_SERIAL_GCOV)
 obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
kernel/gcov/Kconfig +3 -0
index 3941a9c48f83..ea8b514f5676 100644
@@ -51,6 +51,20 @@ config GCOV_PROFILE_ALL
      larger and run slower. Also be sure to exclude files from profiling
      which are not linked to the kernel image to prevent linker errors.
 
+config GCOV_PROFILE_PREREQS
+     bool "Profile Kernel subsytem"
+     depends on !COMPILE_TEST

kernel/gcov/Kconfig config GCOV_PROFILE_ALL · line 66

Quoted 10 lines
kernel/gcov/Kconfig +10 -0
+     depends on GCOV_KERNEL
+     depends on !GCOV_PROFILE_ALL
+     help
+       This options activates profiling for the specified kernel modules.
+
+       When some modules need Gcov data, enable this config, then configure
+       with gcov on the corresponding modules,The directories or files of
+       these modules will be added profiling flags after kernel compile.
+
+       If unsure, say N.

This is not quite what I had in mind. A user still needs to manually select GCOV_PROFILE, then GCOV_PROFILE_PREREQS, then SERIAL_GCOV.

My though was that you could provide an automatic config option that is invisible in the configuration dialog, and that is automatically selected when all prereqs for enabling GCOV in a module directory are met.

Something like the following:

config GCOV_PROFILE_PREREQS

Quoted 9 lines
        bool
        default y if GCOV_KERNEL && !COMPILE_TEST
        default n

There's no need to add GCOV_KERNEL_ALL here since that is about a user choice ("I want all code compiled with profiling") vs. this new symbol which is about an ability ("all prereqs for enabling profiling in specific directories are met).

As far as I'm concerned, The GCOV_KERNEL_ALL will conflict with GCOV_PROFILE_PREREQS,since the GCOV_KERNEL_ALL will profing all code which contain the new config.

Quoted 11 lines

kernel/gcov/Kconfig config GCOV_PROFILE_ALL · line 70

Quoted 6 lines
kernel/gcov/Kconfig +1 -0
+
 choice
      prompt "Specify GCOV format"
      depends on GCOV_KERNEL

--
Peter Oberparleiter
Linux on Z Development - IBM Germany