From patchwork Wed Mar 1 05:27:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 9597575 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C8F860414 for ; Wed, 1 Mar 2017 05:38:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F21326E56 for ; Wed, 1 Mar 2017 05:38:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13EAD28410; Wed, 1 Mar 2017 05:38:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8268C28306 for ; Wed, 1 Mar 2017 05:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752065AbdCAFip (ORCPT ); Wed, 1 Mar 2017 00:38:45 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:35427 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbdCAFil (ORCPT ); Wed, 1 Mar 2017 00:38:41 -0500 Received: by mail-qk0-f193.google.com with SMTP id n127so8225299qkf.2; Tue, 28 Feb 2017 21:36:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references:reply-to:organization; bh=/xptmugn5q77t5y9i6jvOr4NYuLGYBjPGRH8v824kIM=; b=qIEgWzB8ZbPC1vczikhGt7M3xbRfm873wk81VX7kh/WOz/QSaWBp18zDAfLVS9f3oo 75XvcdXzVFzVqq4W8SO4H89DxyBytGyE0sLMBslCr+393jxz93JTyo9itxaOvwPfgQxw LaHu6wl+Nf8rbzpXYw806pmAYxhxTsMSBUe30BQFZWzy2dUFroBbYGehmFCCOBdH62Xi psVp4G4eBc+1BBq8uPJjNVtaTSeLgOYtZ9GjlU64qcChhooNQSRIiISUhWb/jU9QqtXy IfDL3ANOTGIgAQjGUgeDr2mUAVTccPI/wLtlAgRzMa5jCCLi1jCtFMADY/yi3ml2i879 Oe4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references:reply-to:organization; bh=/xptmugn5q77t5y9i6jvOr4NYuLGYBjPGRH8v824kIM=; b=mTjB5p4Qxw/rfmxT72rir05Svb0sR6fqd5gDusemdfSnGEIRGHDSHgtjc+34OH0jpx j6IoDgr6SVKwGpkQKHUsPUDgnqSC2IlRhs+F1leVOeaIu1q13kr+NDTe5X2fs2Bpuq4n bsNhblqHrug+wKwuA8J6PW5k/zfTrhxgi3CJphYxQIJGX8ukZINvQ+bSYuX3rGBsX1vZ wnvPHs3tx8djAKTHhSeCEAs/o+CxqUO6zOitNlLcSP3D+VTNSiQeXrSJ8fVqGFkficTS eHS6wqy36CVBwCcRaKN+lTd+Uc64Nywzxz14CEHzla3ZXOftbi2n4dzviN+ODwnX2ZVx Zxqw== X-Gm-Message-State: AMke39njdCx0BsrE0BubsgEBetLN5LvIic/ikihbGIE8Ka0kN/VYCp1QoyHiYXY4cXH5WA== X-Received: by 10.200.33.141 with SMTP id 13mr8251355qty.83.1488346117632; Tue, 28 Feb 2017 21:28:37 -0800 (PST) Received: from z87.localdomain (pool-96-230-116-151.bstnma.fios.verizon.net. [96.230.116.151]) by smtp.gmail.com with ESMTPSA id c141sm2530517qkb.10.2017.02.28.21.28.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Feb 2017 21:28:36 -0800 (PST) From: Len Brown To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Len Brown Subject: [PATCH 22/44] tools/power turbostat: use tsc_tweak everwhere it is needed Date: Wed, 1 Mar 2017 00:27:26 -0500 Message-Id: <008d396eb219ee5a1c98c9ef01c35752d35f0d6c.1488345270.git.len.brown@intel.com> X-Mailer: git-send-email 2.11.0.161.g6610af872 In-Reply-To: <20170301052748.27810-1-lenb@kernel.org> References: <20170301052748.27810-1-lenb@kernel.org> In-Reply-To: <678a3bd1b3de6d2ebf604e7d708bc8150bb667e9.1488345270.git.len.brown@intel.com> References: <678a3bd1b3de6d2ebf604e7d708bc8150bb667e9.1488345270.git.len.brown@intel.com> Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Len Brown The CPU ticks at a rate in the "bus clock" domain. eg. 100 MHz * bus_ratio. On newer processors, the TSC has been moved out of this BCLK domain and into a separate crystal-clock domain. While the TSC ticks "close to" the base frequency, those that look closely at the numbers will notice small errors in calculations that mix units of TSC clocks and bus clocks. "tsc_tweak" was introduced to address the most visible mixing -- the %Busy and the the Busy_MHz calculations. (A simplification as since removed TSC from the BusyMHz calculation) Here we apply the tsc_tweak to everyplace where BCLK and TSC units are mixed. The results is that on a system which is 100% idle, the sum of the C-states are now much more likely to be closer to 100%. Reported-by: Travis Downs Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 6867557596af..bbdf9ba9d41b 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -680,7 +680,7 @@ int dump_counters(struct thread_data *t, struct core_data *c, int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) { - double interval_float; + double interval_float, tsc; char *fmt8; int i; struct msr_counter *mp; @@ -695,6 +695,8 @@ int format_counters(struct thread_data *t, struct core_data *c, interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; + tsc = t->tsc * tsc_tweak; + /* topo columns, print blanks on 1st (average) line */ if (t == &average.threads) { if (DO_BIC(BIC_Package)) @@ -725,14 +727,14 @@ int format_counters(struct thread_data *t, struct core_data *c, 1.0 / units * t->aperf / interval_float); if (DO_BIC(BIC_Busy)) - outp += sprintf(outp, "\t%.2f", 100.0 * t->mperf/t->tsc/tsc_tweak); + outp += sprintf(outp, "\t%.2f", 100.0 * t->mperf/tsc); if (DO_BIC(BIC_Bzy_MHz)) { if (has_base_hz) outp += sprintf(outp, "\t%.0f", base_hz / units * t->aperf / t->mperf); else outp += sprintf(outp, "\t%.0f", - 1.0 * t->tsc / units * t->aperf / t->mperf / interval_float); + tsc / units * t->aperf / t->mperf / interval_float); } if (DO_BIC(BIC_TSC_MHz)) @@ -748,7 +750,7 @@ int format_counters(struct thread_data *t, struct core_data *c, /* C1 */ if (DO_BIC(BIC_CPU_c1)) - outp += sprintf(outp, "\t%.2f", 100.0 * t->c1/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * t->c1/tsc); /* Added counters */ for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { @@ -760,7 +762,7 @@ int format_counters(struct thread_data *t, struct core_data *c, } else if (mp->format == FORMAT_DELTA) { outp += sprintf(outp, "\t%lld", t->counter[i]); } else if (mp->format == FORMAT_PERCENT) { - outp += sprintf(outp, "\t%.2f", 100.0 * t->counter[i]/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * t->counter[i]/tsc); } } @@ -769,15 +771,15 @@ int format_counters(struct thread_data *t, struct core_data *c, goto done; if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) - outp += sprintf(outp, "\t%.2f", 100.0 * c->c3/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * c->c3/tsc); if (DO_BIC(BIC_CPU_c6)) - outp += sprintf(outp, "\t%.2f", 100.0 * c->c6/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * c->c6/tsc); if (DO_BIC(BIC_CPU_c7)) - outp += sprintf(outp, "\t%.2f", 100.0 * c->c7/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * c->c7/tsc); /* Mod%c6 */ if (DO_BIC(BIC_Mod_c6)) - outp += sprintf(outp, "\t%.2f", 100.0 * c->mc6_us / t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * c->mc6_us / tsc); if (DO_BIC(BIC_CoreTmp)) outp += sprintf(outp, "\t%d", c->core_temp_c); @@ -791,7 +793,7 @@ int format_counters(struct thread_data *t, struct core_data *c, } else if (mp->format == FORMAT_DELTA) { outp += sprintf(outp, "\t%lld", c->counter[i]); } else if (mp->format == FORMAT_PERCENT) { - outp += sprintf(outp, "\t%.2f", 100.0 * c->counter[i]/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * c->counter[i]/tsc); } } @@ -819,24 +821,24 @@ int format_counters(struct thread_data *t, struct core_data *c, /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ if (do_skl_residency) { - outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_wtd_core_c0/t->tsc); - outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_core_c0/t->tsc); - outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_gfxe_c0/t->tsc); - outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_both_core_gfxe_c0/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_wtd_core_c0/tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_core_c0/tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_gfxe_c0/tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_both_core_gfxe_c0/tsc); } if (do_pc2) - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc2/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc2/tsc); if (do_pc3) - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc3/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc3/tsc); if (do_pc6) - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc6/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc6/tsc); if (do_pc7) - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc7/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc7/tsc); if (do_c8_c9_c10) { - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc8/t->tsc); - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc9/t->tsc); - outp += sprintf(outp, "\t%.2f", 100.0 * p->pc10/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc8/tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc9/tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc10/tsc); } /* @@ -878,7 +880,7 @@ int format_counters(struct thread_data *t, struct core_data *c, } else if (mp->format == FORMAT_DELTA) { outp += sprintf(outp, "\t%lld", p->counter[i]); } else if (mp->format == FORMAT_PERCENT) { - outp += sprintf(outp, "\t%.2f", 100.0 * p->counter[i]/t->tsc); + outp += sprintf(outp, "\t%.2f", 100.0 * p->counter[i]/tsc); } } @@ -1048,7 +1050,7 @@ delta_thread(struct thread_data *new, struct thread_data *old, old->c1 = 0; else { /* normal case, derive c1 */ - old->c1 = old->tsc - old->mperf - core_delta->c3 + old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 - core_delta->c6 - core_delta->c7; } }