diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-04-30 18:31:12 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-05-02 11:00:44 -0400 |
commit | fb72014d98afd51e85aab9c061344ef32d615606 (patch) | |
tree | 18713d4d1084870c604b512396b893944a2bbdab /tools/perf | |
parent | bc4b473f1aa2ef785ccfd890a24a1de5a6660f98 (diff) |
perf tools: Don't use code surrounded by __KERNEL__
We need to refactor code to be explicitely shared by the kernel and at
least the tools/ userspace programs, so, till we do that, copy the bare
minimum bitmap/bitops code needed by tools/perf.
Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Makefile | 16 | ||||
-rw-r--r-- | tools/perf/util/bitmap.c | 21 | ||||
-rw-r--r-- | tools/perf/util/hweight.c | 31 | ||||
-rw-r--r-- | tools/perf/util/include/asm/bitops.h | 18 | ||||
-rw-r--r-- | tools/perf/util/include/asm/hweight.h | 8 | ||||
-rw-r--r-- | tools/perf/util/include/linux/bitmap.h | 38 | ||||
-rw-r--r-- | tools/perf/util/include/linux/bitops.h | 20 |
7 files changed, 105 insertions, 47 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 739c4412b183..c5ac0a991565 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -377,9 +377,9 @@ LIB_H += util/include/linux/rbtree.h | |||
377 | LIB_H += util/include/linux/string.h | 377 | LIB_H += util/include/linux/string.h |
378 | LIB_H += util/include/linux/types.h | 378 | LIB_H += util/include/linux/types.h |
379 | LIB_H += util/include/asm/asm-offsets.h | 379 | LIB_H += util/include/asm/asm-offsets.h |
380 | LIB_H += util/include/asm/bitops.h | ||
381 | LIB_H += util/include/asm/bug.h | 380 | LIB_H += util/include/asm/bug.h |
382 | LIB_H += util/include/asm/byteorder.h | 381 | LIB_H += util/include/asm/byteorder.h |
382 | LIB_H += util/include/asm/hweight.h | ||
383 | LIB_H += util/include/asm/swab.h | 383 | LIB_H += util/include/asm/swab.h |
384 | LIB_H += util/include/asm/system.h | 384 | LIB_H += util/include/asm/system.h |
385 | LIB_H += util/include/asm/uaccess.h | 385 | LIB_H += util/include/asm/uaccess.h |
@@ -435,7 +435,6 @@ LIB_OBJS += $(OUTPUT)util/path.o | |||
435 | LIB_OBJS += $(OUTPUT)util/rbtree.o | 435 | LIB_OBJS += $(OUTPUT)util/rbtree.o |
436 | LIB_OBJS += $(OUTPUT)util/bitmap.o | 436 | LIB_OBJS += $(OUTPUT)util/bitmap.o |
437 | LIB_OBJS += $(OUTPUT)util/hweight.o | 437 | LIB_OBJS += $(OUTPUT)util/hweight.o |
438 | LIB_OBJS += $(OUTPUT)util/find_next_bit.o | ||
439 | LIB_OBJS += $(OUTPUT)util/run-command.o | 438 | LIB_OBJS += $(OUTPUT)util/run-command.o |
440 | LIB_OBJS += $(OUTPUT)util/quote.o | 439 | LIB_OBJS += $(OUTPUT)util/quote.o |
441 | LIB_OBJS += $(OUTPUT)util/strbuf.o | 440 | LIB_OBJS += $(OUTPUT)util/strbuf.o |
@@ -948,19 +947,6 @@ $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS | |||
948 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS | 947 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS |
949 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 948 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
950 | 949 | ||
951 | # some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing | ||
952 | # from <string.h> that comes from kernel headers wrapping. | ||
953 | KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//` | ||
954 | |||
955 | $(OUTPUT)util/bitmap.o: ../../lib/bitmap.c $(OUTPUT)PERF-CFLAGS | ||
956 | $(QUIET_CC)$(CC) -o $@ -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
957 | |||
958 | $(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS | ||
959 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
960 | |||
961 | $(OUTPUT)util/find_next_bit.o: ../../lib/find_next_bit.c $(OUTPUT)PERF-CFLAGS | ||
962 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
963 | |||
964 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS | 950 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS |
965 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 951 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
966 | 952 | ||
diff --git a/tools/perf/util/bitmap.c b/tools/perf/util/bitmap.c new file mode 100644 index 000000000000..5e230acae1e9 --- /dev/null +++ b/tools/perf/util/bitmap.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * From lib/bitmap.c | ||
3 | * Helper functions for bitmap.h. | ||
4 | * | ||
5 | * This source code is licensed under the GNU General Public License, | ||
6 | * Version 2. See the file COPYING for more details. | ||
7 | */ | ||
8 | #include <linux/bitmap.h> | ||
9 | |||
10 | int __bitmap_weight(const unsigned long *bitmap, int bits) | ||
11 | { | ||
12 | int k, w = 0, lim = bits/BITS_PER_LONG; | ||
13 | |||
14 | for (k = 0; k < lim; k++) | ||
15 | w += hweight_long(bitmap[k]); | ||
16 | |||
17 | if (bits % BITS_PER_LONG) | ||
18 | w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); | ||
19 | |||
20 | return w; | ||
21 | } | ||
diff --git a/tools/perf/util/hweight.c b/tools/perf/util/hweight.c new file mode 100644 index 000000000000..5c1d0d099f0d --- /dev/null +++ b/tools/perf/util/hweight.c | |||
@@ -0,0 +1,31 @@ | |||
1 | #include <linux/bitops.h> | ||
2 | |||
3 | /** | ||
4 | * hweightN - returns the hamming weight of a N-bit word | ||
5 | * @x: the word to weigh | ||
6 | * | ||
7 | * The Hamming Weight of a number is the total number of bits set in it. | ||
8 | */ | ||
9 | |||
10 | unsigned int hweight32(unsigned int w) | ||
11 | { | ||
12 | unsigned int res = w - ((w >> 1) & 0x55555555); | ||
13 | res = (res & 0x33333333) + ((res >> 2) & 0x33333333); | ||
14 | res = (res + (res >> 4)) & 0x0F0F0F0F; | ||
15 | res = res + (res >> 8); | ||
16 | return (res + (res >> 16)) & 0x000000FF; | ||
17 | } | ||
18 | |||
19 | unsigned long hweight64(__u64 w) | ||
20 | { | ||
21 | #if BITS_PER_LONG == 32 | ||
22 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | ||
23 | #elif BITS_PER_LONG == 64 | ||
24 | __u64 res = w - ((w >> 1) & 0x5555555555555555ul); | ||
25 | res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul); | ||
26 | res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful; | ||
27 | res = res + (res >> 8); | ||
28 | res = res + (res >> 16); | ||
29 | return (res + (res >> 32)) & 0x00000000000000FFul; | ||
30 | #endif | ||
31 | } | ||
diff --git a/tools/perf/util/include/asm/bitops.h b/tools/perf/util/include/asm/bitops.h deleted file mode 100644 index 58e9817ffae0..000000000000 --- a/tools/perf/util/include/asm/bitops.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef _PERF_ASM_BITOPS_H_ | ||
2 | #define _PERF_ASM_BITOPS_H_ | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | #include "../../types.h" | ||
6 | #include <linux/compiler.h> | ||
7 | |||
8 | /* CHECKME: Not sure both always match */ | ||
9 | #define BITS_PER_LONG __WORDSIZE | ||
10 | |||
11 | #include "../../../../include/asm-generic/bitops/__fls.h" | ||
12 | #include "../../../../include/asm-generic/bitops/fls.h" | ||
13 | #include "../../../../include/asm-generic/bitops/fls64.h" | ||
14 | #include "../../../../include/asm-generic/bitops/__ffs.h" | ||
15 | #include "../../../../include/asm-generic/bitops/ffz.h" | ||
16 | #include "../../../../include/asm-generic/bitops/hweight.h" | ||
17 | |||
18 | #endif | ||
diff --git a/tools/perf/util/include/asm/hweight.h b/tools/perf/util/include/asm/hweight.h new file mode 100644 index 000000000000..36cf26d434a5 --- /dev/null +++ b/tools/perf/util/include/asm/hweight.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef PERF_HWEIGHT_H | ||
2 | #define PERF_HWEIGHT_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | unsigned int hweight32(unsigned int w); | ||
6 | unsigned long hweight64(__u64 w); | ||
7 | |||
8 | #endif /* PERF_HWEIGHT_H */ | ||
diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h index 94507639a8c4..eda4416efa0a 100644 --- a/tools/perf/util/include/linux/bitmap.h +++ b/tools/perf/util/include/linux/bitmap.h | |||
@@ -1,3 +1,35 @@ | |||
1 | #include "../../../../include/linux/bitmap.h" | 1 | #ifndef _PERF_BITOPS_H |
2 | #include "../../../../include/asm-generic/bitops/find.h" | 2 | #define _PERF_BITOPS_H |
3 | #include <linux/errno.h> | 3 | |
4 | #include <string.h> | ||
5 | #include <linux/bitops.h> | ||
6 | |||
7 | int __bitmap_weight(const unsigned long *bitmap, int bits); | ||
8 | |||
9 | #define BITMAP_LAST_WORD_MASK(nbits) \ | ||
10 | ( \ | ||
11 | ((nbits) % BITS_PER_LONG) ? \ | ||
12 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | ||
13 | ) | ||
14 | |||
15 | #define small_const_nbits(nbits) \ | ||
16 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | ||
17 | |||
18 | static inline void bitmap_zero(unsigned long *dst, int nbits) | ||
19 | { | ||
20 | if (small_const_nbits(nbits)) | ||
21 | *dst = 0UL; | ||
22 | else { | ||
23 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | ||
24 | memset(dst, 0, len); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | static inline int bitmap_weight(const unsigned long *src, int nbits) | ||
29 | { | ||
30 | if (small_const_nbits(nbits)) | ||
31 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | ||
32 | return __bitmap_weight(src, nbits); | ||
33 | } | ||
34 | |||
35 | #endif /* _PERF_BITOPS_H */ | ||
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h index 8d63116e9435..bb4ac2e05385 100644 --- a/tools/perf/util/include/linux/bitops.h +++ b/tools/perf/util/include/linux/bitops.h | |||
@@ -1,13 +1,12 @@ | |||
1 | #ifndef _PERF_LINUX_BITOPS_H_ | 1 | #ifndef _PERF_LINUX_BITOPS_H_ |
2 | #define _PERF_LINUX_BITOPS_H_ | 2 | #define _PERF_LINUX_BITOPS_H_ |
3 | 3 | ||
4 | #define __KERNEL__ | 4 | #include <linux/kernel.h> |
5 | #include <asm/hweight.h> | ||
5 | 6 | ||
6 | #define CONFIG_GENERIC_FIND_NEXT_BIT | 7 | #define BITS_PER_LONG __WORDSIZE |
7 | #define CONFIG_GENERIC_FIND_FIRST_BIT | 8 | #define BITS_PER_BYTE 8 |
8 | #include "../../../../include/linux/bitops.h" | 9 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
9 | |||
10 | #undef __KERNEL__ | ||
11 | 10 | ||
12 | static inline void set_bit(int nr, unsigned long *addr) | 11 | static inline void set_bit(int nr, unsigned long *addr) |
13 | { | 12 | { |
@@ -20,10 +19,9 @@ static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) | |||
20 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; | 19 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; |
21 | } | 20 | } |
22 | 21 | ||
23 | unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned | 22 | static inline unsigned long hweight_long(unsigned long w) |
24 | long size, unsigned long offset); | 23 | { |
25 | 24 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | |
26 | unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned | 25 | } |
27 | long size, unsigned long offset); | ||
28 | 26 | ||
29 | #endif | 27 | #endif |