Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Objectives
To introduce CPU scheduling, which is the basis for multiprogrammed
operating systems
Basic Concepts
Maximum CPU utilization obtained with multiprogramming
CPUI/O Burst Cycle Process execution consists of a cycle of CPU
CPU Scheduler
Selects from among the processes in memory that are ready to
Terminates
Dispatcher
Dispatcher module gives control of the CPU to the process selected
switching context
Scheduling Criteria
CPU utilization keep the CPU as busy as possible
Throughput # of processes that complete their execution per time
unit
ready queue
submitted until the first response is produced, not output (for timesharing environment)
Burst Time
P1
24
P2
P3
P2
24
P3
27
30
P2
0
P3
3
P1
6
30
SJF is optimal gives minimum average waiting time for a given set of
processes
Example of SJF
Process
Arrival Time
Burst Time
P1
0.0
P2
2.0
P3
4.0
P4
5.0
P1
P4
0
P3
9
P2
16
24
exponential averaging
n 1 t n 1 n .
n+1 = n
=1
n+1 = tn
Only the actual last CPU burst counts
n+1 = tn+(1 - ) tn -1 +
+(1 - )j tn -j +
+(1 - )n +1 0
Since both and (1 - ) are less than or equal to 1, each successive
Priority Scheduling
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (smallest
Preemptive
Nonpreemptive
burst time
process
If there are n processes in the ready queue and the time quantum is
q, then each process gets 1/n of the CPU time in chunks of at most
q time units at once. No process waits more than (n-1)q time units.
Performance
q large FIFO
Burst Time
P1
24
P2
P3
P1
0
P2
4
P3
7
P1
10
P1
14
P1
18 22
P1
26
P1
30
Multilevel Queue
Ready queue is partitioned into separate queues:
foreground (interactive)
background (batch)
foreground RR
background FCFS
Fixed priority scheduling; (i.e., serve all from foreground then from
background). Possibility of starvation.
Time slice each queue gets a certain amount of CPU time which
it can schedule amongst its processes; i.e., 80% to foreground in
RR
parameters:
number of queues
Q2 FCFS
Scheduling
Thread Scheduling
Distinction between user-level and kernel-level threads
Many-to-one and many-to-many models, thread library schedules user-
Pthread Scheduling
API allows specifying either PCS or SCS during thread creation
Multiple-Processor Scheduling
CPU scheduling more complex when multiple CPUs are available
Homogeneous processors within a multiprocessor
Asymmetric multiprocessing only one processor accesses the
currently running
soft affinity
hard affinity
Multicore Processors
Recent trend to place multiple processor cores on same physical chip
Faster and consume less power
Multiple threads per core also growing
Solaris Scheduling
Windows XP Priorities
Linux Scheduling
Constant order O(1) scheduling time
Two priority ranges: time-sharing and real-time
Real-time range from 0 to 99 and nice value from 100 to 140
(figure 5.15)
Algorithm Evaluation
Deterministic modeling takes a particular predetermined workload
Queueing models
Implementation
End of Chapter 5
5.08
In-5.7
In-5.8
In-5.9
Dispatch Latency
Priority
2.
* Note the JVM Does Not Specify Whether Threads are Time-Sliced or
Not
Time-Slicing
Since the JVM Doesnt Ensure Time-Slicing, the yield() Method May Be
Used:
while (true) {
// perform CPU-intensive task
...
Thread.yield();
}
This Yields Control to Another Thread of Equal Priority
Thread Priorities
Priority
Comment
Thread.MIN_PRIORITY
Thread.MAX_PRIORITY
Thread.NORM_PRIORITY
Solaris 2 Scheduling