Initial scheduler
Fix TSS Also change to .{} syntax where appropriate. Added the SS segment Fixed spelling Refactoring GDT Multitasking working for now WIP scheduler Refactored Bitmap a bit WIP still Task switching working Handlers return the stack pointer that will be used to restore the tasks stack, normal handlers will return the same stack pointer it was called with where task switching will return the stack pointer of the next task and restore its state using the interrupt stub. Initial scheduler done Created a stage 2 init task Change u32 to usize Move Task to arch specific WIP WIP2 Removed esp from task, replaced with stack_pointer Removed the debug logs Fixed init task stack Change pickNextTask to pointer manipulation This allows less allocations so faster switching Temporary enable interrupts for some runtime tests PIT and RTC need interrupts enabled to run their runtime tests Renamed schedule => pickNextTask, comptime bitmap for pids not task init And some other stuff: No pub for the task anymore Use the leak detector allocator Fmt Fix unit tests And some other stuff :P PR review Moved Task out of arch and have the stack init in the arch file Mocking clean up Removed commented code Renamed createTask to scheduleTask where the user will have to provide a task to schedule Removed redundant pub in log runtime test Removed global allocator for scheduler Cleaner assembly in paging Fmt Added new Scheduler test mode Added new test mode to CI Removed one of the prints Added doc comment, task test for i386 Removed test WIP Runtime tests work Have a global set in one task and reacted to in another. Also test that local variables are preserved after a task switch. Removed new lines Increased line length Move the allocation of the bool above the task creation
This commit is contained in:
parent
20826548e8
commit
d600be874c
30 changed files with 1127 additions and 395 deletions
|
@ -27,6 +27,9 @@ pub const TestMode = enum {
|
|||
/// Run the panic runtime test.
|
||||
Panic,
|
||||
|
||||
/// Run the scheduler runtime test.
|
||||
Scheduler,
|
||||
|
||||
///
|
||||
/// Return a string description for the test mode provided.
|
||||
///
|
||||
|
@ -41,6 +44,7 @@ pub const TestMode = enum {
|
|||
.None => "Runs the OS normally (Default)",
|
||||
.Initialisation => "Initialisation runtime tests",
|
||||
.Panic => "Panic runtime tests",
|
||||
.Scheduler => "Scheduler runtime tests",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -143,6 +147,35 @@ pub const RuntimeStep = struct {
|
|||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// This tests the OS's scheduling by checking that we schedule a task that prints the success.
|
||||
///
|
||||
/// Arguments:
|
||||
/// IN/OUT self: *RuntimeStep - Self.
|
||||
///
|
||||
/// Return: bool
|
||||
/// Whether the test has passed or failed.
|
||||
///
|
||||
fn test_scheduler(self: *RuntimeStep) bool {
|
||||
var state: usize = 0;
|
||||
while (true) {
|
||||
const msg = self.get_msg() catch return false;
|
||||
defer self.builder.allocator.free(msg);
|
||||
|
||||
std.debug.warn("{}\n", .{msg});
|
||||
|
||||
// Make sure `[INFO] Switched` then `[INFO] SUCCESS: Scheduler variables preserved` are logged in this order
|
||||
if (std.mem.eql(u8, msg, "[INFO] Switched") and state == 0) {
|
||||
state = 1;
|
||||
} else if (std.mem.eql(u8, msg, "[INFO] SUCCESS: Scheduler variables preserved") and state == 1) {
|
||||
state = 2;
|
||||
}
|
||||
if (state == 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// The make function that is called by the builder. This will create the qemu process with the
|
||||
/// stdout as a Pipe. Then create the read thread to read the logs from the qemu stdout. Then
|
||||
|
@ -204,7 +237,7 @@ pub const RuntimeStep = struct {
|
|||
fn read_logs(self: *RuntimeStep) void {
|
||||
const stream = self.os_proc.stdout.?.reader();
|
||||
// Line shouldn't be longer than this
|
||||
const max_line_length: usize = 128;
|
||||
const max_line_length: usize = 1024;
|
||||
while (true) {
|
||||
const line = stream.readUntilDelimiterAlloc(self.builder.allocator, '\n', max_line_length) catch |e| switch (e) {
|
||||
error.EndOfStream => {
|
||||
|
@ -212,7 +245,10 @@ pub const RuntimeStep = struct {
|
|||
// join the thread to exit nicely :)
|
||||
return;
|
||||
},
|
||||
else => unreachable,
|
||||
else => {
|
||||
std.debug.warn("Unexpected error: {}\n", .{e});
|
||||
unreachable;
|
||||
},
|
||||
};
|
||||
|
||||
// put line in the queue
|
||||
|
@ -270,6 +306,7 @@ pub const RuntimeStep = struct {
|
|||
.None => print_logs,
|
||||
.Initialisation => test_init,
|
||||
.Panic => test_panic,
|
||||
.Scheduler => test_scheduler,
|
||||
},
|
||||
};
|
||||
return runtime_step;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue