public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf stat: Add hint for SMI cost measurement
@ 2019-04-24 15:46 kan.liang
  2019-04-25  6:39 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: kan.liang @ 2019-04-24 15:46 UTC (permalink / raw)
  To: acme, mingo, linux-kernel; +Cc: jolsa, namhyung, lgoncalv, ak, Kan Liang

From: Kan Liang <kan.liang@linux.intel.com>

Cstate may cause drift between aperf and cycles, which impact the
accuracy of SMI cost measurement.

Add smi_env_check() to check if cstate is completely disabled during the
measurement. If not, give a hint to user.

Update the document as well.

Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 tools/perf/Documentation/perf-stat.txt |  4 ++++
 tools/perf/builtin-stat.c              | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 39c05f8..e0d8763 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -309,6 +309,10 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf
 
 Users who wants to get the actual value can apply --no-metric-only.
 
+Cstate may cause drift between aperf and cycles.
+Please completely disable cstate during the measurement.
+E.g. set idle=poll in grub
+
 EXAMPLES
 --------
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c3625ec..ac273b4 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -87,6 +87,7 @@
 
 #define DEFAULT_SEPARATOR	" "
 #define FREEZE_ON_SMI_PATH	"devices/cpu/freeze_on_smi"
+#define CPUIDLE_CUR_DRV		"devices/system/cpu/cpuidle/current_driver"
 
 static void print_counters(struct timespec *ts, int argc, const char **argv);
 
@@ -1024,6 +1025,25 @@ __weak void arch_topdown_group_warn(void)
 {
 }
 
+static void smi_env_check(void)
+{
+	char *name;
+	size_t len;
+
+	if (sysfs__read_str(CPUIDLE_CUR_DRV, &name, &len)) {
+		pr_warning("Failed to check cstate status.\n");
+		return;
+	}
+
+	if (strncmp(name, "none", 4)) {
+		pr_warning("Cstate may cause drift between aperf and cycles. "
+			   "Please completely disable cstate, "
+			   "E.g. set idle=poll in grub\n");
+	}
+
+	free(name);
+}
+
 /*
  * Add default attributes, if there were no attributes specified or
  * if -d/--detailed, -d -d or -d -d -d is used:
@@ -1196,6 +1216,9 @@ static int add_default_attributes(void)
 
 		if (pmu_have_event("msr", "aperf") &&
 		    pmu_have_event("msr", "smi")) {
+
+			smi_env_check();
+
 			if (!force_metric_only)
 				stat_config.metric_only = true;
 			err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-25 19:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-24 15:46 [PATCH] perf stat: Add hint for SMI cost measurement kan.liang
2019-04-25  6:39 ` Ingo Molnar
2019-04-25 13:14   ` Liang, Kan
2019-04-25 17:47     ` Ingo Molnar
2019-04-25 19:05       ` Liang, Kan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox