[PATCH 5/6] rust: hrtimer: Add HrTimerCallbackContext::forward_now()

Lyude Paul posted 6 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH 5/6] rust: hrtimer: Add HrTimerCallbackContext::forward_now()
Posted by Lyude Paul 10 months, 1 week ago
Using the HrTimerClockBase::time() function we just added, add a binding
for hrtimer_forward_now().

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 rust/kernel/time/hrtimer.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index 521ff1a8a5aa8..d52cbb6cfc57f 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -556,6 +556,14 @@ pub fn forward(&self, now: Ktime, interval: Ktime) -> u64 {
         // SAFETY: The C API requirements for this function are fulfilled by our type invariants.
         unsafe { bindings::hrtimer_forward(self.raw_get_timer(), now.to_ns(), interval.to_ns()) }
     }
+
+    /// Forward the time expiry so it expires after now.
+    ///
+    /// This is a variant of [`HrTimerCallbackContext::forward()`] that uses an interval after the
+    /// current time of the [`HrTimerClockBase`] for this [`HrTimerCallbackContext`].
+    pub fn forward_now(&self, interval: Ktime) -> u64 {
+        self.forward(self.clock_base().time(), interval)
+    }
 }
 
 /// Use to implement the [`HasHrTimer<T>`] trait.
-- 
2.48.1
Re: [PATCH 5/6] rust: hrtimer: Add HrTimerCallbackContext::forward_now()
Posted by Andreas Hindborg 10 months ago
"Lyude Paul" <lyude@redhat.com> writes:

> Using the HrTimerClockBase::time() function we just added, add a binding
> for hrtimer_forward_now().
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> ---
>  rust/kernel/time/hrtimer.rs | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index 521ff1a8a5aa8..d52cbb6cfc57f 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -556,6 +556,14 @@ pub fn forward(&self, now: Ktime, interval: Ktime) -> u64 {
>          // SAFETY: The C API requirements for this function are fulfilled by our type invariants.
>          unsafe { bindings::hrtimer_forward(self.raw_get_timer(), now.to_ns(), interval.to_ns()) }
>      }
> +
> +    /// Forward the time expiry so it expires after now.

I would suggest "so it expires at `duration (if renamed)` after now.`

> +    ///
> +    /// This is a variant of [`HrTimerCallbackContext::forward()`] that uses an interval after the
> +    /// current time of the [`HrTimerClockBase`] for this [`HrTimerCallbackContext`].
> +    pub fn forward_now(&self, interval: Ktime) -> u64 {

I think we should rename `interval` to `duration`, that will match the
upcoming changes to `Ktime`.


Best regards,
Andreas Hindborg