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.h184
1 files changed, 169 insertions, 15 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 7fa371898e3e..883cd44ff765 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -16,7 +16,7 @@
16#include <linux/log2.h> 16#include <linux/log2.h>
17#include <linux/typecheck.h> 17#include <linux/typecheck.h>
18#include <linux/ratelimit.h> 18#include <linux/ratelimit.h>
19#include <linux/dynamic_printk.h> 19#include <linux/dynamic_debug.h>
20#include <asm/byteorder.h> 20#include <asm/byteorder.h>
21#include <asm/bug.h> 21#include <asm/bug.h>
22 22
@@ -242,6 +242,20 @@ 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
258void log_buf_kexec_setup(void);
245#else 259#else
246static inline int vprintk(const char *s, va_list args) 260static inline int vprintk(const char *s, va_list args)
247 __attribute__ ((format (printf, 1, 0))); 261 __attribute__ ((format (printf, 1, 0)));
@@ -253,6 +267,13 @@ static inline int printk_ratelimit(void) { return 0; }
253static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 267static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
254 unsigned int interval_msec) \ 268 unsigned int interval_msec) \
255 { return false; } 269 { return false; }
270
271/* No effect, but we still get type checking even in the !PRINTK case: */
272#define printk_once(x...) printk(x)
273
274static inline void log_buf_kexec_setup(void)
275{
276}
256#endif 277#endif
257 278
258extern int printk_needs_cpu(int cpu); 279extern int printk_needs_cpu(int cpu);
@@ -353,14 +374,26 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
353 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 374 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
354#define pr_info(fmt, ...) \ 375#define pr_info(fmt, ...) \
355 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 376 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
377#define pr_cont(fmt, ...) \
378 printk(KERN_CONT fmt, ##__VA_ARGS__)
379
380/* pr_devel() should produce zero code unless DEBUG is defined */
381#ifdef DEBUG
382#define pr_devel(fmt, ...) \
383 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
384#else
385#define pr_devel(fmt, ...) \
386 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
387#endif
356 388
357/* If you are writing a driver, please use dev_dbg instead */ 389/* If you are writing a driver, please use dev_dbg instead */
358#if defined(DEBUG) 390#if defined(DEBUG)
359#define pr_debug(fmt, ...) \ 391#define pr_debug(fmt, ...) \
360 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 392 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
361#elif defined(CONFIG_DYNAMIC_PRINTK_DEBUG) 393#elif defined(CONFIG_DYNAMIC_DEBUG)
394/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
362#define pr_debug(fmt, ...) do { \ 395#define pr_debug(fmt, ...) do { \
363 dynamic_pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ 396 dynamic_pr_debug(fmt, ##__VA_ARGS__); \
364 } while (0) 397 } while (0)
365#else 398#else
366#define pr_debug(fmt, ...) \ 399#define pr_debug(fmt, ...) \
@@ -368,6 +401,139 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
368#endif 401#endif
369 402
370/* 403/*
404 * General tracing related utility functions - trace_printk(),
405 * tracing_on/tracing_off and tracing_start()/tracing_stop
406 *
407 * Use tracing_on/tracing_off when you want to quickly turn on or off
408 * tracing. It simply enables or disables the recording of the trace events.
409 * This also corresponds to the user space debugfs/tracing/tracing_on
410 * file, which gives a means for the kernel and userspace to interact.
411 * Place a tracing_off() in the kernel where you want tracing to end.
412 * From user space, examine the trace, and then echo 1 > tracing_on
413 * to continue tracing.
414 *
415 * tracing_stop/tracing_start has slightly more overhead. It is used
416 * by things like suspend to ram where disabling the recording of the
417 * trace is not enough, but tracing must actually stop because things
418 * like calling smp_processor_id() may crash the system.
419 *
420 * Most likely, you want to use tracing_on/tracing_off.
421 */
422#ifdef CONFIG_RING_BUFFER
423void tracing_on(void);
424void tracing_off(void);
425/* trace_off_permanent stops recording with no way to bring it back */
426void tracing_off_permanent(void);
427int tracing_is_on(void);
428#else
429static inline void tracing_on(void) { }
430static inline void tracing_off(void) { }
431static inline void tracing_off_permanent(void) { }
432static inline int tracing_is_on(void) { return 0; }
433#endif
434#ifdef CONFIG_TRACING
435extern void tracing_start(void);
436extern void tracing_stop(void);
437extern void ftrace_off_permanent(void);
438
439extern void
440ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
441
442static inline void __attribute__ ((format (printf, 1, 2)))
443____trace_printk_check_format(const char *fmt, ...)
444{
445}
446#define __trace_printk_check_format(fmt, args...) \
447do { \
448 if (0) \
449 ____trace_printk_check_format(fmt, ##args); \
450} while (0)
451
452/**
453 * trace_printk - printf formatting in the ftrace buffer
454 * @fmt: the printf format for printing
455 *
456 * Note: __trace_printk is an internal function for trace_printk and
457 * the @ip is passed in via the trace_printk macro.
458 *
459 * This function allows a kernel developer to debug fast path sections
460 * that printk is not appropriate for. By scattering in various
461 * printk like tracing in the code, a developer can quickly see
462 * where problems are occurring.
463 *
464 * This is intended as a debugging tool for the developer only.
465 * Please refrain from leaving trace_printks scattered around in
466 * your code.
467 */
468
469#define trace_printk(fmt, args...) \
470do { \
471 __trace_printk_check_format(fmt, ##args); \
472 if (__builtin_constant_p(fmt)) { \
473 static const char *trace_printk_fmt \
474 __attribute__((section("__trace_printk_fmt"))) = \
475 __builtin_constant_p(fmt) ? fmt : NULL; \
476 \
477 __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \
478 } else \
479 __trace_printk(_THIS_IP_, fmt, ##args); \
480} while (0)
481
482extern int
483__trace_bprintk(unsigned long ip, const char *fmt, ...)
484 __attribute__ ((format (printf, 2, 3)));
485
486extern int
487__trace_printk(unsigned long ip, const char *fmt, ...)
488 __attribute__ ((format (printf, 2, 3)));
489
490/*
491 * The double __builtin_constant_p is because gcc will give us an error
492 * if we try to allocate the static variable to fmt if it is not a
493 * constant. Even with the outer if statement.
494 */
495#define ftrace_vprintk(fmt, vargs) \
496do { \
497 if (__builtin_constant_p(fmt)) { \
498 static const char *trace_printk_fmt \
499 __attribute__((section("__trace_printk_fmt"))) = \
500 __builtin_constant_p(fmt) ? fmt : NULL; \
501 \
502 __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \
503 } else \
504 __ftrace_vprintk(_THIS_IP_, fmt, vargs); \
505} while (0)
506
507extern int
508__ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
509
510extern int
511__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
512
513extern void ftrace_dump(void);
514#else
515static inline void
516ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
517static inline int
518trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
519
520static inline void tracing_start(void) { }
521static inline void tracing_stop(void) { }
522static inline void ftrace_off_permanent(void) { }
523static inline int
524trace_printk(const char *fmt, ...)
525{
526 return 0;
527}
528static inline int
529ftrace_vprintk(const char *fmt, va_list ap)
530{
531 return 0;
532}
533static inline void ftrace_dump(void) { }
534#endif /* CONFIG_TRACING */
535
536/*
371 * Display an IP address in readable format. 537 * Display an IP address in readable format.
372 */ 538 */
373 539
@@ -378,18 +544,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
378 ((unsigned char *)&addr)[3] 544 ((unsigned char *)&addr)[3]
379#define NIPQUAD_FMT "%u.%u.%u.%u" 545#define NIPQUAD_FMT "%u.%u.%u.%u"
380 546
381#if defined(__LITTLE_ENDIAN)
382#define HIPQUAD(addr) \
383 ((unsigned char *)&addr)[3], \
384 ((unsigned char *)&addr)[2], \
385 ((unsigned char *)&addr)[1], \
386 ((unsigned char *)&addr)[0]
387#elif defined(__BIG_ENDIAN)
388#define HIPQUAD NIPQUAD
389#else
390#error "Please fix asm/byteorder.h"
391#endif /* __LITTLE_ENDIAN */
392
393/* 547/*
394 * min()/max()/clamp() macros that also do 548 * min()/max()/clamp() macros that also do
395 * strict type-checking.. See the 549 * strict type-checking.. See the