linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] percpu: use bitmap_clear
@ 2012-01-20 15:15 Akinobu Mita
  2012-01-20 15:15 ` [PATCH] ocfs2: use find_last_bit Akinobu Mita
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Tejun Heo, Christoph Lameter

Use bitmap_clear rather than clearing individual bits in a memory region.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux-foundation.org>
---
 mm/percpu-vm.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 12a48a88..405d331 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -184,8 +184,7 @@ static void pcpu_unmap_pages(struct pcpu_chunk *chunk,
 				   page_end - page_start);
 	}
 
-	for (i = page_start; i < page_end; i++)
-		__clear_bit(i, populated);
+	bitmap_clear(populated, page_start, page_end - page_start);
 }
 
 /**
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] ocfs2: use find_last_bit
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
@ 2012-01-20 15:15 ` Akinobu Mita
  2012-01-20 15:15 ` [PATCH] ocfs2: use bitmap_weight() Akinobu Mita
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Mark Fasheh, Joel Becker, ocfs2-devel

We already have find_last_bit. So just use it as described in the comment.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: ocfs2-devel@oss.oracle.com
---
 fs/ocfs2/cluster/heartbeat.c |   18 ++----------------
 1 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index cd36cb5..120fad9 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -956,23 +956,9 @@ out:
 	return changed;
 }
 
-/* This could be faster if we just implmented a find_last_bit, but I
- * don't think the circumstances warrant it. */
-static int o2hb_highest_node(unsigned long *nodes,
-			     int numbits)
+static int o2hb_highest_node(unsigned long *nodes, int numbits)
 {
-	int highest, node;
-
-	highest = numbits;
-	node = -1;
-	while ((node = find_next_bit(nodes, numbits, node + 1)) != -1) {
-		if (node >= numbits)
-			break;
-
-		highest = node;
-	}
-
-	return highest;
+	return find_last_bit(nodes, numbits);
 }
 
 static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] ocfs2: use bitmap_weight()
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
  2012-01-20 15:15 ` [PATCH] ocfs2: use find_last_bit Akinobu Mita
