hpsa: cleanup bitops usage
PATCH 1/1 hpsa: cleanup bitops usage
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.
--- drivers/scsi/hpsa.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/scsi/hpsa.c +3 -6
@@ -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),
Signature · 1 line
1.9.1
PATCH 1/1 ia64: Use bitmap_weight
Use bitmap_weight to count the total number of bits set in bitmap. This change just simplifies the code a bit.
--- arch/ia64/hp/common/sba_iommu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/ia64/hp/common/sba_iommu.c +4 -5
@@ -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);
Signature · 1 line
1.9.1
PATCH 1/1 cpqarray: simplify bitops usages
In reply to Akinobu MitaRemove unnecessary adjustment for bit number and address of bitmask. This change just simplifies the code a bit.
--- drivers/block/cpqarray.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/cpqarray.c +4 -4
@@ -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++; } }
Signature · 1 line
1.9.1
PATCH 1/1 pktcdvd: convert char array to bitmap
In reply to Akinobu MitaThe written[] array in pkt_gather_data() can be converted to bitmap. It can reduce stack usage and simplify the code a bit.
--- drivers/block/pktcdvd.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/block/pktcdvd.c +4 -8
@@ -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 );
Signature · 1 line
1.9.1
PATCH 1/1 drbd: use bitmap_weight()
In reply to Akinobu MitaUse bitmap_weight to count the total number of bits set in bitmap. This change just simplifies the code a bit.
--- drivers/block/drbd/drbd_bitmap.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/block/drbd/drbd_bitmap.c +10 -16
@@ -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, conststatic 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);
Signature · 1 line
1.9.1
Lars Ellenberg
maintainerRe: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
Quoted 2 lines · Akinobu Mita
Use
bitmap_weightto 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?
Re: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
2015-03-21 0:14 GMT+09:00 Lars Ellenberg <[email protected]>:
Quoted 10 lines · Akinobu Mita
Quoted 2 lines
Use
bitmap_weightto 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 tohweight_longthen set to ~0UL each word in turn, than to firstbitmap_weight()all words, thenbitmap_fill()all words.
I see. I'll remove the change in bm_set_full_words_within_one_page().
Quoted 6 lines
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.