mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-31 07:18:22 +00:00
refactor: remove ke.Cpu struct
This commit is contained in:
+25
-11
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user