From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 C060B3EA947 for ; Fri, 26 Jun 2026 09:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782467897; cv=none; b=MSmjV9SuhRnimlKkfAMVTrEqgnbpDmj8a9vkbPoqqIZwcGYFqKI+cIaQT+2o4ZsMb43exqHklsCfJoeoL5aCGvmj/HCU11A0nWBfBAMxA1hznq+R/q6yaI37wqOq7oQaYm2vt78QSK0spwwXYmV/WT2+ir0ywYdqj0c3zQRUyrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782467897; c=relaxed/simple; bh=e8c/bjTanH7hEivd6Gmfp7ldoOFkpJ1/tuoogJBqsWE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nr0072936V1YsKLDcInIvmwcrZO72RsGNNq0ucjrdCJUbvI4/EkxRohBLIMRPIvjeV6d7UfYkBT9a9cXcKFZwAJsWTZ+THUlP32U73qK3bjFvmgGJvrTobV16f0sXAQDWb1hbtXBd7wyPfjR72f91iQZygd0Xegn8aUqvtEWu2Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=E9ThupwA; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="E9ThupwA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=jehp8Dq6Kg/PIriEosSRwzz4xDur7VDm7brzEWiKkEU=; b=E9ThupwAXyEzI8/N94Re9BVT21 v6RgkB13BZg0HK6G9kEnJPpcx0+cAiUZmHOdSwb3rSGV/5BWXgykAWiKNb7Gv7hkqmmr7MoueZuSk o2YgBhW3AU41YYOlNwII5N11Wf9RFbM6f4FvPNBa6u1LBaMvyu5qlOmKXg50/hTN/UtFbP1lIoEQI lQUIMVuf5CnsYbjFbcY8nnp+NLVRzejSdedqJtTtl8sdeBmZIoZZ86JdMLXpH+ecrb1osPn1pH7MC Zm0aHnFyQV2IumjLDDQ4V85VQBYgY3SFh2UUU8PuhJs5DxPzdutrwmE8szfYnn02VuLbcpj9bD7wh 1lr4PlqA==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wd3K2-003t4O-2w; Fri, 26 Jun 2026 09:58:07 +0000 From: Breno Leitao Date: Fri, 26 Jun 2026 02:57:53 -0700 Subject: [PATCH v5 1/3] workqueue: split kick_pool() into kick_pool_pick() 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-Transfer-Encoding: 7bit Message-Id: <20260626-fastwake-v5-1-9ae2f1867234@debian.org> References: <20260626-fastwake-v5-0-9ae2f1867234@debian.org> In-Reply-To: <20260626-fastwake-v5-0-9ae2f1867234@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, bigeasy@linutronix.de, Hillf Danton , Breno Leitao , kernel-team@meta.com, kmagar@redhat.com, psuriset@redhat.com, david.dai@linux.dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2604; i=leitao@debian.org; h=from:subject:message-id; bh=e8c/bjTanH7hEivd6Gmfp7ldoOFkpJ1/tuoogJBqsWE=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqPk0mH/8j2/UOGqagfYhQu6ofShkPzdZlaGR1u 8MNYd6gPiiJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaj5NJgAKCRA1o5Of/Hh3 bbzxD/4nAWbdB8B9OLiOk4GBU4cPyzVaa95wycVsJtEu+M6hPRU7mNUvqCNvSXLD5GoKM2TPWGI xH2CoqOCTUt8V9fG9MStdASkmVjnoqDra+x72hiVUQ2XbwhU1VV2vwwNZQ6Xt/lfuQXJNUIHsuw EXjKrxD0FLjs0oQIDysIe+xHk3Ajt5hNvpblhIPNnuWhtavtvwQ8HLYYM5A66rN6Bzk+uWZK7Lt f5rBUI3j2QAiuIFmiT5ZD7tYhGvVbrjX8VJMsnvT9k4SUvUIwc+Yk0hoaK8kUhUuJ7CKk0xSExj GFUTee1qRePN+ledyZirX90kNtZTnq7kUr7b5948dP8f6O5zsyPz45H23JLQ439gSJ9qSfr8CgD zm5bQv4UmqRUI4XRu6MmQJ6EwgskdAdbW52457o41vPsotsmNsf2Ncry127K9OnvowjDGpWIRt9 JT9Tqv6zGhWwNF0oASRBJ/mQwYHHzwjDFsC4t1UElukHIHnm1lPFAcLVEuxnBnGOoefsmXBqj80 7/BEn+bnOJ0GSqkwhmbddO3RoAoEZ5qG9no00nDWYnSb/vLVyN8ipgt5G0TzQnlyoE1Fp+yeV8G ABqp0fBgiBDkrO0/IePOvCNccpkcBnNKBa9YRBD3YVIiHBpMln0RxDTrUUbWjRnHKrOrQvP4+/2 +K6SfkqsaGSYJOA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Factor the worker selection out of kick_pool() into kick_pool_pick(), which picks and claims the worker under pool->lock but, instead of waking it, returns the worker's task via an out-param so the caller can issue the wakeup after dropping pool->lock. BH kicks and wake_cpu setup still happen under the lock. kick_pool() becomes a thin wrapper that wakes the returned task, so all existing callers keep waking under pool->lock. Pure refactor, no functional change. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 78f25afb4a9d6..e855d15c1fb7b 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1258,19 +1258,27 @@ static void kick_bh_pool(struct worker_pool *pool) } /** - * kick_pool - wake up an idle worker if necessary + * kick_pool_pick - select an idle worker to kick, deferring the wakeup * @pool: pool to kick + * @wakep: out-param, set to the task to wake after pool->lock is dropped * - * @pool may have pending work items. Wake up worker if necessary. Returns - * whether a worker was woken up. + * Like kick_pool() but, for a regular (non-BH) pool, returns the picked + * worker's task via @wakep instead of waking it, so the caller can issue the + * wakeup after dropping pool->lock (the wakeup takes rq->lock). Worker + * selection, wake_cpu setup and the BH kick still happen under the lock. + * Returns whether a worker was selected or kicked. + * + * Must be called with @pool->lock held. */ -static bool kick_pool(struct worker_pool *pool) +static bool kick_pool_pick(struct worker_pool *pool, struct task_struct **wakep) { struct worker *worker = first_idle_worker(pool); struct task_struct *p; lockdep_assert_held(&pool->lock); + *wakep = NULL; + if (!need_more_worker(pool) || !worker) return false; @@ -1310,10 +1318,27 @@ static bool kick_pool(struct worker_pool *pool) } } #endif - wake_up_process(p); + *wakep = p; return true; } +/** + * kick_pool - wake up an idle worker if necessary + * @pool: pool to kick + * + * @pool may have pending work items. Wake up worker if necessary. Returns + * whether a worker was woken up. + */ +static bool kick_pool(struct worker_pool *pool) +{ + struct task_struct *p; + bool kicked = kick_pool_pick(pool, &p); + + if (p) + wake_up_process(p); + return kicked; +} + #ifdef CONFIG_WQ_CPU_INTENSIVE_REPORT /* -- 2.53.0-Meta