aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /include/linux/kernel.h
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h454
1 files changed, 204 insertions, 250 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2b0a35e6bc69..953352a88336 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -17,13 +17,11 @@
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/log2.h> 18#include <linux/log2.h>
19#include <linux/typecheck.h> 19#include <linux/typecheck.h>
20#include <linux/printk.h>
20#include <linux/dynamic_debug.h> 21#include <linux/dynamic_debug.h>
21#include <asm/byteorder.h> 22#include <asm/byteorder.h>
22#include <asm/bug.h> 23#include <asm/bug.h>
23 24
24extern const char linux_banner[];
25extern const char linux_proc_banner[];
26
27#define USHRT_MAX ((u16)(~0U)) 25#define USHRT_MAX ((u16)(~0U))
28#define SHRT_MAX ((s16)(USHRT_MAX>>1)) 26#define SHRT_MAX ((s16)(USHRT_MAX>>1))
29#define SHRT_MIN ((s16)(-SHRT_MAX - 1)) 27#define SHRT_MIN ((s16)(-SHRT_MAX - 1))
@@ -58,7 +56,20 @@ extern const char linux_proc_banner[];
58 56
59#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) 57#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
60#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 58#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
61#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) 59
60/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
61#define roundup(x, y) ( \
62{ \
63 const 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; \
@@ -99,31 +110,6 @@ extern const char linux_proc_banner[];
99 */ 110 */
100#define lower_32_bits(n) ((u32)(n)) 111#define lower_32_bits(n) ((u32)(n))
101 112
102#define KERN_EMERG "<0>" /* system is unusable */
103#define KERN_ALERT "<1>" /* action must be taken immediately */
104#define KERN_CRIT "<2>" /* critical conditions */
105#define KERN_ERR "<3>" /* error conditions */
106#define KERN_WARNING "<4>" /* warning conditions */
107#define KERN_NOTICE "<5>" /* normal but significant condition */
108#define KERN_INFO "<6>" /* informational */
109#define KERN_DEBUG "<7>" /* debug-level messages */
110
111/* Use the default kernel loglevel */
112#define KERN_DEFAULT "<d>"
113/*
114 * Annotation for a "continued" line of log printout (only done after a
115 * line that had no enclosing \n). Only to be used by core/arch code
116 * during early bootup (a continued line is not SMP-safe otherwise).
117 */
118#define KERN_CONT "<c>"
119
120extern int console_printk[];
121
122#define console_loglevel (console_printk[0])
123#define default_message_loglevel (console_printk[1])
124#define minimum_console_loglevel (console_printk[2])
125#define default_console_loglevel (console_printk[3])
126
127struct completion; 113struct completion;
128struct pt_regs; 114struct pt_regs;
129struct user; 115struct user;
@@ -157,8 +143,26 @@ extern int _cond_resched(void);
157 143
158#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) 144#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
159 145
160#define abs(x) ({ \ 146/*
161 long __x = (x); \ 147 * abs() handles unsigned and signed longs, ints, shorts and chars. For all
148 * input types abs() returns a signed long.
149 * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
150 * for those.
151 */
152#define abs(x) ({ \
153 long ret; \
154 if (sizeof(x) == sizeof(long)) { \
155 long __x = (x); \
156 ret = (__x < 0) ? -__x : __x; \
157 } else { \
158 int __x = (x); \
159 ret = (__x < 0) ? -__x : __x; \
160 } \
161 ret; \
162 })
163
164#define abs64(x) ({ \
165 s64 __x = (x); \
162 (__x < 0) ? -__x : __x; \ 166 (__x < 0) ? -__x : __x; \
163 }) 167 })
164 168
@@ -171,11 +175,6 @@ static inline void might_fault(void)
171} 175}
172#endif 176#endif
173 177
174struct va_format {
175 const char *fmt;
176 va_list *va;
177};
178
179extern struct atomic_notifier_head panic_notifier_list; 178extern struct atomic_notifier_head panic_notifier_list;
180extern long (*panic_blink)(int state); 179extern long (*panic_blink)(int state);
181NORET_TYPE void panic(const char * fmt, ...) 180NORET_TYPE void panic(const char * fmt, ...)
@@ -188,14 +187,107 @@ NORET_TYPE void do_exit(long error_code)
188 ATTRIB_NORET; 187 ATTRIB_NORET;
189NORET_TYPE void complete_and_exit(struct completion *, long) 188NORET_TYPE void complete_and_exit(struct completion *, long)
190 ATTRIB_NORET; 189 ATTRIB_NORET;
190
191/* Internal, do not use. */
192int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
193int __must_check _kstrtol(const char *s, unsigned int base, long *res);
194
195int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
196int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
197static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
198{
199 /*
200 * We want to shortcut function call, but
201 * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
202 */
203 if (sizeof(unsigned long) == sizeof(unsigned long long) &&
204 __alignof__(unsigned long) == __alignof__(unsigned long long))
205 return kstrtoull(s, base, (unsigned long long *)res);
206 else
207 return _kstrtoul(s, base, res);
208}
209
210static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
211{
212 /*
213 * We want to shortcut function call, but
214 * __builtin_types_compatible_p(long, long long) = 0.
215 */
216 if (sizeof(long) == sizeof(long long) &&
217 __alignof__(long) == __alignof__(long long))
218 return kstrtoll(s, base, (long long *)res);
219 else
220 return _kstrtol(s, base, res);
221}
222
223int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
224int __must_check kstrtoint(const char *s, unsigned int base, int *res);
225
226static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
227{
228 return kstrtoull(s, base, res);
229}
230
231static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
232{
233 return kstrtoll(s, base, res);
234}
235
236static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
237{
238 return kstrtouint(s, base, res);
239}
240
241static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
242{
243 return kstrtoint(s, base, res);
244}
245
246int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
247int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
248int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
249int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
250
251int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
252int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
253int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
254int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
255int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
256int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
257int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
258int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
259int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
260int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
261
262static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
263{
264 return kstrtoull_from_user(s, count, base, res);
265}
266
267static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
268{
269 return kstrtoll_from_user(s, count, base, res);
270}
271
272static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
273{
274 return kstrtouint_from_user(s, count, base, res);
275}
276
277static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
278{
279 return kstrtoint_from_user(s, count, base, res);
280}
281
191extern unsigned long simple_strtoul(const char *,char **,unsigned int); 282extern unsigned long simple_strtoul(const char *,char **,unsigned int);
192extern long simple_strtol(const char *,char **,unsigned int); 283extern long simple_strtol(const char *,char **,unsigned int);
193extern unsigned long long simple_strtoull(const char *,char **,unsigned int); 284extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
194extern long long simple_strtoll(const char *,char **,unsigned int); 285extern long long simple_strtoll(const char *,char **,unsigned int);
195extern int strict_strtoul(const char *, unsigned int, unsigned long *); 286#define strict_strtoul kstrtoul
196extern int strict_strtol(const char *, unsigned int, long *); 287#define strict_strtol kstrtol
197extern int strict_strtoull(const char *, unsigned int, unsigned long long *); 288#define strict_strtoull kstrtoull
198extern int strict_strtoll(const char *, unsigned int, long long *); 289#define strict_strtoll kstrtoll
290
199extern int sprintf(char * buf, const char * fmt, ...) 291extern int sprintf(char * buf, const char * fmt, ...)
200 __attribute__ ((format (printf, 2, 3))); 292 __attribute__ ((format (printf, 2, 3)));
201extern int vsprintf(char *buf, const char *, va_list) 293extern int vsprintf(char *buf, const char *, va_list)
@@ -222,6 +314,7 @@ extern char *get_options(const char *str, int nints, int *ints);
222extern unsigned long long memparse(const char *ptr, char **retptr); 314extern unsigned long long memparse(const char *ptr, char **retptr);
223 315
224extern int core_kernel_text(unsigned long addr); 316extern int core_kernel_text(unsigned long addr);
317extern int core_kernel_data(unsigned long addr);
225extern int __kernel_text_address(unsigned long addr); 318extern int __kernel_text_address(unsigned long addr);
226extern int kernel_text_address(unsigned long addr); 319extern int kernel_text_address(unsigned long addr);
227extern int func_ptr_is_kernel_text(void *ptr); 320extern int func_ptr_is_kernel_text(void *ptr);
@@ -229,109 +322,8 @@ extern int func_ptr_is_kernel_text(void *ptr);
229struct pid; 322struct pid;
230extern struct pid *session_of_pgrp(struct pid *pgrp); 323extern struct pid *session_of_pgrp(struct pid *pgrp);
231 324
232/*
233 * FW_BUG
234 * Add this to a message where you are sure the firmware is buggy or behaves
235 * really stupid or out of spec. Be aware that the responsible BIOS developer
236 * should be able to fix this issue or at least get a concrete idea of the
237 * problem by reading your message without the need of looking at the kernel
238 * code.
239 *
240 * Use it for definite and high priority BIOS bugs.
241 *
242 * FW_WARN
243 * Use it for not that clear (e.g. could the kernel messed up things already?)
244 * and medium priority BIOS bugs.
245 *
246 * FW_INFO
247 * Use this one if you want to tell the user or vendor about something
248 * suspicious, but generally harmless related to the firmware.
249 *
250 * Use it for information or very low priority BIOS bugs.
251 */
252#define FW_BUG "[Firmware Bug]: "
253#define FW_WARN "[Firmware Warn]: "
254#define FW_INFO "[Firmware Info]: "
255
256/*
257 * HW_ERR
258 * Add this to a message for hardware errors, so that user can report
259 * it to hardware vendor instead of LKML or software vendor.
260 */
261#define HW_ERR "[Hardware Error]: "
262
263#ifdef CONFIG_PRINTK
264asmlinkage int vprintk(const char *fmt, va_list args)
265 __attribute__ ((format (printf, 1, 0)));
266asmlinkage int printk(const char * fmt, ...)
267 __attribute__ ((format (printf, 1, 2))) __cold;
268
269extern int __printk_ratelimit(const char *func);
270#define printk_ratelimit() __printk_ratelimit(__func__)
271extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
272 unsigned int interval_msec);
273
274extern int printk_delay_msec;
275
276/*
277 * Print a one-time message (analogous to WARN_ONCE() et al):
278 */
279#define printk_once(x...) ({ \
280 static bool __print_once; \
281 \
282 if (!__print_once) { \
283 __print_once = true; \
284 printk(x); \
285 } \
286})
287
288void log_buf_kexec_setup(void);
289#else
290static inline int vprintk(const char *s, va_list args)
291 __attribute__ ((format (printf, 1, 0)));
292static inline int vprintk(const char *s, va_list args) { return 0; }
293static inline int printk(const char *s, ...)
294 __attribute__ ((format (printf, 1, 2)));
295static inline int __cold printk(const char *s, ...) { return 0; }
296static inline int printk_ratelimit(void) { return 0; }
297static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
298 unsigned int interval_msec) \
299 { return false; }
300
301/* No effect, but we still get type checking even in the !PRINTK case: */
302#define printk_once(x...) printk(x)
303
304static inline void log_buf_kexec_setup(void)
305{
306}
307#endif
308
309/*
310 * Dummy printk for disabled debugging statements to use whilst maintaining
311 * gcc's format and side-effect checking.
312 */
313static inline __attribute__ ((format (printf, 1, 2)))
314int no_printk(const char *s, ...) { return 0; }
315
316extern int printk_needs_cpu(int cpu);
317extern void printk_tick(void);
318
319extern void asmlinkage __attribute__((format(printf, 1, 2)))
320 early_printk(const char *fmt, ...);
321
322unsigned long int_sqrt(unsigned long); 325unsigned long int_sqrt(unsigned long);
323 326
324static inline void console_silent(void)
325{
326 console_loglevel = 0;
327}
328
329static inline void console_verbose(void)
330{
331 if (console_loglevel)
332 console_loglevel = 15;
333}
334
335extern void bust_spinlocks(int yes); 327extern void bust_spinlocks(int yes);
336extern void wake_up_klogd(void); 328extern void wake_up_klogd(void);
337extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 329extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
@@ -345,6 +337,8 @@ extern int test_taint(unsigned flag);
345extern unsigned long get_taint(void); 337extern unsigned long get_taint(void);
346extern int root_mountflags; 338extern int root_mountflags;
347 339
340extern bool early_boot_irqs_disabled;
341
348/* Values used for system_state */ 342/* Values used for system_state */
349extern enum system_states { 343extern enum system_states {
350 SYSTEM_BOOTING, 344 SYSTEM_BOOTING,
@@ -368,22 +362,6 @@ extern enum system_states {
368#define TAINT_CRAP 10 362#define TAINT_CRAP 10
369#define TAINT_FIRMWARE_WORKAROUND 11 363#define TAINT_FIRMWARE_WORKAROUND 11
370 364
371extern void dump_stack(void) __cold;
372
373enum {
374 DUMP_PREFIX_NONE,
375 DUMP_PREFIX_ADDRESS,
376 DUMP_PREFIX_OFFSET
377};
378extern void hex_dump_to_buffer(const void *buf, size_t len,
379 int rowsize, int groupsize,
380 char *linebuf, size_t linebuflen, bool ascii);
381extern void print_hex_dump(const char *level, const char *prefix_str,
382 int prefix_type, int rowsize, int groupsize,
383 const void *buf, size_t len, bool ascii);
384extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
385 const void *buf, size_t len);
386
387extern const char hex_asc[]; 365extern const char hex_asc[];
388#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] 366#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
389#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] 367#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
@@ -396,94 +374,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
396} 374}
397 375
398extern int hex_to_bin(char ch); 376extern int hex_to_bin(char ch);
399 377extern void hex2bin(u8 *dst, const char *src, size_t count);
400#ifndef pr_fmt
401#define pr_fmt(fmt) fmt
402#endif
403
404#define pr_emerg(fmt, ...) \
405 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
406#define pr_alert(fmt, ...) \
407 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
408#define pr_crit(fmt, ...) \
409 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
410#define pr_err(fmt, ...) \
411 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
412#define pr_warning(fmt, ...) \
413 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
414#define pr_warn pr_warning
415#define pr_notice(fmt, ...) \
416 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
417#define pr_info(fmt, ...) \
418 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
419#define pr_cont(fmt, ...) \
420 printk(KERN_CONT fmt, ##__VA_ARGS__)
421
422/* pr_devel() should produce zero code unless DEBUG is defined */
423#ifdef DEBUG
424#define pr_devel(fmt, ...) \
425 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
426#else
427#define pr_devel(fmt, ...) \
428 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
429#endif
430
431/* If you are writing a driver, please use dev_dbg instead */
432#if defined(DEBUG)
433#define pr_debug(fmt, ...) \
434 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
435#elif defined(CONFIG_DYNAMIC_DEBUG)
436/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
437#define pr_debug(fmt, ...) \
438 dynamic_pr_debug(fmt, ##__VA_ARGS__)
439#else
440#define pr_debug(fmt, ...) \
441 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
442#endif
443
444/*
445 * ratelimited messages with local ratelimit_state,
446 * no local ratelimit_state used in the !PRINTK case
447 */
448#ifdef CONFIG_PRINTK
449#define printk_ratelimited(fmt, ...) ({ \
450 static DEFINE_RATELIMIT_STATE(_rs, \
451 DEFAULT_RATELIMIT_INTERVAL, \
452 DEFAULT_RATELIMIT_BURST); \
453 \
454 if (__ratelimit(&_rs)) \
455 printk(fmt, ##__VA_ARGS__); \
456})
457#else
458/* No effect, but we still get type checking even in the !PRINTK case: */
459#define printk_ratelimited printk
460#endif
461
462#define pr_emerg_ratelimited(fmt, ...) \
463 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
464#define pr_alert_ratelimited(fmt, ...) \
465 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
466#define pr_crit_ratelimited(fmt, ...) \
467 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
468#define pr_err_ratelimited(fmt, ...) \
469 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
470#define pr_warning_ratelimited(fmt, ...) \
471 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
472#define pr_warn_ratelimited pr_warning_ratelimited
473#define pr_notice_ratelimited(fmt, ...) \
474 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
475#define pr_info_ratelimited(fmt, ...) \
476 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
477/* no pr_cont_ratelimited, don't do that... */
478/* If you are writing a driver, please use dev_dbg instead */
479#if defined(DEBUG)
480#define pr_debug_ratelimited(fmt, ...) \
481 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
482#else
483#define pr_debug_ratelimited(fmt, ...) \
484 ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
485 ##__VA_ARGS__); 0; })
486#endif
487 378
488/* 379/*
489 * General tracing related utility functions - trace_printk(), 380 * General tracing related utility functions - trace_printk(),
@@ -640,6 +531,34 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
640 (void) (&_max1 == &_max2); \ 531 (void) (&_max1 == &_max2); \
641 _max1 > _max2 ? _max1 : _max2; }) 532 _max1 > _max2 ? _max1 : _max2; })
642 533
534#define min3(x, y, z) ({ \
535 typeof(x) _min1 = (x); \
536 typeof(y) _min2 = (y); \
537 typeof(z) _min3 = (z); \
538 (void) (&_min1 == &_min2); \
539 (void) (&_min1 == &_min3); \
540 _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
541 (_min2 < _min3 ? _min2 : _min3); })
542
543#define max3(x, y, z) ({ \
544 typeof(x) _max1 = (x); \
545 typeof(y) _max2 = (y); \
546 typeof(z) _max3 = (z); \
547 (void) (&_max1 == &_max2); \
548 (void) (&_max1 == &_max3); \
549 _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
550 (_max2 > _max3 ? _max2 : _max3); })
551
552/**
553 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
554 * @x: value1
555 * @y: value2
556 */
557#define min_not_zero(x, y) ({ \
558 typeof(x) __x = (x); \
559 typeof(y) __y = (y); \
560 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
561
643/** 562/**
644 * clamp - return a value clamped to a given range with strict typechecking 563 * clamp - return a value clamped to a given range with strict typechecking
645 * @val: current value 564 * @val: current value
@@ -750,11 +669,12 @@ struct sysinfo {
750 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ 669 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
751}; 670};
752 671
753/* Force a compilation error if condition is true */ 672#ifdef __CHECKER__
754#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) 673#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
755 674#define BUILD_BUG_ON_ZERO(e) (0)
756/* Force a compilation error if condition is constant and true */ 675#define BUILD_BUG_ON_NULL(e) ((void*)0)
757#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) 676#define BUILD_BUG_ON(condition)
677#else /* __CHECKER__ */
758 678
759/* Force a compilation error if a constant expression is not a power of 2 */ 679/* Force a compilation error if a constant expression is not a power of 2 */
760#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ 680#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
@@ -767,6 +687,33 @@ struct sysinfo {
767#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 687#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
768#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) 688#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
769 689
690/**
691 * BUILD_BUG_ON - break compile if a condition is true.
692 * @condition: the condition which the compiler should know is false.
693 *
694 * If you have some code which relies on certain constants being equal, or
695 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
696 * detect if someone changes it.
697 *
698 * The implementation uses gcc's reluctance to create a negative array, but
699 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
700 * to inline functions). So as a fallback we use the optimizer; if it can't
701 * prove the condition is false, it will cause a link error on the undefined
702 * "__build_bug_on_failed". This error message can be harder to track down
703 * though, hence the two different methods.
704 */
705#ifndef __OPTIMIZE__
706#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
707#else
708extern int __build_bug_on_failed;
709#define BUILD_BUG_ON(condition) \
710 do { \
711 ((void)sizeof(char[1 - 2*!!(condition)])); \
712 if (condition) __build_bug_on_failed = 1; \
713 } while(0)
714#endif
715#endif /* __CHECKER__ */
716
770/* Trap pasters of __FUNCTION__ at compile-time */ 717/* Trap pasters of __FUNCTION__ at compile-time */
771#define __FUNCTION__ (__func__) 718#define __FUNCTION__ (__func__)
772 719
@@ -777,6 +724,13 @@ struct sysinfo {
777#define NUMA_BUILD 0 724#define NUMA_BUILD 0
778#endif 725#endif
779 726
727/* This helps us avoid #ifdef CONFIG_COMPACTION */
728#ifdef CONFIG_COMPACTION
729#define COMPACTION_BUILD 1
730#else
731#define COMPACTION_BUILD 0
732#endif
733
780/* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ 734/* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
781#ifdef CONFIG_FTRACE_MCOUNT_RECORD 735#ifdef CONFIG_FTRACE_MCOUNT_RECORD
782# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD 736# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD