rq->clock_task may be updated between the two calls of
rq_clock_task() in update_curr_rt(). Calling rq_clock_task() only
once makes it more accurate and efficient, taking update_curr() as
reference.
Signed-off-by: Wen Yang <[email protected]>
Reviewed-by: Jiang Biao <[email protected]>
---
kernel/sched/rt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 4056c19..d6d2a65 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -950,12 +950,13 @@ static void update_curr_rt(struct rq *rq)
{
struct task_struct *curr = rq->curr;
struct sched_rt_entity *rt_se = &curr->rt;
+ u64 now = rq_clock_task(rq);
u64 delta_exec;
if (curr->sched_class != &rt_sched_class)
return;
- delta_exec = rq_clock_task(rq) - curr->se.exec_start;
+ delta_exec = now - curr->se.exec_start;
if (unlikely((s64)delta_exec <= 0))
return;
@@ -968,7 +969,7 @@ static void update_curr_rt(struct rq *rq)
curr->se.sum_exec_runtime += delta_exec;
account_group_exec_runtime(curr, delta_exec);
- curr->se.exec_start = rq_clock_task(rq);
+ curr->se.exec_start = now;
cgroup_account_cputime(curr, delta_exec);
sched_rt_avg_update(rq, delta_exec);
--
1.9.1
On Mon, Feb 05, 2018 at 11:18:41AM +0800, Wen Yang wrote:
> rq->clock_task may be updated between the two calls of
> rq_clock_task() in update_curr_rt(). Calling rq_clock_task() only
> once makes it more accurate and efficient, taking update_curr() as
> reference.
>
> Signed-off-by: Wen Yang <[email protected]>
> Reviewed-by: Jiang Biao <[email protected]>
Thanks!
On Mon, Feb 05, 2018 at 11:30:38AM +0100, Peter Zijlstra wrote:
> On Mon, Feb 05, 2018 at 11:18:41AM +0800, Wen Yang wrote:
> > rq->clock_task may be updated between the two calls of
> > rq_clock_task() in update_curr_rt(). Calling rq_clock_task() only
> > once makes it more accurate and efficient, taking update_curr() as
> > reference.
> >
> > Signed-off-by: Wen Yang <[email protected]>
> > Reviewed-by: Jiang Biao <[email protected]>
>
> Thanks!
I just noticed update_curr_dl() has the exact same issue, could you also
do a patch for that?
* Wen Yang <[email protected]> wrote:
> rq->clock_task may be updated between the two calls of
> rq_clock_task() in update_curr_rt(). Calling rq_clock_task() only
> once makes it more accurate and efficient, taking update_curr() as
> reference.
>
> Signed-off-by: Wen Yang <[email protected]>
> Reviewed-by: Jiang Biao <[email protected]>
> ---
> kernel/sched/rt.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 4056c19..d6d2a65 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -950,12 +950,13 @@ static void update_curr_rt(struct rq *rq)
> {
> struct task_struct *curr = rq->curr;
> struct sched_rt_entity *rt_se = &curr->rt;
> + u64 now = rq_clock_task(rq);
> u64 delta_exec;
>
> if (curr->sched_class != &rt_sched_class)
> return;
>
> - delta_exec = rq_clock_task(rq) - curr->se.exec_start;
> + delta_exec = now - curr->se.exec_start;
Small nit: shouldn't we calculate 'now' after the return?
OTOH that 'return' should only be triggered statistically AFAICS, i.e. very
rarely.
Thanks,
Ingo
Commit-ID: e7ad203166fff89b1d8253faf68fbe6966bf7181
Gitweb: https://git.kernel.org/tip/e7ad203166fff89b1d8253faf68fbe6966bf7181
Author: Wen Yang <[email protected]>
AuthorDate: Mon, 5 Feb 2018 11:18:41 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 6 Feb 2018 10:20:34 +0100
sched/rt: Make update_curr_rt() more accurate
rq->clock_task may be updated between the two calls of
rq_clock_task() in update_curr_rt(). Calling rq_clock_task() only
once makes it more accurate and efficient, taking update_curr() as
reference.
Signed-off-by: Wen Yang <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Jiang Biao <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/sched/rt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 89a086e..663b235 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -950,12 +950,13 @@ static void update_curr_rt(struct rq *rq)
{
struct task_struct *curr = rq->curr;
struct sched_rt_entity *rt_se = &curr->rt;
+ u64 now = rq_clock_task(rq);
u64 delta_exec;
if (curr->sched_class != &rt_sched_class)
return;
- delta_exec = rq_clock_task(rq) - curr->se.exec_start;
+ delta_exec = now - curr->se.exec_start;
if (unlikely((s64)delta_exec <= 0))
return;
@@ -968,7 +969,7 @@ static void update_curr_rt(struct rq *rq)
curr->se.sum_exec_runtime += delta_exec;
account_group_exec_runtime(curr, delta_exec);
- curr->se.exec_start = rq_clock_task(rq);
+ curr->se.exec_start = now;
cgroup_account_cputime(curr, delta_exec);
sched_rt_avg_update(rq, delta_exec);