linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, "Doug Smythies" <dsmythies@telus.net>,
	"LesÅ�aw Kopeć" <leslaw.kopec@nasza-klasa.pl>,
	"Aman Gupta" <aman@tmm1.net>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Ingo Molnar" <mingo@elte.hu>,
	"Kerin Millar" <kerframil@gmail.com>
Subject: [ 47/47] sched: Fix nohz load accounting -- again!
Date: Fri, 04 May 2012 13:43:31 -0700	[thread overview]
Message-ID: <20120504204248.905290700@linuxfoundation.org> (raw)
In-Reply-To: <20120504204307.GA13761@kroah.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4170 bytes --]

3.0-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <peterz@infradead.org>

commit c308b56b5398779cd3da0f62ab26b0453494c3d4 upstream.
[ backported to 3.0 by Kerin Millar <kerframil@gmail.com>]

Various people reported nohz load tracking still being wrecked, but Doug
spotted the actual problem. We fold the nohz remainder in too soon,
causing us to loose samples and under-account.

So instead of playing catch-up up-front, always do a single load-fold
with whatever state we encounter and only then fold the nohz remainder
and play catch-up.

Reported-by: Doug Smythies <dsmythies@telus.net>
Reported-by: LesÅ=82aw Kope=C4=87 <leslaw.kopec@nasza-klasa.pl>
Reported-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-4v31etnhgg9kwd6ocgx3rxl8@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Cc: Kerin Millar <kerframil@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


---
 kernel/sched.c |   53 ++++++++++++++++++++++++++---------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3392,13 +3392,10 @@ calc_load_n(unsigned long load, unsigned
  * Once we've updated the global active value, we need to apply the exponential
  * weights adjusted to the number of cycles missed.
  */
-static void calc_global_nohz(unsigned long ticks)
+static void calc_global_nohz(void)
 {
 	long delta, active, n;
 
-	if (time_before(jiffies, calc_load_update))
-		return;
-
 	/*
 	 * If we crossed a calc_load_update boundary, make sure to fold
 	 * any pending idle changes, the respective CPUs might have
@@ -3410,31 +3407,25 @@ static void calc_global_nohz(unsigned lo
 		atomic_long_add(delta, &calc_load_tasks);
 
 	/*
-	 * If we were idle for multiple load cycles, apply them.
+	 * It could be the one fold was all it took, we done!
 	 */
-	if (ticks >= LOAD_FREQ) {
-		n = ticks / LOAD_FREQ;
+	if (time_before(jiffies, calc_load_update + 10))
+		return;
 
-		active = atomic_long_read(&calc_load_tasks);
-		active = active > 0 ? active * FIXED_1 : 0;
+	/*
+	 * Catch-up, fold however many we are behind still
+	 */
+	delta = jiffies - calc_load_update - 10;
+	n = 1 + (delta / LOAD_FREQ);
 
-		avenrun[0] = calc_load_n(avenrun[0], EXP_1, active, n);
-		avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n);
-		avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n);
+	active = atomic_long_read(&calc_load_tasks);
+	active = active > 0 ? active * FIXED_1 : 0;
 
-		calc_load_update += n * LOAD_FREQ;
-	}
+	avenrun[0] = calc_load_n(avenrun[0], EXP_1, active, n);
+	avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n);
+	avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n);
 
-	/*
-	 * Its possible the remainder of the above division also crosses
-	 * a LOAD_FREQ period, the regular check in calc_global_load()
-	 * which comes after this will take care of that.
-	 *
-	 * Consider us being 11 ticks before a cycle completion, and us
-	 * sleeping for 4*LOAD_FREQ + 22 ticks, then the above code will
-	 * age us 4 cycles, and the test in calc_global_load() will
-	 * pick up the final one.
-	 */
+	calc_load_update += n * LOAD_FREQ;
 }
 #else
 static void calc_load_account_idle(struct rq *this_rq)
@@ -3446,7 +3437,7 @@ static inline long calc_load_fold_idle(v
 	return 0;
 }
 
-static void calc_global_nohz(unsigned long ticks)
+static void calc_global_nohz(void)
 {
 }
 #endif
