Skip to contentSkip to conversation

Add new workqueue wrapper and enqueue on cpu functions

PATCH In review Marco Crivellari 4 participants 10 messages Feb 4 – Jul 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 706e833e9702..adbecdb2b3a9 100644
@@ -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() -> &'static Queue {
     // 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() -> &'static Queue {
+    // 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
maintainer
#2 lore raw

Re: [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_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 +2 -0
index 706e833e9702..adbecdb2b3a9 100644
@@ -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() -> &'static Queue {
     // 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() -> &'static Queue {
+    // 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

#3 lore raw

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
maintainer
#4 lore raw

Re: [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

#5 lore raw

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

#6 lore raw

Re: [PATCH v5 1/2] rust: add system_default() around the new system_dfl_wq

In reply to Alice Ryhl
Quoted 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:

https://lore.kernel.org/all/[email protected]/

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
#7 lore raw

PATCH v5 2/2 rust: add system_percpu() and per-cpu enqueue functions

In reply to Marco Crivellari

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_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
index c50012a940a3..ee6aa8f18507 100644
@@ -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
#8 lore raw
In reply to Marco Crivellari
Quoted 4 lines · Marco Crivellari

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 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

#9 lore raw

Hi,

Quoted 8 lines · Miguel Ojeda
Quoted 4 lines · Marco Crivellari

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.

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 ... rustfmt on the patchset).

Sure, I will do it for v6.

Thank you!

Signature · 3 lines
Marco Crivellari

SUSE Labs