4. CPU Scheduling
4. CPU Scheduling
Basic Concepts
Maximum CPU utilization
obtained with
multiprogramming
0 24 27 30
P2 P3 P1
0 3 6 30
0 3 9 16 24
P1 P2 P4 P1 P3
0 1 5 10 17 26
Commonly, α set to ½
Shortest Remaining Time First
Scheduling
P1 P2 P4 P1 P3
0 1 5 10 17 26
The CPU is allocated to the process with the highest priority (smallest integer
highest priority)
• Preemptive
• Nonpreemptive
SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
With priority
scheduling, have
separate queues for
each priority.
Schedule the
process in the
highest-priority
queue!
Multilevel Queue
Linux scheduling
Windows scheduling
Solaris scheduling
Linux Scheduling Through Version 2.5
Prior to kernel version 2.5, ran variation of standard UNIX scheduling algorithm
Version 2.5 moved to constant order O(1) scheduling time
◦ Preemptive, priority based
◦ Two priority ranges: time-sharing and real-time
◦ Real-time range from 0 to 99 and nice value from 100 to 140
◦ Map into global priority with numerically lower values indicating higher priority
◦ Higher priority gets larger q
◦ Task run-able as long as time left in time slice ( active)
◦ If no time left (expired), not run-able until all other tasks use their slices
◦ All run-able tasks tracked in per-CPU runqueue data structure
Two priority arrays (active, expired)
Tasks indexed by priority
When no more active, arrays are exchanged
◦ Worked well, but poor response times for interactive processes
Linux Scheduling in Version 2.6.23 +
Priority-based scheduling
Six classes available
◦ Time sharing (default) (TS)
◦ Interactive (IA)
◦ Real time (RT)
◦ System (SYS)
◦ Fair Share (FSS)
◦ Fixed priority (FP)
Given thread can be in one class at a time
Each class has its own scheduling algorithm
Time sharing is multi-level feedback queue
◦ Loadable table configurable by sysadmin