@@ -3474,8 +3465,6 @@ void calc_global_load(unsigned long tick
 {
 	long active;
 
-	calc_global_nohz(ticks);
-
 	if (time_before(jiffies, calc_load_update + 10))
 		return;
 
@@ -3487,6 +3476,16 @@ void calc_global_load(unsigned long tick
 	avenrun[2] = calc_load(avenrun[2], EXP_15, active);
 
 	calc_load_update += LOAD_FREQ;
+
+	/*
+	 * Account one period with whatever state we found before
+	 * folding in the nohz state and ageing the entire idle period.
+	 *
+	 * This avoids loosing a sample when we go idle between
+	 * calc_load_account_active() (10 ticks ago) and now and thus
+	 * under-accounting.
+	 */
+	calc_global_nohz();
 }
 
 /*



      parent reply	other threads:[~2012-05-04 20:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-04 20:43 [ 00/47] 3.0.31-stable review Greg KH
2012-05-04 20:42 ` [ 01/47] nfs: Enclose hostname in brackets when needed in nfs_do_root_mount Greg KH
2012-05-04 20:42 ` [ 02/47] NFSv4: Ensure that the LOCK code sets exception->inode Greg KH
2012-05-04 20:42 ` [ 03/47] NFSv4: Ensure that we check lock exclusive/shared type against open modes Greg KH
2012-05-04 20:42 ` [ 04/47] x86, apic: APIC code touches invalid MSR on P5 class machines Greg KH
2012-05-04 20:42 ` [ 05/47] Revert "autofs: work around unhappy compat problem on x86-64" Greg KH
2012-05-04 20:42 ` [ 06/47] xen: correctly check for pending events when restoring irq flags Greg KH
2012-05-04 20:42 ` [ 07/47] xen/smp: Fix crash when booting with ACPI hotplug CPUs Greg KH
2012-05-04 20:42 ` [ 08/47] ASoC: dapm: Ensure power gets managed for line widgets Greg KH
2012-05-04 20:42 ` [ 09/47] dmaengine: at_hdmac: remove clear-on-read in atc_dostart() Greg KH
2012-05-04 20:42 ` [ 10/47] hwmon: fam15h_power: fix bogus values with current BIOSes Greg KH
2012-05-04 20:42 ` [ 11/47] hwmon: (fam15h_power) Fix pci_device_id array Greg KH
2012-05-04 20:42 ` [ 12/47] drm/i915: handle input/output sdvo timings separately in mode_set Greg KH
2012-05-04 20:42 ` [ 13/47] drm/i915: fix integer overflow in i915_gem_execbuffer2() Greg KH
2012-05-04 20:42 ` [ 14/47] drm/i915: fix integer overflow in i915_gem_do_execbuffer() Greg KH
2012-05-04 20:42 ` [ 15/47] nl80211: ensure interface is up in various APIs Greg KH
2012-05-04 20:43 ` [ 16/47] EHCI: fix criterion for resuming the root hub Greg KH
2012-05-04 20:43 ` [ 17/47] brcm80211: smac: resume transmit fifo upon receiving frames Greg KH
2012-05-04 20:43 ` [ 18/47] Fix modpost failures in fedora 17 Greg KH
2012-05-04 20:43 ` [ 19/47] KVM: unmap pages from the iommu when slots are removed Greg KH
2012-05-04 20:43 ` [ 20/47] mmc: unbreak sdhci-esdhc-imx on i.MX25 Greg KH
2012-05-04 20:43 ` [ 21/47] nfsd: fix b0rken error value for setattr on read-only mount Greg KH
2012-05-04 20:43 ` [ 22/47] nfsd: fix error values returned by nfsd4_lockt() when nfsd_open() fails Greg KH
2012-05-04 20:43 ` [ 23/47] [PATCH] Revert "usb: Fix build error due to dma_mask is not at pdev_archdata at ARM" Greg KH
2012-05-07  1:59   ` Ben Hutchings
2012-05-08  0:31     ` Greg KH
2012-05-04 20:43 ` [ 24/47] USB: cdc-wdm: fix race leading leading to memory corruption Greg KH
2012-05-04 20:43 ` [ 25/47] USB: EHCI: fix crash during suspend on ASUS computers Greg KH
2012-05-04 20:43 ` [ 26/47] USB: gadget: storage gadgets send wrong error code for unknown commands Greg KH
2012-05-04 20:43 ` [ 27/47] usb gadget: uvc: uvc_request_data::length field must be signed Greg KH
2012-05-04 20:43 ` [ 28/47] pipes: add a "packetized pipe" mode for writing Greg KH
2012-05-04 20:43 ` [ 29/47] autofs: make the autofsv5 packet file descriptor use a packetized pipe Greg KH
2012-05-04 20:43 ` [ 30/47] ARM: 7403/1: tls: remove covert channel via TPIDRURW Greg KH
2012-05-04 20:43 ` [ 31/47] SCSI: libsas: fix sas_find_bcast_phy() in the presence of vacant phys Greg KH
2012-05-04 20:43 ` [ 32/47] SCSI: libsas: fix false positive device attached conditions Greg KH
2012-05-04 20:43 ` [ 33/47] efi: Add new variable attributes Greg KH
2012-05-04 20:43 ` [ 34/47] efivars: String functions Greg KH
2012-05-04 20:43 ` [ 35/47] efivars: fix warnings when CONFIG_PSTORE=n Greg KH
2012-05-04 20:43 ` [ 36/47] efi: Validate UEFI boot variables Greg KH
2012-05-04 20:43 ` [ 37/47] efivars: Improve variable validation Greg KH
2012-05-04 20:43 ` [ 38/47] hwmon: (coretemp) Increase CPU core limit Greg KH
2012-05-04 20:43 ` [ 39/47] hwmon: (coretemp) fix oops on cpu unplug Greg KH
2012-05-04 20:43 ` [ 40/47] libata: skip old error history when counting probe trials Greg KH
2012-05-04 20:43 ` [ 41/47] i2c: pnx: Disable clk in suspend Greg KH
2012-05-04 20:43 ` [ 42/47] ipw2200: Fix race condition in the command completion acknowledge Greg KH
2012-05-04 20:43 ` [ 43/47] mac80211: fix AP mode EAP tx for VLAN stations Greg KH
2012-05-04 20:43 ` [ 44/47] rtlwifi: Fix oops on unload Greg KH
2012-05-04 20:43 ` [ 45/47] wl1251: fix crash on remove due to premature kfree Greg KH
2012-05-04 20:43 ` [ 46/47] wl1251: fix crash on remove due to leftover work item Greg KH
2012-05-04 20:43 ` Greg KH [this message]

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=20120504204248.905290700@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=aman@tmm1.net \
    --cc=dsmythies@telus.net \
    --cc=kerframil@gmail.com \
    --cc=leslaw.kopec@nasza-klasa.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).