mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Vincent Guittot <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, tglx@linutronix.de, mingo@kernel.org,
	torvalds@linux-foundation.org, hpa@zytor.com,
	vincent.guittot@linaro.org, linux-kernel@vger.kernel.org
Subject: [tip:sched/core] sched/pelt: Fix false running accounting
Date: Thu, 10 Aug 2017 05:07:08 -0700	[thread overview]
Message-ID: <tip-f235a54f00449c611f85173fe8a66c4d189c5ce1@git.kernel.org> (raw)
In-Reply-To: <1498885573-18984-1-git-send-email-vincent.guittot@linaro.org>

Commit-ID:  f235a54f00449c611f85173fe8a66c4d189c5ce1
Gitweb:     http://git.kernel.org/tip/f235a54f00449c611f85173fe8a66c4d189c5ce1
Author:     Vincent Guittot <vincent.guittot@linaro.org>
AuthorDate: Sat, 1 Jul 2017 07:06:13 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 12:18:15 +0200

sched/pelt: Fix false running accounting

The running state is a subset of runnable state which means that running
can't be set if runnable (weight) is cleared. There are corner cases
where the current sched_entity has been already dequeued but cfs_rq->curr
has not been updated yet and still points to the dequeued sched_entity.
If ___update_load_avg() is called at that time, weight will be 0 and running
will be set which is not possible.

This case happens during pick_next_task_fair() when a cfs_rq becomes idles.
The current sched_entity has been dequeued so se->on_rq is cleared and
cfs_rq->weight is null. But cfs_rq->curr still points to se (it will be
cleared when picking the idle thread). Because the cfs_rq becomes idle,
idle_balance() is called and ends up to call update_blocked_averages()
with these wrong running and runnable states.

Add a test in ___update_load_avg() to correct the running state in this case.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Morten.Rasmussen@arm.com
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dietmar.eggemann@arm.com
Link: http://lkml.kernel.org/r/1498885573-18984-1-git-send-email-vincent.guittot@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 75c58c7..ef5b66b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2991,6 +2991,18 @@ ___update_load_avg(u64 now, int cpu, struct sched_avg *sa,
 	sa->last_update_time += delta << 10;
 
 	/*
+	 * running is a subset of runnable (weight) so running can't be set if
+	 * runnable is clear. But there are some corner cases where the current
+	 * se has been already dequeued but cfs_rq->curr still points to it.
+	 * This means that weight will be 0 but not running for a sched_entity
+	 * but also for a cfs_rq if the latter becomes idle. As an example,
+	 * this happens during idle_balance() which calls
+	 * update_blocked_averages()
+	 */
+	if (!weight)
+		running = 0;
+
+	/*
 	 * Now we know we crossed measurement unit boundaries. The *_avg
 	 * accrues by two steps:
 	 *

  parent reply	other threads:[~2017-08-10 12:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 13:58 [PATCH] sched/pelt: fix false running accounting in PELT Vincent Guittot
2017-07-01  5:06 ` [PATCH v2] sched/pelt: fix false running accounting Vincent Guittot
2017-07-04  7:27   ` Peter Zijlstra
2017-07-04  7:37     ` Vincent Guittot
2017-07-04  8:34     ` Peter Zijlstra
2017-07-04  9:12       ` Vincent Guittot
2017-07-04  9:44         ` Peter Zijlstra
2017-07-04  9:57           ` Vincent Guittot
2017-07-04 11:07             ` Peter Zijlstra
2017-08-10 12:07   ` tip-bot for Vincent Guittot [this message]
2017-07-01  5:09 ` [PATCH] sched/pelt: fix false running accounting in PELT Vincent Guittot
2017-07-01 16:57 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-f235a54f00449c611f85173fe8a66c4d189c5ce1@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®