mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Initial process waiting/waking
Processes can now wait on signals/children/time. There is no clock currently so "time" is just a monotonically increating tick count. Added a SLEEP syscall to test this waiting/waking.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
#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"
|
||||
#include "process.h"
|
||||
|
||||
class lapic;
|
||||
struct page_table;
|
||||
@@ -13,42 +11,6 @@ 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);
|
||||
|
||||
/// A process
|
||||
struct process
|
||||
{
|
||||
uint32_t pid;
|
||||
uint32_t ppid;
|
||||
|
||||
uint8_t priority;
|
||||
|
||||
uint8_t reserved0;
|
||||
uint16_t reserved;
|
||||
|
||||
process_flags flags;
|
||||
|
||||
addr_t rsp;
|
||||
page_table *pml4;
|
||||
|
||||
/// Helper to check if this process is ready
|
||||
/// \returns true if the process has the ready flag
|
||||
inline bool ready() { return bitfield_has(flags, process_flags::ready); }
|
||||
};
|
||||
|
||||
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
|
||||
@@ -80,10 +42,17 @@ public:
|
||||
/// \returns A pointer to the current process' process struct
|
||||
inline process * current() { return m_current; }
|
||||
|
||||
/// Look up a process by its PID
|
||||
/// \arg pid The requested PID
|
||||
/// \returns The process matching that PID, or nullptr
|
||||
process_node * get_process_by_id(uint32_t pid);
|
||||
|
||||
/// 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 syscall_dispatch(addr_t, const cpu_state &);
|
||||
friend addr_t isr_handler(addr_t, cpu_state);
|
||||
|
||||
/// Handle a timer tick
|
||||
@@ -91,15 +60,19 @@ public:
|
||||
/// \returns The stack pointer to switch to
|
||||
addr_t tick(addr_t rsp0);
|
||||
|
||||
private:
|
||||
void prune(uint64_t now);
|
||||
|
||||
lapic *m_apic;
|
||||
|
||||
uint32_t m_next_pid;
|
||||
|
||||
process_node *m_current;
|
||||
using process_slab = kutil::slab_allocator<process>;
|
||||
process_slab m_process_allocator;
|
||||
|
||||
process_node *m_current;
|
||||
process_list m_runlists[num_priorities];
|
||||
process_list m_blocked;
|
||||
process_list m_exited;
|
||||
|
||||
static scheduler s_instance;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user