bitops: introduce for_each_clear_bit()
Subsystems (5)
cover bitops: introduce for_each_clear_bit()
This patch set introduces for_each_clear_bit() which is similar to for_each_set_bit(), but it iterates over all the cleared bits in a memory region.
This also renames for_each_set_bit_cont() to for_each_set_bit_from() because it is anologous to list_for_each_entry_from() in list.h rather than list_for_each_entry_continue(), and then introduces for_each_clear_bit_from(), too.
Akinobu Mita (7):
bitops: rename for_each_set_bit_cont in favor of anologous to list.h
function
bitops: remove for_each_set_bit_cont
bitops: introduce list_for_each_clear_bit
mtd: use for_each_clear_bit
s390/char: use for_each_clear_bit
uwb: use for_each_clear_bit
x86: use for_each_clear_bit_from
arch/x86/kernel/cpu/perf_event.c | 4 ++-- arch/x86/kernel/irqinit.c | 6 +++--- drivers/mtd/chips/cfi_cmdset_0001.c | 6 ++---- drivers/s390/char/sclp_cmd.c | 5 ++--- drivers/uwb/allocator.c | 6 ++---- include/linux/bitops.h | 13 ++++++++++++- tools/perf/util/include/linux/bitops.h | 2 +- 7 files changed, 24 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.4.4
PATCH 1/7 bitops: rename for_each_set_bit_cont in favor of anologous to list.h function
This renames for_each_set_bit_cont() to for_each_set_bit_from() because it is anologous to list_for_each_entry_from() in list.h rather than list_for_each_entry_continue().
This doesn't remove for_each_set_bit_cont() for now.
--- arch/x86/kernel/cpu/perf_event.c | 4 ++-- include/linux/bitops.h | 5 ++++- tools/perf/util/include/linux/bitops.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event.c +2 -2
@@ -577,14 +577,14 @@ static bool __perf_sched_find_counter(struct perf_sched *sched)/* Prefer fixed purpose counters */ if (x86_pmu.num_counters_fixed) { idx =X86_PMC_IDX_FIXED ; -for_each_set_bit_cont (idx, c->idxmsk,X86_PMC_IDX_MAX ) { +for_each_set_bit_from (idx, c->idxmsk,X86_PMC_IDX_MAX ) {if (!__test_and_set_bit (idx, sched->state.used)) goto done; } }/* Grab the first unused counter starting with idx */ idx = sched->state.counter; -for_each_set_bit_cont (idx, c->idxmsk,X86_PMC_IDX_FIXED ) { +for_each_set_bit_from (idx, c->idxmsk,X86_PMC_IDX_FIXED ) {if (!__test_and_set_bit (idx, sched->state.used)) goto done; }
include/linux/bitops.h +4 -1
@@ -27,11 +27,14 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) = find_next_bit((addr), (size), (bit) + 1))/* same as for_each_set_bit() but use bit as value to start with */ -#define for_each_set_bit_cont (bit, addr, size) \ +#define for_each_set_bit_from (bit, addr, size) \ for ((bit) = find_next_bit((addr), (size), (bit)); \ (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1)) +#define for_each_set_bit_cont (bit, addr, size) \ + for_each_set_bit_from(bit, addr, size) +static __inline__int get_bitmask_order (unsigned int count) {int order;
tools/perf/util/include/linux/bitops.h +1 -1
@@ -15,7 +15,7 @@ (bit) = find_next_bit((addr), (size), (bit) + 1))/* same as for_each_set_bit() but use bit as value to start with */ -#define for_each_set_bit_cont (bit, addr, size) \ +#define for_each_set_bit_from (bit, addr, size) \ for ((bit) = find_next_bit((addr), (size), (bit)); \ (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1))
Signature · 1 line
1.7.4.4
PATCH 2/7 bitops: remove for_each_set_bit_cont
In reply to Akinobu MitaRemove for_each_set_bit_cont() after confirming that no one uses for_each_set_bit_cont() anymore.
--- include/linux/bitops.h | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
include/linux/bitops.h +0 -3
@@ -32,9 +32,6 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1)) -#define for_each_set_bit_cont (bit, addr, size) \ - for_each_set_bit_from(bit, addr, size) -static __inline__int get_bitmask_order (unsigned int count) {int order;
Signature · 1 line
1.7.4.4
PATCH 3/7 bitops: introduce list_for_each_clear_bit
In reply to Akinobu MitaIntroduce list_for_each_clear_bit() and list_for_each_clear_bit_from(). They are similar to for_each_set_bit() and list_for_each_set_bit_from(), but they iterate over all the cleared bits in a memory region.
--- include/linux/bitops.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
include/linux/bitops.h +11 -0
@@ -32,6 +32,17 @@ extern unsigned long __sw_hweight64(__u64 w); (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1)) +#define for_each_clear_bit (bit, addr, size) \ + for ((bit) = find_first_zero_bit((addr), (size)); \ + (bit) < (size); \ + (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) + +/* same as for_each_clear_bit() but use bit as value to start with */ +#define for_each_clear_bit_from (bit, addr, size) \ + for ((bit) = find_next_zero_bit((addr), (size), (bit)); \ + (bit) < (size); \ + (bit) = find_next_zero_bit((addr), (size), (bit) + 1)) +static __inline__int get_bitmask_order (unsigned int count) {int order;
Signature · 1 line
1.7.4.4
Re: [PATCH 3/7] bitops: introduce list_for_each_clear_bit
Hello.
Quoted 1 line · Akinobu Mita
Introduce
list_for_each_clear_bit()andlist_for_each_clear_bit_from().
It seems you've got somewhat muddled -- you're actually introducingfor_each_clear_bit() and for_each_clear_bit_from()
Quoted 16 lines
They are similar to
for_each_set_bit()andlist_for_each_set_bit_from(), but they iterate over all the cleared bits in a memory region.Signed-off-by Akinobu Mita<[email protected]>Cc Robert Richter<[email protected]>Cc Thomas Gleixner<[email protected]>Cc Ingo Molnar<[email protected]>Cc "H. Peter Anvin"<[email protected]>Cc David Woodhouse<[email protected]>Cc Martin Schwidefsky<[email protected]>Cc Heiko Carstens<[email protected]>
WBR, Sergei
Re: [PATCH 3/7] bitops: introduce list_for_each_clear_bit
2012/1/14 Sergei Shtylyov <[email protected]>:
Quoted 9 lines
Hello.
Quoted 1 line · Akinobu Mita
Introduce
list_for_each_clear_bit()andlist_for_each_clear_bit_from().It seems you've got somewhat muddled -- you're actually introducing
for_each_clear_bit()andfor_each_clear_bit_from()
Oops, thanks for a notification.
PATCH 4/7 mtd: use for_each_clear_bit
In reply to Akinobu MitaUse for_each_clear_bit() to iterate over all the cleared bit in a memory region.
--- drivers/mtd/chips/cfi_cmdset_0001.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +2 -4
@@ -2526,12 +2526,10 @@ static void cfi_intelext_restore_locks(struct mtd_info *mtd)if (!region->lockmap)continue ; -for (block =0 ; block < region->numblocks; block++) { +for_each_clear_bit (block, region->lockmap, region->numblocks) { len = region->erasesize; adr = region->offset + block * len; - -if (!test_bit (block, region->lockmap)) -cfi_intelext_unlock (mtd, adr, len); +cfi_intelext_unlock (mtd, adr, len); } } }
Signature · 1 line
1.7.4.4
PATCH 5/7 s390/char: use for_each_clear_bit
In reply to Akinobu MitaUse for_each_clear_bit() to iterate over all the cleared bit in a memory region.
--- drivers/s390/char/sclp_cmd.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/s390/char/sclp_cmd.c +2 -3
@@ -441,9 +441,8 @@ static int sclp_mem_notifier(struct notifier_block *nb, start = arg->start_pfn <<PAGE_SHIFT ; size = arg->nr_pages <<PAGE_SHIFT ;mutex_lock (&sclp_mem_mutex); -for (id =0 ; id <= sclp_max_storage_id; id++) -if (!test_bit (id, sclp_storage_ids)) -sclp_attach_storage (id); +for_each_clear_bit (id, sclp_storage_ids, sclp_max_storage_id +1 ) +sclp_attach_storage (id);switch (action) {case MEM_ONLINE :case MEM_GOING_OFFLINE :
Signature · 1 line
1.7.4.4
PATCH 6/7 uwb: use for_each_clear_bit
In reply to Akinobu MitaUse for_each_clear_bit() to iterate over all the cleared bit in a memory region.
--- drivers/uwb/allocator.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/uwb/allocator.c +2 -4
@@ -334,10 +334,8 @@ int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *availab/* fill the not available vector from the available bm */ -for (bit_index =0 ; bit_index <UWB_NUM_MAS ; bit_index++) { -if (!test_bit (bit_index, available->bm)) - ai->bm[bit_index] =UWB_RSV_MAS_NOT_AVAIL ; - } +for_each_clear_bit (bit_index, available->bm,UWB_NUM_MAS ) + ai->bm[bit_index] =UWB_RSV_MAS_NOT_AVAIL ;if (ai->max_interval ==1 ) {get_row_descriptors (ai);
Signature · 1 line
1.7.4.4
PATCH 7/7 x86: use for_each_clear_bit_from
In reply to Akinobu MitaUse for_each_clear_bit() to iterate over all the cleared bit in a memory region.
--- arch/x86/kernel/irqinit.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/irqinit.c +3 -3
@@ -306,10 +306,10 @@ void __init native_init_IRQ(void)* us. (some of these will be overridden and become * 'special' SMP interrupts) */ -for (i =FIRST_EXTERNAL_VECTOR ; i <NR_VECTORS ; i++) { + i =FIRST_EXTERNAL_VECTOR ; +for_each_clear_bit_from (i, used_vectors,NR_VECTORS ) {/* IA32_SYSCALL_VECTOR could be used in trap_init already. */ -if (!test_bit (i, used_vectors)) -set_intr_gate (i, interrupt[i-FIRST_EXTERNAL_VECTOR ]); +set_intr_gate (i, interrupt[i -FIRST_EXTERNAL_VECTOR ]); }if (!acpi_ioapic && !of_ioapic)
Signature · 1 line
1.7.4.4