Scheduler

Basic Concepts

The OpenHarmony LiteOS-A kernel uses the preemptive scheduling mechanism for tasks. The task with a higher priority is scheduled over the task with a lower priority. Time slice round-robin is used to schedule tasks with the same priority. The system runs based on the real-time timeline from the startup, which ensures good real-time performance of the scheduling algorithm.

The OpenHarmony scheduling algorithm is embedded with the tickless mechanism, which ensures lower power consumption and on-demand response to tick interrupts. This minimizes useless tick interrupt response time and further improves the real-time performance of the system.

The OpenHarmony process scheduling policy is SCHED_RR, and the thread scheduling policy can be SCHED_RR or SCHED_FIFO.

Threads are the minimum scheduling units in the OpenHarmony.

Working Principles

The OpenHarmony uses process priority queue and thread priority queue for scheduling. The process priority ranges from 0 to 31, and there are 32 process priority bucket queues. Each bucket queue corresponds to a thread priority bucket queue. The thread priority ranges from 0 to 31, and a thread priority bucket queue also has 32 priority queues.

Figure 1 Schematic diagram of scheduling priority bucket queues

The OpenHarmony system starts scheduling after the kernel initialization is complete. The processes or threads created during running are added to the scheduling queues. The system selects the optimal thread for scheduling based on the priorities of the processes and threads and the time slice consumption of the threads. Once a thread is scheduled, it is deleted from the scheduling queue. If a thread is blocked during running, the thread is added to the corresponding blocking queue and triggers scheduling of another thread. If no thread in the scheduling queue can be scheduled, the system selects the thread of the KIdle process for scheduling.

Figure 2 Scheduling process

Development Guidelines

Available APIs

Category

API

Description

System scheduling

LOS_Schedule

Triggers system scheduling.

How to Develop

NOTE: Scheduling cannot be triggered during the system initialization process.