intro to o/s scheduling

47
Intro to O/S Scheduling 1. Intro to O/S Scheduling 2. What is Scheduling? 3. Computer Systems Scheduling 4. O/S Scheduling Categories 5. O/S Scheduling and Process State 6. O/S Scheduling Layers 7. Scheduling Algorithm Criteria 8. Introduction to Performance 9. Time as a Performance Metric 10. Rate as a Performance Metric 11. Response Time and Throughput

Upload: sivan

Post on 31-Jan-2016

68 views

Category:

Documents


0 download

DESCRIPTION

Intro to O/S Scheduling. 1. Intro to O/S Scheduling 2. What is Scheduling? 3. Computer Systems Scheduling 4. O/S Scheduling Categories 5. O/S Scheduling and Process State 6. O/S Scheduling Layers 7. Scheduling Algorithm Criteria 8. Introduction to Performance - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Intro to O/S Scheduling

Intro to O/S SchedulingIntro to O/S Scheduling

1. Intro to O/S Scheduling2. What is Scheduling?3. Computer Systems Scheduling4. O/S Scheduling Categories5. O/S Scheduling and Process State6. O/S Scheduling Layers7. Scheduling Algorithm Criteria8. Introduction to Performance9. Time as a Performance Metric10. Rate as a Performance Metric11. Response Time and Throughput

1. Intro to O/S Scheduling2. What is Scheduling?3. Computer Systems Scheduling4. O/S Scheduling Categories5. O/S Scheduling and Process State6. O/S Scheduling Layers7. Scheduling Algorithm Criteria8. Introduction to Performance9. Time as a Performance Metric10. Rate as a Performance Metric11. Response Time and Throughput

Page 2: Intro to O/S Scheduling

12. Utilization as a Performance Measurement13. Queuing Notation14. How Preemption Fits in15. FCFS Defined16. FCFS Examples17. FCFS analyzed18. SJF Example19. SJF Features20. Estimating Service Time21. SRT22. HRRN Scheduling

12. Utilization as a Performance Measurement13. Queuing Notation14. How Preemption Fits in15. FCFS Defined16. FCFS Examples17. FCFS analyzed18. SJF Example19. SJF Features20. Estimating Service Time21. SRT22. HRRN Scheduling

Intro to O/S Scheduling (continued)Intro to O/S Scheduling (continued)

Page 3: Intro to O/S Scheduling

23. RR Scheduling24. RR Example25. RR Tq and System Turnaround Time26. RR Tq and E[Tq]27. RR Example Tq = 128. RR Example Tq = 1029. RR Example Tq = 10030. RR Example Tq = 3031. RR Features Summary

23. RR Scheduling24. RR Example25. RR Tq and System Turnaround Time26. RR Tq and E[Tq]27. RR Example Tq = 128. RR Example Tq = 1029. RR Example Tq = 10030. RR Example Tq = 3031. RR Features Summary

Intro to O/S Scheduling (continued)Intro to O/S Scheduling (continued)

Page 4: Intro to O/S Scheduling

What is Scheduling?What is Scheduling?

Many definitions exist, our on-line Webster server came up with:

1. to appoint, assign, or designate for a fixed time

2. a procedural plan that indicates the time and sequence of each operation

Many definitions exist, our on-line Webster server came up with:

1. to appoint, assign, or designate for a fixed time

2. a procedural plan that indicates the time and sequence of each operation

Page 5: Intro to O/S Scheduling

What is Scheduling? (continued)What is Scheduling? (continued)

Scheduling is an open research area, studied in engineering, decision sciences, operations research, and mathematics.

This lecture focuses on O/S level scheduling in uniprocessor computer systems.

Scheduling is an open research area, studied in engineering, decision sciences, operations research, and mathematics.

This lecture focuses on O/S level scheduling in uniprocessor computer systems.

Page 6: Intro to O/S Scheduling

Computer Systems SchedulingComputer Systems Scheduling

In a computer system typically there are:

1. Servers which respond to processes' requests for service (e.g. I/O, CPU, Data Communication, adders, bus, etc.).

2. Requests are serviced in order of their Priority, with highest priority jobs going first.

In a computer system typically there are:

1. Servers which respond to processes' requests for service (e.g. I/O, CPU, Data Communication, adders, bus, etc.).

2. Requests are serviced in order of their Priority, with highest priority jobs going first.

Page 7: Intro to O/S Scheduling

3. A preemption occurs if a server: a) Partially services a request, say b) Preserves partial results of service for A c) Begins/resumes servicing another request with higher priority, say B d) The server will later resume servicing.

The computer systems scheduling primitives address these issues.

3. A preemption occurs if a server: a) Partially services a request, say b) Preserves partial results of service for A c) Begins/resumes servicing another request with higher priority, say B d) The server will later resume servicing.

The computer systems scheduling primitives address these issues.

Computer Systems SchedulingComputer Systems Scheduling

Page 8: Intro to O/S Scheduling

O/S Scheduling CategoriesO/S Scheduling Categories

1. Long Term Scheduling - Which Jobs to add to the Processing

2. Medium Term Scheduling -Which process to load into

memory

3. Short Term Scheduling - Which ready process gets

the CPU

4. I/O Term Scheduling - Which pending I/O request

does an I/O device service.

1. Long Term Scheduling - Which Jobs to add to the Processing

2. Medium Term Scheduling -Which process to load into

memory

3. Short Term Scheduling - Which ready process gets

the CPU

4. I/O Term Scheduling - Which pending I/O request

does an I/O device service.

Page 9: Intro to O/S Scheduling

O/S Scheduling and Process StateO/S Scheduling and Process State

New

Ready,Suspended Ready Running

Long- Term Scheduling

ExitEvent Wait

BlockedBlocked, Suspended

Medium- Term Scheduling

Medium- Term Scheduling

Short- Term Scheduling

Long- Term Scheduling

Page 10: Intro to O/S Scheduling

O/S Scheduling LayersO/S Scheduling Layers

The long term scheduling primitives are supported by the ``low level'' short term scheduling primitives.The long term scheduling primitives are supported by the ``low level'' short term scheduling primitives.

Page 11: Intro to O/S Scheduling

runready

short term

ready

transput waitmain-store wait

medium

readylong term

Figure 2: Scheduling Layers Transput denotes I/O

Figure 2: Scheduling Layers Transput denotes I/O

Page 12: Intro to O/S Scheduling

O/S Scheduling LayersO/S Scheduling Layers

Queuing discipline reflects scheduling.

Queuing discipline reflects scheduling.

Figure 6Figure 6

Page 13: Intro to O/S Scheduling

Scheduling Algorithm CriteriaScheduling Algorithm Criteria

The following issues impact scheduling algorithm selection:

1. Feasibility of computation2. Feasibility of schedule

3. Efficiency of computation

4. Efficiency of schedule

5. Ease of implementation

Both qualitative and quantitative issues matter.

The following issues impact scheduling algorithm selection:

1. Feasibility of computation2. Feasibility of schedule

3. Efficiency of computation

4. Efficiency of schedule

5. Ease of implementation

Both qualitative and quantitative issues matter.

Page 14: Intro to O/S Scheduling

Scheduling Algorithm CriteriaScheduling Algorithm Criteria

Stallings [3] gives the following schedulingcriteria:

1. User Oriented - Performance

a) Response Time

b) Turnaround Time

c) Deadlines

2. User Oriented - Other Criteria - Predictability

Stallings [3] gives the following schedulingcriteria:

1. User Oriented - Performance

a) Response Time

b) Turnaround Time

c) Deadlines

2. User Oriented - Other Criteria - Predictability

Page 15: Intro to O/S Scheduling

3. Systemic Performance

a) Throughput

b) Processor Utilization

4. Systemic - Other Performance

a) Fairness

b) Enforcing Priorities

c) Balancing Resources

3. Systemic Performance

a) Throughput

b) Processor Utilization

4. Systemic - Other Performance

a) Fairness

b) Enforcing Priorities

c) Balancing Resources

Scheduling Algorithm CriteriaScheduling Algorithm Criteria

Page 16: Intro to O/S Scheduling

Introduction to PerformanceIntroduction to Performance

Performance denotes computational speed measurements and is sensitive to scheduling efficiency.

Categories of classic performance measures:

1. Time (e.g. response time)

2. Rate (e.g. throughput)

