Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: mirq-test@xxxxxxxxxxxx
- Subject: Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage
- From: Yury Norov <yury.norov@xxxxxxxxx>
- Date: Sun, 28 Nov 2021 22:38:39 -0800
- Cc: linux-kernel@xxxxxxxxxxxxxxx, Yury Norov <yury.norov@xxxxxxxxx>, "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>, "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>, "Paul E. McKenney" <paulmck@xxxxxxxxxx>, "Rafael J. Wysocki" <rafael@xxxxxxxxxx>, Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>, Alexey Klimov <aklimov@xxxxxxxxxx>, Amitkumar Karwar <amitkarwar@xxxxxxxxx>, Andi Kleen <ak@xxxxxxxxxxxxxxx>, Andrew Lunn <andrew@xxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Andy Gross <agross@xxxxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>, Andy Shevchenko <andy@xxxxxxxxxxxxx>, Anup Patel <anup.patel@xxxxxxx>, Ard Biesheuvel <ardb@xxxxxxxxxx>, Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Christoph Hellwig <hch@xxxxxx>, Christoph Lameter <cl@xxxxxxxxx>, Daniel Vetter <daniel@xxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, David Airlie <airlied@xxxxxxxx>, David Laight <David.Laight@xxxxxxxxxx>, Dennis Zhou <dennis@xxxxxxxxxx>, Dinh Nguyen <dinguyen@xxxxxxxxxx>, Geetha sowjanya <gakula@xxxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, Hans de Goede <hdegoede@xxxxxxxxxx>, Heiko Carstens <hca@xxxxxxxxxxxxx>, Ian Rogers <irogers@xxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Jakub Kicinski <kuba@xxxxxxxxxx>, Jason Wessel <jason.wessel@xxxxxxxxxxxxx>, Jens Axboe <axboe@xxxxxx>, Jiri Olsa <jolsa@xxxxxxxxxx>, Jonathan Cameron <jic23@xxxxxxxxxx>, Juri Lelli <juri.lelli@xxxxxxxxxx>, Kalle Valo <kvalo@xxxxxxxxxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>, Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxx>, Lee Jones <lee.jones@xxxxxxxxxx>, Marc Zyngier <maz@xxxxxxxxxx>, Marcin Wojtas <mw@xxxxxxxxxxxx>, Mark Gross <markgross@xxxxxxxxxx>, Mark Rutland <mark.rutland@xxxxxxx>, Matti Vaittinen <mazziesaccount@xxxxxxxxx>, Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>, Mel Gorman <mgorman@xxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Mike Marciniszyn <mike.marciniszyn@xxxxxxxxxxxxxxxxxxxx>, Nicholas Piggin <npiggin@xxxxxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Petr Mladek <pmladek@xxxxxxxx>, Randy Dunlap <rdunlap@xxxxxxxxxxxxx>, Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>, Roy Pledge <Roy.Pledge@xxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Saeed Mahameed <saeedm@xxxxxxxxxx>, Sagi Grimberg <sagi@xxxxxxxxxxx>, Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>, Solomon Peachy <pizza@xxxxxxxxxxxx>, Stephen Boyd <sboyd@xxxxxxxxxx>, Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>, Steven Rostedt <rostedt@xxxxxxxxxxx>, Subbaraya Sundeep <sbhatta@xxxxxxxxxxx>, Sudeep Holla <sudeep.holla@xxxxxxx>, Sunil Goutham <sgoutham@xxxxxxxxxxx>, Tariq Toukan <tariqt@xxxxxxxxxx>, Tejun Heo <tj@xxxxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ulf Hansson <ulf.hansson@xxxxxxxxxx>, Vincent Guittot <vincent.guittot@xxxxxxxxxx>, Vineet Gupta <vgupta@xxxxxxxxxx>, Viresh Kumar <viresh.kumar@xxxxxxxxxx>, Vivien Didelot <vivien.didelot@xxxxxxxxx>, Vlastimil Babka <vbabka@xxxxxxx>, Will Deacon <will@xxxxxxxxxx>, bcm-kernel-feedback-list@xxxxxxxxxxxx, kvm@xxxxxxxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-crypto@xxxxxxxxxxxxxxx, linux-csky@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, linux-perf-users@xxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx
- In-reply-to: <YaPEfZ0t9UFGwpml@qmqm.qmqm.pl>
- References: <20211128035704.270739-1-yury.norov@gmail.com> <YaPEfZ0t9UFGwpml@qmqm.qmqm.pl>
On Sun, Nov 28, 2021 at 07:03:41PM +0100, mirq-test@xxxxxxxxxxxx wrote:
> On Sat, Nov 27, 2021 at 07:56:55PM -0800, Yury Norov wrote:
> > 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.
>
> Having slept on it I have more structured thoughts:
>
> First, I like substituting bitmap_empty/full where possible - I think
> the change stands on its own, so could be split and sent as is.
Ok, I can do it.
> I don't like the proposed API very much. One problem is that it hides
> the comparison operator and makes call sites less readable:
>
> bitmap_weight(...) > N
>
> becomes:
>
> bitmap_weight_gt(..., N)
>
> and:
> bitmap_weight(...) <= N
>
> becomes:
>
> bitmap_weight_lt(..., N+1)
> or:
> !bitmap_weight_gt(..., N)
>
> I'd rather see something resembling memcmp() API that's known enough
> to be easier to grasp. For above examples:
>
> bitmap_weight_cmp(..., N) > 0
> bitmap_weight_cmp(..., N) <= 0
> ...
bitmap_weight_cmp() cannot be efficient. Consider this example:
bitmap_weight_lt(1000 0000 0000 0000, 1) == false
^
stop here
bitmap_weight_cmp(1000 0000 0000 0000, 1) == 0
^
stop here
I agree that '_gt' is less verbose than '>', but the advantage of
'_gt' over '>' is proportional to length of bitmap, and it means
that this API should exist.
> This would also make the implementation easier in not having to
> copy and paste the code three times. Could also use a simple
> optimization reducing code size:
In the next version I'll reduce code duplication like this:
bool bitmap_eq(..., N);
bool bitmap_ge(..., N);
#define bitmap_weight_gt(..., N) bitmap_weight_ge(..., N + 1)
#define bitmap_weight_lt(..., N) !bitmap_weight_ge(..., N)
#define bitmap_weight_le(..., N) !bitmap_weight_gt(..., N)
Thanks,
Yury
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]