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 2885FC433EF for ; Mon, 18 Jul 2022 21:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235131AbiGRV2I (ORCPT ); Mon, 18 Jul 2022 17:28:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233730AbiGRV1n (ORCPT ); Mon, 18 Jul 2022 17:27:43 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C67832FFC2; Mon, 18 Jul 2022 14:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lSkv8nOF7z0qY9Il4gJSah6aT0EynXIpnmz3r7Nd3zY=; b=VzUCoQthtH6+JWXI+qC6/dm9sU e9VkL400c12o9AcDiovabduBPJZzKqkLZfdimO/F4yIEr5iP89pOkuBws2+TTwCI0XA9S+ri2MYOH iQwsce1cEC0SfvgKLAKdxvzsC4oQZXpxVP2qjS6q2qE5idAMTbIUR+e4XeR2d3HwUE0Gpoffjc7lE biZ0mnyUt9Ca8FMMtPr1yyOFp1njQv+GJCg+7ZJwuG3vBAyGq2yL8mza2zXnWaK7WBLHrcW+YwJsX yIAjSpKZtSRI5Z6E5VhdDvn34wNl1HtLT3EsgE4NYbyy1OfZK5vxvMygXZvng7SNR4QjP0msQdMtk 1fMHlWwg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDYGQ-004u7h-1o; Mon, 18 Jul 2022 21:26:50 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id D5CEA9802A7; Mon, 18 Jul 2022 23:26:48 +0200 (CEST) Date: Mon, 18 Jul 2022 23:26:48 +0200 From: Peter Zijlstra To: Yury Norov Cc: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Andy Shevchenko , Ben Segall , Christoph Lameter , Dan Williams , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , Dietmar Eggemann , Eric Dumazet , Frederic Weisbecker , Guenter Roeck , Ingo Molnar , Isabella Basso , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Kees Cook , Martin KaFai Lau , Mel Gorman , Miroslav Benes , Nathan Chancellor , "Paul E . McKenney" , Randy Dunlap , Rasmus Villemoes , Sebastian Andrzej Siewior , Song Liu , Steven Rostedt , Tejun Heo , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vlastimil Babka , Yonghong Song , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH 07/16] smp: optimize smp_call_function_many_cond() Message-ID: References: <20220718192844.1805158-1-yury.norov@gmail.com> <20220718192844.1805158-8-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220718192844.1805158-8-yury.norov@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 18, 2022 at 12:28:35PM -0700, Yury Norov wrote: > 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); This is more complex code for, very little to no gain. Why ?!