rust: workqueue: take a Delta<Jiffy> for the enqueue delay
PATCH v9 1/1 rust: workqueue: take a Delta<Jiffy> for the enqueue delay
From: FUJITA Tomonori <[email protected]>
enqueue_delayed() takes the delay as a raw Jiffies, which is a c_ulong alias. The type does not show the unit, so callers pass a bare integer.
Take the delay as Delta<Jiffy> instead. A caller that already has a value in jiffies passes it without conversion. A caller that has a Delta in nanoseconds converts it with Delta::to_jiffies_timeout(), which rounds up, so a short delay does not become zero.
---
v9:
- Send as a single patch. Patches 1/4 and 2/4 of v8 are in v7.4-rc1,
and the condvar patch was sent separately
- Rebase on v7.4-rc1. The doc example now uses system_dfl()
v8: https://lore.kernel.org/rust-for-linux/[email protected]/
--- rust/kernel/workqueue.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
rust/kernel/workqueue.rs +9 -4
@@ -171,7 +171,7 @@//! /// 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_dfl().enqueue_delayed(val, 12); +//! let _ = workqueue::system_dfl().enqueue_delayed(val, kernel::time::Delta::from_jiffies(12)); //! } //! //! /// It is also possible to use the ordinary `enqueue` method together with `DelayedWork`. This
@@ -197,7 +197,10 @@ Arc, LockClassKey, // }, - time::Jiffies, + time::{ + Delta, + Jiffy, // + }, types::Opaque, };use core::{marker::PhantomData , ptr::NonNull };
@@ -303,7 +306,9 @@ pub fn enqueue<W, const ID: u64>(&self, w: W) -> W::EnqueueOutput/// This may fail if the work item is already enqueued in a workqueue. /// /// The work item will be submitted using `WORK_CPU_UNBOUND`. -pub fn enqueue_delayed <W ,const ID :u64 >(&self, w:W , delay:Jiffies ) ->W ::EnqueueOutput +/// +/// A negative delay is treated as zero. +pub fn enqueue_delayed <W ,const ID :u64 >(&self, w:W , delay:Delta <Jiffy >) ->W ::EnqueueOutput where W :RawDelayedWorkItem <ID > +Send + 'static, {
@@ -328,7 +333,7 @@ pub fn enqueue_delayed<W, const ID: u64>(&self, w: W, delay: Jiffies) -> W::Enqu bindings::wq_misc_consts_WORK_CPU_UNBOUND as ffi::c_int, queue_ptr, container_of!(work_ptr, bindings::delayed_work, work), - delay, + delay.as_jiffies_unsigned (), ) }) }
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.43.0
Quoted 6 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
enqueue_delayed()takes the delay as a raw Jiffies, which is ac_ulongalias. The type does not show the unit, so callers pass a bare integer.
Quoted 7 lines
Take the delay as Delta<Jiffy> instead. A caller that already has a value in jiffies passes it without conversion. A caller that has a Delta in nanoseconds converts it with
Delta::to_jiffies_timeout(), which rounds up, so a short delay does not become zero.Reviewed-by Gary Guo <[email protected]>Signed-off-by FUJITA Tomonori <[email protected]>
rust/kernel/workqueue.rs line 174
Quoted 10 lines
rust/kernel/workqueue.rs +1
-1@@ -171,7 +171,7 @@//! /// 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_dfl().enqueue_delayed(val, 12); +//! let _ = workqueue::system_dfl().enqueue_delayed(val, kernel::time::Delta::from_jiffies(12));
Would be nice to import Delta so this line is not so long.
Alice
Quoted 6 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
enqueue_delayed()takes the delay as a raw Jiffies, which is ac_ulongalias. The type does not show the unit, so callers pass a bare integer.
Quoted 7 lines
Take the delay as Delta<Jiffy> instead. A caller that already has a value in jiffies passes it without conversion. A caller that has a Delta in nanoseconds converts it with
Delta::to_jiffies_timeout(), which rounds up, so a short delay does not become zero.Reviewed-by Gary Guo <[email protected]>Signed-off-by FUJITA Tomonori <[email protected]>
Tejun: I am happy to pick this one, but of course please shout if you are planning to do it yourself!
Thanks!
Cheers,
Miguel