diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 556d781e69fe..d9e75ec7def5 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -242,6 +242,19 @@ 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 | |||
| 245 | void log_buf_kexec_setup(void); | 258 | void log_buf_kexec_setup(void); |
| 246 | #else | 259 | #else |
| 247 | static inline int vprintk(const char *s, va_list args) | 260 | static inline int vprintk(const char *s, va_list args) |
| @@ -254,6 +267,10 @@ static inline int printk_ratelimit(void) { return 0; } | |||
| 254 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ | 267 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ |
| 255 | unsigned int interval_msec) \ | 268 | unsigned int interval_msec) \ |
| 256 | { 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 | |||
| 257 | static inline void log_buf_kexec_setup(void) | 274 | static inline void log_buf_kexec_setup(void) |
| 258 | { | 275 | { |
| 259 | } | 276 | } |
| @@ -375,6 +392,139 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 375 | #endif | 392 | #endif |
| 376 | 393 | ||
| 377 | /* | 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 | /* | ||
| 378 | * Display an IP address in readable format. | 528 | * Display an IP address in readable format. |
| 379 | */ | 529 | */ |
| 380 | 530 | ||
