aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 7fa371898e3e..7742798c9208 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -242,6 +242,19 @@ extern struct ratelimit_state printk_ratelimit_state;
242extern int printk_ratelimit(void); 242extern int printk_ratelimit(void);
243extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 243extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
244 unsigned int interval_msec); 244 unsigned int interval_msec);
245
246/*
247 * Print a one-time message (analogous to WARN_ONCE() et al):
248 */
249#define printk_once(x...) ({ \
250 static int __print_once = 1; \
251 \
252 if (__print_once) { \
253 __print_once = 0; \
254 printk(x); \
255 } \
256})
257
245#else 258#else
246static inline int vprintk(const char *s, va_list args) 259static inline int vprintk(const char *s, va_list args)
247 __attribute__ ((format (printf, 1, 0))); 260 __attribute__ ((format (printf, 1, 0)));
@@ -253,6 +266,10 @@ static inline int printk_ratelimit(void) { return 0; }
253static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 266static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
254 unsigned int interval_msec) \ 267 unsigned int interval_msec) \
255 { return false; } 268 { return false; }
269
270/* No effect, but we still get type checking even in the !PRINTK case: */
271#define printk_once(x...) printk(x)
272
256#endif 273#endif
257 274
258extern int printk_needs_cpu(int cpu); 275extern int printk_needs_cpu(int cpu);
@@ -368,6 +385,125 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
368#endif 385#endif
369 386
370/* 387/*
388 * General tracing related utility functions - trace_printk(),
389 * tracing_on/tracing_off and tracing_start()/tracing_stop
390 *
391 * Use tracing_on/tracing_off when you want to quickly turn on or off
392 * tracing. It simply enables or disables the recording of the trace events.
393 * This also corresponds to the user space debugfs/tracing/tracing_on
394 * file, which gives a means for the kernel and userspace to interact.
395 * Place a tracing_off() in the kernel where you want tracing to end.
396 * From user space, examine the trace, and then echo 1 > tracing_on
397 * to continue tracing.
398 *
399 * tracing_stop/tracing_start has slightly more overhead. It is used
400 * by things like suspend to ram where disabling the recording of the
401 * trace is not enough, but tracing must actually stop because things
402 * like calling smp_processor_id() may crash the system.
403 *
404 * Most likely, you want to use tracing_on/tracing_off.
405 */
406#ifdef CONFIG_RING_BUFFER
407void tracing_on(void);
408void tracing_off(void);
409/* trace_off_permanent stops recording with no way to bring it back */
410void tracing_off_permanent(void);
411int tracing_is_on(void);
412#else
413static inline void tracing_on(void) { }
414static inline void tracing_off(void) { }
415static inline void tracing_off_permanent(void) { }
416static inline int tracing_is_on(void) { return 0; }
417#endif
418#ifdef CONFIG_TRACING
419extern void tracing_start(void);
420extern void tracing_stop(void);
421extern void ftrace_off_permanent(void);
422
423extern void
424ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
425
426static inline void __attribute__ ((format (printf, 1, 2)))
427____trace_printk_check_format(const char *fmt, ...)
428{
429}
430#define __trace_printk_check_format(fmt, args...) \
431do { \
432 if (0) \
433 ____trace_printk_check_format(fmt, ##args); \
434} while (0)
435
436/**
437 * trace_printk - printf formatting in the ftrace buffer
438 * @fmt: the printf format for printing
439 *
440 * Note: __trace_printk is an internal function for trace_printk and
441 * the @ip is passed in via the trace_printk macro.
442 *
443 * This function allows a kernel developer to debug fast path sections
444 * that printk is not appropriate for. By scattering in various
445 * printk like tracing in the code, a developer can quickly see
446 * where problems are occurring.
447 *
448 * This is intended as a debugging tool for the developer only.
449 * Please refrain from leaving trace_printks scattered around in
450 * your code.
451 */
452
453#define trace_printk(fmt, args...) \
454do { \
455 static const char *trace_printk_fmt \
456 __attribute__((section("__trace_printk_fmt"))); \
457 \
458 if (!trace_printk_fmt) \
459 trace_printk_fmt = fmt; \
460 \
461 __trace_printk_check_format(fmt, ##args); \
462 __trace_printk(_THIS_IP_, trace_printk_fmt, ##args); \
463} while (0)
464
465extern int
466__trace_printk(unsigned long ip, const char *fmt, ...)
467 __attribute__ ((format (printf, 2, 3)));
468
469#define ftrace_vprintk(fmt, vargs) \
470do { \
471 static const char *trace_printk_fmt \
472 __attribute__((section("__trace_printk_fmt"))); \
473 \
474 if (!trace_printk_fmt) \
475 trace_printk_fmt = fmt; \
476 \
477 __ftrace_vprintk(_THIS_IP_, trace_printk_fmt, vargs); \
478} while (0)
479
480extern int
481__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
482
483extern void ftrace_dump(void);
484#else
485static inline void
486ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
487static inline int
488trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
489
490static inline void tracing_start(void) { }
491static inline void tracing_stop(void) { }
492static inline void ftrace_off_permanent(void) { }
493static inline int
494trace_printk(const char *fmt, ...)
495{
496 return 0;
497}
498static inline int
499ftrace_vprintk(const char *fmt, va_list ap)
500{
501 return 0;
502}
503static inline void ftrace_dump(void) { }
504#endif /* CONFIG_TRACING */
505
506/*
371 * Display an IP address in readable format. 507 * Display an IP address in readable format.
372 */ 508 */
373 509