[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH Mach] Add a mach host operation which returns elapsed time si
From: |
Zhaoming Luo |
Subject: |
[RFC PATCH Mach] Add a mach host operation which returns elapsed time since bootup |
Date: |
Wed, 18 Dec 2024 09:20:00 +0800 |
The precision of this implmentation is 10ms. Not sure how to do with the
possible data race.
Signed-off-by: Zhaoming Luo <zhmingluo@163.com>
---
include/mach/mach_host.defs | 7 +++++++
kern/mach_clock.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/mach/mach_host.defs b/include/mach/mach_host.defs
index 8fd9d6b3..67f72cda 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 elapsed time on this host.
+ */
+routine host_get_elapsed_time(
+ host : host_t;
+ out elapsed_time : time_value_t);
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index 4b953650..a1e45802 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -571,6 +571,26 @@ host_adjust_time64(
return (KERN_SUCCESS);
}
+/*
+ * Read the elapsed time since bootup.
+ */
+kern_return_t
+host_get_elapsed_time(const host_t host, time_value_t *elapsed_time)
+{
+ unsigned long read_elapsed_ticks;
+ int64_t elapsed_usec;
+
+ if (host == HOST_NULL)
+ return (KERN_INVALID_HOST);
+
+ read_elapsed_ticks = elapsed_ticks;
+ elapsed_usec = read_elapsed_ticks * tick;
+ elapsed_time->seconds = elapsed_usec / MICROSECONDS_IN_ONE_SECOND;
+ elapsed_time->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
- [RFC PATCH Mach] Add a mach host operation which returns elapsed time since bootup,
Zhaoming Luo <=