Ch03 CPU Scheduling
Ch03 CPU Scheduling
Application profile:
▪ A program alternates between CPU and I/O
▪ The process is CPU-bound (mainly CPU usage)
or I/O-bound (mostly I/O wait)
When to schedule
▪ When a process is created/ terminates
▪ When a process issues a blocking call
▪ On I/O interrupt
2
Scheduling Issues
Is preemption allowed?
▪ Nonpreemptive scheduler does not use clock
interrupts to stop a process
Different applications require different optimization
criteria
▪ Batch systems (throughput, turnaround time)
▪ Interactive system (response time, fairness, user
expectation)
▪ Real-time systems (meeting deadlines)
3
Scheduling
Scheduling is the activity of selecting the next
request to be serviced by a server
▪ In an OS, a request is the execution of a job or a
process, and the server is the CPU
7
Ready and Wait Queues
8
Representation of Process Scheduling
9
CPU Scheduling
Maximum CPU utilization
CPU–I/O Burst Cycle – Process
execution consists of a cycle of
CPU execution and I/O wait
CPU burst followed by I/O burst
10
Benefits of threads
Responsiveness – may allow continued execution if
part of the process is blocked, especially important
for user interfaces
Resource Sharing – threads share resources of
process, easier than shared memory or message
passing
Economy – cheaper than process creation, thread
switching lower overhead than context switching
Scalability – process can take advantage of
multicore architectures
11
CPU Scheduler
The CPU scheduler selects from among the
processes in the ready queue, and allocates a CPU
core to one of them
CPU scheduling decisions may take place when a
process:
▪ Switches from running to waiting state
▪ Switches from running to ready state
▪ Switches from waiting to ready
▪ Terminates
12
Diagram of Process States
2 4
1
3
13
Kinds of Scheduling
Non-preemptive scheduling: A process runs to
completion when scheduled
Preemptive scheduling: take CPU from the process.
15
Dispatcher
Dispatch latency is the time it takes for the
dispatcher to stop one process and start another
running
16
Scheduling Criteria
Completion time (c): Time when a job or process is
completed
Turnaround time (ta): Time between the submission
of a job or process and its completion by the
system. This concept is meaningful for
noninteractive jobs or processes only.
Weighted turnaround (w): Ratio of the turnaround
time of a job or process to its own service time.