The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Marco Crivellari <marco.crivellari@suse.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Marco Crivellari <marco.crivellari@suse.com>,
	Michal Hocko <mhocko@suse.com>
Subject: [RFC PATCH 2/2] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq
Date: Tue,  5 May 2026 18:16:58 +0200	[thread overview]
Message-ID: <20260505161658.401998-3-marco.crivellari@suse.com> (raw)
In-Reply-To: <20260505161658.401998-1-marco.crivellari@suse.com>

There may be situations where local execution is not strictly needed for
correctness, but it is preferred for performance gains.

The Workqueue API currently do not distinguish between these two instances.

So add WQ_PREFER_PERCPU and system_prefer_percpu_wq, so that it would be the
first choice for workload who don't strictly need local execution for
correctness but only to maintain locality.

Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
 include/linux/workqueue.h | 7 +++++++
 kernel/workqueue.c        | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index f46379d937c9..be65df3dea5b 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -404,6 +404,7 @@ enum wq_flags {
 	 */
 	WQ_POWER_EFFICIENT	= 1 << 7,
 	WQ_PERCPU		= 1 << 8, /* bound to a specific cpu */
+	WQ_PREFER_PERCPU	= 1 << 9, /* prefer local cpu, but it doesn't require it */
 
 	__WQ_DESTROYING		= 1 << 15, /* internal: workqueue is destroying */
 	__WQ_DRAINING		= 1 << 16, /* internal: workqueue is draining */
@@ -460,6 +461,9 @@ enum wq_consts {
  *
  * system_bh[_highpri]_wq are convenience interface to softirq. BH work items
  * are executed in the queueing CPU's BH context in the queueing order.
+ *
+ * system_prefer_percpu_wq is for work items which prefer to be local but
+ * doesn't require it
  */
 extern struct workqueue_struct *system_wq; /* use system_percpu_wq, this will be removed */
 extern struct workqueue_struct *system_percpu_wq;
@@ -473,6 +477,7 @@ extern struct workqueue_struct *system_freezable_power_efficient_wq;
 extern struct workqueue_struct *system_bh_wq;
 extern struct workqueue_struct *system_bh_highpri_wq;
 extern struct workqueue_struct *system_dfl_long_wq;
+extern struct workqueue_struct *system_prefer_percpu_wq;
 
 void workqueue_softirq_action(bool highpri);
 void workqueue_softirq_dead(unsigned int cpu);
@@ -873,6 +878,8 @@ extern void __warn_flushing_systemwide_wq(void)
 	     _wq == system_freezable_wq) ||				\
 	    (__builtin_constant_p(_wq == system_power_efficient_wq) &&	\
 	     _wq == system_power_efficient_wq) ||			\
+	    (__builtin_constant_p(_wq == system_prefer_percpu_wq) &&	\
+	     _wq == system_prefer_percpu_wq) ||				\
 	    (__builtin_constant_p(_wq == system_freezable_power_efficient_wq) && \
 	     _wq == system_freezable_power_efficient_wq))		\
 		__warn_flushing_systemwide_wq();			\
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 5f747f241a5f..abba222a2d58 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -545,6 +545,8 @@ struct workqueue_struct *system_bh_highpri_wq;
 EXPORT_SYMBOL_GPL(system_bh_highpri_wq);
 struct workqueue_struct *system_dfl_long_wq __ro_after_init;
 EXPORT_SYMBOL_GPL(system_dfl_long_wq);
+struct workqueue_struct *system_prefer_percpu_wq __ro_after_init;
+EXPORT_SYMBOL_GPL(system_prefer_percpu_wq);
 
 static int worker_thread(void *__worker);
 static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
@@ -8029,11 +8031,13 @@ void __init workqueue_init_early(void)
 	system_bh_highpri_wq = alloc_workqueue("events_bh_highpri",
 					       WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 0);
 	system_dfl_long_wq = alloc_workqueue("events_dfl_long", WQ_UNBOUND, WQ_MAX_ACTIVE);
+	system_prefer_percpu_wq = alloc_workqueue("events_prefer_percpu", WQ_PREFER_PERCPU, 0);
 	BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq ||
 	       !system_unbound_wq || !system_freezable_wq || !system_dfl_wq ||
 	       !system_power_efficient_wq ||
 	       !system_freezable_power_efficient_wq ||
-	       !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq);
+	       !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq ||
+	       !system_prefer_percpu_wq);
 }
 
 static void __init wq_cpu_intensive_thresh_init(void)
-- 
2.53.0


  parent reply	other threads:[~2026-05-05 16:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 16:16 [RFC PATCH 0/2] Add queue_*() functions and prefer per-cpu workqueue and flag Marco Crivellari
2026-05-05 16:16 ` [RFC PATCH 1/2] workqueue: Add queue_*() functions, future schedule_*() replacement Marco Crivellari
2026-05-05 16:16 ` Marco Crivellari [this message]
2026-05-05 20:18 ` [RFC PATCH 0/2] Add queue_*() functions and prefer per-cpu workqueue and flag Tejun Heo
2026-05-06 13:40   ` Breno Leitao
2026-05-07 10:25     ` Marco Crivellari
2026-05-07 21:27       ` Tejun Heo
2026-05-08 12:09         ` Frederic Weisbecker
2026-05-08 15:11           ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260505161658.401998-3-marco.crivellari@suse.com \
    --to=marco.crivellari@suse.com \
    --cc=bigeasy@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox