Lines Matching full:work
3 //! Work queues.
5 //! This file has two components: The raw work item API, and the safe work item API.
15 //! The raw API consists of the `RawWorkItem` trait, where the work item needs to provide an
16 //! arbitrary function that knows how to enqueue the work item. It should usually not be used
21 //! The safe API is used via the `Work` struct and `WorkItem` traits. Furthermore, it also includes
24 //! * The `Work` struct is the Rust wrapper for the C `work_struct` type.
38 //! use kernel::workqueue::{self, Work, WorkItem};
45 //! work: Work<MyStruct>,
49 //! impl HasWork<Self> for MyStruct { self.work }
56 //! work <- new_work!("MyStruct::work"),
81 //! use kernel::workqueue::{self, Work, WorkItem};
89 //! work_1: Work<MyStruct, 1>,
91 //! work_2: Work<MyStruct, 2>,
143 /// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
147 … $crate::workqueue::Work::new($crate::optional_name!($($name)?), $crate::static_lock_class!())
151 /// A kernel work queue.
155 /// It allows work items to be queued to run on thread pools managed by the kernel. Several are
178 /// Enqueues a work item.
180 /// This may fail if the work item is already enqueued in a workqueue.
182 /// The work item will be submitted using `WORK_CPU_UNBOUND`.
197 // `__enqueue`, then the work item was successfully enqueued, and `bindings::queue_work_on` in enqueue()
207 /// Tries to spawn the given function or closure as a work item.
209 /// This method can fail because it allocates memory to store the work item.
212 work <- new_work!("Queue::try_spawn"), in try_spawn()
225 work: Work<ClosureWork<T>>, field
246 /// A raw work item.
268 /// Enqueues this work item on a queue using the provided `queue_work_on` method.
281 /// If the work item type is annotated with any lifetimes, then you must not call the function
284 /// If the work item type is not [`Send`], then the function pointer must be called on the same
291 /// Defines the method that should be called directly when a work item is executed.
298 /// This trait is used when the `work_struct` field is defined using the [`Work`] helper.
308 /// Run this work item.
317 /// Defines the method that should be called when this work item is executed.
319 /// This trait is used when the `work_struct` field is defined using the [`Work`] helper.
325 /// The method that should be called when this work item is executed.
329 /// Links for a work item.
332 /// trait, and defines the linked list pointers necessary to enqueue a work item in a workqueue.
338 pub struct Work<T: ?Sized, const ID: u64 = 0> { struct
339 work: Opaque<bindings::work_struct>, field
343 // SAFETY: Kernel work items are usable from any thread.
345 // We do not need to constrain `T` since the work item does not actually contain a `T`.
346 unsafe impl<T: ?Sized, const ID: u64> Send for Work<T, ID> {} argument
347 // SAFETY: Kernel work items are usable from any thread.
349 // We do not need to constrain `T` since the work item does not actually contain a `T`.
350 unsafe impl<T: ?Sized, const ID: u64> Sync for Work<T, ID> {} implementation
352 impl<T: ?Sized, const ID: u64> Work<T, ID> { implementation
353 /// Creates a new instance of [`Work`].
360 // SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work in new()
388 // the compiler does not complain that the `work` field is unused. in raw_get()
389 unsafe { Opaque::raw_get(core::ptr::addr_of!((*ptr).work)) } in raw_get()
393 /// Declares that a type has a [`Work<T, ID>`] field.
401 /// use kernel::workqueue::Work;
404 /// work_field: Work<MyWorkItem, 1>,
412 /// Note that since the `Work` type is annotated with an id, you can have several `work_struct`
417 /// The [`OFFSET`] constant must be the offset of a field in Self of type [`Work<T, ID>`]. The meth…
420 /// [`Work<T, ID>`]: Work
424 /// The offset of the [`Work<T, ID>`] field.
426 /// [`Work<T, ID>`]: Work
429 /// Returns the offset of the [`Work<T, ID>`] field.
433 /// [`Work<T, ID>`]: Work
440 /// Returns a pointer to the [`Work<T, ID>`] field.
446 /// [`Work<T, ID>`]: Work
448 unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work<T, ID> { in raw_get_work()
450 unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut Work<T, ID> } in raw_get_work()
453 /// Returns a pointer to the struct containing the [`Work<T, ID>`] field.
457 /// The pointer must point at a [`Work<T, ID>`] field in a struct of type `Self`.
459 /// [`Work<T, ID>`]: Work
461 unsafe fn work_container_of(ptr: *mut Work<T, ID>) -> *mut Self in work_container_of()
478 /// use kernel::workqueue::{self, Work};
481 /// work_field: Work<MyStruct, 17>,
503 … unsafe fn raw_get_work(ptr: *mut Self) -> *mut $crate::workqueue::Work<$work_type $(, $id)?> {
514 impl<T> HasWork<Self> for ClosureWork<T> { self.work }
523 // SAFETY: The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`. in run()
524 let ptr = ptr as *mut Work<T, ID>; in run()
551 let work_ptr = unsafe { Work::raw_get(work_ptr) }; in __enqueue()
556 // SAFETY: The work queue has not taken ownership of the pointer. in __enqueue()
568 // SAFETY: The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`. in run()
569 let ptr = ptr as *mut Work<T, ID>; in run()
600 let work_ptr = unsafe { Work::raw_get(work_ptr) }; in __enqueue()
610 /// Returns the system work queue (`system_wq`).
615 /// Callers shouldn't queue work items which can run for too long.
621 /// Returns the system high-priority work queue (`system_highpri_wq`).
623 /// It is similar to the one returned by [`system`] but for work items which require higher
630 /// Returns the system work queue for potentially long-running work items (`system_long_wq`).
632 /// It is similar to the one returned by [`system`] but may host long running work items. Queue
639 /// Returns the system unbound work queue (`system_unbound_wq`).
641 /// Workers are not bound to any specific CPU, not concurrency managed, and all queued work items
649 /// Returns the system freezable work queue (`system_freezable_wq`).
653 /// A freezable workqueue participates in the freeze phase of the system suspend operations. Work
654 /// items on the workqueue are drained and no new work item starts execution until thawed.
660 /// Returns the system power-efficient work queue (`system_power_efficient_wq`).
670 /// Returns the system freezable power-efficient work queue (`system_freezable_power_efficient_wq`).
674 /// A freezable workqueue participates in the freeze phase of the system suspend operations. Work
675 /// items on the workqueue are drained and no new work item starts execution until thawed.