9#ifndef MAXOS_PROCESSES_SCHEDULER_H
10#define MAXOS_PROCESSES_SCHEDULER_H
12#include <libcommon/vector.h>
22namespace MaxOS::processes {
32 bool m_active =
false;
40 common::Spinlock m_lock;
45 common::Map<uint64_t, uint64_t> m_core_pids;
46 common::Map<uint64_t, uint64_t> m_core_tids;
93 common::Vector<Process*> m_processes;
94 common::Vector<Thread*> m_threads;
96 uint64_t m_next_thread_index;
124 [[nodiscard]] uint64_t
ticks()
const;
125 [[nodiscard]] uint64_t
core_id()
const;
Handles a certain interrupt number.
virtual void handle_interrupt()
Handles an interrupt.
The global scheduler that manages all processes and threads across all cores.
static uint64_t next_pid()
Gets the next usable global PID.
static Scheduler * core_scheduler()
Gets the scheduler for the currently executing core.
static Process * get_process(uint64_t pid)
Gets a process on the currently executing core by its PID.
static uint64_t remove_process(Process *process)
Removes a process from the scheduler if the process has no threads, if it does then the threads are s...
uint64_t add_process(Process *process, Scheduler *scheduler=nullptr)
Adds a process to the least busy core.
static void print_running_header()
Print the header for the running processes in the form ({name}:t{tid}c{core})
static uint64_t next_tid()
Gets the next usable global TID.
uint64_t add_thread(Thread *thread, Scheduler *scheduler=nullptr)
Adds a thread to the least busy core.
static void prepare_initrd(multiboot_tag_module *module)
Loads the initrd into the init program at 0xFFF000.
~GlobalScheduler()
Destroys the global scheduler and frees the per core schedulers.
system::Core * least_busy_core(bool check_threads=false)
Finds the core with the least amount of threads/processes.
static GlobalScheduler * system_scheduler()
Gets the system scheduler.
static Process * current_process()
Gets the process on the currently executing core.
static Thread * get_thread(uint64_t tid)
Gets a thread on the currently executing core by its TID.
static void activate()
Activates each core's scheduler.
static void deactivate()
Deactivates each core's scheduler.
static bool is_active()
Checks if the global scheduler is active.
void balance()
Moves processes and threads between cores to balance the load so that each core has a similar amount ...
static Thread * current_thread()
Gets the thread on the currently executing core.
static void load_multiboot_elfs(system::Multiboot *multiboot)
Loads any valid ELF files from the multiboot structure.
static system::cpu_status_t * force_remove_process(Process *process)
Removes a process from the scheduler and deletes all threads, begins running the next process.
A process that can be scheduled by the Scheduler, wraps & manages threads as well as its own address ...
Schedules processes to run on the core via their threads.
uint64_t remove_process(Process *process)
Removes a process from the scheduler if the process has no threads, if it does then the threads are s...
uint64_t ticks() const
Gets how long the system has been running for.
uint64_t thread_amount()
Gets how many threads are running on this scheduler.
Thread * current_thread()
Gets the currently executing thread.
system::cpu_status_t * force_remove_process(Process *process)
Removes a process from the scheduler and deletes all threads, begins running the next process.
Process * get_process(uint64_t pid)
Gets a process by its PID.
uint64_t add_process(Process *process)
Adds a process to the scheduler.
Thread * get_thread(uint64_t tid)
Gets a thread by its TID.
uint64_t add_thread(Thread *thread)
Adds a thread to the scheduler.
system::cpu_status_t * schedule(system::cpu_status_t *cpu_state)
Schedules the next thread to run.
uint64_t process_amount()
Gets how processes are running on this scheduler.
void activate()
Activates the scheduler.
Process * current_process()
Gets the current process.
uint64_t core_id() const
Gets the core that this scheduler handles processes for.
system::cpu_status_t * schedule_next(system::cpu_status_t *status)
Schedules the next thread to run.
void deactivate()
Deactivates the scheduler.
The execution context of a sub-process thread.
Manages all the resource registries for each resource type.
Manages the creation, retention and destruction of resources representing processes.
A resource registry for a specific resource type.
Manages the creation, retention and destruction of resources representing threads.
Represents a CPU core in the system.
Parses and provides access to Multiboot 2 information.
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
Defines inter-process communication (IPC) methods such as shared memory and message endpoints.
Defines a MemoryManager class for handling memory allocation and deallocation.
Defines Process and Thread classes for managing processes and their execution contexts.
constexpr size_t TICKS_PER_EVENT
Number of times the clock has to interrupt before switching to the next process/thread.
Defines scheduler resource classes for wrapping Processe and Thread objects as Resources in the Globa...
A tag containing information about a loaded module.