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 8E4842BEFED for ; Tue, 16 Jun 2026 13:34:23 +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=1781616865; cv=none; b=ZVV3kGYCiB21FQ/+Lg8O7hLQHKMC5/iAwJaEpVTKfQ9VHFRS6Af43JjM5iW46LEVzMJpYglj/3yp5Lvcyro8D2I/R0j7JNOQ3bCrAUpCCDezguqm7nIaNILo2721/vJfZB0Q0feAo4hE1iq24OsNPIfhTGfthxlIlClSpcuaHn8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781616865; c=relaxed/simple; bh=c+4LbJ3gMx9qJUlSsDNFD9XxCuN5iCHFGns/3U6IpxU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZMEvzbZr7MWyg3rGMG8T1aefdyg/I90pGwj1/BKhDOYo0blY7bEbJmMeGOlm5jGhc1TABfRgI4oEa2fkb7cPlZozZmqArEZ79/vyL0FlE/+7MrXf7WjqDAwwsD5yu5FOBsI516eBKjFsSc7dY3Q8Jur0X6vVeQbo8VTcD9+2nZQ= 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=mA5DhFxR; 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="mA5DhFxR" 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=zZ/QEL0ID8h7u6cAQJchn8RHzU+66NOaG1F8TcgtXjQ=; b=mA5DhFxRMgltmKVuj0udCv0HBV B8gfMNMGUlBwaniKeCH2SUSNh7NdQCZDtxaC4nZvsGN16BnX6lHi1f4SIYS4iTRl3BtNmWlCx3DFG WZ4Jz3Uu5y0h5DuByxYG/qSUpLhdQPUt6bMHjz6qxuOVNqaDJY89hK7ZJdSIc61q6v3kYrkPpWEE1 oePTiFNgVYe4VH/vVGikjqub/BFuiVGiQkXcujQkD8BHZEgZC6NVjsqJi5cZ5ti86j317h09Uj/gq 2jmGTIn1Xe39T6CT/5vRTjoWn4d7sdGky8YqT3L0AdwKd9vEd3oKrX5CLqrz7bQUpcnCBxx7/RtNC YT0j9YeA==; 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 1wZTvk-00DsxG-34; Tue, 16 Jun 2026 13:34:17 +0000 From: Breno Leitao Date: Tue, 16 Jun 2026 06:33:31 -0700 Subject: [PATCH v3 1/3] workqueue: split kick_pool() into kick_pool_pick() + wake_up_q() 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: <20260616-fastwake-v3-1-79da19fcd08f@debian.org> References: <20260616-fastwake-v3-0-79da19fcd08f@debian.org> In-Reply-To: <20260616-fastwake-v3-0-79da19fcd08f@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 X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2586; i=leitao@debian.org; h=from:subject:message-id; bh=c+4LbJ3gMx9qJUlSsDNFD9XxCuN5iCHFGns/3U6IpxU=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqMVDQIIF2V0Ml5UDUAZacF4azUTWWcJQSwM56Z uAJzIZYCCCJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCajFQ0AAKCRA1o5Of/Hh3 beHvD/oCu8Px7M+1iuo1IXIbDa8t3t7NdPUHHftYYPX1ntYA4eXF2u/Rylp8ZmgUAKYnRZjNJ5e PRapsCra6AHdT8raRRh0A8td3vgF0JAwvvXhgdj8lWTq9mTbHMfaXG4GubfNNqM2TS539Q3LXdv R3kVKl/iq+TNdprSKCsjHev89BAei9lTmnZVEOCvFnkses5uMHUDgR/wpj6nk1NsGyYfFEWbp25 vYjTUrMYv+YkN8UzwMBeq4agYGmPw1a4wbpNXd2R8aZWaI+ab9bcknfg3VvDa6xoAN88wBk7Ke4 mkkKeAWnZ6iHk3yhOVLIJWjvKWvbYAY+JBaPKhrczygsKPIX1KmfaCpdBXpgH9vXyyy5kapPqnz qayyxx96wsd5LxQC0G9ODoqtvZ07+OHJRta/W//WiHS4M7OacRzG22dRnFhgK39EjRfATPSeaeO psTLmfRS9IDSmlONETZoOTFcEmMBg3WM/WkmqZMGhtcGXgklBXj7x3527RYmP/er8xc7QqPJjSP A03NGgjtkIDyBUnp7vvktoGDh68i+XgkdQ7JK84jgygoYhwK9xQst6K/6p5jrx/TgVyK4/wwbxl 11vt5+4ij8pkUGRebwyBytRLHUsbhQtmFtEuG8YY2rI3tGMNPJuEvzImkqKGa232MKhrskqmG1y BR3CTOqlsxtaj+g== 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, queues it on a caller-provided wake_q via wake_q_add(). The caller issues the wakeup later with wake_up_q(). wake_q_add() is safe under the lock (cmpxchg + get_task_struct()); only wake_up_q() takes rq->lock. kick_pool() becomes a thin wrapper using a local wake_q, so all existing callers keep waking under pool->lock. Pure refactor, no functional change. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 78f25afb4a9d6..fd3b5bc78df9e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -1258,13 +1259,17 @@ static void kick_bh_pool(struct worker_pool *pool) } /** - * kick_pool - wake up an idle worker if necessary + * kick_pool_pick - select and claim an idle worker, deferring the wakeup * @pool: pool to kick + * @wakeq: wake_q to queue the selected worker on * - * @pool may have pending work items. Wake up worker if necessary. Returns - * whether a worker was woken up. + * Like kick_pool() but queues the picked worker on @wakeq (wake_q_add()) + * instead of waking it, so the caller can wake_up_q(@wakeq) after dropping + * pool->lock. Returns whether a worker was selected. + * + * 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 wake_q_head *wakeq) { struct worker *worker = first_idle_worker(pool); struct task_struct *p; @@ -1310,10 +1315,27 @@ static bool kick_pool(struct worker_pool *pool) } } #endif - wake_up_process(p); + wake_q_add(wakeq, 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) +{ + DEFINE_WAKE_Q(wakeq); + bool kicked; + + kicked = kick_pool_pick(pool, &wakeq); + wake_up_q(&wakeq); + return kicked; +} + #ifdef CONFIG_WQ_CPU_INTENSIVE_REPORT /* -- 2.53.0-Meta