All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup
@ 2018-08-31 22:42 Steve Muckle
  2018-09-03  4:27 ` Dietmar Eggemann
  2018-09-10 10:07 ` [tip:sched/core] sched/fair: Fix vruntime_normalized() " tip-bot for Steve Muckle
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Muckle @ 2018-08-31 22:42 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: linux-kernel, kernel-team, Todd Kjos, Paul Turner,
	Quentin Perret, Patrick Bellasi, Chris Redpath, Morten Rasmussen,
	Dietmar Eggemann, Miguel de Dios, John Dias, Steve Muckle

When a task which previously ran on a given CPU is remotely queued to
wake up on that same CPU, there is a period where the task's state is
TASK_WAKING and its vruntime is not normalized. This is not accounted
for in vruntime_normalized() which will cause an
error in the task's vruntime if it is switched from the fair class
during this time, for example if it is boosted to RT priority via
rt_mutex_setprio. The rq's min_vruntime will not be subtracted from the
task's vruntime but it will be added again when the task returns to the
fair class. The task's vruntime will have been erroneously doubled and
the effective priority of the task will be reduced.

Note this will also lead to inflation of all vruntimes since the doubled
vruntime value will become the rq's min_vruntime when other tasks leave
the rq. This leads to repeated doubling of the vruntime and priority
penalty.

Fix this by recognizing a WAKING task's vruntime as normalized only if
sched_remote_wakeup is true. This indicates a migration, in which case
the vruntime would have been normalized in migrate_task_rq_fair().

Based on a similar patch from joaodias@google.com.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Steve Muckle <smuckle@google.com>
---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b39fb596f6c1..b3b62cf37fb6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9638,7 +9638,8 @@ static inline bool vruntime_normalized(struct task_struct *p)
 	 * - A task which has been woken up by try_to_wake_up() and
 	 *   waiting for actually being woken up by sched_ttwu_pending().
 	 */
-	if (!se->sum_exec_runtime || p->state == TASK_WAKING)
+	if (!se->sum_exec_runtime ||
+	    (p->state == TASK_WAKING && p->sched_remote_wakeup))
 		return true;
 
 	return false;
