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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85EB7C43334 for ; Mon, 18 Jul 2022 21:27:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7E036B0071; Mon, 18 Jul 2022 17:27:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B05596B0087; Mon, 18 Jul 2022 17:27:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97F2F8E0001; Mon, 18 Jul 2022 17:27:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 841096B0071 for ; Mon, 18 Jul 2022 17:27:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 57B8933DAB for ; Mon, 18 Jul 2022 21:27:20 +0000 (UTC) X-FDA: 79701506640.18.99C6B67 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf29.hostedemail.com (Postfix) with ESMTP id 9D982120062 for ; Mon, 18 Jul 2022 21:27:17 +0000 (UTC) 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> ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=VzUCoQth; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658179640; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lSkv8nOF7z0qY9Il4gJSah6aT0EynXIpnmz3r7Nd3zY=; b=vBECMcMMHFhG49FW2D3/76g5io64uNT2cg1SlgHcHTk+MnBUSjBQ+ZrfGfOSszU9cLKbzj N0svLk2gxmdeMJfQq1FnhnXLb8QOy7b06J+JebMbOiWYVV/OsyJZXS8XrfIpjnuRjFfy4z qGLyAuRh6+9HtE8zxQLxyJZ8zQoZTe0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658179640; a=rsa-sha256; cv=none; b=FFFG2u9BKoo0bV7er7G7Eh2W3L35gU7gCVqedn6gqujMNZuKehR0BmXIpo61vIgpUpJWP8 JE1yvWvJWwxa3K0L2iKYWwx+V549eri/s4ujLQl8k1bjkaYLiSJb1kowLsW//1LjZB/f/G h7hFp5PuyKPJl0ybWgHm8wh6CWsBDFo= X-Rspamd-Queue-Id: 9D982120062 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=VzUCoQth; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pe7ahaggsmhtzozoeayhmbwuhk6tu4mp X-HE-Tag: 1658179637-436390 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 ?!