CPU scheduler
CPU scheduler is made of 2 components:
- This short-term scheduler - select which task to run
- The dispatcher - switch context, switch to user mode, jump to the proper location in the user program to restart the program
The goal of the scheduling algorithm is to optimize the following, which are sometimes conflicting amongst themselves:
- CPU utilization
- throughput
- turnaround time: from submission of job till finishing the job
- waiting time: time spent in the ready queue
- response time: submission of job till first response
Scheduling algorithms
The algorithms that we have covered in class are:
- first-come, first-served
- shortest-job-first scheduling
- shortest-remaining-time-first shceduling
- priority scheduling
- round-robin scheduling (based on time quantum)
- multilevel queue scheduling (system, interactive, batch)
- multilevel feedback queue scheduling (allowing a process to move between queues)
Algorithm evaluations are through:
- algorithm evaluation
- deterministic modeling
- queueing models
- simulation
- implementation
Some intrinsic issues of multi-processor scheduling (as opposed to uniprocessor scheduling) are:
- processor affinity (soft vs. hard)
- load balancing (push vs. pull migration) - Linux implements both - push is done every 200 ms, pull is done when a processor is empty.
Linux implementation
Linux is preemptive, priority-based (multilevel feedback queue). Each processor maintains its own runqueue and schedules itself independently Each runqueue has two priority arrays - active vs. expired array
There are 0-140 numeric priority values. 0-99 are for real-time system tasks, and 100-140 are for other tasks. Different priority level gets different time slices, which range from 10ms to 100 ms per time slice. Context switching overhead is about 0.1- 1 ms. Roughly 1% overhead due to context switching.
Tasks with more interactivity (I/O related sleep time) will get higher priority (e.g. with -5 nice value). Tasks with shorter sleep time (less interactivity) receives lower priority.
A fun anecdotal information bit. Traditional Unix scheduler uses a simple formula to (re)calculate process priority on a per second interval. The priority is (recent CPU usage divided by 2) + base. Higher the number, lower the priority.
Finally, let's clarify a few key terms:
multiprocessing - multiple CPUs/cores multiprogramming - multiple jobs or processes multithreading - multiple threads per process