mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-02 08:08:21 +00:00
refactor(ke): read_time_nano -> read_time
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@ pub fn log(
|
|||||||
// Reserve space in the ring buffer.
|
// Reserve space in the ring buffer.
|
||||||
var res = ringbuffer.reserve(required_len) catch return;
|
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);
|
res.info.length = @truncate(required_len);
|
||||||
|
|
||||||
// Format the log message into the reserved buffer.
|
// Format the log message into the reserved buffer.
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ pub const dpc = struct {
|
|||||||
|
|
||||||
pub const time = struct {
|
pub const time = struct {
|
||||||
pub const register_source = p.time.register_source;
|
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 best = p.time.best;
|
||||||
pub const sleep = p.time.sleep;
|
pub const sleep = p.time.sleep;
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -246,7 +246,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.time.read_time_nano();
|
td.sleep_start = ke.time.read_time();
|
||||||
td.runq = null;
|
td.runq = null;
|
||||||
|
|
||||||
yield(ke.cpu.current());
|
yield(ke.cpu.current());
|
||||||
@@ -259,7 +259,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.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 (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.
|
||||||
|
|||||||
+6
-6
@@ -28,7 +28,7 @@ pub const TimeCounter = struct {
|
|||||||
|
|
||||||
var best_tc: ?*TimeCounter = null;
|
var best_tc: ?*TimeCounter = null;
|
||||||
|
|
||||||
const TimeState = struct {
|
const State = struct {
|
||||||
// Counter value at the time the current TimeCounter was selected.
|
// Counter value at the time the current TimeCounter was selected.
|
||||||
// Used as the baseline for elapsed time calculation.
|
// Used as the baseline for elapsed time calculation.
|
||||||
initial_count: u64,
|
initial_count: u64,
|
||||||
@@ -39,7 +39,7 @@ const TimeState = struct {
|
|||||||
|
|
||||||
// SeqLock-protected time state.
|
// SeqLock-protected time state.
|
||||||
// Avoids a race on `initial_count` and `offset` with `update_overflow`.
|
// 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,
|
.initial_count = 0,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
});
|
});
|
||||||
@@ -88,7 +88,7 @@ pub fn register_source(tc: *TimeCounter) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the time elapsed since boot in nanoseconds.
|
/// 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 tc = best_tc orelse return 0;
|
||||||
|
|
||||||
const s = state.load();
|
const s = state.load();
|
||||||
@@ -104,15 +104,15 @@ pub fn best() ?*TimeCounter {
|
|||||||
|
|
||||||
/// Do a busy sleep of `ns` nanoseconds using TimeCounter.
|
/// Do a busy sleep of `ns` nanoseconds using TimeCounter.
|
||||||
pub fn sleep(ns: r.Nanoseconds) void {
|
pub fn sleep(ns: r.Nanoseconds) void {
|
||||||
const start = read_time_nano();
|
const start = read_time();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var cur = read_time_nano();
|
var cur = read_time();
|
||||||
|
|
||||||
if (cur < start) continue;
|
if (cur < start) continue;
|
||||||
|
|
||||||
if (cur - start >= ns) {
|
if (cur - start >= ns) {
|
||||||
cur = read_time_nano();
|
cur = read_time();
|
||||||
|
|
||||||
// Check again as we may have overflowed and read a bogus value..
|
// Check again as we may have overflowed and read a bogus value..
|
||||||
// This is kinda hacky but oh well.
|
// This is kinda hacky but oh well.
|
||||||
|
|||||||
+3
-3
@@ -75,7 +75,7 @@ pub fn set(timer: *Timer, time: r.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.time.read_time_nano() + time;
|
timer.deadline = ke.time.read_time() + time;
|
||||||
|
|
||||||
timer.cpu = cpu;
|
timer.cpu = cpu;
|
||||||
timer.dpc = dpc;
|
timer.dpc = dpc;
|
||||||
@@ -143,7 +143,7 @@ fn handle_expiry(_: ?*anyopaque) void {
|
|||||||
const cpu = percpu.local();
|
const cpu = percpu.local();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const curtime = ke.time.read_time_nano();
|
const curtime = ke.time.read_time();
|
||||||
|
|
||||||
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.time.read_time_nano();
|
const now = ke.time.read_time();
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user