refactor: remove ke.Cpu struct

This commit is contained in:
Loïc Grégoire
2026-03-30 17:45:49 -04:00
parent 84500e2ff3
commit faf76ca485
15 changed files with 221 additions and 261 deletions
+25 -11
View File
@@ -19,15 +19,28 @@ pub const Ipl = enum(u8) {
}
};
/// Bitmask of pending software interrupts on this CPU.
const pending_softints = ke.CpuLocal(std.atomic.Value(u8), .init(0));
const PerCpu = struct {
/// Current IPL on this CPU.
ipl: Ipl,
/// Bitmask of pending software interrupts on this CPU.
pending_softints: std.atomic.Value(u8),
};
pub const percpu = ke.CpuLocal(PerCpu, .{
.ipl = .Passive,
.pending_softints = std.atomic.Value(u8).init(0),
});
pub fn current() Ipl {
return percpu.local().ipl;
}
/// Raise IPL to `new`.
/// Panics if the current IPL is higher than requested.
pub fn raise(new: Ipl) Ipl {
const ints = ki.impl.disable_interrupts();
var cpu = ke.curcpu();
var cpu = percpu.local();
const old = cpu.ipl;
if (@intFromEnum(new) < @intFromEnum(old)) {
@@ -49,7 +62,8 @@ pub fn raise(new: Ipl) Ipl {
/// Panics if the current IPL is lower than requested.
pub fn lower(new: Ipl) void {
const ints = ki.impl.disable_interrupts();
var cpu = ke.curcpu();
var cpu = percpu.local();
const cpu_id = ke.cpu.current();
const old = cpu.ipl;
if (@intFromEnum(new) > @intFromEnum(old)) {
@@ -65,7 +79,7 @@ pub fn lower(new: Ipl) void {
ki.impl.restore_interrupts(ints);
if (@intFromEnum(new) < @intFromEnum(Ipl.Dispatch) and is_softint_pending(.Dispatch)) {
ki.dpc.dispatch(cpu);
ki.dpc.dispatch(cpu_id);
}
}
@@ -75,7 +89,7 @@ comptime {
/// Set the hardware IPL to `new`.
pub fn set_hardware(new: Ipl) Ipl {
var cpu = ke.curcpu();
var cpu = percpu.local();
const old = cpu.ipl;
cpu.ipl = new;
@@ -86,15 +100,15 @@ pub fn set_hardware(new: Ipl) Ipl {
}
/// Mark a software interrupt of IPL `ipl` on `cpu` as pending.
pub fn set_softint_pending(cpu: *ke.Cpu, ipl: Ipl) void {
pub fn set_softint_pending(cpu: u32, ipl: Ipl) void {
std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch));
_ = pending_softints.remote(cpu).bitSet(@intCast(@intFromEnum(ipl)), .monotonic);
_ = percpu.remote(cpu).pending_softints.bitSet(@intCast(@intFromEnum(ipl)), .monotonic);
}
/// Mark a software interrupt of IPL `ipl` on `cpu` as handled.
pub fn clear_softint_pending(cpu: *ke.Cpu, ipl: Ipl) void {
pub fn clear_softint_pending(cpu: u32, ipl: Ipl) void {
std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch));
_ = pending_softints.remote(cpu).bitReset(@intCast(@intFromEnum(ipl)), .monotonic);
_ = percpu.remote(cpu).pending_softints.bitReset(@intCast(@intFromEnum(ipl)), .monotonic);
}
/// Check whether a software interrupt of IPL `ipl` on the current CPU is pending.
@@ -102,5 +116,5 @@ pub fn is_softint_pending(ipl: Ipl) bool {
std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch));
const shift: u3 = @intCast(@intFromEnum(ipl));
const bit: u8 = @as(u8, 1) << shift;
return pending_softints.local().load(.monotonic) & bit != 0;
return percpu.local().pending_softints.load(.monotonic) & bit != 0;
}