diff --git a/include/arch.h b/include/arch.h index 24f657a..d70f415 100644 --- a/include/arch.h +++ b/include/arch.h @@ -20,6 +20,8 @@ typedef struct task { uint64_t rsi, rdi, rsp, rbp; uint64_t cr3; + uint64_t cpu_time; + uint64_t cpu_time_expired; uint64_t id; void *stack; diff --git a/include/version.h b/include/version.h index 81c6401..20594b2 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 1 -#define VERSION_BUILD 979 +#define VERSION_BUILD 983 diff --git a/kernel/cpu/task.c b/kernel/cpu/task.c index 0a99c7f..3c24b1f 100644 --- a/kernel/cpu/task.c +++ b/kernel/cpu/task.c @@ -23,11 +23,20 @@ void task_switch_asm(task_t *, task_t *); void task_switch(struct frame *state) { UNUSED(state); - asm volatile("cli"); + task_t *next = current_task->next; task_t *last = current_task; + if (current_task->cpu_time_expired) { + current_task->cpu_time_expired--; + outb(0x20, 0x20); + task_switch_asm(current_task, current_task); + return; + } + + current_task->cpu_time_expired = current_task->cpu_time; + current_task = next; // LOG("Смена потоков %u->%u\n", last->id, next->id); @@ -55,6 +64,7 @@ uint64_t task_new_thread(void (*func)(void *)) { stack[--stack_top] = (uint64_t)0; new_task->rsp = (uint64_t)new_task->stack + sizeof(uint64_t) * stack_top; + new_task->cpu_time = 500; new_task->id = next_thread_id++; new_task->cr3 = cr3; @@ -89,6 +99,7 @@ void task_init( ) { kernel_task->id = next_thread_id++; kernel_task->rsp = rsp; kernel_task->cr3 = cr3; + kernel_task->cpu_time = 1000; current_task = kernel_task;