CS837: ADV.
OPERATING SYSTEMS
MULTIPROCESSOR & REAL-TIME
SCHEDULING
Dr. Mian M.Hamayun
[email protected]http://seecs.nust.edu.pk/faculty/mianhamayun.html
TYPES OF MULTIPROCESSOR
SYSTEMS
Distributed Systems: Loosely connected
relatively independent systems e.g. PCs
connected via internet.
Non-uniform or Specialized Processor
Systems: Systems with specialized processors
e.g. I/O processors, Vector processors etc.
Symmetric Multiprocessors(SMP): Similar
processors or chips generally connected by a
common bus or specialized network. Share
memory and other resources.
2
GRANULARITY OF PARALLELISM
Another characteristic of MP systems is the frequency of
synchronization between processes in a system.
1) Independent Parallelism: No explicit synchronization among
processes e.g. separate applications i.e. time-sharing system
2) Very Course Grain Parallelism: Loosely coupled tasks that
require no or little synchronization. e.g. Large Application
compilation (with many sources files).
3) Coarse Grain Parallelism: Process level synchronization. e.g.
a process spawning multiple other processes.
4) Medium Grain Parallelism: Frequent synchronization required.
e.g. parallelism between multiple threads of the same process.
5) Fine Grain Parallelism: Parallelism down to the instruction
level e.g. DSP/VLIW applications, ILP (Instruction Level
Parallelism)
3
GRANULARITY OF PARALLELISM
4
DESIGN ISSUES
Scheduling on a multiprocessor system involves the following
issues:
1. Assignment of a Processor to a Processes: Decision
of where to run a process.
2. Use of multiprogramming on individual processors:
How to run multiple processes on an individual
processor.
3. Process Dispatching: Actual decision of which process
to run next.
The approach taken will depend on the degree of granularity of
applications and the number of processors available.
5
DESIGN ISSUES
Assignment of a Processor to a Processes:
Assuming all processors are equal, it is
simplest to treat processors as a pooled
resource and assign process to processors on
demand.
Should the assignment be dynamic or static?
6
DESIGN ISSUES
Assignment of a Processor to a Processes:
Dynamic Assignment
Threads are moved from a queue of one processor
to a queue of another processor
Static Assignment
Permanently assign process to a processor
Dedicate short-term queue for each processor &
requires less scheduling overhead
Allows the use of ‘group’ or ‘gang’ scheduling (later)
May leave a processor idle with an empty queue
while others have a backlog!
7
DESIGN ISSUES:
SCHEDULING ON AN SMP
Master/Slave Model: The kernel routines are run on
only one of the cores. The other cores are assigned
tasks by the master.
Advantages
Simpler to implement
Simple conflict resolution
Disadvantages
Failure of the master may bring down the whole system
The master may become a performance bottleneck
8
DESIGN ISSUES:
SCHEDULING ON AN SMP
Peer Model: The scheduling algorithm is run on any
core that is idle and needs a new job.
Advantages
Can tolerate System Failures
OS execution load is distributed on the entire system
Disadvantages
Difficult to implement
OS must ensure that two processors don’t select the
same process or some processes disappear.
Shared system data structures may become a
bottleneck.
9
COMPARISON: ONE VS. TWO
PROCESSORS
Dual-processor system has ½ of the
processing rate of a single
processor system.
Coefficient of Variation Cs = 0;
No variability in service times of
processes i.e. services times are
equal for all processes.
A single process with long service
time is much less disruptive in the
FCFS case.
General Conclusion:
Specific scheduling discipline is
much less important with two or
more processors.
10
THREAD SCHEDULING ON
MULTIPROCESSORS
An application can be a set of threads that
cooperate and execute concurrently in the
same address space.
Threads serve as structuring aid and to
overlap I/O and processing on uniprocessor
systems.
True parallelism on multi-processor systems.
Dramatic gains in performance are possible as
compared to uniprocessor systems.
11
APPROACHES TO THREAD
SCHEDULING ON MULTIPROCESSORS
Many proposals exist but four general approaches
stand out:
1) Load Sharing
2) Gang Scheduling
3) Dedicated processor assignment
4) Dynamic scheduling
12
THREAD SCHEDULING:
LOAD SHARING
Usually threads are not dedicated to processors!
Whenever a processor is idle it pulls a job from a
single shared queue or multiple queues are
used for priorities.
Load evenly distributed on all processors.
No central scheduler needed.
The system could be viewed as a multi-server
queuing architecture.
The central queue(s) needs mutual exclusion and
may become a bottleneck!
13
THREAD SCHEDULING:
GANG SCHEDULING
A set of related threads is run simultaneously
on a set of processors on a one-by-one basis.
Synchronization, blocking time may be reduced
and performance may increase. Applications
may make faster progress.
Scheduling overhead may decrease as a
single decision affects a number of threads.
Performance usually superior to Load Sharing.
14
THREAD SCHEDULING:
GANG SCHEDULING – EXAMPLE
Suppose we have a four processor system and we
have two applications to run. One with 4 threads and
the other with just one thread.
System is shared equally among the two applications
(Uniform Division)
Utilization
Group 1 Group 2 Individual System
PE 1
T1 T1 100% 25.0%
PE 2 Utilization: 62.5%
T2 Idle 50% 12.5% Wastage: 37.5 %
PE 3 T3 Idle 50% 12.5%
PE 4
T4 Idle 50% 12.5%
15
THREAD SCHEDULING:
GANG SCHEDULING – EXAMPLE
We have 5 threads we may give 4/5 to application 1
and 1/5 of the system share to application 2.
Group 1 Group 2 Utilization
(Share: 4/5) (Share 1/5) Individual System
PE 1
T1 T1 100% 25.0%
Utilization: 85.0%
PE 2 80% 20.0% Wastage: 15.0%
T2 Idle
PE 3 T3 Idle 80% 20.0%
PE 4
T4 Idle 80% 20.0%
16
THREAD SCHEDULING: DEDICATED
PROCESSOR ASSIGNMENT
Each program is assigned a number of processors equal
to the threads in the program.
The processors remain dedicated to the program till
its completion.
Some processors may be idle: there is no
multiprogramming of processors!
Reverse of Load Sharing.
Extreme form of Gang Scheduling.
May result in good performance for systems with a large
number of processors by avoiding process/thread
switching during the lifetime of a program.
17
THREAD SCHEDULING: DEDICATED
PROCESSOR ASSIGNMENT
18
THREAD SCHEDULING: DYNAMIC
SCHEDULING
Number of threads of the program can be
altered at runtime on system demand.
Special Runtime support needed for this kind of
system.
Simulations suggest that this form of scheduling
is superior to both Gang Scheduling and
Dedicated Assignment.
Experience with actual systems is needed to
prove the worth of dynamic scheduling.
19