Skip to content

Commit 0339413

Browse files
wedsonafhtejun
authored andcommitted
rust: workqueue: define built-in queues
We provide these methods because it lets us access these queues from Rust without using unsafe code. These methods return `&'static Queue`. References annotated with the 'static lifetime are used when the referent will stay alive forever. That is ok for these queues because they are global variables and cannot be destroyed. Signed-off-by: Wedson Almeida Filho <[email protected]> Co-developed-by: Alice Ryhl <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Gary Guo <[email protected]> Reviewed-by: "Andreas Hindborg (Samsung)" <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent d4d791d commit 0339413

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

rust/kernel/workqueue.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,74 @@ pub unsafe trait RawWorkItem<const ID: u64> {
107107
where
108108
F: FnOnce(*mut bindings::work_struct) -> bool;
109109
}
110+
111+
/// Returns the system work queue (`system_wq`).
112+
///
113+
/// It is the one used by `schedule[_delayed]_work[_on]()`. Multi-CPU multi-threaded. There are
114+
/// users which expect relatively short queue flush time.
115+
///
116+
/// Callers shouldn't queue work items which can run for too long.
117+
pub fn system() -> &'static Queue {
118+
// SAFETY: `system_wq` is a C global, always available.
119+
unsafe { Queue::from_raw(bindings::system_wq) }
120+
}
121+
122+
/// Returns the system high-priority work queue (`system_highpri_wq`).
123+
///
124+
/// It is similar to the one returned by [`system`] but for work items which require higher
125+
/// scheduling priority.
126+
pub fn system_highpri() -> &'static Queue {
127+
// SAFETY: `system_highpri_wq` is a C global, always available.
128+
unsafe { Queue::from_raw(bindings::system_highpri_wq) }
129+
}
130+
131+
/// Returns the system work queue for potentially long-running work items (`system_long_wq`).
132+
///
133+
/// It is similar to the one returned by [`system`] but may host long running work items. Queue
134+
/// flushing might take relatively long.
135+
pub fn system_long() -> &'static Queue {
136+
// SAFETY: `system_long_wq` is a C global, always available.
137+
unsafe { Queue::from_raw(bindings::system_long_wq) }
138+
}
139+
140+
/// Returns the system unbound work queue (`system_unbound_wq`).
141+
///
142+
/// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items
143+
/// are executed immediately as long as `max_active` limit is not reached and resources are
144+
/// available.
145+
pub fn system_unbound() -> &'static Queue {
146+
// SAFETY: `system_unbound_wq` is a C global, always available.
147+
unsafe { Queue::from_raw(bindings::system_unbound_wq) }
148+
}
149+
150+
/// Returns the system freezable work queue (`system_freezable_wq`).
151+
///
152+
/// It is equivalent to the one returned by [`system`] except that it's freezable.
153+
///
154+
/// A freezable workqueue participates in the freeze phase of the system suspend operations. Work
155+
/// items on the workqueue are drained and no new work item starts execution until thawed.
156+
pub fn system_freezable() -> &'static Queue {
157+
// SAFETY: `system_freezable_wq` is a C global, always available.
158+
unsafe { Queue::from_raw(bindings::system_freezable_wq) }
159+
}
160+
161+
/// Returns the system power-efficient work queue (`system_power_efficient_wq`).
162+
///
163+
/// It is inclined towards saving power and is converted to "unbound" variants if the
164+
/// `workqueue.power_efficient` kernel parameter is specified; otherwise, it is similar to the one
165+
/// returned by [`system`].
166+
pub fn system_power_efficient() -> &'static Queue {
167+
// SAFETY: `system_power_efficient_wq` is a C global, always available.
168+
unsafe { Queue::from_raw(bindings::system_power_efficient_wq) }
169+
}
170+
171+
/// Returns the system freezable power-efficient work queue (`system_freezable_power_efficient_wq`).
172+
///
173+
/// It is similar to the one returned by [`system_power_efficient`] except that is freezable.
174+
///
175+
/// A freezable workqueue participates in the freeze phase of the system suspend operations. Work
176+
/// items on the workqueue are drained and no new work item starts execution until thawed.
177+
pub fn system_freezable_power_efficient() -> &'static Queue {
178+
// SAFETY: `system_freezable_power_efficient_wq` is a C global, always available.
179+
unsafe { Queue::from_raw(bindings::system_freezable_power_efficient_wq) }
180+
}

0 commit comments

Comments
 (0)