Re: [PATCH v8 01/14] rust: time: Add Ktime::from_ns()
From: Benno Lossin
Date: Wed Feb 19 2025 - 07:01:28 EST
On 18.02.25 14:27, Andreas Hindborg wrote:
> From: Lyude Paul <lyude@xxxxxxxxxx>
>
> A simple function to turn the provided value in nanoseconds into a Ktime
> value. We allow any type which implements Into<bindings::ktime_t>, which
> resolves to Into<i64>.
>
> This is useful for some of the older DRM APIs that never got moved to
> Ktime.
Are these older DRM APIs on the C side, or on the Rust side? If they are
on the Rust side, we should just move them to Ktime, no?
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
> Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>
This seems wrong considering the `From Lyude Paul` line above :) (or is
it possible to review your own patch?)
The patch itself looks good, so iff the above question is answered with
"the older DRM APIs are on the C side" then:
Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
---
Cheers,
Benno
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> ---
> rust/kernel/time.rs | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 379c0f5772e57..87e47f2f5618d 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -8,6 +8,8 @@
> //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h).
> //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h).
>
> +use core::convert::Into;
> +
> /// The number of nanoseconds per millisecond.
> pub const NSEC_PER_MSEC: i64 = bindings::NSEC_PER_MSEC as i64;
>
> @@ -63,6 +65,12 @@ pub fn to_ns(self) -> i64 {
> pub fn to_ms(self) -> i64 {
> self.divns_constant::<NSEC_PER_MSEC>()
> }
> +
> + /// Creates a new Ktime from the given duration in nanoseconds.
> + #[inline]
> + pub fn from_nanos(ns: impl Into<bindings::ktime_t>) -> Self {
> + Self { inner: ns.into() }
> + }
> }
>
> /// Returns the number of milliseconds between two ktimes.
>
> --
> 2.47.0
>
>