All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] lib/find: add find_nth_bit()
@ 2022-07-06 18:22 Yury Norov
  2022-07-06 18:22 ` [PATCH 1/5] lib: add find_nth(,and,andnot)_bit() Yury Norov
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Yury Norov @ 2022-07-06 18:22 UTC (permalink / raw)
  To: linux-kernel, 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,
	Toke Høiland-Jørgensen
  Cc: Yury Norov

Kernel lacks for a function that searches for Nth bit in a bitmap.
Usually people do it like this:
	for_each_set_bit(bit, mask, size)
		if (--n == 0)
			return bit;

Which is not so elegant, and very slow.

This series adds fast routines for this task, and applies them where
appropriate.

While here, move thin wrappers around find_bit() in nodemask.c to a
corresponding header, and because nodemask.c is empty after that,
remove it.

On top of "lib: cleanup bitmap-related headers":
https://lkml.org/lkml/2022/7/6/1202

Yury Norov (5):
  lib: add find_nth(,and,andnot)_bit()
  lib/bitmap: add tests for find_nth_bit()
  remove bitmap_ord_to_pos
  cpumask: add cpumask_nth_{,and,andnot}
  lib/nodemask: inline next_node_in() and node_random()

 MAINTAINERS              |  1 -
 include/linux/bitmap.h   |  1 -
 include/linux/bitops.h   | 19 ++++++++++
 include/linux/cpumask.h  | 44 ++++++++++++++++++++++
 include/linux/find.h     | 79 ++++++++++++++++++++++++++++++++++++++++
 include/linux/nodemask.h | 27 +++++++++++---
 lib/Makefile             |  2 +-
 lib/bitmap.c             | 36 ++----------------
 lib/cpumask.c            | 26 ++++++-------
 lib/find_bit.c           | 20 ++++++++++
 lib/find_bit_benchmark.c | 17 +++++++++
 lib/nodemask.c           | 31 ----------------
 lib/test_bitmap.c        | 36 +++++++++++++++++-
 13 files changed, 250 insertions(+), 89 deletions(-)
 delete mode 100644 lib/nodemask.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH v2 0/5] lib/find: add find_nth_bit()
@ 2022-07-11  4:47 Yury Norov
  2022-07-11  4:47 ` [PATCH 1/5] lib: add find_nth(,and,andnot)_bit() Yury Norov
  0 siblings, 1 reply; 12+ messages in thread
From: Yury Norov @ 2022-07-11  4:47 UTC (permalink / raw)
  To: linux-kernel, 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,
	Toke Høiland-Jørgensen
  Cc: Yury Norov

Kernel lacks for a function that searches for Nth bit in a bitmap.
Usually people do it like this:
        for_each_set_bit(bit, mask, size)
                if (--n == 0)
                        return bit;

Which is not so elegant, and very slow.

This series adds fast routines for this task, and applies them where
appropriate.

While here, move thin wrappers around find_bit() in nodemask.c to a
corresponding header, and because nodemask.c is empty after that,
remove it.

v1: https://lore.kernel.org/lkml/20220706182300.70862-4-yury.norov@gmail.com/T/
v2: - count Nth bit from 0 (was 1);
    - use 'invert' trick in _find_nth_bit(), as in _find_next_bit();
    - cleanup comments;
    - fns() is kept inline - looking at __ffs() generic implementation,
      I decided to keep it untouched.

Yury Norov (5):
  lib: add find_nth(,and,andnot)_bit()
  lib/bitmap: add tests for find_nth_bit()
  lib/bitmap: remove bitmap_ord_to_pos
  cpumask: add cpumask_nth_{,and,andnot}
  lib/nodemask: inline next_node_in() and node_random()

 MAINTAINERS              |  1 -
 include/linux/bitmap.h   |  1 -
 include/linux/bitops.h   | 19 +++++++++
 include/linux/cpumask.h  | 44 +++++++++++++++++++++
 include/linux/find.h     | 83 ++++++++++++++++++++++++++++++++++++++++
 include/linux/nodemask.h | 27 ++++++++++---
 lib/Makefile             |  2 +-
 lib/bitmap.c             | 36 ++---------------
 lib/cpumask.c            | 26 ++++++-------
 lib/find_bit.c           | 20 ++++++++++
 lib/find_bit_benchmark.c | 17 ++++++++
 lib/nodemask.c           | 31 ---------------
 lib/test_bitmap.c        | 36 ++++++++++++++++-
 13 files changed, 254 insertions(+), 89 deletions(-)
 delete mode 100644 lib/nodemask.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-07-11  4:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 18:22 [PATCH 0/5] lib/find: add find_nth_bit() Yury Norov
2022-07-06 18:22 ` [PATCH 1/5] lib: add find_nth(,and,andnot)_bit() Yury Norov
2022-07-07  7:25   ` Rasmus Villemoes
2022-07-07 21:03     ` Yury Norov
2022-07-08  8:26       ` Rasmus Villemoes
2022-07-08  9:12         ` Andy Shevchenko
2022-07-08 16:40           ` Yury Norov
2022-07-06 18:22 ` [PATCH 2/5] lib/bitmap: add tests for find_nth_bit() Yury Norov
2022-07-06 18:22 ` [PATCH 3/5] lib/bitmap: remove bitmap_ord_to_pos Yury Norov
2022-07-06 18:22 ` [PATCH 4/5] cpumask: add cpumask_nth_{,and,andnot} Yury Norov
2022-07-06 18:23 ` [PATCH 5/5] lib/nodemask: inline next_node_in() and node_random() Yury Norov
2022-07-11  4:47 [PATCH v2 0/5] lib/find: add find_nth_bit() Yury Norov
2022-07-11  4:47 ` [PATCH 1/5] lib: add find_nth(,and,andnot)_bit() Yury Norov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.