From 35094cb2981668b10bffbcddf677057e30184ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Sat, 28 Mar 2026 01:25:06 -0400 Subject: [PATCH] style(ke): rename timecounter to time --- src/kern/log.zig | 2 +- src/kern/private.zig | 2 +- src/kern/root.zig | 18 ++++++++---------- src/kern/sched.zig | 4 ++-- src/kern/{timecounter.zig => time.zig} | 2 +- src/kern/timer.zig | 8 ++++---- src/platform/um/timer.zig | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) rename src/kern/{timecounter.zig => time.zig} (98%) diff --git a/src/kern/log.zig b/src/kern/log.zig index f15f1e8..53c3d28 100644 --- a/src/kern/log.zig +++ b/src/kern/log.zig @@ -96,7 +96,7 @@ pub fn log( var res = ringbuffer.reserve(discarder.fullCount()) catch return; - res.info.timestamp = ke.timecounter.read_time_nano(); + res.info.timestamp = ke.time.read_time_nano(); res.info.length = @truncate(discarder.fullCount()); res.buf = std.fmt.bufPrint(res.buf, fmt ++ "\n", args) catch return; diff --git a/src/kern/private.zig b/src/kern/private.zig index 704fc68..52a1369 100644 --- a/src/kern/private.zig +++ b/src/kern/private.zig @@ -25,7 +25,7 @@ pub const log = @import("log.zig"); pub const cpu = @import("cpu.zig"); pub const thread = @import("thread.zig"); pub const dpc = @import("dpc.zig"); -pub const timecounter = @import("timecounter.zig"); +pub const time = @import("time.zig"); pub const sched = @import("sched.zig"); pub const wait = @import("wait.zig"); pub const timer = @import("timer.zig"); diff --git a/src/kern/root.zig b/src/kern/root.zig index d45ec16..ac19acc 100644 --- a/src/kern/root.zig +++ b/src/kern/root.zig @@ -10,8 +10,12 @@ pub const Ipl = p.ipl.Ipl; pub const SpinLock = p.spinlock.SpinLock; pub const Thread = p.thread.Thread; pub const Dpc = p.dpc.Dpc; -pub const TimeCounter = p.timecounter.TimeCounter; +pub const TimeCounter = p.time.TimeCounter; pub const Timer = p.timer.Timer; +pub const Console = p.log.Console; +pub const Cpu = p.cpu.Cpu; +pub const CpuLocal = p.cpu.CpuLocal; +pub const CpuMask = p.cpu.CpuMask; // === Exported Interfaces === pub const panic = p.panic.panic; @@ -30,9 +34,9 @@ pub const dpc = struct { pub const enqueue = p.dpc.enqueue; }; -pub const timecounter = struct { - pub const register = p.timecounter.register; - pub const read_time_nano = p.timecounter.read_time_nano; +pub const time = struct { + pub const register_source = p.time.register_source; + pub const read_time_nano = p.time.read_time_nano; }; pub const sched = struct { @@ -56,12 +60,6 @@ pub const log = struct { pub const log = p.log.log; }; -pub const Console = p.log.Console; - -pub const Cpu = p.cpu.Cpu; -pub const CpuLocal = p.cpu.CpuLocal; -pub const CpuMask = p.cpu.CpuMask; - comptime { if (!@hasDecl(p.impl, "curcpu")) @compileError("impl must provide curcpu()"); } diff --git a/src/kern/sched.zig b/src/kern/sched.zig index 0cd1128..4575576 100644 --- a/src/kern/sched.zig +++ b/src/kern/sched.zig @@ -228,7 +228,7 @@ pub fn block() void { td.lock.acquire_no_ipl(); td.state = .Blocked; - td.sleep_start = ke.timecounter.read_time_nano(); + td.sleep_start = ke.time.read_time_nano(); td.runq = null; yield(ke.curcpu()); @@ -241,7 +241,7 @@ pub fn block() void { pub fn unblock(td: *ke.Thread) void { const ipl = td.lock.acquire(); - td.sleep_time = (ke.timecounter.read_time_nano() - td.sleep_start) / std.time.ns_per_ms; + td.sleep_time = (ke.time.read_time_nano() - td.sleep_start) / std.time.ns_per_ms; if (td.sleep_time >= config.CONFIG_SCHED_TIMESLICE and td.priority_class == .Batch) { // If we have slept for more than a tick, update interactivity. diff --git a/src/kern/timecounter.zig b/src/kern/time.zig similarity index 98% rename from src/kern/timecounter.zig rename to src/kern/time.zig index 15cbf2a..fa64dbb 100644 --- a/src/kern/timecounter.zig +++ b/src/kern/time.zig @@ -60,7 +60,7 @@ fn ticks_to_ns(tc: *TimeCounter, count: u64) u64 { /// Register a time-keeping source. /// The TimeCounter will be used if it is the highest quality one available. /// This function cannot be safely called when the hardware timer has been started, as data races on `best_tc` are not avoided. -pub fn register(tc: *TimeCounter) void { +pub fn register_source(tc: *TimeCounter) void { // Precompute scaling factors for the fast multiply-shift path. // This is meant to avoid 128-bit division and only use multiplication for 64-bit counters. if (tc.mask == std.math.maxInt(u64)) { diff --git a/src/kern/timer.zig b/src/kern/timer.zig index 8ec40c4..f2c5bef 100644 --- a/src/kern/timer.zig +++ b/src/kern/timer.zig @@ -75,7 +75,7 @@ pub fn set(timer: *Timer, time: b.Nanoseconds, dpc: ?*ke.Dpc) void { defer cpu.lock.release_no_ipl(); // Initialize the timer. - timer.deadline = ke.timecounter.read_time_nano() + time; + timer.deadline = ke.time.read_time_nano() + time; timer.cpu = cpu; timer.dpc = dpc; @@ -134,7 +134,7 @@ pub fn clock() void { ke.dpc.enqueue(&percpu.local().dpc, null); // Check for overflows. // This is fine to call a lot, as the function only gets expensive (i.e seqlock store) when an overflow actually happens. - ki.timecounter.update_overflow(); + ki.time.update_overflow(); } // Called in a DPC when a timer has expired. @@ -143,7 +143,7 @@ fn handle_expiry(_: ?*anyopaque) void { const cpu = percpu.local(); while (true) { - const curtime = ke.timecounter.read_time_nano(); + const curtime = ke.time.read_time_nano(); cpu.lock.acquire_no_ipl(); @@ -162,7 +162,7 @@ fn handle_expiry(_: ?*anyopaque) void { cpu.lock.release_no_ipl(); // Re-check in case the timer expired while we were here. - const now = ke.timecounter.read_time_nano(); + const now = ke.time.read_time_nano(); if (next.deadline <= now or next.deadline - now <= std.time.ns_per_ms) { continue; // expired in the meantime, loop again } diff --git a/src/platform/um/timer.zig b/src/platform/um/timer.zig index 6b641ed..4abc321 100644 --- a/src/platform/um/timer.zig +++ b/src/platform/um/timer.zig @@ -57,7 +57,7 @@ pub fn init() void { posix.sigaction(posix.SIG.ALRM, &act, null); - ke.timecounter.register(&tc); + ke.time.register_source(&tc); } pub fn init_cpu() void {