History

bitmap: genericize percpu bitmap region iterators

Bitmaps are fairly popular for their space efficiency, but we don't have generic iterators available. Make percpu's bitmap region iterators available to everyone.

Dennis Zhou committed 6 years ago

Commit e837dfd1 parent 147a0972 files · +51 −45Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/bitmap.h+35−0
@@ -456,6 +456,41 @@ static inline int bitmap_parse(const char *buf, unsigned int buflen, · 455 unmodified lines
456 return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);456 return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
457}457}
458 458
459static inline void bitmap_next_clear_region(unsigned long *bitmap,
460 unsigned int *rs, unsigned int *re,
461 unsigned int end)
462{
463 *rs = find_next_zero_bit(bitmap, end, *rs);
464 *re = find_next_bit(bitmap, end, *rs + 1);
465}
466
467static inline void bitmap_next_set_region(unsigned long *bitmap,
468 unsigned int *rs, unsigned int *re,
469 unsigned int end)
470{
471 *rs = find_next_bit(bitmap, end, *rs);
472 *re = find_next_zero_bit(bitmap, end, *rs + 1);
473}
474
475/*
476 * Bitmap region iterators. Iterates over the bitmap between [@start, @end).
477 * @rs and @re should be integer variables and will be set to start and end
478 * index of the current clear or set region.
479 */
480#define bitmap_for_each_clear_region(bitmap, rs, re, start, end) \
481 for ((rs) = (start), \
482 bitmap_next_clear_region((bitmap), &(rs), &(re), (end)); \
483 (rs) < (re); \
484 (rs) = (re) + 1, \
485 bitmap_next_clear_region((bitmap), &(rs), &(re), (end)))
486
487#define bitmap_for_each_set_region(bitmap, rs, re, start, end) \
488 for ((rs) = (start), \
489 bitmap_next_set_region((bitmap), &(rs), &(re), (end)); \
490 (rs) < (re); \
491 (rs) = (re) + 1, \
492 bitmap_next_set_region((bitmap), &(rs), &(re), (end)))
493
459/**494/**
460 * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.495 * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
461 * @n: u64 value496 * @n: u64 value