CPU Scheduling: - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

CPU Scheduling:

Description:

Elapsed time between the submission of a request until there ... After this time has elapsed, the process is preempted and added to the end of the ready queue. ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 43
Provided by: mario231
Category:

less

Transcript and Presenter's Notes

Title: CPU Scheduling:


1
CPU Scheduling
  • Chapter 9

2
Goals of Scheduling
  • Quick response time
  • Fast throughput
  • Processor efficiency

3
Type of Scheduling
  • Long-term
  • performed when new process is created
  • Medium-term
  • swapping
  • Short-term
  • which ready process to execute next

4
Long-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

5
Medium-Term Scheduling
  • Main memory management
  • Swapping
  • Based on the need to manage multiprogramming

6
Short-Term Scheduling
  • Determines which process gets the cpu.
  • Only picks processes that are currently in
    memory (in the ready state /queue)
  • Can not take a long time to pick.

7
Scheduling and Process State Transition
New
Long-term scheduling
Long-term scheduling
Exit
Running
Ready, suspend
Ready
Short-term scheduling
Medium-term scheduling
Blocked
Blocked, suspend
Medium-term scheduling
8
Short-Term Scheduling Criteria
  • User-oriented
  • Response Time
  • Elapsed time between the submission of a request
    until there is output.
  • System-oriented
  • effective and efficient utilization of the
    processor

9
Short-Term Scheduling Criteria
  • Performance-related
  • measurable such as response time and throughput
  • Not performance related
  • predictability

10
Decision Mode Short term scheduler
  • Nonpreemptive
  • Once a process is in the running state, it will
    continue until it terminates or blocks itself for
    I/O
  • Preemptive
  • Currently running process may be interrupted and
    moved to the Ready state by the operating system
  • Allows for better service since any one process
    cannot monopolize the processor for very long

11
Scheduler Goals
  • Fairness
  • - each process gets a fair share of CPU time
  • Efficiency
  • - keep the CPU busy
  • Response Time
  • - cant seem slow to users
  • Turnaround
  • - minimize the time batch users must wait for
    output
  • Throughput
  • - maximize the number of jobs processed and
    completed per unit time (more batch oriented)

12
Which goal?
  • Cant do all of them - some goals contradict
  • Old method
  • - Batch system - one at a time - read the next
    set of cards or tape
  • Multi-user systems required something better than
    sequential batch processing
  • - Most unpredictable aspect is the amount of time
    waiting on I/O
  • Run to completion (non-preemptive) vs. preemptive
  • Old batch systems were run to completion which
    was simple and easy to implement
  • Preemption enhances fairness and throughput, but
    leads to problems of synchronization

13
Scheduling Algorithms
  • Common Scheduling Algorithms
  • FCFS or FIFO
  • Round-Robin
  • Shortest Process Next or Shortest Job first
  • Shortest Remaining Process Next
  • Multi level feedback / Priority
  • Highest Response Ratio Next
  • Common measurements
  • w time spent in system so far
  • e time spent in execution
  • s total time required by process
  • Turnaround time total time in system (Tq)
  • Normalized turnaround Tq/Ts

14
First-IN, First-OUT (FIFO) Scheduling
  • Example Process Burst Time
  • P1 24
  • P2 3
  • P3 3
  • Suppose that the processes arrive in the order
    P1 , P2 , P3 The Gantt Chart for the schedule
    isAverage waiting time (0 24 27)/3
    17

15
First Come First Serve
16
First Come First Serve
17
FIFO Scheduling (Cont.)
  • Suppose that the processes arrive in the order
  • P2 , P3 , P1 .
  • The Gantt chart for the schedule is
  • Waiting time for P1 6 P2 0 P3 3
  • Average waiting time (6 0 3)/3 3
  • Much better than previous case.

P1
P3
P2
6
3
30
0
18
FIFO (First in first out)
  • Very simple
  • Non Preemptive
  • Favors long process over short process
  • Favors CPU bound over I/O bound
  • Often used in combination with other algorithms

19
Alternating Sequence of CPU And I/O Bursts
20
Round Robin
  • Very simple - Oldest fair algorithm
  • No priorities - equal importance
  • Each process gets a small unit of CPU time (time
    quantum), usually 10-100 milliseconds. After
    this time has elapsed, the process is preempted
    and added to the end of the ready queue.
  • Always have overhead of the process switch, so
    the quantum length can be important for
    efficiency
  • q large ? FCFS
  • q small ? q must be large with respect to context
    switch, otherwise overhead is too high.

