From nobody Wed Apr 1 11:33:13 2026 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4851E3D9023 for ; Tue, 31 Mar 2026 11:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774956741; cv=none; b=XMOGwtSLtNDnyHFdXm/WpovMrCzrz82iFkirBCOWpMEaOr6yr09TS//alWk5jayIjzk0o6ZYPUFUbdodZgLX3XlzfVw6rSPABETLaw07XO/6FDHmbUOamAbhjTdZFyPTUVqPH7eNzvrpGSQthVjQaOJfLBeLd13uw4QZr4LUhzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774956741; c=relaxed/simple; bh=TCy2KX9qDbiHGy1QuZHj0y6OOg+oyJE4Ks74Pqah68A=; h=Subject:Date:References:To:In-Reply-To:Mime-Version:Message-Id: From:Content-Type:Cc; b=tB40Pkp+mPwDyQt9jIjYx/EK8uSY+6hPKZ1T3o4npTYRTCqtiejcZvGqsYoP+KEJNhq0YcMg8z+A1L6kqE+gmBBTVWlzCRAl3N7JvxNhc6G99JY1JKPpw9zXlpNXiFy2nJkZQVUpgjptA5pHlwdVBo/AWFw5LDrByU4SE4rfHko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ZCmx/T8Z; arc=none smtp.client-ip=209.127.230.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ZCmx/T8Z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1774956727; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=KHQMxt7OqXLP0XEy9NJ/DuIMZST6z1kq98CQ96mzrVY=; b=ZCmx/T8Z8OR00gPQgwTCay76rknyED4x2Aw6w9YCRE3TJsu3W7pb1MXn61MRpuO9s5E0wR LSumeiIcWJ8Yoh9n+MQv6mJOEF6jwcMmKwsqFCPinQsJZjEoCSA23WeauYIvv0fvds/F8F Di7tsmZUL9j0kDIR9g4YQPPqSxitfG92wlGrXb5JhrBzqDCB6W/RvhwNHDNTtYrlSXBLt8 4cePQUIY9fd+7+YJZxpKGrkIwqMbH0y2lk//EmHahW8Qzc+QRxx/gzHQjakLicZQntUgp1 IyYOPUK81s89GSsfYj8jtBuhQyP5MQhmBiLOzEvYzIlSV9RRn/zMJRKI/SmKcA== Subject: [PATCH v4 03/12] smp: Remove get_cpu from smp_call_function_any Date: Tue, 31 Mar 2026 19:30:54 +0800 X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable References: <20260331113103.2197007-1-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou To: , , , , , , , , , , , , In-Reply-To: <20260331113103.2197007-1-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Message-Id: <20260331113103.2197007-4-zhouchuyi@bytedance.com> From: "Chuyi Zhou" Cc: , "Chuyi Zhou" Content-Type: text/plain; charset="utf-8" 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 =3D true; unsigned int cpu; int ret; =20 - /* Try for same CPU (cheapest) */ + /* + * Prevent migration to another CPU after selecting the current CPU + * as the target. + */ cpu =3D get_cpu(); - if (!cpumask_test_cpu(cpu, mask)) + + /* Try for same CPU (cheapest) */ + if (!cpumask_test_cpu(cpu, mask)) { cpu =3D sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); + local =3D false; + put_cpu(); + } =20 ret =3D smp_call_function_single(cpu, func, info, wait); - put_cpu(); + if (local) + put_cpu(); return ret; } EXPORT_SYMBOL_GPL(smp_call_function_any); --=20 2.20.1