[kernel] Keep other threads out of idle priority

Split out different constants for scheduler::idle_priority and
scheduler::max_priority, so that threads never fall to the same priority
level as the idle threads.
This commit is contained in:
Justin C. Miller
2023-02-18 14:17:57 -08:00
parent e250aaef30
commit 8817766469
5 changed files with 10 additions and 9 deletions

View File

@@ -12,7 +12,6 @@
#include "logger.h" #include "logger.h"
#include "msr.h" #include "msr.h"
#include "objects/thread.h" #include "objects/thread.h"
#include "scheduler.h"
#include "syscall.h" #include "syscall.h"
#include "tss.h" #include "tss.h"
@@ -162,7 +161,6 @@ cpu_init(cpu_data *cpu, bool bsp)
obj::thread *idle = obj::thread::create_idle_thread( obj::thread *idle = obj::thread::create_idle_thread(
g_kernel_process, g_kernel_process,
scheduler::max_priority,
cpu->rsp0); cpu->rsp0);
cpu->thread = idle; cpu->thread = idle;

View File

@@ -171,9 +171,9 @@ thread::setup_kernel_stack()
} }
thread * thread *
thread::create_idle_thread(process &kernel, uint8_t pri, uintptr_t rsp0) thread::create_idle_thread(process &kernel, uintptr_t rsp0)
{ {
thread *idle = new thread(kernel, pri, rsp0); thread *idle = new thread(kernel, scheduler::idle_priority, rsp0);
idle->set_state(state::constant); idle->set_state(state::constant);
idle->set_state(state::ready); idle->set_state(state::ready);
return idle; return idle;

View File

@@ -168,9 +168,8 @@ public:
/// Create the kernel idle thread /// Create the kernel idle thread
/// \arg kernel The process object that owns kernel tasks /// \arg kernel The process object that owns kernel tasks
/// \arg pri The idle thread priority value
/// \arg rsp The existing stack for the idle thread /// \arg rsp The existing stack for the idle thread
static thread * create_idle_thread(process &kernel, uint8_t pri, uintptr_t rsp); static thread * create_idle_thread(process &kernel, uintptr_t rsp);
protected: protected:
/// Don't delete a thread on no handles, the scheduler takes /// Don't delete a thread on no handles, the scheduler takes

View File

@@ -226,8 +226,8 @@ scheduler::steal_work(cpu_data &cpu)
size_t stolen = 0; size_t stolen = 0;
// Don't steal from max_priority, that's the idle thread // Steal from most urgent queues first, don't steal idle threads
for (unsigned pri = 0; pri < max_priority; ++pri) for (unsigned pri = 0; pri < idle_priority; ++pri)
stolen += balance_lists(my_queue.ready[pri], other_queue.ready[pri], cpu); stolen += balance_lists(my_queue.ready[pri], other_queue.ready[pri], cpu);
stolen += balance_lists(my_queue.blocked, other_queue.blocked, cpu); stolen += balance_lists(my_queue.blocked, other_queue.blocked, cpu);
@@ -334,6 +334,7 @@ void
scheduler::maybe_schedule(TCB *t) scheduler::maybe_schedule(TCB *t)
{ {
cpu_data *cpu = t->cpu; cpu_data *cpu = t->cpu;
kassert(cpu, "thread with a null cpu");
run_queue &queue = m_run_queues[cpu->index]; run_queue &queue = m_run_queues[cpu->index];
uint8_t current_pri = queue.current->priority; uint8_t current_pri = queue.current->priority;

View File

@@ -29,8 +29,11 @@ public:
/// Total number of priority levels /// Total number of priority levels
static const uint8_t num_priorities = 8; static const uint8_t num_priorities = 8;
/// Idle task priority, less urgent than anything
static const uint8_t idle_priority = num_priorities - 1;
/// Maximum (least urgent/interactive) priority /// Maximum (least urgent/interactive) priority
static const uint8_t max_priority = num_priorities - 1; static const uint8_t max_priority = idle_priority - 1;
/// Default priority on process creation /// Default priority on process creation
static const uint8_t default_priority = 1; static const uint8_t default_priority = 1;