Skip to contentSkip to conversation

sched: Use for_each_bit

PATCH In review Akinobu Mita 3 participants 12 messages Jan 31, 2010 – Feb 2, 2010

Subsystems (10)
lore
Share & tools
lore
#2 lore raw

PATCH 3/7 phonet: Use for_each_bit

In reply to Akinobu Mita
---
 net/phonet/pn_dev.c     |    3 +--
 net/phonet/pn_netlink.c |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
net/phonet/pn_dev.c +1 -2
index bc4a33b..52edfc4 100644
@@ -107,8 +107,7 @@ static void phonet_device_destroy(struct net_device *dev)
 	if (pnd) {
 		u8 addr;
 
-		for (addr = find_first_bit(pnd->addrs, 64); addr < 64;
-			addr = find_next_bit(pnd->addrs, 64, 1+addr))
+		for_each_bit(addr, pnd->addrs, 64)
 			phonet_address_notify(RTM_DELADDR, dev, addr);
 		kfree(pnd);
 	}
net/phonet/pn_netlink.c +1 -2
index 2e6c7eb..4edc048 100644
@@ -141,8 +141,7 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 			continue;
 
 		addr_idx = 0;
-		for (addr = find_first_bit(pnd->addrs, 64); addr < 64;
-			addr = find_next_bit(pnd->addrs, 64, 1+addr)) {
+		for_each_bit(addr, pnd->addrs, 64) {
 			if (addr_idx++ < addr_start_idx)
 				continue;
 
Signature · 1 line
1.6.0.6
#4 lore raw

PATCH 5/7 infiniband: Use for_each_bit

In reply to Akinobu Mita
Cc Roland Dreier <[email protected]>
Cc Sean Hefty <[email protected]>
Cc Hal Rosenstock <[email protected]>
---
 drivers/infiniband/core/mad.c |   21 +++++----------------
 1 files changed, 5 insertions(+), 16 deletions(-)
drivers/infiniband/core/mad.c +5 -16
index 7522008..a0b00ba 100644
@@ -1193,10 +1193,7 @@ static int method_in_use(struct ib_mad_mgmt_method_table **method,
 {
 	int i;
 
-	for (i = find_first_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS);
-	     i < IB_MGMT_MAX_METHODS;
-	     i = find_next_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS,
-			       1+i)) {
+	for_each_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS) {
 		if ((*method)->agent[i]) {
 			printk(KERN_ERR PFX "Method %d already in use\n", i);
 			return -EINVAL;
@@ -1330,13 +1327,9 @@ static int add_nonoui_reg_req(struct ib_mad_reg_req *mad_reg_req,
 		goto error3;
 
 	/* Finally, add in methods being registered */
-	for (i = find_first_bit(mad_reg_req->method_mask,
-				IB_MGMT_MAX_METHODS);
-	     i < IB_MGMT_MAX_METHODS;
-	     i = find_next_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS,
-			       1+i)) {
+	for_each_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS)
 		(*method)->agent[i] = agent_priv;
-	}
+
 	return 0;
 
 error3:
@@ -1429,13 +1422,9 @@ check_in_use:
 		goto error4;
 
 	/* Finally, add in methods being registered */
-	for (i = find_first_bit(mad_reg_req->method_mask,
-				IB_MGMT_MAX_METHODS);
-	     i < IB_MGMT_MAX_METHODS;
-	     i = find_next_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS,
-			       1+i)) {
+	for_each_bit(i, mad_reg_req->method_mask, IB_MGMT_MAX_METHODS)
 		(*method)->agent[i] = agent_priv;
-	}
+
 	return 0;
 
 error4:
Signature · 1 line
1.6.0.6
#5 lore raw

PATCH 6/7 atm: Use for_each_bit

In reply to Akinobu Mita
---
 drivers/atm/lanai.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/atm/lanai.c +3 -4
index cf97c34..97700f8 100644
@@ -306,11 +306,10 @@ static void vci_bitfield_iterate(struct lanai_dev *lanai,
 	const unsigned long *lp,
 	void (*func)(struct lanai_dev *,vci_t vci))
 {
-	vci_t vci = find_first_bit(lp, NUM_VCI);
-	while (vci < NUM_VCI) {
+	vci_t vci;
+
+	for_each_bit(vci, lp, NUM_VCI)
 		func(lanai, vci);
-		vci = find_next_bit(lp, NUM_VCI, vci + 1);
-	}
 }
 
 /* -------------------- BUFFER  UTILITIES: */
Signature · 1 line
1.6.0.6
#0 lore raw

PATCH 1/7 sched: Use for_each_bit

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/sched_cpupri.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
kernel/sched_cpupri.c +1 -3
index 597b330..eeb3506 100644
@@ -47,9 +47,7 @@ static int convert_prio(int prio)
 }
 
 #define for_each_cpupri_active(array, idx)                    \
-  for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES);     \
-       idx < CPUPRI_NR_PRIORITIES;                            \
-       idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+	for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)
 
 /**
  * cpupri_find - find the best (lowest-pri) CPU in the system
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 2/7 bitmap: Use for_each_bit

---
 lib/bitmap.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
lib/bitmap.c +4 -9
index 11bf497..84292c9 100644
@@ -733,10 +733,9 @@ void bitmap_remap(unsigned long *dst, const unsigned long *src,
 	bitmap_zero(dst, bits);
 
 	w = bitmap_weight(new, bits);
-	for (oldbit = find_first_bit(src, bits);
-	     oldbit < bits;
-	     oldbit = find_next_bit(src, bits, oldbit + 1)) {
+	for_each_bit(oldbit, src, bits) {
 	     	int n = bitmap_pos_to_ord(old, oldbit, bits);
+
 		if (n < 0 || w == 0)
 			set_bit(oldbit, dst);	/* identity map */
 		else
