Chapter-3 CPU Scheduling
Chapter-3 CPU Scheduling
Scheduling Criteria
▪ Used for comparing CPU-scheduling algorithms.
The criteria include the following:
▪ CPU utilization – keep the CPU as busy as
possible. It can range from 0 to 100 percent.
▪ Throughput – # of processes that complete their
execution per unit time. Work completed per unit
time is called Throughput.
▪ Turnaround time(TAT) – It is the time interval from
the time of submission (AT) of a process to the time
of the completion (CT) of the process.
▪ TAT = CT - AT
WT = TAT - BT
Scheduling Criteria
▪ Waiting time –The time spent by a process waiting
in the ready queue for getting the CPU. The time
difference b/w Turnaround Time and Burst Time is
called Waiting Time.
▪ WT = TAT – BT
▪ BT : This is the time required by the process for it’s
execution.
▪ Response time – is the time from the submission
of a request until the first response is produced.
Important CPU scheduling Terminologies
▪ Burst Time/Execution Time: It is a time required
by the process to complete execution.
▪ Arrival Time: when a process enters in a ready
state
▪ Finish Time/Completion time: when process
complete and exit from a system
▪ CPU/IO burst cycle: Characterizes process
execution, which alternates between CPU and I/O
activity. CPU times are usually shorter than the time
of I/O.
Scheduling Algorithm Criteria
Scheduling Algorithms
▪ CPU scheduling deals with the problem of deciding
which of the processes in the ready queue is to be
allocated the CPU’s core.
• First-Come First-Serve Scheduling, FCFS
• Shortest-Job-First Scheduling, SJF
• Priority Scheduling
• Round Robin Scheduling
• Multilevel Queue Scheduling
• Multilevel Feedback-Queue Scheduling
First- Come, First-Served (FCFS) Scheduling
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
P1 0 8
P2 1 4
P3 2 9
p4 3 5
Example of Shortest-remaining-time-first
AT BT TAT=CT-AT WT=TAT-BT
P1 0 8 17 09
P2 1 4 4 0
P3 2 9 24 15
P4 3 5 7 02
P1 24
P2 3
P3 3
Example of RR with Time Quantum = 4
▪ Three queues:
• Q0 – RR with time quantum 8 milliseconds
• Q1 – RR time quantum 16 milliseconds
• Q2 – FCFS
Example of Multilevel Feedback Queue
Example of Multilevel Feedback Queue
▪ Scheduling
• A new process enters queue Q0 which is served in
RR
When it gains CPU, the process receives 8
milliseconds
If it does not finish in 8 milliseconds, the
process is moved to queue Q1
• At Q1 job is again served in RR and receives 16
additional milliseconds
If
it still does not complete, it is preempted and
moved to queue Q2
Thread Scheduling
▪ Execution of multiple threads on a single CPU in
some order is called thread scheduling
▪ Threads has user-level and kernel-level threads.
▪ Scheduling of threads involves two boundary
scheduling:
• Scheduling of user level threads (ULT) to kernel
level threads (KLT) via lightweight process (LWP)
by the application developer.
• Scheduling of kernel level threads by the system
scheduler to perform different unique OS
functions.
Thread Scheduling
▪ User-level threads are managed by a thread library.
▪ To run on a CPU, user-level threads must ultimately
be mapped to an associated kernel-level thread.
▪ This mapping is done by lightweight process (LWP)
interface.
Thread Scheduling
▪ User level thread scheduling is process-contention
scope (PCS) since scheduling competition is within
the process
• Typically done via priority set by programmer
▪ Kernel level thread scheduling onto available CPU is
system-contention scope (SCS) – competition
among all threads in system
Multiple-Processor Scheduling
▪ CPU scheduling becomes more complex when
multiple CPUs are available.
▪ Load sharing balances the load among multiple
processors.
▪ Multi processor system may be any one of the
following architectures:
• Multicore CPUs
• Multithreaded cores
• NUMA (Non Uniform Memory Access systems
• Heterogeneous system/Homogeneous system
Multiple-Processor Scheduling-Approaches
▪ Asymmetric multiprocessing, in which one
processor is the master, controlling all activities and
running all kernel code, while the other runs only
user code.
▪ Symmetric multiprocessing, SMP, where each
processor schedules its own jobs, either from a
common ready queue or from separate ready
queues for each processor.
• Virtually all modern OSes support SMP, including
XP, Win 2000, Solaris, Linux, and Mac OSX.
Symmetric multiprocessing (SMP)
Multicore Processors