style(ke): rename timecounter to time

This commit is contained in:
Loïc Grégoire
2026-03-28 01:25:06 -04:00
parent a589b5a56f
commit 35094cb298
7 changed files with 18 additions and 20 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ pub fn log(
var res = ringbuffer.reserve(discarder.fullCount()) catch return; 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.info.length = @truncate(discarder.fullCount());
res.buf = std.fmt.bufPrint(res.buf, fmt ++ "\n", args) catch return; res.buf = std.fmt.bufPrint(res.buf, fmt ++ "\n", args) catch return;
+1 -1
View File
@@ -25,7 +25,7 @@ pub const log = @import("log.zig");
pub const cpu = @import("cpu.zig"); pub const cpu = @import("cpu.zig");
pub const thread = @import("thread.zig"); pub const thread = @import("thread.zig");
pub const dpc = @import("dpc.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 sched = @import("sched.zig");
pub const wait = @import("wait.zig"); pub const wait = @import("wait.zig");
pub const timer = @import("timer.zig"); pub const timer = @import("timer.zig");
+8 -10
View File
@@ -10,8 +10,12 @@ pub const Ipl = p.ipl.Ipl;
pub const SpinLock = p.spinlock.SpinLock; pub const SpinLock = p.spinlock.SpinLock;
pub const Thread = p.thread.Thread; pub const Thread = p.thread.Thread;
pub const Dpc = p.dpc.Dpc; 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 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 === // === Exported Interfaces ===
pub const panic = p.panic.panic; pub const panic = p.panic.panic;
@@ -30,9 +34,9 @@ pub const dpc = struct {
pub const enqueue = p.dpc.enqueue; pub const enqueue = p.dpc.enqueue;
}; };
pub const timecounter = struct { pub const time = struct {
pub const register = p.timecounter.register; pub const register_source = p.time.register_source;
pub const read_time_nano = p.timecounter.read_time_nano; pub const read_time_nano = p.time.read_time_nano;
}; };
pub const sched = struct { pub const sched = struct {
@@ -56,12 +60,6 @@ pub const log = struct {
pub const log = p.log.log; 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 { comptime {
if (!@hasDecl(p.impl, "curcpu")) @compileError("impl must provide curcpu()"); if (!@hasDecl(p.impl, "curcpu")) @compileError("impl must provide curcpu()");
} }
+2 -2
View File
@@ -228,7 +228,7 @@ pub fn block() void {
td.lock.acquire_no_ipl(); td.lock.acquire_no_ipl();
td.state = .Blocked; td.state = .Blocked;
td.sleep_start = ke.timecounter.read_time_nano(); td.sleep_start = ke.time.read_time_nano();
td.runq = null; td.runq = null;
yield(ke.curcpu()); yield(ke.curcpu());
@@ -241,7 +241,7 @@ pub fn block() void {
pub fn unblock(td: *ke.Thread) void { pub fn unblock(td: *ke.Thread) void {
const ipl = td.lock.acquire(); 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 (td.sleep_time >= config.CONFIG_SCHED_TIMESLICE and td.priority_class == .Batch) {
// If we have slept for more than a tick, update interactivity. // If we have slept for more than a tick, update interactivity.
@@ -60,7 +60,7 @@ fn ticks_to_ns(tc: *TimeCounter, count: u64) u64 {
/// Register a time-keeping source. /// Register a time-keeping source.
/// The TimeCounter will be used if it is the highest quality one available. /// 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. /// 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. // 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. // This is meant to avoid 128-bit division and only use multiplication for 64-bit counters.
if (tc.mask == std.math.maxInt(u64)) { if (tc.mask == std.math.maxInt(u64)) {
+4 -4
View File
@@ -75,7 +75,7 @@ pub fn set(timer: *Timer, time: b.Nanoseconds, dpc: ?*ke.Dpc) void {
defer cpu.lock.release_no_ipl(); defer cpu.lock.release_no_ipl();
// Initialize the timer. // Initialize the timer.
timer.deadline = ke.timecounter.read_time_nano() + time; timer.deadline = ke.time.read_time_nano() + time;
timer.cpu = cpu; timer.cpu = cpu;
timer.dpc = dpc; timer.dpc = dpc;
@@ -134,7 +134,7 @@ pub fn clock() void {
ke.dpc.enqueue(&percpu.local().dpc, null); ke.dpc.enqueue(&percpu.local().dpc, null);
// Check for overflows. // 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. // 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. // Called in a DPC when a timer has expired.
@@ -143,7 +143,7 @@ fn handle_expiry(_: ?*anyopaque) void {
const cpu = percpu.local(); const cpu = percpu.local();
while (true) { while (true) {
const curtime = ke.timecounter.read_time_nano(); const curtime = ke.time.read_time_nano();
cpu.lock.acquire_no_ipl(); cpu.lock.acquire_no_ipl();
@@ -162,7 +162,7 @@ fn handle_expiry(_: ?*anyopaque) void {
cpu.lock.release_no_ipl(); cpu.lock.release_no_ipl();
// Re-check in case the timer expired while we were here. // 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) { if (next.deadline <= now or next.deadline - now <= std.time.ns_per_ms) {
continue; // expired in the meantime, loop again continue; // expired in the meantime, loop again
} }
+1 -1
View File
@@ -57,7 +57,7 @@ pub fn init() void {
posix.sigaction(posix.SIG.ALRM, &act, null); posix.sigaction(posix.SIG.ALRM, &act, null);
ke.timecounter.register(&tc); ke.time.register_source(&tc);
} }
pub fn init_cpu() void { pub fn init_cpu() void {