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 1/2] workqueue: Add queue_*() functions, future schedule_*() replacement
Date: Tue,  5 May 2026 18:16:57 +0200	[thread overview]
Message-ID: <20260505161658.401998-2-marco.crivellari@suse.com> (raw)
In-Reply-To: <20260505161658.401998-1-marco.crivellari@suse.com>

This is part of the workqueue refactoring. More details can be found at
the Link below.

The acqual schedule_*() interface used to schedule work items on a
workqueue doesn't distinguish between bound and unbound workqueue but
only system_percpu_wq is used. So introduce the bound and unbound versions.

To better reflect what these function does, rename them with a cleaner and
unified interface dropping the "schedule_*()" prefix and using "queue_*()".

This change introduce:
- queue_{bound|unbound}_work() with the bound version being the future
  replacement of schedule_work()

- queue_bound_work_on() as future replacement of schedule_work_on()

- queue_bound_delayed_work() as future replacement of
  schedule_delayed_work()

- add queue_unbound_delayed_work() to offer the unbound version

- queue_bound_delayed_work_on() as future replacement of
  schedule_delayed_work_on()

A further step would be the conversion of all the users to the new
introduced interfaces and the migration, whether locality is not
strictly required, to the unbound version.

In a future relase cycle and once users are migrated, the schedule_*()
interface will be removed.

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 | 101 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index ab6cb70ca1a5..f46379d937c9 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -732,12 +732,26 @@ static inline bool mod_delayed_work(struct workqueue_struct *wq,
  * @work: job to be done
  *
  * This puts a job on a specific cpu
+ *
+ * Note: this function will be replaced by queue_bound_work_on()
  */
 static inline bool schedule_work_on(int cpu, struct work_struct *work)
 {
 	return queue_work_on(cpu, system_percpu_wq, work);
 }
 
+/**
+ * queue_bound_work_on - put work task on a specific cpu
+ * @cpu: cpu to put the work task on
+ * @work: job to be done
+ *
+ * This puts a job on a specific cpu
+ */
+static inline bool queue_bound_work_on(int cpu, struct work_struct *work)
+{
+	return queue_work_on(cpu, system_percpu_wq, work);
+}
+
 /**
  * schedule_work - put work task in per-CPU workqueue
  * @work: job to be done
@@ -751,12 +765,53 @@ static inline bool schedule_work_on(int cpu, struct work_struct *work)
  *
  * Shares the same memory-ordering properties of queue_work(), cf. the
  * DocBook header of queue_work().
+ *
+ * Note: this function will be removed in future, use schedule_{bound|unbound}_work()
+ * instead.
  */
 static inline bool schedule_work(struct work_struct *work)
 {
 	return queue_work(system_percpu_wq, work);
 }
 
+/**
+ * queue_bound_work - put work task in per-CPU workqueue
+ * @work: job to be done
+ *
+ * Returns %false if @work was already on the system per-CPU workqueue and
+ * %true otherwise.
+ *
+ * This puts a job in the system per-CPU workqueue if it was not already
+ * queued and leaves it in the same position on the system per-CPU
+ * workqueue otherwise.
+ *
+ * Shares the same memory-ordering properties of queue_work(), cf. the
+ * DocBook header of queue_work().
+ */
+static inline bool queue_bound_work(struct work_struct *work)
+{
+	return queue_work(system_percpu_wq, work);
+}
+
+/**
+ * queue_unbound_work - put work task in unbound workqueue
+ * @work: job to be done
+ *
+ * Returns %false if @work was already on the system unbound workqueue and
+ * %true otherwise.
+ *
+ * This puts a job in the system unbound workqueue if it was not already
+ * queued and leaves it in the same position on the system unbound
+ * workqueue otherwise.
+ *
+ * Shares the same memory-ordering properties of queue_work(), cf. the
+ * DocBook header of queue_work().
+ */
+static inline bool queue_unbound_work(struct work_struct *work)
+{
+	return queue_work(system_dfl_wq, work);
+}
+
 /**
  * enable_and_queue_work - Enable and queue a work item on a specific workqueue
  * @wq: The target workqueue
@@ -832,6 +887,9 @@ extern void __warn_flushing_systemwide_wq(void)
  *
  * After waiting for a given time this puts a job in the system per-CPU
  * workqueue on the specified CPU.
+ *
+ * Note: this function will be removed. Please use queue_delayed_bound_work_on()
+ * instead
  */
 static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
 					    unsigned long delay)
@@ -839,6 +897,21 @@ static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *dwork,
 	return queue_delayed_work_on(cpu, system_percpu_wq, dwork, delay);
 }
 
+/**
+ * queue_delayed_bound_work_on - queue work in per-CPU workqueue on CPU after delay
+ * @cpu: cpu to use
+ * @dwork: job to be done
+ * @delay: number of jiffies to wait
+ *
+ * After waiting for a given time this puts a job in the system per-CPU
+ * workqueue on the specified CPU.
+ */
+static inline bool queue_delayed_bound_work_on(int cpu, struct delayed_work *dwork,
+					    unsigned long delay)
+{
+	return queue_delayed_work_on(cpu, system_percpu_wq, dwork, delay);
+}
+
 /**
  * schedule_delayed_work - put work task in per-CPU workqueue after delay
  * @dwork: job to be done
@@ -853,6 +926,34 @@ static inline bool schedule_delayed_work(struct delayed_work *dwork,
 	return queue_delayed_work(system_percpu_wq, dwork, delay);
 }
 
+/**
+ * queue_delayed_bound_work - put work task in per-CPU workqueue after delay
+ * @dwork: job to be done
+ * @delay: number of jiffies to wait or 0 for immediate execution
+ *
+ * After waiting for a given time this puts a job in the system per-CPU
+ * workqueue.
+ */
+static inline bool queue_delayed_bound_work(struct delayed_work *dwork,
+					 unsigned long delay)
+{
+	return queue_delayed_work(system_percpu_wq, dwork, delay);
+}
+
+/**
+ * queue_delayed_unbound_work - put work task in unbound workqueue after delay
+ * @dwork: job to be done
+ * @delay: number of jiffies to wait or 0 for immediate execution
+ *
+ * After waiting for a given time this puts a job in the system unbound
+ * workqueue.
+ */
+static inline bool queue_delayed_unbound_work(struct delayed_work *dwork,
+					 unsigned long delay)
+{
+	return queue_delayed_work(system_dfl_wq, dwork, delay);
+}
+
 #ifndef CONFIG_SMP
 static inline long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
 {
-- 
2.53.0


  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 ` Marco Crivellari [this message]
2026-05-05 16:16 ` [RFC PATCH 2/2] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq Marco Crivellari
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-2-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