diff options
| author | Ada Christine <adachristine18@gmail.com> | 2026-05-22 17:47:03 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2026-05-22 17:47:03 +0000 |
| commit | 3bbd1849d38ed66afd1ba8abb59ac6cdb12138d6 (patch) | |
| tree | 805d58790fb1f5962190c1b6328fbbf592090b49 /kc/core/task.c | |
| parent | 1da7411533622bd5c89034fc961bd510b132ea26 (diff) | |
cleanup, second thread for testing differential sleeps
Diffstat (limited to 'kc/core/task.c')
| -rw-r--r-- | kc/core/task.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/kc/core/task.c b/kc/core/task.c index dc7e218..e5933bd 100644 --- a/kc/core/task.c +++ b/kc/core/task.c @@ -16,8 +16,6 @@ #include "arch_thread.h" -extern uint64_t *get_tss_rsp0(void); - static void lock_scheduler(void); static void unlock_scheduler(void); static void lock_preempt(void); @@ -70,14 +68,16 @@ static void *idle_thread_entry(void *) return nullptr; } -static void *sleepy_thread_entry(void *) +static void *sleepy_thread_entry(void *p) { + uint64_t sleep_nanoseconds = (uint64_t)p; int thread_slept_count = 0; while (true) { - sleep_thread(1000000000); + sleep_thread(sleep_nanoseconds); thread_slept_count++; + kprintf("thread slept %d times\n", thread_slept_count); } (void)thread_slept_count; @@ -100,8 +100,10 @@ noreturn void task_init(void) timesource->nanoseconds_delta()); idle_thread = create_thread(idle_thread_entry, nullptr); - struct kc_thread *sleepy_thread = create_thread(sleepy_thread_entry, nullptr); + struct kc_thread *sleepy_thread = create_thread(sleepy_thread_entry, (void *)3000000000); + struct kc_thread *sleepy_thread2 = create_thread(sleepy_thread_entry, (void *)5000000000); ready_thread_push(sleepy_thread); + ready_thread_push(sleepy_thread2); __asm__ volatile ("movq %%rsp, %0" : "=g"(boot_thread.kernel_stack_pointer) :); ready_thread_push(idle_thread); block_thread(BLOCKED); @@ -110,9 +112,19 @@ noreturn void task_init(void) PANIC(DEAD_END); } +static inline bool check_preempt_count() +{ + if (atomic_load(&preempt_switch_count) > 0) + { + return true; + } + + return false; +} + void task_schedule(void) { - if (atomic_load(&preempt_switch_count)) + if (check_preempt_count()) { preempt_switch_flag = true; return; @@ -134,10 +146,6 @@ void task_schedule(void) { return; } - else - { - // NULL statement????? idon't like - } } set_thread(this_thread); } @@ -162,7 +170,7 @@ static void unlock_scheduler(void) static void unlock_preempt(void) { - if (atomic_load(&preempt_switch_count) >= 1) + if (atomic_load(&preempt_switch_count) > 0) { preempt_switch_count--; } @@ -343,7 +351,6 @@ static int sleeping_thread_callback(uint64_t nanoseconds) if (this_thread->sleep_expiration <= nanoseconds) { - kprintf("thread awakened: %p\n", this_thread); this_thread->sleep_expiration = 0; unblock_thread(this_thread); } |
