Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2991525imw; Sun, 10 Jul 2022 22:07:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t2UHG7QcYkeIBmXxoz/X2UYbN+QXjfEqGejYbwfNnshMiSJZpFp7GSyXGl0OJQq+PoFbe4 X-Received: by 2002:a17:907:60cb:b0:726:a69a:c7a with SMTP id hv11-20020a17090760cb00b00726a69a0c7amr17343658ejc.156.1657516071239; Sun, 10 Jul 2022 22:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657516071; cv=none; d=google.com; s=arc-20160816; b=dUOdEFGYXloauAdVkDs+CC63YoJ6/96hT0hnVPrQp9JamUONjrF7ZAVmRmgD7+I9KB OMROQa91WE0X8PXVL+0v+cGkVkpZ3UEFWX04Ag78aO51kjMFzCAEI0J8GnOpe2nk9BkR ukzw1U4BA4gUZ/g1XIp2pT/KWHigzVFgEU5nXLo6bKMcZoJ5PUOi57oPt1M8/6kDnN75 lEuTSH2GB23qJ2ZcdCDjmCxf2dwE6w6fiYNUgejENB/gOqMtGU1uoEieGoTPoXPINwGs J5a576d0oGduPamXlHwkL9Cki30l33vBQF23XqrthBdNnvnoDaw+FPU9JMV6WdtCt1dW iMIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A6q5z8s18QRfHFAJrndvZI9vXCYXjK+FWxgchg+J6RI=; b=xG/isLBhH720wwMzvuJ715q9uM+Hq+G49YLtPPI7yF0elXmT+/DcsGAzYwRFKouCBj LfUXG93cImyYfST2unimeKZypjYUvB4KavZfWrIhT0gGOaBar5z1dPGIvRmcC+8c1GLT 8mC6GqVfjBxPzw75r6yLjXQNrcsnZxPZAVkdNJabdUC+j0hehLIzXzNxi7gCK6GF1z+q yxQ4yOzUcx4y2Kfz9zp2deJawh8t3Iyo4aDLtOnaBaLX5l9woVHA2/rdgowxN4/6ZrF+ Z405LkBNgn3nkJd5j8DVjo+KJX1m3Lzc9wGyFuCtWdH8+FYUmpi0KWEltfwKmIdYnbu1 ABwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QBLvVko+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc17-20020a170907169100b00729c19c5106si7285229ejc.999.2022.07.10.22.07.25; Sun, 10 Jul 2022 22:07:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QBLvVko+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbiGKErb (ORCPT + 99 others); Mon, 11 Jul 2022 00:47:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbiGKErT (ORCPT ); Mon, 11 Jul 2022 00:47:19 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3000260CF for ; Sun, 10 Jul 2022 21:47:18 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id f12so3014869qka.12 for ; Sun, 10 Jul 2022 21:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A6q5z8s18QRfHFAJrndvZI9vXCYXjK+FWxgchg+J6RI=; b=QBLvVko+rS1FTRCtsf8vYGAy3nf88w3gkkF8Q6lJ4404r2d6ucehKkAsSxdZTlDrJN 2pUb0w/ZNLfWKoV4hMSenj84fR8fbAkByJK+izpYCcYmSoKXJdYn/I7UMDtX8zVvxjPy +fcOJSDoVp+JIfnFpHlM5gNfBGdf/kVhF+DUWvoNP+Jw1pE5yLBMGxfKlhxkbnxbH9zW woWPX6MRG8VWKSr5Gw1JueW0KsxNBk5D/3JQRTdRjlPpYt3y+5gACNvHDQUMggy1U/Mu PBs1b1FO5Hl0pyz9+ImqpzBvXjW1oP1Sibb7/pjUgGo0k88vOsDm4Vv1aswEUmmhOtFw V0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A6q5z8s18QRfHFAJrndvZI9vXCYXjK+FWxgchg+J6RI=; b=LwaZkJIIXAajkHyEI1XpauvtZm8nuF0afGVvnPw0CU+bYIXMToooRR+z5eU4+KWuaz 8nMcq1APDyuEGgceYZfLhqjx18WN4sJxF+5QZAfc4X2/4wLEp7cbkdfvr5nllOM32ATD hgnEsQWCJdgB6g2aLhMrAdVYNPiosYuBjK+tt2Gkld58K+g/q3kZu5DzjLcIuXDaMv85 PzHWeOTMIiq9ZptfUfzI4ble3zKa7ulO1Jcwn4MhFhbyRP0M31WQ+GMAFNBHfqAMjkOa EprIX4w6d6LZ7SI4mHgGrAx91FIGUi3YW2WQ/wPhconFHFK64GdxkzJ6KxQHqbdbJ+RF J0yA== X-Gm-Message-State: AJIora8Ea4jEJZ6SKaDRdXMIw+VesGzcDzowTREodWxIJF6u/7ppne+L lg2cuiNRENl8FEX+wEfbPEniT7YUAQLeKg== X-Received: by 2002:a37:a695:0:b0:6b5:8c47:ab0 with SMTP id p143-20020a37a695000000b006b58c470ab0mr1252213qke.579.1657514837051; Sun, 10 Jul 2022 21:47:17 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:a22e:180:f963:1eff]) by smtp.gmail.com with ESMTPSA id s12-20020a05620a29cc00b006b28349678dsm5975138qkp.80.2022.07.10.21.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jul 2022 21:47:16 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Alexander Lobakin , Andy Shevchenko , Arnd Bergmann , David Gow , Eric Dumazet , Isabella Basso , Kees Cook , Keith Busch , Kumar Kartikeya Dwivedi , Marco Elver , Mark Rutland , Rasmus Villemoes , Steven Rostedt , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Cc: Yury Norov Subject: [PATCH 3/5] lib/bitmap: remove bitmap_ord_to_pos Date: Sun, 10 Jul 2022 21:47:09 -0700 Message-Id: <20220711044711.466822-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220711044711.466822-1-yury.norov@gmail.com> References: <20220711044711.466822-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have find_nth_bit(), we can drop bitmap_ord_to_pos(). Signed-off-by: Yury Norov --- include/linux/bitmap.h | 1 - lib/bitmap.c | 36 +++--------------------------------- lib/nodemask.c | 3 +-- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 035d4ac66641..0de6f6a101a9 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -222,7 +222,6 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n #else #define bitmap_copy_le bitmap_copy #endif -unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits); int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits); diff --git a/lib/bitmap.c b/lib/bitmap.c index b580b381eca1..0b1082aa0b2c 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -956,36 +956,6 @@ static int bitmap_pos_to_ord(const unsigned long *buf, unsigned int pos, unsigne return __bitmap_weight(buf, pos); } -/** - * bitmap_ord_to_pos - find position of n-th set bit in bitmap - * @buf: pointer to bitmap - * @ord: ordinal bit position (n-th set bit, n >= 0) - * @nbits: number of valid bit positions in @buf - * - * Map the ordinal offset of bit @ord in @buf to its position in @buf. - * Value of @ord should be in range 0 <= @ord < weight(buf). If @ord - * >= weight(buf), returns @nbits. - * - * If for example, just bits 4 through 7 are set in @buf, then @ord - * values 0 through 3 will get mapped to 4 through 7, respectively, - * and all other @ord values returns @nbits. When @ord value 3 - * gets mapped to (returns) @pos value 7 in this example, that means - * that the 3rd set bit (starting with 0th) is at position 7 in @buf. - * - * The bit positions 0 through @nbits-1 are valid positions in @buf. - */ -unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsigned int nbits) -{ - unsigned int pos; - - for (pos = find_first_bit(buf, nbits); - pos < nbits && ord; - pos = find_next_bit(buf, nbits, pos + 1)) - ord--; - - return pos; -} - /** * bitmap_remap - Apply map defined by a pair of bitmaps to another bitmap * @dst: remapped result @@ -1035,7 +1005,7 @@ void bitmap_remap(unsigned long *dst, const unsigned long *src, if (n < 0 || w == 0) set_bit(oldbit, dst); /* identity map */ else - set_bit(bitmap_ord_to_pos(new, n % w, nbits), dst); + set_bit(find_nth_bit(new, nbits, n % w), dst); } } EXPORT_SYMBOL(bitmap_remap); @@ -1074,7 +1044,7 @@ int bitmap_bitremap(int oldbit, const unsigned long *old, if (n < 0 || w == 0) return oldbit; else - return bitmap_ord_to_pos(new, n % w, bits); + return find_nth_bit(new, bits, n % w); } EXPORT_SYMBOL(bitmap_bitremap); @@ -1198,7 +1168,7 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, * The following code is a more efficient, but less * obvious, equivalent to the loop: * for (m = 0; m < bitmap_weight(relmap, bits); m++) { - * n = bitmap_ord_to_pos(orig, m, bits); + * n = find_nth_bit(orig, bits, m); * if (test_bit(m, orig)) * set_bit(n, dst); * } diff --git a/lib/nodemask.c b/lib/nodemask.c index e22647f5181b..7dad4ce8ff59 100644 --- a/lib/nodemask.c +++ b/lib/nodemask.c @@ -24,8 +24,7 @@ int node_random(const nodemask_t *maskp) w = nodes_weight(*maskp); if (w) - bit = bitmap_ord_to_pos(maskp->bits, - get_random_int() % w, MAX_NUMNODES); + bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w); return bit; } #endif -- 2.34.1