From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
Alexander Lobakin <alexandr.lobakin@intel.com>,
Alexei Starovoitov <ast@kernel.org>,
Alexey Klimov <aklimov@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andrii Nakryiko <andrii@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Ben Segall <bsegall@google.com>, Christoph Lameter <cl@linux.com>,
Dan Williams <dan.j.williams@intel.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Dennis Zhou <dennis@kernel.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Eric Dumazet <edumazet@google.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Guenter Roeck <linux@roeck-us.net>,
Ingo Molnar <mingo@redhat.com>,
Isabella Basso <isabbasso@riseup.net>,
John Fastabend <john.fastabend@gmail.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Juergen Gross <jgross@suse.com>,
Juri Lelli <juri.lelli@redhat.com>, KP Singh <kpsingh@kernel.org>,
Kees Cook <keescook@chromium.org>,
Martin KaFai Lau <kafai@fb.com>, Mel Gorman <mgorman@suse.de>,
Miroslav Benes <mbenes@suse.cz>,
Nathan Chancellor <nathan@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Randy Dunlap <rdunlap@infradead.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Song Liu <songliubraving@fb.com>,
Steven Rostedt <rostedt@goodmis.org>, Tejun Heo <tj@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Valentin Schneider <vschneid@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Vlastimil Babka <vbabka@suse.cz>, Yonghong Song <yhs@fb.com>,
Yury Norov <yury.norov@gmail.com>,
linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH 07/16] smp: optimize smp_call_function_many_cond()
Date: Mon, 18 Jul 2022 12:28:35 -0700 [thread overview]
Message-ID: <20220718192844.1805158-8-yury.norov@gmail.com> (raw)
In-Reply-To: <20220718192844.1805158-1-yury.norov@gmail.com>
smp_call_function_many_cond() is often passed with cpu_online_mask.
If this is the case, we can use num_online_cpus(), which is O(1)
instead of cpumask_{first,next}(), which is O(N).
It can be optimized further: if cpu_online_mask has 0 or single bit
set (depending on cpu_online(this_cpu), we can return result without
AND'ing with user's mask.
Caught with CONFIG_DEBUG_BITMAP:
[ 7.830337] Call trace:
[ 7.830397] __bitmap_check_params+0x1d8/0x260
[ 7.830499] smp_call_function_many_cond+0x1e8/0x45c
[ 7.830607] kick_all_cpus_sync+0x44/0x80
[ 7.830698] bpf_int_jit_compile+0x34c/0x5cc
[ 7.830796] bpf_prog_select_runtime+0x118/0x190
[ 7.830900] bpf_prepare_filter+0x3dc/0x51c
[ 7.830995] __get_filter+0xd4/0x170
[ 7.831145] sk_attach_filter+0x18/0xb0
[ 7.831236] sock_setsockopt+0x5b0/0x1214
[ 7.831330] __sys_setsockopt+0x144/0x170
[ 7.831431] __arm64_sys_setsockopt+0x2c/0x40
[ 7.831541] invoke_syscall+0x48/0x114
[ 7.831634] el0_svc_common.constprop.0+0x44/0xfc
[ 7.831745] do_el0_svc+0x30/0xc0
[ 7.831825] el0_svc+0x2c/0x84
[ 7.831899] el0t_64_sync_handler+0xbc/0x140
[ 7.831999] el0t_64_sync+0x18c/0x190
[ 7.832086] ---[ end trace 0000000000000000 ]---
[ 7.832375] b1: ffff24d1ffd98a48
[ 7.832385] b2: ffffa65533a29a38
[ 7.832393] b3: ffffa65533a29a38
[ 7.832400] nbits: 256
[ 7.832407] start: 0
[ 7.832412] off: 0
[ 7.832418] smp: Bitmap: parameters check failed
[ 7.832432] smp: include/linux/bitmap.h [363]: bitmap_and
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
kernel/smp.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/kernel/smp.c b/kernel/smp.c
index dd215f439426..7ed2b9b12f74 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -880,6 +880,28 @@ EXPORT_SYMBOL_GPL(smp_call_function_any);
#define SCF_WAIT (1U << 0)
#define SCF_RUN_LOCAL (1U << 1)
+/* Check if we need remote execution, i.e., any CPU excluding this one. */
+static inline bool __need_remote_exec(const struct cpumask *mask, unsigned int this_cpu)
+{
+ unsigned int cpu;
+
+ switch (num_online_cpus()) {
+ case 0:
+ return false;
+ case 1:
+ return cpu_online(this_cpu) ? false : true;
+ default:
+ if (mask == cpu_online_mask)
+ return true;
+ }
+
+ cpu = cpumask_first_and(mask, cpu_online_mask);
+ if (cpu == this_cpu)
+ cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
+
+ return cpu < nr_cpu_ids;
+}
+
static void smp_call_function_many_cond(const struct cpumask *mask,
smp_call_func_t func, void *info,
unsigned int scf_flags,
@@ -916,12 +938,7 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
if ((scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask))
run_local = true;
- /* Check if we need remote execution, i.e., any CPU excluding this one. */
- cpu = cpumask_first_and(mask, cpu_online_mask);
- if (cpu == this_cpu)
- cpu = cpumask_next_and(cpu, mask, cpu_online_mask);
- if (cpu < nr_cpu_ids)
- run_remote = true;
+ run_remote = __need_remote_exec(mask, this_cpu);
if (run_remote) {
cfd = this_cpu_ptr(&cfd_data);
--
2.34.1
next prev parent reply other threads:[~2022-07-18 19:29 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 19:28 [PATCH 00/16] Introduce DEBUG_BITMAP config option and bitmap_check_params() Yury Norov
2022-07-18 19:28 ` [PATCH 01/16] lib/bitmap: add bitmap_check_params() Yury Norov
2022-07-18 21:01 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 02/16] lib/bitmap: don't call bitmap_set() with len == 0 Yury Norov
2022-07-18 21:06 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 03/16] lib/test_bitmap: don't test bitmap_set if nbits " Yury Norov
2022-07-18 21:08 ` Andy Shevchenko
2022-08-09 12:37 ` Rasmus Villemoes
2022-07-18 19:28 ` [PATCH 04/16] lib/test_bitmap: test test_bitmap_arr{32,64} starting from nbits == 1 Yury Norov
2022-07-18 21:09 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 05/16] lib/test_bitmap: disable compile-time test if DEBUG_BITMAP() is enabled Yury Norov
2022-07-18 21:10 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 06/16] lib/test_bitmap: delete meaningless test for bitmap_cut Yury Norov
2022-07-18 21:11 ` Andy Shevchenko
2022-07-18 19:28 ` Yury Norov [this message]
2022-07-18 21:26 ` [PATCH 07/16] smp: optimize smp_call_function_many_cond() Peter Zijlstra
2022-07-18 21:36 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 08/16] smp: optimize smp_call_function_many_cond() for more Yury Norov
2022-07-18 21:29 ` Peter Zijlstra
2022-07-20 17:06 ` Yury Norov
2022-07-18 21:37 ` Andy Shevchenko
2022-07-18 19:28 ` [PATCH 09/16] irq: don't copy cpu affinity mask if source is equal to destination Yury Norov
2022-07-18 21:30 ` Peter Zijlstra
2022-07-18 19:28 ` [PATCH 10/16] sched: optimize __set_cpus_allowed_ptr_locked() Yury Norov
2022-07-18 21:34 ` Peter Zijlstra
2022-07-18 19:28 ` [PATCH 11/16] time: optimize tick_check_preferred() Yury Norov
2022-08-06 8:30 ` Thomas Gleixner
2022-08-08 11:42 ` Thomas Gleixner
2022-08-08 16:38 ` Yury Norov
2022-08-09 12:29 ` Rasmus Villemoes
2022-07-18 19:28 ` [PATCH 12/16] time: optimize tick_check_percpu() Yury Norov
2022-07-18 19:28 ` [PATCH 13/16] time: optimize tick_setup_device() Yury Norov
2022-07-18 21:35 ` Peter Zijlstra
2022-07-18 19:28 ` [PATCH 14/16] mm/percpu: optimize pcpu_alloc_area() Yury Norov
2022-07-19 4:25 ` Dennis Zhou
2022-07-18 19:28 ` [PATCH 15/16] sched/topology: optimize topology_span_sane() Yury Norov
2022-07-18 21:37 ` Peter Zijlstra
2022-07-18 19:28 ` [PATCH 16/16] lib: create CONFIG_DEBUG_BITMAP parameter Yury Norov
2022-07-18 21:39 ` Andy Shevchenko
2022-07-20 16:49 ` 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=20220718192844.1805158-8-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=aklimov@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexandr.lobakin@intel.com \
--cc=andrii@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=cl@linux.com \
--cc=dan.j.williams@intel.com \
--cc=daniel@iogearbox.net \
--cc=dennis@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=isabbasso@riseup.net \
--cc=jgross@suse.com \
--cc=john.fastabend@gmail.com \
--cc=jpoimboe@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@rasmusvillemoes.dk \
--cc=linux@roeck-us.net \
--cc=mbenes@suse.cz \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yhs@fb.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;
as well as URLs for NNTP newsgroup(s).