Skip to content

Commit a3a70ca

Browse files
author
Peter Zijlstra
committed
sched/deadline: Fix dl_server behaviour
John reported undesirable behaviour with the dl_server since commit: cccb45d ("sched/deadline: Less agressive dl_server handling"). When starving fair tasks on purpose (starting spinning FIFO tasks), his fair workload, which often goes (briefly) idle, would delay fair invocations for a second, running one invocation per second was both unexpected and terribly slow. The reason this happens is that when dl_se->server_pick_task() returns NULL, indicating no runnable tasks, it would yield, pushing any later jobs out a whole period (1 second). Instead simply stop the server. This should restore behaviour in that a later wakeup (which restarts the server) will be able to continue running (subject to the CBS wakeup rules). Notably, this does not re-introduce the behaviour cccb45d set out to solve, any start/stop cycle is naturally throttled by the timer period (no active cancel). Fixes: cccb45d ("sched/deadline: Less agressive dl_server handling") Reported-by: John Stultz <jstultz@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: John Stultz <jstultz@google.com>
1 parent 4ae8d9a commit a3a70ca

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

include/linux/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ struct sched_dl_entity {
706706
unsigned int dl_defer : 1;
707707
unsigned int dl_defer_armed : 1;
708708
unsigned int dl_defer_running : 1;
709-
unsigned int dl_server_idle : 1;
710709

711710
/*
712711
* Bandwidth enforcement timer. Each -deadline task has its

kernel/sched/deadline.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,10 +1571,8 @@ void dl_server_update_idle_time(struct rq *rq, struct task_struct *p)
15711571
void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec)
15721572
{
15731573
/* 0 runtime = fair server disabled */
1574-
if (dl_se->dl_runtime) {
1575-
dl_se->dl_server_idle = 0;
1574+
if (dl_se->dl_runtime)
15761575
update_curr_dl_se(dl_se->rq, dl_se, delta_exec);
1577-
}
15781576
}
15791577

15801578
void dl_server_start(struct sched_dl_entity *dl_se)
@@ -1602,20 +1600,6 @@ void dl_server_stop(struct sched_dl_entity *dl_se)
16021600
dl_se->dl_server_active = 0;
16031601
}
16041602

1605-
static bool dl_server_stopped(struct sched_dl_entity *dl_se)
1606-
{
1607-
if (!dl_se->dl_server_active)
1608-
return true;
1609-
1610-
if (dl_se->dl_server_idle) {
1611-
dl_server_stop(dl_se);
1612-
return true;
1613-
}
1614-
1615-
dl_se->dl_server_idle = 1;
1616-
return false;
1617-
}
1618-
16191603
void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq,
16201604
dl_server_pick_f pick_task)
16211605
{
@@ -2384,10 +2368,7 @@ static struct task_struct *__pick_task_dl(struct rq *rq)
23842368
if (dl_server(dl_se)) {
23852369
p = dl_se->server_pick_task(dl_se);
23862370
if (!p) {
2387-
if (!dl_server_stopped(dl_se)) {
2388-
dl_se->dl_yielded = 1;
2389-
update_curr_dl_se(rq, dl_se, 0);
2390-
}
2371+
dl_server_stop(dl_se);
23912372
goto again;
23922373
}
23932374
rq->dl_server = dl_se;

kernel/sched/sched.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,39 @@ extern s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, s6
371371
* dl_server_update() -- called from update_curr_common(), propagates runtime
372372
* to the server.
373373
*
374-
* dl_server_start()
375-
* dl_server_stop() -- start/stop the server when it has (no) tasks.
374+
* dl_server_start() -- start the server when it has tasks; it will stop
375+
* automatically when there are no more tasks, per
376+
* dl_se::server_pick() returning NULL.
377+
*
378+
* dl_server_stop() -- (force) stop the server; use when updating
379+
* parameters.
376380
*
377381
* dl_server_init() -- initializes the server.
382+
*
383+
* When started the dl_server will (per dl_defer) schedule a timer for its
384+
* zero-laxity point -- that is, unlike regular EDF tasks which run ASAP, a
385+
* server will run at the very end of its period.
386+
*
387+
* This is done such that any runtime from the target class can be accounted
388+
* against the server -- through dl_server_update() above -- such that when it
389+
* becomes time to run, it might already be out of runtime and get deferred
390+
* until the next period. In this case dl_server_timer() will alternate
391+
* between defer and replenish but never actually enqueue the server.
392+
*
393+
* Only when the target class does not manage to exhaust the server's runtime
394+
* (there's actualy starvation in the given period), will the dl_server get on
395+
* the runqueue. Once queued it will pick tasks from the target class and run
396+
* them until either its runtime is exhaused, at which point its back to
397+
* dl_server_timer, or until there are no more tasks to run, at which point
398+
* the dl_server stops itself.
399+
*
400+
* By stopping at this point the dl_server retains bandwidth, which, if a new
401+
* task wakes up imminently (starting the server again), can be used --
402+
* subject to CBS wakeup rules -- without having to wait for the next period.
403+
*
404+
* Additionally, because of the dl_defer behaviour the start/stop behaviour is
405+
* naturally thottled to once per period, avoiding high context switch
406+
* workloads from spamming the hrtimer program/cancel paths.
378407
*/
379408
extern void dl_server_update(struct sched_dl_entity *dl_se, s64 delta_exec);
380409
extern void dl_server_start(struct sched_dl_entity *dl_se);

0 commit comments

Comments
 (0)