ke: use assert_interface for ki.impl

This commit is contained in:
Loïc Grégoire
2026-06-26 17:46:25 -04:00
parent 06e0b857ad
commit b67391e1f2
6 changed files with 60 additions and 26 deletions
+1 -6
View File
@@ -28,18 +28,13 @@ pub fn current() u32 {
return id.local().*;
}
comptime {
if (!@hasDecl(ki.impl, "percpu_ptr")) @compileError("impl must provide percpu_ptr()");
if (!@hasDecl(ki.impl, "percpu_ptr_other")) @compileError("impl must provide percpu_ptr_other()");
}
/// Wraps around CPU-local data.
pub fn CpuLocal(comptime T: type, comptime init: T) type {
return struct {
var storage: T linksection(".data.percpu") = init;
/// Return a pointer to local CPU data.
pub fn local() @TypeOf(ki.impl.percpu_ptr(&storage)) {
pub fn local() *T {
return ki.impl.percpu_ptr(&storage);
}
-4
View File
@@ -83,10 +83,6 @@ pub fn lower(new: Ipl) void {
}
}
comptime {
if (!@hasDecl(ki.impl, "set_hardware_ipl")) @compileError("impl must provide set_hardware_ipl()");
}
/// Set the hardware IPL to `new`.
pub fn set_hardware(new: Ipl) Ipl {
var cpu = percpu.local();
+59 -1
View File
@@ -1,6 +1,7 @@
const r = @import("root");
const std = @import("std");
const rtl = @import("rtl");
const config = @import("config");
const init_mod = @import("init.zig");
pub const impl = switch (config.arch) {
@@ -9,6 +10,63 @@ pub const impl = switch (config.arch) {
else => @compileError("unsupported architecture"),
};
const ImplSchema = struct {
pub const ThreadContext = struct {};
/// Set the hardware interrupt priority level.
pub fn set_hardware_ipl(level: ipl.Ipl) void {
_ = level;
}
/// Read a per-cpu pointer on another CPU.
pub fn percpu_ptr_other(variable: anytype, id: u32) @TypeOf(variable) {
_ = id;
}
/// Read a per-cpu pointer on the current CPU.
pub fn percpu_ptr(variable: anytype) @TypeOf(variable) {}
/// Send a rescheduling inter-processor interrupt (IPI)
/// on the target CPU.
pub fn send_resched_ipi(target: u32) void {
_ = target;
}
/// Send a TLB shootdown IPI on the target CPU.
pub fn send_tlb_ipi(target: u32) void {
_ = target;
}
/// Flush the entire TLB on the current CPU.
pub fn flush_full_tlb() void {}
/// Flush the TLB entry matching `va` on the current CPU.
pub fn flush_tlb(va: r.VAddr) void {
_ = va;
}
/// Enable interrupts.
pub fn enable_interrupts() void {}
/// Disable interrupts.
/// Return the previous interrupt state.
pub fn disable_interrupts() bool {
return false;
}
/// Restore the state of interrupts.
pub fn restore_interrupts(state: bool) void {
_ = state;
}
/// Implementation-defined early initialization.
pub fn early_init() void {}
};
comptime {
rtl.assert_interface(impl, ImplSchema);
}
pub const init = init_mod.init;
// === Exported Modules ===
-4
View File
@@ -88,10 +88,6 @@ const r = @import("root");
const ke = r.ke;
const ki = ke.private;
comptime {
if (!@hasDecl(ki.impl, "send_resched_ipi")) @compileError("impl must provide send_resched_ipi");
}
const runqueues_n = 64;
const interactivity_threshold = 30;
const scaling_factor = 50;
-6
View File
@@ -8,12 +8,6 @@ const ke = r.ke;
const ki = ke.private;
const mm = r.mm;
comptime {
if (!@hasDecl(ki.impl, "send_tlb_ipi")) @compileError("impl must provide send_tlb_ipi");
if (!@hasDecl(ki.impl, "flush_full_tlb")) @compileError("impl must provide flush_full_tlb");
if (!@hasDecl(ki.impl, "flush_tlb")) @compileError("impl must provide flush_tlb");
}
/// Structure representing a single shootdown request.
pub const ShootdownState = struct {
/// State of the request.
-5
View File
@@ -167,8 +167,3 @@ pub const Thread = struct {
return self.priority >= Priority.low_interactive and self.priority <= Priority.high_interactive;
}
};
comptime {
if (!@hasDecl(ki.impl, "ThreadContext")) @compileError("impl must provide ThreadContext");
if (!@hasDecl(ki.impl.ThreadContext, "init")) @compileError("ThreadContext must have init()");
}