tracing: Remove trace_printk.h from kernel.h
Subsystems (22)
v2 cover tracing: Remove trace_printk.h from kernel.h
Remove trace_printk.h by creating a trace_controls.h for those places that need access to tracing prototypes like tracing_off() and for the places that need trace_printk() directly, to have it included directly.
Changse since v1: https://lore.kernel.org/all/[email protected]/
- Create a trace_controls.h header to move the prototypes into and not include it back into kernel.h
- Just remove trace_printk.h from kernel.h with no alternative to keep the previous behavior.
Steven Rostedt (2):
tracing: Move non-trace_printk prototypes into trace_controls.h
tracing: Remove trace_printk.h from kernel.h
----
arch/powerpc/kvm/book3s_xics.c | 1 + arch/powerpc/xmon/xmon.c | 1 + arch/s390/kernel/ipl.c | 1 + arch/s390/kernel/machine_kexec.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem.h | 2 ++ drivers/hwtracing/stm/dummy_stm.c | 4 +++ drivers/infiniband/hw/hfi1/trace_dbg.h | 1 + drivers/tty/sysrq.c | 1 + drivers/usb/early/xhci-dbc.c | 1 + fs/ext4/inline.c | 1 + include/linux/ftrace.h | 2 ++ include/linux/kernel.h | 1 - include/linux/sunrpc/debug.h | 1 + include/linux/trace_controls.h | 54 ++++++++++++++++++++++++++++++++ include/linux/trace_printk.h | 56 ++-------------------------------- kernel/debug/debug_core.c | 1 + kernel/panic.c | 1 + kernel/rcu/rcu.h | 2 ++ kernel/rcu/rcutorture.c | 1 + kernel/trace/ring_buffer_benchmark.c | 1 + kernel/trace/trace.h | 1 + kernel/trace/trace_benchmark.c | 1 + lib/sys_info.c | 1 + samples/fprobe/fprobe_example.c | 1 + samples/ftrace/ftrace-direct-too.c | 1 - samples/trace_printk/trace-printk.c | 1 + 27 files changed, 86 insertions(+), 55 deletions(-) create mode 100644 include/linux/trace_controls.h
PATCH v2 1/2 tracing: Move non-trace_printk prototypes into trace_controls.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 separated into their own header file as 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.
---
Changes since v1: https://patch.msgid.link/[email protected]
- Instead of moving back into kernel.h, create a new trace_controls.h header.
arch/powerpc/xmon/xmon.c | 1 + arch/s390/kernel/ipl.c | 1 + arch/s390/kernel/machine_kexec.c | 1 + drivers/gpu/drm/i915/i915_gem.h | 1 + drivers/tty/sysrq.c | 1 + include/linux/trace_controls.h | 54 ++++++++++++++++++++++++++++++++ include/linux/trace_printk.h | 51 ------------------------------ kernel/debug/debug_core.c | 1 + kernel/panic.c | 1 + kernel/rcu/rcu.h | 2 ++ kernel/rcu/rcutorture.c | 1 + kernel/trace/trace.h | 1 + kernel/trace/trace_benchmark.c | 1 + lib/sys_info.c | 1 + 14 files changed, 67 insertions(+), 51 deletions(-) create mode 100644 include/linux/trace_controls.h
arch/powerpc/xmon/xmon.c +1 -0
@@ -27,6 +27,7 @@#include <linux/highmem.h> #include <linux/security.h> #include <linux/debugfs.h> +#include <linux/trace_controls.h> #include <asm/ptrace.h> #include <asm/smp.h>
arch/s390/kernel/ipl.c +1 -0
@@ -22,6 +22,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/secure_boot.h> +#include <linux/trace_controls.h> #include <asm/asm-extable.h> #include <asm/machine.h> #include <asm/diag.h>
arch/s390/kernel/machine_kexec.c +1 -0
@@ -12,6 +12,7 @@#include <linux/delay.h> #include <linux/reboot.h> #include <linux/ftrace.h> +#include <linux/trace_controls.h> #include <linux/debug_locks.h> #include <linux/cpufeature.h> #include <asm/guarded_storage.h>
drivers/gpu/drm/i915/i915_gem.h +1 -0
@@ -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_controls.h> #define GEM_TRACE (...) trace_printk(__VA_ARGS__)#define GEM_TRACE_ERR (...) do { \ pr_err(__VA_ARGS__); \
drivers/tty/sysrq.c +1 -0
@@ -324,6 +324,7 @@ static const struct sysrq_key_op sysrq_showstate_blocked_op = { };#ifdef CONFIG_TRACING +#include <linux/trace_controls.h> #include <linux/ftrace.h> static void sysrq_ftrace_dump (u8 key)
include/linux/trace_controls.h new file +54 -0
54 lines not on this page · raw message
include/linux/trace_printk.h +0 -51
77 lines not on this page · raw message
kernel/debug/debug_core.c +1 -0
@@ -27,6 +27,7 @@#define pr_fmt (fmt) "KGDB: " fmt +#include <linux/trace_controls.h> #include <linux/pid_namespace.h> #include <linux/clocksource.h> #include <linux/serial_core.h>
kernel/panic.c +1 -0
@@ -9,6 +9,7 @@* This function is used through-out the kernel (including mm and fs) * to indicate a major problem. */ +#include <linux/trace_controls.h> #include <linux/debug_locks.h> #include <linux/sched/debug.h> #include <linux/interrupt.h>
kernel/rcu/rcu.h +2 -0
@@ -280,6 +280,8 @@ extern int rcu_cpu_stall_notifiers;#ifdef CONFIG_RCU_STALL_COMMON +#include <linux/trace_controls.h> +extern int rcu_cpu_stall_ftrace_dump;extern int rcu_cpu_stall_suppress;extern int rcu_cpu_stall_timeout;
kernel/rcu/rcutorture.c +1 -0
@@ -39,6 +39,7 @@#include <linux/srcu.h> #include <linux/slab.h> #include <linux/trace_clock.h> +#include <linux/trace_controls.h> #include <asm/byteorder.h> #include <linux/torture.h> #include <linux/vmalloc.h>
kernel/trace/trace.h +1 -0
@@ -22,6 +22,7 @@#include <linux/ctype.h> #include <linux/once_lite.h> #include <linux/ftrace_regs.h> +#include <linux/trace_controls.h> #include <linux/llist.h> #include "pid_list.h"
kernel/trace/trace_benchmark.c +1 -0
@@ -3,6 +3,7 @@#include <linux/module.h> #include <linux/kthread.h> #include <linux/trace_clock.h> +#include <linux/trace_controls.h> #define CREATE_TRACE_POINTS #include "trace_benchmark.h"
lib/sys_info.c +1 -0
@@ -8,6 +8,7 @@#include <linux/ftrace.h> #include <linux/nmi.h> #include <linux/sched/debug.h> +#include <linux/trace_controls.h> #include <linux/string.h> #include <linux/sysctl.h>
Signature · 1 line
2.53.0
Re: [PATCH v2 1/2] tracing: Move non-trace_printk prototypes into trace_controls.h
Quoted 11 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
In order to remove the include to
trace_printk.hfromkernel.hthe tracing control prototypes need to be separated into their own header file as they are used in other common header files likercu.h. There's no point in removingtrace_printk.hfromkernel.hif it just gets added back to other common headers.Prototypes are very cheap for the compiler and should not be an issue.
Signed-off-by Steven Rostedt <[email protected]>
Quoted 119 lines
---
Changes since v1: https://patch.msgid.link/[email protected]- Instead of moving back into
kernel.h, create a newtrace_controls.hheader.arch/powerpc/xmon/xmon.c | 1 + arch/s390/kernel/ipl.c | 1 + arch/s390/kernel/machine_kexec.c | 1 + drivers/gpu/drm/i915/i915_gem.h | 1 + drivers/tty/sysrq.c | 1 + include/linux/trace_controls.h | 54 ++++++++++++++++++++++++++++++++ include/linux/trace_printk.h | 51 ------------------------------ kernel/debug/debug_core.c | 1 + kernel/panic.c | 1 + kernel/rcu/rcu.h | 2 ++ kernel/rcu/rcutorture.c | 1 + kernel/trace/trace.h | 1 + kernel/trace/trace_benchmark.c | 1 + lib/sys_info.c | 1 + 14 files changed, 67 insertions(+), 51 deletions(-) create mode 100644 include/linux/trace_controls.harch/powerpc/xmon/xmon.c +1
-0@@ -27,6 +27,7 @@#include <linux/highmem.h> #include <linux/security.h> #include <linux/debugfs.h> +#include <linux/trace_controls.h> #include <asm/ptrace.h> #include <asm/smp.h> arch/s390/kernel/ipl.c +1
-0@@ -22,6 +22,7 @@#include <linux/debug_locks.h> #include <linux/vmalloc.h> #include <linux/secure_boot.h> +#include <linux/trace_controls.h> #include <asm/asm-extable.h> #include <asm/machine.h> #include <asm/diag.h> arch/s390/kernel/machine_kexec.c +1
-0@@ -12,6 +12,7 @@#include <linux/delay.h> #include <linux/reboot.h> #include <linux/ftrace.h> +#include <linux/trace_controls.h> #include <linux/debug_locks.h> #include <linux/cpufeature.h> #include <asm/guarded_storage.h> drivers/gpu/drm/i915/i915_gem.h +1
-0@@ -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_controls.h> #define GEM_TRACE (...) trace_printk(__VA_ARGS__)#define GEM_TRACE_ERR (...) do { \ pr_err(__VA_ARGS__); \drivers/tty/sysrq.c +1
-0@@ -324,6 +324,7 @@ static const struct sysrq_key_op sysrq_showstate_blocked_op = { };#ifdef CONFIG_TRACING +#include <linux/trace_controls.h> #include <linux/ftrace.h> static void sysrq_ftrace_dump (u8 key)include/linux/trace_controls.h new file +30
-0@@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_TRACE_CONTROLS_H +#define _LINUX_TRACE_CONTROLS_H + + +/* +* General tracing related utility functions - trace_printk(), +* tracing_on/tracing_off and tracing_start()/tracing_stop +* +* Use tracing_on/tracing_off when you want to quickly turn on or off +* tracing. It simply enables or disables the recording of the trace events. +* This also corresponds to the user space /sys/kernel/tracing/tracing_on +* file, which gives a means for the kernel and userspace to interact. +* Place a tracing_off() in the kernel where you want tracing to end. +* From user space, examine the trace, and then echo 1 > tracing_on +* to continue tracing. +* +* tracing_stop/tracing_start has slightly more overhead. It is used +* by things like suspend to ram where disabling the recording of the +* trace is not enough, but tracing must actually stop because things +* like calling smp_processor_id() may crash the system. +* +* Most likely, you want to use tracing_on/tracing_off. +*/ +enum ftrace_dump_mode { +DUMP_NONE , +DUMP_ALL , +DUMP_ORIG , +DUMP_PARAM , +};
include/linux/trace_controls.h line 40
Quoted 10 lines
include/linux/trace_controls.h new file +10
-0+ +#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 ); +void trace_dump_stack (int skip);
The function description says:
record a stack back trace in the trace buffer
So, to me it sounds like it should go to the trace_printk.h.
include/linux/trace_controls.h line 41
Quoted 1 line
include/linux/trace_controls.h new file +1
-0+void ftrace_dump (enum ftrace_dump_mode oops_dump_mode);
Same here, based on the function name, it relates to ftrace.h, not the tracing control itself.
For example, lib/sys_info.c only calls ftrace_dump, and already includes ftrace.h. If you place ftrace_dump() as suggested, you can include only ftrace.h in there, and don't include trace_printk.h and trace_control.h
Thanks,
Yury
Quoted 186 lines
include/linux/trace_controls.h new file +13
-0+#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 ) { } +static inline void trace_dump_stack (int skip) { } +static inline void ftrace_dump (enum ftrace_dump_mode oops_dump_mode) { } +#endif + +#endif /* _LINUX_TRACE_CONTROLS_H */ include/linux/trace_printk.h +0
-51@@ -7,43 +7,7 @@#include <linux/stddef.h> #include <linux/stringify.h> -/* -* General tracing related utility functions - trace_printk(), -* tracing_on/tracing_off and tracing_start()/tracing_stop -* -* Use tracing_on/tracing_off when you want to quickly turn on or off -* tracing. It simply enables or disables the recording of the trace events. -* This also corresponds to the user space /sys/kernel/tracing/tracing_on -* file, which gives a means for the kernel and userspace to interact. -* Place a tracing_off() in the kernel where you want tracing to end. -* From user space, examine the trace, and then echo 1 > tracing_on -* to continue tracing. -* -* tracing_stop/tracing_start has slightly more overhead. It is used -* by things like suspend to ram where disabling the recording of the -* trace is not enough, but tracing must actually stop because things -* like calling smp_processor_id() may crash the system. -* -* Most likely, you want to use tracing_on/tracing_off. -*/ - -enum ftrace_dump_mode { -DUMP_NONE , -DUMP_ALL , -DUMP_ORIG , -DUMP_PARAM , -}; -#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, ...) {@@ -149,8 +113,6 @@ int __trace_printk(unsigned long ip, const char *fmt, ...);extern int __trace_bputs (unsigned long ip,const char *str);extern int __trace_puts (unsigned long ip,const char *str); -extern void trace_dump_stack (int skip); -/* * The double __builtin_constant_p is because gcc will give us an error * if we try to allocate the static variable to fmt if it is not a @@ -173,19 +135,7 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); extern __printf(2, 0) int __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, ...) {@@ -196,7 +146,6 @@ ftrace_vprintk(const char *fmt, va_list ap) {return 0 ; } -static inline void ftrace_dump (enum ftrace_dump_mode oops_dump_mode) { }#endif /* CONFIG_TRACING */ #endif kernel/debug/debug_core.c +1
-0@@ -27,6 +27,7 @@#define pr_fmt (fmt) "KGDB: " fmt +#include <linux/trace_controls.h> #include <linux/pid_namespace.h> #include <linux/clocksource.h> #include <linux/serial_core.h> kernel/panic.c +1
-0@@ -9,6 +9,7 @@* This function is used through-out the kernel (including mm and fs) * to indicate a major problem. */ +#include <linux/trace_controls.h> #include <linux/debug_locks.h> #include <linux/sched/debug.h> #include <linux/interrupt.h> kernel/rcu/rcu.h +2
-0@@ -280,6 +280,8 @@ extern int rcu_cpu_stall_notifiers;#ifdef CONFIG_RCU_STALL_COMMON +#include <linux/trace_controls.h> +extern int rcu_cpu_stall_ftrace_dump;extern int rcu_cpu_stall_suppress;extern int rcu_cpu_stall_timeout;kernel/rcu/rcutorture.c +1
-0@@ -39,6 +39,7 @@#include <linux/srcu.h> #include <linux/slab.h> #include <linux/trace_clock.h> +#include <linux/trace_controls.h> #include <asm/byteorder.h> #include <linux/torture.h> #include <linux/vmalloc.h> kernel/trace/trace.h +1
-0@@ -22,6 +22,7 @@#include <linux/ctype.h> #include <linux/once_lite.h> #include <linux/ftrace_regs.h> +#include <linux/trace_controls.h> #include <linux/llist.h> #include "pid_list.h" kernel/trace/trace_benchmark.c +1
-0@@ -3,6 +3,7 @@#include <linux/module.h> #include <linux/kthread.h> #include <linux/trace_clock.h> +#include <linux/trace_controls.h> #define CREATE_TRACE_POINTS #include "trace_benchmark.h" lib/sys_info.c +1
-0@@ -8,6 +8,7 @@#include <linux/ftrace.h> #include <linux/nmi.h> #include <linux/sched/debug.h> +#include <linux/trace_controls.h> #include <linux/string.h> #include <linux/sysctl.h> Signature · 1 line
2.53.0
Re: [PATCH v2 1/2] tracing: Move non-trace_printk prototypes into trace_controls.h
Quoted 9 lines · On Mon, 22 Jun 2026 09:41:16 -0400 Yury Norov <[email protected]> wrote:
Quoted 8 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
In order to remove the include to
trace_printk.hfromkernel.hthe tracing control prototypes need to be separated into their own header file as they are used in other common header files likercu.h. There's no point in removingtrace_printk.hfromkernel.hif it just gets added back to other common headers.
Quoted 5 lines
Quoted 3 lines
Prototypes are very cheap for the compiler and should not be an issue.
Signed-off-by Steven Rostedt <[email protected]>Suggested-by Yury Norov <[email protected]>
Thanks, I'll add you tag.
-- Steve
Re: [PATCH v2 1/2] tracing: Move non-trace_printk prototypes into trace_controls.h
Quoted 12 lines · Steven Rostedt
Quoted 9 lines · On Mon, 22 Jun 2026 09:41:16 -0400 Yury Norov <[email protected]> wrote:
Quoted 8 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
In order to remove the include to
trace_printk.hfromkernel.hthe tracing control prototypes need to be separated into their own header file as they are used in other common header files likercu.h. There's no point in removingtrace_printk.hfromkernel.hif it just gets added back to other common headers.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Prototypes are very cheap for the compiler and should not be an issue.
Signed-off-by Steven Rostedt <[email protected]>Suggested-by Yury Norov <[email protected]>Thanks, I'll add you tag.
Thanks, but can you also comment on trace_dump/ftrace_dump?
Re: [PATCH v2 1/2] tracing: Move non-trace_printk prototypes into trace_controls.h
Quoted 5 lines · On Mon, 22 Jun 2026 12:02:17 -0400 Yury Norov <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line
Suggested-by Yury Norov <[email protected]>Thanks, I'll add you tag.
Thanks, but can you also comment on trace_dump/ftrace_dump?
You mean just add to the change log about trace_dump and ftrace_dump being used here too?
It's there mainly because some bug code in headers uses it.
-- Steve
Re: [PATCH v2 1/2] tracing: Move non-trace_printk prototypes into trace_controls.h
In reply to Yury NorovQuoted 7 lines · On Mon, 22 Jun 2026 09:41:16 -0400 Yury Norov <[email protected]> wrote:
Quoted 1 line
+void
trace_dump_stack(int skip);The function description says:
record a stack back trace in the trace buffer
So, to me it sounds like it should go to the
trace_printk.h.
The main reason I don't want these in trace_printk.h is because they are not the same as trace_printk(). These are usually called when things go wrong, and are usually called along with tracing_off(), to stop the trace to make sure you don't lose the trace of the bug that triggered the dump.
These can also be in production with no problem, as they are triggered when things go wrong. trace_printk() should *not* be used in production.
The uses of these are fundamentally different than the use of trace_printk(). They are not just for development environments.
I'll update the change log to note this.
-- Steve
PATCH v2 2/2 tracing: Remove trace_printk.h from kernel.h
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
There have been complaints about trace_printk.h causing more build time for being in kernel.h. Move it out of kernel.h and place it in the headers and C files that use it.
---
Changes since v1: https://patch.msgid.link/[email protected]
- Just remove trace_printk.h and fix up all the places that need it.
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/ftrace.h | 2 ++ include/linux/kernel.h | 1 - include/linux/sunrpc/debug.h | 1 + include/linux/trace_printk.h | 5 +++-- kernel/trace/ring_buffer_benchmark.c | 1 + samples/fprobe/fprobe_example.c | 1 + samples/ftrace/ftrace-direct-too.c | 1 - samples/trace_printk/trace-printk.c | 1 + 15 files changed, 19 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_xics.c +1 -0
@@ -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
@@ -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
@@ -117,6 +117,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);#if IS_ENABLED (CONFIG_DRM_I915_TRACE_GEM )#include <linux/trace_controls.h> +#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
@@ -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
@@ -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
@@ -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
@@ -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/ftrace.h +2 -0
@@ -8,6 +8,8 @@#define _LINUX_FTRACE_H#include <linux/trace_recursion.h> +#include <linux/trace_controls.h> +#include <linux/trace_printk.h> #include <linux/trace_clock.h> #include <linux/jump_label.h> #include <linux/kallsyms.h>
include/linux/kernel.h +0 -1
@@ -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
@@ -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
@@ -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> #ifdef CONFIG_TRACING static inline __printf(1, 2)
@@ -147,5 +148,5 @@ ftrace_vprintk(const char *fmt, va_list ap)return 0 ; }#endif /* CONFIG_TRACING */ - +#endif /* !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) && !defined(BUILD_VDSO) */ #endif
kernel/trace/ring_buffer_benchmark.c +1 -0
@@ -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>
samples/fprobe/fprobe_example.c +1 -0
@@ -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-too.c +0 -1
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only #include <linux/module.h> -#include <linux/mm.h> /* for handle_mm_fault() */ #include <linux/ftrace.h> #if !defined(CONFIG_ARM64 ) && !defined(CONFIG_PPC32 )
samples/trace_printk/trace-printk.c +1 -0
@@ -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/irq_work.h>
Signature · 1 line
2.53.0
Quoted 7 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
There have been complaints about
trace_printk.hcausing more build time for being inkernel.h. Move it out ofkernel.hand place it in the headers and C files that use it.
Link is nice, but can you explain in the commit message what those complaints exactly are? There's enough opinions shared to make a nice summary. I even think it's important enough to become a Documentation rule.
Quoted 40 lines
Signed-off-by Steven Rostedt <[email protected]>---
Changes since v1: https://patch.msgid.link/[email protected]- Just remove
trace_printk.hand fix up all the places that need it.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/ftrace.h | 2 ++ include/linux/kernel.h | 1 - include/linux/sunrpc/debug.h | 1 + include/linux/trace_printk.h | 5 +++-- kernel/trace/ring_buffer_benchmark.c | 1 + samples/fprobe/fprobe_example.c | 1 + samples/ftrace/ftrace-direct-too.c | 1 - samples/trace_printk/trace-printk.c | 1 + 15 files changed, 19 insertions(+), 4 deletions(-)arch/powerpc/kvm/book3s_xics.c +1
-0@@ -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 +0
-0
drivers/gpu/drm/i915/gt/intel_gtt.h line 38
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +1
-0@@ -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>
So, before it was included unconditionally, now it's included. It looks technically correct, but conceptually - I'm not sure.
I'm not a developer of this driver, but ... here we need trace_printk.h if TRACE_GTT is enabled, in the next header TRACE_GEM needs it. To me it sounds like the whole driver simply needs trace_printk.h.
Quoted 20 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +0
-0#define GTT_TRACE (...) trace_printk(__VA_ARGS__)#else #define GTT_TRACE (...)drivers/gpu/drm/i915/i915_gem.h +1
-0@@ -117,6 +117,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);#if IS_ENABLED (CONFIG_DRM_I915_TRACE_GEM )#include <linux/trace_controls.h> +#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 +0
-0
drivers/hwtracing/stm/dummy_stm.c line 20
Quoted 7 lines
drivers/hwtracing/stm/dummy_stm.c +4
-0@@ -14,6 +14,10 @@#include <linux/stm.h> #include <uapi/linux/stm.h> +#ifdef DEBUG +#include <linux/trace_printk.h> +#endif +
Same here. The cost of adding the header in a particular C file is unmeasurable. But playing "#undef DEBUG #ifdef DEBUG" games looks weird.
Imagine, the developer has this DEBUG enabled, then adds another debugging trace_pritnk() out of the DEBUG block, compiles his patch well, then sends to the user, who has DEBUG disabled; and now we hit the same problem as in the config-based case.
Let's put it simple: dummy_stm just needs trace_printk.h.
Quoted 149 lines
drivers/hwtracing/stm/dummy_stm.c +0
-0static 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@@ -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@@ -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@@ -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/ftrace.h +2
-0@@ -8,6 +8,8 @@#define _LINUX_FTRACE_H#include <linux/trace_recursion.h> +#include <linux/trace_controls.h> +#include <linux/trace_printk.h> #include <linux/trace_clock.h> #include <linux/jump_label.h> #include <linux/kallsyms.h> include/linux/kernel.h +0
-1@@ -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@@ -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@@ -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> #ifdef CONFIG_TRACING static inline __printf(1, 2)@@ -147,5 +148,5 @@ ftrace_vprintk(const char *fmt, va_list ap)return 0 ; }#endif /* CONFIG_TRACING */ - +#endif /* !defined(__ASSEMBLY__) && !defined(__GENKSYMS__) && !defined(BUILD_VDSO) */ #endif kernel/trace/ring_buffer_benchmark.c +1
-0@@ -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> samples/fprobe/fprobe_example.c +1
-0@@ -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-too.c +0
-1@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only #include <linux/module.h> -#include <linux/mm.h> /* for handle_mm_fault() */ #include <linux/ftrace.h> #if !defined(CONFIG_ARM64 ) && !defined(CONFIG_PPC32 )samples/trace_printk/trace-printk.c +1
-0@@ -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/irq_work.h> Signature · 1 line
2.53.0
Quoted 7 lines · On Mon, 22 Jun 2026 12:01:05 -0400 Yury Norov <[email protected]> wrote:
Quoted 6 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
There have been complaints about
trace_printk.hcausing more build time for being inkernel.h. Move it out ofkernel.hand place it in the headers and C files that use it.
Quoted 6 lines
Quoted 1 line
Link is nice, but can you explain in the commit message what those complaints exactly are? There's enough opinions shared to make a nice summary. I even think it's important enough to become a Documentation rule.
What rule is that?
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gtt.h line 38
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +1
-0@@ -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> So, before it was included unconditionally, now it's included. It looks technically correct, but conceptually - I'm not sure.
Quoted 3 lines
I'm not a developer of this driver, but ... here we need
trace_printk.hifTRACE_GTTis enabled, in the next headerTRACE_GEMneeds it. To me it sounds like the whole driver simply needstrace_printk.h.
I just added it when trace_printk() is being used. Why else should it be included when trace_printk() is not used. There's precedent to add includes within #if blocks that contain code that requires the include where nothing else needs it.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +0
-0#define GTT_TRACE (...) trace_printk(__VA_ARGS__)#else #define GTT_TRACE (...)drivers/gpu/drm/i915/i915_gem.h +1
-0@@ -117,6 +117,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);#if IS_ENABLED (CONFIG_DRM_I915_TRACE_GEM )#include <linux/trace_controls.h> +#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 +0
-0@@ -14,6 +14,10 @@#include <linux/stm.h> #include <uapi/linux/stm.h>
Quoted 8 lines
drivers/hwtracing/stm/dummy_stm.c line 20
Quoted 4 lines
drivers/hwtracing/stm/dummy_stm.c +4
-0+#ifdef DEBUG +#include <linux/trace_printk.h> +#endif +Same here. The cost of adding the header in a particular C file is unmeasurable. But playing "#undef DEBUG #ifdef DEBUG" games looks weird.
This one I'll agree with you. I didn't like the if conditional, and looking at it now, I think it's not needed.
But the first instance above, if it is possible to add the include within the #if conditional where trace_printk() is used then why not add the include then?
-- Steve
Quoted 10 lines · On Mon, 22 Jun 2026 09:07:39 -0400 Steven Rostedt <[email protected]> wrote:
Remove
trace_printk.hby creating atrace_controls.hfor those places that need access to tracing prototypes liketracing_off()and for the places that needtrace_printk()directly, to have it included directly.Changse since v1: https://lore.kernel.org/all/[email protected]/
- Create a
trace_controls.hheader to move the prototypes into and not include it back intokernel.h
Quoted 7 lines
- Just remove
trace_printk.hfromkernel.hwith no alternative to keep the previous behavior.Steven Rostedt (2):
tracing: Move non-trace_printk prototypes intotrace_controls.h
tracing: Removetrace_printk.hfromkernel.h
The series looks good to me.
for this series.
Thanks,
Quoted 30 lines
----
arch/powerpc/kvm/book3s_xics.c | 1 + arch/powerpc/xmon/xmon.c | 1 + arch/s390/kernel/ipl.c | 1 + arch/s390/kernel/machine_kexec.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem.h | 2 ++ drivers/hwtracing/stm/dummy_stm.c | 4 +++ drivers/infiniband/hw/hfi1/trace_dbg.h | 1 + drivers/tty/sysrq.c | 1 + drivers/usb/early/xhci-dbc.c | 1 + fs/ext4/inline.c | 1 + include/linux/ftrace.h | 2 ++ include/linux/kernel.h | 1 - include/linux/sunrpc/debug.h | 1 + include/linux/trace_controls.h | 54 ++++++++++++++++++++++++++++++++ include/linux/trace_printk.h | 56 ++-------------------------------- kernel/debug/debug_core.c | 1 + kernel/panic.c | 1 + kernel/rcu/rcu.h | 2 ++ kernel/rcu/rcutorture.c | 1 + kernel/trace/ring_buffer_benchmark.c | 1 + kernel/trace/trace.h | 1 + kernel/trace/trace_benchmark.c | 1 + lib/sys_info.c | 1 + samples/fprobe/fprobe_example.c | 1 + samples/ftrace/ftrace-direct-too.c | 1 - samples/trace_printk/trace-printk.c | 1 + 27 files changed, 86 insertions(+), 55 deletions(-) create mode 100644 include/linux/trace_controls.h
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 3 lines · On Mon, 22 Jun 2026 23:44:16 +0900 Masami Hiramatsu (Google)…
The series looks good to me.
Thanks!
-- Steve