refactor(ke): read_time_nano -> read_time

This commit is contained in:
Loïc Grégoire
2026-04-19 08:41:26 -04:00
parent a7e319c922
commit b646115dfc
5 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ pub fn log(
// Reserve space in the ring buffer.
var res = ringbuffer.reserve(required_len) catch return;
res.info.timestamp = ke.time.read_time_nano();
res.info.timestamp = ke.time.read_time();
res.info.length = @truncate(required_len);
// Format the log message into the reserved buffer.
+1 -1
View File
@@ -37,7 +37,7 @@ pub const dpc = struct {
pub const time = struct {
pub const register_source = p.time.register_source;
pub const read_time_nano = p.time.read_time_nano;
pub const read_time = p.time.read_time;
pub const best = p.time.best;
pub const sleep = p.time.sleep;
};
+2 -2
View File
@@ -246,7 +246,7 @@ pub fn block() void {
td.lock.acquire_no_ipl();
td.state = .Blocked;
td.sleep_start = ke.time.read_time_nano();
td.sleep_start = ke.time.read_time();
td.runq = null;
yield(ke.cpu.current());
@@ -259,7 +259,7 @@ pub fn block() void {
pub fn unblock(td: *ke.Thread) void {
const ipl = td.lock.acquire();
td.sleep_time = (ke.time.read_time_nano() - td.sleep_start) / std.time.ns_per_ms;
td.sleep_time = (ke.time.read_time() - 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.
+6 -6
View File
@@ -28,7 +28,7 @@ pub const TimeCounter = struct {
var best_tc: ?*TimeCounter = null;
const TimeState = struct {
const State = struct {
// Counter value at the time the current TimeCounter was selected.
// Used as the baseline for elapsed time calculation.
initial_count: u64,
@@ -39,7 +39,7 @@ const TimeState = struct {
// SeqLock-protected time state.
// Avoids a race on `initial_count` and `offset` with `update_overflow`.
var state = rtl.SeqLock(TimeState).init(.{
var state = rtl.SeqLock(State).init(.{
.initial_count = 0,
.offset = 0,
});
@@ -88,7 +88,7 @@ pub fn register_source(tc: *TimeCounter) void {
}
/// Return the time elapsed since boot in nanoseconds.
pub fn read_time_nano() r.Nanoseconds {
pub fn read_time() r.Nanoseconds {
const tc = best_tc orelse return 0;
const s = state.load();
@@ -104,15 +104,15 @@ pub fn best() ?*TimeCounter {
/// Do a busy sleep of `ns` nanoseconds using TimeCounter.
pub fn sleep(ns: r.Nanoseconds) void {
const start = read_time_nano();
const start = read_time();
while (true) {
var cur = read_time_nano();
var cur = read_time();
if (cur < start) continue;
if (cur - start >= ns) {
cur = read_time_nano();
cur = read_time();
// Check again as we may have overflowed and read a bogus value..
// This is kinda hacky but oh well.
+3 -3
View File
@@ -75,7 +75,7 @@ pub fn set(timer: *Timer, time: r.Nanoseconds, dpc: ?*ke.Dpc) void {
defer cpu.lock.release_no_ipl();
// Initialize the timer.
timer.deadline = ke.time.read_time_nano() + time;
timer.deadline = ke.time.read_time() + time;
timer.cpu = cpu;
timer.dpc = dpc;
@@ -143,7 +143,7 @@ fn handle_expiry(_: ?*anyopaque) void {
const cpu = percpu.local();
while (true) {
const curtime = ke.time.read_time_nano();
const curtime = ke.time.read_time();
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.time.read_time_nano();
const now = ke.time.read_time();
if (next.deadline <= now or next.deadline - now <= std.time.ns_per_ms) {
continue; // expired in the meantime, loop again
}