* [PATCH tip] sched/rt: Fix picking RT and DL tasks from empty queue
@ 2014-03-04 15:25 Kirill Tkhai
2014-03-05 11:59 ` Peter Zijlstra
2014-03-11 12:39 ` [tip:sched/core] " tip-bot for Kirill Tkhai
0 siblings, 2 replies; 3+ messages in thread
From: Kirill Tkhai @ 2014-03-04 15:25 UTC (permalink / raw)
To: linux-kernel; +Cc: Juri Lelli, Peter Zijlstra, Ingo Molnar, tkhai
The problems:
1)We check for rt_nr_running before call of put_prev_task().
If previous task is RT, its rt_rq may become throttled
and dequeued after this call.
In case of p is from rt->rq this just causes picking a task
from throttled queue, but in case of its rt_rq is child
we are guaranteed catch BUG_ON.
2)The same with deadline class. The only difference we operate
on only dl_rq.
This patch fix all above and it adds a small skip in DL update
like we've already done for RT class:
if (unlikely((s64)delta_exec <= 0))
return;
This will optimize sequential update_curr_dl() calls a little.
Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
CC: Juri Lelli <juri.lelli@gmail.com>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Ingo Molnar <mingo@redhat.com>
---
kernel/sched/deadline.c | 10 ++++++++--
kernel/sched/rt.c | 7 +++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index e4f3ac3..27ef409 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -609,8 +609,8 @@ static void update_curr_dl(struct rq *rq)
* approach need further study.
*/
delta_exec = rq_clock_task(rq) - curr->se.exec_start;
- if (unlikely((s64)delta_exec < 0))
- delta_exec = 0;
+ if (unlikely((s64)delta_exec <= 0))
+ return;
schedstat_set(curr->se.statistics.exec_max,
max(curr->se.statistics.exec_max, delta_exec));
@@ -1023,6 +1023,12 @@ struct task_struct *pick_next_task_dl(struct rq *rq, struct task_struct *prev)
if (need_pull_dl_task(rq, prev))
pull_dl_task(rq);
+ /*
+ * When prev is DL, we may throttle it in put_prev_task().
+ * So, we update time before we check for dl_nr_running.
+ */
+ if (prev->sched_class == &dl_sched_class)
+ update_curr_dl(rq);
if (unlikely(!dl_rq->dl_nr_running))
return NULL;
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index facc824..f3cee0a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1379,6 +1379,13 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev)
return RETRY_TASK;
}
+ /*
+ * We may dequeue prev's rt_rq in put_prev_task().
+ * So, we update time before rt_nr_running check.
+ */
+ if (prev->sched_class == &rt_sched_class)
+ update_curr_rt(rq);
+
if (!rt_rq->rt_nr_running)
return NULL;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH tip] sched/rt: Fix picking RT and DL tasks from empty queue
2014-03-04 15:25 [PATCH tip] sched/rt: Fix picking RT and DL tasks from empty queue Kirill Tkhai
@ 2014-03-05 11:59 ` Peter Zijlstra
2014-03-11 12:39 ` [tip:sched/core] " tip-bot for Kirill Tkhai
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2014-03-05 11:59 UTC (permalink / raw)
To: Kirill Tkhai; +Cc: linux-kernel, Juri Lelli, Ingo Molnar, tkhai
On Tue, Mar 04, 2014 at 07:25:46PM +0400, Kirill Tkhai wrote:
> The problems:
>
> 1)We check for rt_nr_running before call of put_prev_task().
> If previous task is RT, its rt_rq may become throttled
> and dequeued after this call.
>
> In case of p is from rt->rq this just causes picking a task
> from throttled queue, but in case of its rt_rq is child
> we are guaranteed catch BUG_ON.
>
> 2)The same with deadline class. The only difference we operate
> on only dl_rq.
>
> This patch fix all above and it adds a small skip in DL update
> like we've already done for RT class:
>
> if (unlikely((s64)delta_exec <= 0))
> return;
>
> This will optimize sequential update_curr_dl() calls a little.
>
Ah indeed, good catch that. Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:sched/core] sched/rt: Fix picking RT and DL tasks from empty queue
2014-03-04 15:25 [PATCH tip] sched/rt: Fix picking RT and DL tasks from empty queue Kirill Tkhai
2014-03-05 11:59 ` Peter Zijlstra
@ 2014-03-11 12:39 ` tip-bot for Kirill Tkhai
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Kirill Tkhai @ 2014-03-11 12:39 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, ktkhai, hpa, mingo, peterz, tglx, juri.lelli
Commit-ID: 734ff2a71f9e6aa6fedfa5a9a34818b8586516d5
Gitweb: http://git.kernel.org/tip/734ff2a71f9e6aa6fedfa5a9a34818b8586516d5
Author: Kirill Tkhai <ktkhai@parallels.com>
AuthorDate: Tue, 4 Mar 2014 19:25:46 +0400
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 11 Mar 2014 12:05:35 +0100
sched/rt: Fix picking RT and DL tasks from empty queue
The problems:
1) We check for rt_nr_running before call of put_prev_task().
If previous task is RT, its rt_rq may become throttled
and dequeued after this call.
In case of p is from rt->rq this just causes picking a task
from throttled queue, but in case of its rt_rq is child
we are guaranteed catch BUG_ON.
2) The same with deadline class. The only difference we operate
on only dl_rq.
This patch fixes all the above problems and it adds a small skip in the
DL update like we've already done for RT class:
if (unlikely((s64)delta_exec <= 0))
return;
This will optimize sequential update_curr_dl() calls a little.
Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@gmail.com>
Link: http://lkml.kernel.org/r/1393946746.3643.3.camel@tkhai
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/deadline.c | 10 ++++++++--
kernel/sched/rt.c | 7 +++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index e4f3ac3..27ef409 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -609,8 +609,8 @@ static void update_curr_dl(struct rq *rq)
* approach need further study.
*/
delta_exec = rq_clock_task(rq) - curr->se.exec_start;
- if (unlikely((s64)delta_exec < 0))
- delta_exec = 0;
+ if (unlikely((s64)delta_exec <= 0))
+ return;
schedstat_set(curr->se.statistics.exec_max,
max(curr->se.statistics.exec_max, delta_exec));
@@ -1023,6 +1023,12 @@ struct task_struct *pick_next_task_dl(struct rq *rq, struct task_struct *prev)
if (need_pull_dl_task(rq, prev))
pull_dl_task(rq);
+ /*
+ * When prev is DL, we may throttle it in put_prev_task().
+ * So, we update time before we check for dl_nr_running.
+ */
+ if (prev->sched_class == &dl_sched_class)
+ update_curr_dl(rq);
if (unlikely(!dl_rq->dl_nr_running))
return NULL;
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index facc824..f3cee0a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1379,6 +1379,13 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev)
return RETRY_TASK;
}
+ /*
+ * We may dequeue prev's rt_rq in put_prev_task().
+ * So, we update time before rt_nr_running check.
+ */
+ if (prev->sched_class == &rt_sched_class)
+ update_curr_rt(rq);
+
if (!rt_rq->rt_nr_running)
return NULL;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-11 12:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-04 15:25 [PATCH tip] sched/rt: Fix picking RT and DL tasks from empty queue Kirill Tkhai
2014-03-05 11:59 ` Peter Zijlstra
2014-03-11 12:39 ` [tip:sched/core] " tip-bot for Kirill Tkhai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome