From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 252D2C433EF for ; Sun, 28 Nov 2021 23:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347376AbhK1Xlr (ORCPT ); Sun, 28 Nov 2021 18:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241220AbhK1Xjr (ORCPT ); Sun, 28 Nov 2021 18:39:47 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 898A5C06174A; Sun, 28 Nov 2021 15:36:30 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id 193so20935202qkh.10; Sun, 28 Nov 2021 15:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+pvPLMMOaG75eXeO+MYWVtFy7p98nfe1U4iD6DUFgqs=; b=FqHxiwrQ7QYivLGpovhQrNQCHUCj7LxMV2WH4G2Ujzkjgck5ZuLpYg6YmyS5/pcjd8 PioI6TsqEy6uPfhoz8wEavEgHnpCryLeBpBEb8dr5G6s12WteiFVLQFxrBR47EVsTB3X ndIWwpq8YabRGonzz7m7f+N7UJXzBMp2vfRHxXo9M1u6ZB6qiEh6DrJAZ2z7gRkAQ5sC IqRPeZsbgWqH6z7gZV/iyVzYOISv9QQ48jjOTsL+5HMXkolOWVbHK0gj+h+Ra3+OPnrQ HZwGnjmshXRb1nFHqTfVME98Ezv2622Zg9Ol7LGc837jR3cjnZ1W8PCl/MaA7m1eTWjV ggTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+pvPLMMOaG75eXeO+MYWVtFy7p98nfe1U4iD6DUFgqs=; b=7aCKBvnO39Y1LuXAjf4CAl3P3dr+n5iUSl7lBKO5t77W1Le21lLr7YvRw5FaPKHmiq ShOcyu57BVIRMNdlGnbI7HN6yV8DB/P0OlwZIZSm0MdLTk/GO/V3xwjg10HglkSYi5Pe KrwAAOWXjINFeJyw7pAJvUpSmV+8tZGvKFTlXrPIHi044KxyTJK2kYrHPdVS+PzBJxmJ pbWzbRIiqHJKtcgqWhXjLSdGtZNNl/WztchxAiPoYIaXMWhM8IZ5xaQK8EkvKC6k4Sv1 Ur5vhoAmKInmDomlj15CoBqvBDVzl9Cdf/xXZmiMwTzxKaN+tsRQDozr7sbd7WLF+IzA jhGg== X-Gm-Message-State: AOAM533px3vhgBpnIVbCj0cROWTiO3A0pfax9x4pTNf3EOCzzykhbySL 8xS7jW+rvn1ISeyXYMYWOKs= X-Google-Smtp-Source: ABdhPJwjz8dPYMt9os+urjypBO3KPO0n0aAUmhuhKTUddMw0/hFm/BxjybZbsejId+j0oxfauAhjwQ== X-Received: by 2002:a05:620a:4491:: with SMTP id x17mr26762094qkp.528.1638142589577; Sun, 28 Nov 2021 15:36:29 -0800 (PST) Received: from localhost ([66.216.211.25]) by smtp.gmail.com with ESMTPSA id h19sm8013261qth.63.2021.11.28.15.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Nov 2021 15:36:28 -0800 (PST) Date: Sun, 28 Nov 2021 15:36:27 -0800 From: Yury Norov To: Nicholas Piggin Cc: Arnaldo Carvalho de Melo , Andy Gross , David Airlie , Alexey Klimov , Andi Kleen , Andrew Morton , Alexander Shishkin , Amitkumar Karwar , Andrew Lunn , Andy Shevchenko , Anup Patel , Ard Biesheuvel , Arnd Bergmann , Jens Axboe , bcm-kernel-feedback-list@broadcom.com, Borislav Petkov , Catalin Marinas , Christoph Lameter , Daniel Vetter , Dave Hansen , David Laight , Dennis Zhou , Dinh Nguyen , Geetha sowjanya , Geert Uytterhoeven , Greg Kroah-Hartman , Guo Ren , Heiko Carstens , Christoph Hellwig , Hans de Goede , Ian Rogers , Jason Wessel , "James E.J. Bottomley" , Jonathan Cameron , Jiri Olsa , Juri Lelli , Kees Cook , Krzysztof Kozlowski , Jakub Kicinski , Kalle Valo , kvm@vger.kernel.org, Lee Jones , linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Russell King , linux-crypto@vger.kernel.org, linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Rasmus Villemoes , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-snps-arc@lists.infradead.org, Andy Lutomirski , Mark Gross , Mark Rutland , "Martin K. Petersen" , Marc Zyngier , Matti Vaittinen , Mauro Carvalho Chehab , Mel Gorman , Mike Marciniszyn , Ingo Molnar , Michael Ellerman , Marcin Wojtas , Palmer Dabbelt , "Paul E. McKenney" , Peter Zijlstra , Solomon Peachy , Petr Mladek , "Rafael J. Wysocki" , Randy Dunlap , Steven Rostedt , Roy Pledge , Saeed Mahameed , Sagi Grimberg , Subbaraya Sundeep , Stephen Boyd , Sergey Senozhatsky , Stephen Rothwell , Sunil Goutham , Sudeep Holla , Tariq Toukan , Thomas Gleixner , Tejun Heo , Thomas Bogendoerfer , Ulf Hansson , Vlastimil Babka , Vineet Gupta , Vincent Guittot , Viresh Kumar , Vivien Didelot , Will Deacon Subject: Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage Message-ID: <20211128233627.GA323159@lapt> References: <20211128035704.270739-1-yury.norov@gmail.com> <1638096766.3elxdzb8ly.astroid@bobo.none> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1638096766.3elxdzb8ly.astroid@bobo.none> Precedence: bulk List-ID: X-Mailing-List: linux-csky@vger.kernel.org On Sun, Nov 28, 2021 at 09:08:41PM +1000, Nicholas Piggin wrote: > Excerpts from Yury Norov's message of November 28, 2021 1:56 pm: > > In many cases people use bitmap_weight()-based functions like this: > > > > if (num_present_cpus() > 1) > > do_something(); > > > > This may take considerable amount of time on many-cpus machines because > > num_present_cpus() will traverse every word of underlying cpumask > > unconditionally. > > > > We can significantly improve on it for many real cases if stop traversing > > the mask as soon as we count present cpus to any number greater than 1: > > > > if (num_present_cpus_gt(1)) > > do_something(); > > > > To implement this idea, the series adds bitmap_weight_{eq,gt,le} > > functions together with corresponding wrappers in cpumask and nodemask. > > There would be no change to callers if you maintain counters like what > is done for num_online_cpus() today. Maybe some fixes to arch code that > does not use set_cpu_possible() etc APIs required, but AFAIKS it would > be better to fix such cases anyway. Thanks, Nick. I'll try to do this.