:::{note} AI Translation Notice
This document was automatically translated by Qwen/Qwen3-8B
model, for reference only.
Source document: kernel/sched/rt.md
Translation time: 2025-05-19 01:41:17
Translation model: Qwen/Qwen3-8B
Please report issues via Community Channel
:::
RT (Real-Time Scheduler), real-time scheduler. Real-time scheduling is a method of allocating CPU resources to complete real-time processing tasks.
In DragonOS, processes are divided into two categories: "real-time processes" and "normal processes". Real-time processes have higher priority than normal processes. If there are real-time processes in the current system's execution queue, the RT scheduler will prioritize selecting a real-time process. If there are multiple real-time processes in the queue, the scheduler will select the one with the highest priority to execute.
RTQueue is a scheduling queue used to store real-time processes with a state of running. Each CPU maintains its own RTQueue, and it primarily uses Vec as the main storage structure to implement this.
RT Scheduler class, which mainly implements the initialization and scheduling function of the RT scheduler.
Currently, the main scheduling policies in DragonOS are SCHED_NORMAL policy | SCHED_FIFO policy | SCHED_RT policy. The specific scheduling policies are as follows:
SCHED_NORMAL policy: SCHED_NORMAL is an "absolute fair scheduling policy", and processes using this policy are scheduled using CFS.
SCHED_FIFO policy: SCHED_FIFO is a "real-time process scheduling policy", which is a first-in-first-out scheduling strategy. This policy does not involve the CPU time slice mechanism. Without a higher-priority process, the process can only wait for other processes to release CPU resources. In the SCHED_FIFO policy, the running time of the process scheduled by the scheduler is not limited and can run for an arbitrary length of time.
SCHED_RR policy: SCHED_RR is a "real-time process scheduling policy", which uses a time-slice rotation mechanism. The time_slice of the corresponding process will decrease during execution. Once the process uses up its CPU time slice, it will be added to the execution queue of the same priority on the same CPU. At the same time, the CPU resource is released, and the CPU usage will be allocated to the next process to execute.
Several commonly used methods
How to create a real-time process
struct process_control_block *pcb_name = kthread_run_rt(&fn_name, NULL, "test create rt pcb");
Where kthread_run_rt is a macro for creating a kernel real-time thread
Meaning of fields related to real-time processes in the PCB
How real-time processes are stored in the queue
Todo