Skip to content

Commit 2be24b8

Browse files
Yury Norovgregkh
authored andcommitted
tracing: move tracing declarations from kernel.h to a dedicated header
[ Upstream commit bec261f ] Tracing is a half of the kernel.h in terms of LOCs, although it's a self-consistent part. It is intended for quick debugging purposes and isn't used by the normal tracing utilities. Move it to a separate header. If someone needs to just throw a trace_printk() in their driver, they will not have to pull all the heavy tracing machinery. This is a pure move. Link: https://lkml.kernel.org/r/20260116042510.241009-7-ynorov@nvidia.com Signed-off-by: Yury Norov <ynorov@nvidia.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Cc: Aaron Tomlin <atomlin@atomlin.com> Cc: Andi Shyti <andi.shyti@linux.intel.com> Cc: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Jani Nikula <jani.nikula@intel.com> Cc: Petr Pavlu <petr.pavlu@suse.com> Cc: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 473e470 ("tracing: move __printf() attribute on __ftrace_vbprintk()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d09b029 commit 2be24b8

2 files changed

Lines changed: 205 additions & 195 deletions

File tree

include/linux/kernel.h

Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <linux/build_bug.h>
3333
#include <linux/sprintf.h>
3434
#include <linux/static_call_types.h>
35-
#include <linux/instruction_pointer.h>
35+
#include <linux/trace_printk.h>
3636
#include <linux/util_macros.h>
3737
#include <linux/wordpart.h>
3838

@@ -192,200 +192,6 @@ enum system_states {
192192
};
193193
extern enum system_states system_state;
194194

