diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-09-25 09:55:59 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-08 13:23:43 -0400 |
| commit | ba4aa02b417f08a0bee5e7b8ed70cac788a7c854 (patch) | |
| tree | 323d36f3989038af416de1571ac12f643a635bec /tools/include | |
| parent | 7c5314b88da6d5af98239786772a1c44cc5eb67d (diff) | |
tools include: Adopt linux/bits.h
So that we reduce the difference of tools/include/linux/bitops.h to the
original kernel file, include/linux/bitops.h, trying to remove the need
to define BITS_PER_LONG, to avoid clashes with asm/bitsperlong.h.
And the things removed from tools/include/linux/bitops.h are really in
linux/bits.h, so that we can have a copy and then
tools/perf/check_headers.sh will tell us when new stuff gets added to
linux/bits.h so that we can check if it is useful and if any adjustment
needs to be done to the tools/{include,arch}/ copies.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Sverdlin <alexander.sverdlin@nokia.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-y1sqyydvfzo0bjjoj4zsl562@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include')
| -rw-r--r-- | tools/include/linux/bitops.h | 7 | ||||
| -rw-r--r-- | tools/include/linux/bits.h | 26 |
2 files changed, 28 insertions, 5 deletions
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h index acc704bd3998..0b0ef3abc966 100644 --- a/tools/include/linux/bitops.h +++ b/tools/include/linux/bitops.h | |||
| @@ -3,8 +3,6 @@ | |||
| 3 | #define _TOOLS_LINUX_BITOPS_H_ | 3 | #define _TOOLS_LINUX_BITOPS_H_ |
| 4 | 4 | ||
| 5 | #include <asm/types.h> | 5 | #include <asm/types.h> |
| 6 | #include <linux/compiler.h> | ||
| 7 | |||
| 8 | #ifndef __WORDSIZE | 6 | #ifndef __WORDSIZE |
| 9 | #define __WORDSIZE (__SIZEOF_LONG__ * 8) | 7 | #define __WORDSIZE (__SIZEOF_LONG__ * 8) |
| 10 | #endif | 8 | #endif |
| @@ -12,10 +10,9 @@ | |||
| 12 | #ifndef BITS_PER_LONG | 10 | #ifndef BITS_PER_LONG |
| 13 | # define BITS_PER_LONG __WORDSIZE | 11 | # define BITS_PER_LONG __WORDSIZE |
| 14 | #endif | 12 | #endif |
| 13 | #include <linux/bits.h> | ||
| 14 | #include <linux/compiler.h> | ||
| 15 | 15 | ||
| 16 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) | ||
| 17 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) | ||
| 18 | #define BITS_PER_BYTE 8 | ||
| 19 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) | 16 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
| 20 | #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) | 17 | #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) |
| 21 | #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) | 18 | #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) |
diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h new file mode 100644 index 000000000000..2b7b532c1d51 --- /dev/null +++ b/tools/include/linux/bits.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | #ifndef __LINUX_BITS_H | ||
| 3 | #define __LINUX_BITS_H | ||
| 4 | #include <asm/bitsperlong.h> | ||
| 5 | |||
| 6 | #define BIT(nr) (1UL << (nr)) | ||
| 7 | #define BIT_ULL(nr) (1ULL << (nr)) | ||
| 8 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) | ||
| 9 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) | ||
| 10 | #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG)) | ||
| 11 | #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG) | ||
| 12 | #define BITS_PER_BYTE 8 | ||
| 13 | |||
| 14 | /* | ||
| 15 | * Create a contiguous bitmask starting at bit position @l and ending at | ||
| 16 | * position @h. For example | ||
| 17 | * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. | ||
| 18 | */ | ||
| 19 | #define GENMASK(h, l) \ | ||
| 20 | (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) | ||
| 21 | |||
| 22 | #define GENMASK_ULL(h, l) \ | ||
| 23 | (((~0ULL) - (1ULL << (l)) + 1) & \ | ||
| 24 | (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) | ||
| 25 | |||
| 26 | #endif /* __LINUX_BITS_H */ | ||
