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: add missing bitmap_[subset(), andnot()]

The bitmap_subset() and bitmap_andnot() functions are not present in the
tools version of include/linux/bitmap.h, so add them as subsequent patches
implement test code that requires them.

We also add the missing __bitmap_subset() to tools/lib/bitmap.c.

Link: https://lkml.kernel.org/r/0fd0d4ec868297f522003cb4b5898b53b498805b.1769097829.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Yury Norov <ynorov@nvidia.com>
Cc: Chris Mason <clm@fb.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
21c8a5ba 1c628004

+51
+22
tools/include/linux/bitmap.h
··· 24 24 void __bitmap_clear(unsigned long *map, unsigned int start, int len); 25 25 bool __bitmap_intersects(const unsigned long *bitmap1, 26 26 const unsigned long *bitmap2, unsigned int bits); 27 + bool __bitmap_subset(const unsigned long *bitmap1, 28 + const unsigned long *bitmap2, unsigned int nbits); 29 + bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 30 + const unsigned long *bitmap2, unsigned int nbits); 27 31 28 32 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) 29 33 #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) ··· 83 79 *dst = *src1 | *src2; 84 80 else 85 81 __bitmap_or(dst, src1, src2, nbits); 82 + } 83 + 84 + static __always_inline 85 + bool bitmap_andnot(unsigned long *dst, const unsigned long *src1, 86 + const unsigned long *src2, unsigned int nbits) 87 + { 88 + if (small_const_nbits(nbits)) 89 + return (*dst = *src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; 90 + return __bitmap_andnot(dst, src1, src2, nbits); 86 91 } 87 92 88 93 static inline unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags __maybe_unused) ··· 168 155 return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; 169 156 else 170 157 return __bitmap_intersects(src1, src2, nbits); 158 + } 159 + 160 + static __always_inline 161 + bool bitmap_subset(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) 162 + { 163 + if (small_const_nbits(nbits)) 164 + return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)); 165 + else 166 + return __bitmap_subset(src1, src2, nbits); 171 167 } 172 168 173 169 static inline void bitmap_set(unsigned long *map, unsigned int start, unsigned int nbits)
+29
tools/lib/bitmap.c
··· 140 140 *p &= ~mask_to_clear; 141 141 } 142 142 } 143 + 144 + bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, 145 + const unsigned long *bitmap2, unsigned int bits) 146 + { 147 + unsigned int k; 148 + unsigned int lim = bits/BITS_PER_LONG; 149 + unsigned long result = 0; 150 + 151 + for (k = 0; k < lim; k++) 152 + result |= (dst[k] = bitmap1[k] & ~bitmap2[k]); 153 + if (bits % BITS_PER_LONG) 154 + result |= (dst[k] = bitmap1[k] & ~bitmap2[k] & 155 + BITMAP_LAST_WORD_MASK(bits)); 156 + return result != 0; 157 + } 158 + 159 + bool __bitmap_subset(const unsigned long *bitmap1, 160 + const unsigned long *bitmap2, unsigned int bits) 161 + { 162 + unsigned int k, lim = bits/BITS_PER_LONG; 163 + for (k = 0; k < lim; ++k) 164 + if (bitmap1[k] & ~bitmap2[k]) 165 + return false; 166 + 167 + if (bits % BITS_PER_LONG) 168 + if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) 169 + return false; 170 + return true; 171 + }