diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2b0a35e6bc69..450092c1e35f 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -58,7 +58,18 @@ extern const char linux_proc_banner[]; | |||
| 58 | 58 | ||
| 59 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) | 59 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
| 60 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | 60 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 61 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) | 61 | #define roundup(x, y) ( \ |
| 62 | { \ | ||
| 63 | typeof(y) __y = y; \ | ||
| 64 | (((x) + (__y - 1)) / __y) * __y; \ | ||
| 65 | } \ | ||
| 66 | ) | ||
| 67 | #define rounddown(x, y) ( \ | ||
| 68 | { \ | ||
| 69 | typeof(x) __x = (x); \ | ||
| 70 | __x - (__x % (y)); \ | ||
| 71 | } \ | ||
| 72 | ) | ||
| 62 | #define DIV_ROUND_CLOSEST(x, divisor)( \ | 73 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
| 63 | { \ | 74 | { \ |
| 64 | typeof(divisor) __divisor = divisor; \ | 75 | typeof(divisor) __divisor = divisor; \ |
| @@ -162,6 +173,11 @@ extern int _cond_resched(void); | |||
| 162 | (__x < 0) ? -__x : __x; \ | 173 | (__x < 0) ? -__x : __x; \ |
| 163 | }) | 174 | }) |
| 164 | 175 | ||
| 176 | #define abs64(x) ({ \ | ||
| 177 | s64 __x = (x); \ | ||
| 178 | (__x < 0) ? -__x : __x; \ | ||
| 179 | }) | ||
| 180 | |||
| 165 | #ifdef CONFIG_PROVE_LOCKING | 181 | #ifdef CONFIG_PROVE_LOCKING |
| 166 | void might_fault(void); | 182 | void might_fault(void); |
| 167 | #else | 183 | #else |
| @@ -192,10 +208,10 @@ extern unsigned long simple_strtoul(const char *,char **,unsigned int); | |||
| 192 | extern long simple_strtol(const char *,char **,unsigned int); | 208 | extern long simple_strtol(const char *,char **,unsigned int); |
| 193 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); | 209 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
| 194 | extern long long simple_strtoll(const char *,char **,unsigned int); | 210 | extern long long simple_strtoll(const char *,char **,unsigned int); |
| 195 | extern int strict_strtoul(const char *, unsigned int, unsigned long *); | 211 | extern int __must_check strict_strtoul(const char *, unsigned int, unsigned long *); |
| 196 | extern int strict_strtol(const char *, unsigned int, long *); | 212 | extern int __must_check strict_strtol(const char *, unsigned int, long *); |
| 197 | extern int strict_strtoull(const char *, unsigned int, unsigned long long *); | 213 | extern int __must_check strict_strtoull(const char *, unsigned int, unsigned long long *); |
| 198 | extern int strict_strtoll(const char *, unsigned int, long long *); | 214 | extern int __must_check strict_strtoll(const char *, unsigned int, long long *); |
| 199 | extern int sprintf(char * buf, const char * fmt, ...) | 215 | extern int sprintf(char * buf, const char * fmt, ...) |
| 200 | __attribute__ ((format (printf, 2, 3))); | 216 | __attribute__ ((format (printf, 2, 3))); |
| 201 | extern int vsprintf(char *buf, const char *, va_list) | 217 | extern int vsprintf(char *buf, const char *, va_list) |
| @@ -266,6 +282,11 @@ asmlinkage int vprintk(const char *fmt, va_list args) | |||
| 266 | asmlinkage int printk(const char * fmt, ...) | 282 | asmlinkage int printk(const char * fmt, ...) |
| 267 | __attribute__ ((format (printf, 1, 2))) __cold; | 283 | __attribute__ ((format (printf, 1, 2))) __cold; |
| 268 | 284 | ||
| 285 | /* | ||
| 286 | * Please don't use printk_ratelimit(), because it shares ratelimiting state | ||
| 287 | * with all other unrelated printk_ratelimit() callsites. Instead use | ||
| 288 | * printk_ratelimited() or plain old __ratelimit(). | ||
| 289 | */ | ||
| 269 | extern int __printk_ratelimit(const char *func); | 290 | extern int __printk_ratelimit(const char *func); |
| 270 | #define printk_ratelimit() __printk_ratelimit(__func__) | 291 | #define printk_ratelimit() __printk_ratelimit(__func__) |
| 271 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | 292 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| @@ -640,6 +661,34 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
| 640 | (void) (&_max1 == &_max2); \ | 661 | (void) (&_max1 == &_max2); \ |
| 641 | _max1 > _max2 ? _max1 : _max2; }) | 662 | _max1 > _max2 ? _max1 : _max2; }) |
| 642 | 663 | ||
| 664 | #define min3(x, y, z) ({ \ | ||
| 665 | typeof(x) _min1 = (x); \ | ||
| 666 | typeof(y) _min2 = (y); \ | ||
| 667 | typeof(z) _min3 = (z); \ | ||
| 668 | (void) (&_min1 == &_min2); \ | ||
| 669 | (void) (&_min1 == &_min3); \ | ||
| 670 | _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ | ||
| 671 | (_min2 < _min3 ? _min2 : _min3); }) | ||
| 672 | |||
| 673 | #define max3(x, y, z) ({ \ | ||
| 674 | typeof(x) _max1 = (x); \ | ||
| 675 | typeof(y) _max2 = (y); \ | ||
| 676 | typeof(z) _max3 = (z); \ | ||
| 677 | (void) (&_max1 == &_max2); \ | ||
| 678 | (void) (&_max1 == &_max3); \ | ||
| 679 | _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ | ||
| 680 | (_max2 > _max3 ? _max2 : _max3); }) | ||
| 681 | |||
| 682 | /** | ||
| 683 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero | ||
| 684 | * @x: value1 | ||
| 685 | * @y: value2 | ||
| 686 | */ | ||
| 687 | #define min_not_zero(x, y) ({ \ | ||
| 688 | typeof(x) __x = (x); \ | ||
| 689 | typeof(y) __y = (y); \ | ||
| 690 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) | ||
| 691 | |||
| 643 | /** | 692 | /** |
| 644 | * clamp - return a value clamped to a given range with strict typechecking | 693 | * clamp - return a value clamped to a given range with strict typechecking |
| 645 | * @val: current value | 694 | * @val: current value |
