-
Notifications
You must be signed in to change notification settings - Fork 0
Scheduler
The MVM (Micro Virtual Machine) kernel uses a scheduler to manage the concurrent execution of multiple processes. The scheduler employs a round-robin algorithm, allocating a single instruction cycle to each process before switching to the next. This approach prioritises simplicity and reliability over complex scheduling strategies.
The round-robin algorithm is a simple and efficient scheduling technique, particularly well-suited to the MVM's design. Each process in the ready queue is given a single instruction cycle to execute. After the instruction completes, the scheduler selects the next process from the ready queue, effectively creating a circular order of execution.
The scheduler uses the following data structures:
-
Ready Queue: A queue (
LinkedList
) containing the PIDs of processes ready to run. Processes are added to the ready queue when they are created or become ready after being blocked. - Running Process: A variable to store the PID of the currently running process.
The scheduler's algorithm is straightforward.
Its function (eventLoop
) iterates through a list of processes (keepPcs
),
executing a single instruction per process in a round-robin fashion:
-
Get Next Process: Retrieve the next process from the ready queue (using
getNextProcess()
). -
Load Process State: Load the process's state (registers, program counter, etc.) from its PCB (
KProcess
). - Execute Instruction: Execute a single instruction.
-
Save Process State: Save the process's state back into the PCB using the kernels
snapShotManager
. - Add to Ready Queue (if not finished): Add the process to the back of the ready queue, unless the process has ended.
This is repeated until all processes in keepPcs
are finished.
When a process terminates (e.g., by executing the exit
system call or completing its instructions),
the scheduler removes it from the ready queue.
The scheduler is integrated into the kernel (os/OS.kt
).
The kernel is responsible for managing process creation, termination, and other tasks related to process management.
The scheduler runs continuously to ensure processes are able to execute their instructions.
This scheduling model does not prioritise certain processes or consider their CPU usage. It also does not support preemption, and processes are limited to executing a single instruction at a time. A long-running process that does not perform system calls will not give up the processor.
This document provides an overview of the MVM kernel scheduler. For more information on other kernel components, please consult other parts of this wiki.
Built with ❤️ & Kotlin
Getting Started
Assembly Language
Standard Library
- Standard Library Overview
- String Functions
- Array Functions
- Maths Functions
- Clean Functions
- I/O Functions
- System Functions
- Conversion Functions
System Calls
- System Call Overview
- File System Calls
- Process Management Calls
- IPC Calls
- Host OS Calls
- Other System Calls
Kernel + OS
Error Handling
Advanced Topics
Appendix
Project Information