Task Scheduler
git-svn-id: https://spexeah.com:8443/svn/Asuro@109 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
1 parent
8ce80d46c0
commit
31db2c943b
11 files changed
+86
-3
No files matched your search
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
-3
@@ -13,7 +13,8 @@ uses
|
|||||||
console,
|
console,
|
||||||
bios_data_area,
|
bios_data_area,
|
||||||
keyboard,
|
keyboard,
|
||||||
memorymanager;
|
memorymanager,
|
||||||
|
scheduler;
|
||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
||||||
|
|
||||||
@@ -49,8 +50,9 @@ begin
|
|||||||
idt.init();
|
idt.init();
|
||||||
isr.init();
|
isr.init();
|
||||||
irq.init();
|
irq.init();
|
||||||
|
|
||||||
memorymanager.init();
|
memorymanager.init();
|
||||||
|
scheduler.init();
|
||||||
|
|
||||||
pint2:= kalloc(18);
|
pint2:= kalloc(18);
|
||||||
pint:= kalloc(sizeof(uint32));
|
pint:= kalloc(sizeof(uint32));
|
||||||
if pint = nil then console.writestringln('!');
|
if pint = nil then console.writestringln('!');
|
||||||
@@ -59,13 +61,14 @@ begin
|
|||||||
console.writeintln(pint^);
|
console.writeintln(pint^);
|
||||||
kfree(pint);
|
kfree(pint);
|
||||||
pint2:= kalloc(128);
|
pint2:= kalloc(128);
|
||||||
util.halt_and_catch_fire;
|
|
||||||
|
|
||||||
STI;
|
STI;
|
||||||
isr32.hook(uint32(@bios_data_area.tick_update));
|
isr32.hook(uint32(@bios_data_area.tick_update));
|
||||||
|
|
||||||
//drivers
|
//drivers
|
||||||
keyboard.init(keyboard_layout);
|
keyboard.init(keyboard_layout);
|
||||||
|
scheduler.add_task(5);
|
||||||
|
scheduler.add_task(15);
|
||||||
|
|
||||||
asm
|
asm
|
||||||
MOV dds, CS
|
MOV dds, CS
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
unit scheduler;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
console,
|
||||||
|
isr32,
|
||||||
|
memorymanager;
|
||||||
|
|
||||||
|
const
|
||||||
|
Quantum = 64;
|
||||||
|
|
||||||
|
type
|
||||||
|
TScheduler_Entry = packed record
|
||||||
|
ThreadID : uint32;
|
||||||
|
Priority : uint8;
|
||||||
|
Delta : uint32;
|
||||||
|
Next : void;
|
||||||
|
end;
|
||||||
|
PScheduler_Entry = ^TScheduler_Entry;
|
||||||
|
|
||||||
|
procedure init;
|
||||||
|
procedure add_task(priority : uint8);
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
var
|
||||||
|
Tick : uint32;
|
||||||
|
Root_Task : PScheduler_Entry = nil;
|
||||||
|
Current_Task : PScheduler_Entry = nil;
|
||||||
|
|
||||||
|
procedure context_switch();
|
||||||
|
begin
|
||||||
|
// This will switch contexts eventually,
|
||||||
|
// For now just print upon context switch.
|
||||||
|
Current_Task:= PScheduler_Entry(Current_Task^.Next);
|
||||||
|
console.writestring('Task: ');
|
||||||
|
console.writeintln(Current_Task^.ThreadID);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure add_task(priority : uint8);
|
||||||
|
var
|
||||||
|
new_task : PScheduler_Entry;
|
||||||
|
task : PScheduler_Entry;
|
||||||
|
i : uint32;
|
||||||
|
|
||||||
|
begin
|
||||||
|
new_task:= PScheduler_Entry(kalloc(sizeof(TScheduler_Entry)));
|
||||||
|
new_task^.Priority:= priority;
|
||||||
|
new_task^.Delta:= Tick;
|
||||||
|
new_task^.Next:= void(Root_Task);
|
||||||
|
task:= Root_Task;
|
||||||
|
i:= 1;
|
||||||
|
while PScheduler_Entry(task^.next) <> Root_Task do begin
|
||||||
|
i:= i+1;
|
||||||
|
task:= PScheduler_Entry(task^.next);
|
||||||
|
end;
|
||||||
|
task^.next:= void(new_task);
|
||||||
|
new_task^.ThreadID:= i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure delta(data : void);
|
||||||
|
begin
|
||||||
|
Tick:= Tick + 1;
|
||||||
|
If (Current_Task^.Delta + (Current_Task^.Priority * Quantum)) <= Tick then context_switch();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure init;
|
||||||
|
begin
|
||||||
|
Root_Task:= PScheduler_Entry(kalloc(sizeof(TScheduler_Entry)));
|
||||||
|
Root_Task^.ThreadID:= 0;
|
||||||
|
Root_Task^.Priority:= 1;
|
||||||
|
Root_Task^.Delta:= 0;
|
||||||
|
Root_Task^.Next:= void(Root_Task);
|
||||||
|
Current_Task:= Root_Task;
|
||||||
|
Tick:= 0;
|
||||||
|
isr32.hook(uint32(@delta));
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
Reference in new issue
Block a user