Commit 48be3a67 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/deadline: Always calculate end of period on sched_yield()

Steven noticed that occasionally a sched_yield() call would not result
in a wait for the next period edge as expected.

It turns out that when we call update_curr_dl() and end up with
delta_exec <= 0, we will bail early and fail to throttle.

Further inspection of the yield code revealed that yield_task_dl()
clearing dl.runtime is wrong too, it will not account the last bit of
runtime which could result in dl.runtime < 0, which in turn means that
replenish would gift us with too much runtime.

Fix both issues by not relying on the dl.runtime value for yield.
Reported-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Tested-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Clark Williams <williams@redhat.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Juri Lelli <juri.lelli@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160223122822.GP6357@twins.programming.kicks-ass.netSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 6fe1f348
...@@ -399,6 +399,9 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se, ...@@ -399,6 +399,9 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se,
dl_se->runtime = pi_se->dl_runtime; dl_se->runtime = pi_se->dl_runtime;
} }
if (dl_se->dl_yielded && dl_se->runtime > 0)
dl_se->runtime = 0;
/* /*
* We keep moving the deadline away until we get some * We keep moving the deadline away until we get some
* available runtime for the entity. This ensures correct * available runtime for the entity. This ensures correct
...@@ -735,8 +738,11 @@ static void update_curr_dl(struct rq *rq) ...@@ -735,8 +738,11 @@ static void update_curr_dl(struct rq *rq)
* approach need further study. * approach need further study.
*/ */
delta_exec = rq_clock_task(rq) - curr->se.exec_start; delta_exec = rq_clock_task(rq) - curr->se.exec_start;
if (unlikely((s64)delta_exec <= 0)) if (unlikely((s64)delta_exec <= 0)) {
if (unlikely(dl_se->dl_yielded))
goto throttle;
return; return;
}
schedstat_set(curr->se.statistics.exec_max, schedstat_set(curr->se.statistics.exec_max,
max(curr->se.statistics.exec_max, delta_exec)); max(curr->se.statistics.exec_max, delta_exec));
...@@ -749,8 +755,10 @@ static void update_curr_dl(struct rq *rq) ...@@ -749,8 +755,10 @@ static void update_curr_dl(struct rq *rq)
sched_rt_avg_update(rq, delta_exec); sched_rt_avg_update(rq, delta_exec);
dl_se->runtime -= dl_se->dl_yielded ? 0 : delta_exec; dl_se->runtime -= delta_exec;
if (dl_runtime_exceeded(dl_se)) {
throttle:
if (dl_runtime_exceeded(dl_se) || dl_se->dl_yielded) {
dl_se->dl_throttled = 1; dl_se->dl_throttled = 1;
__dequeue_task_dl(rq, curr, 0); __dequeue_task_dl(rq, curr, 0);
if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr))) if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr)))
...@@ -994,18 +1002,14 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) ...@@ -994,18 +1002,14 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
*/ */
static void yield_task_dl(struct rq *rq) static void yield_task_dl(struct rq *rq)
{ {
struct task_struct *p = rq->curr;
/* /*
* We make the task go to sleep until its current deadline by * We make the task go to sleep until its current deadline by
* forcing its runtime to zero. This way, update_curr_dl() stops * forcing its runtime to zero. This way, update_curr_dl() stops
* it and the bandwidth timer will wake it up and will give it * it and the bandwidth timer will wake it up and will give it
* new scheduling parameters (thanks to dl_yielded=1). * new scheduling parameters (thanks to dl_yielded=1).
*/ */
if (p->dl.runtime > 0) {
rq->curr->dl.dl_yielded = 1; rq->curr->dl.dl_yielded = 1;
p->dl.runtime = 0;
}
update_rq_clock(rq); update_rq_clock(rq);
update_curr_dl(rq); update_curr_dl(rq);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment