mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay()
@ 2014-12-16 15:58 Xunlei Pang
  2014-12-16 18:09 ` bsegall
  2015-01-14 14:01 ` [tip:sched/core] " tip-bot for Xunlei Pang
  0 siblings, 2 replies; 3+ messages in thread
From: Xunlei Pang @ 2014-12-16 15:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Ingo Molnar, Xunlei Pang

In __synchronize_entity_decay(), if "decays" happens to be zero, 
se->avg.decay_count will not be zeroed, holding the positive value
assigned when dequeued last time.

This is problematic in the following case:
If this runnable task is CFS-balanced to other CPUs soon afterwards, 
migrate_task_rq_fair() will treat it as a blocked task due to its
non-zero decay_count, thereby adding its load to cfs_rq->removed_load
wrongly.

Thus, we must zero se->avg.decay_count in this case as well.

Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index df2cdf7..ea517cd 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2574,11 +2574,11 @@ static inline u64 __synchronize_entity_decay(struct sched_entity *se)
 	u64 decays = atomic64_read(&cfs_rq->decay_counter);
 
 	decays -= se->avg.decay_count;
+	se->avg.decay_count = 0;
 	if (!decays)
 		return 0;
 
 	se->avg.load_avg_contrib = decay_load(se->avg.load_avg_contrib, decays);
-	se->avg.decay_count = 0;
 
 	return decays;
 }
-- 
1.9.1


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

* Re: [PATCH] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay()
  2014-12-16 15:58 [PATCH] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay() Xunlei Pang
@ 2014-12-16 18:09 ` bsegall
  2015-01-14 14:01 ` [tip:sched/core] " tip-bot for Xunlei Pang
  1 sibling, 0 replies; 3+ messages in thread
From: bsegall @ 2014-12-16 18:09 UTC (permalink / raw)
  To: Xunlei Pang; +Cc: linux-kernel, Peter Zijlstra, Ingo Molnar, pjt

Xunlei Pang <pang.xunlei@linaro.org> writes:

> In __synchronize_entity_decay(), if "decays" happens to be zero, 
> se->avg.decay_count will not be zeroed, holding the positive value
> assigned when dequeued last time.
>
> This is problematic in the following case:
> If this runnable task is CFS-balanced to other CPUs soon afterwards, 
> migrate_task_rq_fair() will treat it as a blocked task due to its
> non-zero decay_count, thereby adding its load to cfs_rq->removed_load
> wrongly.
>
> Thus, we must zero se->avg.decay_count in this case as well.

Yep. We probably didn't notice this because migrate will happen to clear
this by doing decay_count = -__synch(), but you can hit this via
switched_from_fair or just on enqueue followed by a load-balance
migration that thinks decay_counter was zero due to being on_rq.

>
> Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>

Reviewed-by: Ben Segall <bsegall@google.com>

> ---
>  kernel/sched/fair.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index df2cdf7..ea517cd 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -2574,11 +2574,11 @@ static inline u64 __synchronize_entity_decay(struct sched_entity *se)
>  	u64 decays = atomic64_read(&cfs_rq->decay_counter);
>  
>  	decays -= se->avg.decay_count;
> +	se->avg.decay_count = 0;
>  	if (!decays)
>  		return 0;
>  
>  	se->avg.load_avg_contrib = decay_load(se->avg.load_avg_contrib, decays);
> -	se->avg.decay_count = 0;
>  
>  	return decays;
>  }

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

* [tip:sched/core] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay()
  2014-12-16 15:58 [PATCH] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay() Xunlei Pang
  2014-12-16 18:09 ` bsegall
@ 2015-01-14 14:01 ` tip-bot for Xunlei Pang
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Xunlei Pang @ 2015-01-14 14:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, tglx, bsegall, pang.xunlei, peterz, torvalds, mingo, hpa

Commit-ID:  638476007d13534b2ed4134bf0279ef44071140b
Gitweb:     http://git.kernel.org/tip/638476007d13534b2ed4134bf0279ef44071140b
Author:     Xunlei Pang <pang.xunlei@linaro.org>
AuthorDate: Tue, 16 Dec 2014 23:58:29 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 14 Jan 2015 13:34:13 +0100

sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay()

In __synchronize_entity_decay(), if "decays" happens to be zero,
se->avg.decay_count will not be zeroed, holding the positive value
assigned when dequeued last time.

This is problematic in the following case:
If this runnable task is CFS-balanced to other CPUs soon afterwards,
migrate_task_rq_fair() will treat it as a blocked task due to its
non-zero decay_count, thereby adding its load to cfs_rq->removed_load
wrongly.

Thus, we must zero se->avg.decay_count in this case as well.

Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ben Segall <bsegall@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1418745509-2609-1-git-send-email-pang.xunlei@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 40667cb..97000a9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2574,11 +2574,11 @@ static inline u64 __synchronize_entity_decay(struct sched_entity *se)
 	u64 decays = atomic64_read(&cfs_rq->decay_counter);
 
 	decays -= se->avg.decay_count;
+	se->avg.decay_count = 0;
 	if (!decays)
 		return 0;
 
 	se->avg.load_avg_contrib = decay_load(se->avg.load_avg_contrib, decays);
-	se->avg.decay_count = 0;
 
 	return decays;
 }

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

end of thread, other threads:[~2015-01-14 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-16 15:58 [PATCH] sched/fair: Fix the dealing with decay_count in __synchronize_entity_decay() Xunlei Pang
2014-12-16 18:09 ` bsegall
2015-01-14 14:01 ` [tip:sched/core] " tip-bot for Xunlei Pang

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