Skip to contentSkip to conversation

tracing: Move trace_printk.h out of kernel.h

PATCH In review Steven Rostedt 9 participants 20 messages Jun 21 – Jul 1

Subsystems (20)
DRM drivers Documentation KVM USB +16 more subsystems
lore
Share & tools
lore
#0 lore raw

cover tracing: Move trace_printk.h out of kernel.h

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Instead, add a CONFIG_TRACE_PRINTK_DEBUGGING option that developers that do use it can set and not have to always remember to add #include <linux/trace_printk.h> to the files they add trace_printk() while debugging. It also means that those that do not have that config set will not have to worry about wasted CPU cycles as it is only include in the CFLAGS when the option is set, and its completely ignored otherwise.

Steven Rostedt (2):
tracing: Move non-trace_printk prototypes back to kernel.h
tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

----

 .../driver_development_debugging_guide.rst         |  2 +-
 Makefile                                           |  5 +++++
 arch/powerpc/kvm/book3s_xics.c                     |  1 +
 drivers/gpu/drm/i915/gt/intel_gtt.h                |  1 +
 drivers/gpu/drm/i915/i915_gem.h                    |  1 +
 drivers/hwtracing/stm/dummy_stm.c                  |  4 ++++
 drivers/infiniband/hw/hfi1/trace_dbg.h             |  1 +
 drivers/usb/early/xhci-dbc.c                       |  1 +
 fs/ext4/inline.c                                   |  1 +
 include/linux/kernel.h                             | 19 ++++++++++++++++++-
 include/linux/sunrpc/debug.h                       |  1 +
 include/linux/trace_printk.h                       | 22 +++-------------------
 kernel/trace/Kconfig                               | 10 ++++++++++
 kernel/trace/ring_buffer_benchmark.c               |  1 +
 kernel/trace/trace.h                               |  1 +
 samples/fprobe/fprobe_example.c                    |  1 +
 samples/ftrace/ftrace-direct-modify.c              |  1 +
 samples/ftrace/ftrace-direct-multi-modify.c        |  1 +
 samples/ftrace/ftrace-direct-multi.c               |  2 +-
 samples/ftrace/ftrace-direct-too.c                 |  2 +-
 samples/ftrace/ftrace-direct.c                     |  2 +-
 21 files changed, 56 insertions(+), 24 deletions(-)
#1 lore raw

PATCH 1/2 tracing: Move non-trace_printk prototypes back to kernel.h

From: Steven Rostedt <[email protected]>

In order to remove the include to trace_printk.h from kernel.h the tracing control prototypes need to be moved back into kernel.h. That's because they are used in other common header files like rcu.h. There's no point in removing trace_printk.h from kernel.h if it just gets added back to other common headers.

Prototypes are very cheap for the compiler and should not be an issue.

---
 include/linux/kernel.h       | 18 ++++++++++++++++++
 include/linux/trace_printk.h | 17 -----------------
 2 files changed, 18 insertions(+), 17 deletions(-)
include/linux/kernel.h +18 -0
index e5570a16cbb1..c3c68128827c 100644
@@ -194,4 +194,22 @@ extern enum system_states system_state;
 # define REBUILD_DUE_TO_DYNAMIC_FTRACE
 #endif
 
+#ifdef CONFIG_TRACING
+void tracing_on(void);
+void tracing_off(void);
+int tracing_is_on(void);
+void tracing_snapshot(void);
+void tracing_snapshot_alloc(void);
+void tracing_start(void);
+void tracing_stop(void);
+#else
+static inline void tracing_start(void) { }
+static inline void tracing_stop(void) { }
+static inline void tracing_on(void) { }
+static inline void tracing_off(void) { }
+static inline int tracing_is_on(void) { return 0; }
+static inline void tracing_snapshot(void) { }
+static inline void tracing_snapshot_alloc(void) { }
+#endif
+
 #endif
include/linux/trace_printk.h +0 -17
index 3d54f440dccf..879fed0805fd 100644
@@ -35,15 +35,6 @@ enum ftrace_dump_mode {
 };
 
 #ifdef CONFIG_TRACING