21
Process set for our examples
Process Arrival Time Service Time
Assume process switch requires 3 units of
time. Assume 1 unit of time is required for
algorithm execution. Assume scheduling
algorithm itself is non Pre emptable.
22
Round Robin (q 5)
OS
0 3 10 18 26
34 38 46 53
61
Process
A 7 B 15 C 23 D
31 B 35 E 43 F 50 C 58
A - 4 B - 6 C - 13 D - 8 B - 1 E - 5 F - 4 C -
8 G - 12 H - 4 D - 3 C - 3 G - 7
61 69 76 82
88 94
OS
Process
G 66 H 73 D 79 C
85 G 93 G 96
23
Round Robin (q 5)
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 6.27
24
Round Robin
  • Reduces bias in favor of long processes but....
  • What about CPU bound processes?
  • What are some solutions?

25
Shortest Process Next
  • Predictability of longer processes is reduced
  • If estimated time for process not correct, the
    operating system may abort it
  • Possibility of starvation for longer processes
  • Still penalizes short jobs that arrive after long
    ones begin

26
Shortest Process Next (Non- Pre-emptive)
OS
0 3 11 19 30
37 44 52 67
Process
A 7 B 16 D 27 F
34 H 41 E 49 G 64 C 80
A - 4 B - 6 C - 13 D - 8 C - 13 E - 5 F - 4 G -
12 H - 4
T 7
T 16
T 27
27
Shortest Process Next
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 3.33
28
Shortest Remaining Time
  • Scheduling algorithm executes when either
  • current process completes or
  • new process arrives
  • Scheduler chooses job with earliest expected
    completion time (including estimated process
    switch times)

29
Shortest Remaining Time
OS
0 3 6 11-12
14 22-23 26 28
33 40
Process
A 5 A 8 B 13
B 19 E 25 E 27 E 30 F
37
40 47 58 73
OS
Process
H 44 D 55 G 70 C 86
30
Shortest Remaining time (Pre-emptive)
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 3.70
31
Highest Response Ratio Next (HRRN)
  • Scheduler only executes when a process completes
  • Scheduler chooses the process with the largest
    value of

time spent waiting expected service time
expected service time
32
Highest Response Ratio Next (HRRN)
OS
0 3 10 19 35
42 50 57 68
Process
A 7 B 16 C 32 F
39 E 47 H 54 D 65 G 80
T 16 C 5 13/ 13 1.38 D 3 8/8 1
37
T 39 D 26 8/ 8 4.25 E 20 5/5
5 G 14 12 /12 2.16 H 12 4/4 4
T 47 D 34 8/ 8 5.25 G 22 12 /12
2.83 H 20 4/4 6
T 32 D 19 8/ 8 3.37 E 13 5/5
3.6 F 11 4/4 3.75 G 7 12 /12
1.58 H 5 4/4 2.25
T 54 D 41 8/ 8 6.12 G 29 12 /12 3.41
33
Highest Response Ratio Next (HRRN)
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 4.14
34
Feedback
  • Penalize jobs that have been running longer
  • Dont know remaining time process needs to execute

35
Multi-level Feedback
Arriving processes are inserted into level
1 Scheduling algorithm executes when job finishes
or quantum expires Picks the next process in the
lowest numbered queue
36
Multi-level Feedback
37
Multi-level Feedback
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 9.64
38
Priorities
  • Scheduler chooses a process of higher priority
    over one of lower priority
  • Have 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

39
Multiple Priority Queue
  • Some variation of this scheme is used in most of
    todays OS.
  • A process can move between the various queues
    aging can be implemented this way.

40
Multiple Priority Queue
  • Multilevel-feedback-queue scheduler defined by
    the following parameters
  • number of queues
  • scheduling algorithms for each queue
  • method used to determine when to upgrade a
    process
  • method used to determine when to demote a process
  • method used to determine which queue a process
    will enter when that process needs service

41
Recommended Practice
Process A/T Finish Ts
Turn
Tq/Ts /around
AVG 9.64
42
Recommended Practice
  • Compete the the table using the following
    policies
  • First Come First Served
  • Round Robin (q 4)
  • Shortest Process next
  • Shortest Remaining time
  • Highest Response Ration Next
  • Multi- level feedback with unbounded number of
    levels starting at level 1 Processes in level i
    running for 3i units. IE q level i 3i)
Write a Comment
User Comments (0)
About PowerShow.com