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>
This commit is contained in:
parent
bc4b473f1a
commit
fb72014d98
7 changed files with 105 additions and 47 deletions
|
@ -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 */
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef _PERF_LINUX_BITOPS_H_
|
||||
#define _PERF_LINUX_BITOPS_H_
|
||||
|
||||
#define __KERNEL__
|
||||
#include <linux/kernel.h>
|
||||
#include <asm/hweight.h>
|
||||
|
||||
#define CONFIG_GENERIC_FIND_NEXT_BIT
|
||||
#define CONFIG_GENERIC_FIND_FIRST_BIT
|
||||
#include "../../../../include/linux/bitops.h"
|
||||
|
||||
#undef __KERNEL__
|
||||
#define BITS_PER_LONG __WORDSIZE
|
||||
#define BITS_PER_BYTE 8
|
||||
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
|
||||
|
||||
static inline void set_bit(int nr, unsigned long *addr)
|
||||
{
|
||||
|
@ -20,10 +19,9 @@ static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
|
|||
(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
|
||||
}
|
||||
|
||||
unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned
|
||||
long size, unsigned long offset);
|
||||
|
||||
unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned
|
||||
long size, unsigned long offset);
|
||||
static inline unsigned long hweight_long(unsigned long w)
|
||||
{
|
||||
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue