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)); })
31 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
34 #define max(x, y) ({ \
35 typeof(x) _max1 = (x); \
36 typeof(y) _max2 = (y); \
37 (void) (&_max1 == &_max2); \
38 _max1 > _max2 ? _max1 : _max2; })
42 #define min(x, y) ({ \
43 typeof(x) _min1 = (x); \
44 typeof(y) _min2 = (y); \
45 (void) (&_min1 == &_min2); \
46 _min1 < _min2 ? _min1 : _min2; })
50 #define BUG_ON(cond) assert(!(cond))
54 * Both need more care to handle endianness
55 * (Don't use bitmap_copy_le() for now)
57 #define cpu_to_le64(x) (x)
58 #define cpu_to_le32(x) (x)
61 vscnprintf(char *buf
, size_t size
, const char *fmt
, va_list args
)
66 i
= vsnprintf(buf
, size
, fmt
, args
);
68 return (i
>= ssize
) ? (ssize
- 1) : i
;
71 static inline int scnprintf(char * buf
, size_t size
, const char * fmt
, ...)
78 i
= vsnprintf(buf
, size
, fmt
, args
);
81 return (i
>= ssize
) ? (ssize
- 1) : i
;
84 static inline unsigned long
85 simple_strtoul(const char *nptr
, char **endptr
, int base
)
87 return strtoul(nptr
, endptr
, base
);
90 int eprintf(int level
,
91 const char *fmt
, ...) __attribute__((format(printf
, 2, 3)));
94 #define pr_fmt(fmt) fmt
97 #define pr_err(fmt, ...) \
98 eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
99 #define pr_warning(fmt, ...) \
100 eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
101 #define pr_info(fmt, ...) \
102 eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
103 #define pr_debug(fmt, ...) \
104 eprintf(1, pr_fmt(fmt), ##__VA_ARGS__)
105 #define pr_debugN(n, fmt, ...) \
106 eprintf(n, pr_fmt(fmt), ##__VA_ARGS__)
107 #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
108 #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)
109 #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)