Skip to contentSkip to conversation

rust: workqueue: take a Delta<Jiffy> for the enqueue delay

PATCH New FUJITA Tomonori 1 participant 1 message Nov 17 Rust

lore
Share & tools
lore
#0 lore raw

PATCH v10 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.

---
v10:
- Import Delta in the doc example so that the line is shorter (Alice)
- Add Alice's Reviewed-by
v9: https://lore.kernel.org/rust-for-linux/[email protected]/
- 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 | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
rust/kernel/workqueue.rs +10 -4
index a872f9fffb90..8717a78a1ebe 100644
@@ -135,6 +135,7 @@
 //!
 //! ```
 //! use kernel::sync::Arc;
+//! use kernel::time::Delta;
 //! use kernel::workqueue::{self, impl_has_delayed_work, new_delayed_work, DelayedWork, WorkItem};
 //!
 //! #[pin_data]
@@ -171,7 +172,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, Delta::from_jiffies(12));
 //! }
 //!
 //! /// It is also possible to use the ordinary `enqueue` method together with `DelayedWork`. This
@@ -197,7 +198,10 @@
         Arc,
         LockClassKey, //
     },
-    time::Jiffies,
+    time::{
+        Delta,
+        Jiffy, //
+    },
     types::Opaque,
 };
 use core::{marker::PhantomData, ptr::NonNull};
@@ -303,7 +307,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 +334,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: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0