Process scheduling
The Kersel's scheduler makes scheduling decisions when:
- a process becomes unblocked;
- the timeslice for a running process expires;
- a running process is preempted.
In QNX, every process has its own priority. The scheduler selects the
next process to run by looking at the priority assigned to every process
that is READY. The process with the highest priority is selected to run.
The prioriries assigned to processes range from 0 (the lowest) to
31 (the highest). The default priority for a new process is inherited
from its parent, this is normally set to 10 for programs started by
the shell. You can use getprio() C function to
determine the priority of a process and setprio() C function to set the
priority of a process. QNX provides three scheduling methods: FIFO,
round-robin, and adaptive scheduling. Each process on the system my
run any one of these methods. These scheduling methods apply only when
two or more processes that shere the same priority are READY. If a
higher priority process becomes ready, it immediatelly preempts all
lower-priority processes.
The scheduling method of a process is inherited from its parent
process, but it can be changed using sched_setscheduler() C function
or it cab be determined by the sched_getscheduler() C
function.
FIFO scheduling
In FIFO scheduling, a process selected to run continues executing
until it:
- voluntarily relinquishes (e.g. it blocks)
- is preempted by a higher-priority process
Two process that run at the same priority level can use FIFO
scheduling to ensure mutual exclusion to a shared resource. Neither
process will be preempted by the other while it is executing.
Round-robin scheduling
In round-robin scheduling, a process selected to run continues
executing until it:
- voluntarily relinquishes control
- is preempted by a higher-priority process
- consumes its timeslice
A timeslice is the unit of time assigned to every process. Once it
consumes its timeslice, a process is preempted and the next READY
process at the same priority level is given control. A timeslice is
100 milliseconds. Apart from time slicing, round-robin scheduling is
identical to FIFO scheduling.
Adaptive scheduling
In adaptive scheduling, a process behaves as follows:
- If the process consumes its timeslice (i.e. it does not
block), its priority is reduced by 1 if another process at the same
priority is READY. This is known as priority decay.
- If the process has decayed and remains unscheduled for one second,
its priority is boosted by 1 (a process is never boosted above its
original priority).
- If the process blocks, it immediately reverts to its original
priority.
You can use adaptive scheduling in envirinments where potentially
compute-intensive background processes are shering the computer with
interactive users. You should find that adaptive scheduling gives
retains fast interactive response for other processes. Adaptive
scheduling is the default scheduling method for programs created by
the shell.