Re: [PATCH net-next v3 4/8] rust: time: Implement addition of Ktime and Delta
From: Alice Ryhl
Date: Wed Oct 16 2024 - 04:26:21 EST
On Wed, Oct 16, 2024 at 5:53 AM FUJITA Tomonori
<fujita.tomonori@xxxxxxxxx> wrote:
>
> Implement Add<Delta> for Ktime to support the operation:
>
> Ktime = Ktime + Delta
>
> This is typically used to calculate the future time when the timeout
> will occur.
>
> timeout Ktime = current Ktime (via ktime_get()) + Delta;
> // do something
> if (ktime_get() > timeout Ktime) {
> // timed out
> }
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> rust/kernel/time.rs | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 8c00854db58c..9b0537b63cf7 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -155,3 +155,14 @@ pub fn as_secs(self) -> i64 {
> self.nanos / NSEC_PER_SEC
> }
> }
> +
> +impl core::ops::Add<Delta> for Ktime {
> + type Output = Ktime;
> +
> + #[inline]
> + fn add(self, delta: Delta) -> Ktime {
> + Ktime {
> + inner: self.inner + delta.as_nanos(),
You don't want to do `delta.inner` here?
Alice