0% found this document useful (0 votes)
22 views25 pages

Ch03 CPU Scheduling

Uploaded by

22070049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views25 pages

Ch03 CPU Scheduling

Uploaded by

22070049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Scheduling Issues

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

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


4
Scheduling
Long-Term Scheduling (Job Scheduling)
▪ Decides when to admit an arrived process for
scheduling, depending on its nature (whether
CPU-bound or I/O-bound) and resources
Medium-Term Scheduling
▪ Decides when to swap out a process from
memory and when to load it back
Short-Term Scheduling (CPU Scheduling)
▪ Decides which ready process to service next on
the CPU and for how long

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


5
Scheduling

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


6
CPU Scheduling
Process scheduler selects among available
processes for the next execution on the CPU
Goal: Maximize CPU use, quickly switch processes
onto CPU
Maintains scheduling queues of processes
▪ Ready queue – set of all processes residing in
main memory, ready and waiting to execute
▪ Wait queues – a set of processes waiting for an
event (i.e., I/O)

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.

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


14
Dispatcher
The Dispatcher module gives control of the CPU to
the process selected by the CPU scheduler:
▪ Switching context
▪ Switching to user mode
▪ Jumping to the proper location in the user
program to restart that program

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.

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


17
Non-preemptive Scheduling Policies
First-come, first-served (FCFS) scheduling
Shortest request next (SRN) scheduling
Highest response ratio next (HRN) scheduling

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


18
Non-preemptive Scheduling Policies
First-Come, First-Served (FCFS) scheduling
▪ Requests are scheduled in the order in which
they arrive in the system

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


19
Non-preemptive Scheduling Policies
Shortest Request Next (SRN) scheduling
▪ Schedules the request with the smallest service
time

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


20
Non-preemptive Scheduling Policies
Highest response ratio next (HRN) scheduling
▪ Selects the process with the highest response
ratio

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


21
Preemptive Scheduling Policies
Round-Robin scheduling with time-slicing (RR)
Least Completed Next (LCN) scheduling
Shortest Time to Go (STG) scheduling

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


22
Preemptive Scheduling Policies
Round-Robin scheduling with time-slicing (RR)
▪ The kernel arranges to raise a timer interrupt
when the time slice elapses.

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


23
Preemptive Scheduling Policies
Least Completed Next (LCN) scheduling
▪ Schedules the process that has so far consumed
the least amount of CPU time

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


24
Preemptive Scheduling Policies
Shortest Time to Go (STG) scheduling
▪ Schedules a process whose remaining CPU time
requirements are the smallest in the system

Source: Dhananjay Dhamdhere - Operating Systems, McGraw Hill (2008)


25

You might also like