bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 1/1] Add a mach host operation which returns elapsed time sinc


From: Zhaoming Luo
Subject: [PATCH v3 1/1] Add a mach host operation which returns elapsed time since bootup
Date: Mon, 23 Dec 2024 12:41:14 +0800

A CLOCK_MONOTONIC with 10ms resolution can be fetched using
host_get_uptime().

Signed-off-by: Zhaoming Luo <zhmingluo@163.com>
---
 include/mach/mach_host.defs |  7 +++++++
 kern/mach_clock.c           | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/mach/mach_host.defs b/include/mach/mach_host.defs
index 8fd9d6b3..7ea99bbe 100644
--- a/include/mach/mach_host.defs
+++ b/include/mach/mach_host.defs
@@ -386,3 +386,10 @@ routine    host_adjust_time64(
 routine        host_get_kernel_version(
                host            : host_t;
        out     kernel_version  : new_kernel_version_t);
+
+/*
+ *     Get the uptime on this host.
+ */
+routine        host_get_uptime(
+               host            : host_t;
+       out     up_time         : time_value_t);
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index 4b953650..309c6e07 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -571,6 +571,25 @@ host_adjust_time64(
        return (KERN_SUCCESS);
 }
 
+/*
+ * Read the uptime (the elapsed time since boot up).
+ */
+kern_return_t
+host_get_uptime(const host_t host, time_value_t *uptime)
+{
+       int64_t elapsed_usec;
+
+       if (host == HOST_NULL)
+               return (KERN_INVALID_HOST);
+
+       elapsed_usec =
+           __atomic_load_n(&elapsed_ticks, __ATOMIC_RELAXED) * tick;
+       uptime->seconds = elapsed_usec / MICROSECONDS_IN_ONE_SECOND;
+       uptime->microseconds = elapsed_usec % MICROSECONDS_IN_ONE_SECOND;
+
+       return (KERN_SUCCESS);
+}
+
 void mapable_time_init(void)
 {
        if (kmem_alloc_wired(kernel_map, (vm_offset_t *) &mtime, PAGE_SIZE)
-- 
2.45.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]