3. Resource (e.g. utilization)

Performance denotes computational speed measurements and is sensitive to scheduling efficiency.

Categories of classic performance measures:

1. Time (e.g. response time)

2. Rate (e.g. throughput)

3. Resource (e.g. utilization)

Page 17: Intro to O/S Scheduling

Time as a Performance MetricTime as a Performance Metric

There are intervals in user/computer interaction:1. Response time --- Time until either: a) System Begins Response, or b) System Ends Response2. Reaction time --- User Latency3. Turnaround Time --- Process Duration4. Think Time --- User Latency 5. Stretch Factor --- Reaction of system to a fixed increased load

There are intervals in user/computer interaction:1. Response time --- Time until either: a) System Begins Response, or b) System Ends Response2. Reaction time --- User Latency3. Turnaround Time --- Process Duration4. Think Time --- User Latency 5. Stretch Factor --- Reaction of system to a fixed increased load

Page 18: Intro to O/S Scheduling

Figure 4: Definitions of Response Time

Figure 4: Definitions of Response Time

Page 19: Intro to O/S Scheduling

Rate as a Performance MetricRate as a Performance Metric

Owners of computers want to know the throughput (Operations/ Time) of the system:

1. Processing- MIPS, MFLOPS, GFLOPS, TFLOPS, Sustained, Peak2. I/O- (Transactions/ Second), Bandwidth3. Network/Data Communications- Bandwidth, bps, fps, Mbps, pps4. Efficiency- Measures Achieved Throughput Available Throughput

Owners of computers want to know the throughput (Operations/ Time) of the system:

1. Processing- MIPS, MFLOPS, GFLOPS, TFLOPS, Sustained, Peak2. I/O- (Transactions/ Second), Bandwidth3. Network/Data Communications- Bandwidth, bps, fps, Mbps, pps4. Efficiency- Measures Achieved Throughput Available Throughput

Page 20: Intro to O/S Scheduling

Figure 5: Efficiency of a Multiprocessor SystemFigure 5: Efficiency of a Multiprocessor System

Page 21: Intro to O/S Scheduling

Response Time and ThroughputResponse Time and Throughput

Figure 6: Response Time vs. Throughput

Figure 6: Response Time vs. Throughput

Page 22: Intro to O/S Scheduling

Utilization as a Performance Measurement

Utilization as a Performance Measurement

Expensive computing resources should be used.

1. Idle Time --- How long the resources are unused

2. Utilization --- The ratio: Time Used Total Time

Expensive computing resources should be used.

1. Idle Time --- How long the resources are unused

2. Utilization --- The ratio: Time Used Total Time

Page 23: Intro to O/S Scheduling

Figure 7: Meaning of Time MeasurementsFigure 7: Meaning of Time Measurements

Queuing NotationQueuing Notation

Symbol

TqTs

Meaning

Turn Around TimeService Time

Table 1: NotationTable 1: Notation

Page 24: Intro to O/S Scheduling

How Preemption Fits InHow Preemption Fits In

Symbol

Arrival Time in the systemContext Switch CostTime Waiting Queue

TaTcTw

Meaning

Table 2: Extended notationTable 2: Extended notation

Page 25: Intro to O/S Scheduling

Figure 8: Preemption and Time MeasurementsFigure 8: Preemption and Time Measurements

Page 26: Intro to O/S Scheduling

FCFS DefinedFCFS Defined

First Come First Serve (FCFS) scheduling:

1. is nonpreemptive

2. uses a FIFO queue

First Come First Serve (FCFS) scheduling:

1. is nonpreemptive

2. uses a FIFO queue

Page 27: Intro to O/S Scheduling

An FCFS ExampleAn FCFS Example

Figure 9: FCFS Example Time LineFigure 9: FCFS Example Time Line

Page 28: Intro to O/S Scheduling

Table 3: Example FCFS Job SchedulesTable 3: Example FCFS Job Schedules

Jobs

TaId Ts TaTq Tq

Case 2Case 1

A 30

B 60

C 210

20 280

10 260

0 210

0 30

10 80

20 280

Page 29: Intro to O/S Scheduling

FCFS AnalyzedFCFS Analyzed

The throughput is 1/E[Tq] solving for E[Tq]: • Case 1: E[Tq]= (280+260+210) / 3 = 250• Case 2: E[Tq]= (30+80+280) / 3 = 130Some characteristics of FCFS scheduling:1. Penalizes short jobs2. Rewards long jobs3. Large variance in throughput4. Sensitive to order of arrival5. Is starvation free6. Easy to implement

The throughput is 1/E[Tq] solving for E[Tq]: • Case 1: E[Tq]= (280+260+210) / 3 = 250• Case 2: E[Tq]= (30+80+280) / 3 = 130Some characteristics of FCFS scheduling:1. Penalizes short jobs2. Rewards long jobs3. Large variance in throughput4. Sensitive to order of arrival5. Is starvation free6. Easy to implement

Page 30: Intro to O/S Scheduling

SJF (also called SPN)SJF (also called SPN)

Shortest Job First (SJF) is also calledShortest Process Next (SPN):

1. Services jobs in ascending order

2. Is non-preemptive

Shortest Job First (SJF) is also calledShortest Process Next (SPN):

1. Services jobs in ascending order

2. Is non-preemptive

Page 31: Intro to O/S Scheduling

SJF ExampleSJF Example

Consider the same jobs again:Consider the same jobs again:

Figure 10: SJF Example Time LineFigure 10: SJF Example Time Line

Page 32: Intro to O/S Scheduling

Jobs

TaId Ts TaTq

Case 2Case 1

A 30

B 60

C 210

20 220

10 290

0 210

0 30

10 80

20 280

Tq

Table 4: Example SJF Job SchedulesTable 4: Example SJF Job Schedules

Page 33: Intro to O/S Scheduling

SJF FeaturesSJF Features

Recall that throughput is 1/E[Tq] solving for E[Tq]:• Case 1: E[Tq] = (220+290+210) / 3 = 240• Case 2: E[Tq] = (30+80+280) / 3 = 140Some characteristics of SJF scheduling:1. Penalizes long jobs2. Rewards short jobs3. Somewhat sensitive to order of arrival4. Gives optimal nonpreemptive throughput 5. Permits Starvation6. Knowing Ts difficult

Recall that throughput is 1/E[Tq] solving for E[Tq]:• Case 1: E[Tq] = (220+290+210) / 3 = 240• Case 2: E[Tq] = (30+80+280) / 3 = 140Some characteristics of SJF scheduling:1. Penalizes long jobs2. Rewards short jobs3. Somewhat sensitive to order of arrival4. Gives optimal nonpreemptive throughput 5. Permits Starvation6. Knowing Ts difficult

Page 34: Intro to O/S Scheduling

Estimating Service TimeEstimating Service Time

Let Sn be the estimate for a job's nth service time,

Tn, for a process.

Let , 0< <1 be a tuning parameter.

Sn+1 = (1 - ) Sn + Tn

= (1 - )n So + sum((1- )(n - i) Ti-1)(from i=1 to n+1)

Let Sn be the estimate for a job's nth service time,

Tn, for a process.

Let , 0< <1 be a tuning parameter.

Sn+1 = (1 - ) Sn + Tn

= (1 - )n So + sum((1- )(n - i) Ti-1)(from i=1 to n+1)

Page 35: Intro to O/S Scheduling

Estimating Service Time (continued)Estimating Service Time (continued)

When computing the estimate Sn:

= 0 disregard Tn in estimate.

= 1 only Tn impacts estimate.

0< <1 older Tn and initial guess So

eventually get discounted (at an

exponential rate).

When computing the estimate Sn:

= 0 disregard Tn in estimate.

= 1 only Tn impacts estimate.

0< <1 older Tn and initial guess So

eventually get discounted (at an

exponential rate).

Page 36: Intro to O/S Scheduling

SRTSRT

In SJF servicing long jobs forces shorter newly arrived jobs to wait.

Shortest Remaining Time (SRT) is a preemptive version of SJF.

1. Service Times may be estimated.2. Favor jobs with smaller Tq.

The heuristic presented may be used to estimate Tn.

In SJF servicing long jobs forces shorter newly arrived jobs to wait.

Shortest Remaining Time (SRT) is a preemptive version of SJF.

