Add new workqueue wrapper and enqueue on cpu functions
v5 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 v5:
- system_dfl() renamed to system_default()
- Cover letter v4:
https://lore.kernel.org/all/[email protected]/
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_default() 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 v5 1/2 rust: add system_default() 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_default(), 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_default () -> &'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
Alice Ryhl
maintainerRe: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq
Quoted 29 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_default(), 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 +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) } }
rust/kernel/workqueue.rs pub fn system_long() -> &'static Queue { · line 987
Quoted 10 lines
rust/kernel/workqueue.rs +10
-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_default () -> &'staticQueue { +// SAFETY: `system_dfl_wq` is a C global, always available. +unsafe {Queue ::from_raw (bindings::system_dfl_wq) }
I don't think we should use different naming than C.
Alice
Re: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq
Quoted 2 lines · Alice Ryhl
[...]
I don't think we should use different naming than C.
mmmh I think I misunderstood you here then:
https://lore.kernel.org/all/[email protected]/
What do you meant?
Thank you!
Signature · 3 lines
Marco Crivellari L3 Support Engineer
Alice Ryhl
maintainerRe: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq
Quoted 5 lines · Marco Crivellari
Quoted 2 lines · Alice Ryhl
[...]
I don't think we should use different naming than C.
Quoted 7 lines
mmmh I think I misunderstood you here then:
https://lore.kernel.org/all/[email protected]/
What do you meant?
Thank you!
I think the ideal would be to rename it to default in C too. :)
Alice
Re: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq
Quoted 1 line · Alice Ryhl
I think the ideal would be to rename it to default in C too. :)
| $ git grep system_dfl_wq next-20260204 | wc -l | 115
Quoted 1 line
Alice
Sebastian
Re: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq
In reply to Alice RyhlQuoted 12 lines · Alice Ryhl
Quoted 9 lines · Marco Crivellari
Quoted 2 lines · Alice Ryhl
[...]
I don't think we should use different naming than C.mmmh I think I misunderstood you here then:
Quoted 7 lines
Quoted 3 lines
What do you meant?
Thank you!
I think the ideal would be to rename it to default in C too. :)
Alice
Hi,
While I respect your preference for a different name there it doesn't seem to be any urge for that in the C side of the kernel. So I would really stick with what we have there.
If you have any specific naming preferences for the Rust side, please articulate them, I am more than happy to follow but asking to go with yet another rename seems out of order.
Thanks!
Signature · 3 lines
Marco Crivellari SUSE Labs
PATCH v5 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
Quoted 4 lines · Marco Crivellari
Recently the workqueue code has been changed introducing two new workqueue,
system_percpu_wqandsystem_dfl_wq, as a future replacement forsystem_wqandsystem_unbound_wqrespectively.
The C side merged the warning, and now this triggers in on of our doctests:
workqueue: work func _R...sync_completion_rs_18... enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.
Should we move forward with this, then?
(By the way, please run make ... rustfmt on the patchset).
Thanks!
Cheers,
Miguel
Hi,
Quoted 8 lines · Miguel Ojeda
Quoted 4 lines · Marco Crivellari
Recently the workqueue code has been changed introducing two new workqueue,
system_percpu_wqandsystem_dfl_wq, as a future replacement forsystem_wqandsystem_unbound_wqrespectively.
Quoted 6 lines
The C side merged the warning, and now this triggers in on of our doctests:
workqueue: work func _R...sync_completion_rs_18... enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.
Should we move forward with this, then?
Sounds good to me. Would version 5 be fine?
Do you have other suggestions?
Quoted 1 line
(By the way, please run
make ... rustfmton the patchset).
Sure, I will do it for v6.
Thank you!
Signature · 3 lines
Marco Crivellari SUSE Labs