-void tracing_on(void);
-void tracing_off(void);
-int tracing_is_on(void);
-void tracing_snapshot(void);
-void tracing_snapshot_alloc(void);
-
-extern void tracing_start(void);
-extern void tracing_stop(void);
-
 static inline __printf(1, 2)
 void ____trace_printk_check_format(const char *fmt, ...)
 {
@@ -176,16 +167,8 @@ __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
 
 extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
 #else
-static inline void tracing_start(void) { }
-static inline void tracing_stop(void) { }
 static inline void trace_dump_stack(int skip) { }
 
-static inline void tracing_on(void) { }
-static inline void tracing_off(void) { }
-static inline int tracing_is_on(void) { return 0; }
-static inline void tracing_snapshot(void) { }
-static inline void tracing_snapshot_alloc(void) { }
-
 static inline __printf(1, 2)
 int trace_printk(const char *fmt, ...)
 {
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/2] tracing: Move non-trace_printk prototypes back to kernel.h

Quoted 4 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

In order to remove the include to trace_printk.h from kernel.h the tracing control prototypes need to be moved back into kernel.h. That's because

Please don't. Instead, you can split them out to trace_control.h, and include where needed. I actually have a prototype for it, FYI:

https://github.com/norov/linux/tree/trace_pritk3

Quoted 5 lines

they are used in other common header files like rcu.h. There's no point in removing trace_printk.h from kernel.h if it just gets added back to other common headers.

Prototypes are very cheap for the compiler and should not be an issue.

It's not about cost, it's about mess. kernel.h is included everywhere. Is that API needed everywhere? No, it's needed in literally 10 files. So, no place in kernel.h.

Quoted 73 lines
---
 include/linux/kernel.h       | 18 ++++++++++++++++++
 include/linux/trace_printk.h | 17 -----------------
 2 files changed, 18 insertions(+), 17 deletions(-)
include/linux/kernel.h +18 -0
index e5570a16cbb1..c3c68128827c 100644
@@ -194,4 +194,22 @@ extern enum system_states system_state;
 # define REBUILD_DUE_TO_DYNAMIC_FTRACE
 #endif
 
+#ifdef CONFIG_TRACING
+void tracing_on(void);
+void tracing_off(void);
+int tracing_is_on(void);
+void tracing_snapshot(void);
+void tracing_snapshot_alloc(void);
+void tracing_start(void);
+void tracing_stop(void);
+#else
+static inline void tracing_start(void) { }
+static inline void tracing_stop(void) { }
+static inline void tracing_on(void) { }
+static inline void tracing_off(void) { }
+static inline int tracing_is_on(void) { return 0; }
+static inline void tracing_snapshot(void) { }
+static inline void tracing_snapshot_alloc(void) { }
+#endif
+
 #endif
include/linux/trace_printk.h +0 -17
index 3d54f440dccf..879fed0805fd 100644
@@ -35,15 +35,6 @@ enum ftrace_dump_mode {
 };
 
 #ifdef CONFIG_TRACING
-void tracing_on(void);
-void tracing_off(void);
-int tracing_is_on(void);
-void tracing_snapshot(void);
-void tracing_snapshot_alloc(void);
-
-extern void tracing_start(void);
-extern void tracing_stop(void);
-
 static inline __printf(1, 2)
 void ____trace_printk_check_format(const char *fmt, ...)
 {
@@ -176,16 +167,8 @@ __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
 
 extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
 #else
-static inline void tracing_start(void) { }
-static inline void tracing_stop(void) { }
 static inline void trace_dump_stack(int skip) { }
 
-static inline void tracing_on(void) { }
-static inline void tracing_off(void) { }
-static inline int tracing_is_on(void) { return 0; }
-static inline void tracing_snapshot(void) { }
-static inline void tracing_snapshot_alloc(void) { }
-
 static inline __printf(1, 2)
 int trace_printk(const char *fmt, ...)
 {
Signature · 1 line
2.53.0
maintainer
#3 lore raw

Re: [PATCH 1/2] tracing: Move non-trace_printk prototypes back to kernel.h

Quoted 11 lines · Yury Norov
Quoted 4 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

In order to remove the include to trace_printk.h from kernel.h the tracing control prototypes need to be moved back into kernel.h. That's because

Please don't. Instead, you can split them out to trace_control.h, and include where needed. I actually have a prototype for it, FYI:

https://github.com/norov/linux/tree/trace_pritk3

Sure, I have no problem adding another header for this.

Quoted 10 lines
Quoted 5 lines

they are used in other common header files like rcu.h. There's no point in removing trace_printk.h from kernel.h if it just gets added back to other common headers.

Prototypes are very cheap for the compiler and should not be an issue.

It's not about cost, it's about mess. kernel.h is included everywhere. Is that API needed everywhere? No, it's needed in literally 10 files. So, no place in kernel.h.

Well one of those files is rcu.h which is also pretty much included everywhere. But OK.

-- Steve

Quoted 3 lines
Quoted 3 lines

2.53.0

#4 lore raw

PATCH 2/2 tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

---
 .../debugging/driver_development_debugging_guide.rst   |  2 +-
 Makefile                                               |  5 +++++
 arch/powerpc/kvm/book3s_xics.c                         |  1 +
 drivers/gpu/drm/i915/gt/intel_gtt.h                    |  1 +
 drivers/gpu/drm/i915/i915_gem.h                        |  1 +
 drivers/hwtracing/stm/dummy_stm.c                      |  4 ++++
 drivers/infiniband/hw/hfi1/trace_dbg.h                 |  1 +
 drivers/usb/early/xhci-dbc.c                           |  1 +
 fs/ext4/inline.c                                       |  1 +
 include/linux/kernel.h                                 |  1 -
 include/linux/sunrpc/debug.h                           |  1 +
 include/linux/trace_printk.h                           |  5 +++--
 kernel/trace/Kconfig                                   | 10 ++++++++++
 kernel/trace/ring_buffer_benchmark.c                   |  1 +
 kernel/trace/trace.h                                   |  1 +
 samples/fprobe/fprobe_example.c                        |  1 +
 samples/ftrace/ftrace-direct-modify.c                  |  1 +
 samples/ftrace/ftrace-direct-multi-modify.c            |  1 +
 samples/ftrace/ftrace-direct-multi.c                   |  2 +-
 samples/ftrace/ftrace-direct-too.c                     |  2 +-
 samples/ftrace/ftrace-direct.c                         |  2 +-
 21 files changed, 38 insertions(+), 7 deletions(-)
Documentation/process/debugging/driver_development_debugging_guide.rst +1 -1
index aca08f457793..3c87aa03622f 100644
@@ -52,7 +52,7 @@ For the full documentation see :doc:`/core-api/printk-basics`
 Trace_printk
 ~~~~~~~~~~~~
 
-Prerequisite: ``CONFIG_DYNAMIC_FTRACE`` & ``#include <linux/ftrace.h>``
+Prerequisite: ``CONFIG_TRACE_PRINTK_DEBUGGING``
 
 It is a tiny bit less comfortable to use than printk(), because you will have
 to read the messages from the trace file (See: :ref:`read_ftrace_log`
Makefile +5 -0
index d1c595db55c9..2f5923d5393b 100644
@@ -840,6 +840,11 @@ ifdef CONFIG_FUNCTION_TRACER
   CC_FLAGS_FTRACE := -pg
 endif
 
+ifdef CONFIG_TRACE_PRINTK_DEBUGGING
+  # Allow trace_printk() to be used anywhere without including the header.
+  LINUXINCLUDE += -include $(srctree)/include/linux/trace_printk.h
+endif
+
 ifdef CONFIG_TRACEPOINTS
 # To check for unused tracepoints (tracepoints that are defined but never
 # called), run with:
arch/powerpc/kvm/book3s_xics.c +1 -0
index 74a44fa702b0..ef5eb596a56e 100644
@@ -26,6 +26,7 @@
 #if 1
 #define XICS_DBG(fmt...) do { } while (0)
 #else
+#include <linux/trace_printk.h>
 #define XICS_DBG(fmt...) trace_printk(fmt)
 #endif
 
drivers/gpu/drm/i915/gt/intel_gtt.h +1 -0
index b54ee4f25af1..f6f223090760 100644
@@ -35,6 +35,7 @@
 #define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
 
 #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GTT)
+#include <linux/trace_printk.h>
 #define GTT_TRACE(...) trace_printk(__VA_ARGS__)
 #else
 #define GTT_TRACE(...)
drivers/gpu/drm/i915/i915_gem.h +1 -0
index 20b3cb29cfff..5cab1836dc1d 100644
@@ -116,6 +116,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
+#include <linux/trace_printk.h>
 #define GEM_TRACE(...) trace_printk(__VA_ARGS__)
 #define GEM_TRACE_ERR(...) do {						\
 	pr_err(__VA_ARGS__);						\
drivers/hwtracing/stm/dummy_stm.c +4 -0
index 38528ffdc0b3..784f9af7ccba 100644
@@ -14,6 +14,10 @@
 #include <linux/stm.h>
 #include <uapi/linux/stm.h>
 
+#ifdef DEBUG
+#include <linux/trace_printk.h>
+#endif
+
 static ssize_t notrace
 dummy_stm_packet(struct stm_data *stm_data, unsigned int master,
 		 unsigned int channel, unsigned int packet, unsigned int flags,
drivers/infiniband/hw/hfi1/trace_dbg.h +1 -0
index 58304b91380f..30df5e246586 100644
@@ -103,6 +103,7 @@ __hfi1_trace_def(IOCTL);
  */
 
 #ifdef HFI1_EARLY_DBG
+#include <linux/trace_printk.h>
 #define hfi1_dbg_early(fmt, ...) \
 	trace_printk(fmt, ##__VA_ARGS__)
 #else
drivers/usb/early/xhci-dbc.c +1 -0
index 41118bba9197..955c73bd601f 100644
@@ -30,6 +30,7 @@ static struct xdbc_state xdbc;
 static bool early_console_keep;
 
 #ifdef XDBC_TRACE
+#include <linux/trace_printk.h>
 #define	xdbc_trace	trace_printk
 #else
 static inline void xdbc_trace(const char *fmt, ...) { }
fs/ext4/inline.c +1 -0
index 8045e4ff270c..0eff4a0c6a6c 100644
@@ -934,6 +934,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
 }
 
 #ifdef INLINE_DIR_DEBUG
+#include <linux/trace_printk.h>
 void ext4_show_inline_dir(struct inode *dir, struct buffer_head *bh,
 			  void *inline_start, int inline_size)
 {
include/linux/kernel.h +0 -1
index c3c68128827c..538655385089 100644
@@ -31,7 +31,6 @@
 #include <linux/build_bug.h>
 #include <linux/sprintf.h>
 #include <linux/static_call_types.h>
-#include <linux/trace_printk.h>
 #include <linux/util_macros.h>
 #include <linux/wordpart.h>
 
include/linux/sunrpc/debug.h +1 -0
index ab61bed2f7af..7524f5d82fba 100644
@@ -29,6 +29,7 @@ extern unsigned int		nlm_debug;
 # define ifdebug(fac)		if (unlikely(rpc_debug & RPCDBG_##fac))
 
 # if IS_ENABLED(CONFIG_SUNRPC_DEBUG_TRACE)
+#  include <linux/trace_printk.h>
 #  define __sunrpc_printk(fmt, ...)	trace_printk(fmt, ##__VA_ARGS__)
 # else
 #  define __sunrpc_printk(fmt, ...)	printk(KERN_DEFAULT fmt, ##__VA_ARGS__)
include/linux/trace_printk.h +3 -2
index 879fed0805fd..66edec6d5dbf 100644
@@ -1,11 +1,12 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _LINUX_TRACE_PRINTK_H
 #define _LINUX_TRACE_PRINTK_H
+#if !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) && !defined(BUILD_VDSO)
 
-#include <linux/compiler_attributes.h>
 #include <linux/instruction_pointer.h>
 #include <linux/stddef.h>
 #include <linux/stringify.h>
+#include <linux/stdarg.h>
 
 /*
  * General tracing related utility functions - trace_printk(),
@@ -181,5 +182,5 @@ ftrace_vprintk(const char *fmt, va_list ap)
 }
 static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 #endif /* CONFIG_TRACING */
-
+#endif /* !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) */
 #endif
kernel/trace/Kconfig +10 -0
index 084f34dc6c9f..ffbd1b0ce66e 100644
@@ -210,6 +210,16 @@ menuconfig FTRACE
 
 if FTRACE
 
+config TRACE_PRINTK_DEBUGGING
+	bool "Debug with trace_printk()"
+	help
+	  If you need to debug with trace_printk(), instead of adding
+	  include <linux/trace_printk.h> to every file you add a trace_printk
+	  to, select this option and it will add trace_printk.h to all code
+	  to allow tracing with trace_printk() with.
+
+	  If in doubt, select N
+
 config TRACEFS_AUTOMOUNT_DEPRECATED
 	bool "Automount tracefs on debugfs [DEPRECATED]"
 	depends on TRACING
kernel/trace/ring_buffer_benchmark.c +1 -0
index 593e3b59e42e..2bb25caebb75 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2009 Steven Rostedt <[email protected]>
  */
 #include <linux/ring_buffer.h>
+#include <linux/trace_printk.h>
 #include <linux/completion.h>
 #include <linux/kthread.h>
 #include <uapi/linux/sched/types.h>
kernel/trace/trace.h +1 -0
index 80fe152af1dd..580a3deab1e9 100644
@@ -13,6 +13,7 @@
 #include <linux/ftrace.h>
 #include <linux/trace.h>
 #include <linux/hw_breakpoint.h>
+#include <linux/trace_printk.h>
 #include <linux/trace_seq.h>
 #include <linux/trace_events.h>
 #include <linux/compiler.h>
samples/fprobe/fprobe_example.c +1 -0
index bfe98ce826f3..de81b9b4ca7d 100644
@@ -12,6 +12,7 @@
 
 #define pr_fmt(fmt) "%s: " fmt, __func__
 
+#include <linux/trace_printk.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/fprobe.h>
samples/ftrace/ftrace-direct-modify.c +1 -0
index 1ba1927b548e..30d0f8e644c8 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/ftrace.h>
samples/ftrace/ftrace-direct-multi-modify.c +1 -0
index 7a7822dfeb50..f64b929e19ec 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/ftrace.h>
samples/ftrace/ftrace-direct-multi.c +1 -1
index 3fe6ddaf0b69..d32644a49554 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
 #include <linux/module.h>
-
 #include <linux/mm.h> /* for handle_mm_fault() */
 #include <linux/ftrace.h>
 #include <linux/sched/stat.h>
samples/ftrace/ftrace-direct-too.c +1 -1
index bf2411aa6fd7..266fcb233301 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
 #include <linux/module.h>
-
 #include <linux/mm.h> /* for handle_mm_fault() */
 #include <linux/ftrace.h>
 #if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
samples/ftrace/ftrace-direct.c +1 -1
index 5368c8c39cbb..85e0dff9b691 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/trace_printk.h>
 #include <linux/module.h>
-
 #include <linux/sched.h> /* for wake_up_process() */
 #include <linux/ftrace.h>
 #if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
Signature · 1 line
2.53.0
maintainer
#5 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

Quoted 6 lines · On Sun, 21 Jun 2026 05:34:32 -0400 Steven Rostedt <[email protected]> wrote:

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

Bah, I only tested with the config option enabled, and missed some dependencies with it disabled.

For instance, rcu.h also uses ftrace_dump() so that too needs to go into kernel.h. I also need to add a few more includes to trace_printk.h.

OK, I need to run this through all my tests to find where else I missed adding the includes. But the idea should hopefully satisfy everyone.

-- Steve

#6 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

Quoted 10 lines · Steven Rostedt
Quoted 6 lines · On Sun, 21 Jun 2026 05:34:32 -0400 Steven Rostedt <[email protected]> wrote:

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

Quoted 2 lines

Bah, I only tested with the config option enabled, and missed some dependencies with it disabled.

Yes you did.

Quoted 2 lines

For instance, rcu.h also uses ftrace_dump() so that too needs to go into kernel.h.

No, it shouldn't.

Quoted 4 lines

I also need to add a few more includes to trace_printk.h.

OK, I need to run this through all my tests to find where else I missed adding the includes. But the idea should hopefully satisfy everyone.

If you include it under config in kernel.h, to make the kernel buildable, you need to include trace_printk.h explicitly where it's actually used. IOW, apply my patch v4-7.

Then, developers who use trace_printk() on their development machine, will be really frustrated when their debugging code will break client build just because CONFIG_TRACE_PRINTK_DEBUGGING is disabled there. They will spend a day, at best, communicating with remote managers, and end up with adding #include <linux/trace_printk.h> in the files they touch. Is that your plan?

If I was one of those developers, the solution would be simple for me:
don't use trace_printk() at all.

Thanks,
Yury

#7 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

Quoted 19 lines · Yury Norov
Quoted 10 lines · Steven Rostedt
Quoted 6 lines · On Sun, 21 Jun 2026 05:34:32 -0400 Steven Rostedt <[email protected]> wrote:

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

Quoted 2 lines

Bah, I only tested with the config option enabled, and missed some dependencies with it disabled.

Yes you did.

Quoted 2 lines

For instance, rcu.h also uses ftrace_dump() so that too needs to go into kernel.h.

Quoted 8 lines

No, it shouldn't.

Quoted 4 lines

I also need to add a few more includes to trace_printk.h.

OK, I need to run this through all my tests to find where else I missed adding the includes. But the idea should hopefully satisfy everyone.

If you include it under config in kernel.h, to make the kernel buildable,

I mean: in kernel.h or in Makefile.

Quoted 15 lines

you need to include trace_printk.h explicitly where it's actually used. IOW, apply my patch v4-7.

Then, developers who use trace_printk() on their development machine, will be really frustrated when their debugging code will break client build just because CONFIG_TRACE_PRINTK_DEBUGGING is disabled there. They will spend a day, at best, communicating with remote managers, and end up with adding #include <linux/trace_printk.h> in the files they touch. Is that your plan?

If I was one of those developers, the solution would be simple for me:
don't use trace_printk() at all.

Thanks,
Yury

#8 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

In reply to Steven Rostedt
Quoted 6 lines · Steven Rostedt

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

IOW, you make it worse just because.

With the header being separate I add the three trace_printk()s and the include to the source file I'm investigating. The recompile will build exactly this source file.

Having to enable the config knob will result in a full kernel rebuild for no value.

Seriously?

Thanks,

tglx

maintainer
#9 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

Quoted 10 lines · Thomas Gleixner
Quoted 6 lines · Steven Rostedt

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

IOW, you make it worse just because.

Quoted 8 lines

With the header being separate I add the three trace_printk()s and the include to the source file I'm investigating. The recompile will build exactly this source file.

Having to enable the config knob will result in a full kernel rebuild for no value.

Seriously?

Like having lockdep enabled, this would always be set in the development environment. It's not something to only enable when you need to add a trace_printk. If you don't want to rebuild everything, by all means add the include file by file. There's nothing preventing you to do that with this solution.

-- Steve

P.S. I'm replying on my phone as I'm in the London Tube. Thus why I'm not trimming my email.

Quoted 5 lines

Thanks,

tglx

#10 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

In reply to Thomas Gleixner
Quoted 8 lines · On Sun, 21 Jun 2026 12:13:00 +0200 Thomas Gleixner <[email protected]> wrote:
Quoted 6 lines · Steven Rostedt

Instead of having trace_printk.h included in kernel.h, create a config TRACE_PRINTK_DEBUGGING that when set will update the CFLAGS in the Makefile to allow developers to add trace_printk() without the need to add the include for it. Having it included in the Makefile keeps it from being in the dependency chain and it will not waste extra CPU cycles for those building the kernel without using trace_printk.

Quoted 8 lines

IOW, you make it worse just because.

With the header being separate I add the three trace_printk()s and the include to the source file I'm investigating. The recompile will build exactly this source file.

Having to enable the config knob will result in a full kernel rebuild for no value.

Indeed...
Isn't trace_printk() just an extern?
Having it defined somewhere isn't going to make any difference to build times.

David

Quoted 9 lines

Seriously?

Thanks,

tglx

#11 lore raw

Re: [PATCH 2/2] tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

Quoted 3 lines · On Sun, 21 Jun 2026 13:55:31 +0100 David Laight <[email protected]>…

Indeed...
Isn't trace_printk() just an extern?
Having it defined somewhere isn't going to make any difference to build times.

No it is not. It is a macro to cut as many nanoseconds as possible as trace_printk() was created to debug tight race conditions and any added latency can make the race go away.

-- Steve

#12 lore raw
In reply to Steven Rostedt

Le 21/06/2026 à 11:34, Steven Rostedt a écrit :

Quoted 4 lines

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Do we have a measurement of the increased compilation time ?

Christophe

Quoted 36 lines

Instead, add a CONFIG_TRACE_PRINTK_DEBUGGING option that developers that do use it can set and not have to always remember to add #include <linux/trace_printk.h> to the files they add trace_printk() while debugging. It also means that those that do not have that config set will not have to worry about wasted CPU cycles as it is only include in the CFLAGS when the option is set, and its completely ignored otherwise.

Steven Rostedt (2):
tracing: Move non-trace_printk prototypes back to kernel.h
tracing: Add CONFIG_TRACE_PRINTK_DEBUGGING to clean up kernel.h

----

  .../driver_development_debugging_guide.rst         |  2 +-
  Makefile                                           |  5 +++++
  arch/powerpc/kvm/book3s_xics.c                     |  1 +
  drivers/gpu/drm/i915/gt/intel_gtt.h                |  1 +
  drivers/gpu/drm/i915/i915_gem.h                    |  1 +
  drivers/hwtracing/stm/dummy_stm.c                  |  4 ++++
  drivers/infiniband/hw/hfi1/trace_dbg.h             |  1 +
  drivers/usb/early/xhci-dbc.c                       |  1 +
  fs/ext4/inline.c                                   |  1 +
  include/linux/kernel.h                             | 19 ++++++++++++++++++-
  include/linux/sunrpc/debug.h                       |  1 +
  include/linux/trace_printk.h                       | 22 +++-------------------
  kernel/trace/Kconfig                               | 10 ++++++++++
  kernel/trace/ring_buffer_benchmark.c               |  1 +
  kernel/trace/trace.h                               |  1 +
  samples/fprobe/fprobe_example.c                    |  1 +
  samples/ftrace/ftrace-direct-modify.c              |  1 +
  samples/ftrace/ftrace-direct-multi-modify.c        |  1 +
  samples/ftrace/ftrace-direct-multi.c               |  2 +-
  samples/ftrace/ftrace-direct-too.c                 |  2 +-
  samples/ftrace/ftrace-direct.c                     |  2 +-
  21 files changed, 56 insertions(+), 24 deletions(-)
#13 lore raw
Quoted 6 lines · On Mon, 22 Jun 2026 10:05:13 +0200 "Christophe Leroy (CS GROUP)"…
Quoted 4 lines

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Do we have a measurement of the increased compilation time ?

I believe Yury does.

-- Steve

#14 lore raw
Quoted 11 lines · Steven Rostedt
Quoted 6 lines · On Mon, 22 Jun 2026 10:05:13 +0200 "Christophe Leroy (CS GROUP)"…
Quoted 4 lines

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Do we have a measurement of the increased compilation time ?

I believe Yury does.

I re-run compilation is a more strict environment, and the difference is negligible.

#15 lore raw
In reply to Steven Rostedt
Quoted 11 lines · Steven Rostedt

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Instead, add a CONFIG_TRACE_PRINTK_DEBUGGING option that developers that do use it can set and not have to always remember to add #include <linux/trace_printk.h> to the files they add trace_printk() while debugging. It also means that those that do not have that config set will not have to worry about wasted CPU cycles as it is only include in the CFLAGS when the option is set, and its completely ignored otherwise.

Did you forget your C 101 class? If you use a function, you gotta include the relevant header.

You don't see userspace saying: 'Hey, you know what, perhaps we should add stdio.h to every other header, just in case someone wants to printf()' either.

I really don't understand your argument. Yes, maybe someone will forget and then either their editor (if they have a halfway modern setup with LSP enabled) or their build will complain, but so what? This is all trivial stuff, surely we have more pressing matters to concern outselves with?

#16 lore raw
Quoted 2 lines · On Mon, 22 Jun 2026 10:34:40 +0200 Peter Zijlstra <[email protected]> wrote:

Did you forget your C 101 class? If you use a function, you gotta include the relevant header.

If this was the way it was back in 2009, yeah sure. But the header wasn't need for 17 years. Now it suddenly will be.

-- Steve

reviewer
#17 lore raw
In reply to Peter Zijlstra
Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · Steven Rostedt

There's been complaints about trace_printk() being defined in kernel.h as it can increase the compilation time. As it is only used by some developers for debugging purposes, it should not be in kernel.h causing lots of wasted CPU cycles for those that do not ever care about it.

Instead, add a CONFIG_TRACE_PRINTK_DEBUGGING option that developers that do use it can set and not have to always remember to add #include <linux/trace_printk.h> to the files they add trace_printk() while debugging. It also means that those that do not have that config set will not have to worry about wasted CPU cycles as it is only include in the CFLAGS when the option is set, and its completely ignored otherwise.

Quoted 2 lines

Did you forget your C 101 class? If you use a function, you gotta include the relevant header.

Also item #1 in Documentation/process/submit-checklist.rst.

Quoted 9 lines

You don't see userspace saying: 'Hey, you know what, perhaps we should add stdio.h to every other header, just in case someone wants to printf()' either.

I really don't understand your argument. Yes, maybe someone will forget and then either their editor (if they have a halfway modern setup with LSP enabled) or their build will complain, but so what? This is all trivial stuff, surely we have more pressing matters to concern outselves with?

Signature · 1 line
~Randy
#18 lore raw
Quoted 4 lines · On Mon, 22 Jun 2026 09:40:45 -0700 Randy Dunlap <[email protected]> wrote:
Quoted 2 lines

Did you forget your C 101 class? If you use a function, you gotta include the relevant header.

Also item #1 in Documentation/process/submit-checklist.rst.

What is that? Remove all trace_printk()s before you submit?

Because that is what you should do. But now you also need to remember to remove the include <linux/trace_printk.h> too. Or, I guess if someone uses it a lot, they may just keep it in their files without the trace_printk()s.

-- Steve

#19 lore raw

✗ Fi.CI.BUILD: failure for tracing: Move trace_printk.h out of kernel.h

In reply to Steven Rostedt
== Series Details ==

== Series Details ==

Series: tracing: Move trace_printk.h out of kernel.h
URL : https://patchwork.freedesktop.org/series/169614/
State : failure

== Summary ==

Error: make failed
DESCEND objtool
CC kernel/rcu/tree.o
In file included from kernel/rcu/tree.c:70:
kernel/rcu/tree_stall.h: In function ‘rcu_stall_kick_kthreads’:
kernel/rcu/rcu.h:337:17: error: implicit declaration of function ‘ftrace_dump’; did you mean ‘ftrace_bug’? [-Werror=implicit-function-declaration]

  337 |                 ftrace_dump(oops_dump_mode); \
      |                 ^~~~~~~~~~~
kernel/rcu/tree_stall.h:238:17: note: in expansion of macro ‘rcu_ftrace_dump’
  238 |                 rcu_ftrace_dump(DUMP_ALL);
      |                 ^~~~~~~~~~~~~~~

kernel/rcu/tree_stall.h:238:33: error: ‘DUMP_ALL’ undeclared (first use in this function)
238 | rcu_ftrace_dump(DUMP_ALL);
| ^~~~~~~~
kernel/rcu/rcu.h:337:29: note: in definition of macro ‘rcu_ftrace_dump’

  337 |                 ftrace_dump(oops_dump_mode); \
      |                             ^~~~~~~~~~~~~~

kernel/rcu/tree_stall.h:238:33: note: each undeclared identifier is reported only once for each function it appears in
238 | rcu_ftrace_dump(DUMP_ALL);
| ^~~~~~~~
kernel/rcu/rcu.h:337:29: note: in definition of macro ‘rcu_ftrace_dump’

  337 |                 ftrace_dump(oops_dump_mode); \
      |                             ^~~~~~~~~~~~~~

kernel/rcu/tree_stall.h: In function ‘check_cpu_stall’:
kernel/rcu/tree_stall.h:859:41: error: ‘DUMP_ALL’ undeclared (first use in this function)
859 | rcu_ftrace_dump(DUMP_ALL);
| ^~~~~~~~
kernel/rcu/rcu.h:337:29: note: in definition of macro ‘rcu_ftrace_dump’

  337 |                 ftrace_dump(oops_dump_mode); \
      |                             ^~~~~~~~~~~~~~

cc1: some warnings being treated as errors
make[4]: *** [scripts/Makefile.build:289: kernel/rcu/tree.o] Error 1 make[3]: *** [scripts/Makefile.build:549: kernel/rcu] Error 2 make[2]: *** [scripts/Makefile.build:549: kernel] Error 2 make[1]: *** [/home/kbuild2/kernel/Makefile:2189: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Build failed, no error log produced