written 5.8 years ago by |
Scheduler - key component of a kernel
A scheduler has algorithms that determine which task executes when.
Scheduler uses following entities/policies for task scheduling.
(a) Schedulable entities
(b) Multitasking
(c) Context Switching
(d) Dispatcher
(e) Scheduling Algorithms
(A) Schedulable entities:
Any task that can be scheduled for execution is a schedulable entity.
For eg: an ISR, a function or any process.
When a schedulable entity enters ready state, it is scheduled to be executed by the processor, as per the order.
(B) Multitasking:
The kernel schedules multiple tasks in such a way that many tasks appear to be executing concurrently.
The scheduler must ensure that the appropriate task runs without any latency.
(C) Context Switching:
Whenever a task is in execution, the registers hold the contents related to that task.
When the OS decides to switch the task, it needs to store this context(contents of ongoing task). For this, OS uses special memory block to store this context called Task Control Block(TCB).
In the TCB, OS stores all the info required by itself and the task for execution.
When a task is running, the context is frequently updating and is maintained in the TCB.
(D) Dispatcher:
- The dispatcher is responsible for dispatching the tasks in the running state. Thus the dispatches controls the task switching and execution flow.
(E) Scheduling Algorithms:
The scheduler determines which tasks run by implementing a scheduling algorithm.
2 types: Preemptive priority based scheduling
$\hspace{2.5cm}$ Round Robin scheduling
Preemptive
- In this scheduling, if a higher priority task enters ready state, then it preempts or suspends the lower priority task and higher priority task enters execution.
Round Robin
- Each task is given a fixed time slot.