From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra13.linbit.com (zimbra.linbit.com [212.69.161.123]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail09.linbit.com (LINBIT Mail Daemon) with ESMTPS id 3EBC21019A36 for ; Thu, 19 Mar 2015 21:08:45 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra13.linbit.com (Postfix) with ESMTP id 323DF453CB7 for ; Thu, 19 Mar 2015 21:08:45 +0100 (CET) Received: from zimbra13.linbit.com ([127.0.0.1]) by localhost (zimbra13.linbit.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id CWWxiUPcqOKS for ; Thu, 19 Mar 2015 21:08:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra13.linbit.com (Postfix) with ESMTP id 95966453CA0 for ; Thu, 19 Mar 2015 21:08:43 +0100 (CET) Received: from zimbra13.linbit.com ([127.0.0.1]) by localhost (zimbra13.linbit.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mbY0AnGCBzY1 for ; Thu, 19 Mar 2015 21:08:43 +0100 (CET) Received: from soda.linbit (tuerlsteher.linbit.com [86.59.100.100]) by zimbra13.linbit.com (Postfix) with ESMTPS id D0BE3453C93 for ; Thu, 19 Mar 2015 21:08:42 +0100 (CET) Resent-Message-ID: <20150319200842.GD3556@soda.linbit> Received: from mail-pd0-f174.google.com (mail-pd0-f174.google.com [209.85.192.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mail09.linbit.com (LINBIT Mail Daemon) with ESMTPS id D1C091028A59 for ; Sat, 14 Mar 2015 02:35:52 +0100 (CET) Received: by pdbcz9 with SMTP id cz9so1632252pdb.3 for ; Fri, 13 Mar 2015 18:35:50 -0700 (PDT) From: Akinobu Mita To: linux-kernel@vger.kernel.org Date: Sat, 14 Mar 2015 10:12:56 +0900 Message-Id: <1426295577-10836-4-git-send-email-akinobu.mita@gmail.com> In-Reply-To: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> References: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> Cc: Philipp Reisner , drbd-dev@lists.linbit.com, Akinobu Mita , Lars Ellenberg Subject: [Drbd-dev] [PATCH] drbd: use bitmap_weight() List-Id: "*Coordination* of development, patches, contributions -- *Questions* \(even to developers\) go to drbd-user, please." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Cc: Philipp Reisner Cc: Lars Ellenberg 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 +#include #include #include #include @@ -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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756859AbbCNBNj (ORCPT ); Fri, 13 Mar 2015 21:13:39 -0400 Received: from mail-pd0-f169.google.com ([209.85.192.169]:34019 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755597AbbCNBN2 (ORCPT ); Fri, 13 Mar 2015 21:13:28 -0400 From: Akinobu Mita To: linux-kernel@vger.kernel.org Cc: Akinobu Mita , Philipp Reisner , Lars Ellenberg , drbd-dev@lists.linbit.com Subject: [PATCH] drbd: use bitmap_weight() Date: Sat, 14 Mar 2015 10:12:56 +0900 Message-Id: <1426295577-10836-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> References: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Philipp Reisner Cc: Lars Ellenberg 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 +#include #include #include #include @@ -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