mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-31 15:28:21 +00:00
refactor: use root instead of base
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const pl = b.pl;
|
||||
const amd64 = b.arch;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const pl = r.pl;
|
||||
const amd64 = r.arch;
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
pub const init = @import("init.zig");
|
||||
pub const early_init = init.early_init;
|
||||
|
||||
pub export var cpu_self_offset: usize linksection(b.percpu) = 0;
|
||||
pub export var cpu_self_offset: usize linksection(r.percpu) = 0;
|
||||
pub export var cpu_offsets: [*]usize = undefined;
|
||||
|
||||
pub const ThreadContext = struct {
|
||||
@@ -28,7 +28,7 @@ pub const ThreadContext = struct {
|
||||
// TODO: This shouldn't be reached!!!
|
||||
}
|
||||
|
||||
pub fn init(stack: b.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) @This() {
|
||||
pub fn init(stack: r.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) @This() {
|
||||
var ctx: @This() = undefined;
|
||||
ctx.rdi = @intFromPtr(entry);
|
||||
ctx.rsi = @intFromPtr(arg);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const amd64 = @import("arch");
|
||||
const int = @import("int.zig");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const std = @import("std");
|
||||
const impl = @import("impl.zig");
|
||||
const ke = b.ke;
|
||||
const ki = b.ke.private;
|
||||
const pl = b.pl;
|
||||
const ke = r.ke;
|
||||
const ki = r.ke.private;
|
||||
const pl = r.pl;
|
||||
|
||||
var gdt = extern struct {
|
||||
entries: [9]u64 align(1),
|
||||
@@ -28,7 +28,7 @@ var gdt = extern struct {
|
||||
|
||||
extern fn gdt_load(gdtr: *const amd64.Gdtr) callconv(.{ .x86_64_sysv = .{} }) void;
|
||||
|
||||
fn early_cpu_init() linksection(b.init) void {
|
||||
fn early_cpu_init() linksection(r.init) void {
|
||||
const gdtr: amd64.Gdtr = .{
|
||||
.limit = @sizeOf(@TypeOf(gdt)) - 1,
|
||||
.base = @intFromPtr(&gdt),
|
||||
@@ -96,7 +96,7 @@ pub fn ap_entry(cpu_id: u32) noreturn {
|
||||
var initial_offsets: [1]usize = undefined;
|
||||
extern var __percpu_start: u8;
|
||||
|
||||
pub fn early_init() linksection(b.init) void {
|
||||
pub fn early_init() linksection(r.init) void {
|
||||
amd64.detect_cpu_features();
|
||||
early_cpu_init();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const amd64 = @import("arch");
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
extern const __interrupt_vectors: [256]usize;
|
||||
@@ -79,7 +79,7 @@ export fn isr_handler_main(frame: *const amd64.IrqFrame) callconv(.{ .x86_64_sys
|
||||
|
||||
extern fn idt_load(idt_ptr: *const amd64.Idtr) callconv(.{ .x86_64_sysv = .{} }) void;
|
||||
|
||||
pub fn init() linksection(b.init) void {
|
||||
pub fn init() linksection(r.init) void {
|
||||
const idtr: amd64.Idtr = .{
|
||||
.limit = @sizeOf(@TypeOf(idt)) - 1,
|
||||
.base = @intFromPtr(&idt),
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const config = @import("config");
|
||||
const ke = b.ke;
|
||||
const ki = b.ke.private;
|
||||
const ke = r.ke;
|
||||
const ki = r.ke.private;
|
||||
|
||||
extern var __init_array_percpu_start: u8;
|
||||
extern var __init_array_percpu_end: u8;
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
const std = @import("std");
|
||||
const config = @import("config");
|
||||
const rtl = @import("rtl");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
/// Deferred Procedure Call (DPC) structure.
|
||||
@@ -40,9 +40,9 @@ const pcpu = ke.CpuLocal(PerCpu, .{
|
||||
.queue = undefined,
|
||||
});
|
||||
|
||||
export const dpc_percpu_init linksection(b.percpu_init) = &pcpu_init;
|
||||
export const dpc_percpu_init linksection(r.percpu_init) = &pcpu_init;
|
||||
|
||||
fn pcpu_init() linksection(b.init) callconv(.c) void {
|
||||
fn pcpu_init() linksection(r.init) callconv(.c) void {
|
||||
pcpu.local().queue.init();
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -1,15 +1,15 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const pl = b.pl;
|
||||
const ke = b.ke;
|
||||
const arch = b.arch;
|
||||
const r = @import("root");
|
||||
const pl = r.pl;
|
||||
const ke = r.ke;
|
||||
const arch = r.arch;
|
||||
const ki = ke.private;
|
||||
const ex = b.ex;
|
||||
const ex = r.ex;
|
||||
|
||||
var thread0: ke.Thread = undefined;
|
||||
var stack: [8192]u8 align(16) = undefined;
|
||||
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(b.init) void {
|
||||
pub fn init(boot_info: *pl.BootInfo) linksection(r.init) void {
|
||||
ki.impl.early_init();
|
||||
std.log.info("hello, world", .{});
|
||||
pl.early_init(boot_info);
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
/// Interrupt priority level (IPL)
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const rtl = @import("rtl");
|
||||
const pl = b.pl;
|
||||
const ke = b.ke;
|
||||
const pl = r.pl;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
const config = @import("config");
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@
|
||||
//! the next generation and a stub (containing only the descriptor ID) is left at
|
||||
//! the original position so the data ring can be walked linearly during eviction.
|
||||
const std = @import("std");
|
||||
const base = @import("base");
|
||||
const r = @import("root");
|
||||
const rtl = @import("rtl");
|
||||
const ke = base.ke;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
const BlkPos = struct {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
const std = @import("std");
|
||||
const config = @import("config");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const ksyms = @import("ksyms");
|
||||
const ke = b.ke;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
extern var text_start_addr: u8;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
const std = @import("std");
|
||||
const config = @import("config");
|
||||
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const pl = b.pl;
|
||||
|
||||
const init_mod = @import("init.zig");
|
||||
|
||||
pub const impl = if (@hasDecl(config, "CONFIG_ARCH_AMD64"))
|
||||
|
||||
+5
-5
@@ -84,8 +84,8 @@
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const config = @import("config");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
comptime {
|
||||
@@ -274,10 +274,10 @@ pub fn unblock(td: *ke.Thread) void {
|
||||
td.lock.release(ipl);
|
||||
}
|
||||
|
||||
export const sched_percpu_init linksection(b.percpu_init) = &init_cpu;
|
||||
export const sched_percpu_init linksection(r.percpu_init) = &init_cpu;
|
||||
|
||||
/// Initialize a CPU for use by the scheduler.
|
||||
fn init_cpu() linksection(b.init) callconv(.c) void {
|
||||
fn init_cpu() linksection(r.init) callconv(.c) void {
|
||||
var cpu = percpu.local();
|
||||
|
||||
cpu.* = .{
|
||||
@@ -312,7 +312,7 @@ fn init_cpu() linksection(b.init) callconv(.c) void {
|
||||
}
|
||||
|
||||
/// Called on CPU 0 to initialize load balancing mechanisms.
|
||||
pub fn late_init() linksection(b.init) void {
|
||||
pub fn late_init() linksection(r.init) void {
|
||||
balance_dpc = ke.Dpc.init(balance);
|
||||
balance_timer.init();
|
||||
ke.timer.set(&balance_timer, balance_interval * std.time.ns_per_ms, &balance_dpc);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const ke = @import("root").ke;
|
||||
|
||||
/// Simple Spin lock implementation.
|
||||
pub const SpinLock = struct {
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const r = @import("root");
|
||||
const rtl = @import("rtl");
|
||||
|
||||
const ke = b.ke;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
/// Structure representing a kernel thread.
|
||||
@@ -95,7 +95,7 @@ pub const Thread = struct {
|
||||
/// - `stack_size`: Size of the stack
|
||||
/// - `entry`: Entry point of the thread
|
||||
/// - `arg`: Extraneous argument to be passed to `entry`
|
||||
pub fn init(thread: *Thread, stack: b.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) void {
|
||||
pub fn init(thread: *Thread, stack: r.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) void {
|
||||
thread.* = .{
|
||||
.context = .init(stack, stack_size, entry, arg),
|
||||
.lock = .init(),
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
/// TimeCounter structure.
|
||||
@@ -88,7 +88,7 @@ pub fn register_source(tc: *TimeCounter) void {
|
||||
}
|
||||
|
||||
/// Return the time elapsed since boot in nanoseconds.
|
||||
pub fn read_time_nano() b.Nanoseconds {
|
||||
pub fn read_time_nano() r.Nanoseconds {
|
||||
const tc = best_tc orelse return 0;
|
||||
|
||||
const s = state.load();
|
||||
@@ -103,7 +103,7 @@ pub fn best() ?*TimeCounter {
|
||||
}
|
||||
|
||||
/// Do a busy sleep of `ns` nanoseconds using TimeCounter.
|
||||
pub fn sleep(ns: b.Nanoseconds) void {
|
||||
pub fn sleep(ns: r.Nanoseconds) void {
|
||||
const start = read_time_nano();
|
||||
|
||||
while (true) {
|
||||
|
||||
+5
-5
@@ -2,10 +2,10 @@
|
||||
//! Timer objects are useful when one wants to wait a fixed amount of time for an event to occur.
|
||||
const std = @import("std");
|
||||
const rtl = @import("rtl");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
const pl = b.pl;
|
||||
const pl = r.pl;
|
||||
|
||||
const PerCpu = struct {
|
||||
/// Heap of pending timers on this CPU.
|
||||
@@ -30,7 +30,7 @@ pub const Timer = struct {
|
||||
/// Timer state.
|
||||
state: std.atomic.Value(State),
|
||||
/// When the timer is bound to expire.
|
||||
deadline: b.Nanoseconds,
|
||||
deadline: r.Nanoseconds,
|
||||
/// Attached DPC.
|
||||
dpc: ?*ke.Dpc,
|
||||
/// Intrusive pairing heap node.
|
||||
@@ -60,7 +60,7 @@ const percpu = ke.CpuLocal(PerCpu, .{
|
||||
|
||||
/// Start a timer with an expiration time.
|
||||
/// A DPC that will be enqueued upon expiration can be passed.
|
||||
pub fn set(timer: *Timer, time: b.Nanoseconds, dpc: ?*ke.Dpc) void {
|
||||
pub fn set(timer: *Timer, time: r.Nanoseconds, dpc: ?*ke.Dpc) void {
|
||||
const ipl = timer.hdr.lock.acquire();
|
||||
defer timer.hdr.lock.release(ipl);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const c = b.pl.impl.c;
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const c = r.pl.impl.c;
|
||||
const ke = r.ke;
|
||||
const ki = ke.private;
|
||||
|
||||
fn set_signals(enabled: bool) bool {
|
||||
@@ -45,7 +45,7 @@ pub fn restore_interrupts(val: bool) void {
|
||||
}
|
||||
|
||||
pub fn send_resched_ipi(cpu: u32) void {
|
||||
_ = c.pthread_kill(b.pl.impl.percpu.remote(cpu).pthread, c.SIGUSR1);
|
||||
_ = c.pthread_kill(r.pl.impl.percpu.remote(cpu).pthread, c.SIGUSR1);
|
||||
}
|
||||
|
||||
pub const ThreadContext = struct {
|
||||
@@ -58,7 +58,7 @@ pub const ThreadContext = struct {
|
||||
entry(arg);
|
||||
}
|
||||
|
||||
pub fn init(stack: b.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) ThreadContext {
|
||||
pub fn init(stack: r.VAddr, stack_size: usize, entry: *const fn (?*anyopaque) void, arg: ?*anyopaque) ThreadContext {
|
||||
var new: ThreadContext = .{ .ucontext = undefined };
|
||||
|
||||
if (c.getcontext(&new.ucontext) == -1) {
|
||||
@@ -103,13 +103,13 @@ const bootstrap_offsets = [1]usize{0};
|
||||
|
||||
pub fn early_init() void {
|
||||
// Ensure we can use per-cpu data.
|
||||
b.pl.impl.cpu_offsets = @constCast(&bootstrap_offsets);
|
||||
r.pl.impl.cpu_offsets = @constCast(&bootstrap_offsets);
|
||||
}
|
||||
|
||||
pub inline fn percpu_ptr_other(variable: anytype, cpu_id: usize) @TypeOf(variable) {
|
||||
return @ptrFromInt(@intFromPtr(variable) +% b.pl.impl.cpu_offsets[cpu_id]);
|
||||
return @ptrFromInt(@intFromPtr(variable) +% r.pl.impl.cpu_offsets[cpu_id]);
|
||||
}
|
||||
|
||||
pub inline fn percpu_ptr(variable: anytype) @TypeOf(variable) {
|
||||
return @ptrFromInt(@intFromPtr(variable) +% b.pl.impl.cpu_offsets[b.pl.impl.my_cpu_id]);
|
||||
return @ptrFromInt(@intFromPtr(variable) +% r.pl.impl.cpu_offsets[r.pl.impl.my_cpu_id]);
|
||||
}
|
||||
|
||||
+4
-4
@@ -3,8 +3,8 @@
|
||||
//! See more here: https://youtu.be/OAAiOEQhsK0
|
||||
const rtl = @import("rtl");
|
||||
const std = @import("std");
|
||||
const b = @import("base");
|
||||
const ke = b.ke;
|
||||
const r = @import("root");
|
||||
const ke = r.ke;
|
||||
|
||||
/// Header for waitable objects.
|
||||
/// This must be added to any structured which is considered waitable.
|
||||
@@ -73,7 +73,7 @@ pub const Status = enum(u8) {
|
||||
};
|
||||
|
||||
/// Wait for the provided object to be signaled.
|
||||
pub fn wait_one(object: *DispatchHeader, timeout: ?b.Nanoseconds) !usize {
|
||||
pub fn wait_one(object: *DispatchHeader, timeout: ?r.Nanoseconds) !usize {
|
||||
var objects = [_]*DispatchHeader{object};
|
||||
return wait_any(&objects, timeout, null);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ pub fn wait_one(object: *DispatchHeader, timeout: ?b.Nanoseconds) !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, timeout: ?b.Nanoseconds, waitblocks: ?[*]WaitBlock) !usize {
|
||||
pub fn wait_any(objects: []*DispatchHeader, timeout: ?r.Nanoseconds, waitblocks: ?[*]WaitBlock) !usize {
|
||||
const ipl = ke.ipl.raise(.Dispatch);
|
||||
defer ke.ipl.lower(ipl);
|
||||
const curtd = ke.curcpu().current_thread.?;
|
||||
|
||||
Reference in New Issue
Block a user