You are on page 1of 5

Short Term Scheduling Policies

The Issues

Short Term Scheduling Policies


Common Assumptions - 1

For any of the Short Term scheduling policies, one needs to compute
the following :
i) Specify the Gantt Chart ( A chart depicting the allocation sequence
of each of the processes {User Process block as well as Kernel
Processes} to the CPU as well as the corresponding CPU
occupancy time.)
ii) The average Turn around time for ALL the concerned USER
Processs CPU bound Chunks.
iii) The average Waiting time for ALL the concerned USER Processs
CPU bound Chunks.
.

4/28/2012

CPU_Sche_Policy

PSD

Short Term Scheduling Policies


Common Assumptions - 2
1.

Each of the Process has to be scheduled by the Dispatcher.

2.

Context Switching + Dispatcher Time + Context Switching has to be there


between any two processes .

Context Switch Dispatcher

1 Unit

Context Switch

1 Unit

Enqueuer
2 Units

4/28/2012

CPU_Sche_Policy

PSD

(a)First come First Served (FCFS).


(b) Shortest Job First (SJF) based on the Estimated
Service Time.
(c) Dead Line based (starting with job having shortest
service time in case of Same Deadline Limits).
(d) Pre-Fixed Priority Based with Fixed Number of
Priority levels , where each of the Processes
assigned a Pre-Fixed Priority from the set of
available number of Priorities.

Arrival of any new Process will cause the running user process to be preempted and invoking of the Enqueuer while invoking of Enqueuer will also
cause the context switch before & after the Enqueuer.

3.

For any of the specified Ready Queue Status one needs to compare
the performances of the adopted scheduling policies following non
preemptive scheduling policies :
(a)First come First Served (FCFS).
(b) Shortest Job First (SJF) based on the Estimated Service Time.
(c) Dead Line based (starting with job having shortest service time in case of
Same Deadline Limits).
(d) Pre-Fixed Priority Based with Fixed Number of Priority levels , where
each of the Processes assigned a Pre-Fixed Priority from the set of
available number of Priorities.

Non Pre Emptive Short Term Scheduling Policies

Context Switch
1 Unit

3 Units

Assume Context switching time = 1 unit (fixed).


Dispatcher Execution time = 3 units (fixed).
Enqueuer Execution time = 2 units (fixed).

Context Switch
1 Unit

4. There cannot be two Successive Context Switches.

4/28/2012

CPU_Sche_Policy

PSD

4/28/2012

CPU_Sche_Policy

PSD

Short Term Scheduling Policies


Non Pre-emptive FCFS - 1

Case Study - 1
Consider a typical Ready queue status of a computer
system having Uni-processor with support for multi
programming as given below.

The Policy :
a) Form the READY Queue of Processes
based on their Arrival Time.
b) Select Process from the READY Queue
Front for Dispatching.
c) Repeat the previous step till READY
Queue is Empty.

-----------------------------------------------------------------------------------Process Arrival Time Service time


Deadline Limits
Chunk No. in units in units (Estimated) in units
-----------------------------------------------------------------------------------P0
10
200
560
P1
5
400
1100
P2
13
250
none
P3
8
50
250
P4
20
300
650

------------------------------------------------------------------------4/28/2012

CPU_Scheduling

CPU_Sche_Policy

PSD

PSD

4/28/2012

CPU_Sche_Policy

PSD

Short Term Scheduling Policies


Non Pre-emptive FCFS - 2

Short Term Scheduling Policies


Non Pre-emptive FCFS - 3

The READY Queue / List structure :


-------------------------------------------------------------------------Process Arrival Time Service time
-------------------------------------------------------------------------P1
5
400
P3
8
50
P0
10
200
P2
13
250
P4
20
300
-------------------------------------------------------------------------4/28/2012

CPU_Sche_Policy

PSD

GANTT Chart

EnQEnQEnQEnQDiSEnQDiS
P1 P3 P0 P2 P1 P4 P1
5

11

4/28/2012

Short Term Scheduling Policies


Non Pre-emptive FCFS - 4

PSD

CPU_Scheduling

PSD

PSD

DiS

DiS

P1 P3 P3 P0
429 434

CPU_Sche_Policy

DiS
P2

P0

484 489

689

P2

694

DiS
P4
944

P4

949

PSD

1249

Total Waiting Time = 24+426+479+681+929 = 2539 units


Average Waiting Time = 2539 / 5 = 507.8 units

4/28/2012

CPU_Sche_Policy

PSD

10

Short Term Scheduling Policies


Non Pre_emptive SJF - 2
Ready List / Queue Structure

The Policy :
a) Form the READY Queue of Processes
based on their Estimated Service Time.
b) Select Process from the READY Queue
Front for Dispatching.
c) Repeat the previous step till READY
Queue is Empty.

CPU_Sche_Policy

29

Average Turn Around Time = 3739 / 5 = 747.8 units

Short Term Scheduling Policies


Non Pre-emptive SJF - 1

