From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sg-1-103.ptr.blmpb.com (sg-1-103.ptr.blmpb.com [118.26.132.103]) (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 0A4B41DF73C for ; Mon, 2 Mar 2026 07:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.103 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438016; cv=none; b=S+WfHOSn9rURI3R/m55zqLjt6MeoCqL9sFiwPD7rFApzb8XVvKGh6xHDnznKq5zHIa1YwxKT+wR8qnB0WZLhjKUoddpYcqb2OJfmFr46pMswg6ln7u+0j3QVb8wh26u2vxehEBq9hKi5h/IusqN8/iHLQT7s9KiwkhK/Og+H7aM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438016; c=relaxed/simple; bh=TCy2KX9qDbiHGy1QuZHj0y6OOg+oyJE4Ks74Pqah68A=; h=In-Reply-To:Cc:Message-Id:Content-Type:Subject:References:To:From: Date:Mime-Version; b=JegkQckedm4yyJImtn/mYzBP8cbLAdhXZXhk3yhgrZQxq8R4ShllEdUsbV4rkNbSRSgllYYsn3VXM5++KRJ0UIzfWvGbK6eq9zMYN2nQzRoq6viraH22W8dfDZckDBjCemRR3YLbxDpRupwub1U1whmmHQLW3LZB6JRFSWggCjE= 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=DBny4CM9; arc=none smtp.client-ip=118.26.132.103 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="DBny4CM9" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1772438003; 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=DBny4CM9qZq/PLHV90WtFVxoDEOx0sGU5FShhHT26Dc9R09lOdLB2XLE8gh8E3J2BklO1+ cGJhJfbb/xqfwemf+MJ3r+G9JRk99PHwNFokFXlxWTTq/Tu0irm3L7gHXycxg35IRrNzlv XLx81IxhV6SM1pZdqU3L+fCXtF1kp5WFMQ6VnmsFWGwP115A2sVYMkyBUuvJURsRP4+Tp2 E8r3ivbau1HrYAvCRoUgY2F+HNv9qUBfGkNmWDZHCfa9FluX1RdIplThJVV4kSm7aAqirn hIVChIr4lu8NFDgn+lvEsYz1tpCqTocyWp0KNFBruv++BrjZO+sdzbasBjOSzg== In-Reply-To: <20260302075216.2170675-1-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou Cc: , "Chuyi Zhou" Message-Id: <20260302075216.2170675-4-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 Subject: [PATCH v2 03/12] smp: Remove get_cpu from smp_call_function_any References: <20260302075216.2170675-1-zhouchuyi@bytedance.com> To: , , , , , , , , , , , From: "Chuyi Zhou" Date: Mon, 2 Mar 2026 15:52:07 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 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)); + local = false; + put_cpu(); + } ret = smp_call_function_single(cpu, func, info, wait); - put_cpu(); + if (local) + put_cpu(); return ret; } EXPORT_SYMBOL_GPL(smp_call_function_any); -- 2.20.1