ia64/xen-unstable

annotate xen/include/xen/lib.h @ 19473:2fa1d38097da

Use unlikely() in BUG_ON()/WARN_ON()

-fno-reorder-blocks was added in c/s 1712, when x86-64 just started to
become enabled. The reason it got added is entirely unclear to me, and
it prevents the intended effect of unlikely() constructs (in
particular
the ones added here) of moving out of line code which is expected to
never get executed, as well as using forward branches (which are
statically predicted taken by various processors' branch prediction
units) preferably to reach infrequently executed code.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 31 13:22:12 2009 +0100 (2009-03-31)
parents 372ec886ad0c
children 5369133d772c
rev   line source
kaf24@1210 1 #ifndef __LIB_H__
kaf24@1210 2 #define __LIB_H__
kaf24@1210 3
kaf24@4809 4 #include <xen/inttypes.h>
kfraser@11879 5 #include <xen/stdarg.h>
kaf24@3827 6 #include <xen/config.h>
kaf24@1210 7 #include <xen/types.h>
cl349@5285 8 #include <xen/xmalloc.h>
kaf24@1486 9 #include <xen/string.h>
kfraser@14021 10 #include <asm/bug.h>
kaf24@1210 11
kfraser@14021 12 void __bug(char *file, int line) __attribute__((noreturn));
kfraser@14590 13 void __warn(char *file, int line);
kfraser@14021 14
keir@19473 15 #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
keir@19473 16 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
kaf24@3848 17
kaf24@9878 18 /* Force a compilation error if condition is true */
keir@18909 19 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
kaf24@9878 20
kfraser@14054 21 #ifndef assert_failed
kfraser@14054 22 #define assert_failed(p) \
kfraser@14054 23 do { \
kfraser@14054 24 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
kfraser@14054 25 __LINE__, __FILE__); \
kfraser@14054 26 BUG(); \
kfraser@14054 27 } while (0)
kfraser@14054 28 #endif
kfraser@14054 29
kaf24@1210 30 #ifndef NDEBUG
kfraser@14054 31 #define ASSERT(p) \
kfraser@14054 32 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
kaf24@1210 33 #else
kfraser@14054 34 #define ASSERT(p) ((void)0)
kaf24@1210 35 #endif
kaf24@1210 36
kaf24@2635 37 #define SWAP(_a, _b) \
kaf24@2635 38 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
kaf24@2635 39
iap10@4606 40 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
arun@3920 41
kaf24@3354 42 #define reserve_bootmem(_p,_l) ((void)0)
kaf24@1210 43
cl349@2448 44 struct domain;
cl349@2448 45
kaf24@3338 46 void cmdline_parse(char *cmdline);
kaf24@3338 47
kfraser@11212 48 /*#define DEBUG_TRACE_DUMP*/
kfraser@11212 49 #ifdef DEBUG_TRACE_DUMP
kaf24@3875 50 extern void debugtrace_dump(void);
kaf24@3827 51 extern void debugtrace_printk(const char *fmt, ...);
kaf24@3827 52 #else
kaf24@3875 53 #define debugtrace_dump() ((void)0)
kaf24@3875 54 #define debugtrace_printk(_f, ...) ((void)0)
kaf24@3827 55 #endif
kaf24@3827 56
kaf24@4654 57 /* Allows us to use '%p' as general-purpose machine-word format char. */
kaf24@4654 58 #define _p(_x) ((void *)(unsigned long)(_x))
kfraser@11947 59 extern void printk(const char *format, ...)
kaf24@4654 60 __attribute__ ((format (printf, 1, 2)));
kaf24@9454 61 extern void panic(const char *format, ...)
kaf24@9454 62 __attribute__ ((format (printf, 1, 2)));
kaf24@4654 63 extern long vm_assist(struct domain *, unsigned int, unsigned int);
kaf24@12030 64 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
kaf24@12030 65 extern int printk_ratelimit(void);
kaf24@1210 66
kaf24@1210 67 /* vsprintf.c */
keir@13756 68 #define sprintf __xen_has_no_sprintf__
kfraser@13697 69 #define vsprintf __xen_has_no_vsprintf__
kaf24@1210 70 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@4654 71 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 72 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 73 __attribute__ ((format (printf, 3, 0)));
kaf24@8520 74 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@8520 75 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 76 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 77 __attribute__ ((format (printf, 3, 0)));
kfraser@15816 78 extern int sscanf(const char * buf, const char * fmt, ...)
kfraser@15816 79 __attribute__ ((format (scanf, 2, 3)));
kfraser@15816 80 extern int vsscanf(const char * buf, const char * fmt, va_list args)
kfraser@15816 81 __attribute__ ((format (scanf, 2, 0)));
kaf24@1210 82
kaf24@4850 83 long simple_strtol(
kfraser@13156 84 const char *cp,const char **endp, unsigned int base);
kaf24@4850 85 unsigned long simple_strtoul(
kfraser@13156 86 const char *cp,const char **endp, unsigned int base);
kaf24@4850 87 long long simple_strtoll(
kfraser@13156 88 const char *cp,const char **endp, unsigned int base);
kaf24@4850 89 unsigned long long simple_strtoull(
kfraser@13156 90 const char *cp,const char **endp, unsigned int base);
kaf24@4850 91
kfraser@13156 92 unsigned long long parse_size_and_unit(const char *s, const char **ps);
kaf24@1210 93
kaf24@8846 94 #define TAINT_UNSAFE_SMP (1<<0)
kaf24@8846 95 #define TAINT_MACHINE_CHECK (1<<1)
kaf24@8846 96 #define TAINT_BAD_PAGE (1<<2)
kaf24@10500 97 #define TAINT_SYNC_CONSOLE (1<<3)
keir@19373 98 #define TAINT_ERROR_INJECT (1<<4)
kaf24@8846 99 extern int tainted;
kaf24@8846 100 #define TAINT_STRING_MAX_LEN 20
kaf24@8846 101 extern char *print_tainted(char *str);
kaf24@8846 102 extern void add_taint(unsigned);
kaf24@8846 103
kaf24@1210 104 #endif /* __LIB_H__ */