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 46E8E421A13 for ; Tue, 26 May 2026 18:08:16 +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=1779818897; cv=none; b=CaxbW9xbnJNMApXBXaISeRH24LwTFQ7VZpHIGUudW3DCMIchOxtqFFeyd1DAPv5V0u6L7NfjdWmRCWF/1qx9gjMKogb7gENvqJk5oYuc5dkI6jmNfi5MxBat2t9ke4JGg5Lz8ru9fXwi1A1Jyk3jQ6TCT8mJXawr5noBuzCaJsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779818897; c=relaxed/simple; bh=Sjago3jtBD4V02QbFl9FT/wPn0DLucs0jnujBLxQpfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UriVCLjj79f8gXUdRWO+Rl+y0QuEa0ciayjXJIQlKa6Dr+sUD6fynVpzldERKEXEAyodvK1EUYQt7495y5Iz3hokbU9Gd7ZLQZW4qfYhFTG4kJ1x5o+WZ8j4bBQCQjNvOYfecWMezZx+sLIq8uhtBMo4eUs5hPpqc3HRbimfJTQ= 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=ivRcFh/H; 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="ivRcFh/H" 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=RBkg9puqnsn/oMOz1istftb0PbC8C6//C02CGsLpVh4=; b=ivRcFh/HrEpc8MfwQ2MhoGrgBQ qxCCcC3B5wBTZ++VN+DQ1hPe6ueJ6mt7JS4Bf+OSVWKcuSeuwBPGbeynkehTMx2s01GVOAMonNG/3 D+fYmPmd4T3GUekKIUttKv4rnhZrY42rT+8rvsefHsB/VxMG8f7cRFmAzSfPqJBlJADTj0t8rHSeF ZtujQZKHtihiZR7yWKu31UWEM9XC1EN7S1O/MNyAJj4H9Mvh+FQPeXWtO7IFWNHKC0hT+//ierSAD YnMpASUZAIQB5Hm6LkF3b/pcdeUwpVeAauvsgY7NP2oaPYyfhRXSuSrcc7bDQCVO4RT9fGuzBze7/ JLbdGHLQ==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wRwCI-002Wtw-0j; Tue, 26 May 2026 18:08:10 +0000 From: Breno Leitao Date: Tue, 26 May 2026 14:08:05 -0400 Subject: [PATCH 1/2] workqueue: split kick_pool() into kick_pool_pick() + wake_up_process() 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: <20260526-fastwake-v1-1-e69ad86923e6@debian.org> References: <20260526-fastwake-v1-0-e69ad86923e6@debian.org> In-Reply-To: <20260526-fastwake-v1-0-e69ad86923e6@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, bigeasy@linutronix.de, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=2794; i=leitao@debian.org; h=from:subject:message-id; bh=Sjago3jtBD4V02QbFl9FT/wPn0DLucs0jnujBLxQpfg=; b=owEBbQKS/ZANAwAKATWjk5/8eHdtAcsmYgBqFeGHr5sb7EUvoGFb3hUdkE4Tc5pAZ3h5OxsHm bqJVUlsKg+JAjMEAAEKAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCahXhhwAKCRA1o5Of/Hh3 bbseEACag5ZzGaYp227K16rVYxgWc50swp6k242DDEoisI9yGetbLmWLOhbsMTtJbp5/oivgcFb RP29dri+H21sF82Eo6OGFTmYYz4DIaXHgYGUeNmEH7J6Vp8uFNwvJkpo8KpybjUwmVqktBa2rcB ws6gd5hfr5/iy2Xa2fD8c7+PD5fXK+9S+QzUu27xeDteHW3MpXfOykeWkeO6WPx7VaSYmDSTmSs uKZwmEHhutEfRDmaOQ/AQ/X5hmHntieS7m6aADVhMPNqE/RpGTiVLFbzH8kEyA1eR7tRIBWJOYu DIphGMbn+PdBLl/jZ6GwvKzNwmS5HesQgViBbHPgm5Z42Fp9AYYZuxJZDPbyPwE0Gs6gEBKP43f 5dD97O54GD+/FpdhaQKuT8bBY7KWVEYZFTWdKviAAWu/K80wV+uROaFLb9N1Nxv/w59Hbq5nqEX M9hTVKBuYUguRzHyvqsgu9jF1A17c1wz9rD1WNRp7ZZBHbnStdEKpVxP+xAhoSOlxf4MXGd1h8I 8SbXiSmzi9rNdV+3JaD4IVqOZuxSuQuq59Tqml4TiahzwkGhfg+n++1vrCPEkmV3oc9tfz50IMU O38N5+HI/Df0Yik3zkPWwoXIoTba/jnNIE5ej8ToUTT8GW2ZsvkvU3Z3jth1s0Wm/1bEX3a3Vgr 9Lm4iZtsdERfzJQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Factor the worker-selection part of kick_pool() out into a new helper kick_pool_pick() that picks the worker to wake (and applies the wake_cpu / repatriation hint that requires pool->lock) but does not call wake_up_process() on it. It returns the task_struct of the worker to wake, or NULL when no wakeup is needed. kick_pool() becomes a thin wrapper that calls kick_pool_pick() and then wake_up_process() on the returned task, so all existing callers keep their current behavior. This is a pure refactor with no functional change. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 8df671066dd1..b788d7c44ac0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1258,13 +1258,21 @@ static void kick_bh_pool(struct worker_pool *pool) } /** - * kick_pool - wake up an idle worker if necessary + * kick_pool_pick - select a worker to wake up but defer the wakeup * @pool: pool to kick * - * @pool may have pending work items. Wake up worker if necessary. Returns - * whether a worker was woken up. + * Same selection logic as kick_pool() but returns the task that should be + * woken instead of calling wake_up_process() on it. The caller is + * responsible for calling wake_up_process() on the returned task (typically + * after dropping @pool->lock to shorten the locked region). + * + * Returns the task_struct to wake, or NULL if no wakeup is needed (e.g. the + * pool was empty, no idle worker was available, or it was a BH pool which + * was already kicked synchronously). + * + * Must be called with @pool->lock held. */ -static bool kick_pool(struct worker_pool *pool) +static struct task_struct *kick_pool_pick(struct worker_pool *pool) { struct worker *worker = first_idle_worker(pool); struct task_struct *p; @@ -1272,11 +1280,11 @@ static bool kick_pool(struct worker_pool *pool) lockdep_assert_held(&pool->lock); if (!need_more_worker(pool) || !worker) - return false; + return NULL; if (pool->flags & POOL_BH) { kick_bh_pool(pool); - return true; + return NULL; } p = worker->task; @@ -1310,6 +1318,22 @@ static bool kick_pool(struct worker_pool *pool) } } #endif + return p; +} + +/** + * 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 = kick_pool_pick(pool); + + if (!p) + return false; wake_up_process(p); return true; } -- 2.51.0