-- 
2.19.0.rc1.350.ge57e33dbd1-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup
  2018-08-31 22:42 [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup Steve Muckle
@ 2018-09-03  4:27 ` Dietmar Eggemann
  2018-09-10 10:07 ` [tip:sched/core] sched/fair: Fix vruntime_normalized() " tip-bot for Steve Muckle
  1 sibling, 0 replies; 3+ messages in thread
From: Dietmar Eggemann @ 2018-09-03  4:27 UTC (permalink / raw)
  To: Steve Muckle, Peter Zijlstra, Ingo Molnar
  Cc: linux-kernel, kernel-team, Todd Kjos, Paul Turner,
	Quentin Perret, Patrick Bellasi, Chris Redpath, Morten Rasmussen,
	Miguel de Dios, John Dias

On 08/31/2018 03:42 PM, Steve Muckle wrote:
> When a task which previously ran on a given CPU is remotely queued to
> wake up on that same CPU, there is a period where the task's state is
> TASK_WAKING and its vruntime is not normalized. This is not accounted
> for in vruntime_normalized() which will cause an
> error in the task's vruntime if it is switched from the fair class
> during this time, for example if it is boosted to RT priority via
> rt_mutex_setprio. The rq's min_vruntime will not be subtracted from the
> task's vruntime but it will be added again when the task returns to the
> fair class. The task's vruntime will have been erroneously doubled and
> the effective priority of the task will be reduced.
> 
> Note this will also lead to inflation of all vruntimes since the doubled
> vruntime value will become the rq's min_vruntime when other tasks leave
> the rq. This leads to repeated doubling of the vruntime and priority
> penalty.
> 
> Fix this by recognizing a WAKING task's vruntime as normalized only if
> sched_remote_wakeup is true. This indicates a migration, in which case
> the vruntime would have been normalized in migrate_task_rq_fair().
> 
> Based on a similar patch from joaodias@google.com.
> 
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Steve Muckle <smuckle@google.com>
> ---
>   kernel/sched/fair.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index b39fb596f6c1..b3b62cf37fb6 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -9638,7 +9638,8 @@ static inline bool vruntime_normalized(struct task_struct *p)
>   	 * - A task which has been woken up by try_to_wake_up() and
>   	 *   waiting for actually being woken up by sched_ttwu_pending().
>   	 */
> -	if (!se->sum_exec_runtime || p->state == TASK_WAKING)
> +	if (!se->sum_exec_runtime ||
> +	    (p->state == TASK_WAKING && p->sched_remote_wakeup))
>   		return true;
>   
>   	return false;
> 

Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched/fair: Fix vruntime_normalized() for remote non-migration wakeup
  2018-08-31 22:42 [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup Steve Muckle
  2018-09-03  4:27 ` Dietmar Eggemann
@ 2018-09-10 10:07 ` tip-bot for Steve Muckle
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Steve Muckle @ 2018-09-10 10:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, dietmar.eggemann, Morten.Rasmussen, tkjos, peterz,
	quentin.perret, smuckle, migueldedios, Patrick.Bellasi, torvalds,
	pjt, linux-kernel, joaodias, mingo, hpa, Chris.Redpath

Commit-ID:  d0cdb3ce8834332d918fc9c8ff74f8a169ec9abe
Gitweb:     https://git.kernel.org/tip/d0cdb3ce8834332d918fc9c8ff74f8a169ec9abe
Author:     Steve Muckle <smuckle@google.com>
AuthorDate: Fri, 31 Aug 2018 15:42:17 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 10 Sep 2018 10:13:47 +0200

sched/fair: Fix vruntime_normalized() for remote non-migration wakeup

When a task which previously ran on a given CPU is remotely queued to
wake up on that same CPU, there is a period where the task's state is
TASK_WAKING and its vruntime is not normalized. This is not accounted
for in vruntime_normalized() which will cause an error in the task's
vruntime if it is switched from the fair class during this time.

For example if it is boosted to RT priority via rt_mutex_setprio(),
rq->min_vruntime will not be subtracted from the task's vruntime but
it will be added again when the task returns to the fair class. The
task's vruntime will have been erroneously doubled and the effective
priority of the task will be reduced.

Note this will also lead to inflation of all vruntimes since the doubled
vruntime value will become the rq's min_vruntime when other tasks leave
the rq. This leads to repeated doubling of the vruntime and priority
penalty.

Fix this by recognizing a WAKING task's vruntime as normalized only if
sched_remote_wakeup is true. This indicates a migration, in which case
the vruntime would have been normalized in migrate_task_rq_fair().

Based on a similar patch from John Dias <joaodias@google.com>.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Steve Muckle <smuckle@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Chris Redpath <Chris.Redpath@arm.com>
Cc: John Dias <joaodias@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Miguel de Dios <migueldedios@google.com>
Cc: Morten Rasmussen <Morten.Rasmussen@arm.com>
Cc: Patrick Bellasi <Patrick.Bellasi@arm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Quentin Perret <quentin.perret@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Todd Kjos <tkjos@google.com>
Cc: kernel-team@android.com
Fixes: b5179ac70de8 ("sched/fair: Prepare to fix fairness problems on migration")
Link: http://lkml.kernel.org/r/20180831224217.169476-1-smuckle@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8cff8d55ee95..c6b7d6daab20 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9644,7 +9644,8 @@ static inline bool vruntime_normalized(struct task_struct *p)
 	 * - A task which has been woken up by try_to_wake_up() and
 	 *   waiting for actually being woken up by sched_ttwu_pending().
 	 */
-	if (!se->sum_exec_runtime || p->state == TASK_WAKING)
+	if (!se->sum_exec_runtime ||
+	    (p->state == TASK_WAKING && p->sched_remote_wakeup))
 		return true;
 
 	return false;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-10 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31 22:42 [PATCH] sched/fair: fix vruntime_normalized for remote non-migration wakeup Steve Muckle
2018-09-03  4:27 ` Dietmar Eggemann
2018-09-10 10:07 ` [tip:sched/core] sched/fair: Fix vruntime_normalized() " tip-bot for Steve Muckle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.