LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] hpsa: cleanup bitops usage
@ 2015-03-14 1:12 Akinobu Mita
2015-03-14 1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel
Cc: Akinobu Mita, Don Brace, iss_storagedev, storagedev,
James E.J. Bottomley, linux-scsi
Remove unnecessary adjustment for bit number and address of bitmask,
and use BITS_TO_LONGS macro to calculate bitmap size. This change
just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Don Brace <don.brace@pmcs.com>
Cc: iss_storagedev@hp.com
Cc: storagedev@pmcs.com
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
---
drivers/scsi/hpsa.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a1cfbd3..73a282b 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -4697,8 +4697,7 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
offset = (i + 1) % h->nr_cmds;
continue;
}
- set_bit(i & (BITS_PER_LONG - 1),
- h->cmd_pool_bits + (i / BITS_PER_LONG));
+ set_bit(i, h->cmd_pool_bits);
break; /* it's ours now. */
}
h->last_allocation = i; /* benignly racy */
@@ -4729,8 +4728,7 @@ static void cmd_free(struct ctlr_info *h, struct CommandList *c)
int i;
i = c - h->cmd_pool;
- clear_bit(i & (BITS_PER_LONG - 1),
- h->cmd_pool_bits + (i / BITS_PER_LONG));
+ clear_bit(i, h->cmd_pool_bits);
}
}
@@ -6410,8 +6408,7 @@ out_disable:
static int hpsa_allocate_cmd_pool(struct ctlr_info *h)
{
- h->cmd_pool_bits = kzalloc(
- DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
+ h->cmd_pool_bits = kcalloc(BITS_TO_LONGS(h->nr_cmds),
sizeof(unsigned long), GFP_KERNEL);
h->cmd_pool = pci_alloc_consistent(h->pdev,
h->nr_cmds * sizeof(*h->cmd_pool),
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] cpqarray: simplify bitops usages
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
@ 2015-03-14 1:12 ` Akinobu Mita
2015-03-14 1:12 ` [PATCH] pktcdvd: convert char array to bitmap Akinobu Mita
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Akinobu Mita, Don Brace, iss_storagedev
Remove unnecessary adjustment for bit number and address of bitmask.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Don Brace <don.brace@pmcs.com>
Cc: iss_storagedev@hp.com
---
drivers/block/cpqarray.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 2b94403..34dde22 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -422,8 +422,8 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
hba[i]->cmd_pool = pci_alloc_consistent(
hba[i]->pci_dev, NR_CMDS * sizeof(cmdlist_t),
&(hba[i]->cmd_pool_dhandle));
- hba[i]->cmd_pool_bits = kcalloc(
- DIV_ROUND_UP(NR_CMDS, BITS_PER_LONG), sizeof(unsigned long),
+ hba[i]->cmd_pool_bits = kcalloc(BITS_TO_LONGS(NR_CMDS),
+ sizeof(unsigned long),
GFP_KERNEL);
if (!hba[i]->cmd_pool_bits || !hba[i]->cmd_pool)
@@ -1373,7 +1373,7 @@ static cmdlist_t * cmd_alloc(ctlr_info_t *h, int get_from_pool)
i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS);
if (i == NR_CMDS)
return NULL;
- } while(test_and_set_bit(i&(BITS_PER_LONG-1), h->cmd_pool_bits+(i/BITS_PER_LONG)) != 0);
+ } while (test_and_set_bit(i, h->cmd_pool_bits) != 0);
c = h->cmd_pool + i;
cmd_dhandle = h->cmd_pool_dhandle + i*sizeof(cmdlist_t);
h->nr_allocs++;
@@ -1393,7 +1393,7 @@ static void cmd_free(ctlr_info_t *h, cmdlist_t *c, int got_from_pool)
c->busaddr);
} else {
i = c - h->cmd_pool;
- clear_bit(i&(BITS_PER_LONG-1), h->cmd_pool_bits+(i/BITS_PER_LONG));
+ clear_bit(i, h->cmd_pool_bits);
h->nr_frees++;
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] pktcdvd: convert char array to bitmap
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
2015-03-14 1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
@ 2015-03-14 1:12 ` Akinobu Mita
2015-03-14 1:12 ` [PATCH] drbd: use bitmap_weight() Akinobu Mita
2015-03-14 1:12 ` [PATCH] ia64: Use bitmap_weight Akinobu Mita
3 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Akinobu Mita, Jiri Kosina
The written[] array in pkt_gather_data() can be converted to bitmap.
It can reduce stack usage and simplify the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jiri Kosina <jkosina@suse.cz>
---
drivers/block/pktcdvd.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 09e628da..1aff5ca 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1019,7 +1019,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
int frames_read = 0;
struct bio *bio;
int f;
- char written[PACKET_MAX_SIZE];
+ DECLARE_BITMAP(written, PACKET_MAX_SIZE);
BUG_ON(bio_list_empty(&pkt->orig_bios));
@@ -1029,7 +1029,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
/*
* Figure out which frames we need to read before we can write.
*/
- memset(written, 0, sizeof(written));
+ bitmap_zero(written, PACKET_MAX_SIZE);
spin_lock(&pkt->lock);
bio_list_for_each(bio, &pkt->orig_bios) {
int first_frame = (bio->bi_iter.bi_sector - pkt->sector) /
@@ -1038,8 +1038,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
pd->stats.secs_w += num_frames * (CD_FRAMESIZE >> 9);
BUG_ON(first_frame < 0);
BUG_ON(first_frame + num_frames > pkt->frames);
- for (f = first_frame; f < first_frame + num_frames; f++)
- written[f] = 1;
+ bitmap_set(written, first_frame, num_frames);
}
spin_unlock(&pkt->lock);
@@ -1052,12 +1051,9 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
/*
* Schedule reads for missing parts of the packet.
*/
- for (f = 0; f < pkt->frames; f++) {
+ for_each_clear_bit(f, written, pkt->frames) {
int p, offset;
- if (written[f])
- continue;
-
bio = pkt->r_bios[f];
bio_reset(bio);
bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] drbd: use bitmap_weight()
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
2015-03-14 1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
2015-03-14 1:12 ` [PATCH] pktcdvd: convert char array to bitmap Akinobu Mita
@ 2015-03-14 1:12 ` Akinobu Mita
2015-03-20 15:14 ` [Drbd-dev] " Lars Ellenberg
2015-03-14 1:12 ` [PATCH] ia64: Use bitmap_weight Akinobu Mita
3 siblings, 1 reply; 8+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Akinobu Mita, Philipp Reisner, Lars Ellenberg, drbd-dev
Use bitmap_weight to count the total number of bits set in bitmap.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Philipp Reisner <lars.ellenberg@linbit.com>
Cc: Lars Ellenberg <philipp.reisner@linbit.com>
Cc: drbd-dev@lists.linbit.com
---
drivers/block/drbd/drbd_bitmap.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 434c77d..39d31af 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -24,7 +24,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/drbd.h>
@@ -559,21 +559,19 @@ static unsigned long bm_count_bits(struct drbd_bitmap *b)
unsigned long *p_addr;
unsigned long bits = 0;
unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1;
- int idx, i, last_word;
+ int idx, last_word;
/* all but last page */
for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) {
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < LWPP; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, PAGE_SIZE * BITS_PER_BYTE);
__bm_unmap(p_addr);
cond_resched();
}
/* last (or only) page */
last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL;
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < last_word; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, last_word * BITS_PER_LONG);
p_addr[last_word] &= cpu_to_lel(mask);
bits += hweight_long(p_addr[last_word]);
/* 32bit arch, may have an unused padding long */
@@ -1424,15 +1422,12 @@ int drbd_bm_clear_bits(struct drbd_device *device, const unsigned long s, const
static inline void bm_set_full_words_within_one_page(struct drbd_bitmap *b,
int page_nr, int first_word, int last_word)
{
- int i;
- int bits;
- int changed = 0;
unsigned long *paddr = kmap_atomic(b->bm_pages[page_nr]);
- for (i = first_word; i < last_word; i++) {
- bits = hweight_long(paddr[i]);
- paddr[i] = ~0UL;
- changed += BITS_PER_LONG - bits;
- }
+ int nbits = (last_word - first_word) * BITS_PER_LONG;
+ int changed;
+
+ changed = nbits - bitmap_weight(paddr + first_word, nbits);
+ bitmap_fill(paddr + first_word, nbits);
kunmap_atomic(paddr);
if (changed) {
/* We only need lazy writeout, the information is still in the
@@ -1637,8 +1632,7 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
int n = e-s;
p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s));
bm = p_addr + MLPP(s);
- while (n--)
- count += hweight_long(*bm++);
+ count = bitmap_weight(bm, n * BITS_PER_LONG);
bm_unmap(p_addr);
} else {
drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s);
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] ia64: Use bitmap_weight
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
` (2 preceding siblings ...)
2015-03-14 1:12 ` [PATCH] drbd: use bitmap_weight() Akinobu Mita
@ 2015-03-14 1:12 ` Akinobu Mita
3 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Akinobu Mita, Tony Luck, Fenghua Yu, linux-ia64
Use bitmap_weight to count the total number of bits set in bitmap.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
---
arch/ia64/hp/common/sba_iommu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 344387a..9c944fa 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -33,7 +33,7 @@
#include <linux/acpi.h>
#include <linux/efi.h>
#include <linux/nodemask.h>
-#include <linux/bitops.h> /* hweight64() */
+#include <linux/bitmap.h> /* bitmap_weight() */
#include <linux/crash_dump.h>
#include <linux/iommu-helper.h>
#include <linux/dma-mapping.h>
@@ -1901,8 +1901,7 @@ static int
ioc_show(struct seq_file *s, void *v)
{
struct ioc *ioc = v;
- unsigned long *res_ptr = (unsigned long *)ioc->res_map;
- int i, used = 0;
+ int used;
seq_printf(s, "Hewlett Packard %s IOC rev %d.%d\n",
ioc->name, ((ioc->rev >> 4) & 0xF), (ioc->rev & 0xF));
@@ -1913,8 +1912,8 @@ ioc_show(struct seq_file *s, void *v)
seq_printf(s, "IOVA size : %ld MB\n", ((ioc->pdir_size >> 3) * iovp_size)/(1024*1024));
seq_printf(s, "IOVA page size : %ld kb\n", iovp_size/1024);
- for (i = 0; i < (ioc->res_size / sizeof(unsigned long)); ++i, ++res_ptr)
- used += hweight64(*res_ptr);
+ used = bitmap_weight((unsigned long *)ioc->res_map,
+ ioc->res_size * BITS_PER_BYTE);
seq_printf(s, "PDIR size : %d entries\n", ioc->pdir_size >> 3);
seq_printf(s, "PDIR used : %d entries\n", used);
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
2015-03-14 1:12 ` [PATCH] drbd: use bitmap_weight() Akinobu Mita
@ 2015-03-20 15:14 ` Lars Ellenberg
2015-03-22 2:11 ` Akinobu Mita
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ellenberg @ 2015-03-20 15:14 UTC (permalink / raw)
To: Akinobu Mita; +Cc: linux-kernel, drbd-dev
On Sat, Mar 14, 2015 at 10:12:56AM +0900, Akinobu Mita wrote:
> Use bitmap_weight to count the total number of bits set in bitmap.
> This change just simplifies the code a bit.
"Simplifies", not sure about that, but ok, maybe.
For the "bm_set_full_words_within_one_page", I disagree.
I think it is more cpu cache friendly to hweight_long then set to ~0UL
each word in turn, than to first bitmap_weight() all words, then
bitmap_fill() all words.
Thanks,
Lars Ellenberg
BTW, you swapped names and email addresses of phil and me. Are those
listed incorrectly somewhere, or was that just a mishap on your part?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
2015-03-20 15:14 ` [Drbd-dev] " Lars Ellenberg
@ 2015-03-22 2:11 ` Akinobu Mita
0 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-22 2:11 UTC (permalink / raw)
To: Akinobu Mita, LKML, drbd-dev
2015-03-21 0:14 GMT+09:00 Lars Ellenberg <lars.ellenberg@linbit.com>:
> On Sat, Mar 14, 2015 at 10:12:56AM +0900, Akinobu Mita wrote:
>> Use bitmap_weight to count the total number of bits set in bitmap.
>> This change just simplifies the code a bit.
>
> "Simplifies", not sure about that, but ok, maybe.
>
> For the "bm_set_full_words_within_one_page", I disagree.
> I think it is more cpu cache friendly to hweight_long then set to ~0UL
> each word in turn, than to first bitmap_weight() all words, then
> bitmap_fill() all words.
I see. I'll remove the change in bm_set_full_words_within_one_page().
> Thanks,
>
> Lars Ellenberg
>
> BTW, you swapped names and email addresses of phil and me. Are those
> listed incorrectly somewhere, or was that just a mishap on your part?
It's just my mistake. I copied your names from MAINTAINERS, but it
doesn't list your email addresses then I incorrectly swapped while
retrieving email addrsses from git log.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] drbd: use bitmap_weight()
@ 2015-03-22 7:31 Akinobu Mita
0 siblings, 0 replies; 8+ messages in thread
From: Akinobu Mita @ 2015-03-22 7:31 UTC (permalink / raw)
To: linux-kernel; +Cc: Akinobu Mita, Philipp Reisner, Lars Ellenberg, drbd-dev
Use bitmap_weight to count the total number of bits set in bitmap.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Lars Ellenberg <lars.ellenberg@linbit.com>
Cc: drbd-dev@lists.linbit.com
---
drivers/block/drbd/drbd_bitmap.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 434c77d..1e62c49 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -24,7 +24,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/drbd.h>
@@ -559,21 +559,19 @@ static unsigned long bm_count_bits(struct drbd_bitmap *b)
unsigned long *p_addr;
unsigned long bits = 0;
unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1;
- int idx, i, last_word;
+ int idx, last_word;
/* all but last page */
for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) {
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < LWPP; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, PAGE_SIZE * BITS_PER_BYTE);
__bm_unmap(p_addr);
cond_resched();
}
/* last (or only) page */
last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL;
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < last_word; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, last_word * BITS_PER_LONG);
p_addr[last_word] &= cpu_to_lel(mask);
bits += hweight_long(p_addr[last_word]);
/* 32bit arch, may have an unused padding long */
@@ -1637,8 +1635,7 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
int n = e-s;
p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s));
bm = p_addr + MLPP(s);
- while (n--)
- count += hweight_long(*bm++);
+ count = bitmap_weight(bm, n * BITS_PER_LONG);
bm_unmap(p_addr);
} else {
drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s);
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-03-22 7:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
2015-03-14 1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
2015-03-14 1:12 ` [PATCH] pktcdvd: convert char array to bitmap Akinobu Mita
2015-03-14 1:12 ` [PATCH] drbd: use bitmap_weight() Akinobu Mita
2015-03-20 15:14 ` [Drbd-dev] " Lars Ellenberg
2015-03-22 2:11 ` Akinobu Mita
2015-03-14 1:12 ` [PATCH] ia64: Use bitmap_weight Akinobu Mita
2015-03-22 7:31 [PATCH] drbd: use bitmap_weight() Akinobu Mita
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).