From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F0D3321DE for ; Wed, 18 Mar 2026 15:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773848404; cv=none; b=p0hgGnhunNTXpb3wGBfW+XE4HPxx+3s4EEa54QL4i5m9eA8dWfNh7XQQwgk9+t1zU8pX8l9mJUZwrmP0YsgNZx8+LHBC+fNnHy9kJKtVdvKezZK6iJG52iNCLPzvWByZXS+vzkt4D4FYCaj4ZAIMF/MF2g07SJm3p/ILhvrxlgw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773848404; c=relaxed/simple; bh=sFU5bPlNQeC2Hk6el9zMyvsIoqEEs2ay8RSg9z8n1fI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YfxQB/AZLh03y/roR5xtPsoll1rnPIC/Bx1Sr6mDd9RTd/vJkllaCRVdNkRLs1jGThlfEThCs4mescXIBrj3MHKyMzHdS57yWKCW8FozE6swHGeeVhSqYSSKVcj7gt122YbwVK4WBCoJt5sDnHBhkzrOnVTQMBfCnIwBMLp0IXA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=J0SMZFuf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NpwI0wnA; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="J0SMZFuf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NpwI0wnA" Date: Wed, 18 Mar 2026 16:39:55 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1773848397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NNZ/dvKBTDY6S5FMU+5PB94QayMj9maDy6JGUhi/uV0=; b=J0SMZFufrRpmlQsEsxHvqrtxWnz5bEarCVQeP/HjuY/nfWsnPOld7iWyrZbXtY/Ogcfqfm X/+t0sjIAVR34MG/AgOayQLiAlKRtAeahT/FDiBGR9HY2by7raulUC2ABmtm3Z3j1llEid 1p8gwLl4NSDFxZArUfQmv9WDZIVbAG1DwfPIVSH30Hg8aXSifTyLeUf8YFtrwRiu7qwCfW iNfvedJ9FnCvB2NlNHySOhPb4xnH7e0j0/3FYD7viPPgK7LDVKV5fK0I8Z4FV0NwHij3BP idzus3fOFpy0SsqHte4t9QKJAVApYYszb0XixHgO4PMwn3upgfRGqqKZCnoktw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1773848397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NNZ/dvKBTDY6S5FMU+5PB94QayMj9maDy6JGUhi/uV0=; b=NpwI0wnA07V9MVM8BjMnr5NjZ8np1wwqevEcBgykLU5qgNDy1DtA6zCR852bI32a16ldPV mf5l4xPrWYWW19Bg== From: Sebastian Andrzej Siewior To: Steven Rostedt Cc: Chuyi Zhou , tglx@linutronix.de, mingo@redhat.com, luto@kernel.org, peterz@infradead.org, paulmck@kernel.org, muchun.song@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, pbonzini@redhat.com, clrkwllms@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 03/12] smp: Remove get_cpu from smp_call_function_any Message-ID: <20260318153955.AbRuTUwB@linutronix.de> References: <20260318045638.1572777-1-zhouchuyi@bytedance.com> <20260318045638.1572777-4-zhouchuyi@bytedance.com> <20260318103237.390815ae@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20260318103237.390815ae@gandalf.local.home> On 2026-03-18 10:32:37 [-0400], Steven Rostedt wrote: > On Wed, 18 Mar 2026 12:56:29 +0800 > "Chuyi Zhou" wrote: > > > Now smp_call_function_single() would enable preemption before > > csd_lock_wait() to reduce the critical section. To allow callers of > > smp_call_function_any() to also benefit from this optimization, remove > > get_cpu()/put_cpu() from smp_call_function_any(). > > > > Signed-off-by: Chuyi Zhou > > Reviewed-by: Muchun Song > > --- > > kernel/smp.c | 16 +++++++++++++--- > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > diff --git a/kernel/smp.c b/kernel/smp.c > > index b603d4229f95..80daf9dd4a25 100644 > > --- a/kernel/smp.c > > +++ b/kernel/smp.c > > @@ -761,16 +761,26 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async); > > int smp_call_function_any(const struct cpumask *mask, > > smp_call_func_t func, void *info, int wait) > > { > > + bool local = true; > > unsigned int cpu; > > int ret; > > > > - /* Try for same CPU (cheapest) */ > > + /* > > + * Prevent migration to another CPU after selecting the current CPU > > + * as the target. > > + */ > > cpu = get_cpu(); > > - if (!cpumask_test_cpu(cpu, mask)) > > + > > + /* Try for same CPU (cheapest) */ > > + if (!cpumask_test_cpu(cpu, mask)) { > > cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); > > Hmm, isn't this looking for another CPU that is closest to the current CPU? > > By allowing migration, it is possible that the task will migrate to another > CPU where this will pick one that is much farther. > > I'm not sure if that's really an issue or not, as I believe it's mostly for > performance reasons. Then again, why even keep preemption disabled for the > current CPU case? Isn't disabling preemption more for performance than > correctness? > > Perhaps migrate_disable() is all that is needed? You want the local-CPU so it is cheap as in direct invocation. But if you migrate away between the get_cpu() and the check in generic_exec_single() you do trigger an interrupt. A migration here would not be wrong, it would just not be as cheap as intended. Not sure if migrate_disable() counters the cheap part again. An alternative would be to have the local execution in __generic_exec_local() and have it run with disabled preemption and a fallback with enabled preemption where it is enqueue and probably waited for. > -- Steve Sebastian