qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

bitmap: introduce bitmap_count_one()

Count how many bits set in the bitmap.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>

authored by

Peter Xu and committed by
Juan Quintela
fc7deeea ab089e05

+25
+10
include/qemu/bitmap.h
··· 82 82 const unsigned long *bitmap2, long bits); 83 83 int slow_bitmap_intersects(const unsigned long *bitmap1, 84 84 const unsigned long *bitmap2, long bits); 85 + long slow_bitmap_count_one(const unsigned long *bitmap, long nbits); 85 86 86 87 static inline unsigned long *bitmap_try_new(long nbits) 87 88 { ··· 213 214 return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; 214 215 } else { 215 216 return slow_bitmap_intersects(src1, src2, nbits); 217 + } 218 + } 219 + 220 + static inline long bitmap_count_one(const unsigned long *bitmap, long nbits) 221 + { 222 + if (small_nbits(nbits)) { 223 + return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits)); 224 + } else { 225 + return slow_bitmap_count_one(bitmap, nbits); 216 226 } 217 227 } 218 228
+15
util/bitmap.c
··· 355 355 } 356 356 return 0; 357 357 } 358 + 359 + long slow_bitmap_count_one(const unsigned long *bitmap, long nbits) 360 + { 361 + long k, lim = nbits / BITS_PER_LONG, result = 0; 362 + 363 + for (k = 0; k < lim; k++) { 364 + result += ctpopl(bitmap[k]); 365 + } 366 + 367 + if (nbits % BITS_PER_LONG) { 368 + result += ctpopl(bitmap[k] & BITMAP_LAST_WORD_MASK(nbits)); 369 + } 370 + 371 + return result; 372 + }