@@ -903,9 +902,7 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig,
 	 */
 
 	m = 0;
-	for (n = find_first_bit(relmap, bits);
-	     n < bits;
-	     n = find_next_bit(relmap, bits, n + 1)) {
+	for_each_bit(n, relmap, bits) {
 		/* m == bitmap_pos_to_ord(relmap, n, bits) */
 		if (test_bit(m, orig))
 			set_bit(n, dst);
@@ -934,9 +931,7 @@ void bitmap_fold(unsigned long *dst, const unsigned long *orig,
 		return;
 	bitmap_zero(dst, bits);
 
-	for (oldbit = find_first_bit(orig, bits);
-	     oldbit < bits;
-	     oldbit = find_next_bit(orig, bits, oldbit + 1))
+	for_each_bit(oldbit, orig, bits)
 		set_bit(oldbit % sz, dst);
 }
 EXPORT_SYMBOL(bitmap_fold);
Signature · 1 line
1.6.0.6
#6 lore raw

PATCH 7/7 hpet: Use for_each_bit

In reply to Akinobu Mita
---
 drivers/char/hpet.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/char/hpet.c +1 -3
index e481c59..b509185 100644
@@ -215,9 +215,7 @@ static void hpet_timer_set_irq(struct hpet_dev *devp)
 	else
 		v &= ~0xffff;
 
-	for (irq = find_first_bit(&v, HPET_MAX_IRQ); irq < HPET_MAX_IRQ;
-		irq = find_next_bit(&v, HPET_MAX_IRQ, 1 + irq)) {
-
+	for_each_bit(irq, &v, HPET_MAX_IRQ) {
 		if (irq >= nr_irqs) {
 			irq = HPET_MAX_IRQ;
 			break;
Signature · 1 line
1.6.0.6
#3 lore raw

PATCH 4/7 intel-iommu: Use for_each_bit

In reply to Akinobu Mita
---
 drivers/pci/intel-iommu.c |   33 +++++++--------------------------
 1 files changed, 7 insertions(+), 26 deletions(-)
drivers/pci/intel-iommu.c +7 -26
index 4173125..7768bf8 100644
@@ -491,13 +491,11 @@ static void domain_update_iommu_coherency(struct dmar_domain *domain)
 
 	domain->iommu_coherency = 1;
 
-	i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus);
-	for (; i < g_num_of_iommus; ) {
+	for_each_bit(i, &domain->iommu_bmp, g_num_of_iommus) {
 		if (!ecap_coherent(g_iommus[i]->ecap)) {
 			domain->iommu_coherency = 0;
 			break;
 		}
-		i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1);
 	}
 }
 
@@ -507,13 +505,11 @@ static void domain_update_iommu_snooping(struct dmar_domain *domain)
 
 	domain->iommu_snooping = 1;
 
-	i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus);
-	for (; i < g_num_of_iommus; ) {
+	for_each_bit(i, &domain->iommu_bmp, g_num_of_iommus) {
 		if (!ecap_sc_support(g_iommus[i]->ecap)) {
 			domain->iommu_snooping = 0;
 			break;
 		}
-		i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1);
 	}
 }
 
@@ -1194,8 +1190,7 @@ void free_dmar_iommu(struct intel_iommu *iommu)
 	unsigned long flags;
 
 	if ((iommu->domains) && (iommu->domain_ids)) {
-		i = find_first_bit(iommu->domain_ids, cap_ndoms(iommu->cap));
-		for (; i < cap_ndoms(iommu->cap); ) {
+		for_each_bit(i, iommu->domain_ids, cap_ndoms(iommu->cap)) {
 			domain = iommu->domains[i];
 			clear_bit(i, iommu->domain_ids);
 
@@ -1207,9 +1202,6 @@ void free_dmar_iommu(struct intel_iommu *iommu)
 					domain_exit(domain);
 			}
 			spin_unlock_irqrestore(&domain->iommu_lock, flags);
-
-			i = find_next_bit(iommu->domain_ids,
-				cap_ndoms(iommu->cap), i+1);
 		}
 	}
 
@@ -1292,14 +1284,11 @@ static void iommu_detach_domain(struct dmar_domain *domain,
 
 	spin_lock_irqsave(&iommu->lock, flags);
 	ndomains = cap_ndoms(iommu->cap);
-	num = find_first_bit(iommu->domain_ids, ndomains);
-	for (; num < ndomains; ) {
+	for_each_bit(num, iommu->domain_ids, ndomains) {
 		if (iommu->domains[num] == domain) {
 			found = 1;
 			break;
 		}
-		num = find_next_bit(iommu->domain_ids,
-				    cap_ndoms(iommu->cap), num+1);
 	}
 
 	if (found) {
@@ -1485,15 +1474,12 @@ static int domain_context_mapping_one(struct dmar_domain *domain, int segment,
 
 		/* find an available domain id for this device in iommu */
 		ndomains = cap_ndoms(iommu->cap);
-		num = find_first_bit(iommu->domain_ids, ndomains);
-		for (; num < ndomains; ) {
+		for_each_bit(num, iommu->domain_ids, ndomains) {
 			if (iommu->domains[num] == domain) {
 				id = num;
 				found = 1;
 				break;
 			}
-			num = find_next_bit(iommu->domain_ids,
-					    cap_ndoms(iommu->cap), num+1);
 		}
 
 		if (found == 0) {
@@ -3441,12 +3427,9 @@ static int vm_domain_min_agaw(struct dmar_domain *domain)
 	int i;
 	int min_agaw = domain->agaw;
 
-	i = find_first_bit(&domain->iommu_bmp, g_num_of_iommus);
-	for (; i < g_num_of_iommus; ) {
+	for_each_bit(i, &domain->iommu_bmp, g_num_of_iommus) {
 		if (min_agaw > g_iommus[i]->agaw)
 			min_agaw = g_iommus[i]->agaw;
-
-		i = find_next_bit(&domain->iommu_bmp, g_num_of_iommus, i+1);
 	}
 
 	return min_agaw;
@@ -3512,8 +3495,7 @@ static void iommu_free_vm_domain(struct dmar_domain *domain)
 		iommu = drhd->iommu;
 
 		ndomains = cap_ndoms(iommu->cap);
-		i = find_first_bit(iommu->domain_ids, ndomains);
-		for (; i < ndomains; ) {
+		for_each_bit(i, iommu->domain_ids, ndomains) {
 			if (iommu->domains[i] == domain) {
 				spin_lock_irqsave(&iommu->lock, flags);
 				clear_bit(i, iommu->domain_ids);
@@ -3521,7 +3503,6 @@ static void iommu_free_vm_domain(struct dmar_domain *domain)
 				spin_unlock_irqrestore(&iommu->lock, flags);
 				break;
 			}
-			i = find_next_bit(iommu->domain_ids, ndomains, i+1);
 		}
 	}
 }
Signature · 1 line
1.6.0.6
#7 lore raw
In reply to Akinobu Mita
Quoted 5 lines · Akinobu Mita

 #define for_each_cpupri_active(array, idx)                    \
-  for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES);     \
-       idx < CPUPRI_NR_PRIORITIES;                            \
-       idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+       for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)

It should be called for_each_set_bit().

maintainer
#8 lore raw
Quoted 8 lines · On Sun, 31 Jan 2010 14:06:10 +0200 Alexey Dobriyan <[email protected]> wrote:
Quoted 5 lines · Akinobu Mita

__#define for_each_cpupri_active(array, idx) __ __ __ __ __ __ __ __ __ __\
- __for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES); __ __ \
- __ __ __ idx < CPUPRI_NR_PRIORITIES; __ __ __ __ __ __ __ __ __ __ __ __ __ __\
- __ __ __ idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+ __ __ __ for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)

It should be called for_each_set_bit().

Agree.

#9 lore raw

2010/2/1 Andrew Morton <[email protected]>:

Quoted 9 lines · On Sun, 31 Jan 2010 14:06:10 +0200 Alexey Dobriyan <[email protected]> wrote:
Quoted 8 lines · Akinobu Mita
Quoted 5 lines

__#define for_each_cpupri_active(array, idx) __ __ __ __ __ __ __ __ __ __\
- __for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES); __ __ \
- __ __ __ idx < CPUPRI_NR_PRIORITIES; __ __ __ __ __ __ __ __ __ __ __ __ __ __\
- __ __ __ idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+ __ __ __ for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)

Quoted 3 lines
Quoted 1 line

It should be called for_each_set_bit().

Agree.

(I'm resending because I failed to reply all)

You mean for_each_bit() should be renamed to for_each_set_bit() ?

I'm not sure. But if so, find_first_bit() also should be renamed to find_first_set_bit() and so on?

maintainer
#10 lore raw
Quoted 10 lines · On Mon, 1 Feb 2010 11:54:14 +0900 Akinobu Mita <[email protected]> wrote:

2010/2/1 Andrew Morton <[email protected]>:

Quoted 9 lines · On Sun, 31 Jan 2010 14:06:10 +0200 Alexey Dobriyan <[email protected]> wrote:
Quoted 8 lines · Akinobu Mita
Quoted 5 lines

__#define for_each_cpupri_active(array, idx) __ __ __ __ __ __ __ __ __ __\
- __for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES); __ __ \
- __ __ __ idx < CPUPRI_NR_PRIORITIES; __ __ __ __ __ __ __ __ __ __ __ __ __ __\
- __ __ __ idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+ __ __ __ for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

It should be called for_each_set_bit().

Agree.

(I'm resending because I failed to reply all)

You mean for_each_bit() should be renamed to for_each_set_bit() ?

Yes.

Quoted 2 lines

I'm not sure. But if so, find_first_bit() also should be renamed to find_first_set_bit() and so on?

Yes, it should have been. It's a bit late to correct that mistake, but it's not too late to fix for_each_bit().

#11 lore raw
In reply to Akinobu Mita
Commit-ID:  90fdbdb48442a03c72cae5463e6edb64cb3a3a7d
Gitweb:     http://git.kernel.org/tip/90fdbdb48442a03c72cae5463e6edb64cb3a3a7d
Author:     Akinobu Mita <[email protected]>
AuthorDate: Sun, 31 Jan 2010 20:53:24 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 2 Feb 2010 06:58:27 +0100

sched: Use for_each_bit

No change in functionality.

Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/sched_cpupri.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
kernel/sched_cpupri.c +1 -3
index 597b330..eeb3506 100644
@@ -47,9 +47,7 @@ static int convert_prio(int prio)
 }
 
 #define for_each_cpupri_active(array, idx)                    \
-  for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES);     \
-       idx < CPUPRI_NR_PRIORITIES;                            \
-       idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+	for_each_bit(idx, array, CPUPRI_NR_PRIORITIES)
 
 /**
  * cpupri_find - find the best (lowest-pri) CPU in the system