@ 2012-01-20 15:15 ` Akinobu Mita
  2012-01-20 15:15 ` [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear() Akinobu Mita
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Mark Fasheh, Joel Becker, ocfs2-devel

Use bitmap_weight instead of reinventing the wheel.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: ocfs2-devel@oss.oracle.com
---
 fs/ocfs2/cluster/heartbeat.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 120fad9..7542566 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -35,6 +35,7 @@
 #include <linux/time.h>
 #include <linux/debugfs.h>
 #include <linux/slab.h>
+#include <linux/bitmap.h>
 
 #include "heartbeat.h"
 #include "tcp.h"
@@ -282,15 +283,6 @@ struct o2hb_bio_wait_ctxt {
 	int               wc_error;
 };
 
-static int o2hb_pop_count(void *map, int count)
-{
-	int i = -1, pop = 0;
-
-	while ((i = find_next_bit(map, count, i + 1)) < count)
-		pop++;
-	return pop;
-}
-
 static void o2hb_write_timeout(struct work_struct *work)
 {
 	int failed, quorum;
@@ -307,9 +299,9 @@ static void o2hb_write_timeout(struct work_struct *work)
 		spin_lock_irqsave(&o2hb_live_lock, flags);
 		if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
 			set_bit(reg->hr_region_num, o2hb_failed_region_bitmap);
-		failed = o2hb_pop_count(&o2hb_failed_region_bitmap,
+		failed = bitmap_weight(o2hb_failed_region_bitmap,
 					O2NM_MAX_REGIONS);
-		quorum = o2hb_pop_count(&o2hb_quorum_region_bitmap,
+		quorum = bitmap_weight(o2hb_quorum_region_bitmap,
 					O2NM_MAX_REGIONS);
 		spin_unlock_irqrestore(&o2hb_live_lock, flags);
 
@@ -771,7 +763,7 @@ static void o2hb_set_quorum_device(struct o2hb_region *reg)
 	 * If global heartbeat active, unpin all regions if the
 	 * region count > CUT_OFF
 	 */
-	if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
+	if (bitmap_weight(o2hb_quorum_region_bitmap,
 			   O2NM_MAX_REGIONS) > O2HB_PIN_CUT_OFF)
 		o2hb_region_unpin(NULL);
 unlock:
@@ -1813,7 +1805,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
 	live_threshold = O2HB_LIVE_THRESHOLD;
 	if (o2hb_global_heartbeat_active()) {
 		spin_lock(&o2hb_live_lock);
-		if (o2hb_pop_count(&o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1)
+		if (bitmap_weight(o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1)
 			live_threshold <<= 1;
 		spin_unlock(&o2hb_live_lock);
 	}
@@ -2164,7 +2156,7 @@ static void o2hb_heartbeat_group_drop_item(struct config_group *group,
 	if (!o2hb_dependent_users)
 		goto unlock;
 
-	if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
+	if (bitmap_weight(o2hb_quorum_region_bitmap,
 			   O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
 		o2hb_region_pin(NULL);
 
@@ -2458,7 +2450,7 @@ static int o2hb_region_inc_user(const char *region_uuid)
 	if (o2hb_dependent_users > 1)
 		goto unlock;
 
-	if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
+	if (bitmap_weight(o2hb_quorum_region_bitmap,
 			   O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
 		ret = o2hb_region_pin(NULL);
 
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
  2012-01-20 15:15 ` [PATCH] ocfs2: use find_last_bit Akinobu Mita
  2012-01-20 15:15 ` [PATCH] ocfs2: use bitmap_weight() Akinobu Mita
@ 2012-01-20 15:15 ` Akinobu Mita
  2012-01-20 15:27   ` Akinobu Mita
  2012-01-20 15:28   ` Konrad Rzeszutek Wilk
  2012-01-20 15:15 ` [PATCH] hpsa: use find_first_zero_bit Akinobu Mita
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Jeremy Fitzhardinge, Konrad Rzeszutek Wilk,
	xen-devel, virtualization

Use bitmap_set and bitmap_clear rather than modifying individual bits
in a memory region.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: xen-devel@lists.xensource.com
Cc: virtualization@lists.linux-foundation.org
---
 drivers/block/xen-blkfront.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 2f22874..619868d 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -43,6 +43,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/scatterlist.h>
+#include <linux/bitmap.h>
 
 #include <xen/xen.h>
 #include <xen/xenbus.h>
@@ -177,8 +178,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
 
 	spin_lock(&minor_lock);
 	if (find_next_bit(minors, end, minor) >= end) {
-		for (; minor < end; ++minor)
-			__set_bit(minor, minors);
+		bitmap_set(minors, minor, nr);
 		rc = 0;
 	} else
 		rc = -EBUSY;
@@ -193,8 +193,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
 
 	BUG_ON(end > nr_minors);
 	spin_lock(&minor_lock);
-	for (; minor < end; ++minor)
-		__clear_bit(minor, minors);
+	bitmap_clear(minors,  minor, nr);
 	spin_unlock(&minor_lock);
 }
 
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] hpsa: use find_first_zero_bit
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
                   ` (2 preceding siblings ...)
  2012-01-20 15:15 ` [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear() Akinobu Mita
@ 2012-01-20 15:15 ` Akinobu Mita
  2012-01-20 15:41   ` scameron
  2012-01-20 15:15 ` [PATCH] sysctl: use bitmap library functions Akinobu Mita
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Stephen M. Cameron, iss_storagedev,
	James E.J. Bottomley, linux-scsi

Use find_first_zero_bit to find the first cleared bit in a memory region.

This also includes the following minor changes.
- Use bitmap_zero
- Reduce unnecessary atomic bitops usage

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
Cc: iss_storagedev@hp.com
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/hpsa.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 7d14443..7f79ed8 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -577,21 +577,19 @@ static int hpsa_find_target_lun(struct ctlr_info *h,
 	int i, found = 0;
 	DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES);
 
-	memset(&lun_taken[0], 0, HPSA_MAX_DEVICES >> 3);
+	bitmap_zero(lun_taken, HPSA_MAX_DEVICES);
 
 	for (i = 0; i < h->ndevices; i++) {
 		if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
-			set_bit(h->dev[i]->target, lun_taken);
+			__set_bit(h->dev[i]->target, lun_taken);
 	}
 
-	for (i = 0; i < HPSA_MAX_DEVICES; i++) {
-		if (!test_bit(i, lun_taken)) {
-			/* *bus = 1; */
-			*target = i;
-			*lun = 0;
-			found = 1;
-			break;
-		}
+	i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES);
+	if (i < HPSA_MAX_DEVICES) {
+		/* *bus = 1; */
+		*target = i;
+		*lun = 0;
+		found = 1;
 	}
 	return !found;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH] sysctl: use bitmap library functions
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
                   ` (3 preceding siblings ...)
  2012-01-20 15:15 ` [PATCH] hpsa: use find_first_zero_bit Akinobu Mita
@ 2012-01-20 15:15 ` Akinobu Mita
  2012-01-20 15:19 ` [PATCH] percpu: use bitmap_clear Christoph Lameter
  2012-01-20 17:24 ` Tejun Heo
  6 siblings, 0 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:15 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita

Use bitmap_set() instead of using set_bit() for each bit.  This conversion
is valid because the bitmap is private in the function call and atomic
bitops was unnecessary.

This also includes minor change.
- Use bitmap_copy() for shorter typing

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 kernel/sysctl.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index f487f25..57c92a7 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -58,6 +58,7 @@
 #include <linux/oom.h>
 #include <linux/kmod.h>
 #include <linux/capability.h>
+#include <linux/bitmap.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -2884,9 +2885,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
 				}
 			}
 
-			while (val_a <= val_b)
-				set_bit(val_a++, tmp_bitmap);
-
+			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
 			first = 0;
 			proc_skip_char(&kbuf, &left, '\n');
 		}
@@ -2929,8 +2928,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
 			if (*ppos)
 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
 			else
-				memcpy(bitmap, tmp_bitmap,
-					BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
+				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
 		}
 		kfree(tmp_bitmap);
 		*lenp -= left;
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] percpu: use bitmap_clear
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
                   ` (4 preceding siblings ...)
  2012-01-20 15:15 ` [PATCH] sysctl: use bitmap library functions Akinobu Mita
@ 2012-01-20 15:19 ` Christoph Lameter
  2012-01-20 17:24 ` Tejun Heo
  6 siblings, 0 replies; 16+ messages in thread
From: Christoph Lameter @ 2012-01-20 15:19 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, akpm, Tejun Heo

On Sat, 21 Jan 2012, Akinobu Mita wrote:

> Use bitmap_clear rather than clearing individual bits in a memory region.

Acked-by: Christoph Lameter <cl@linux.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 15:15 ` [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear() Akinobu Mita
@ 2012-01-20 15:27   ` Akinobu Mita
  2012-01-20 15:28   ` Konrad Rzeszutek Wilk
  1 sibling, 0 replies; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:27 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Jeremy Fitzhardinge, Konrad Rzeszutek Wilk,
	xen-devel, virtualization

I used Jeremy Fitzhardinge's old email address...

2012/1/21 Akinobu Mita <akinobu.mita@gmail.com>:
> Use bitmap_set and bitmap_clear rather than modifying individual bits
> in a memory region.
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

Cc: Jeremy Fitzhardinge <jeremy@goop.org>

> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: xen-devel@lists.xensource.com
> Cc: virtualization@lists.linux-foundation.org
> ---
>  drivers/block/xen-blkfront.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 2f22874..619868d 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -43,6 +43,7 @@
>  #include <linux/slab.h>
>  #include <linux/mutex.h>
>  #include <linux/scatterlist.h>
> +#include <linux/bitmap.h>
>
>  #include <xen/xen.h>
>  #include <xen/xenbus.h>
> @@ -177,8 +178,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
>
>        spin_lock(&minor_lock);
>        if (find_next_bit(minors, end, minor) >= end) {
> -               for (; minor < end; ++minor)
> -                       __set_bit(minor, minors);
> +               bitmap_set(minors, minor, nr);
>                rc = 0;
>        } else
>                rc = -EBUSY;
> @@ -193,8 +193,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
>
>        BUG_ON(end > nr_minors);
>        spin_lock(&minor_lock);
> -       for (; minor < end; ++minor)
> -               __clear_bit(minor, minors);
> +       bitmap_clear(minors,  minor, nr);
>        spin_unlock(&minor_lock);
>  }
>
> --
> 1.7.4.4
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 15:15 ` [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear() Akinobu Mita
  2012-01-20 15:27   ` Akinobu Mita
@ 2012-01-20 15:28   ` Konrad Rzeszutek Wilk
  2012-01-20 15:41     ` Akinobu Mita
  1 sibling, 1 reply; 16+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-01-20 15:28 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, akpm, Jeremy Fitzhardinge, xen-devel, virtualization

On Sat, Jan 21, 2012 at 12:15:26AM +0900, Akinobu Mita wrote:
> Use bitmap_set and bitmap_clear rather than modifying individual bits
> in a memory region.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: xen-devel@lists.xensource.com
> Cc: virtualization@lists.linux-foundation.org
> ---
>  drivers/block/xen-blkfront.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 2f22874..619868d 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -43,6 +43,7 @@
>  #include <linux/slab.h>
>  #include <linux/mutex.h>
>  #include <linux/scatterlist.h>
> +#include <linux/bitmap.h>
>  
>  #include <xen/xen.h>
>  #include <xen/xenbus.h>
> @@ -177,8 +178,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
>  
>  	spin_lock(&minor_lock);
>  	if (find_next_bit(minors, end, minor) >= end) {
> -		for (; minor < end; ++minor)
> -			__set_bit(minor, minors);
> +		bitmap_set(minors, minor, nr);

Hm, I would have thought the last argument should have been 'end'?

Did you test this patch with a large amount of minors?

>  		rc = 0;
>  	} else
>  		rc = -EBUSY;
> @@ -193,8 +193,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
>  
>  	BUG_ON(end > nr_minors);
>  	spin_lock(&minor_lock);
> -	for (; minor < end; ++minor)
> -		__clear_bit(minor, minors);
> +	bitmap_clear(minors,  minor, nr);

Ditto.
>  	spin_unlock(&minor_lock);
>  }
>  
> -- 
> 1.7.4.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] hpsa: use find_first_zero_bit
  2012-01-20 15:15 ` [PATCH] hpsa: use find_first_zero_bit Akinobu Mita
@ 2012-01-20 15:41   ` scameron
  0 siblings, 0 replies; 16+ messages in thread
From: scameron @ 2012-01-20 15:41 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, akpm, iss_storagedev, James E.J. Bottomley,
	linux-scsi, scameron

On Sat, Jan 21, 2012 at 12:15:27AM +0900, Akinobu Mita wrote:
> Use find_first_zero_bit to find the first cleared bit in a memory region.
> 
> This also includes the following minor changes.
> - Use bitmap_zero
> - Reduce unnecessary atomic bitops usage

Ack.

This isn't performance sensitive code though, hpsa_find_target_lun()
only gets called during device discovery when a multi-lun device
like a tape drive with an auto changer is encountered.

I tried it out and it doesn't conflict with any of the patches
I sent up yesterday, and it works with a tape drive/autochanger.

-- steve
 
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
> Cc: iss_storagedev@hp.com
> Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
> Cc: linux-scsi@vger.kernel.org
> ---
>  drivers/scsi/hpsa.c |   18 ++++++++----------
>  1 files changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> index 7d14443..7f79ed8 100644
> --- a/drivers/scsi/hpsa.c
> +++ b/drivers/scsi/hpsa.c
> @@ -577,21 +577,19 @@ static int hpsa_find_target_lun(struct ctlr_info *h,
>  	int i, found = 0;
>  	DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES);
>  
> -	memset(&lun_taken[0], 0, HPSA_MAX_DEVICES >> 3);
> +	bitmap_zero(lun_taken, HPSA_MAX_DEVICES);
>  
>  	for (i = 0; i < h->ndevices; i++) {
>  		if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
> -			set_bit(h->dev[i]->target, lun_taken);
> +			__set_bit(h->dev[i]->target, lun_taken);
>  	}
>  
> -	for (i = 0; i < HPSA_MAX_DEVICES; i++) {
> -		if (!test_bit(i, lun_taken)) {
> -			/* *bus = 1; */
> -			*target = i;
> -			*lun = 0;
> -			found = 1;
> -			break;
> -		}
> +	i = find_first_zero_bit(lun_taken, HPSA_MAX_DEVICES);
> +	if (i < HPSA_MAX_DEVICES) {
> +		/* *bus = 1; */
> +		*target = i;
> +		*lun = 0;
> +		found = 1;
>  	}
>  	return !found;
>  }
> -- 
> 1.7.4.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 15:28   ` Konrad Rzeszutek Wilk
@ 2012-01-20 15:41     ` Akinobu Mita
  2012-01-20 16:09       ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 16+ messages in thread
From: Akinobu Mita @ 2012-01-20 15:41 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: linux-kernel, akpm, Jeremy Fitzhardinge Jeremy Fitzhardinge,
	xen-devel, virtualization

2012/1/21 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>:
> On Sat, Jan 21, 2012 at 12:15:26AM +0900, Akinobu Mita wrote:
>> Use bitmap_set and bitmap_clear rather than modifying individual bits
>> in a memory region.
>>
>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>> Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
>> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>> Cc: xen-devel@lists.xensource.com
>> Cc: virtualization@lists.linux-foundation.org
>> ---
>>  drivers/block/xen-blkfront.c |    7 +++----
>>  1 files changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
>> index 2f22874..619868d 100644
>> --- a/drivers/block/xen-blkfront.c
>> +++ b/drivers/block/xen-blkfront.c
>> @@ -43,6 +43,7 @@
>>  #include <linux/slab.h>
>>  #include <linux/mutex.h>
>>  #include <linux/scatterlist.h>
>> +#include <linux/bitmap.h>
>>
>>  #include <xen/xen.h>
>>  #include <xen/xenbus.h>
>> @@ -177,8 +178,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
>>
>>       spin_lock(&minor_lock);
>>       if (find_next_bit(minors, end, minor) >= end) {
>> -             for (; minor < end; ++minor)
>> -                     __set_bit(minor, minors);
>> +             bitmap_set(minors, minor, nr);
>
> Hm, I would have thought the last argument should have been 'end'?

'end' is the index of the last bit to clear.  But the last argument of
bitmap_clear() is the number of bits to clear.  So I think 'nr' is correct.

> Did you test this patch with a large amount of minors?

Sorry I didn't do runtime test.

>>               rc = 0;
>>       } else
>>               rc = -EBUSY;
>> @@ -193,8 +193,7 @@ static void xlbd_release_minors(unsigned int minor, unsigned int nr)
>>
>>       BUG_ON(end > nr_minors);
>>       spin_lock(&minor_lock);
>> -     for (; minor < end; ++minor)
>> -             __clear_bit(minor, minors);
>> +     bitmap_clear(minors,  minor, nr);
>
> Ditto.
>>       spin_unlock(&minor_lock);
>>  }
>>
>> --
>> 1.7.4.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 15:41     ` Akinobu Mita
@ 2012-01-20 16:09       ` Konrad Rzeszutek Wilk
  2012-01-20 23:11         ` Andrew Morton
  0 siblings, 1 reply; 16+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-01-20 16:09 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, akpm, Jeremy Fitzhardinge Jeremy Fitzhardinge,
	xen-devel, virtualization

On Sat, Jan 21, 2012 at 12:41:56AM +0900, Akinobu Mita wrote:
> 2012/1/21 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>:
> > On Sat, Jan 21, 2012 at 12:15:26AM +0900, Akinobu Mita wrote:
> >> Use bitmap_set and bitmap_clear rather than modifying individual bits
> >> in a memory region.
> >>
> >> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> >> Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> >> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> >> Cc: xen-devel@lists.xensource.com
> >> Cc: virtualization@lists.linux-foundation.org
> >> ---
> >>  drivers/block/xen-blkfront.c |    7 +++----
> >>  1 files changed, 3 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> >> index 2f22874..619868d 100644
> >> --- a/drivers/block/xen-blkfront.c
> >> +++ b/drivers/block/xen-blkfront.c
> >> @@ -43,6 +43,7 @@
> >>  #include <linux/slab.h>
> >>  #include <linux/mutex.h>
> >>  #include <linux/scatterlist.h>
> >> +#include <linux/bitmap.h>
> >>
> >>  #include <xen/xen.h>
> >>  #include <xen/xenbus.h>
> >> @@ -177,8 +178,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
> >>
> >>       spin_lock(&minor_lock);
> >>       if (find_next_bit(minors, end, minor) >= end) {
> >> -             for (; minor < end; ++minor)
> >> -                     __set_bit(minor, minors);
> >> +             bitmap_set(minors, minor, nr);
> >
> > Hm, I would have thought the last argument should have been 'end'?
> 
> 'end' is the index of the last bit to clear.  But the last argument of
> bitmap_clear() is the number of bits to clear.  So I think 'nr' is correct.

Ah, I see it.
> 
> > Did you test this patch with a large amount of minors?
> 
> Sorry I didn't do runtime test.

Please do.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] percpu: use bitmap_clear
  2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
                   ` (5 preceding siblings ...)
  2012-01-20 15:19 ` [PATCH] percpu: use bitmap_clear Christoph Lameter
@ 2012-01-20 17:24 ` Tejun Heo
  6 siblings, 0 replies; 16+ messages in thread
From: Tejun Heo @ 2012-01-20 17:24 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, akpm, Christoph Lameter

On Sat, Jan 21, 2012 at 12:15:23AM +0900, Akinobu Mita wrote:
> Use bitmap_clear rather than clearing individual bits in a memory region.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Christoph Lameter <cl@linux-foundation.org>

Applied to percpu/for-3.4 w/ cl's ack added.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 16:09       ` Konrad Rzeszutek Wilk
@ 2012-01-20 23:11         ` Andrew Morton
  2012-01-20 23:55           ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Morton @ 2012-01-20 23:11 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Akinobu Mita, linux-kernel,
	Jeremy Fitzhardinge Jeremy Fitzhardinge, xen-devel,
	virtualization

On Fri, 20 Jan 2012 11:09:38 -0500
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:

> > 
> > > Did you test this patch with a large amount of minors?
> > 
> > Sorry I didn't do runtime test.
> 
> Please do.

The poor guy probably doesn't know how to test it and surely it would
be quite a lot of work for him to do so.

Overall, it would be much more efficient if the tester of this code is
someone who is set up to easily apply the patch and test it.  ie: the
code maintainer(s).


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 23:11         ` Andrew Morton
@ 2012-01-20 23:55           ` Konrad Rzeszutek Wilk
  2012-01-21  0:04             ` Andrew Morton
  0 siblings, 1 reply; 16+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-01-20 23:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Akinobu Mita, linux-kernel,
	Jeremy Fitzhardinge Jeremy Fitzhardinge, xen-devel,
	virtualization

On Fri, Jan 20, 2012 at 03:11:49PM -0800, Andrew Morton wrote:
> On Fri, 20 Jan 2012 11:09:38 -0500
> Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:
> 
> > > 
> > > > Did you test this patch with a large amount of minors?
> > > 
> > > Sorry I didn't do runtime test.
> > 
> > Please do.
> 
> The poor guy probably doesn't know how to test it and surely it would
> be quite a lot of work for him to do so.
> 
> Overall, it would be much more efficient if the tester of this code is
> someone who is set up to easily apply the patch and test it.  ie: the
> code maintainer(s).

<grins>

This patch aside - Andrew how do you deal with a large amount of patches
and make sure they are tested? Is there a weekly Test Tuesday where you 
kick off your automated tests and dilligently look for any variations?

Or is it more of compile the kernel with X features and run it for a week
doing normal (and abnormal!) things to see if it falls over?

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear()
  2012-01-20 23:55           ` Konrad Rzeszutek Wilk
@ 2012-01-21  0:04             ` Andrew Morton
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Morton @ 2012-01-21  0:04 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Akinobu Mita, linux-kernel,
	Jeremy Fitzhardinge Jeremy Fitzhardinge, xen-devel,
	virtualization

On Fri, 20 Jan 2012 18:55:08 -0500
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:

> On Fri, Jan 20, 2012 at 03:11:49PM -0800, Andrew Morton wrote:
> > On Fri, 20 Jan 2012 11:09:38 -0500
> > Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:
> > 
> > > > 
> > > > > Did you test this patch with a large amount of minors?
> > > > 
> > > > Sorry I didn't do runtime test.
> > > 
> > > Please do.
> > 
> > The poor guy probably doesn't know how to test it and surely it would
> > be quite a lot of work for him to do so.
> > 
> > Overall, it would be much more efficient if the tester of this code is
> > someone who is set up to easily apply the patch and test it.  ie: the
> > code maintainer(s).
> 
> <grins>
> 
> This patch aside - Andrew how do you deal with a large amount of patches
> and make sure they are tested?

Not very well :(

> Is there a weekly Test Tuesday where you 
> kick off your automated tests and dilligently look for any variations?
> Or is it more of compile the kernel with X features and run it for a week
> doing normal (and abnormal!) things to see if it falls over?

I build all the patches I have along with all of linux-next and boot
the thing, then use the resulting kernel for a few hours compilation
testing, then shove it all into linux-next where I naively hope that
someone else is testing things.

The coverage which is obtained this way is pretty poor.  

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-01-21  0:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-20 15:15 [PATCH] percpu: use bitmap_clear Akinobu Mita
2012-01-20 15:15 ` [PATCH] ocfs2: use find_last_bit Akinobu Mita
2012-01-20 15:15 ` [PATCH] ocfs2: use bitmap_weight() Akinobu Mita
2012-01-20 15:15 ` [PATCH] xen-blkfront: use bitmap_set() and bitmap_clear() Akinobu Mita
2012-01-20 15:27   ` Akinobu Mita
2012-01-20 15:28   ` Konrad Rzeszutek Wilk
2012-01-20 15:41     ` Akinobu Mita
2012-01-20 16:09       ` Konrad Rzeszutek Wilk
2012-01-20 23:11         ` Andrew Morton
2012-01-20 23:55           ` Konrad Rzeszutek Wilk
2012-01-21  0:04             ` Andrew Morton
2012-01-20 15:15 ` [PATCH] hpsa: use find_first_zero_bit Akinobu Mita
2012-01-20 15:41   ` scameron
2012-01-20 15:15 ` [PATCH] sysctl: use bitmap library functions Akinobu Mita
2012-01-20 15:19 ` [PATCH] percpu: use bitmap_clear Christoph Lameter
2012-01-20 17:24 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).