Thread displacement on multicore systems
On a multicore system, the scheduling policy follows the same rules as on a single-core system. In addition to the policy, the QNX OS scheduler must also adhere to processor affinity.
The OS sometimes makes scheduling decisions that entail thread displacement, which involves preempting a lower-priority thread and running a higher-priority one on a given processor (CPU).
- A high-priority thread T that becomes ready on CPU A and belongs to a cluster that includes CPU A will preempt (displace) a lower-priority thread running on that CPU.
- A thread T that becomes ready on CPU A and belongs to a cluster that includes CPU A will not preempt a lower-priority thread running on another CPU in the cluster.
- A high-priority thread T that becomes ready on CPU A, belongs to a cluster that does not include CPU A, but has higher priority than all of the threads running on CPUs in its cluster, will preempt a lower-priority thread running on another CPU.
- A thread T that becomes ready on CPU A, belongs to a cluster that does not include CPU A, and has higher priority than some but not all of the threads running in its cluster, may or may not preempt a lower-priority thread running on another CPU.
- Any ready thread T will always preempt an idle thread. Thus, when we say that T won't preempt a lower-priority thread, it means a non-idle lower-priority thread.
The end result is that only the highest-priority thread on the system is guaranteed to run on some processor in its cluster. While the highest priority thread gets chosen for each individual scheduling decision, this doesn't mean that on a system with N processors, the N non-blocked threads with the highest priorities will always be running at a given time. For instance, as one thread runs, it may unblock other threads and, consequently, some running threads might have lower priorities than some of those ready to run. In this case, the next time a processor that's running a lower-priority thread makes a scheduling decision, it will choose a higher-priority one.