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