-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Arnaldo Carvalho de Melo
committed
May 2, 2010
1 parent
bc4b473
commit fb72014
Showing
7 changed files
with
105 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* From lib/bitmap.c | ||
* Helper functions for bitmap.h. | ||
* | ||
* This source code is licensed under the GNU General Public License, | ||
* Version 2. See the file COPYING for more details. | ||
*/ | ||
#include <linux/bitmap.h> | ||
|
||
int __bitmap_weight(const unsigned long *bitmap, int bits) | ||
{ | ||
int k, w = 0, lim = bits/BITS_PER_LONG; | ||
|
||
for (k = 0; k < lim; k++) | ||
w += hweight_long(bitmap[k]); | ||
|
||
if (bits % BITS_PER_LONG) | ||
w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); | ||
|
||
return w; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <linux/bitops.h> | ||
|
||
/** | ||
* hweightN - returns the hamming weight of a N-bit word | ||
* @x: the word to weigh | ||
* | ||
* The Hamming Weight of a number is the total number of bits set in it. | ||
*/ | ||
|
||
unsigned int hweight32(unsigned int w) | ||
{ | ||
unsigned int res = w - ((w >> 1) & 0x55555555); | ||
res = (res & 0x33333333) + ((res >> 2) & 0x33333333); | ||
res = (res + (res >> 4)) & 0x0F0F0F0F; | ||
res = res + (res >> 8); | ||
return (res + (res >> 16)) & 0x000000FF; | ||
} | ||
|
||
unsigned long hweight64(__u64 w) | ||
{ | ||
#if BITS_PER_LONG == 32 | ||
return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | ||
#elif BITS_PER_LONG == 64 | ||
__u64 res = w - ((w >> 1) & 0x5555555555555555ul); | ||
res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul); | ||
res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful; | ||
res = res + (res >> 8); | ||
res = res + (res >> 16); | ||
return (res + (res >> 32)) & 0x00000000000000FFul; | ||
#endif | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef PERF_HWEIGHT_H | ||
#define PERF_HWEIGHT_H | ||
|
||
#include <linux/types.h> | ||
unsigned int hweight32(unsigned int w); | ||
unsigned long hweight64(__u64 w); | ||
|
||
#endif /* PERF_HWEIGHT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
#include "../../../../include/linux/bitmap.h" | ||
#include "../../../../include/asm-generic/bitops/find.h" | ||
#include <linux/errno.h> | ||
#ifndef _PERF_BITOPS_H | ||
#define _PERF_BITOPS_H | ||
|
||
#include <string.h> | ||
#include <linux/bitops.h> | ||
|
||
int __bitmap_weight(const unsigned long *bitmap, int bits); | ||
|
||
#define BITMAP_LAST_WORD_MASK(nbits) \ | ||
( \ | ||
((nbits) % BITS_PER_LONG) ? \ | ||
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | ||
) | ||
|
||
#define small_const_nbits(nbits) \ | ||
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | ||
|
||
static inline void bitmap_zero(unsigned long *dst, int nbits) | ||
{ | ||
if (small_const_nbits(nbits)) | ||
*dst = 0UL; | ||
else { | ||
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | ||
memset(dst, 0, len); | ||
} | ||
} | ||
|
||
static inline int bitmap_weight(const unsigned long *src, int nbits) | ||
{ | ||
if (small_const_nbits(nbits)) | ||
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | ||
return __bitmap_weight(src, nbits); | ||
} | ||
|
||
#endif /* _PERF_BITOPS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters