rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq
Subsystems (6)
Alice Ryhl
maintainerPATCH 1/1 rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq
From: Danilo Krummrich <[email protected]>
system_wq is deprecated and triggers a runtime warning:
[ 0.857414] workqueue: work func ...WorkItemPointerKy0_E3runB7_ enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.Replace system() with system_percpu() and system_dfl(), to match the previous behavior of the deprecated system() and convert doc examples and tests to system_dfl().
---
This patch was previously sent as part of other workqueue series [1][2]. However it's a fix that is independent of those series, so it's sent on its own here.
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
Changes since [2]:
- Rebase on v7.3-rc7 and also convert the new SpinLockIrq KUnit test, which calls workqueue::system() and otherwise fails to build.
- Add Fixes: tag for the commit that made system_wq warn.
- Collect Reviewed-by from Daniel.
--- Documentation/rust/testing.rst | 2 +- Documentation/translations/zh_CN/rust/testing.rst | 2 +- drivers/android/binder/process.rs | 4 +-- rust/kernel/sync/completion.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 2 +- rust/kernel/workqueue.rs | 42 +++++++++++++++-------- 6 files changed, 33 insertions(+), 21 deletions(-)
Documentation/rust/testing.rst +1 -1
@@ -97,7 +97,7 @@ operator are also supported as usual, e.g.: /// ``` /// # use kernel::{spawn_work_item, workqueue}; - /// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?; + /// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?; /// # Ok::<(), Error>(()) /// ```
Documentation/translations/zh_CN/rust/testing.rst +1 -1
@@ -93,7 +93,7 @@ KUnit 测试即文档测试 /// ``` /// # use kernel::{spawn_work_item, workqueue}; - /// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?; + /// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?; /// # Ok::<(), Error>(()) /// ```
drivers/android/binder/process.rs +2 -2
@@ -1728,7 +1728,7 @@ pub(crate) fn release(this: Arc<Process>, _file: &File) {if should_schedule {// Ignore failures to schedule to the workqueue. Those just mean that we're already // scheduled for execution. -let _ = workqueue::system ().enqueue (this); +let _ = workqueue::system_percpu ().enqueue (this); }drop (binderfs_file);
@@ -1745,7 +1745,7 @@ pub(crate) fn flush(this: ArcBorrow<'_, Process>) -> Result {if should_schedule {// Ignore failures to schedule to the workqueue. Those just mean that we're already // scheduled for execution. -let _ = workqueue::system ().enqueue (Arc ::from (this)); +let _ = workqueue::system_percpu ().enqueue (Arc ::from (this)); }Ok (()) }
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_dfl().enqueue(this.clone()); /// /// Ok(this) /// }
rust/kernel/sync/lock/spinlock.rs +1 -1
@@ -450,7 +450,7 @@ fn run(this: Arc<Self>) {fn spinlock_irq_condvar () ->Result {let testdata =Test ::new ()?; -let _ = workqueue::system ().enqueue (testdata.clone ()); +let _ = workqueue::system_dfl ().enqueue (testdata.clone ());// Let the updater know when we're ready to wait let mut state = testdata.state.lock ();
rust/kernel/workqueue.rs +27 -15
107 lines not on this page · raw message
---
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
change-id: 20261013-rust-workqueue-system-fix-5f9020c90f27
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Gary Guo
maintainerQuoted 9 lines · Alice Ryhl
From: Danilo Krummrich <[email protected]>
system_wqis deprecated and triggers a runtime warning:[ 0.857414] workqueue: work func ...WorkItemPointerKy0_E3runB7_ enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.Replace
system()withsystem_percpu()andsystem_dfl(), to match the previous behavior of the deprecatedsystem()and convert doc examples and tests tosystem_dfl().
system_unbound() is also deprecated (replaced by system_dfl(). It appears to have no users, so we should remove it in the same patch.
Best,
Gary
Quoted 26 lines
Fixes 64d8eae3f895 ("workqueue: Add warnings and fallback if system_{unbound}_wq is used")Signed-off-by Danilo Krummrich <[email protected]>Reviewed-by Daniel Almeida <[email protected]>Signed-off-by Alice Ryhl <[email protected]>---
This patch was previously sent as part of other workqueue series [1][2]. However it's a fix that is independent of those series, so it's sent on its own here.[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]Changes since [2]:
- Rebase on v7.3-rc7 and also convert the new SpinLockIrq KUnit test, which callsworkqueue::system()and otherwise fails to build.
- Add Fixes: tag for the commit that madesystem_wqwarn.
- Collect Reviewed-by from Daniel.--- Documentation/rust/testing.rst | 2 +- Documentation/translations/zh_CN/rust/testing.rst | 2 +- drivers/android/binder/process.rs | 4 +-- rust/kernel/sync/completion.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 2 +- rust/kernel/workqueue.rs | 42 +++++++++++++++-------- 6 files changed, 33 insertions(+), 21 deletions(-)
Quoted 6 lines · Alice Ryhl
From: Danilo Krummrich <[email protected]>
system_wqis deprecated and triggers a runtime warning:[ 0.857414] workqueue: work func ...WorkItemPointerKy0_E3runB7_ enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.
Quoted 8 lines
Replace
system()withsystem_percpu()andsystem_dfl(), to match the previous behavior of the deprecatedsystem()and convert doc examples and tests tosystem_dfl().Fixes 64d8eae3f895 ("workqueue: Add warnings and fallback if system_{unbound}_wq is used")Signed-off-by Danilo Krummrich <[email protected]>Reviewed-by Daniel Almeida <[email protected]>Signed-off-by Alice Ryhl <[email protected]>
FWIW:
Regards,
Boqun
Quoted 14 lines
---
This patch was previously sent as part of other workqueue series [1][2]. However it's a fix that is independent of those series, so it's sent on its own here.[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]Changes since [2]:
- Rebase on v7.3-rc7 and also convert the new SpinLockIrq KUnit test, which callsworkqueue::system()and otherwise fails to build.
- Add Fixes: tag for the commit that madesystem_wqwarn.
- Collect Reviewed-by from Daniel.
---
[...]
Alice Ryhl
maintainerQuoted 6 lines · Gary Guo
Quoted 4 lines · Alice Ryhl
From: Danilo Krummrich <[email protected]>
system_wqis deprecated and triggers a runtime warning:
Quoted 8 lines
Quoted 5 lines
[ 0.857414] workqueue: work func ...WorkItemPointerKy0_E3runB7_ enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.Replace
system()withsystem_percpu()andsystem_dfl(), to match the previous behavior of the deprecatedsystem()and convert doc examples and tests tosystem_dfl().
system_unbound()is also deprecated (replaced bysystem_dfl(). It appears to have no users, so we should remove it in the same patch.
I will resend with that change tomorrow.
Alice
Quoted 41 lines · Alice Ryhl
From: Danilo Krummrich <[email protected]>
system_wqis deprecated and triggers a runtime warning:[ 0.857414] workqueue: work func ...WorkItemPointerKy0_E3runB7_ enqueued on deprecated workqueue. Use system_{percpu|dfl}_wq instead.Replace
system()withsystem_percpu()andsystem_dfl(), to match the previous behavior of the deprecatedsystem()and convert doc examples and tests tosystem_dfl().Fixes 64d8eae3f895 ("workqueue: Add warnings and fallback if system_{unbound}_wq is used")Signed-off-by Danilo Krummrich <[email protected]>Reviewed-by Daniel Almeida <[email protected]>Signed-off-by Alice Ryhl <[email protected]>---
This patch was previously sent as part of other workqueue series [1][2]. However it's a fix that is independent of those series, so it's sent on its own here.[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]Changes since [2]:
- Rebase on v7.3-rc7 and also convert the new SpinLockIrq KUnit test, which callsworkqueue::system()and otherwise fails to build.
- Add Fixes: tag for the commit that madesystem_wqwarn.
- Collect Reviewed-by from Daniel.--- Documentation/rust/testing.rst | 2 +- Documentation/translations/zh_CN/rust/testing.rst | 2 +- drivers/android/binder/process.rs | 4 +-- rust/kernel/sync/completion.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 2 +- rust/kernel/workqueue.rs | 42 +++++++++++++++-------- 6 files changed, 33 insertions(+), 21 deletions(-)Documentation/rust/testing.rst +0
-0
Documentation/rust/testing.rst operator are also supported as usual, e.g.: · line 103
Quoted 8 lines
Documentation/rust/testing.rst +1
-1@@ -97,7 +97,7 @@ operator are also supported as usual, e.g.: /// ``` /// # use kernel::{spawn_work_item, workqueue}; - /// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?; + /// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?; /// # Ok::<(), Error>(()) /// ```
LGTM in terms of documentation part.
Quoted 186 lines
Documentation/translations/zh_CN/rust/testing.rst +1
-1@@ -93,7 +93,7 @@ KUnit 测试即文档测试 /// ``` /// # use kernel::{spawn_work_item, workqueue}; - /// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?; + /// spawn_work_item!(workqueue::system_dfl(), || pr_info!("x\n"))?; /// # Ok::<(), Error>(()) /// ```drivers/android/binder/process.rs +2
-2@@ -1728,7 +1728,7 @@ pub(crate) fn release(this: Arc<Process>, _file: &File) {if should_schedule {// Ignore failures to schedule to the workqueue. Those just mean that we're already // scheduled for execution. -let _ = workqueue::system ().enqueue (this); +let _ = workqueue::system_percpu ().enqueue (this); }drop (binderfs_file);@@ -1745,7 +1745,7 @@ pub(crate) fn flush(this: ArcBorrow<'_, Process>) -> Result {if should_schedule {// Ignore failures to schedule to the workqueue. Those just mean that we're already // scheduled for execution. -let _ = workqueue::system ().enqueue (Arc ::from (this)); +let _ = workqueue::system_percpu ().enqueue (Arc ::from (this)); }Ok (()) }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_dfl().enqueue(this.clone()); /// /// Ok(this) /// } rust/kernel/sync/lock/spinlock.rs +1
-1@@ -450,7 +450,7 @@ fn run(this: Arc<Self>) {fn spinlock_irq_condvar () ->Result {let testdata =Test ::new ()?; -let _ = workqueue::system ().enqueue (testdata.clone ()); +let _ = workqueue::system_dfl ().enqueue (testdata.clone ());// Let the updater know when we're ready to wait let mut state = testdata.state.lock ();rust/kernel/workqueue.rs +27
-16@@ -67,7 +67,7 @@//! /// This method will enqueue the struct for execution on the system workqueue, where its value //! /// will be printed. //! fn print_later(val: Arc<MyStruct>) { -//! let _ = workqueue::system().enqueue(val); +//! let _ = workqueue::system_dfl().enqueue(val); //! } //! # print_later(MyStruct::new(42).unwrap()); //! ``` @@ -121,11 +121,11 @@//! } //! //! fn print_1_later(val: Arc<MyStruct>) { -//! let _ = workqueue::system().enqueue::<Arc<MyStruct>, 1>(val); +//! let _ = workqueue::system_dfl().enqueue::<Arc<MyStruct>, 1>(val); //! } //! //! fn print_2_later(val: Arc<MyStruct>) { -//! let _ = workqueue::system().enqueue::<Arc<MyStruct>, 2>(val); +//! let _ = workqueue::system_dfl().enqueue::<Arc<MyStruct>, 2>(val); //! } //! # print_1_later(MyStruct::new(24, 25).unwrap()); //! # print_2_later(MyStruct::new(41, 42).unwrap()); @@ -171,13 +171,13 @@//! /// This method will enqueue the struct for execution on the system workqueue, where its value //! /// will be printed 12 jiffies later. //! fn print_later(val: Arc<MyStruct>) { -//! let _ = workqueue::system().enqueue_delayed(val, 12); +//! let _ = workqueue::system_dfl().enqueue_delayed(val, 12); //! } //! //! /// It is also possible to use the ordinary `enqueue` method together with `DelayedWork`. This //! /// is equivalent to calling `enqueue_delayed` with a delay of zero. //! fn print_now(val: Arc<MyStruct>) { -//! let _ = workqueue::system().enqueue(val); +//! let _ = workqueue::system_dfl().enqueue(val); //! } //! # print_later(MyStruct::new(42).unwrap()); //! # print_now(MyStruct::new(42).unwrap()); @@ -1024,20 +1024,32 @@ unsafe impl<T, const ID: u64> RawDelayedWorkItem<ID> for ARef<T> { } -/// Returns the system work queue (`system_wq`). +/// Returns the system per-cpu work queue (`system_percpu_wq`). /// /// It is the one used by `schedule[_delayed]_work[_on]()`. Multi-CPU multi-threaded. There are /// users which expect relatively short queue flush time. /// /// Callers shouldn't queue work items which can run for too long. -pub fn system () -> &'staticQueue { -// SAFETY: `system_wq` is a C global, always available. -unsafe {Queue ::from_raw (bindings::system_wq) } +#[inline] +pub fn system_percpu () -> &'staticQueue { +// SAFETY: `system_percpu_wq` is a C global, always available. +unsafe {Queue ::from_raw (bindings::system_percpu_wq) } +} + +/// Returns the system default (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. +#[inline] +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 high-priority work queue (`system_highpri_wq`). /// -/// It is similar to the one returned by [`system`] but for work items which require higher +/// It is similar to the one returned by [`system_percpu`] but for work items which require higher /// scheduling priority. pub fn system_highpri () -> &'staticQueue {// SAFETY: `system_highpri_wq` is a C global, always available. @@ -1046,8 +1058,8 @@ pub fn system_highpri() -> &'static Queue {/// Returns the system work queue for potentially long-running work items (`system_long_wq`). /// -/// It is similar to the one returned by [`system`] but may host long running work items. Queue -/// flushing might take relatively long. +/// It is similar to the one returned by [`system_percpu`] but may host long running work items. +/// Queue flushing might take relatively long. pub fn system_long () -> &'staticQueue {// SAFETY: `system_long_wq` is a C global, always available. unsafe {Queue ::from_raw (bindings::system_long_wq) }@@ -1065,7 +1077,7 @@ pub fn system_unbound() -> &'static Queue {/// Returns the system freezable work queue (`system_freezable_wq`). /// -/// It is equivalent to the one returned by [`system`] except that it's freezable. +/// It is equivalent to the one returned by [`system_percpu`] except that it's freezable. /// /// A freezable workqueue participates in the freeze phase of the system suspend operations. Work /// items on the workqueue are drained and no new work item starts execution until thawed. @@ -1078,7 +1090,7 @@ pub fn system_freezable() -> &'static Queue {/// /// It is inclined towards saving power and is converted to "unbound" variants if the /// `workqueue.power_efficient` kernel parameter is specified; otherwise, it is similar to the one -/// returned by [`system`]. +/// returned by [`system_percpu`]. pub fn system_power_efficient () -> &'staticQueue {// SAFETY: `system_power_efficient_wq` is a C global, always available. unsafe {Queue ::from_raw (bindings::system_power_efficient_wq) }@@ -1097,7 +1109,7 @@ pub fn system_freezable_power_efficient() -> &'static Queue {/// Returns the system bottom halves work queue (`system_bh_wq`). /// -/// It is similar to the one returned by [`system`] but for work items which +/// It is similar to the one returned by [`system_percpu`] but for work items which /// need to run from a softirq context. pub fn system_bh () -> &'staticQueue {// SAFETY: `system_bh_wq` is a C global, always available. ---base-commit:
24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
change-id: 20261013-rust-workqueue-system-fix-5f9020c90f27Best regards,