/    /  OS – Thread Scheduling

Thread scheduling

 

The scheduling of thread involves two boundary scheduling:

  1. Scheduling of Kernel-Level Threads by the system scheduler.
  2. Scheduling of User-Level Threads or ULT to Kernel-Level Threads or KLT by using Lightweight process or LWP. 

 

Lightweight process (LWP):

The Lightweight process is threads that act as an interface for the User-Level Threads to access the physical CPU resources. 

The number of the lightweight processes depends on the type of application, for an I\O bound application the number of LWP depends on the user level threads, and for CPU bound application each thread is connected to a separate kernel-level thread.

 

In real-time, the first boundary of thread scheduling is beyond specifying the scheduling policy and the priority, therefore, it requires two controls to be specified for the User level threads: 

  1. Contention scope – Control scope defines the extent to which contention takes place. Contention refers to the competition among the ULTs to access the KLTs.

Contention scope can be further classified into Process Contention Scope (PCS) and System Contention Scope (SCS).

 

  • Process Contention Scope: Process Contention Scope is when the contention takes place in the same process. 
  • System contention scope (SCS): System Contention Scope refers to the contention that takes place among all the threads in the system. 

 

 

  1.  Allocation domain – The allocation domain is a set of multiple (or single) resources for which a thread is competing. 

Advantages of PCS over SCS:

The advantages of PCS over SCS are as follows:

  1. It is cheaper.
  2. It helps reduce system calls and achieve better performance.
  3. If the SCS thread is a part of more than one allocation domain, the system will have to handle multiple interfaces. 
  4. PCS thread can share one or multiple available LWPs, while every SCS thread needs a separate LWP. Therefore, for every system call, a separate KLT will be created.

 

Reference:

Thread Scheduling.