195-
/*
196-
* General tracing related utility functions - trace_printk(),
197-
* tracing_on/tracing_off and tracing_start()/tracing_stop
198-
*
199-
* Use tracing_on/tracing_off when you want to quickly turn on or off
200-
* tracing. It simply enables or disables the recording of the trace events.
201-
* This also corresponds to the user space /sys/kernel/tracing/tracing_on
202-
* file, which gives a means for the kernel and userspace to interact.
203-
* Place a tracing_off() in the kernel where you want tracing to end.
204-
* From user space, examine the trace, and then echo 1 > tracing_on
205-
* to continue tracing.
206-
*
207-
* tracing_stop/tracing_start has slightly more overhead. It is used
208-
* by things like suspend to ram where disabling the recording of the
209-
* trace is not enough, but tracing must actually stop because things
210-
* like calling smp_processor_id() may crash the system.
211-
*
212-
* Most likely, you want to use tracing_on/tracing_off.
213-
*/
214-
215-
enum ftrace_dump_mode {
216-
DUMP_NONE,
217-
DUMP_ALL,
218-
DUMP_ORIG,
219-
DUMP_PARAM,
220-
};
221-
222-
#ifdef CONFIG_TRACING
223-
void tracing_on(void);
224-
void tracing_off(void);
225-
int tracing_is_on(void);
226-
void tracing_snapshot(void);
227-
void tracing_snapshot_alloc(void);
228-
229-
extern void tracing_start(void);
230-
extern void tracing_stop(void);
231-
232-
static inline __printf(1, 2)
233-
void ____trace_printk_check_format(const char *fmt, ...)
234-
{
235-
}
236-
#define __trace_printk_check_format(fmt, args...) \
237-
do { \
238-
if (0) \
239-
____trace_printk_check_format(fmt, ##args); \
240-
} while (0)
241-
242-
/**
243-
* trace_printk - printf formatting in the ftrace buffer
244-
* @fmt: the printf format for printing
245-
*
246-
* Note: __trace_printk is an internal function for trace_printk() and
247-
* the @ip is passed in via the trace_printk() macro.
248-
*
249-
* This function allows a kernel developer to debug fast path sections
250-
* that printk is not appropriate for. By scattering in various
251-
* printk like tracing in the code, a developer can quickly see
252-
* where problems are occurring.
253-
*
254-
* This is intended as a debugging tool for the developer only.
255-
* Please refrain from leaving trace_printks scattered around in
256-
* your code. (Extra memory is used for special buffers that are
257-
* allocated when trace_printk() is used.)
258-
*
259-
* A little optimization trick is done here. If there's only one
260-
* argument, there's no need to scan the string for printf formats.
261-
* The trace_puts() will suffice. But how can we take advantage of
262-
* using trace_puts() when trace_printk() has only one argument?
263-
* By stringifying the args and checking the size we can tell
264-
* whether or not there are args. __stringify((__VA_ARGS__)) will
265-
* turn into "()\0" with a size of 3 when there are no args, anything
266-
* else will be bigger. All we need to do is define a string to this,
267-
* and then take its size and compare to 3. If it's bigger, use
268-
* do_trace_printk() otherwise, optimize it to trace_puts(). Then just
269-
* let gcc optimize the rest.
270-
*/
271-
272-
#define trace_printk(fmt, ...) \
273-
do { \
274-
char _______STR[] = __stringify((__VA_ARGS__)); \
275-
if (sizeof(_______STR) > 3) \
276-
do_trace_printk(fmt, ##__VA_ARGS__); \
277-
else \
278-
trace_puts(fmt); \
279-
} while (0)
280-
281-
#define do_trace_printk(fmt, args...) \
282-
do { \
283-
static const char *trace_printk_fmt __used \
284-
__section("__trace_printk_fmt") = \
285-
__builtin_constant_p(fmt) ? fmt : NULL; \
286-
\
287-
__trace_printk_check_format(fmt, ##args); \
288-
\
289-
if (__builtin_constant_p(fmt)) \
290-
__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \
291-
else \
292-
__trace_printk(_THIS_IP_, fmt, ##args); \
293-
} while (0)
294-
295-
extern __printf(2, 3)
296-
int __trace_bprintk(unsigned long ip, const char *fmt, ...);
297-
298-
extern __printf(2, 3)
299-
int __trace_printk(unsigned long ip, const char *fmt, ...);
300-
301-
/**
302-
* trace_puts - write a string into the ftrace buffer
303-
* @str: the string to record
304-
*
305-
* Note: __trace_bputs is an internal function for trace_puts and
306-
* the @ip is passed in via the trace_puts macro.
307-
*
308-
* This is similar to trace_printk() but is made for those really fast
309-
* paths that a developer wants the least amount of "Heisenbug" effects,
310-
* where the processing of the print format is still too much.
311-
*
312-
* This function allows a kernel developer to debug fast path sections
313-
* that printk is not appropriate for. By scattering in various
314-
* printk like tracing in the code, a developer can quickly see
315-
* where problems are occurring.
316-
*
317-
* This is intended as a debugging tool for the developer only.
318-
* Please refrain from leaving trace_puts scattered around in
319-
* your code. (Extra memory is used for special buffers that are
320-
* allocated when trace_puts() is used.)
321-
*
322-
* Returns: 0 if nothing was written, positive # if string was.
323-
* (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
324-
*/
325-
326-
#define trace_puts(str) ({ \
327-
static const char *trace_printk_fmt __used \
328-
__section("__trace_printk_fmt") = \
329-
__builtin_constant_p(str) ? str : NULL; \
330-
\
331-
if (__builtin_constant_p(str)) \
332-
__trace_bputs(_THIS_IP_, trace_printk_fmt); \
333-
else \
334-
__trace_puts(_THIS_IP_, str); \
335-
})
336-
extern int __trace_bputs(unsigned long ip, const char *str);
337-
extern int __trace_puts(unsigned long ip, const char *str);
338-
339-
extern void trace_dump_stack(int skip);
340-
341-
/*
342-
* The double __builtin_constant_p is because gcc will give us an error
343-
* if we try to allocate the static variable to fmt if it is not a
344-
* constant. Even with the outer if statement.
345-
*/
346-
#define ftrace_vprintk(fmt, vargs) \
347-
do { \
348-
if (__builtin_constant_p(fmt)) { \
349-
static const char *trace_printk_fmt __used \
350-
__section("__trace_printk_fmt") = \
351-
__builtin_constant_p(fmt) ? fmt : NULL; \
352-
\
353-
__ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \
354-
} else \
355-
__ftrace_vprintk(_THIS_IP_, fmt, vargs); \
356-
} while (0)
357-
358-
extern __printf(2, 0) int
359-
__ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
360-
361-
extern __printf(2, 0) int
362-
__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
363-
364-
extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
365-
#else
366-
static inline void tracing_start(void) { }
367-
static inline void tracing_stop(void) { }
368-
static inline void trace_dump_stack(int skip) { }
369-
370-
static inline void tracing_on(void) { }
371-
static inline void tracing_off(void) { }
372-
static inline int tracing_is_on(void) { return 0; }
373-
static inline void tracing_snapshot(void) { }
374-
static inline void tracing_snapshot_alloc(void) { }
375-
376-
static inline __printf(1, 2)
377-
int trace_printk(const char *fmt, ...)
378-
{
379-
return 0;
380-
}
381-
static __printf(1, 0) inline int
382-
ftrace_vprintk(const char *fmt, va_list ap)
383-
{
384-
return 0;
385-
}
386-
static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
387-
#endif /* CONFIG_TRACING */
388-
389195
/* Rebuild everything on CONFIG_DYNAMIC_FTRACE */
390196
#ifdef CONFIG_DYNAMIC_FTRACE
391197
# define REBUILD_DUE_TO_DYNAMIC_FTRACE

0 commit comments

Comments
 (0)