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 230262D63F8 for ; Wed, 24 Jun 2026 11:47:59 +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=1782301681; cv=none; b=q4IKyH3gSwEL28uy/zjq8oJcqIyjlHk7/VHbZLXhscqkMBxq52Bq4HWXdNL75V6bwLplzQqJZYPcWRLx1uBWuxvxbUXBAB4sn40rt/JLG0RY0zmWUYxHeiUY1PYHWIVz8JoqXSOmYdiLsNMev2fxei0ssvl/RkCEm/DnUmtOphI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782301681; c=relaxed/simple; bh=c+4LbJ3gMx9qJUlSsDNFD9XxCuN5iCHFGns/3U6IpxU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QqyqnUQiMCsBFykGhb9Dwp4l/vuS0wUpCHEBrK62Ez6zll/uioxL5WSRAa9m2zcFXx478o1osn4VGpJukUIbp5swCDLQUGSTcaKXpahUtCO0Y+kONl1SMNE5C6Pnhk+pLv8M8r/tBXTJF3147lfBWysAi1lc7ZrKy471hV8sLKU= 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=m4TWoEJz; 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="m4TWoEJz" 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=m4TWoEJzbFREiJkVpJBtR3y0Uv VRxk6NBfoh0O10hXiioKrQkSuKacMarqbbTyEPHr4UTmTNXGfLO/jim+UTVOU+O8uEgLGfNoYcw0V Nbk7Bj7cQmfyoVBn6b4gWaIXpkr+8RU1O5g85c0q+Hbu5GP5Ag0HMPTVQvMhagcMllAa8+At8/T7d Cm18ydej9hsTgfHrmFGPtScOrMEdU3Nnr2s65tSHmLarX6YChbDVFfXbK25+D3/jYI/RkEpvjatZS UAhc7MdTDxFGP8J4JwYh500x01eDvva52gXJDD1HrfN1GgN4IUQSTnrzlG/O2f34ukiQZ92M3e4Rx /BqlqKyQ==; 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 1wcM5E-002Oxj-27; Wed, 24 Jun 2026 11:47:56 +0000 From: Breno Leitao Date: Wed, 24 Jun 2026 04:47:39 -0700 Subject: [PATCH v4 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: <20260624-fastwake-v4-1-7b6d7b494a44@debian.org> References: <20260624-fastwake-v4-0-7b6d7b494a44@debian.org> In-Reply-To: <20260624-fastwake-v4-0-7b6d7b494a44@debian.org> To: Tejun Heo , Lai Jiangshan , bigeasy@linutronix.de 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=2586; i=leitao@debian.org; h=from:subject:message-id; bh=c+4LbJ3gMx9qJUlSsDNFD9XxCuN5iCHFGns/3U6IpxU=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqO8Pkro+oY0VnH8/UK2LFfEQwewR632z+kSyzs dCSlEQ++muJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCajvD5AAKCRA1o5Of/Hh3 bdQuD/9TCD4yJjmDCthWm+H9tLo1bRk2lVF3a2CFXBB7fnpsnIE7FpnS351t46r7Wbrv/jM0Fie 8yDxKL5YLyDzSuhnYL7VbgltPjG0aw4uwlokSX5qNWgKG09t8yBxVOPzlD/eYjdenIjhmaqHNlo cH0kDXKGMqxjaRuutON3H9wpCEdPyt8x6ogik8IGb4XSaikJwOPBCfRV66W5Sd+sWyMvij3lsLX N/ApGN51yBCfsUIdQPpIxeFto9AsDU8vs80Lg7951CMGj2zKw5uDb5piFPgrtziJUoZectUKNtZ Al8GyylPTAh0lWx67/YNwlCeolXeIh1FSVJ+rw6c7eWvG+NsiWoitdEsXzH30xBnitdVo8BAFn/ 3qJVzWb7AG15Q8uVnyL8PdIxgCgMjiJIFyaJGX7qUw/rcg2Kpp6vF/3iKbD6rz0VM6fUZ3OokJQ 4g+zAkGWzc84ro1f4NoqJCE7WQIsHkLUmTL4Xfj+BsOnDOcY+xodvIclz2Gtk59VkG8gpX8PtwL 7dHJaxSneccQ0dHWYYi89y6Taod/VuHwLHgGW5Yc81AXhAt/HPkuwqsGCTYSN30OFTFQGBeM3yB QV+SGQoMh0QE8zC7gwyuzEA6w2dnHjjaOzYAmMrFVMkQX3JPWzJHV2Ouzh6mMmQzLAmg2I5s6sw L0C0ftBtX5dsTTg== 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