Scheduling Behavior in Real-Time Operating Systems
- 更新时间2023-02-17
- 阅读时长3分钟
Scheduling Behavior in Real-Time Operating Systems
The way a real-time operating system (RTOS) schedules tasks guarantees that high-priority tasks execute within precise time constraints. Understanding how scheduling works in an RTOS can help you set the right priorities for deterministic tasks in your application.
The following list contains some key concepts that underlie the RTOS scheduling process:
Thread States
At any given time, every thread in a real-time system is either running or blocked.
- The thread finishes executing.
- The thread is preempted by a higher-priority thread.
- The thread becomes blocked by the built-in timing mechanism of a Timed Loop or by a blocking node, such as the Wait node within a While Loop.
When a thread becomes unblocked, it enters the run queue in order of priority.
Priority-Based Scheduling of Timed Loops
The RTOS scheduler handles new Timed Loop threads that enter the run queue in different ways depending on their priorities.
Use the following table to decide how to set relative priorities for Timed Loops in a real-time application so that the application meets timing requirements.
| Priority of new Timed Loop thread | RTOS scheduler behavior |
|---|---|
| Higher priority than running thread | The scheduler preempts the running thread so that the new thread can execute immediately. The preempted thread then moves behind the new thread in the run queue. |
| Equal priority as running thread | The scheduler places the new thread behind all other threads of the same priority in the run queue. Threads of equal priority are scheduled according to a first-in, first-out policy. |
| Lower priority than running thread | The scheduler allows the new thread to run only after all higher-priority threads are blocked. |
Although it seems intuitive to set the priority of each loop based on the importance of the loop, this strategy can cause jitter. Instead, set the priority of each loop based on how important it is for the task fulfill a certain timing guarantee.
相关内容
- Determinism and Jitter in a Real-Time System
Determinism is the characteristic that describes how consistently a system executes tasks within a time constraint.
- Priority Inheritance of Threads
When a lower-priority thread holds a shared resource needed by a higher-priority thread, the real-time controller implements priority inheritance by temporarily increasing the priority of the thread holding the shared resource so that the resource can return promptly to the higher-priority thread.