Skip to content

Commit

Permalink
jytjytjty
Browse files Browse the repository at this point in the history
Signed-off-by: TalonFloof <[email protected]>
  • Loading branch information
TalonFloof committed Nov 14, 2024
1 parent a303dd5 commit 60ad6a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
23 changes: 15 additions & 8 deletions kobold/hal/alarmqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@ const physmem = @import("root").physmem;
pub const AlarmQueueNode = struct {
deadline: u64,
data: ?*anyopaque = null,
func: *fn(?*anyopaque) callconv(.C) void,
func: *fn (?*anyopaque) callconv(.C) void,
};

const AlarmQueueList = std.DoublyLinkedList(AlarmQueueNode);
pub const AlarmQueue = struct {
lock: Spinlock = .unaquired,
list: AlarmQueueList = .{},
timerCounter: u64 = 0,
timerNextInterval: u64 = 0,

pub fn addAlarm(timeout: u64, func: *fn(?*anyopaque) callconv(.C) void, data: ?*anyopaque) void {
const node = @ptrCast(@alignCast(physmem.Allocate(@sizeOf(AlarmQueueList.Node),@alignOf(AlarmQueueList.node)).?));
pub fn addAlarm(self: *AlarmQueue, timeout: u64, func: *fn (?*anyopaque) callconv(.C) void, data: ?*anyopaque) void {
const old = hal.arch.intControl(false);
self.lock.acquire();
const node: AlarmQueueList.Node = @ptrCast(@alignCast(physmem.Allocate(@sizeOf(AlarmQueueList.Node), @alignOf(AlarmQueueList.node)).?));
node.data.deadline = hal.arch.getHart().timerCounter + timeout;
node.data.data = data;
node.data.func = func;
self.schedule();
self.lock.release();
_ = hal.arch.intControl(old);
}

fn recalibrate() void {
fn schedule(self: *AlarmQueue) void {
const elapsedTime = hal.arch.getHart().timerNextInterval - hal.arch.getRemainingTime();
var ind = list.first;
while(ind != null) {
var closestDeadline: u64 = 0xffff_ffff_ffff_ffff;
var ind = self.list.first;
while (ind != null) {
ind = ind.?.next;
}
}
};
};
4 changes: 2 additions & 2 deletions kobold/hal/hart.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const alarmqueue = @import("alarmqueue.zig");

pub const HartInfo = struct {
pub const ArchData: type = switch (builtin.cpu.arch) {
Expand All @@ -25,8 +26,7 @@ pub const HartInfo = struct {
activeContextStack: usize = 0,
activeSyscallStack: usize = 0,
trapStack: usize = 0,
timerCounter: u64 = 0, // In microseconds
timerNextInterval: u64 = 0, // The inital set time of the timer, in microseconds
alarmQueue: alarmqueue.AlarmQueue = .{},
archData: ArchData = ArchData{},
hartID: usize = 0,

Expand Down
4 changes: 2 additions & 2 deletions kobold/hal/x86_64/timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ pub fn setDeadline(microsecs: usize) void {

pub fn getRemainingUs() usize {
const count = 0xffffffff - apic.read(0x390);
returns @intFromFloat(@as(f64, @floatFromInt(count)) * (@as(f64, @floatFromInt(ticksPerSecond)) / 1000000.0));
}
return @intFromFloat(@as(f64, @floatFromInt(count)) * (@as(f64, @floatFromInt(ticksPerSecond)) / 1000000.0));
}

0 comments on commit 60ad6a6

Please sign in to comment.