![]() |
Max OS 0.3
|
The global scheduler that manages all processes and threads across all cores. More...
#include <scheduler.h>
Public Member Functions | |
| GlobalScheduler (system::Multiboot &multiboot) | |
| Constructs a new Global Scheduler object. Registers as the interrupt handler for interrupt 0x20 and setups the shared resource registries. Loads any ELF files from the multiboot structure. | |
| ~GlobalScheduler () | |
| Destroys the global scheduler and frees the per core schedulers. | |
| system::cpu_status_t * | handle_interrupt (system::cpu_status_t *status) final |
| Handles the interrupt 0x20. | |
| void | balance () |
| Moves processes and threads between cores to balance the load so that each core has a similar amount of threads and processes. | |
| uint64_t | add_process (Process *process) |
| Adds a process to the least busy core. | |
| uint64_t | add_thread (Thread *thread) |
| Adds a thread to the least busy core. | |
Public Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler | |
| virtual void | handle_interrupt () |
| Handles an interrupt. | |
Static Public Member Functions | |
| static GlobalScheduler * | system_scheduler () |
| Gets the system scheduler. | |
| static Scheduler * | core_scheduler () |
| Gets the scheduler for the currently executing core. | |
| static system::cpu_status_t * | yield (system::cpu_status_t *current) |
| Pass execution to the next thread. | |
| 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. | |
| static void | load_multiboot_elfs (system::Multiboot *multiboot) |
| Loads any valid ELF files from the multiboot structure. | |
| static void | print_running_header () |
| Print the header for the running processes in the form ({name}:t{tid}c{core}) | |
| 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 stopped but the process is not removed (this will be done automatically when all threads are stopped) | |
| 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. | |
| static Process * | current_process () |
| Gets the process on 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 | next_pid () |
| Gets the next usable global PID. | |
| static Thread * | current_thread () |
| Gets the thread on the currently executing core. | |
| static Thread * | get_thread (uint64_t tid) |
| Gets a thread on the currently executing core by its TID. | |
| static uint64_t | next_tid () |
| Gets the next usable global TID. | |
Additional Inherited Members | |
Protected Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler | |
| InterruptHandler (uint8_t interrupt_number, int64_t redirect=-1, uint64_t redirect_index=0) | |
| Creates a new interrupt handler and registers it with the interrupt manager. | |
| ~InterruptHandler () | |
| Destroys the interrupt handler and unregisters it from the interrupt manager. | |
Protected Attributes inherited from MaxOS::hardwarecommunication::InterruptHandler | |
| uint8_t | m_interrupt_number |
| The interrupt number this handler handles. | |
The global scheduler that manages all processes and threads across all cores.
Definition at line 26 of file scheduler.h.
|
explicit |
Constructs a new Global Scheduler object. Registers as the interrupt handler for interrupt 0x20 and setups the shared resource registries. Loads any ELF files from the multiboot structure.
| multiboot | The multiboot structure that may contain ELF files to load |
Definition at line 24 of file scheduler.cpp.
References MaxOS::system::CPU::cores, MaxOS::Logger::INFO(), and load_multiboot_elfs().
| GlobalScheduler::~GlobalScheduler | ( | ) |
Destroys the global scheduler and frees the per core schedulers.
Definition at line 87 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
|
static |
Activates each core's scheduler.
Definition at line 101 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by kernel_main().
| uint64_t GlobalScheduler::add_process | ( | Process * | process | ) |
Adds a process to the least busy core.
| process | The process to add |
Definition at line 186 of file scheduler.cpp.
References MaxOS::processes::Scheduler::add_process(), core_scheduler(), MaxOS::system::CPU::cores, MaxOS::Logger::DEBUG(), MaxOS::common::Map< Key, Value >::insert(), MaxOS::processes::Process::name, and MaxOS::processes::Scheduler::process_amount().
Referenced by load_multiboot_elfs().
| uint64_t GlobalScheduler::add_thread | ( | Thread * | thread | ) |
Adds a thread to the least busy core.
| thread | The thread to add |
Definition at line 217 of file scheduler.cpp.
References MaxOS::processes::Scheduler::add_thread(), core_scheduler(), MaxOS::system::CPU::cores, MaxOS::Logger::DEBUG(), MaxOS::common::Map< Key, Value >::insert(), and MaxOS::processes::Scheduler::thread_amount().
| void GlobalScheduler::balance | ( | ) |
Moves processes and threads between cores to balance the load so that each core has a similar amount of threads and processes.
Definition at line 126 of file scheduler.cpp.
|
static |
Gets the scheduler for the currently executing core.
Definition at line 349 of file scheduler.cpp.
References MaxOS::system::CPU::executing_core(), and MaxOS::system::Core::scheduler.
Referenced by MaxOS::common::BlockingLock::acquire(), add_process(), add_thread(), current_process(), current_thread(), handle_interrupt(), MaxOS::system::CPU::PANIC(), MaxOS::system::SyscallManager::syscall_close_process(), MaxOS::system::SyscallManager::syscall_thread_close(), and yield().
|
static |
Gets the process on the currently executing core.
Definition at line 280 of file scheduler.cpp.
References core_scheduler(), and MaxOS::processes::Scheduler::current_process().
Referenced by MaxOS::filesystem::VFSResourceRegistry::create_resource(), MaxOS::memory::VirtualMemoryManager::free(), MaxOS::filesystem::VFSResourceRegistry::get_resource(), MaxOS::memory::VirtualMemoryManager::load_shared_memory(), MaxOS::processes::SharedMemory::open(), MaxOS::system::CPU::PANIC(), MaxOS::system::CPU::prepare_for_panic(), print_running_header(), MaxOS::processes::SharedMemory::read(), MaxOS::system::SyscallManager::syscall_close_process(), MaxOS::system::SyscallManager::syscall_resource_close(), MaxOS::system::SyscallManager::syscall_resource_open(), MaxOS::system::SyscallManager::syscall_resource_read(), and MaxOS::system::SyscallManager::syscall_resource_write().
|
static |
Gets the thread on the currently executing core.
Definition at line 316 of file scheduler.cpp.
References core_scheduler(), and MaxOS::processes::Scheduler::current_thread().
Referenced by MaxOS::common::BlockingLock::acquire(), print_running_header(), MaxOS::system::SyscallManager::syscall_thread_close(), MaxOS::system::SyscallManager::syscall_thread_sleep(), and yield().
|
static |
Deactivates each core's scheduler.
Definition at line 112 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
|
static |
Removes a process from the scheduler and deletes all threads, begins running the next process.
| process | The process to remove |
Definition at line 264 of file scheduler.cpp.
References MaxOS::system::CPU::cores, and MaxOS::processes::Process::pid().
Referenced by MaxOS::system::CPU::prepare_for_panic().
|
static |
Gets a process on the currently executing core by its PID.
| pid | The process ID |
Definition at line 293 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by MaxOS::system::SyscallManager::syscall_close_process().
|
static |
Gets a thread on the currently executing core by its TID.
| tid | The thread ID |
Definition at line 326 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by MaxOS::common::BlockingLock::release(), and MaxOS::system::SyscallManager::syscall_thread_close().
|
finalvirtual |
Handles the interrupt 0x20.
| status | The current CPU status |
Reimplemented from MaxOS::hardwarecommunication::InterruptHandler.
Definition at line 62 of file scheduler.cpp.
References ASSERT, core_scheduler(), and MaxOS::processes::Scheduler::schedule().
|
static |
Checks if the global scheduler is active.
Definition at line 358 of file scheduler.cpp.
|
static |
Loads any valid ELF files from the multiboot structure.
| multiboot | The multiboot structure |
Definition at line 138 of file scheduler.cpp.
References add_process(), MaxOS::Logger::DEBUG(), MaxOS::processes::ELF64::is_valid(), MaxOS::system::Multiboot::start_tag(), system_scheduler(), and MaxOS::memory::PhysicalMemoryManager::to_dm_region().
Referenced by GlobalScheduler().
|
static |
Gets the next usable global PID.
Definition at line 307 of file scheduler.cpp.
Referenced by MaxOS::processes::Scheduler::add_process().
|
static |
Gets the next usable global TID.
Definition at line 340 of file scheduler.cpp.
Referenced by MaxOS::processes::Scheduler::add_thread().
|
static |
Print the header for the running processes in the form ({name}:t{tid}c{core})
Definition at line 168 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::system::CPU::executing_core(), MaxOS::system::Core::id, and MaxOS::Logger::Out().
Referenced by MaxOS::Logger::set_log_level().
|
static |
Removes a process from the scheduler if the process has no threads, if it does then the threads are stopped but the process is not removed (this will be done automatically when all threads are stopped)
| process | The process to remove |
Definition at line 248 of file scheduler.cpp.
References MaxOS::system::CPU::cores, and MaxOS::processes::Process::pid().
|
static |
Gets the system scheduler.
Definition at line 50 of file scheduler.cpp.
Referenced by load_multiboot_elfs(), MaxOS::system::CPU::prepare_for_panic(), and MaxOS::system::SyscallManager::syscall_close_process().
|
static |
Pass execution to the next thread.
| current | where to resume this thread to |
Definition at line 79 of file scheduler.cpp.
References core_scheduler(), current_thread(), MaxOS::processes::Thread::execution_state, and MaxOS::processes::Scheduler::yield().
Referenced by MaxOS::system::SyscallManager::syscall_thread_sleep(), and MaxOS::system::SyscallManager::syscall_thread_yield().