Chapter 5: CPU Scheduling: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
Chapter 5: CPU Scheduling: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
■ Basic Concepts
■ Scheduling Criteria
■ Scheduling Algorithms
■ Thread Scheduling
■ Multi-Processor Scheduling
■ Algorithm Evaluation
#top
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
■ Convoy effect – short processes behind a long process, all the other
processes wait for the one big process to get off the CPU
● Consider one CPU-bound and many I/O-bound processes
■ Associate with each process the length of its next CPU burst
● When the CPU is available, it is assigned to the process that has the
smallest next CPU burst
● FCFS scheduling is used if the next CPU bursts of two processes are the
same
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
P4 P1 P3 P2
0 3 9 16 24
■ Can only estimate the length – should be similar to the previous one
𝜏"#$ = 𝛼. t ) + (1 − 𝛼) 𝜏"
■ a=0
● tn+1 = tn
● Recent history does not count
■ a =1
■ Since both a and (1 - a) are
● tn+1 = tn less than or equal to 1, each
● Only the actual last CPU burst successive term has less
counts weight than its predecessor
■ If we expand the formula, we get:
tn+1 = a tn + (1 - a)a tn -1 + …
+ (1 - a )j a tn -j + …
+ (1 - a )n +1 t0.
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
■ 80% of CPU
bursts should be
shorter than q
● Nonpreemptive
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
pthread_attr_init(&attr);
else {
if (scope == PTHREAD_SCOPE_PROCESS)
printf("PTHREAD_SCOPE_PROCESS");
printf("PTHREAD_SCOPE_SYSTEM");
else
fprintf(stderr, "Illegal scope value.\n");
}
Operating System Concepts 31 Silberschatz, Galvin and Gagne ©2018
Pthread Scheduling API (Cont.)
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_create(&tid[i],&attr,runner,NULL);
pthread_join(tid[i], NULL);
pthread_exit(0);
● Multicore CPUs
● Multithreaded cores
● NUMA systems
● Heterogeneous multiprocessing
■ Multiprocessor scheduling
● Each processor may have its own private queue of threads (Fig. b)
■ Chip-multithreading (CMT)
assigns each core multiple
hardware threads (Intel
refers to this as
hyperthreading)
■ On a quad-core system
with 2 hardware threads
per core (e.g., Intel i7), the
operating system sees 8
logical processors
■ Two levels of
scheduling:
1. The operating
system deciding
which software
thread to run on a
logical CPU
■ Event latency – the amount of time that elapses from when an event
occurs to when it is serviced.
2. Dispatch latency – time for schedule to take current process off CPU and
switch to another
■ Conflict phase of
dispatch latency:
1. Preemption of any
process running in
kernel mode
2. Release by low-
priority process of
resources needed
by high-priority
processes
#include <stdio.h> {
pthread_attr_t attr;
pthread_attr_init(&attr);
else {
pthread_create(&tid[i],&attr,runner,NULL);
pthread_join(tid[i], NULL);
pthread_exit(0);
■ Linux scheduling
■ Windows scheduling
■ Scheduling classes
4 default
4 real-time
● Calculates target latency – interval of time during which task should run
at least once
● Normal default priority yields virtual run time = actual run time
■ To decide next task to run, scheduler picks task with lowest virtual
run time
■ Deterministic modeling
■ Simple and fast, but requires exact numbers for input, applies only to
those inputs
● FCS is 28ms:
● RR is 23ms:
● Clock is a variable
■ Environments vary