From: Chase Douglas <chase.douglas@canonical.com>
To: linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
"Rafael J. Wysocki" <rjw@sisk.pl>,
kernel-team <kernel-team@lists.ubuntu.com>
Subject: [REGRESSION 2.6.30][PATCH v3] sched: update load count only once per cpu in 10 tick update window
Date: Tue, 13 Apr 2010 16:19:11 -0700 [thread overview]
Message-ID: <1271200751-18697-1-git-send-email-chase.douglas@canonical.com> (raw)
There's a period of 10 ticks where calc_load_tasks is updated by all the
cpus for the load avg. Usually all the cpus do this during the first
tick. If any cpus go idle, calc_load_tasks is decremented accordingly.
However, if they wake up calc_load_tasks is not incremented. Thus, if
cpus go idle during the 10 tick period, calc_load_tasks may be
decremented to a non-representative value. This issue can lead to
systems having a load avg of exactly 0, even though the real load avg
could theoretically be up to NR_CPUS.
This change defers calc_load_tasks accounting after each cpu updates the
count until after the 10 tick update window.
A few points:
* A global atomic deferral counter, and not per-cpu vars, is needed
because a cpu may go NOHZ idle and not be able to update the global
calc_load_tasks variable for subsequent load calculations.
* It is not enough to add calls to account for the load when a cpu is
awakened:
- Load avg calculation must be independent of cpu load.
- If a cpu is awakend by one tasks, but then has more scheduled before
the end of the update window, only the first task will be accounted.
BugLink: http://bugs.launchpad.net/bugs/513848
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
Acked-by: Colin King <colin.king@canonical.com>
Acked-by: Andy Whitcroft <apw@canonical.com>
---
kernel/sched.c | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index abb36b1..be348cd 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3010,6 +3010,7 @@ unsigned long this_cpu_load(void)
/* Variables and functions for calc_load */
static atomic_long_t calc_load_tasks;
+static atomic_long_t calc_load_tasks_deferred;
static unsigned long calc_load_update;
unsigned long avenrun[3];
EXPORT_SYMBOL(avenrun);
@@ -3064,7 +3065,7 @@ void calc_global_load(void)
*/
static void calc_load_account_active(struct rq *this_rq)
{
- long nr_active, delta;
+ long nr_active, delta, deferred;
nr_active = this_rq->nr_running;
nr_active += (long) this_rq->nr_uninterruptible;
@@ -3072,6 +3073,25 @@ static void calc_load_account_active(struct rq *this_rq)
if (nr_active != this_rq->calc_load_active) {
delta = nr_active - this_rq->calc_load_active;
this_rq->calc_load_active = nr_active;
+
+ /*
+ * Update calc_load_tasks only once per cpu in 10 tick update
+ * window.
+ */
+ if (unlikely(time_before(jiffies, this_rq->calc_load_update) &&
+ time_after_eq(jiffies, calc_load_update))) {
+ if (delta)
+ atomic_long_add(delta,
+ &calc_load_tasks_deferred);
+ return;
+ }
+
+ if (atomic_long_read(&calc_load_tasks_deferred)) {
+ deferred = atomic_long_xchg(&calc_load_tasks_deferred,
+ 0);
+ delta += deferred;
+ }
+
atomic_long_add(delta, &calc_load_tasks);
}
}
@@ -3106,8 +3126,8 @@ static void update_cpu_load(struct rq *this_rq)
}
if (time_after_eq(jiffies, this_rq->calc_load_update)) {
- this_rq->calc_load_update += LOAD_FREQ;
calc_load_account_active(this_rq);
+ this_rq->calc_load_update += LOAD_FREQ;
}
}
--
1.6.3.3
next reply other threads:[~2010-04-13 23:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-13 23:19 Chase Douglas [this message]
2010-04-19 18:52 ` Peter Zijlstra
2010-04-19 18:56 ` Peter Zijlstra
2010-04-19 20:16 ` Chase Douglas
2010-04-19 20:52 ` Peter Zijlstra
2010-04-19 21:17 ` Chase Douglas
2010-04-22 11:08 ` Peter Zijlstra
2010-04-22 13:18 ` Chase Douglas
2010-04-22 15:35 ` Chase Douglas
2010-04-23 10:49 ` [tip:sched/core] sched: Cure load average vs NO_HZ woes tip-bot for Peter Zijlstra
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=1271200751-18697-1-git-send-email-chase.douglas@canonical.com \
--to=chase.douglas@canonical.com \
--cc=akpm@linux-foundation.org \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rjw@sisk.pl \
--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®