Added kinfo, reduced global state
This commit is contained in:
parent
2213707c6a
commit
e72c8fe6fd
30 changed files with 510 additions and 574 deletions
|
|
@ -3,7 +3,7 @@
|
|||
#include <kprint.h>
|
||||
#include <stdint.h>
|
||||
#include <neobbo.h>
|
||||
#include <arch/amd64/hal/smp.h>
|
||||
#include <smp.h>
|
||||
#include <error.h>
|
||||
#include <string.h>
|
||||
#include <mm/kmalloc.h>
|
||||
|
|
@ -22,26 +22,30 @@ int next_pid = 1;
|
|||
|
||||
void idle_task(){
|
||||
for(;;){
|
||||
kprintf("idling!\n");
|
||||
__builtin_ia32_pause();
|
||||
}
|
||||
}
|
||||
|
||||
void test_task(){
|
||||
kprintf("Hello world from scheduled task!\n");
|
||||
for(;;);
|
||||
//for(;;);
|
||||
}
|
||||
|
||||
void best_task(){
|
||||
kprintf("Hello world I am best\n");
|
||||
for(;;);
|
||||
//for(;;);
|
||||
}
|
||||
|
||||
void thread_exit(){
|
||||
asm("cli");
|
||||
|
||||
#ifdef __x86_64__
|
||||
asm("cli");
|
||||
#endif
|
||||
|
||||
cpu_state *cpu = get_cpu_struct();
|
||||
struct thread *p = cpu->current_process;
|
||||
|
||||
if(p == p->next || p->prev == p){
|
||||
if(p == p->next && p->prev == p){
|
||||
// If this is the only thread in the queue then set cpu->head to NULL, so scheduler knows to idle
|
||||
cpu->head = NULL;
|
||||
}else{
|
||||
|
|
@ -115,8 +119,11 @@ struct thread *add_thread(uint64_t *entry){
|
|||
|
||||
[[noreturn]] void sched(){
|
||||
cpu_state *cpu = get_cpu_struct();
|
||||
cpu->scheduler_initialized = true; // Allow us to get interrupts that schedule us
|
||||
for(;;){
|
||||
asm("cli"); // we sti at the end of switch_context
|
||||
#ifdef __x86_64__
|
||||
asm("cli"); // we sti at the end of switch_context
|
||||
#endif
|
||||
|
||||
struct thread *prev = cpu->current_process;
|
||||
|
||||
|
|
@ -144,37 +151,29 @@ void scheduler_init(){
|
|||
cpu_state *cpu = get_cpu_struct();
|
||||
|
||||
if(cpu->current_process != NULL){
|
||||
kprintf("scheduler on CPU {d} already initialized!\n", cpu->lapic_id);
|
||||
kprintf("scheduler on CPU {d} already initialized!\n", cpu->id);
|
||||
return;
|
||||
}
|
||||
|
||||
idle = alloc_thread();
|
||||
idle->context->rip = (uint64_t)idle_task;
|
||||
|
||||
assert(idle != NULL && "Failed to allocate idle task!");
|
||||
|
||||
if(cpu->id == get_kinfo()->bsp_id){
|
||||
idle = alloc_thread();
|
||||
idle->context->rip = (uint64_t)idle_task;
|
||||
assert(idle != NULL && "Failed to allocate idle task!");
|
||||
}
|
||||
|
||||
cpu->current_process = idle;
|
||||
|
||||
cpu->scheduler_stack = kzalloc(4096);
|
||||
cpu->scheduler_context = (struct context*)((uint64_t)cpu->scheduler_stack + 4096 - sizeof(struct context));
|
||||
cpu->scheduler_context->rbp = (uint64_t)cpu->scheduler_context;
|
||||
cpu->scheduler_context->rip = (uint64_t)sched;
|
||||
kprintf("scheduler on CPU {d} initialized!", cpu->id);
|
||||
|
||||
kprintf("og scheduler context: 0x{x}\n", cpu->scheduler_context);
|
||||
|
||||
struct thread *t1 = add_thread((uint64_t*)test_task);
|
||||
memcpy(t1->name, "testt", 6);
|
||||
|
||||
struct thread *t2 = add_thread((uint64_t *)best_task);
|
||||
memcpy(t2->name, "bestt", 6);
|
||||
|
||||
cpu->scheduler_initialized = true; // Allow us to get interrupts that schedule us
|
||||
sched();
|
||||
|
||||
for(;;);
|
||||
}
|
||||
|
||||
|
||||
void yield(){
|
||||
asm("cli");
|
||||
#ifdef __x86_64__
|
||||
asm("cli");
|
||||
#endif
|
||||
switch_context(&get_cpu_struct()->current_process->context, get_cpu_struct()->scheduler_context);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue