You are on page 1of 7

29/10/2019

Preemptive scheduling
Most of work on scheduling has been focused on
fully preemptive systems, because they allow higher
responsiveness:

Preemptive

 Non Preemptive

Disadvantages of preemptions Cache related preemption delay

However, each preemption has a cost: CRPD: delay introduced by high priority tasks that evict
cache lines containing data used in the future:
 Context switch cost: time taken by the scheduler
to suspend the running task, switch the context, Cache
write B
and dispatch the new incoming task.
1
A
B

2

write A read A read A


Extra time is needed for
cache cache
reading A, thus increasing
hit miss
the WCET of 2.

WCET Preemption indirect costs


Task executing alone (or non preemptively) on a single CPU:  Pipeline cost: time to flush the pipeline when a task
is interrupted and to refill it when task is resumed.
i  Bus cost: time spent waiting for the bus due to
additional conflicts with I/O devices, caused by extra
Task experiencing preemptions by higher priority tasks: accesses to the RAM for the extra cache misses.

i CRPD Pipeline
context
Bus
switch
NP
Ci
WCETi
Ci = CiNP + CRPD

1
29/10/2019

Preemption indirect costs Preemption cost


 Additional preemptions: the extra execution time  WCETs may increase up to 35% in the presence
also increases the number of preemptions: of preemptions (less efficiency):

Non Preemptive

WCET
Preemptive

WCET
+35%

 WCETs become also more variable (less predictability):

Influence on WCETs Advantages of NP scheduling


 As a consequence, WCETs estimations for  It reduces context-switch overhead:
preemptive tasks are  making WCETs smaller and more predictable.
 higher
 less predictable (highly variable)  It simplifies the access to shared resources:
 No semaphores are needed for critical sections
WCET non-preemptive
distribution
 It reduces stack size:
preemptive  Task can share the same stack, since no more than
one task can be in execution

 It allows achieving zero I/O Jitter:


 finishing_time – start_time = Ci (constant)
Cmin C

Advantages of NP scheduling Disadvantages of NP scheduling


In fixed priority systems can improve schedulability:
2 4  In general, NP scheduling reduces schedulability
U    0.97 introducing blocking delays in high priority tasks:
RM 5 7
1
0 5 10 15 20 25 30 35

2
0 7 14 21 28 35
deadline miss
NP-RM deadline deadline
 miss  miss
1
0 5 10 15 20 25 30 35

2
0 7 14 21 28 35

2
29/10/2019

Disadvantages of NP scheduling Non preemptive anomalies


 The utilization bound under non preemptive 1
scheduling drops to zero:
2

C1 = 
3
1
T1 double speed
2  deadline miss
C2 = T1 T2 1
2
 C2
U = + 0 3
T1 

Non-preemptive analysis Non-preemptive analysis


Analysis of non-preemptive systems is more Hence, the analysis of i must be carried out for
complex, because the largest response time may not multiple jobs, until all tasks with priority  Pi are
occur in the first job after the critical instant. completed.
1 1
6 12 18 24 6 12 18 24

2 2
0 10 20 30 0 10 20 30

3 3

Self-pushing phenomenon NOTE


High priority jobs activated during non-preemptive execution of Analysis can reduce to the first job of each task if and only if
lower priority tasks are pushed ahead and introduce higher 1. the task set is feasible under preemptive scheduling;
delays in subsequent jobs of the same task. 2. All deadlines are less than or equal to periods.

Response time analysis Response time analysis


(for preemptively feasible task sets with D  T) (for preemptively feasible task sets with D  T)
Bi Ii Bi Ii
Ci Ci
i i
rik sik fik rik sik fik
WOi = max{sik – rik} WOi = max{sik – rik}
k k

Bi  max{C j } NOTE: the end of Ii cannot coincide with the activation of


Pj  Pi a higher priority task, because it would increase Ii.
hp(i) set of tasks with priority higher than Pi i 1
 WOi 
lp(i) set of tasks with priority lower than Pi
Hence x +1
WOi  Bi    1 Ck
must be used k 1  Tk 
WOi  Worst-case Occupied time: due to blocking Bi from instead of x
Ri = WOi + Ci
lp(i) tasks and interference Ii from hp(i) tasks.

3
29/10/2019

Response time analysis Trade-off solutions


(for preemptively feasible task sets with D  T)
The following solutions can be adopted to balance
i 1 between the two extreme approaches:
WO i
( 0)
 Bi   Ck
k 1
 Preemption Thresholds
 Allow preemption only to tasks with high importance
 WOi( s 1)
i 1 
WO (s)
 Bi     1 C k  Deferred Preemptions
i

k 1  Tk 
  Allow preemption only after a given time interval

 Fixed Preemption Points


Stop when WOi( s )  WOi( s 1)
 Allow preemption only at given points in the task code
Ri = WOi + Ci
19

Preemption Thresholds (PT) Unfeasible task set


Each task has two priorities:
1
2
preemptive

Pi nominal priority: used to enqueue the task in the


ready queue and to preempt
Fully

2
2
i threshold priority: used for task execution (i  Pi) 5 deadline miss
3
0 2 4 6 8 10 12 14 16 18

deadline miss
threshold
1
2
non preemptive

nominal
2
2
Fully

A task i can be preempted 3


5

by h only if Ph > i 0 2 4 6 8 10 12 14 16 18

But feasible with PT Response time analysis (PT)


1 can preempt 3 i can only be preempted i can only be preempted
2 cannot preempt 3 by tasks h: Ph > Pi by tasks h: Ph > i
Pi i 1 cannot preempt 2 i
3 3 1 2
i

2 3 2 2
Pi
sik fik
3
5
1 2  sik 
sik  Bi  (k 1)Ci   
h:Ph Pi  Th
1 Ch

NOTE:
The same feasible schedule is obtained by splitting 3 in  f s 
two non preemptive chuncks: q31 = 2, q32 = 3 f ik  sik  Ci    Th
ik
 ik 1 Ch
Th 
h:Ph  i  

4
29/10/2019

Deferred Preemption Interesting problem

Each task can defer preemption up to qi Given a preemptively feasible task set, find the
longest non-preemptive interval Qi for each task
that still preserves schedulability.

Under EDF Baruah - ECRTS 2005

Under Fix. Pr. Gang-Buttazzo, RTCSA 2009


q2

Often, high priority tasks have Qi = Ci, meaning


q3 that they can execute fully non preemptively.
Bi  max{q j }
Pj  Pi

Blocking tolerance A simple bound for Qi


To compute Qi, we need to find the maximum The longest non preemptive interval Qi is related
blocking time that can be tolerated by a task, called with the maximum blocking time i that can be
blocking tolerance (i): tolerated by higher priority tasks.

 i Ck  Bi It must be i Bi   i
     U lub (i )
 k 1 Tk  Ti
where Bi  max{q j }
Pj  Pi

 i

 i  Ti U lub (i )   U k 
 k 1  Hence: i max{q j }   i
Pj  Pi

A simple bound for Qi A simple bound for Qi


i max{q j }   i i=1 q2  1
Pj  Pi
i=2 q3  min{1, 2}
max {q2, q3, q4}  1
i=1
i=3 q4  min{1, 2, 3}
i=2 max {q3, q4}  2
i=3 q4  3
i=1 Q1 =  (non preemptive)
i=1 q2  1
i=2 q3  min{1, 2} i2 Qi = min{Qi-1, i-1}
i=3 q4  min{1, 2, 3}

5
29/10/2019

Using Qi Experimental Results


Once Qi is computed, it can be used as follows: Avg. # of preemptions n = 16
x 104 Fully preemptive
 Partition each task into a set of NP regions no larger 12
than Qi inserting suitable preemption points.
10

 Incapsulate critical sections into NP regions, avoiding –70%


8
complex concurrency control protocols.
6

preemption points critical section 4


Using Qi
2

Qi Qi 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 U

Fixed Preemption Points (FPP) Example


Let: 1 be fully non preemptive: q11 = C1 = 3
 Each task i is divided in mi chunks: qi,1 ... qi,m
2 consisting of 2 NP chunks: q21 = 1, q22 = 3, C2 = 4
i

 It can only be preempted between chunks 3 be fully non preemptive: q31 = C3 = 2

1
0 6 12 18 24

2
0 9 18 27

3

Note that:
 The worst case response time of 2 does not occur in
Bi  max{q max
j }
the first instance.
Pj  Pi  The interference on 2 is larger than B2 + C1.

Response Time Analysis (FPP) Response Time Analysis (FPP)


 Must be carry out up to the busy period of each task. 1
0 6 12 18 24

2
1
0 9 18 27
0 6 12 18 24
3
2
0 9 18 27

3 Busy period of 2
Level-i busy period
Busy period of 2 It can be computed as the shortest interval that satisfies:
Li up to job Ni:
Level-i busy period Li  B i   Th
Ch
Li
It is the interval in which the processor is busy executing h : Ph  Pi
Ni 
tasks with priority higher than or equal to Pi, including Ti
blocking times. Initial value can be: L(i 0 )  B i  
h : Ph  Pi
Ch

6
29/10/2019

Response Time Analysis (FPP) Response Time Analysis (FPP)


for (i=1 to n) {
0
qilast Ni  Li / Ti
i
0

sik(0)  (k 1)Ti  Ci  qilast 
k=1
sik fik do { s  B  (k 1)C  C  qlast    sik 
(k-1)Ti
ik i i i i   1 Ch
 Th 
   
h:Ph  Pi

 f ik  sik  q last
sik
sik  Bi  (k 1)Ci  Ci  qilast  1 Ch
i

h:Ph  Pi 
Rik  f ik  (k  1)Ti
T h 
if (Rik > Ri) then Ri = Rik
f ik  sik  qilast

Rik  f ik  ( k  1)Ti
s ( 0)
ik 
 (k 1)Ti  Ci  q
last
i  if (Ri > Di) then return(UNFEASIBLE)
k++
NOTE: } while (k  Ni)
Li }
Ri  max Rik  Ni 
Ti return(FEASIBLE)
k[1, N i ]

Special cases Final remarks


 Preemption Thresholds are easy to specify, but it is difficult
 Fully non preemptive scheduling
to predict the number of preemptions and where they
qilast  Ci occur  large preemption overhead

Bi  max{C j }  Deferred Preemption allows bounding the number of


Pj  Pi
preemptions but it is difficult to predict where they occur.
Note that the analysis assumes qilast  0
 Deferred Preemption  Fixed Preemption Points allow more control on
qilast  0 preemptions and can be selected on purpose (e.g., to
minimize overhead, stack size, and reduce WCETs).
Bi  max{Q j }
Pj  Pi  A large final chunk in i reduces the interference from hp-
tasks (hence Ri), but creates more blocking to hp-tasks.

You might also like