This is a page about »Scheduler«.
What is a scheduler and why it is needed?
In OS context, scheduling is the action of assigning resources (e.g. CPU, network links etc.) to perform tasks (e.g. threads, processes or data flows). The main objective is to make all resources busy, ensure multiple users to share system resources effectively and achieve a target quality of service. Almost all programs have some alternating cycle of CPU processing and I/O waiting and time spent on the latter is CPU cycles wasted.
- maximizing throughput (total amount of work completed per time unit)
- minimize waiting time (time from work becomes ready to being executed)
- minimize latency/response time (time from work becomes ready until it is finished or until system responds and returns the first output to user)
- maximizing fairness (equal/appropriate CPU time to each processes)
These are some goals of a scheduler and in practice they can be conflicting (throughput vs latency). In real time systems, scheduler also requires to meet deadlines (a particular point of time by which an task (thread or process) must finish executing otherwise can be considered system failure).
Process Scheduler
Scheduler can be categorized depends on the frequency of decision into long-term, medium-term and short-term. Long-term scheduler decides which processes to be admitted to the ready queue in main memory i.e. what to run on system, the degree of concurrency to be supported and how to manage I/O intensive and CPU intensive processes. Medium-term scheduler temporarily removes processes from main memory and place them in secondary memory or vice versa known as swapping in/out.
Dispatcher
Gives CPU the selected process (by scheduler). Enables context switching through saving state of process/thread and loads the new process/thread’s state.
from kernel mode back to user mode
Short-Term Scheduling (CPU Scheduler)
Determines ready, in-memory process to be executed after clock interrupt, I/O interrupt, OS call/signal or CPU idle. The queue might not be a FIFO queue. There are many implementation
Preemptiveness
CPU scheduling take place in the below conditions,
- when process switches from running to waiting state
- when process switches from running to ready state
- when process switches from waiting to ready state
- when process terminates
If only in 1 and 4 it implies it is a nonpreemptive/cooperative system. If it happens in all 4 condition then it is a preemptive system. Preemptive system is in general not suitable for real time systems. Preemption (interruption) during the kernel is busy with system call can be a problem. Most UNIX system address this by making process wait until system call is completed or blocked before allowing preemption. Such implementation would not guarantee real time response.