From: Len Brown <lenb@kernel.org>
To: linux-pm@vger.kernel.org
Cc: Len Brown <len.brown@intel.com>
Subject: [PATCH 16/16] tools/power turbostat: detect and work around syscall jitter
Date: Sat, 27 Feb 2016 04:01:10 -0500 [thread overview]
Message-ID: <f899e44ea4b92e2bc24b6bf9f9c8458e6477400c.1456563103.git.len.brown@intel.com> (raw)
In-Reply-To: <1456563670-23282-1-git-send-email-lenb@kernel.org>
In-Reply-To: <69807a638f91524ed75027f808cd277417ecee7a.1456563103.git.len.brown@intel.com>
From: Len Brown <len.brown@intel.com>
The accuracy of Bzy_Mhz and Busy% depend on reading
the TSC, APERF, and MPERF close together in time.
When there is a very short measurement interval,
or a large system is profoundly idle, the changes
in APERF and MPERF may be very small.
They can be small enough that an expensive interrupt
between reading APERF and MPERF can cause the APERF/MPERF
ratio to become inaccurate, resulting in invalid
calculation and display of Bzy_MHz.
A dummy APERF read of APERF makes this problem
much more rare. Apparently this 1st systemn call
after exiting a long stretch of idle is when we
typically see expensive timer interrupts that cause
large jitter.
For the cases that dummy APERF read fails to prevent,
we compare the latency of the APERF and MPERF reads.
If they differ by more than 2x, we re-issue them.
Signed-off-by: Len Brown <len.brown@intel.com>
---
tools/power/x86/turbostat/turbostat.c | 51 ++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 9896619..2c43527 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -1059,19 +1059,68 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
{
int cpu = t->cpu_id;
unsigned long long msr;
+ int aperf_mperf_retry_count = 0;
if (cpu_migrate(cpu)) {
fprintf(outf, "Could not migrate to CPU %d\n", cpu);
return -1;
}
+retry:
t->tsc = rdtsc(); /* we are running on local CPU of interest */
if (has_aperf) {
+ unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time;
+
+ /*
+ * The TSC, APERF and MPERF must be read together for
+ * APERF/MPERF and MPERF/TSC to give accurate results.
+ *
+ * Unfortunately, APERF and MPERF are read by
+ * individual system call, so delays may occur
+ * between them. If the time to read them
+ * varies by a large amount, we re-read them.
+ */
+
+ /*
+ * This initial dummy APERF read has been seen to
+ * reduce jitter in the subsequent reads.
+ */
+
+ if (get_msr(cpu, MSR_IA32_APERF, &t->aperf))
+ return -3;
+
+ t->tsc = rdtsc(); /* re-read close to APERF */
+
+ tsc_before = t->tsc;
+
if (get_msr(cpu, MSR_IA32_APERF, &t->aperf))
return -3;
+
+ tsc_between = rdtsc();
+
if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf))
return -4;
+
+ tsc_after = rdtsc();
+
+ aperf_time = tsc_between - tsc_before;
+ mperf_time = tsc_after - tsc_between;
+
+ /*
+ * If the system call latency to read APERF and MPERF
+ * differ by more than 2x, then try again.
+ */
+ if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) {
+ aperf_mperf_retry_count++;
+ if (aperf_mperf_retry_count < 5)
+ goto retry;
+ else
+ warnx("cpu%d jitter %lld %lld\n",
+ cpu, aperf_time, mperf_time);
+ }
+ aperf_mperf_retry_count = 0;
+
t->aperf = t->aperf * aperf_mperf_multiplier;
t->mperf = t->mperf * aperf_mperf_multiplier;
}
@@ -3554,7 +3603,7 @@ int get_and_dump_counters(void)
}
void print_version() {
- fprintf(outf, "turbostat version 4.10 10 Dec, 2015"
+ fprintf(outf, "turbostat version 4.11 27 Feb 2016"
" - Len Brown <lenb@kernel.org>\n");
}
--
2.7.1.339.g0233b80
prev parent reply other threads:[~2016-02-27 9:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-27 9:00 [PATCH 0/16] turbostat updates Len Brown
2016-02-27 9:00 ` [PATCH 01/16] tools/power turbostat: decode more CPUID fields Len Brown
2016-02-27 9:00 ` [PATCH 02/16] tools/power turbostat: CPUID(0x16) leaf shows base, max, and bus frequency Len Brown
2016-02-27 9:00 ` [PATCH 03/16] x86 msr-index: Simplify syntax for HWP fields Len Brown
2016-02-27 9:00 ` [PATCH 04/16] tools/power turbostat: decode HWP registers Len Brown
2016-02-27 9:00 ` [PATCH 05/16] tools/power turbostat: Decode MSR_MISC_PWR_MGMT Len Brown
2016-02-27 9:01 ` [PATCH 06/16] tools/power turbostat: allow sub-sec intervals Len Brown
2016-02-28 3:43 ` Doug Smythies
2016-03-01 2:07 ` Brown, Len
2016-03-13 7:57 ` Len Brown
2016-02-27 9:01 ` [PATCH 07/16] tools/power turbostat: Intel Xeon x200: fix erroneous bclk value Len Brown
2016-02-27 9:01 ` [PATCH 08/16] tools/power turbostat: Intel Xeon x200: fix turbo-ratio decoding Len Brown
2016-02-27 9:01 ` [PATCH 09/16] tools/power turbostat: re-name "%Busy" field to "Busy%" Len Brown
2016-02-27 9:01 ` [PATCH 10/16] tools/power turbostat: add --out option for saving output in a file Len Brown
2016-02-27 9:01 ` [PATCH 11/16] tools/power turbostat: fix compiler warnings Len Brown
2016-02-27 9:01 ` [PATCH 12/16] tools/power turbostat: make fewer systems calls Len Brown
2016-02-27 9:01 ` [PATCH 13/16] tools/power turbostat: show IRQs per CPU Len Brown
2016-02-27 9:01 ` [PATCH 14/16] tools/power turbostat: show GFXMHz Len Brown
2016-02-27 9:01 ` [PATCH 15/16] tools/power turbostat: show GFX%rc6 Len Brown
2016-02-27 9:01 ` Len Brown [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=f899e44ea4b92e2bc24b6bf9f9c8458e6477400c.1456563103.git.len.brown@intel.com \
--to=lenb@kernel.org \
--cc=len.brown@intel.com \
--cc=linux-pm@vger.kernel.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).