diff options
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d3cd23f30039..328bca609b9b 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/bitops.h> | 15 | #include <linux/bitops.h> |
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> | ||
19 | #include <linux/dynamic_debug.h> | 18 | #include <linux/dynamic_debug.h> |
20 | #include <asm/byteorder.h> | 19 | #include <asm/byteorder.h> |
21 | #include <asm/bug.h> | 20 | #include <asm/bug.h> |
@@ -241,8 +240,8 @@ asmlinkage int vprintk(const char *fmt, va_list args) | |||
241 | asmlinkage int printk(const char * fmt, ...) | 240 | asmlinkage int printk(const char * fmt, ...) |
242 | __attribute__ ((format (printf, 1, 2))) __cold; | 241 | __attribute__ ((format (printf, 1, 2))) __cold; |
243 | 242 | ||
244 | extern struct ratelimit_state printk_ratelimit_state; | 243 | extern int __printk_ratelimit(const char *func); |
245 | extern int printk_ratelimit(void); | 244 | #define printk_ratelimit() __printk_ratelimit(__func__) |
246 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | 245 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
247 | unsigned int interval_msec); | 246 | unsigned int interval_msec); |
248 | 247 | ||
@@ -252,10 +251,10 @@ extern int printk_delay_msec; | |||
252 | * Print a one-time message (analogous to WARN_ONCE() et al): | 251 | * Print a one-time message (analogous to WARN_ONCE() et al): |
253 | */ | 252 | */ |
254 | #define printk_once(x...) ({ \ | 253 | #define printk_once(x...) ({ \ |
255 | static bool __print_once = true; \ | 254 | static bool __print_once; \ |
256 | \ | 255 | \ |
257 | if (__print_once) { \ | 256 | if (!__print_once) { \ |
258 | __print_once = false; \ | 257 | __print_once = true; \ |
259 | printk(x); \ | 258 | printk(x); \ |
260 | } \ | 259 | } \ |
261 | }) | 260 | }) |
@@ -398,15 +397,58 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
398 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | 397 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
399 | #elif defined(CONFIG_DYNAMIC_DEBUG) | 398 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
400 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ | 399 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
401 | #define pr_debug(fmt, ...) do { \ | 400 | #define pr_debug(fmt, ...) \ |
402 | dynamic_pr_debug(fmt, ##__VA_ARGS__); \ | 401 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
403 | } while (0) | ||
404 | #else | 402 | #else |
405 | #define pr_debug(fmt, ...) \ | 403 | #define pr_debug(fmt, ...) \ |
406 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) | 404 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) |
407 | #endif | 405 | #endif |
408 | 406 | ||
409 | /* | 407 | /* |
408 | * ratelimited messages with local ratelimit_state, | ||
409 | * no local ratelimit_state used in the !PRINTK case | ||
410 | */ | ||
411 | #ifdef CONFIG_PRINTK | ||
412 | #define printk_ratelimited(fmt, ...) ({ \ | ||
413 | static struct ratelimit_state _rs = { \ | ||
414 | .interval = DEFAULT_RATELIMIT_INTERVAL, \ | ||
415 | .burst = DEFAULT_RATELIMIT_BURST, \ | ||
416 | }; \ | ||
417 | \ | ||
418 | if (!__ratelimit(&_rs)) \ | ||
419 | printk(fmt, ##__VA_ARGS__); \ | ||
420 | }) | ||
421 | #else | ||
422 | /* No effect, but we still get type checking even in the !PRINTK case: */ | ||
423 | #define printk_ratelimited printk | ||
424 | #endif | ||
425 | |||
426 | #define pr_emerg_ratelimited(fmt, ...) \ | ||
427 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | ||
428 | #define pr_alert_ratelimited(fmt, ...) \ | ||
429 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | ||
430 | #define pr_crit_ratelimited(fmt, ...) \ | ||
431 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | ||
432 | #define pr_err_ratelimited(fmt, ...) \ | ||
433 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ||
434 | #define pr_warning_ratelimited(fmt, ...) \ | ||
435 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ||
436 | #define pr_notice_ratelimited(fmt, ...) \ | ||
437 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | ||
438 | #define pr_info_ratelimited(fmt, ...) \ | ||
439 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | ||
440 | /* no pr_cont_ratelimited, don't do that... */ | ||
441 | /* If you are writing a driver, please use dev_dbg instead */ | ||
442 | #if defined(DEBUG) | ||
443 | #define pr_debug_ratelimited(fmt, ...) \ | ||
444 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | ||
445 | #else | ||
446 | #define pr_debug_ratelimited(fmt, ...) \ | ||
447 | ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ | ||
448 | ##__VA_ARGS__); 0; }) | ||
449 | #endif | ||
450 | |||
451 | /* | ||
410 | * General tracing related utility functions - trace_printk(), | 452 | * General tracing related utility functions - trace_printk(), |
411 | * tracing_on/tracing_off and tracing_start()/tracing_stop | 453 | * tracing_on/tracing_off and tracing_start()/tracing_stop |
412 | * | 454 | * |
@@ -493,6 +535,8 @@ extern int | |||
493 | __trace_printk(unsigned long ip, const char *fmt, ...) | 535 | __trace_printk(unsigned long ip, const char *fmt, ...) |
494 | __attribute__ ((format (printf, 2, 3))); | 536 | __attribute__ ((format (printf, 2, 3))); |
495 | 537 | ||
538 | extern void trace_dump_stack(void); | ||
539 | |||
496 | /* | 540 | /* |
497 | * The double __builtin_constant_p is because gcc will give us an error | 541 | * The double __builtin_constant_p is because gcc will give us an error |
498 | * if we try to allocate the static variable to fmt if it is not a | 542 | * if we try to allocate the static variable to fmt if it is not a |
@@ -526,6 +570,7 @@ trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); | |||
526 | static inline void tracing_start(void) { } | 570 | static inline void tracing_start(void) { } |
527 | static inline void tracing_stop(void) { } | 571 | static inline void tracing_stop(void) { } |
528 | static inline void ftrace_off_permanent(void) { } | 572 | static inline void ftrace_off_permanent(void) { } |
573 | static inline void trace_dump_stack(void) { } | ||
529 | static inline int | 574 | static inline int |
530 | trace_printk(const char *fmt, ...) | 575 | trace_printk(const char *fmt, ...) |
531 | { | 576 | { |
@@ -659,6 +704,12 @@ extern int do_sysinfo(struct sysinfo *info); | |||
659 | 704 | ||
660 | #endif /* __KERNEL__ */ | 705 | #endif /* __KERNEL__ */ |
661 | 706 | ||
707 | #ifndef __EXPORTED_HEADERS__ | ||
708 | #ifndef __KERNEL__ | ||
709 | #warning Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders | ||
710 | #endif /* __KERNEL__ */ | ||
711 | #endif /* __EXPORTED_HEADERS__ */ | ||
712 | |||
662 | #define SI_LOAD_SHIFT 16 | 713 | #define SI_LOAD_SHIFT 16 |
663 | struct sysinfo { | 714 | struct sysinfo { |
664 | long uptime; /* Seconds since boot */ | 715 | long uptime; /* Seconds since boot */ |
@@ -683,6 +734,10 @@ struct sysinfo { | |||
683 | /* Force a compilation error if condition is constant and true */ | 734 | /* Force a compilation error if condition is constant and true */ |
684 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) | 735 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) |
685 | 736 | ||
737 | /* Force a compilation error if a constant expression is not a power of 2 */ | ||
738 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | ||
739 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | ||
740 | |||
686 | /* Force a compilation error if condition is true, but also produce a | 741 | /* Force a compilation error if condition is true, but also produce a |
687 | result (of value 0 and type size_t), so the expression can be used | 742 | result (of value 0 and type size_t), so the expression can be used |
688 | e.g. in a structure initializer (or where-ever else comma expressions | 743 | e.g. in a structure initializer (or where-ever else comma expressions |