ke/wait: add wait_reason

This commit is contained in:
Loïc Grégoire
2026-08-02 00:02:00 -04:00
parent 05c7694776
commit 24372a2b4e
12 changed files with 21 additions and 13 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ fn drain_from_all(seq: usize) usize {
fn worker(_: ?*anyopaque) void {
while (true) {
_ = ke.wait.wait_one(&ke.log.event.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&ke.log.event.hdr, "console_worker", .{}) catch unreachable;
ke.log.event.reset();
last_seq = drain_from_all(last_seq);
+1 -1
View File
@@ -257,7 +257,7 @@ pub fn enqueue(item: *WorkItem) void {
fn pool_manager(_: ?*anyopaque) void {
while (true) {
_ = ke.wait.wait_one(&pool_manager_event.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&pool_manager_event.hdr, "work_pool_manager", .{}) catch unreachable;
// We have been signaled, go through every pool and grow it if needed.
// Failure to grow is ignored, it is only a latency problem and should be fixed
+3 -1
View File
@@ -75,7 +75,9 @@ pub const Queue = struct {
self.hdr.lock.release(ipl);
// Wait until the queue has something for us.
_ = try ke.wait.wait_one(&self.hdr, .{ .timeout = timeout });
_ = try ke.wait.wait_one(&self.hdr, "queue", .{
.timeout = timeout,
});
// Grab the queue item and set it to null.
const ret = td.queue_item orelse unreachable;
+3
View File
@@ -99,6 +99,8 @@ pub const Thread = struct {
/// Current wait status.
wait_status: std.atomic.Value(ki.wait.Status),
waitblocks: [4]ki.wait.WaitBlock,
/// Reason for the wait, if any.
wait_reason: ?[]const u8,
/// Timer used for timeouts.
timer: ke.Timer,
/// Turnstile.
@@ -146,6 +148,7 @@ pub const Thread = struct {
.runq_idx = 0,
.wait_status = .init(.Satisfied),
.waitblocks = undefined,
.wait_reason = null,
.timer = undefined,
.turnstile = undefined,
.turnstile_waiter = null,
+1 -1
View File
@@ -441,7 +441,7 @@ pub fn block(turnstile: ?*Turnstile, obj: *anyopaque, own: Ownership, queue: Que
// Now block on the event.
_ = ke.ipl.lower(.Passive);
_ = ke.wait.wait_one(&waiter.event.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&waiter.event.hdr, "turnstile:waiter", .{}) catch unreachable;
_ = ke.ipl.raise(ipl);
}
+6 -3
View File
@@ -105,9 +105,9 @@ const Options = struct {
/// Wait for the provided object to be signaled.
/// This will only return an error if `timeout` is provided and
/// the wait times out.
pub fn wait_one(object: *DispatchHeader, opts: Options) !usize {
pub fn wait_one(object: *DispatchHeader, reason: []const u8, opts: Options) !usize {
var objects = [_]*DispatchHeader{object};
return wait_any(&objects, opts);
return wait_any(&objects, reason, opts);
}
/// Wait for any of the provided objects to be signaled.
@@ -116,7 +116,7 @@ pub fn wait_one(object: *DispatchHeader, opts: Options) !usize {
/// If `timeout` is not provided, it will wait indefinitely.
/// If `waitblocks` is specified, then the wait will use those waitblocks for the operation.
/// Note that if `timeout` is provided, then one additional waitblock must be allocated.
pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
pub fn wait_any(objects: []*DispatchHeader, reason: []const u8, opts: Options) !usize {
const ipl = ke.ipl.raise(.Dispatch);
defer ke.ipl.lower(ipl);
const curtd = ki.sched.percpu.local().current_thread.?;
@@ -206,6 +206,7 @@ pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
}
}
curtd.wait_reason = reason;
// We're good, now actually block.
ki.sched.block_locked(curtd);
} else {
@@ -221,6 +222,8 @@ pub fn wait_any(objects: []*DispatchHeader, opts: Options) !usize {
ke.timer.cancel(timer);
}
curtd.wait_reason = null;
// Find the object that satisfied us.
for (0..total_count) |i| {
const is_timer = has_timeout and i == timer_i;
+1 -1
View File
@@ -47,7 +47,7 @@ fn wait_for_pages(old_ipl: ke.Ipl) void {
list_lock.release(ipl);
_ = ke.wait.wait_one(&free_page_event.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&free_page_event.hdr, "wait_for_pages", .{}) catch unreachable;
ipl = list_lock.acquire();
cnt = free_pages;
+1 -1
View File
@@ -101,7 +101,7 @@ fn perform_delay(ms: usize) void {
var timer: ke.Timer = undefined;
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * ms, .{});
_ = ke.wait.wait_one(&timer.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&timer.hdr, "sleep", .{}) catch unreachable;
}
fn particle(param: ?*anyopaque) void {
+1 -1
View File
@@ -35,7 +35,7 @@ fn delay_ms(ms: usize) void {
var timer: ke.Timer = undefined;
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * ms, .{});
_ = ke.wait.wait_one(&timer.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&timer.hdr, "sleep", .{}) catch unreachable;
}
fn worker(param: ?*anyopaque) void {
+1 -1
View File
@@ -42,7 +42,7 @@ fn delay_ms(ms: usize) void {
var timer: ke.Timer = undefined;
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * ms, .{});
_ = ke.wait.wait_one(&timer.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&timer.hdr, "sleep", .{}) catch unreachable;
}
fn reader(param: ?*anyopaque) void {
+1 -1
View File
@@ -64,7 +64,7 @@ fn delay_ms(ms: usize) void {
var timer: ke.Timer = undefined;
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * ms, .{});
_ = ke.wait.wait_one(&timer.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&timer.hdr, "sleep", .{}) catch unreachable;
}
/// Park here while the checker is verifying quiescence. Only ever called
+1 -1
View File
@@ -46,7 +46,7 @@ fn delay_ms(ms: usize) void {
var timer: ke.Timer = undefined;
timer.init();
ke.timer.set(&timer, std.time.ns_per_ms * ms, .{});
_ = ke.wait.wait_one(&timer.hdr, .{}) catch unreachable;
_ = ke.wait.wait_one(&timer.hdr, "sleep", .{}) catch unreachable;
}
fn wait_flag(flag: *std.atomic.Value(bool)) void {