1 #ifndef PERF_LINUX_KERNEL_H_
2 #define PERF_LINUX_KERNEL_H_
9 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
11 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
12 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
15 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
20 * container_of - cast a member of a structure out to the containing structure
21 * @ptr: the pointer to the member.
22 * @type: the type of the container struct this is embedded in.
23 * @member: the name of the member within the struct.
26 #define container_of(ptr, type, member) ({ \
27 const typeof(((type *)0)->member) * __mptr = (ptr); \
28 (type *)((char *)__mptr - offsetof(type, member)); })
32 #define max(x, y) ({ \
33 typeof(x) _max1 = (x); \
34 typeof(y) _max2 = (y); \
35 (void) (&_max1 == &_max2); \
36 _max1 > _max2 ? _max1 : _max2; })
40 #define min(x, y) ({ \
41 typeof(x) _min1 = (x); \
42 typeof(y) _min2 = (y); \
43 (void) (&_min1 == &_min2); \
44 _min1 < _min2 ? _min1 : _min2; })
48 #define BUG_ON(cond) assert(!(cond))
52 * Both need more care to handle endianness
53 * (Don't use bitmap_copy_le() for now)
55 #define cpu_to_le64(x) (x)
56 #define cpu_to_le32(x) (x)
59 vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
64 i = vsnprintf(buf, size, fmt, args);
66 return (i >= ssize) ? (ssize - 1) : i;
69 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
76 i = vsnprintf(buf, size, fmt, args);
79 return (i >= ssize) ? (ssize - 1) : i;
82 static inline unsigned long
83 simple_strtoul(const char *nptr, char **endptr, int base)
85 return strtoul(nptr, endptr, base);
89 #define pr_fmt(fmt) fmt
92 #define pr_err(fmt, ...) \
93 do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
94 #define pr_warning(fmt, ...) \
95 do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
96 #define pr_info(fmt, ...) \
97 do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
98 #define pr_debug(fmt, ...) \
99 eprintf(1, pr_fmt(fmt), ##__VA_ARGS__)
100 #define pr_debugN(n, fmt, ...) \
101 eprintf(n, pr_fmt(fmt), ##__VA_ARGS__)
102 #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
103 #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)
104 #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)