Add new workqueue wrapper and enqueue on cpu functions
v4 cover Add new workqueue wrapper and enqueue on cpu functions
Hi,
Recently the workqueue code has been changed introducing two new workqueue, system_percpu_wq and system_dfl_wq, as a future replacement for system_wq and system_unbound_wq respectively.
The change has been introduced by:
'commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")'
The old workqueue(s) will be removed in a next release cycle.
=== Introduced Changes by this series ===
1) [P 1] Add wrapper for the new system_dfl_wq
- This change introduce two new Rust functions in order to add a wrapper for
the new wq(s) defined in the C code.
2) [P 2] Add wrapper for system_percpu_wq and two new functions
- The new functions added are enqueue_cpu() and enqueue_delayed_cpu() and
are accepting a u32 parameter, the id of the CPU on which the work should be scheduled on.
Thanks!
---
Changes in v4:
- two new function added in the Queue implementation:
* enqueue_cpu()
* enqueue_delayed_cpu()
These functions receive a u32 CPU id in order to schedule work on that CPU.
More info can be found in the v3 discussion:
https://lore.kernel.org/all/CAAofZF6jcCAdDjRp-7w7+_ZgOG4k3apxbSiKvGoUDVf5hw0GhA@mail.gmail.com/
Changes in v3:
- added a proper comment documenting the new added functions.
Changes in v2:
- added system_percpu() and system_dfl() in order to use the new wq defined in the C code.
- fixed misleading paragraph in the commit log (no warnings are currently present).
Marco Crivellari (2):
rust: add system_dfl() around the new system_dfl_wq
rust: add system_percpu() and per-cpu enqueue functions
rust/kernel/sync/completion.rs | 2 +- rust/kernel/workqueue.rs | 110 +++++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 7 deletions(-)
Signature · 1 line
2.52.0
PATCH v4 1/2 rust: add system_dfl() around the new system_dfl_wq
The C code defines 2 new workqueues: system_percpu_wq and system_dfl_wq, respectively the futures replacement for system_wq and system_unbound_wq.
This change introduce system_dfl(), that use the new system_dfl_wq.
system_unbound_wq will be replaced in a future release cycle and should not be used.
--- rust/kernel/workqueue.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
rust/kernel/workqueue.rs +14 -0
@@ -968,11 +968,25 @@ pub fn system_long() -> &'static Queue {/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items /// are executed immediately as long as `max_active` limit is not reached and resources are /// available. +/// +/// Note: `system_unbound_wq` will be removed in a future release cycle. Use [`system_dfl_wq`] instead. pub fn system_unbound () -> &'staticQueue {// SAFETY: `system_unbound_wq` is a C global, always available. unsafe {Queue ::from_raw (bindings::system_unbound_wq) } } +/// Returns the system unbound work queue (`system_dfl_wq`). +/// +/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items +/// are executed immediately as long as `max_active` limit is not reached and resources are +/// available. +/// +/// Note: `system_dfl_wq` will replace in a future release cycle [`system_unbound_wq`]. +pub fn system_dfl () -> &'staticQueue { +// SAFETY: `system_dfl_wq` is a C global, always available. +unsafe {Queue ::from_raw (bindings::system_dfl_wq) } +} +/// Returns the system freezable work queue (`system_freezable_wq`). /// /// It is equivalent to the one returned by [`system`] except that it's freezable.
Signature · 1 line
2.52.0
Re: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
Quoted 10 lines · Marco Crivellari
The C code defines 2 new workqueues:
system_percpu_wqandsystem_dfl_wq, respectively the futures replacement forsystem_wqandsystem_unbound_wq.This change introduce
system_dfl(), that use the newsystem_dfl_wq.
system_unbound_wqwill be replaced in a future release cycle and should not be used.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>
Re: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
In reply to Marco CrivellariQuoted 19 lines · Marco Crivellari
The C code defines 2 new workqueues:
system_percpu_wqandsystem_dfl_wq, respectively the futures replacement forsystem_wqandsystem_unbound_wq.This change introduce
system_dfl(), that use the newsystem_dfl_wq.
system_unbound_wqwill be replaced in a future release cycle and should not be used.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>--- rust/kernel/workqueue.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+)rust/kernel/workqueue.rs +0
-0
rust/kernel/workqueue.rs pub fn system_long() -> &'static Queue { · line 976
Quoted 9 lines
rust/kernel/workqueue.rs +2
-0@@ -968,11 +968,25 @@ pub fn system_long() -> &'static Queue {/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items /// are executed immediately as long as `max_active` limit is not reached and resources are /// available. +/// +/// Note: `system_unbound_wq` will be removed in a future release cycle. Use [`system_dfl_wq`] instead. pub fn system_unbound () -> &'staticQueue {// SAFETY: `system_unbound_wq` is a C global, always available. unsafe {Queue ::from_raw (bindings::system_unbound_wq) } }
Hi Marco,
The Rust change looks good to me.
Is there any reason that we cannot migrate the user early by just returning system_dfl_wq inside system_unbound? (I guess the question also applies on why system_unbound_wq cannot be the same pointer as system_dfl_wq).
Also, I feel that dfl is not a very intuitive name. I searched the list and the commit history for a while and cannot find the exact explaination on what it means? Does it mean "default" or something else?
Best,
Gary
Quoted 16 lines
rust/kernel/workqueue.rs +12
-0+/// Returns the system unbound work queue (`system_dfl_wq`). +/// +/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items +/// are executed immediately as long as `max_active` limit is not reached and resources are +/// available. +/// +/// Note: `system_dfl_wq` will replace in a future release cycle [`system_unbound_wq`]. +pub fn system_dfl () -> &'staticQueue { +// SAFETY: `system_dfl_wq` is a C global, always available. +unsafe {Queue ::from_raw (bindings::system_dfl_wq) } +} +/// Returns the system freezable work queue (`system_freezable_wq`). /// /// It is equivalent to the one returned by [`system`] except that it's freezable.
Re: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
Quoted 5 lines · Gary Guo
Hi Marco,
The Rust change looks good to me.
Reviewed-by Gary Guo <[email protected]>
Hi Gary,
Thanks!
Quoted 3 lines
Is there any reason that we cannot migrate the user early by just returning
system_dfl_wqinsidesystem_unbound? (I guess the question also applies on whysystem_unbound_wqcannot be the same pointer assystem_dfl_wq).
The 1st version was like you mentioned, both for system() and system_unbound(). It's one of the request made by Alice:
https://lore.kernel.org/all/[email protected]/
To me it was ok to change with her suggestion. :-)
Quoted 3 lines
Also, I feel that
dflis not a very intuitive name. I searched the list and the commit history for a while and cannot find the exact explaination on what it means? Does it mean "default" or something else?
Yes, "dfl" means "default".
There is a huge Workqueue API refactoring. We also noticed many subsystem used system_wq (the - now - old per-cpu workqueue) but many of them didn't really benefit from per-cpu work.
So the idea was, at first, to refactor of the workqueue name changing system_wq to system_percpu_wq and system_unbound_wq to system_dfl_wq, to make clear this should be the default choice.
If you want other details check this discussion:
https://lore.kernel.org/all/[email protected]/
Thank you!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Gary Guo
maintainerRe: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
Quoted 26 lines · Marco Crivellari
Quoted 5 lines · Gary Guo
Hi Marco,
The Rust change looks good to me.
Reviewed-by Gary Guo <[email protected]>Hi Gary,
Thanks!
Quoted 3 lines
Is there any reason that we cannot migrate the user early by just returning
system_dfl_wqinsidesystem_unbound? (I guess the question also applies on whysystem_unbound_wqcannot be the same pointer assystem_dfl_wq).The 1st version was like you mentioned, both for
system()andsystem_unbound(). It's one of the request made by Alice:https://lore.kernel.org/all/[email protected]/
To me it was ok to change with her suggestion. :-)
Quoted 3 lines
Also, I feel that
dflis not a very intuitive name. I searched the list and the commit history for a while and cannot find the exact explaination on what it means? Does it mean "default" or something else?
Quoted 5 lines
Yes, "dfl" means "default".
There is a huge Workqueue API refactoring. We also noticed many subsystem used
system_wq(the - now - old per-cpu workqueue) but many of them didn't really benefit from per-cpu work.
Yeah, I appreciate the system -> system_percpu renaming which does make it clear that this is percpu. However I think system_unbound_wq to system_dfl_wq is somewhat less clear?
What is a problem to leave this still being system_unbound? User would need to make a choice, and unless they know they want percpu it feels like natural that they're going to use the unbounded option.
Best,
Gary
Quoted 10 lines
So the idea was, at first, to refactor of the workqueue name changing
system_wqtosystem_percpu_wqandsystem_unbound_wqtosystem_dfl_wq, to make clear this should be the default choice.If you want other details check this discussion:
https://lore.kernel.org/all/[email protected]/
Thank you!
Re: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
Quoted 9 lines · Gary Guo
[...]
Yeah, I appreciate the system ->system_percpurenaming which does make it clear that this is percpu. However I thinksystem_unbound_wqtosystem_dfl_wqis somewhat less clear?What is a problem to leave this still being
system_unbound? User would need to make a choice, and unless they know they wantpercpuit feels like natural that they're going to use the unbounded option.
Hi Gary,
Yes, it feels natural, as you said. But there are cases where system_wq has been used,
maybe because the name felt like a "default system workqueue", or for other reasons.
There are currently some places where we have already converted from system_wq tosystem_dfl_wq, because they don't need to be per-cpu. So I think that suggesting the
use of an unbound workqueue as default it could work better. :-) Then whoever really needs to be per-cpu, would use the system_percpu_wq.
BTW, few examples about the mentioned conversions:
"ASoC: SDCA: Replace use of system_wq with system_dfl_wq"
https://lore.kernel.org/all/[email protected]/
"Input: gpio_keys - replace use of system_wq with system_dfl_wq"
https://lore.kernel.org/all/[email protected]/
"regulator: irq_helper: replace use of system_wq with system_dfl_wq"
https://lore.kernel.org/all/[email protected]/
"regulator: qcomm-labibb: replace use of system_wq with system_dfl_wq"
https://lore.kernel.org/all/[email protected]/
We're going to have more changes like the above.
Also noticed that system_unbound_wq has been already renamed to system_dfl_wq in about ~120 places in the code. :-)
Thanks!
--
Marco Crivellari
L3 Support Engineer
Alice Ryhl
maintainerRe: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
In reply to Gary GuoQuoted 3 lines · Gary Guo
Is there any reason that we cannot migrate the user early by just returning
system_dfl_wqinsidesystem_unbound? (I guess the question also applies on whysystem_unbound_wqcannot be the same pointer assystem_dfl_wq).
I think this is confusing. Let's just rename it here and update the callers. Otherwise Rust gets out of sync with C naming-wise.
Quoted 3 lines
Also, I feel that
dflis not a very intuitive name. I searched the list and the commit history for a while and cannot find the exact explaination on what it means? Does it mean "default" or something else?
This I agree with. dfl is not a good name. Let's at least call it "default" or "unbound" or whatever.
Alice
Re: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
Quoted 9 lines · Alice Ryhl
Quoted 3 lines · Gary Guo
Is there any reason that we cannot migrate the user early by just returning
system_dfl_wqinsidesystem_unbound? (I guess the question also applies on whysystem_unbound_wqcannot be the same pointer assystem_dfl_wq).I think this is confusing. Let's just rename it here and update the callers. Otherwise Rust gets out of sync with C naming-wise.
Quoted 6 lines
Quoted 3 lines
Also, I feel that
dflis not a very intuitive name. I searched the list and the commit history for a while and cannot find the exact explaination on what it means? Does it mean "default" or something else?This I agree with. dfl is not a good name. Let's at least call it "default" or "unbound" or whatever.
Ok, I will rename system_dfl() to system_default() (to keep consistent the name with C).
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
kernel test robot
build botRe: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq
In reply to Marco Crivellarikernel test robot noticed the following build warnings:
Hi Marco,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rust/rust-next]
[also build test WARNING on linus/master v6.19-rc8 next-20260203] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Marco-Crivellari/rust-add-system_dfl-around-the-new-system_dfl_wq/20260203-233415 base: https://github.com/Rust-for-Linux/linux rust-next patch link: https://lore.kernel.org/r/20260203152818.317806-2-marco.crivellari%40suse.com patch subject: [PATCH v4 1/2] rust: add system_dfl() around the new system_dfl_wq config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260204/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260204/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> warning: unresolved link to `system_dfl_wq`
--> rust/kernel/workqueue.rs:972:80
|
972 | /// Note: system_unbound_wq will be removed in a future release cycle. Use [system_dfl_wq] instead.
| ^^^^^^^^^^^^^ no item named system_dfl_wq in scope
|
= help: to escape [ and ] characters, add '\' before them like \[ or \]
= note: #[warn(rustdoc::broken_intra_doc_links)] on by default
--
>> warning: unresolved link to `system_unbound_wq`
--> rust/kernel/workqueue.rs:984:68
|
984 | /// Note: system_dfl_wq will replace in a future release cycle [system_unbound_wq].
| ^^^^^^^^^^^^^^^^^ no item named system_unbound_wq in scope
|
= help: to escape [ and ] characters, add '\' before them like \[ or \]
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 2/2 rust: add system_percpu() and per-cpu enqueue functions
In reply to Marco CrivellariThe C code defines 2 new workqueues: system_percpu_wq and system_dfl_wq, respectively the futures replacement for system_wq and system_unbound_wq.
This change introduce system_percpu(), that use the new system_percpu_wq.
In order to enqueue on a specific CPU, two new functions have been added to the Queue implementation:
enqueue_cpu() - that receive a u32 CPU id as 2nd argument
enqueue_delayed_cpu() - that receive a u32 CPU id as 3rd argument
system_wq (and so workqueue::system()) will be removed in a future release cycle and should not be used.
--- rust/kernel/sync/completion.rs | 2 +- rust/kernel/workqueue.rs | 96 +++++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 7 deletions(-)
rust/kernel/sync/completion.rs +1 -1
@@ -38,7 +38,7 @@/// done <- Completion::new(), /// }), GFP_KERNEL)?; /// -/// let _ = workqueue::system().enqueue(this.clone()); +/// let _ = workqueue::system_percpu().enqueue(this.clone()); /// /// Ok(this) /// }
rust/kernel/workqueue.rs +90 -6
150 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v4 2/2] rust: add system_percpu() and per-cpu enqueue functions
Quoted 8 lines · Marco Crivellari
The C code defines 2 new workqueues:
system_percpu_wqandsystem_dfl_wq, respectively the futures replacement forsystem_wqandsystem_unbound_wq.This change introduce
system_percpu(), that use the newsystem_percpu_wq.In order to enqueue on a specific CPU, two new functions have been added to the Queue implementation:
Quoted 8 lines
enqueue_cpu()- that receive a u32 CPU id as 2nd argument
enqueue_delayed_cpu()- that receive a u32 CPU id as 3rd argument
system_wq(and soworkqueue::system()) will be removed in a future release cycle and should not be used.Suggested-by Tejun Heo <[email protected]>Signed-off-by Marco Crivellari <[email protected]>
kernel test robot
build botRe: [PATCH v4 2/2] rust: add system_percpu() and per-cpu enqueue functions
In reply to Marco Crivellarikernel test robot noticed the following build errors:
Hi Marco,
kernel test robot noticed the following build errors:
[auto build test ERROR on rust/rust-next]
[also build test ERROR on linus/master v6.19-rc8 next-20260203] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Marco-Crivellari/rust-add-system_dfl-around-the-new-system_dfl_wq/20260203-233415 base: https://github.com/Rust-for-Linux/linux rust-next patch link: https://lore.kernel.org/r/20260203152818.317806-3-marco.crivellari%40suse.com patch subject: [PATCH v4 2/2] rust: add system_percpu() and per-cpu enqueue functions config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260204/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260204/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
PATH=/opt/cross/clang-20/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INFO PATH=/opt/cross/rustc-1.88.0-bindgen-0.72.1/cargo/bin:/opt/cross/clang-20/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/bin/timeout -k 100 12h /usr/bin/make KCFLAGS= -fno-crash-diagnostics -Wno-error=return-type -Wreturn-type -funsigned-char -Wundef -falign-functions=64 W=1 --keep-going LLVM=1 -j32 -C source O=/kbuild/obj/consumer/x86_64-rhel-9.4-rust ARCH=x86_64 SHELL=/bin/bash rustfmtcheck
make: Entering directory '/kbuild/src/consumer'
make[1]: Entering directory '/kbuild/obj/consumer/x86_64-rhel-9.4-rust'
>> Diff in rust/kernel/workqueue.rs:316:
// stay valid until we call the function pointer in the `work_struct`, so the access is ok.
unsafe {
w.__enqueue(move |work_ptr| {
- bindings::queue_work_on(
- cpu_id as ffi::c_int,
- queue_ptr,
- work_ptr,
- )
+ bindings::queue_work_on(cpu_id as ffi::c_int, queue_ptr, work_ptr)
})
}
}
Diff in rust/kernel/workqueue.rs:366:
/// This may fail if the work item is already enqueued in a workqueue.
///
/// The work item will be submitted on cpu_id.
- pub fn enqueue_delayed_cpu<W, const ID: u64>(&self, w: W, delay: Jiffies, cpu_id: u32) -> W::EnqueueOutput
+ pub fn enqueue_delayed_cpu<W, const ID: u64>(
+ &self,
+ w: W,
+ delay: Jiffies,
+ cpu_id: u32,
+ ) -> W::EnqueueOutput
where
W: RawDelayedWorkItem<ID> + Send + 'static,
{
>> Diff in rust/kernel/workqueue.rs:316:
// stay valid until we call the function pointer in the `work_struct`, so the access is ok.
unsafe {
w.__enqueue(move |work_ptr| {
- bindings::queue_work_on(
- cpu_id as ffi::c_int,
- queue_ptr,
- work_ptr,
- )
+ bindings::queue_work_on(cpu_id as ffi::c_int, queue_ptr, work_ptr)
})
}
}
Diff in rust/kernel/workqueue.rs:366:
/// This may fail if the work item is already enqueued in a workqueue.
///
/// The work item will be submitted on cpu_id.
- pub fn enqueue_delayed_cpu<W, const ID: u64>(&self, w: W, delay: Jiffies, cpu_id: u32) -> W::EnqueueOutput
+ pub fn enqueue_delayed_cpu<W, const ID: u64>(
+ &self,
+ w: W,
+ delay: Jiffies,
+ cpu_id: u32, + ) -> W::EnqueueOutput
where
W: RawDelayedWorkItem<ID> + Send + 'static,
{
make[2]: *** [Makefile:1871: rustfmt] Error 123
make[2]: Target 'rustfmtcheck' not remade because of errors. make[1]: Leaving directory '/kbuild/obj/consumer/x86_64-rhel-9.4-rust' make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'rustfmtcheck' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'rustfmtcheck' not remade because of errors.
make: Leaving directory '/kbuild/src/consumer'
--
>> warning: unresolved link to `system_percpu_wq`
--> rust/kernel/workqueue.rs:1013:72
|
1013 | /// Note: system_wq will be removed in a future release cycle. Use [system_percpu_wq] instead.
| ^^^^^^^^^^^^^^^^ no item named system_percpu_wq in scope
|
= help: to escape [ and ] characters, add '\' before them like \[ or \]
= note: #[warn(rustdoc::broken_intra_doc_links)] on by default
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki