Skip to content

Commit ccc9d65

Browse files
Claudio Scordinoingomolnar
authored andcommitted
sched/deadline: Add documentation about GRUB reclaiming
This patch adds the documentation about the GRUB reclaiming algorithm, adding a few details discussed in list. Signed-off-by: Claudio Scordino <claudio@evidence.eu.com> Signed-off-by: Luca Abeni <luca.abeni@santannapisa.it> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Daniel Bristot de Oliveira <bristot@redhat.com> Cc: Joel Fernandes <joelaf@google.com> Cc: Juri Lelli <juri.lelli@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tommaso Cucinotta <tommaso.cucinotta@sssup.it> Link: http://lkml.kernel.org/r/1495138417-6203-11-git-send-email-luca.abeni@santannapisa.it Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent daec579 commit ccc9d65

1 file changed

Lines changed: 168 additions & 0 deletions

File tree

‎Documentation/scheduler/sched-deadline.txt‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CONTENTS
77
0. WARNING
88
1. Overview
99
2. Scheduling algorithm
10+
2.1 Main algorithm
11+
2.2 Bandwidth reclaiming
1012
3. Scheduling Real-Time Tasks
1113
3.1 Definitions
1214
3.2 Schedulability Analysis for Uniprocessor Systems
@@ -44,6 +46,9 @@ CONTENTS
4446
2. Scheduling algorithm
4547
==================
4648

49+
2.1 Main algorithm
50+
------------------
51+
4752
SCHED_DEADLINE uses three parameters, named "runtime", "period", and
4853
"deadline", to schedule tasks. A SCHED_DEADLINE task should receive
4954
"runtime" microseconds of execution time every "period" microseconds, and
@@ -113,6 +118,160 @@ CONTENTS
113118
remaining runtime = remaining runtime + runtime
114119

115120

121+
2.2 Bandwidth reclaiming
122+
------------------------
123+
124+
Bandwidth reclaiming for deadline tasks is based on the GRUB (Greedy
125+
Reclamation of Unused Bandwidth) algorithm [15, 16, 17] and it is enabled
126+
when flag SCHED_FLAG_RECLAIM is set.
127+
128+
The following diagram illustrates the state names for tasks handled by GRUB:
129+
130+
------------
131+
(d) | Active |
132+
------------->| |
133+
| | Contending |
134+
| ------------
135+
| A |
136+
---------- | |
137+
| | | |
138+
| Inactive | |(b) | (a)
139+
| | | |
140+
---------- | |
141+
A | V
142+
| ------------
143+
| | Active |
144+
--------------| Non |
145+
(c) | Contending |
146+
------------
147+
148+
A task can be in one of the following states:
149+
150+
- ActiveContending: if it is ready for execution (or executing);
151+
152+
- ActiveNonContending: if it just blocked and has not yet surpassed the 0-lag
153+
time;
154+
155+
- Inactive: if it is blocked and has surpassed the 0-lag time.
156+
157+
State transitions:
158+
159+
(a) When a task blocks, it does not become immediately inactive since its
160+
bandwidth cannot be immediately reclaimed without breaking the
161+
real-time guarantees. It therefore enters a transitional state called
162+
ActiveNonContending. The scheduler arms the "inactive timer" to fire at
163+
the 0-lag time, when the task's bandwidth can be reclaimed without
164+
breaking the real-time guarantees.
165+
166+
The 0-lag time for a task entering the ActiveNonContending state is
167+
computed as
168+
169+
(runtime * dl_period)
170+
deadline - ---------------------
171+
dl_runtime
172+
173+
where runtime is the remaining runtime, while dl_runtime and dl_period
174+
are the reservation parameters.
175+
176+
(b) If the task wakes up before the inactive timer fires, the task re-enters
177+
the ActiveContending state and the "inactive timer" is canceled.
178+
In addition, if the task wakes up on a different runqueue, then
179+
the task's utilization must be removed from the previous runqueue's active
180+
utilization and must be added to the new runqueue's active utilization.
181+
In order to avoid races between a task waking up on a runqueue while the
182+
"inactive timer" is running on a different CPU, the "dl_non_contending"
183+
flag is used to indicate that a task is not on a runqueue but is active
184+
(so, the flag is set when the task blocks and is cleared when the
185+
"inactive timer" fires or when the task wakes up).
186+
187+
(c) When the "inactive timer" fires, the task enters the Inactive state and
188+
its utilization is removed from the runqueue's active utilization.
189+
190+
(d) When an inactive task wakes up, it enters the ActiveContending state and
191+
its utilization is added to the active utilization of the runqueue where
192+
it has been enqueued.
193+
194+
For each runqueue, the algorithm GRUB keeps track of two different bandwidths:
195+
196+
- Active bandwidth (running_bw): this is the sum of the bandwidths of all
197+
tasks in active state (i.e., ActiveContending or ActiveNonContending);
198+
199+
- Total bandwidth (this_bw): this is the sum of all tasks "belonging" to the
200+
runqueue, including the tasks in Inactive state.
201+
202+
203+
The algorithm reclaims the bandwidth of the tasks in Inactive state.
204+
It does so by decrementing the runtime of the executing task Ti at a pace equal
205+
to
206+
207+
dq = -max{ Ui, (1 - Uinact) } dt
208+
209+
where Uinact is the inactive utilization, computed as (this_bq - running_bw),
210+
and Ui is the bandwidth of task Ti.
211+
212+
213+
Let's now see a trivial example of two deadline tasks with runtime equal
214+
to 4 and period equal to 8 (i.e., bandwidth equal to 0.5):
215+
216+
A Task T1
217+
|
218+
| |
219+
| |
220+
|-------- |----
221+
| | V
222+
|---|---|---|---|---|---|---|---|--------->t
223+
0 1 2 3 4 5 6 7 8
224+
225+
226+
A Task T2
227+
|
228+
| |
229+
| |
230+
| ------------------------|
231+
| | V
232+
|---|---|---|---|---|---|---|---|--------->t
233+
0 1 2 3 4 5 6 7 8
234+
235+
236+
A running_bw
237+
|
238+
1 ----------------- ------
239+
| | |
240+
0.5- -----------------
241+
| |
242+
|---|---|---|---|---|---|---|---|--------->t
243+
0 1 2 3 4 5 6 7 8
244+
245+
246+
- Time t = 0:
247+
248+
Both tasks are ready for execution and therefore in ActiveContending state.
249+
Suppose Task T1 is the first task to start execution.
250+
Since there are no inactive tasks, its runtime is decreased as dq = -1 dt.
251+
252+
- Time t = 2:
253+
254+
Suppose that task T1 blocks
255+
Task T1 therefore enters the ActiveNonContending state. Since its remaining
256+
runtime is equal to 2, its 0-lag time is equal to t = 4.
257+
Task T2 start execution, with runtime still decreased as dq = -1 dt since
258+
there are no inactive tasks.
259+
260+
- Time t = 4:
261+
262+
This is the 0-lag time for Task T1. Since it didn't woken up in the
263+
meantime, it enters the Inactive state. Its bandwidth is removed from
264+
running_bw.
265+
Task T2 continues its execution. However, its runtime is now decreased as
266+
dq = - 0.5 dt because Uinact = 0.5.
267+
Task T2 therefore reclaims the bandwidth unused by Task T1.
268+
269+
- Time t = 8:
270+
271+
Task T1 wakes up. It enters the ActiveContending state again, and the
272+
running_bw is incremented.
273+
274+
116275
3. Scheduling Real-Time Tasks
117276
=============================
118277

@@ -330,6 +489,15 @@ CONTENTS
330489
14 - J. Erickson, U. Devi and S. Baruah. Improved tardiness bounds for
331490
Global EDF. Proceedings of the 22nd Euromicro Conference on
332491
Real-Time Systems, 2010.
492+
15 - G. Lipari, S. Baruah, Greedy reclamation of unused bandwidth in
493+
constant-bandwidth servers, 12th IEEE Euromicro Conference on Real-Time
494+
Systems, 2000.
495+
16 - L. Abeni, J. Lelli, C. Scordino, L. Palopoli, Greedy CPU reclaiming for
496+
SCHED DEADLINE. In Proceedings of the Real-Time Linux Workshop (RTLWS),
497+
Dusseldorf, Germany, 2014.
498+
17 - L. Abeni, G. Lipari, A. Parri, Y. Sun, Multicore CPU reclaiming: parallel
499+
or sequential?. In Proceedings of the 31st Annual ACM Symposium on Applied
500+
Computing, 2016.
333501

334502

335503
4. Bandwidth management

0 commit comments

Comments
 (0)