diff options
| author | Danilo Krummrich <dakr@kernel.org> | 2026-10-14 09:08:35 +0000 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2026-10-21 01:30:34 +0200 |
| commit | 10ff62c6bb0baf9c2f77f92d2bcdaf6566c31191 (patch) | |
| tree | 35c1cebfa97499927aad101ed45d9e905c43f2fa /rust | |
| parent | c03c1a14507dfaf8b856c2608f9ac216021fc222 (diff) | |
rust: workqueue: replace deprecated system_wq with system_{percpu,dfl}_wq
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().
system_unbound_wq is deprecated in the same way, in favor of
system_dfl_wq. Since system_unbound() has no users, just remove it as
well.
Fixes: 64d8eae3f895 ("workqueue: Add warnings and fallback if system_{unbound}_wq is used")
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Boqun Feng <boqun@kernel.org>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Acked-by: Marco Crivellari <marco.crivellari@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://patch.msgid.link/20261014-rust-workqueue-system-fix-v2-1-c018b8f870f9@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/kernel/sync/completion.rs | 2 | ||||
| -rw-r--r-- | rust/kernel/sync/lock/spinlock.rs | 2 | ||||
| -rw-r--r-- | rust/kernel/workqueue.rs | 52 |
3 files changed, 29 insertions, 27 deletions
diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs index 35ff049ff078..1771bfc0ade2 100644 --- a/rust/kernel/sync/completion.rs +++ b/rust/kernel/sync/completion.rs @@ -38,7 +38,7 @@ use crate::{bindings, prelude::*, types::Opaque}; /// done <- Completion::new(), /// }), GFP_KERNEL)?; /// -/// let _ = workqueue::system().enqueue(this.clone()); +/// let _ = workqueue::system_dfl().enqueue(this.clone()); /// /// Ok(this) /// } diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spinlock.rs index aafc80125f59..92ad133262b6 100644 --- a/rust/kernel/sync/lock/spinlock.rs +++ b/rust/kernel/sync/lock/spinlock.rs @@ -450,7 +450,7 @@ mod tests { 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(); diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 7e253b6f299c..a872f9fffb90 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -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 @@ where { } -/// 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() -> &'static Queue { - // SAFETY: `system_wq` is a C global, always available. - unsafe { Queue::from_raw(bindings::system_wq) } +#[inline] +pub fn system_percpu() -> &'static Queue { + // 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() -> &'static Queue { + // 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() -> &'static Queue { // SAFETY: `system_highpri_wq` is a C global, always available. @@ -1046,26 +1058,16 @@ 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() -> &'static Queue { // SAFETY: `system_long_wq` is a C global, always available. unsafe { Queue::from_raw(bindings::system_long_wq) } } -/// Returns the system unbound work queue (`system_unbound_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. -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 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 +1080,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() -> &'static Queue { // SAFETY: `system_power_efficient_wq` is a C global, always available. unsafe { Queue::from_raw(bindings::system_power_efficient_wq) } @@ -1097,7 +1099,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() -> &'static Queue { // SAFETY: `system_bh_wq` is a C global, always available. |
