From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: peterz@infradead.org, fweisbec@gmail.com,
linux-kernel@vger.kernel.org, mingo@redhat.com,
tglx@linutronix.de, ktkhai@virtuozzo.com
Subject: [PATCH] sched: Count loadavg under rq::lock in calc_load_nohz_start()
Date: Fri, 07 Jul 2017 20:06:45 +0300 [thread overview]
Message-ID: <149944712360.6995.921016370988297998.stgit@localhost.localdomain> (raw)
Since calc_load_fold_active() reads two variables (nr_running
and nr_uninterruptible) it may race with parallel try_to_wake_up().
Thus, it must be called under rq::lock to prevent that. Also
put calc_load_migrate() under the lock for uniformity.
I observed machine with negative calc_load_tasks on kernel 3.10,
and this seems to be the reason.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
kernel/sched/core.c | 2 +-
kernel/sched/loadavg.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d3d39a283beb..92b3512bdcfc 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5657,9 +5657,9 @@ int sched_cpu_dying(unsigned int cpu)
}
migrate_tasks(rq, &rf);
BUG_ON(rq->nr_running != 1);
+ calc_load_migrate(rq);
rq_unlock_irqrestore(rq, &rf);
- calc_load_migrate(rq);
update_max_interval();
nohz_balance_exit_idle(cpu);
hrtick_clear(rq);
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index f14716a3522f..723349844990 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -183,13 +183,16 @@ static inline int calc_load_read_idx(void)
void calc_load_nohz_start(void)
{
struct rq *this_rq = this_rq();
+ struct rq_flags rf;
long delta;
/*
* We're going into NO_HZ mode, if there's any pending delta, fold it
* into the pending NO_HZ delta.
*/
+ rq_lock(this_rq, &rf);
delta = calc_load_fold_active(this_rq, 0);
+ rq_unlock(this_rq, &rf);
if (delta) {
int idx = calc_load_write_idx();
reply other threads:[~2017-07-07 17:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=149944712360.6995.921016370988297998.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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®