1. Service Times may be estimated.2. Favor jobs with smaller Tq.

The heuristic presented may be used to estimate Tn.

Page 37: Intro to O/S Scheduling

HRRN SchedulingHRRN Scheduling

Highest Response Ratio Next (HRRN):1. is non preemptive2. is starvation free3. jobs are serviced in descending Response Ratio RR order.4. estimating service time, Ts, may be required.5. Requires Frequent Recomputation of Priorities6. is more fair than FCFS

Page 38: Intro to O/S Scheduling

Response Ratio for a given processes nth service of duration Tn after waiting w duration for service is:

RR(n) = w + Tn

Tn

Estimating Tn can be done as shown earlier.

Response Ratio for a given processes nth service of duration Tn after waiting w duration for service is:

RR(n) = w + Tn

Tn

Estimating Tn can be done as shown earlier.

HRRN SchedulingHRRN Scheduling

Page 39: Intro to O/S Scheduling

RR SchedulingRR Scheduling

Round Robin (RR) scheduling:

1. Is Preemptive

2. Services jobs in FIFO order

The max time to preemption is the quantum, Tq.

Round Robin (RR) scheduling:

1. Is Preemptive

2. Services jobs in FIFO order

The max time to preemption is the quantum, Tq.

Page 40: Intro to O/S Scheduling

RR ExampleRR Example

Let the context switch time is Tc = 5.Let the context switch time is Tc = 5.

See how 0< Tq < 210 impacts performance.See how 0< Tq < 210 impacts performance.

Id Ts T

A 30 20

B 60 10

C 210 0

Table 5: RR Job ExampleTable 5: RR Job Example

Page 41: Intro to O/S Scheduling

RR and System Turnaround TimeRR and System Turnaround Time

Preemption increases system turnaround time (max{Tq}) rewards large Tq (FCFS approximation).Preemption increases system turnaround time (max{Tq}) rewards large Tq (FCFS approximation).

Figure 11: System Turnaround Time as a function of Tq

Figure 11: System Turnaround Time as a function of Tq

Page 42: Intro to O/S Scheduling

RR TQ and E [Tq]RR TQ and E [Tq]

The mean turnaround time for a job E [Tq] The mean turnaround time for a job E [Tq]

Figure 12: E[Tq] as a function of Tq

Figure 12: E[Tq] as a function of Tq

Page 43: Intro to O/S Scheduling

RR Example TQ = 1RR Example TQ = 1

Tq = 1 is far too small a time slice, usually Tq >> TcTq = 1 is far too small a time slice, usually Tq >> Tc

Figure 13: RR Scheduling Example for Tq = 1

Figure 13: RR Scheduling Example for Tq = 1

Page 44: Intro to O/S Scheduling

RR Example TQ = 10RR Example TQ = 10

Tq = 10 is still a bit too small a time slice.Tq = 10 is still a bit too small a time slice.

Figure 14: RR Scheduling Example for Tq = 10

Figure 14: RR Scheduling Example for Tq = 10

Page 45: Intro to O/S Scheduling

RR Example TQ = 100RR Example TQ = 100

Tq = 100 is a bit too large to be a good time slice, typically Tq < E[Tq].Tq = 100 is a bit too large to be a good time slice, typically Tq < E[Tq].

Figure 15: RR Scheduling Example for Tq=100

Figure 15: RR Scheduling Example for Tq=100

Page 46: Intro to O/S Scheduling

RR Example TQ = 30RR Example TQ = 30

Tq = 30 seems to be a good time slice.Tq = 30 seems to be a good time slice.

Figure 16: RR Scheduling Example for Tq = 30

Figure 16: RR Scheduling Example for Tq = 30

Page 47: Intro to O/S Scheduling

RR Features SummaryRR Features Summary

Some characteristics of RR scheduling:

1. Preemptive (at quantum ).2. Less Sensitive to order of arrival.3. Quantum should not be too small .4. Sensitive to overly large (approximates FCFS).5. Low overhead.6. Starvation Impossible.

Some characteristics of RR scheduling:

1. Preemptive (at quantum ).2. Less Sensitive to order of arrival.3. Quantum should not be too small .4. Sensitive to overly large (approximates FCFS).5. Low overhead.6. Starvation Impossible.