17
Uniprocessor Scheduling Chapter 9

Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Embed Size (px)

Citation preview

Page 1: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Uniprocessor Scheduling

Chapter 9

Page 2: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Aim of Scheduling

To improve:

Response time: time it takes a system to react to a given input

Turnaround Time (TAT) = Total time spent in the system = waiting time + service time

Throughput: jobs per minute (inverse of TAT)

Page 3: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Types of Scheduling

Page 4: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Part of the swapping function Swapping-in decision is based on the need to manage the degree of

multiprogramming

Known as the dispatcher Executes most frequently Invoked when an event occurs: Clock interrupts, I/O, OS calls, Signals, etc.

Short-Term Scheduling

Medium-Term Scheduling

Determines which programs are admitted to the system for processing Controls the degree of multiprogramming More processes, smaller percentage of time each process is executed Which job to admit? FCFS, Priority, expected exec time, I/O req.s

Long-Term Scheduling

Page 5: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Evaluation Criteria for Short-Term Scheduling Policies:

User-oriented, performance relatedTurnaround time: time between submission and completionResponse Time: time between submission and the first output.

User-oriented, otherPredictability: For users, it is important that a job runs the same way

(Time & cost) regardless of the system load

System-oriented, Performance relatedMaximize Throughput: rate at which processes are completedProcessor utilization: percentage of time that the processor is busy

System-oriented, otherFairnessEnforcing priorities?Balancing resources? – Is it favoring processes that do not request

stressed resources?

Page 6: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Priorities

Scheduler chooses a process of higher priority over one of lower priority Use multiple ready queues to represent each level of priority Lower-priority may suffer starvation

allow a process to change its priority based on its age or execution history

Nonpreemptive Once a process is in the running state, it will continue until it terminates or blocks

itself Preemptive

Currently running process may be interrupted and moved to the Ready state due to an external event.

No single process can monopolize the processor for very long Better service

Decision Mode

Page 7: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Process Scheduling Example

Page 8: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

First-Come-First-Served (FCFS)

Each process joins the Ready queue

Nonpreemptive

The oldest process in the ready queue is selected to run next

Disadvantage:

A short process may have to wait a very long time before it can execute

Advantage: Favors CPU-bound processes

I/O processes have to wait until CPU-bound process completes

0 5 10 15 20

A

B

C

D

E

Page 9: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Preemption based on a clock (time slicing)

Clock interrupt is generated at periodic intervals (time slice is

determined a priori)

When an interrupt occurs, the currently running process is

placed in the ready queue and next ready job is selected to run

0 5 10 15 20

A

B

C

D

E

Round-Robin (RR)

Page 10: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Nonpreemptive

Process with shortest expected processing time is selected next.

For batch jobs, user is required to estimate the running time. If estimated time

for process not correct, the OS may abort it.

For interactive jobs, OS tries to predict it.

Short process jumps ahead of longer processes

Possibility of starvation for longer processes

0 5 10 15 20

A

B

C

D

E

Shortest Process Next (SPN)

Page 11: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Process Scheduling Example

Page 12: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Preemptive version of shortest process next policy

Achieves better turnaround time as compared to SPN, because a short job is given immediate preference to a running longer job

Risk of starvation for long jobs

Must estimate the remaining processing time Not easy!

0 5 10 15 20

A

B

C

D

E

Shortest Remaining Time (SRT)

Page 13: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Nonpreemptive

An important performance criteria to minimize is:

Normalized TurnAround Time = TAT / ServiceTime

Choose next process with the highest response ratio R (so that it does not get any higher!):

A

B

C

D

E

0 5 10 15 20

Highest Response Ratio Next (HRRN)

(s) Time Service

(s) Time Service (w) ingspent wait Time R

No starvation possible with this formula, shorter jobs are favored against longer ones

Page 14: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Hard to predict the remaining time a process needs to execute.

Instead, we can penalize jobs that have been running longer

Each subsequent time that a job is preempted, it is moved to a lower-priority ready queue. This way, a longer process will gradually drift downward in the hierarchy of queues.

starvation may occur if new jobs enter the system frequently To remedy this, increase priority if a job spends too much time in a lower

priority queue and give more time quantum to lower priority queues.

Feedback (FB)

Page 15: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

A Comparison of Scheduling Policies

Page 16: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Characteristics of Various Scheduling Policies

Page 17: Uniprocessor Scheduling Chapter 9. Aim of Scheduling To improve: Response time: time it takes a system to react to a given input Turnaround Time (TAT)

Traditional UNIX Scheduling

Designed to provide good response time for interactive users while ensuring that low-priority background jobs do not starve

Multilevel feedback using round robin within each of the priority queues. 1-second preemption (much smaller in modern systems; 10-100ms)

Priorities are recomputed once per second.

It is based on process type and execution history

In decreasing order of priority, the bands are as follows: Swapper Block I/O device control File manipulation Character I/O device control User processes