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 C8B5030C145 for ; Wed, 3 Jun 2026 13:40:42 +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=1780494044; cv=none; b=QDYKZIdUqnsD6jsnohz/+AZUverlOy/431VW1diTkQ+u7sO9QF/89/d0X17V8+VhEg9VQjEPH5ifYCTq926OICaHcdiNFBfilX26JULYfJh11MfeP/ptmoOsI5r84tQyc6TERXooGBOsQevLp9NIBqZQFITpFdm7+yiqwcMlxN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780494044; c=relaxed/simple; bh=5zuCILowJvwKt2iMqBvXcW0/SCwgdBL2D6Kzu8fhPPI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BBqYqmE9BdAQ2HS88aN5UTq1dfE+4vJPHBja0uP/usmwBp7dB6FBtrdx2cnW2fc5DRVyRj+fdRY+fAOXWJsNiBohunHsmrFYuoyyPFghEgylqmDGORUY1dNvDEbIwcGyizzbzbFhu3vlIYNQX+o1LXfVLdXIAhgtQerLjjul6rw= 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=TiMH4afT; 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="TiMH4afT" 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=IboW8XcmfP5WrWPuXkFKLhoyJ02H6sqZ2ovSjXYM4rk=; b=TiMH4afTeQCnmBncYWvSlwsyq9 A7bfLEMM22WYv9DiKk7chFPAAYuMPu9VI7pR4I0Ev7JT4+6Pq9EgkJ49u0MBOBayjXIpUolRb6XrZ vLWC1SazXngh9XCIQue3ifXXYCwAYN0BA6lwGvvttuGSr2vOfkZouIv0QwaDGm/KlzYga/8ClEJpm TIrMK6CPCrAxPHB3iUBIfBh/q/r6fDVCpr15KaMOPdS4MXOdNQn5JGLeee7U9L9aXhF9iOxPgU6Wv Dty9Mn0FPO5hdWo4b+Rb2/t3dtmXsl0TBBNoaG679erIDjDE4g5O2/yEOOK58C3IQ5+4Ax7/zO0zO HXa1F89w==; 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 1wUlpb-003m3i-2z; Wed, 03 Jun 2026 13:40:28 +0000 From: Breno Leitao Date: Wed, 03 Jun 2026 06:40:09 -0700 Subject: [PATCH v2 2/4] 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: <20260603-fastwake-v2-2-2977512fe7fa@debian.org> References: <20260603-fastwake-v2-0-2977512fe7fa@debian.org> In-Reply-To: <20260603-fastwake-v2-0-2977512fe7fa@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 X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2670; i=leitao@debian.org; h=from:subject:message-id; bh=5zuCILowJvwKt2iMqBvXcW0/SCwgdBL2D6Kzu8fhPPI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqIC6+Yk1Rky+cgXyoiEq8w5dqJENvLAN9Mm7AW ldV2jM/vLaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaiAuvgAKCRA1o5Of/Hh3 bevTD/0V/Hauv0oijRL9sDMnK+ZKToT3C1d+4+tdOwDkUj8uSekGk7izOkeOe/8/0q6YUKdCKu3 +HBXGU0G8eXqhjMSKc4Kc8XI0Hwhcf14LDRSy2+LbTcAw2YmTbfkv9C1jj4SxzA/bJHXYdnHJlX w7soNoKWHUXkII8JwGFg2j9OkggH4Ofsgq5y0qfDNNvd6lkWPKdSqDM26Wgn8kJxOTvHqSyqIaJ jmxpNDQQYBgauLiI8UccRtFpwEicWcVu7a6t3fYwbIVZP0pzs/MeTQYUEJ8L6+0e+GoVZ9UMwL8 2DxbVSkpKIX5V/up5p6noFsdH7+K65fuLAv+8cvxGqp+WjQGN7hRWRxZQHaBWjpl4nXZywkkkWC Sya9FXOWbkxe1s0MxUkACn1IQQWNfMJndADDAs3Dc0/9r1/uY4Z7lYTQCF1cKiF9qDC7RMsQ392 /pQZ7uUB5XjJ2DoIrdT3YmmIuHReYNFDIE6Ox94RqpLTqCCam8uDwm+kD3OF/aTL2NdMRGqEcgX xjRbbUHHA7xWwL+hKHPu4myr5roPAu8pwRs5j7V09CjR15XYWe6V7zaMmzkAhPjjsC+/IOicmbt lZ4/jJUlBrrbJ8aVQ+QdgLh8m88fLRz/QZOmO92K5MzYqhq7g2suk3Ao2cZosGKpel6DaTz7x+B sJUj5fJ67hlczrw== 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 b3f8b86cb52f..2811ada6dec6 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -1266,13 +1267,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; @@ -1328,10 +1333,27 @@ static bool kick_pool(struct worker_pool *pool) * onto the same cache-hot worker (LIFO reuse). */ list_move(&worker->entry, &pool->kicked_list); - 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.54.0