kvm tools, setup: Create private directory
[linux-2.6/next.git] / tools / perf / util / include / linux / kernel.h
blob1eb804fd3fbff078baa9e70f57d850676607c1b9
1 #ifndef PERF_LINUX_KERNEL_H_
2 #define PERF_LINUX_KERNEL_H_
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <assert.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))
14 #ifndef offsetof
15 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
16 #endif
18 #ifndef container_of
19 /**
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)); })
29 #endif
31 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
33 #ifndef max
34 #define max(x, y) ({ \
35 typeof(x) _max1 = (x); \
36 typeof(y) _max2 = (y); \
37 (void) (&_max1 == &_max2); \
38 _max1 > _max2 ? _max1 : _max2; })
39 #endif
41 #ifndef min
42 #define min(x, y) ({ \
43 typeof(x) _min1 = (x); \
44 typeof(y) _min2 = (y); \
45 (void) (&_min1 == &_min2); \
46 _min1 < _min2 ? _min1 : _min2; })
47 #endif
49 #ifndef BUG_ON
50 #define BUG_ON(cond) assert(!(cond))
51 #endif
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)
60 static inline int
61 vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
63 int i;
64 ssize_t ssize = size;
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, ...)
73 va_list args;
74 ssize_t ssize = size;
75 int i;
77 va_start(args, fmt);
78 i = vsnprintf(buf, size, fmt, args);
79 va_end(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)));
93 #ifndef pr_fmt
94 #define pr_fmt(fmt) fmt
95 #endif
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__)
111 #endif