diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-10-17 11:12:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-10-19 03:26:34 -0400 |
commit | 5a116dd2797677cad48fee2f42267e3cb69f5502 (patch) | |
tree | 94bc08d8c234e26c8b8caa156815964e0a56f159 /tools/perf | |
parent | 11018201b831e19304c0d639f105ad6c27e120b1 (diff) |
perf tools: Use kernel bitmap library
Use the kernel bitmap library for internal perf tools uses.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1255792354-11304-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Makefile | 16 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 3 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 2 | ||||
-rw-r--r-- | tools/perf/util/include/asm/bitops.h | 6 | ||||
-rw-r--r-- | tools/perf/util/include/asm/byteorder.h | 2 | ||||
-rw-r--r-- | tools/perf/util/include/asm/swab.h | 1 | ||||
-rw-r--r-- | tools/perf/util/include/asm/types.h | 17 | ||||
-rw-r--r-- | tools/perf/util/include/asm/uaccess.h | 14 | ||||
-rw-r--r-- | tools/perf/util/include/linux/bitmap.h | 2 | ||||
-rw-r--r-- | tools/perf/util/include/linux/bitops.h | 27 | ||||
-rw-r--r-- | tools/perf/util/include/linux/compiler.h | 10 | ||||
-rw-r--r-- | tools/perf/util/include/linux/ctype.h | 1 | ||||
-rw-r--r-- | tools/perf/util/include/linux/kernel.h | 59 | ||||
-rw-r--r-- | tools/perf/util/include/linux/types.h | 1 |
14 files changed, 156 insertions, 5 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 106c15055b50..2400e5068a2f 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -363,6 +363,9 @@ LIB_OBJS += util/parse-options.o | |||
363 | LIB_OBJS += util/parse-events.o | 363 | LIB_OBJS += util/parse-events.o |
364 | LIB_OBJS += util/path.o | 364 | LIB_OBJS += util/path.o |
365 | LIB_OBJS += util/rbtree.o | 365 | LIB_OBJS += util/rbtree.o |
366 | LIB_OBJS += util/bitmap.o | ||
367 | LIB_OBJS += util/hweight.o | ||
368 | LIB_OBJS += util/find_next_bit.o | ||
366 | LIB_OBJS += util/run-command.o | 369 | LIB_OBJS += util/run-command.o |
367 | LIB_OBJS += util/quote.o | 370 | LIB_OBJS += util/quote.o |
368 | LIB_OBJS += util/strbuf.o | 371 | LIB_OBJS += util/strbuf.o |
@@ -790,6 +793,19 @@ util/config.o: util/config.c PERF-CFLAGS | |||
790 | util/rbtree.o: ../../lib/rbtree.c PERF-CFLAGS | 793 | util/rbtree.o: ../../lib/rbtree.c PERF-CFLAGS |
791 | $(QUIET_CC)$(CC) -o util/rbtree.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 794 | $(QUIET_CC)$(CC) -o util/rbtree.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
792 | 795 | ||
796 | # some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing | ||
797 | # from <string.h> that comes from kernel headers wrapping. | ||
798 | KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//` | ||
799 | |||
800 | util/bitmap.o: ../../lib/bitmap.c PERF-CFLAGS | ||
801 | $(QUIET_CC)$(CC) -o util/bitmap.o -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
802 | |||
803 | util/hweight.o: ../../lib/hweight.c PERF-CFLAGS | ||
804 | $(QUIET_CC)$(CC) -o util/hweight.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
805 | |||
806 | util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS | ||
807 | $(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
808 | |||
793 | perf-%$X: %.o $(PERFLIBS) | 809 | perf-%$X: %.o $(PERFLIBS) |
794 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) | 810 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) |
795 | 811 | ||
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 8b2c860c49a2..fc3709cba136 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -21,9 +21,6 @@ | |||
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <sched.h> | 22 | #include <sched.h> |
23 | 23 | ||
24 | #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | ||
25 | #define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | ||
26 | |||
27 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 24 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; |
28 | 25 | ||
29 | static long default_interval = 0; | 26 | static long default_interval = 0; |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 57ad3f458ef5..807ca66e7a8c 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -38,8 +38,6 @@ static int cwdlen; | |||
38 | #define PR_SET_NAME 15 /* Set process name */ | 38 | #define PR_SET_NAME 15 /* Set process name */ |
39 | #define MAX_CPUS 4096 | 39 | #define MAX_CPUS 4096 |
40 | 40 | ||
41 | #define BUG_ON(x) assert(!(x)) | ||
42 | |||
43 | static u64 run_measurement_overhead; | 41 | static u64 run_measurement_overhead; |
44 | static u64 sleep_measurement_overhead; | 42 | static u64 sleep_measurement_overhead; |
45 | 43 | ||
diff --git a/tools/perf/util/include/asm/bitops.h b/tools/perf/util/include/asm/bitops.h new file mode 100644 index 000000000000..fbe4d9212919 --- /dev/null +++ b/tools/perf/util/include/asm/bitops.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #include "../../../../include/asm-generic/bitops/__fls.h" | ||
2 | #include "../../../../include/asm-generic/bitops/fls.h" | ||
3 | #include "../../../../include/asm-generic/bitops/fls64.h" | ||
4 | #include "../../../../include/asm-generic/bitops/__ffs.h" | ||
5 | #include "../../../../include/asm-generic/bitops/ffz.h" | ||
6 | #include "../../../../include/asm-generic/bitops/hweight.h" | ||
diff --git a/tools/perf/util/include/asm/byteorder.h b/tools/perf/util/include/asm/byteorder.h new file mode 100644 index 000000000000..39f367cfaf56 --- /dev/null +++ b/tools/perf/util/include/asm/byteorder.h | |||
@@ -0,0 +1,2 @@ | |||
1 | #include "../asm/types.h" | ||
2 | #include "../../../../include/linux/swab.h" | ||
diff --git a/tools/perf/util/include/asm/swab.h b/tools/perf/util/include/asm/swab.h new file mode 100644 index 000000000000..ed538942523d --- /dev/null +++ b/tools/perf/util/include/asm/swab.h | |||
@@ -0,0 +1 @@ | |||
/* stub */ | |||
diff --git a/tools/perf/util/include/asm/types.h b/tools/perf/util/include/asm/types.h new file mode 100644 index 000000000000..06703c6cd50e --- /dev/null +++ b/tools/perf/util/include/asm/types.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef PERF_ASM_TYPES_H_ | ||
2 | #define PERF_ASM_TYPES_H_ | ||
3 | |||
4 | #include <linux/compiler.h> | ||
5 | #include "../../types.h" | ||
6 | #include <sys/types.h> | ||
7 | |||
8 | /* CHECKME: Not sure both always match */ | ||
9 | #define BITS_PER_LONG __WORDSIZE | ||
10 | |||
11 | typedef u64 __u64; | ||
12 | typedef u32 __u32; | ||
13 | typedef u16 __u16; | ||
14 | typedef u8 __u8; | ||
15 | typedef s64 __s64; | ||
16 | |||
17 | #endif /* PERF_ASM_TYPES_H_ */ | ||
diff --git a/tools/perf/util/include/asm/uaccess.h b/tools/perf/util/include/asm/uaccess.h new file mode 100644 index 000000000000..d0f72b8fcc35 --- /dev/null +++ b/tools/perf/util/include/asm/uaccess.h | |||
@@ -0,0 +1,14 @@ | |||
1 | #ifndef _PERF_ASM_UACCESS_H_ | ||
2 | #define _PERF_ASM_UACCESS_H_ | ||
3 | |||
4 | #define __get_user(src, dest) \ | ||
5 | ({ \ | ||
6 | (src) = *dest; \ | ||
7 | 0; \ | ||
8 | }) | ||
9 | |||
10 | #define get_user __get_user | ||
11 | |||
12 | #define access_ok(type, addr, size) 1 | ||
13 | |||
14 | #endif | ||
diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h new file mode 100644 index 000000000000..821c1033bccf --- /dev/null +++ b/tools/perf/util/include/linux/bitmap.h | |||
@@ -0,0 +1,2 @@ | |||
1 | #include "../../../../include/linux/bitmap.h" | ||
2 | #include "../../../../include/asm-generic/bitops/find.h" | ||
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h new file mode 100644 index 000000000000..ace57c36d1d0 --- /dev/null +++ b/tools/perf/util/include/linux/bitops.h | |||
@@ -0,0 +1,27 @@ | |||
1 | #ifndef _PERF_LINUX_BITOPS_H_ | ||
2 | #define _PERF_LINUX_BITOPS_H_ | ||
3 | |||
4 | #define __KERNEL__ | ||
5 | |||
6 | #define CONFIG_GENERIC_FIND_NEXT_BIT | ||
7 | #define CONFIG_GENERIC_FIND_FIRST_BIT | ||
8 | #include "../../../../include/linux/bitops.h" | ||
9 | |||
10 | static inline void set_bit(int nr, unsigned long *addr) | ||
11 | { | ||
12 | addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); | ||
13 | } | ||
14 | |||
15 | static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) | ||
16 | { | ||
17 | return ((1UL << (nr % BITS_PER_LONG)) & | ||
18 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; | ||
19 | } | ||
20 | |||
21 | unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned | ||
22 | long size, unsigned long offset); | ||
23 | |||
24 | unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned | ||
25 | long size, unsigned long offset); | ||
26 | |||
27 | #endif | ||
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h new file mode 100644 index 000000000000..dfb0713ed47f --- /dev/null +++ b/tools/perf/util/include/linux/compiler.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef _PERF_LINUX_COMPILER_H_ | ||
2 | #define _PERF_LINUX_COMPILER_H_ | ||
3 | |||
4 | #ifndef __always_inline | ||
5 | #define __always_inline inline | ||
6 | #endif | ||
7 | #define __user | ||
8 | #define __attribute_const__ | ||
9 | |||
10 | #endif | ||
diff --git a/tools/perf/util/include/linux/ctype.h b/tools/perf/util/include/linux/ctype.h new file mode 100644 index 000000000000..bae5783282ef --- /dev/null +++ b/tools/perf/util/include/linux/ctype.h | |||
@@ -0,0 +1 @@ | |||
#include "../../../../include/linux/ctype.h" | |||
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h index a6b87390cb52..4b9204d9b266 100644 --- a/tools/perf/util/include/linux/kernel.h +++ b/tools/perf/util/include/linux/kernel.h | |||
@@ -1,6 +1,16 @@ | |||
1 | #ifndef PERF_LINUX_KERNEL_H_ | 1 | #ifndef PERF_LINUX_KERNEL_H_ |
2 | #define PERF_LINUX_KERNEL_H_ | 2 | #define PERF_LINUX_KERNEL_H_ |
3 | 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 ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) | ||
12 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) | ||
13 | |||
4 | #ifndef offsetof | 14 | #ifndef offsetof |
5 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | 15 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
6 | #endif | 16 | #endif |
@@ -26,4 +36,53 @@ | |||
26 | _max1 > _max2 ? _max1 : _max2; }) | 36 | _max1 > _max2 ? _max1 : _max2; }) |
27 | #endif | 37 | #endif |
28 | 38 | ||
39 | #ifndef min | ||
40 | #define min(x, y) ({ \ | ||
41 | typeof(x) _min1 = (x); \ | ||
42 | typeof(y) _min2 = (y); \ | ||
43 | (void) (&_min1 == &_min2); \ | ||
44 | _min1 < _min2 ? _min1 : _min2; }) | ||
45 | #endif | ||
46 | |||
47 | #ifndef BUG_ON | ||
48 | #define BUG_ON(cond) assert(!(cond)) | ||
49 | #endif | ||
50 | |||
51 | /* | ||
52 | * Both need more care to handle endianness | ||
53 | * (Don't use bitmap_copy_le() for now) | ||
54 | */ | ||
55 | #define cpu_to_le64(x) (x) | ||
56 | #define cpu_to_le32(x) (x) | ||
57 | |||
58 | static inline int | ||
59 | vscnprintf(char *buf, size_t size, const char *fmt, va_list args) | ||
60 | { | ||
61 | int i; | ||
62 | ssize_t ssize = size; | ||
63 | |||
64 | i = vsnprintf(buf, size, fmt, args); | ||
65 | |||
66 | return (i >= ssize) ? (ssize - 1) : i; | ||
67 | } | ||
68 | |||
69 | static inline int scnprintf(char * buf, size_t size, const char * fmt, ...) | ||
70 | { | ||
71 | va_list args; | ||
72 | ssize_t ssize = size; | ||
73 | int i; | ||
74 | |||
75 | va_start(args, fmt); | ||
76 | i = vsnprintf(buf, size, fmt, args); | ||
77 | va_end(args); | ||
78 | |||
79 | return (i >= ssize) ? (ssize - 1) : i; | ||
80 | } | ||
81 | |||
82 | static inline unsigned long | ||
83 | simple_strtoul(const char *nptr, char **endptr, int base) | ||
84 | { | ||
85 | return strtoul(nptr, endptr, base); | ||
86 | } | ||
87 | |||
29 | #endif | 88 | #endif |
diff --git a/tools/perf/util/include/linux/types.h b/tools/perf/util/include/linux/types.h new file mode 100644 index 000000000000..ed538942523d --- /dev/null +++ b/tools/perf/util/include/linux/types.h | |||
@@ -0,0 +1 @@ | |||
/* stub */ | |||