4/28/2012

24

Total Turn Around Time = 424+476+679+931+1229 =3739 units

P1
5
400
429- 5 = 424 29-5 = 24
P3
8
50
484-8 = 476 434-8 = 426
P0
10
200
689-10= 679 489-10= 479
P2
13
250
944-13=931 694-13= 681
P4
20
300
1249-20=1229 949-20= 929
-----------------------------------------------------------------------------------------

CPU_Sche_Policy

17 21

Short Term Scheduling Policies


Non Pre-emptive FCFS - 5

The Various Time Structure :


-------------------------------------------------------------------------Process Arrival Time Service time Turnaround Waiting
Time
Time
--------------------------------------------------------------------------

4/28/2012

14

-------------------------------------------------------------------------Process Arrival Time Service time Deadline Limits


No.
in units
in units
in units
-------------------------------------------------------------------------P3
8
50
250
P0
10
200
560
P2
13
250
none
P4
20
300
650
P1
5
400
1100
-------------------------------------------------------------------------11

4/28/2012

CPU_Sche_Policy

PSD

12

Short Term Scheduling Policies


Non Pre-emptive SJF - 3

Short Term Scheduling Policies


Non Pre-emptive SJF - 4
The various Time Status:
-------------------------------------------------------------------------Process Arrival Time Service time Turnaround Waiting
Time
Time
--------------------------------------------------------------------------

GANTT Chart

EnQEnQEnQEnQDiSEnQDiS
P1 P3 P0 P2 P3 P4 P3
5

11

14

17

21

24

DiS

DiS

P3 P0 P0 P2

29

79

84

DiS
P4

P2

284 289

539

DiS
P1

P4

544

844

P1

849

P3
P0
P2
P4
P1

1249

8
10
13
20
5

50
200
250
300
400

79-8 = 71
284-10= 274
539-13=526
844-20=824
1249- 5 = 1244

29-8 = 21
84-10= 74
289-13= 276
544-20= 524
849-5 = 844

-----------------------------------------------------------------------------------------

4/28/2012

CPU_Sche_Policy

PSD

13

4/28/2012

Average Turn Around Time = 2939/ 5 = 587.9 units


Total Waiting Time = 21+74+276+524+844 = 1739 units

CPU_Sche_Policy

347.8 units

PSD

15

4/28/2012

Ready List/ Queue Structure

CPU_Scheduling

PSD

PSD

16

GANTT Chart

-------------------------------------------------------------------------Process Arrival Time Service time Deadline Limits


No.
in units
in units
in units
-------------------------------------------------------------------------P3
8
50
250
P0
10
200
560
P4
20
300
650
P1
5
400
1100
P2
13
250
none
-------------------------------------------------------------------------CPU_Sche_Policy

CPU_Sche_Policy

Short Term Scheduling Policies


Non Pre-emptive Deadline Based - 3

Short Term Scheduling Policies


Non Pre-emptive Deadline Based - 2

4/28/2012

14

The Policy :
a) Form the READY Queue of Processes
based on their pre fixed Deadline.
b) Select Process from the READY Queue
Front for Dispatching.
c) Repeat the previous step till READY
Queue is Empty.

Total Turn Around Time = 71+274+526+824+1244 = 2939 units

4/28/2012

PSD

Short Term Scheduling Policies


Non Pre-emptive Deadline Based - 1

Short Term Scheduling Policies


Non Pre-emptive SJF - 5

Average Waiting Time = 1739 / 5 =

CPU_Sche_Policy

PSD

EnQEnQEnQEnQDiSEnQDiS
P1 P3 P0 P2 P3 P4 P3
5

17

11

4/28/2012

14

17 21

24

29

DiS

DiS

P3 P0 P0 P4
79

84

284

P4

289

CPU_Sche_Policy

DiS
P1
589

PSD

594

P1

DiS
P2
994 999

P2
1249

18

Short Term Scheduling Policies


Non Pre-emptive Deadline Based - 4

Short Term Scheduling Policies


Non Pre-emptive Deadline Based - 5

The various Time Status:


-------------------------------------------------------------------------Process Arrival Time Service time Turnaround Waiting
Time
Time
-------------------------------------------------------------------------P3
P0
P4
P1
P2

8
10
20
5
13

50
200
300
400
250

Total Turn Around Time = 71+274+569+989+1236


= 3139 units

79-8 = 71
29-8 = 21
284-10= 274 84-10= 74
589-20= 579 289-20= 269
994- 5 = 989 594-5 = 589
1249-13=1236 999-13=986

Average Turn Around Time = 3139 / 5 = 627.8 units


Total Waiting Time = 21+74+269+589+ 986=1939 units
Average Waiting Time = 1939 / 5 = 387.8 units

-----------------------------------------------------------------------------------------

4/28/2012

CPU_Sche_Policy

PSD

19

Non Pre-emptive Priority based Scheduling


