Process Concept: Jobs User Programs Tasks Process
Process Concept: Jobs User Programs Tasks Process
Maximize CPU use, quickly switch processes onto CPU for time
sharing
Process scheduler selects among available processes for
next execution on CPU
Maintains scheduling queues of processes
Job queue – set of all processes in the system
Ready queue – set of all processes residing in main
memory, ready and waiting to execute
Device queues – set of processes waiting for an I/O device
Processes migrate among the various queues
Representation of Process Scheduling
Types of parallelism
Data parallelism – distributes subsets of the same data
across multiple cores, same operation on each
Task parallelism – distributing threads across cores, each
thread performing unique operation
As # of threads grows, so does architectural support for threading
CPUs have cores as well as hardware threads
Consider Oracle SPARC T4 with 8 cores, and 8 hardware
threads per core
Concurrency vs. Parallelism
Concurrent execution on single-core system:
Many-to-One
One-to-One
Many-to-Many
Many-to-One
P 1
P 2
P3
0 24 27 30
P 2
P 3
P 1
0 3 6 30
Associate with each process the length of its next CPU burst
Use these lengths to schedule the process with the shortest
time
SJF is optimal – gives minimum average waiting time for a given
set of processes
The difficulty is knowing the length of the next CPU request
Could ask the user
Example of SJF
P 4
P 1
P3 P2
0 3 9 16 24
P 1
P 2
P4 P1 P3
0 1 5 10 17 26
P 1
P 2
P1 P3 P4
0 1 6 16 18 19
Each process gets a small unit of CPU time (time quantum q),
usually 10-100 milliseconds. After this time has elapsed, the
process is preempted and added to the end of the ready queue.
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.
Timer interrupts every quantum to schedule next process
Performance
q large FIFO
q small q must be large with respect to context switch,
otherwise overhead is too high
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
The Gantt chart is:
P 1
P 2
P 3
P 1
P 1
P 1
P 1
P1
0 4 7 10 14 18 22 26 30
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is
served FCFS
When it gains CPU, job receives 8
milliseconds
If it does not finish in 8 milliseconds,
job is moved to queue Q1
At Q1 job is again served FCFS and
receives 16 additional milliseconds
If it still does not complete, it is
preempted and moved to queue Q2
Real-Time CPU Scheduling
Can present obvious challenges
Soft real-time systems – no
guarantee as to when critical real-
time process will be scheduled
Hard real-time systems – task
must be serviced by its deadline
Two types of latencies affect
performance
1. Interrupt latency – time from arrival of
interrupt to start of routine that
services interrupt
2. Dispatch latency – time for schedule
to take current process off CPU and
switch to another
Real-Time CPU Scheduling (Cont.)
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