[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250503082834.49413-4-marco.crivellari@suse.com>
Date: Sat, 3 May 2025 10:28:33 +0200
From: Marco Crivellari <marco.crivellari@...e.com>
To: linux-kernel@...r.kernel.org
Cc: Tejun Heo <tj@...nel.org>,
Lai Jiangshan <jiangshanlai@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Frederic Weisbecker <frederic@...nel.org>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Marco Crivellari <marco.crivellari@...e.com>
Subject: [PATCH 3/4] Workqueue: add WQ_PERCPU
Currently alloc_workqueue() treats all queues as per-CPU by default,
while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues,
allowing the scheduler to place worker threads where they’re needed and
reducing noise when CPUs are isolated.
This patch adds a new WQ_PERCPU flag to explicitly request the legacy
per-CPU behavior. Both flags coexist for one release cycle to allow
callers to transition their calls.
Once migration is complete, WQ_UNBOUND can be removed and unbound
will become the implicit default.
Suggested-by: Tejun Heo <tj@...nel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@...e.com>
---
include/linux/workqueue.h | 1 +
kernel/workqueue.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 9dea10a09cc5..697aabbd6dcb 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -374,6 +374,7 @@ enum wq_flags {
WQ_HIGHPRI = 1 << 4, /* high priority */
WQ_CPU_INTENSIVE = 1 << 5, /* cpu intensive workqueue */
WQ_SYSFS = 1 << 6, /* visible in sysfs, see workqueue_sysfs_register() */
+ WQ_PERCPU = 1 << 7, /* bound to a specific cpu */
/*
* Per-cpu workqueues are generally preferred because they tend to
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 98cbfc685f39..0a088a2bd6a3 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5670,6 +5670,13 @@ static struct workqueue_struct *__alloc_workqueue(const char *fmt,
return NULL;
}
+ /* one among WQ_UNBOUND and WQ_PERCPU should always be present */
+ if (WARN_ON_ONCE(flags & WQ_UNBOUND && flags & WQ_PERCPU))
+ return NULL;
+
+ if (WARN_ON_ONCE(!(flags & WQ_UNBOUND) && !(flags & WQ_PERCPU)))
+ return NULL;
+
/* see the comment above the definition of WQ_POWER_EFFICIENT */
if ((flags & WQ_POWER_EFFICIENT) && wq_power_efficient)
flags |= WQ_UNBOUND;
--
2.49.0
Powered by blists - more mailing lists