summaryrefslogtreecommitdiff
path: root/rust/helpers/time.c
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2025-06-10 18:32:56 +0900
committerAndreas Hindborg <a.hindborg@kernel.org>2025-06-16 15:02:29 +0200
commitcc6d1098b4cca6ec8e659de8361457c59a90b583 (patch)
tree647d6bce3f674398736271d24c31370b05cec651 /rust/helpers/time.c
parent768dfbfc98e26cfad45f7165a1801d188f3cbd81 (diff)
rust: time: Add ktime_get() to ClockSource trait
Introduce the ktime_get() associated function to the ClockSource trait, allowing each clock source to specify how it retrieves the current time. This enables Instant::now() to be implemented generically using the type-level ClockSource abstraction. This change enhances the type safety and extensibility of timekeeping by statically associating time retrieval mechanisms with their respective clock types. It also reduces the reliance on hardcoded clock logic within Instant. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Link: https://lore.kernel.org/r/20250610093258.3435874-4-fujita.tomonori@gmail.com Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Diffstat (limited to 'rust/helpers/time.c')
-rw-r--r--rust/helpers/time.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/rust/helpers/time.c b/rust/helpers/time.c
index 3d31473bce08..08755db43fc2 100644
--- a/rust/helpers/time.c
+++ b/rust/helpers/time.c
@@ -1,6 +1,22 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/ktime.h>
+#include <linux/timekeeping.h>
+
+ktime_t rust_helper_ktime_get_real(void)
+{
+ return ktime_get_real();
+}
+
+ktime_t rust_helper_ktime_get_boottime(void)
+{
+ return ktime_get_boottime();
+}
+
+ktime_t rust_helper_ktime_get_clocktai(void)
+{
+ return ktime_get_clocktai();
+}
s64 rust_helper_ktime_to_us(const ktime_t kt)
{