![]() |
Max OS 0.3
|
Schedules processes to run on the core via their threads. More...
#include <scheduler.h>
Public Member Functions | |
| Scheduler (uint64_t core_id) | |
| Constructs a new Scheduler object and creates the idle process. | |
| system::cpu_status_t * | schedule (system::cpu_status_t *cpu_state) |
| Schedules the next thread to run. | |
| system::cpu_status_t * | schedule_next (system::cpu_status_t *status) |
| Schedules the next thread to run. | |
| uint64_t | add_process (Process *process) |
| Adds a process to the scheduler. | |
| 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) | |
| system::cpu_status_t * | force_remove_process (Process *process) |
| Removes a process from the scheduler and deletes all threads, begins running the next process. | |
| uint64_t | add_thread (Thread *thread) |
| Adds a thread to the scheduler. | |
| Process * | current_process () |
| Gets the current process. | |
| Process * | get_process (uint64_t pid) |
| Gets a process by its PID. | |
| uint64_t | process_amount () |
| Gets how processes are running on this scheduler. | |
| Thread * | current_thread () |
| Gets the currently executing thread. | |
| Thread * | get_thread (uint64_t tid) |
| Gets a thread by its TID. | |
| uint64_t | thread_amount () |
| Gets how many threads are running on this scheduler. | |
| uint64_t | ticks () const |
| Gets how long the system has been running for. | |
| uint64_t | core_id () const |
| Gets the core that this scheduler handles processes for. | |
| void | activate () |
| Activates the scheduler. | |
| void | deactivate () |
| Deactivates the scheduler. | |
Schedules processes to run on the core via their threads.
Definition at line 90 of file scheduler.h.
| Scheduler::Scheduler | ( | uint64_t | core_id | ) |
Constructs a new Scheduler object and creates the idle process.
Definition at line 417 of file scheduler.cpp.
References MaxOS::processes::GlobalScheduler::add_process(), core_id(), MaxOS::system::CPU::cores, MaxOS::memory::MemoryManager::s_kernel_memory_manager, and MaxOS::processes::GlobalScheduler::system_scheduler().
| void Scheduler::activate | ( | ) |
Activates the scheduler.
Definition at line 641 of file scheduler.cpp.
| uint64_t Scheduler::add_process | ( | Process * | process | ) |
Adds a process to the scheduler.
| process | The process to add |
Definition at line 583 of file scheduler.cpp.
References add_thread(), MaxOS::processes::GlobalScheduler::next_pid(), MaxOS::processes::Process::set_pid(), MaxOS::processes::Process::threads(), and MaxOS::processes::Thread::tid.
Referenced by MaxOS::processes::GlobalScheduler::add_process().
| uint64_t Scheduler::add_thread | ( | Thread * | thread | ) |
Adds a thread to the scheduler.
| thread | The thread to add |
Definition at line 605 of file scheduler.cpp.
References MaxOS::processes::GlobalScheduler::next_tid(), and MaxOS::processes::Thread::tid.
Referenced by add_process(), and MaxOS::processes::GlobalScheduler::add_thread().
| uint64_t Scheduler::core_id | ( | ) | const |
Gets the core that this scheduler handles processes for.
Definition at line 633 of file scheduler.cpp.
Referenced by MaxOS::processes::GlobalScheduler::add_process(), MaxOS::processes::GlobalScheduler::add_thread(), and Scheduler().
| Process * Scheduler::current_process | ( | ) |
Gets the current process.
Definition at line 715 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::processes::Thread::parent_pid, and MaxOS::processes::Process::pid().
Referenced by MaxOS::processes::GlobalScheduler::current_process(), current_process(), schedule(), and schedule_next().
| Thread * Scheduler::current_thread | ( | ) |
Gets the currently executing thread.
Definition at line 759 of file scheduler.cpp.
Referenced by current_process(), MaxOS::processes::GlobalScheduler::current_thread(), force_remove_process(), schedule(), and schedule_next().
| void Scheduler::deactivate | ( | ) |
Deactivates the scheduler.
Definition at line 775 of file scheduler.cpp.
| cpu_status_t * Scheduler::force_remove_process | ( | Process * | process | ) |
Removes a process from the scheduler and deletes all threads, begins running the next process.
| process | The process to remove |
Definition at line 687 of file scheduler.cpp.
References current_thread(), MaxOS::processes::Process::remove_thread(), schedule_next(), MaxOS::processes::Process::threads(), and MaxOS::processes::Thread::tid.
| Process * Scheduler::get_process | ( | uint64_t | pid | ) |
Gets a process by its PID.
| pid | The process ID |
Definition at line 735 of file scheduler.cpp.
References MaxOS::processes::Process::pid().
| Thread * Scheduler::get_thread | ( | uint64_t | tid | ) |
Gets a thread by its TID.
| tid | The thread ID |
Definition at line 786 of file scheduler.cpp.
References MaxOS::processes::Thread::tid.
| uint64_t Scheduler::process_amount | ( | ) |
Gets how processes are running on this scheduler.
Definition at line 750 of file scheduler.cpp.
| uint64_t Scheduler::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)
| process | The process to remove |
Definition at line 652 of file scheduler.cpp.
References MaxOS::processes::Thread::thread_state, and MaxOS::processes::Process::threads().
Referenced by schedule_next().
| cpu_status_t * Scheduler::schedule | ( | system::cpu_status_t * | cpu_state | ) |
Schedules the next thread to run.
| cpu_state | The current CPU state |
Definition at line 446 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::processes::Process::is_kernel, schedule_next(), MaxOS::processes::Thread::ticks, and MaxOS::processes::TICKS_PER_EVENT.
Referenced by MaxOS::processes::GlobalScheduler::handle_interrupt().
| cpu_status_t * Scheduler::schedule_next | ( | system::cpu_status_t * | status | ) |
Schedules the next thread to run.
| status | The current CPU status of the thread |
Definition at line 480 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::processes::Thread::execution_state, MaxOS::processes::Thread::parent_pid, remove_process(), MaxOS::processes::Process::remove_thread(), MaxOS::processes::Thread::save_sse_state(), MaxOS::processes::Thread::thread_state, MaxOS::processes::Process::threads(), MaxOS::processes::TICKS_PER_EVENT, MaxOS::processes::Thread::tid, and MaxOS::processes::Thread::wakeup_time.
Referenced by force_remove_process(), schedule(), and MaxOS::processes::Thread::yield().
| uint64_t Scheduler::thread_amount | ( | ) |
Gets how many threads are running on this scheduler.
Definition at line 768 of file scheduler.cpp.
| uint64_t Scheduler::ticks | ( | ) | const |
Gets how long the system has been running for.
Definition at line 623 of file scheduler.cpp.
Referenced by MaxOS::system::CPU::PANIC().