Skip to content

Commit

Permalink
Добавлено время потока
Browse files Browse the repository at this point in the history
  • Loading branch information
0Nera committed Jan 21, 2024
1 parent a59ba34 commit feaab75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 979
#define VERSION_BUILD 983
13 changes: 12 additions & 1 deletion kernel/cpu/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit feaab75

Please sign in to comment.