![]() |
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. | |
| system::Core * | least_busy_core (bool check_threads=false) |
| Finds the core with the least amount of threads/processes. | |
| uint64_t | add_process (Process *process, Scheduler *scheduler=nullptr) |
| Adds a process to the least busy core. | |
| uint64_t | add_thread (Thread *thread, Scheduler *scheduler=nullptr) |
| 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 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 | prepare_initrd (multiboot_tag_module *module) |
| Loads the initrd into the init program at 0xFFF000. | |
| 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. | |
| virtual | ~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 28 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 29 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 81 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
|
static |
Activates each core's scheduler.
Definition at line 95 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by kernel_main().
Adds a process to the least busy core.
| process | The process to add |
| scheduler | Optional, specify a specific scheduler to add to |
Definition at line 234 of file scheduler.cpp.
References MaxOS::processes::Scheduler::add_process(), MaxOS::processes::Scheduler::core_id(), MaxOS::system::CPU::cores, MaxOS::Logger::DEBUG(), MaxOS::runtime::DEBUG_TARGET, MaxOS::runtime::DO_DEBUGGING, least_busy_core(), MaxOS::processes::Process::name, MaxOS::system::Core::scheduler, and MaxOS::processes::Process::threads().
Referenced by load_multiboot_elfs(), and MaxOS::processes::Scheduler::Scheduler().
Adds a thread to the least busy core.
| thread | The thread to add |
| scheduler | Optional, specify a specific scheduler to add to |
Definition at line 268 of file scheduler.cpp.
References MaxOS::processes::Scheduler::add_thread(), MaxOS::processes::Scheduler::core_id(), MaxOS::system::CPU::cores, MaxOS::Logger::DEBUG(), least_busy_core(), and MaxOS::system::Core::scheduler.
| 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 120 of file scheduler.cpp.
|
static |
Gets the scheduler for the currently executing core.
Definition at line 398 of file scheduler.cpp.
References MaxOS::system::CPU::executing_core(), and MaxOS::system::Core::scheduler.
Referenced by current_process(), current_thread(), handle_interrupt(), MaxOS::system::CPU::PANIC(), and MaxOS::processes::Thread::yield().
|
static |
Gets the process on the currently executing core.
Definition at line 325 of file scheduler.cpp.
References core_scheduler(), and MaxOS::processes::Scheduler::current_process().
Referenced by MaxOS::processes::resources::ProcessResourceRegistry::create_resource(), MaxOS::memory::VirtualMemoryManager::free(), MaxOS::memory::MemoryManager::free(), MaxOS::processes::resources::ProcessResourceRegistry::get_resource(), MaxOS::runtime::GDBServer::handle_remove_breakpoint(), MaxOS::runtime::GDBServer::handle_set_breakpoint(), MaxOS::memory::VirtualMemoryManager::load_shared_memory(), MaxOS::memory::MemoryManager::malloc(), MaxOS::processes::SharedMemory::open(), MaxOS::system::CPU::PANIC(), MaxOS::system::CPU::prepare_for_panic(), print_running_header(), MaxOS::processes::SharedMemory::read(), MaxOS::runtime::GDBServer::send_memory(), MaxOS::processes::resources::BridgeHandler::send_to_bridge(), 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 361 of file scheduler.cpp.
References core_scheduler(), and MaxOS::processes::Scheduler::current_thread().
Referenced by MaxOS::processes::BlockingLock::acquire(), MaxOS::processes::resources::ThreadResourceRegistry::get_resource(), MaxOS::runtime::TrapFlagExcpetion::handle_interrupt(), MaxOS::runtime::BreakPointException::handle_interrupt(), print_running_header(), MaxOS::processes::SharedMessageEndpoint::read(), and MaxOS::processes::resources::BridgeHandler::send_to_bridge().
|
static |
Deactivates each core's scheduler.
Definition at line 106 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by MaxOS::system::CPU::prepare_for_panic().
|
static |
Removes a process from the scheduler and deletes all threads, begins running the next process.
| process | The process to remove |
Definition at line 309 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 338 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by MaxOS::processes::resources::ProcessResourceRegistry::get_resource(), MaxOS::runtime::GDBServer::handle_remove_breakpoint(), MaxOS::runtime::GDBServer::handle_set_breakpoint(), prepare_initrd(), and MaxOS::runtime::GDBServer::send_memory().
|
static |
Gets a thread on the currently executing core by its TID.
| tid | The thread ID |
Definition at line 375 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by MaxOS::processes::resources::ThreadResourceRegistry::get_resource(), and MaxOS::processes::BlockingLock::release().
|
finalvirtual |
Handles the interrupt 0x20.
| status | The current CPU status |
Reimplemented from MaxOS::hardwarecommunication::InterruptHandler.
Definition at line 67 of file scheduler.cpp.
References core_scheduler(), and MaxOS::processes::Scheduler::schedule().
|
static |
Checks if the global scheduler is active.
Definition at line 407 of file scheduler.cpp.
Referenced by MaxOS::system::CPU::prepare_for_panic().
| Core * GlobalScheduler::least_busy_core | ( | bool | check_threads = false | ) |
Finds the core with the least amount of threads/processes.
| check_threads | If true also check for least amount of threads, defaults to false |
Definition at line 130 of file scheduler.cpp.
References MaxOS::system::CPU::cores.
Referenced by add_process(), and add_thread().
|
static |
Loads any valid ELF files from the multiboot structure.
| multiboot | The multiboot structure |
Definition at line 150 of file scheduler.cpp.
References add_process(), MaxOS::Logger::DEBUG(), MaxOS::processes::ELF64::is_valid(), prepare_initrd(), 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 352 of file scheduler.cpp.
Referenced by MaxOS::processes::Scheduler::add_process().
|
static |
Gets the next usable global TID.
Definition at line 389 of file scheduler.cpp.
Referenced by MaxOS::processes::Scheduler::add_thread().
|
static |
Loads the initrd into the init program at 0xFFF000.
| module | The initrd module |
Definition at line 190 of file scheduler.cpp.
References MaxOS::memory::VirtualMemoryManager::allocate(), get_process(), MaxOS::processes::Process::memory_manager, multiboot_tag_module::mod_start, MaxOS::memory::PRESENT, MaxOS::memory::MemoryManager::s_kernel_memory_manager, MaxOS::memory::PhysicalMemoryManager::to_dm_region(), MaxOS::memory::BumpMemoryManager::vmm(), and MaxOS::memory::WRITE.
Referenced by load_multiboot_elfs().
|
static |
Print the header for the running processes in the form ({name}:t{tid}c{core})
Definition at line 214 of file scheduler.cpp.
References MaxOS::Logger::active_logger(), current_process(), current_thread(), MaxOS::system::CPU::executing_core(), MaxOS::system::Core::id, and MaxOS::Logger::printf().
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 293 of file scheduler.cpp.
References MaxOS::system::CPU::cores, and MaxOS::processes::Process::pid().
Referenced by MaxOS::processes::resources::ProcessResource::close(), and MaxOS::processes::resources::ProcessResource::write().
|
static |
Gets the system scheduler.
Definition at line 55 of file scheduler.cpp.
Referenced by MaxOS::processes::resources::ProcessResourceRegistry::create_resource(), load_multiboot_elfs(), MaxOS::system::CPU::prepare_for_panic(), and MaxOS::processes::Scheduler::Scheduler().