Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5527022pxb; Wed, 26 Jan 2022 14:10:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxotlZ6YEHb87E23Nf7wHetwuPdW1dKvprawofv/3ORJjzMccE2NtZkzPiY8g6DUyQt61QO X-Received: by 2002:a05:6402:2548:: with SMTP id l8mr969356edb.129.1643235057191; Wed, 26 Jan 2022 14:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643235057; cv=none; d=google.com; s=arc-20160816; b=uwCCic34fplQP98TpxbIcOvq3myDrXrKxOEKn6U6/m1PbTqIb/k9I0qohepsegzPow WvwNs7E+gzgfPykh+arySs0NMU/1pr5wJFSGcA+2VKZrbjeUld31NIC4LXBn0A397rag 7N6g/Wd+27OIGUb7hK/6yeXGZDkPqW2ehNmtn9V2DESIVvJ8xgVEacouIm2f9WB1efhi TL/hSHjoIxBWZij55PFbbWCmHpfaHsKM2qJXrmvGKD5Ie68NImq7AE0vpWXZgcTrLhGL PxI2ACAlKa8YR89cOsBE7j52g61c87Ffz7Bn7THOWgWLPBVmEi+UthgFo7Eh+vEnIaYJ Ulbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1geGSu+egCHyXH+GEeh4Fh8FJrnDZ8GAZN4GNe7VFSE=; b=gseIAT6gtSriEd/WxJETLmevHZvRTx/vuhUMT+i1AG8VykmAijHsDPa4quHpbJ1F/P MZegAOz5Hfhvcu6enT9Ltm/Vmd2bSMqr9j1Yyj7zNigLQpvPOdYes+nTiK3Ewc6MH+GR /DKEY6G2JPp0zvg5KUQ83Ef+igscbpdc61V6/48dbSAvyZ7tJz2pkCK+5FsPPE2uM+e/ bAfKgUz0ua9BD9c5nX114cL44nPWtguRsg67EzZvasL3O44lTrghKwL7YlbKvNOVwOiH TT68eGXL4yQ8XaRQGBHva5QfuV1pkE6aIKvYiBT/n3mjWgjEJyWNomCvJdrY5Qdh3GGx OWiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fhy0nMAD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs39si285910ejc.669.2022.01.26.14.10.32; Wed, 26 Jan 2022 14:10:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fhy0nMAD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235090AbiAZP4c (ORCPT + 99 others); Wed, 26 Jan 2022 10:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233459AbiAZP42 (ORCPT ); Wed, 26 Jan 2022 10:56:28 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B9CC06161C for ; Wed, 26 Jan 2022 07:56:28 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id k17so6209plk.0 for ; Wed, 26 Jan 2022 07:56:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1geGSu+egCHyXH+GEeh4Fh8FJrnDZ8GAZN4GNe7VFSE=; b=fhy0nMADqT0kgtbLAN3m/Y3M7C3QNtDy9otwevxfHRrcoGKtoVTvAaxbuQwrIc759i pyd3tnChhZTRwxCN3i7QbBi3Qa+MyWf/seYQSt8x4nMI/l/4d0ILRcgMbo1sdjtZbAzJ 4SG1yVRjIPn7CSYtzz5C20Jj25pBxi/bEes66knLT7EQRx40hkItLm7Zpgg2bqOGy+zw hkkv5IZl8/I15PmZx8DBjV91wcES79CR5/wNc/+y+CyCRWFy+tpE0Yp04CsWyYKYvvso yhjBzvzRdCUw1zqdd2ERTZ2SdybPh1Zvq86K07O8r52qncTUzSxbqyxqVhKDx/kMcJRR fz1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1geGSu+egCHyXH+GEeh4Fh8FJrnDZ8GAZN4GNe7VFSE=; b=zUjP7fIhXmSdbc5WZbb3XQQd5h+MLw0yzmZf3k7tuJ1E4LVST+iObX8zBi+KzXGINT LNellRc+nMKzu7RbY4kWco8aFb4aMNksrgllxK0FhIKfdoLm01HBkpLlGpCr+nhnGUQZ Ur2AUbnksiGOwUDCVW80+P51L9zr8yLbRfALKj2DS2fVNhaC1I8y5wI8LgTBpNLTHwxv ITMo66S6O5oFhYjeXvuVorohknUJKi7DRiIzgpR5W+JdDLWsnBc79jULMok3zGDv3TU/ UXdOza5p1ZZQhbPitQzFPx4Cz+6+tFfC8PviURuigZMi7Fr9RfpHvKvYuFxbVDaV48Im VfJg== X-Gm-Message-State: AOAM530fd9OMPipveCXa40/FrsujiDqOqY1Cd5S5NX0mfFGaqM+sbOQz 6q4NAck+4pSBsd4ylHwVO6+McjnX/1mJT1Ldeus= X-Received: by 2002:a17:902:a5c6:b0:149:c926:7c31 with SMTP id t6-20020a170902a5c600b00149c9267c31mr24236146plq.141.1643212587832; Wed, 26 Jan 2022 07:56:27 -0800 (PST) MIME-Version: 1.0 References: <20220123183925.1052919-1-yury.norov@gmail.com> <20220123183925.1052919-28-yury.norov@gmail.com> In-Reply-To: From: Yury Norov Date: Wed, 26 Jan 2022 07:56:16 -0800 Message-ID: Subject: Re: [PATCH 27/54] lib/bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions To: Andy Shevchenko Cc: Rasmus Villemoes , Andrew Morton , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 4:42 AM Andy Shevchenko wrote: > > On Sun, Jan 23, 2022 at 10:38:58AM -0800, Yury Norov wrote: > > Many kernel users use bitmap_weight() to compare the result against > > some number or expression: > > > > if (bitmap_weight(...) > 1) > > do_something(); > > > > It works OK, but may be significantly improved for large bitmaps: if > > first few words count set bits to a number greater than given, we can > > stop counting and immediately return. > > > > The same idea would work in other direction: if we know that the number > > of set bits that we counted so far is small enough, so that it would be > > smaller than required number even if all bits of the rest of the bitmap > > are set, we can stop counting earlier. > > > > This patch adds new bitmap_weight_cmp() as suggested by Micha=C5=82 Mir= os=C5=82aw > > and a family of eq, gt, ge, lt and le wrappers to allow this optimizati= on. > > lt, and le > > > The following patches apply new functions where appropriate. > > What I missed in the above message is the rough statistics like some of t= hem > are used more often, some less, and some, perhaps, just added for the sak= e of > symmetry (the latter is what would be important to see if there are APIs = which > have no users at all). These are my grep numbers. Some lines are declarations and comments, so min= us 6 or 8 for each number, but all new functions have actual users. $ git grep weight_eq|wc -l 35 $ git grep weight_gt|wc -l 20 $ git grep weight_ge|wc -l 25 $ git grep weight_lt|wc -l 14 $ git grep weight_le|wc -l 18