Basic Features - 1
Each process is assigned a pre-fixed priority ( a non
ve integer between 1 .. 10) either by the System
Manager depending on the jobs importance OR by the
internal policy of the concerned operating system.
Lower priority value  Higher Priority.
Higher priority processes are dispatched / scheduled
first.
Processes having the same priority are chosen on a
First Come First Served (FCFS) basis.

CPU_Sche_Policy

PSD

21

Non Pre-emptive Priority Based Scheduling


Case Study- 1
Consider the following Process mix

CPU_Scheduling

PSD

PSD

20

As soon as any new process is brought in the memory by the Medium Term Scheduler,
the following events take place in sequence:
a) The currently running process is brought back into Ready
State from the Running State.
b) The Enqueuer is brought into execution (running state) after
a context switch which brings the newly arrived process in
the Ready Queue.
c) Next the Dispatcher is invoked in order to select the process AFRESH
having the current highest priority in the Ready Queue to be
dispatched next.
Thus the previously Running Process may re-run if that is still having the Highest
Priority OR alternately a new process may get dispatched.

4/28/2012

CPU_Sche_Policy

PSD

22

Consider the Process mix to be scheduled in order of


arrival.
-----------------------------------------------------------------------------------Process Arrival Time Service time
Pre-Assigned
Chunk No. in units
in units
Priority
-----------------------------------------------------------------------------------P1
10
400
3
P3
60
500
4
P0
80
200
1
P2
130
250
1
P4
200
300
2

-------------------------------------------------------------------------

Priority_Sche_Policy

PSD

Non Pre-emptive Priority based Scheduling


Case Study - 2

-----------------------------------------------------------------------------------Process Arrival Time Service time


Pre-Assigned
Chunk No. in units
in units
Priority
-----------------------------------------------------------------------------------P0
80
200
1
P1
10
400
3
P2
130
250
1
P3
60
500
4
P4
200
300
2

4/28/2012

CPU_Sche_Policy

Non Pre-emptive Priority based Scheduling


Basic Features - 2

4/28/2012

4/28/2012

-------------------------------------------------------------------------

23

4/28/2012

CPU_Sche_Policy

PSD

24

Non Pre-emptive Priority based Scheduling


Case Study - 3

Non Pre-emptive Priority based Scheduling


GANTT Chart -1

Dispatcher & Enqueuer Block Structures BUT with no two


consecutive Context Switches.

10

Context Switch Dispatcher Context Switch

1 Unit

3 Units

EnQ
P1
(Pr#3)

1 Unit

13

DiS
P1

P1(Pr # 3) [42 Done] EnQ


P3
{358 Left}
(Pr#4)
18

60

P0(Pr # 1) [42 Done] EnQ


P2
{158 Left}
(Pr#1)

DiS
P0

DiS
P1

63

P1(Pr # 3) [54 Done] EnQ


P0
{346 Left}
(Pr#1)

68

80

P0(Pr # 1) [104 Done] EnQ


P4
{96 Left}
(Pr#2)

DiS
P0

83

88

DiS
P0

Context Switch Enqueuer Context Switch

1 Unit

2 Units

4/28/2012

CPU_Sche_Policy

88

1 Unit

PSD

25

Non Pre-emptive Priority based Scheduling


GANTT Chart - 2

130

4/28/2012

133

138

CPU_Sche_Policy

200

203

208

PSD

26

Non Pre-emptive Priority based Scheduling - 8


The various timing Calculations

P0(Pr # 1) [200 Done]


{COMPLETED}
208

DiS
P1

DiS
P2

304

P2(Pr # 1) [250 Done]


{COMPLETED}

309

P1(Pr # 3) [400 Done]


{346 was Left}

864 869

559

DiS
P3

1215

DiS
P4

-----------------------------------------------------------------------------------Process Arrival Time Turn Around time Waiting Time


Chunk No. in units
in units
in units
[ Priority ]
-----------------------------------------------------------------------------------P0 [1]
80
304 80 = 224
88-80 = 8
P1 [3]
10
1215 10 = 1205
18 10 = 8
P2 [1]
130
559 130 = 429
309 -130 = 179
P3 [4]
60
1720 60 = 1660 1220 60 = 1160
P4 [2]
200
864 200 = 664
564 200 = 364

P4(Pr # 2) [300 Done]


{COMPLETED}

564

864

P3(Pr # 4) [500 Done]


{COMPLETED}

1220

1720

------------------------------------------------------------------------4/28/2012

CPU_Sche_Policy

PSD

27

4/28/2012

Priority_Sche_Policy

PSD

28

Short Term Scheduling Policies


Non Pre-emptive Priority Based - 9
Total Turn Around Time = 224+1205+429+1660+664
= 4182 units
Average Turn Around Time = 4182 / 5 = 836.4 units
Total Waiting Time = 8+8+179+1160+ 364= 1719 units
Average Waiting Time = 1719 / 5 = 343. 8units

4/28/2012

CPU_Scheduling

CPU_Sche_Policy

PSD

PSD

29

You might also like