Operating System Main Goals - PowerPoint PPT Presentation

1 / 64
About This Presentation
Title:

Operating System Main Goals

Description:

Operating System - Main Goals ... Then the load can only be handled if. 12/27/09. OS_05 Scheduling. 48. User-level Thread Scheduling ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 65
Provided by: csBg
Category:

less

Transcript and Presenter's Notes

Title: Operating System Main Goals


1
Operating 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

2
Process 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

3
Scheduling 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

4
Scheduling Algorithm Goals
5
Conflicting 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?

6
Scheduling Types of behavior
  • Bursts of CPU usage alternate with periods of
    I/O wait
  • a CPU-bound process
  • an I/O bound process

7
Utilization 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

8
Utilization 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.

9
When 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)
12
Shortest 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...
13
Determining 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

14
2.0
15
2.0
16
Round 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

17
Context 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

18
Context 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)
20
Dependence on time-quantum
21
An Example
22
First-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
23
Shortest 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

24
Guaranteed 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

25
Guaranteed scheduling example
0
Process 1
Process 2
Process 3
26
Guaranteed scheduling example
1
Process 1
Process 2
Process 3
27
Guaranteed scheduling example
2
Process 1
Process 2
Process 3
28
Guaranteed scheduling example
3
Process 1
Process 2
Process 3
29
Guaranteed scheduling example
4
Process 1
Process 2
Process 3
30
Guaranteed scheduling example
5
Process 1
Process 3
31
Guaranteed scheduling example
6
Process 1
Process 2
Process 3
32
Guaranteed scheduling example
7
Process 1
Process 2
Process 3
33
Guaranteed scheduling example
8
Process 1
Process 2
Process 3
34
Guaranteed scheduling example
9
Process 1
Process 2
Process 3
35
Priority (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

36
Multi-Level Queue Scheduling
  • Highest priority

system processes
interactive processes
Interactive editing processes
batch processes
student processes
Lowest priority
37
Dynamic 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)

38
Parameters 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

39
Scheduling in Interactive Systems
  • A scheduling algorithm with four priority classes

40
Dynamic 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 ...

41
An Example
42
Highest 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
43
Feedback 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

44
Two-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

45
Two level scheduling
CPU
CPU scheduler
disk
Memory scheduler
Memory
46
Scheduling in Batch Systems (2)
  • Three level scheduling

47
Scheduling 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

48
User-level Thread Scheduling
  • Possible scheduling
  • 50-msec process quantum
  • threads run 5 msec/CPU burst

49
Kernel-level Thread Scheduling
  • Possible scheduling
  • 50-msec process quantum
  • threads run 5 msec/CPU burst

50
Scheduling 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)

51
Low-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)

52
Unix priority queues
53
Low-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...

54
WINDOWS NT Scheduling (II)
  • Windows 2000 supports 32 priorities for threads

55
An example of priority inversion
56
Performance Modeling and Scheduling
  • Deterministic Scheduling - very simple
    assumptions, look for Optimality
  • Queueing Theory
  • Simulation

57
Deterministic Models of Processor Scheduling
  • Fig. 3.2-1 Illustrating A-Schedules

58
Deterministic Models of Processor Scheduling
59
Queueing 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

60
SIMULATION
  • 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

61
Evaluation of CPU Schedulers by Simulation
62
Priority 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

63
Example 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
64
WINDOWS NT - Scheduling
  • Mapping of Win32 priorities to Windows 2000
    priorities
Write a Comment
User Comments (0)
About PowerShow.com