mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-01 07:48:20 +00:00
all: type-safe time units
This commit is contained in:
@@ -161,7 +161,7 @@ fn lapic_calibrate(ms: u64) u64 {
|
||||
write(.LvtTimer, (1 << 16));
|
||||
write(.TimerInitialCount, std.math.maxInt(u32));
|
||||
|
||||
ke.time.sleep(std.time.ns_per_ms * ms);
|
||||
ke.time.sleep(.from(r.Milliseconds.init(ms)));
|
||||
|
||||
const ticks = std.math.maxInt(u32) - read(.TimerCurrentCount);
|
||||
|
||||
@@ -200,7 +200,7 @@ pub fn arm_timer(ns: r.Nanoseconds) void {
|
||||
if (amd64.cpu_features.tsc_deadline) {
|
||||
const now = amd64.rdtsc();
|
||||
|
||||
const delta: u64 = @intCast((@as(u128, ns) * tsc.tsc_timer.frequency) / std.time.ns_per_s);
|
||||
const delta: u64 = @intCast((@as(u128, ns.value) * tsc.tsc_timer.frequency) / std.time.ns_per_s);
|
||||
|
||||
const deadline = now +% delta;
|
||||
|
||||
@@ -212,7 +212,7 @@ pub fn arm_timer(ns: r.Nanoseconds) void {
|
||||
write(.LvtTimer, 1 << 16);
|
||||
write(.TimerInitialCount, 0);
|
||||
|
||||
const us = ns / std.time.ns_per_us;
|
||||
const us = ns.to(r.Microseconds).value;
|
||||
const ticks: u32 = @truncate(@max(us * timer_ticks_per_us.local().*, 1));
|
||||
|
||||
// Setup IRQ.
|
||||
|
||||
@@ -65,8 +65,8 @@ pub fn init() linksection(r.init) void {
|
||||
.Unknown => false,
|
||||
};
|
||||
|
||||
const init_delay: usize = if (skip_delay) 0 else std.time.ns_per_ms * 10;
|
||||
const sipi_delay: usize = if (skip_delay) std.time.ns_per_us * 10 else std.time.ns_per_us * 300;
|
||||
const init_delay: r.Nanoseconds = .init(if (skip_delay) 0 else std.time.ns_per_ms * 10);
|
||||
const sipi_delay: r.Nanoseconds = .init(if (skip_delay) std.time.ns_per_us * 10 else std.time.ns_per_us * 300);
|
||||
|
||||
const page: [*]u8 = @ptrFromInt(mm.p2v(0x8000));
|
||||
@memcpy(page[0..trampoline_size], @as([*]u8, @ptrFromInt(trampoline_start)));
|
||||
|
||||
@@ -46,7 +46,7 @@ pub fn init() linksection(r.init) void {
|
||||
// Calculate how many ticks it costs to call tc_sleep.
|
||||
for (0..calib_cost_runs) |_| {
|
||||
const start = amd64.rdtsc();
|
||||
ke.time.sleep(0);
|
||||
ke.time.sleep(.init(0));
|
||||
const end = amd64.rdtsc();
|
||||
calib_cost += (end - start);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ pub fn init() linksection(r.init) void {
|
||||
|
||||
for (0..runs) |i| {
|
||||
const start = amd64.rdtsc();
|
||||
ke.time.sleep(calib_time);
|
||||
ke.time.sleep(.init(calib_time));
|
||||
const end = amd64.rdtsc();
|
||||
freqs[i] = (end - start - calib_cost) * (std.time.ns_per_s / calib_time);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub inline fn debug_read() u8 {
|
||||
}
|
||||
|
||||
/// Arm a one-shot timer to fire in `ns` nanoseconds.
|
||||
pub inline fn arm_timer(ns: u64) void {
|
||||
pub inline fn arm_timer(ns: r.Nanoseconds) void {
|
||||
return impl.arm_timer(ns);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user