authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2023-12-19 23:43:10-08:00
committergravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2023-12-20 09:24:10-08:00
log23adf095798b8345997b2cbe182c7f109fe1da49
tree8c1e32b6b40380f2813eea3f5fc8fe8776a3bc44
parenta86cd9138960fc3d229d8aad3daa6d7f350e2a21
signaturelock-open Commit is signed but in an unrecognized format.

time: add uefi support


1 files changed, 15 insertions(+), 1 deletions(-)

lib/std/time.zig+15-1
...@@ -114,6 +114,13 @@ pub fn nanoTimestamp() i128 {...@@ -114,6 +114,13 @@ pub fn nanoTimestamp() i128 {
114 return ns;114 return ns;
115 }115 }
116116
117 if (builtin.os.tag == .uefi) {
118 var value: std.os.uefi.Time = undefined;
119 const status = std.os.uefi.system_table.runtime_services.getTime(&value, null);
120 assert(status == .Success);
121 return @as(i128, @intCast(value.toEpoch())) * ms_per_s;
122 }
123
117 var ts: os.timespec = undefined;124 var ts: os.timespec = undefined;
118 os.clock_gettime(os.CLOCK.REALTIME, &ts) catch |err| switch (err) {125 os.clock_gettime(os.CLOCK.REALTIME, &ts) catch |err| switch (err) {
119 error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".126 error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
...@@ -176,7 +183,7 @@ pub const Instant = struct {...@@ -176,7 +183,7 @@ pub const Instant = struct {
176 // true if we should use clock_gettime()183 // true if we should use clock_gettime()
177 const is_posix = switch (builtin.os.tag) {184 const is_posix = switch (builtin.os.tag) {
178 .wasi => builtin.link_libc,185 .wasi => builtin.link_libc,
179 .windows => false,186 .windows, .uefi => false,
180 else => true,187 else => true,
181 };188 };
182189
...@@ -197,6 +204,13 @@ pub const Instant = struct {...@@ -197,6 +204,13 @@ pub const Instant = struct {
197 return Instant{ .timestamp = ns };204 return Instant{ .timestamp = ns };
198 }205 }
199206
207 if (builtin.os.tag == .uefi) {
208 var value: std.os.uefi.Time = undefined;
209 const status = std.os.uefi.system_table.runtime_services.getTime(&value, null);
210 if (status != .Success) return error.Unsupported;
211 return Instant{ .timestamp = value.toEpoch() };
212 }
213
200 // On darwin, use UPTIME_RAW instead of MONOTONIC as it ticks while suspended.214 // On darwin, use UPTIME_RAW instead of MONOTONIC as it ticks while suspended.
201 // On linux, use BOOTTIME instead of MONOTONIC as it ticks while suspended.215 // On linux, use BOOTTIME instead of MONOTONIC as it ticks while suspended.
202 // On freebsd derivatives, use MONOTONIC_FAST as currently there's no precision tradeoff.216 // On freebsd derivatives, use MONOTONIC_FAST as currently there's no precision tradeoff.