Title: Operating System Main Goals
1Operating System - Main Goals
- Interleave the execution of the number of
processes to maximize processor utilization while
providing reasonable response time - The main idea of scheduling
- The system decides
- Who will run
- When will it run
- For how long
- In order to achieve its goals
2Process Scheduling
- Quality criteria for scheduling (algorithm)
- Fairness each process gets a fair share of
the cpu - Efficiency keep the cpu busy
- Response time minimize, for interactive users
- Turnaround for batch users (total time of
batch) - Throughput maximal number of processed jobs per
unit time - Waiting time minimize the average over processes
3Scheduling quality measures
- Throughput number of processes completed per
unit time - Turnaround time interval of (real) time from
process submission to completion - Waiting time sum of time intervals the process
spends in the ready queue - Response time the time between submitting a
command and the generation of the first output - CPU utilization the part of the total
(elapsed) time, the cpu is computing some process
between 0 and 100
4Scheduling Algorithm Goals
5Conflicting Goals
- Response Time vs Turnaround time
- A conflict between
- Interactive and batch users.
- Fairness vs Throughput
- Consider a very long job.
- should it be run?
6Scheduling Types of behavior
- Bursts of CPU usage alternate with periods of
I/O wait - a CPU-bound process
- an I/O bound process
7Utilization vs. Turnaround time
- 5 interactive jobs i1i5 and one batch job b
- Interactive jobs 10 cpu 20 disk i/o 70
terminal i/o total time for each job 10 sec. - Batch job 90 cpu 10 disk i/o total time 50
sec. - Cannot run all in parallel !!
- i1..i5 in parallel - disk i/o is 100 utilized
- b and one i in parallel - cpu is 100 utilized
8Utilization vs. Turnaround time (II)
- Two possible schedules
- 1. First i1i5, then b
- UT (10x0.5 50x0.9)/60 83
- TA (10x5 60x1)/6 18sec.
- 2. b and each of the is in parallel
- UT (50x1)/50 100
- TA (1020304050 50)/6 33sec.
9When are Scheduling Decisions made ?
- 1. Process switches from Running to Waiting
(i/o) - 2. New process submission.
- 3. Switch from Running to Ready (clock.. )
- 4. Process switches from Waiting to Ready
(i/o..) - 5. Process terminates
- Types of Scheduling
- Preemptive scheduling processes can be
suspended by scheduler - non-preemptive only 1 And 5.
10(No Transcript)
11(No Transcript)
12Shortest Job First
- If run times are known in advance...
5
2
4
1
571112
B
C
A
D
8.75
4
1
2
4
5
13712
A
5.75
D
B
C
4
and if they are not known they can be
approximated...
13Determining length of next CPU burst
- Can be done by using the length of previous cpu
bursts - tn actual length of nth cpu burst
- Tn1 predicted value for the next cpu burst
- for 0 ? ? ? 1 define
- Tn1 ? tn (1 - ? ) Tn
142.0
152.0
16Round Robin - the oldest method
- Each process gets a small unit of cpu time
(time-quantum), usually 10-100 milliseconds - For n ready processes and time-quantum q, no
process waits more than (n - 1)q - In the limit of very large q - FCFS
- Quantum of time gt switching time
- relatively large waste of cpu time (i.e.
switching) - Quantum of time gtgt switching time
- long response (waiting) time... FCFS
17Context switch overhead
- Context Switching costs something
- Choosing a long time quantum to avoid switching
- Deteriorates response time.
- Increases CPU utilization
- Choosing a short time quantum
- Faster response
- CPU wasted on switches
18Context switch overhead - example
- Assume a context switch takes 5 milliseconds
- Switching after a 20 ms. quantum would mean 20
of the CPU time is wasted on switching - Switching after a 500 ms. quantum and having 10
concurrent users, could possibly mean a 5 second
response time - possible solution settle for 100 ms.
19(No Transcript)
20Dependence on time-quantum
21An Example
22First-Come-First-Served (FCFS)
- Each process joins the Ready queue
- When the current process ceases to execute, the
oldest process in the Ready queue is selected - Average waiting time is 4.6 Average Turnaround
is 8.6
1
2
3
4
5
23Shortest Remaining Time - SRTF
- Preemptive version of the Shortest Job First
policy - Must estimate processing time
- Average waiting time is 3.2 Average Turnaround
is 7.2
24Guaranteed Scheduling
- To achieve guaranteed 1/n of cpu time (for n
processes/users logged on) - Monitor the total amount of cpu time per process
and the total logged on time - Calculate the ratio of allocated cpu time to the
amount of cpu time each process is entitled to - Run the process with the lowest ratio
- Switch to another process when the ratio of the
running process has passed its goal ratio - also called Fair-share Scheduling
25Guaranteed scheduling example
0
Process 1
Process 2
Process 3
26Guaranteed scheduling example
1
Process 1
Process 2
Process 3
27Guaranteed scheduling example
2
Process 1
Process 2
Process 3
28Guaranteed scheduling example
3
Process 1
Process 2
Process 3
29Guaranteed scheduling example
4
Process 1
Process 2
Process 3
30Guaranteed scheduling example
5
Process 1
Process 3
31Guaranteed scheduling example
6
Process 1
Process 2
Process 3
32Guaranteed scheduling example
7
Process 1
Process 2
Process 3
33Guaranteed scheduling example
8
Process 1
Process 2
Process 3
34Guaranteed scheduling example
9
Process 1
Process 2
Process 3
35Priority (Feedback) Scheduling
- Select runnable process with highest priority
- When there are classes of processes with the
same priority - group priorities
- each priority group uses round robin scheduling
- A process from a lower priority group runs only
if there is no higher priority process waiting -
36Multi-Level Queue Scheduling
system processes
interactive processes
Interactive editing processes
batch processes
student processes
Lowest priority
37Dynamic multi level scheduling
- The main drawback of priority scheduling
starvation! - To avoid
- Prevent high priority processes from running
indefinitely by changing priorities dynamically - Each process has a base priority
- increase priorities of waiting processes at each
clock tick - Preserving the SJF priority
- increase priorities of i/o bound processes
- priority 1/f ( f is the fraction of
time-quantum used)
38Parameters defining multi-level scheduling
- Number of queues and scheduling policy in each
queue (FCFS, Priority?) - When to demote a process to a lower queue
- Which queue to promote a process to
- Elapsed time since process received CPU (aging)
- Expected CPU burst
- Process priority
39Scheduling in Interactive Systems
- A scheduling algorithm with four priority classes
40Dynamic Priority Groups - CTSS
- Assign different time quanta to the different
priority classes - Highest priority class 1 quantum, 2nd class 2
quanta, 3rd class 4 quanta, etc. - Move processes that used their time to lower
classes (i.e. classify running processes) - Net result - longer runs for cpu-bound
processes higher priority for i/o-bound
processes - for 100 time quanta - 7 switches
- Unix (low-level) scheduler ...
41An Example
42Highest Response Ratio Next (HRRN)
- Choose next process with the highest ratio
1
2
3
4
5
time spent waiting expected service
time expected service time
43Feedback Scheduling
- Penalize jobs that have been running longer
- Dont know remaining time process needs to
execute - Maintain multiple queues and cascade down after
use of time-slice
44Two-Level Scheduling
- Assume processes can be either in memory or
swapped out (to disk) - Schedule memory-resident processes by a low
level scheduler as before - Swap in/out by a high level scheduler using
- Elapsed time since process swapped in/out
- Allocated cpu time to process
- Process size (takes less space in memory)
- Process priority
45Two level scheduling
CPU
CPU scheduler
disk
Memory scheduler
Memory
46Scheduling in Batch Systems (2)
47Scheduling in Real-Time Systems
- Schedulable real-time system
- Given
- m periodic events
- event i occurs within period Pi and requires Ci
seconds - Then the load can only be handled if
48User-level Thread Scheduling
- Possible scheduling
- 50-msec process quantum
- threads run 5 msec/CPU burst
49Kernel-level Thread Scheduling
- Possible scheduling
- 50-msec process quantum
- threads run 5 msec/CPU burst
50Scheduling in Unix
- Two-level scheduling
- Low level scheduler uses multiple queues to
select the next process, out of the processes in
memory, to get a time quantum. - High level scheduler moves processes from memory
to disk and back, to enable all processes their
share of cpu time - Low-level scheduler keeps queues for each
priority - User mode processes have positive priorities
- Kernel mode processes have negative priorities
(which are higher)
51Low-level Scheduling Algorithm
- Pick process from highest (non-empty) priority
queue - Run for 1 quantum (usually 100 ms.), or until it
blocks - Increment cpu usage count every clock tick
- Every second, recalculate priorities
- Divide cpu usage by 2
- New priority base cpu_usage/2 nice
- (base is usually 0, but, can be niced to less...)
- Use round robin for each queue (separately)
52Unix priority queues
53Low-level Scheduling Algorithm - i/o
- Blocked processes are removed from queue, but,
when the blocking event occurs, are placed in a
high priority queue - The negative priorities are meant for
(returning) blocked processes - Negative priorities are hardwired in the system,
for example, -5 for Disk i/o is meant to enable a
reading/writing process to go back from the disk
without waiting for other processes - Interactive processes get good service, cpu
bound processes get whatever service is left...
54WINDOWS NT Scheduling (II)
- Windows 2000 supports 32 priorities for threads
55An example of priority inversion
56Performance Modeling and Scheduling
- Deterministic Scheduling - very simple
assumptions, look for Optimality - Queueing Theory
- Simulation
57Deterministic Models of Processor Scheduling
- Fig. 3.2-1 Illustrating A-Schedules
58Deterministic Models of Processor Scheduling
59Queueing Theory
- Assumptions on the Probability distribution of
Arriving jobs - e.g. Poisson distribution with
mean L - Assumptions on service distribution - e.g.
Exponential distribution with mean R - Deciding a scheduling discipline and number of
Servers/queues - There are analytic solutions, e.g. Little law
- N L W
60SIMULATION
- Generate a stream of arriving jobs using a
Probability distribution function - Generate Service times using another
distribution function - Decide on scheduling discipline
- Create an Events clock
- Simulate and record various measures like
Turn-around and waiting times, Length of queues
and Utilization - Use of Simulation Languages e.g. GPSS
61Evaluation of CPU Schedulers by Simulation
62Priority Calculation in Unix
- Pj(i) Priority of process j at beginning of
interval i - Basej Base priority of process j
- Uj(i) Processor utilization of process j in
interval i - Guk(i) Total processor utilization of all
processes in group k during interval i - CPUj(i) Exponentially weighted average
processor utilization by process j
through interval i - GCPUk(I) Exponentially weighted average total
processor utilization of group k through
interval i - Wk Weighting assigned to group k, with the
constraint that 0 ? Wk ? 1 - and
63Example of Unix scheduling
priority
60
60
60
75
P3
67
0,1,2..60
CPU count
priority
60
60
75
67
63
P3
CPU count
0,1,2..60
priority
60
75
67
63
76
P1
CPU count
0,1,2..60
7,8,9.. 67
2
3
0
4
1
time
64WINDOWS NT - Scheduling
- Mapping of Win32 priorities to Windows 2000
priorities