From: Marco Crivellari <marco.crivellari@suse.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Marco Crivellari <marco.crivellari@suse.com>
Subject: [PATCH 3/4] Workqueue: add WQ_PERCPU
Date: Sat, 3 May 2025 10:28:33 +0200 [thread overview]
Message-ID: <20250503082834.49413-4-marco.crivellari@suse.com> (raw)
In-Reply-To: <20250503082834.49413-1-marco.crivellari@suse.com>
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@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.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
next prev parent reply other threads:[~2025-05-03 8:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-03 8:28 [PATCH 0/4] Workqueue: rename system workqueue and " Marco Crivellari
2025-05-03 8:28 ` [PATCH 1/4] Workqueue: rename system_wq to system_percpu_wq Marco Crivellari
2025-05-03 8:28 ` [PATCH 2/4] Workqueue: rename system_unbound_wq to system_dfl_wq Marco Crivellari
2025-05-03 8:28 ` Marco Crivellari [this message]
2025-05-03 8:28 ` [PATCH 4/4] Workqueue: add WQ_PERCPU to every alloc_workqueue user Marco Crivellari
2025-05-05 6:56 ` Sebastian Andrzej Siewior
2025-05-05 9:22 ` Michal Hocko
2025-05-06 12:36 ` Frederic Weisbecker
2025-05-05 6:51 ` [PATCH 0/4] Workqueue: rename system workqueue and add WQ_PERCPU Sebastian Andrzej Siewior
2025-05-05 7:55 ` Marco Crivellari
2025-05-05 9:25 ` Michal Hocko
2025-05-06 7:53 ` Marco Crivellari
2025-05-05 23:39 ` Tejun Heo
2025-05-06 10:10 ` Marco Crivellari
2025-05-06 12:55 ` Frederic Weisbecker
2025-05-07 0:42 ` Tejun Heo
2025-05-07 12:04 ` Frederic Weisbecker
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=20250503082834.49413-4-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=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®