mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Initial priority-based scheduler
- Scheduler now has multiple linked_lists of processes at different priorities - Process structure improvements - scheduler::tick() and scheduler::schedule() separation
This commit is contained in:
@@ -1,25 +1,57 @@
|
||||
#pragma once
|
||||
/// \file scheduler.h
|
||||
/// The task scheduler and related definitions
|
||||
#include "kutil/enum_bitfields.h"
|
||||
#include "kutil/linked_list.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "kutil/slab_allocator.h"
|
||||
#include "kutil/vector.h"
|
||||
|
||||
class lapic;
|
||||
struct page_table;
|
||||
struct cpu_state;
|
||||
|
||||
extern "C" addr_t isr_handler(addr_t, cpu_state);
|
||||
|
||||
enum class process_flags : uint32_t
|
||||
{
|
||||
running = 0x00000001,
|
||||
ready = 0x00000002,
|
||||
loading = 0x00000004,
|
||||
|
||||
const_pri = 0x80000000,
|
||||
|
||||
none = 0x00000000
|
||||
};
|
||||
IS_BITFIELD(process_flags);
|
||||
|
||||
struct process
|
||||
{
|
||||
uint16_t pid;
|
||||
uint32_t pid;
|
||||
uint32_t ppid;
|
||||
|
||||
uint8_t priority;
|
||||
|
||||
uint8_t reserved0;
|
||||
uint16_t reserved;
|
||||
|
||||
process_flags flags;
|
||||
|
||||
addr_t rsp;
|
||||
page_table *pml4;
|
||||
};
|
||||
|
||||
using process_list = kutil::linked_list<process>;
|
||||
using process_node = process_list::item_type;
|
||||
using process_slab = kutil::slab_allocator<process>;
|
||||
|
||||
/// The task scheduler
|
||||
class scheduler
|
||||
{
|
||||
public:
|
||||
static const uint8_t num_priorities = 8;
|
||||
static const uint8_t default_priority = num_priorities / 2;
|
||||
|
||||
/// Constructor.
|
||||
/// \arg apic Pointer to the local APIC object
|
||||
scheduler(lapic *apic);
|
||||
@@ -34,20 +66,34 @@ public:
|
||||
/// timer interrupts or other preemption methods.
|
||||
void start();
|
||||
|
||||
/// Handle a timer tick
|
||||
/// Run the scheduler, possibly switching to a new task
|
||||
/// \arg rsp0 The stack pointer of the current interrupt handler
|
||||
/// \returns The stack pointer to handler to switch to
|
||||
addr_t tick(addr_t rsp0);
|
||||
/// \returns The stack pointer to switch to
|
||||
addr_t schedule(addr_t rsp0);
|
||||
|
||||
/// Get the current process.
|
||||
/// \returns A pointer to the current process' process struct
|
||||
inline process * current() { return m_current; }
|
||||
|
||||
/// Get a reference to the system scheduler
|
||||
/// \returns A reference to the global system scheduler
|
||||
static scheduler & get() { return s_instance; }
|
||||
|
||||
private:
|
||||
friend addr_t isr_handler(addr_t, cpu_state);
|
||||
|
||||
/// Handle a timer tick
|
||||
/// \arg rsp0 The stack pointer of the current interrupt handler
|
||||
/// \returns The stack pointer to switch to
|
||||
addr_t tick(addr_t rsp0);
|
||||
|
||||
lapic *m_apic;
|
||||
kutil::vector<process> m_processes;
|
||||
uint16_t m_current;
|
||||
uint16_t m_next_pid;
|
||||
|
||||
uint32_t m_next_pid;
|
||||
|
||||
process_node *m_current;
|
||||
process_slab m_process_allocator;
|
||||
process_list m_runlists[num_priorities];
|
||||
|
||||
static scheduler s_instance;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user