diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-06-01 03:37:47 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-02 14:27:04 -0400 |
commit | 37fbe0a4a0a9afe3b0fe843a4775a85ccf430deb (patch) | |
tree | f6b07c9ec73bd088b19337469c721d60c4a24cba /tools/include/linux/kernel.h | |
parent | 0443f36b0de026143a78c858aac773572f7dd5db (diff) |
perf tools: Move linux/kernel.h to tools/include
This patch moves kernel.h from tools/perf/util/include/linux/kernel.h
to tools/include/linux/kernel.h to enable other libraries use macros in
it, like libbpf which will be introduced by further patches.
MANIFEST is also updated for 'make perf-*-src-pkg'.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1433144296-74992-2-git-send-email-wangnan0@huawei.com
[ Fixed up the ifdef guard to match other entries in tools/include/linux ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include/linux/kernel.h')
-rw-r--r-- | tools/include/linux/kernel.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h new file mode 100644 index 000000000000..76df53539c2a --- /dev/null +++ b/tools/include/linux/kernel.h | |||
@@ -0,0 +1,107 @@ | |||
1 | #ifndef __TOOLS_LINUX_KERNEL_H | ||
2 | #define __TOOLS_LINUX_KERNEL_H | ||
3 | |||
4 | #include <stdarg.h> | ||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <assert.h> | ||
8 | |||
9 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | ||
10 | |||
11 | #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) | ||
12 | #define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | ||
13 | |||
14 | #ifndef offsetof | ||
15 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | ||
16 | #endif | ||
17 | |||
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. | ||
24 | * | ||
25 | */ | ||
26 | #define container_of(ptr, type, member) ({ \ | ||
27 | const typeof(((type *)0)->member) * __mptr = (ptr); \ | ||
28 | (type *)((char *)__mptr - offsetof(type, member)); }) | ||
29 | #endif | ||
30 | |||
31 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | ||
32 | |||
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 | ||
40 | |||
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 | ||
48 | |||
49 | #ifndef roundup | ||
50 | #define roundup(x, y) ( \ | ||
51 | { \ | ||
52 | const typeof(y) __y = y; \ | ||
53 | (((x) + (__y - 1)) / __y) * __y; \ | ||
54 | } \ | ||
55 | ) | ||
56 | #endif | ||
57 | |||
58 | #ifndef BUG_ON | ||
59 | #ifdef NDEBUG | ||
60 | #define BUG_ON(cond) do { if (cond) {} } while (0) | ||
61 | #else | ||
62 | #define BUG_ON(cond) assert(!(cond)) | ||
63 | #endif | ||
64 | #endif | ||
65 | |||
66 | /* | ||
67 | * Both need more care to handle endianness | ||
68 | * (Don't use bitmap_copy_le() for now) | ||
69 | */ | ||
70 | #define cpu_to_le64(x) (x) | ||
71 | #define cpu_to_le32(x) (x) | ||
72 | |||
73 | static inline int | ||
74 | vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | ||
75 | { | ||
76 | int i; | ||
77 | ssize_t ssize = size; | ||
78 | |||
79 | i = vsnprintf(buf, size, fmt, args); | ||
80 | |||
81 | return (i >= ssize) ? (ssize - 1) : i; | ||
82 | } | ||
83 | |||
84 | static inline int scnprintf(char * buf, size_t size, const char * fmt, ...) | ||
85 | { | ||
86 | va_list args; | ||
87 | ssize_t ssize = size; | ||
88 | int i; | ||
89 | |||
90 | va_start(args, fmt); | ||
91 | i = vsnprintf(buf, size, fmt, args); | ||
92 | va_end(args); | ||
93 | |||
94 | return (i >= ssize) ? (ssize - 1) : i; | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * This looks more complex than it should be. But we need to | ||
99 | * get the type for the ~ right in round_down (it needs to be | ||
100 | * as wide as the result!), and we want to evaluate the macro | ||
101 | * arguments just once each. | ||
102 | */ | ||
103 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) | ||
104 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) | ||
105 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) | ||
106 | |||
107 | #endif | ||