diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 82 |
1 files changed, 71 insertions, 11 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index f4e3184fa054..9365227dbaf6 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> |
| @@ -45,6 +44,16 @@ extern const char linux_proc_banner[]; | |||
| 45 | 44 | ||
| 46 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) | 45 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
| 47 | 46 | ||
| 47 | /* | ||
| 48 | * This looks more complex than it should be. But we need to | ||
| 49 | * get the type for the ~ right in round_down (it needs to be | ||
| 50 | * as wide as the result!), and we want to evaluate the macro | ||
| 51 | * arguments just once each. | ||
| 52 | */ | ||
| 53 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) | ||
| 54 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) | ||
| 55 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) | ||
| 56 | |||
| 48 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) | 57 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
| 49 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | 58 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 50 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) | 59 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
| @@ -125,7 +134,7 @@ extern int _cond_resched(void); | |||
| 125 | #endif | 134 | #endif |
| 126 | 135 | ||
| 127 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP | 136 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP |
| 128 | void __might_sleep(char *file, int line, int preempt_offset); | 137 | void __might_sleep(const char *file, int line, int preempt_offset); |
| 129 | /** | 138 | /** |
| 130 | * might_sleep - annotation for functions that can sleep | 139 | * might_sleep - annotation for functions that can sleep |
| 131 | * | 140 | * |
| @@ -139,7 +148,8 @@ extern int _cond_resched(void); | |||
| 139 | # define might_sleep() \ | 148 | # define might_sleep() \ |
| 140 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) | 149 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
| 141 | #else | 150 | #else |
| 142 | static inline void __might_sleep(char *file, int line, int preempt_offset) { } | 151 | static inline void __might_sleep(const char *file, int line, |
| 152 | int preempt_offset) { } | ||
| 143 | # define might_sleep() do { might_resched(); } while (0) | 153 | # define might_sleep() do { might_resched(); } while (0) |
| 144 | #endif | 154 | #endif |
| 145 | 155 | ||
| @@ -241,8 +251,8 @@ asmlinkage int vprintk(const char *fmt, va_list args) | |||
| 241 | asmlinkage int printk(const char * fmt, ...) | 251 | asmlinkage int printk(const char * fmt, ...) |
| 242 | __attribute__ ((format (printf, 1, 2))) __cold; | 252 | __attribute__ ((format (printf, 1, 2))) __cold; |
| 243 | 253 | ||
| 244 | extern struct ratelimit_state printk_ratelimit_state; | 254 | extern int __printk_ratelimit(const char *func); |
| 245 | extern int printk_ratelimit(void); | 255 | #define printk_ratelimit() __printk_ratelimit(__func__) |
| 246 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | 256 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 247 | unsigned int interval_msec); | 257 | unsigned int interval_msec); |
| 248 | 258 | ||
| @@ -252,10 +262,10 @@ extern int printk_delay_msec; | |||
| 252 | * Print a one-time message (analogous to WARN_ONCE() et al): | 262 | * Print a one-time message (analogous to WARN_ONCE() et al): |
| 253 | */ | 263 | */ |
| 254 | #define printk_once(x...) ({ \ | 264 | #define printk_once(x...) ({ \ |
| 255 | static bool __print_once = true; \ | 265 | static bool __print_once; \ |
| 256 | \ | 266 | \ |
| 257 | if (__print_once) { \ | 267 | if (!__print_once) { \ |
| 258 | __print_once = false; \ | 268 | __print_once = true; \ |
| 259 | printk(x); \ | 269 | printk(x); \ |
| 260 | } \ | 270 | } \ |
| 261 | }) | 271 | }) |
| @@ -398,15 +408,58 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 398 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | 408 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) |
| 399 | #elif defined(CONFIG_DYNAMIC_DEBUG) | 409 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
| 400 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ | 410 | /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ |
| 401 | #define pr_debug(fmt, ...) do { \ | 411 | #define pr_debug(fmt, ...) \ |
| 402 | dynamic_pr_debug(fmt, ##__VA_ARGS__); \ | 412 | dynamic_pr_debug(fmt, ##__VA_ARGS__) |
| 403 | } while (0) | ||
| 404 | #else | 413 | #else |
| 405 | #define pr_debug(fmt, ...) \ | 414 | #define pr_debug(fmt, ...) \ |
| 406 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) | 415 | ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) |
| 407 | #endif | 416 | #endif |
| 408 | 417 | ||
| 409 | /* | 418 | /* |
| 419 | * ratelimited messages with local ratelimit_state, | ||
| 420 | * no local ratelimit_state used in the !PRINTK case | ||
| 421 | */ | ||
| 422 | #ifdef CONFIG_PRINTK | ||
| 423 | #define printk_ratelimited(fmt, ...) ({ \ | ||
| 424 | static struct ratelimit_state _rs = { \ | ||
| 425 | .interval = DEFAULT_RATELIMIT_INTERVAL, \ | ||
| 426 | .burst = DEFAULT_RATELIMIT_BURST, \ | ||
| 427 | }; \ | ||
| 428 | \ | ||
| 429 | if (__ratelimit(&_rs)) \ | ||
| 430 | printk(fmt, ##__VA_ARGS__); \ | ||
| 431 | }) | ||
| 432 | #else | ||
| 433 | /* No effect, but we still get type checking even in the !PRINTK case: */ | ||
| 434 | #define printk_ratelimited printk | ||
| 435 | #endif | ||
| 436 | |||
| 437 | #define pr_emerg_ratelimited(fmt, ...) \ | ||
| 438 | printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) | ||
| 439 | #define pr_alert_ratelimited(fmt, ...) \ | ||
| 440 | printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) | ||
| 441 | #define pr_crit_ratelimited(fmt, ...) \ | ||
| 442 | printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) | ||
| 443 | #define pr_err_ratelimited(fmt, ...) \ | ||
| 444 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | ||
| 445 | #define pr_warning_ratelimited(fmt, ...) \ | ||
| 446 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | ||
| 447 | #define pr_notice_ratelimited(fmt, ...) \ | ||
| 448 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | ||
| 449 | #define pr_info_ratelimited(fmt, ...) \ | ||
| 450 | printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | ||
| 451 | /* no pr_cont_ratelimited, don't do that... */ | ||
| 452 | /* If you are writing a driver, please use dev_dbg instead */ | ||
| 453 | #if defined(DEBUG) | ||
| 454 | #define pr_debug_ratelimited(fmt, ...) \ | ||
| 455 | printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | ||
| 456 | #else | ||
| 457 | #define pr_debug_ratelimited(fmt, ...) \ | ||
| 458 | ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ | ||
| 459 | ##__VA_ARGS__); 0; }) | ||
| 460 | #endif | ||
| 461 | |||
| 462 | /* | ||
| 410 | * General tracing related utility functions - trace_printk(), | 463 | * General tracing related utility functions - trace_printk(), |
| 411 | * tracing_on/tracing_off and tracing_start()/tracing_stop | 464 | * tracing_on/tracing_off and tracing_start()/tracing_stop |
| 412 | * | 465 | * |
| @@ -493,6 +546,8 @@ extern int | |||
| 493 | __trace_printk(unsigned long ip, const char *fmt, ...) | 546 | __trace_printk(unsigned long ip, const char *fmt, ...) |
| 494 | __attribute__ ((format (printf, 2, 3))); | 547 | __attribute__ ((format (printf, 2, 3))); |
| 495 | 548 | ||
| 549 | extern void trace_dump_stack(void); | ||
| 550 | |||
| 496 | /* | 551 | /* |
| 497 | * The double __builtin_constant_p is because gcc will give us an error | 552 | * 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 | 553 | * if we try to allocate the static variable to fmt if it is not a |
| @@ -526,6 +581,7 @@ trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); | |||
| 526 | static inline void tracing_start(void) { } | 581 | static inline void tracing_start(void) { } |
| 527 | static inline void tracing_stop(void) { } | 582 | static inline void tracing_stop(void) { } |
| 528 | static inline void ftrace_off_permanent(void) { } | 583 | static inline void ftrace_off_permanent(void) { } |
| 584 | static inline void trace_dump_stack(void) { } | ||
| 529 | static inline int | 585 | static inline int |
| 530 | trace_printk(const char *fmt, ...) | 586 | trace_printk(const char *fmt, ...) |
| 531 | { | 587 | { |
| @@ -689,6 +745,10 @@ struct sysinfo { | |||
| 689 | /* Force a compilation error if condition is constant and true */ | 745 | /* Force a compilation error if condition is constant and true */ |
| 690 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) | 746 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) |
| 691 | 747 | ||
| 748 | /* Force a compilation error if a constant expression is not a power of 2 */ | ||
| 749 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | ||
| 750 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | ||
| 751 | |||
| 692 | /* Force a compilation error if condition is true, but also produce a | 752 | /* Force a compilation error if condition is true, but also produce a |
| 693 | result (of value 0 and type size_t), so the expression can be used | 753 | result (of value 0 and type size_t), so the expression can be used |
| 694 | e.g. in a structure initializer (or where-ever else comma expressions | 754 | e.g. in a structure initializer (or where-ever else comma expressions |
