From: Valentin Schneider <vschneid@redhat.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Yury Norov <yury.norov@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [RFC PATCH bitmap-for-next 1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro
Date: Thu, 6 Oct 2022 13:21:09 +0100 [thread overview]
Message-ID: <20221006122112.663119-2-vschneid@redhat.com> (raw)
In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com>
In preparation of introducing cpumask_next_and_wrap(), gather the
would-be-boiler-plate logic into a macro, as was done in
e79864f3164c ("lib/find_bit: optimize find_next_bit() functions")
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
lib/cpumask.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/lib/cpumask.c b/lib/cpumask.c
index c7c392514fd3..6e576485c84f 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -7,8 +7,27 @@
#include <linux/memblock.h>
#include <linux/numa.h>
+#define CPUMASK_NEXT_WRAP(FETCH_NEXT, n, start, wrap) \
+({ \
+ unsigned int next; \
+ \
+again: \
+ next = (FETCH_NEXT); \
+ \
+ if (wrap && n < start && next >= start) { \
+ next = nr_cpumask_bits; \
+ } else if (next >= nr_cpumask_bits) { \
+ wrap = true; \
+ n = -1; \
+ goto again; \
+ } \
+ \
+ next; \
+})
+
/**
- * cpumask_next_wrap - helper to implement for_each_cpu_wrap
+ * cpumask_next_wrap - Get the next CPU in a mask, starting from a given
+ * position and wrapping around to visit all CPUs.
* @n: the cpu prior to the place to search
* @mask: the cpumask pointer
* @start: the start point of the iteration
@@ -21,21 +40,7 @@
*/
unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
{
- unsigned int next;
-
-again:
- next = cpumask_next(n, mask);
-
- if (wrap && n < start && next >= start) {
- return nr_cpumask_bits;
-
- } else if (next >= nr_cpumask_bits) {
- wrap = true;
- n = -1;
- goto again;
- }
-
- return next;
+ return CPUMASK_NEXT_WRAP(cpumask_next(n, mask), n, start, wrap);
}
EXPORT_SYMBOL(cpumask_next_wrap);
--
2.31.1
next prev parent reply other threads:[~2022-10-06 12:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 12:21 [RFC PATCH bitmap-for-next 0/4] lib/cpumask, blk_mq: Fix blk_mq_hctx_next_cpu() vs cpumask_check() Valentin Schneider
2022-10-06 12:21 ` Valentin Schneider [this message]
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 2/4] lib/cpumask: Fix cpumask_check() warning in cpumask_next_wrap*() Valentin Schneider
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 3/4] lib/cpumask: Introduce cpumask_next_and_wrap() Valentin Schneider
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 4/4] blk_mq: Fix cpumask_check() warning in blk_mq_hctx_next_cpu() Valentin Schneider
2022-10-06 13:50 ` Yury Norov
2022-10-06 15:17 ` Valentin Schneider
2022-10-07 5:15 ` Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221006122112.663119-2-vschneid@redhat.com \
--to=vschneid@redhat.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox