Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools bitmap: Implement bitmap_equal() operation at bitmap API

Extend tools bitmap API with bitmap_equal() implementation.

The implementation has been derived from the kernel.

Extend tools bitmap API with bitmap_free() implementation for symmetry
with bitmap_alloc() function.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/43757993-0b28-d8af-a6c7-ede12e3a6877@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Alexey Budankov and committed by
Arnaldo Carvalho de Melo
8812ad41 b9fb2de0

+45
+30
tools/include/linux/bitmap.h
··· 15 15 const unsigned long *bitmap2, int bits); 16 16 int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 17 17 const unsigned long *bitmap2, unsigned int bits); 18 + int __bitmap_equal(const unsigned long *bitmap1, 19 + const unsigned long *bitmap2, unsigned int bits); 18 20 void bitmap_clear(unsigned long *map, unsigned int start, int len); 19 21 20 22 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) ··· 126 124 } 127 125 128 126 /* 127 + * bitmap_free - Free bitmap 128 + * @bitmap: pointer to bitmap 129 + */ 130 + static inline void bitmap_free(unsigned long *bitmap) 131 + { 132 + free(bitmap); 133 + } 134 + 135 + /* 129 136 * bitmap_scnprintf - print bitmap list into buffer 130 137 * @bitmap: bitmap 131 138 * @nbits: size of bitmap ··· 157 146 if (small_const_nbits(nbits)) 158 147 return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0; 159 148 return __bitmap_and(dst, src1, src2, nbits); 149 + } 150 + 151 + #ifdef __LITTLE_ENDIAN 152 + #define BITMAP_MEM_ALIGNMENT 8 153 + #else 154 + #define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long)) 155 + #endif 156 + #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) 157 + #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 158 + 159 + static inline int bitmap_equal(const unsigned long *src1, 160 + const unsigned long *src2, unsigned int nbits) 161 + { 162 + if (small_const_nbits(nbits)) 163 + return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); 164 + if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && 165 + IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) 166 + return !memcmp(src1, src2, nbits / 8); 167 + return __bitmap_equal(src1, src2, nbits); 160 168 } 161 169 162 170 #endif /* _PERF_BITOPS_H */
+15
tools/lib/bitmap.c
··· 71 71 BITMAP_LAST_WORD_MASK(bits)); 72 72 return result != 0; 73 73 } 74 + 75 + int __bitmap_equal(const unsigned long *bitmap1, 76 + const unsigned long *bitmap2, unsigned int bits) 77 + { 78 + unsigned int k, lim = bits/BITS_PER_LONG; 79 + for (k = 0; k < lim; ++k) 80 + if (bitmap1[k] != bitmap2[k]) 81 + return 0; 82 + 83 + if (bits % BITS_PER_LONG) 84 + if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) 85 + return 0; 86 + 87 + return 1; 88 + }