[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241005122531.20298-4-fujita.tomonori@gmail.com>
Date: Sat, 5 Oct 2024 21:25:28 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: netdev@...r.kernel.org
Cc: rust-for-linux@...r.kernel.org,
andrew@...n.ch,
hkallweit1@...il.com,
tmgross@...ch.edu,
ojeda@...nel.org,
alex.gaynor@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me,
a.hindborg@...sung.com,
aliceryhl@...gle.com,
anna-maria@...utronix.de,
frederic@...nel.org,
tglx@...utronix.de,
arnd@...db.de,
linux-kernel@...r.kernel.org
Subject: [PATCH net-next v2 3/6] rust: time: Implement addition of Ktime and Delta
Implement Add<Delta> for Ktime to support the operation:
Ktime = Ktime + Delta
This is used to calculate the future time when the timeout will occur.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
---
rust/helpers/time.c | 5 +++++
rust/kernel/time.rs | 11 +++++++++++
2 files changed, 16 insertions(+)
diff --git a/rust/helpers/time.c b/rust/helpers/time.c
index d6f61affb2c3..60dee69f4efc 100644
--- a/rust/helpers/time.c
+++ b/rust/helpers/time.c
@@ -2,6 +2,11 @@
#include <linux/ktime.h>
+ktime_t rust_helper_ktime_add_ns(const ktime_t kt, const u64 nsec)
+{
+ return ktime_add_ns(kt, nsec);
+}
+
int rust_helper_ktime_compare(const ktime_t cmp1, const ktime_t cmp2)
{
return ktime_compare(cmp1, cmp2);
diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 6c5a1c50c5f1..3e00ad22ed89 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -167,3 +167,14 @@ pub fn as_micros(self) -> i64 {
self.nanos / NSEC_PER_USEC
}
}
+
+impl core::ops::Add<Delta> for Ktime {
+ type Output = Ktime;
+
+ #[inline]
+ fn add(self, delta: Delta) -> Ktime {
+ // SAFETY: FFI call.
+ let t = unsafe { bindings::ktime_add_ns(self.inner, delta.as_nanos() as u64) };
+ Ktime::from_raw(t)
+ }
+}
--
2.34.1
Powered by blists - more mailing lists