Skip to contentSkip to conversation

bitops: introduce for_each_clear_bit()

PATCH In review Akinobu Mita 2 participants 10 messages Jan 13, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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(-)
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]>
Signature · 1 line
1.7.4.4
#1 lore raw

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.

Cc Robert Richter <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 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
index 5adce10..d594326 100644
@@ -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
index 3c1063a..9e79b2a 100644
@@ -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
index 62cdee7..f1584833 100644
@@ -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
#2 lore raw

PATCH 2/7 bitops: remove for_each_set_bit_cont

In reply to Akinobu Mita

Remove for_each_set_bit_cont() after confirming that no one uses for_each_set_bit_cont() anymore.

Cc Robert Richter <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 include/linux/bitops.h |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
include/linux/bitops.h +0 -3
index 9e79b2a..15ad702 100644
@@ -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
#3 lore raw

PATCH 3/7 bitops: introduce list_for_each_clear_bit

In reply to Akinobu Mita

Introduce 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.

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]>
---
 include/linux/bitops.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
include/linux/bitops.h +11 -0
index 15ad702..c8a0d65 100644
@@ -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
#4 lore raw

Re: [PATCH 3/7] bitops: introduce list_for_each_clear_bit

Hello.

Quoted 1 line · Akinobu Mita

Introduce list_for_each_clear_bit() and list_for_each_clear_bit_from().

It seems you've got somewhat muddled -- you're actually introducing
for_each_clear_bit() and for_each_clear_bit_from()

Quoted 16 lines

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.

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

#5 lore raw

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() and list_for_each_clear_bit_from().

  It seems you've got somewhat muddled -- you're actually introducing for_each_clear_bit() and for_each_clear_bit_from()

Oops, thanks for a notification.

#6 lore raw

PATCH 4/7 mtd: use for_each_clear_bit

In reply to Akinobu Mita

Use 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
index e1e122f..9bcd1f4 100644
@@ -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
#7 lore raw

PATCH 5/7 s390/char: use for_each_clear_bit

In reply to Akinobu Mita

Use 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
index 0b54a91..168525a 100644
@@ -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
#8 lore raw

PATCH 6/7 uwb: use for_each_clear_bit

In reply to Akinobu Mita

Use 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
index e45e673..6e3e713 100644
@@ -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
#9 lore raw

PATCH 7/7 x86: use for_each_clear_bit_from

In reply to Akinobu Mita

Use for_each_clear_bit() to iterate over all the cleared bit in a memory region.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/irqinit.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/irqinit.c +3 -3
index 313fb5c..43e2b1c 100644
@@ -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