linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: acme@redhat.com, mingo@redhat.com, linux-kernel@vger.kernel.org
Cc: jolsa@redhat.com, namhyung@gmail.com, lgoncalv@redhat.com,
	ak@linux.intel.com, Kan Liang <kan.liang@linux.intel.com>
Subject: [PATCH V2] perf stat: Add hint for SMI cost measurement
Date: Fri, 26 Apr 2019 05:45:03 -0700	[thread overview]
Message-ID: <1556282703-120695-1-git-send-email-kan.liang@linux.intel.com> (raw)

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

Entering/exiting a C-state deeper than C0 may cause slight difference in
counts between aperf and unhalted core cycles, which may impact the SMI
cost.

Add smi_env_check() to check if C-state 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>
---

Changes since V1:
- Update changelog, document, and user-visible message

 tools/perf/Documentation/perf-stat.txt |  5 +++++
 tools/perf/builtin-stat.c              | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 39c05f8..19b7267 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -309,6 +309,11 @@ 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.
 
+Entering/exiting a C-state deeper than C0 may cause slight difference in counts
+between aperf and unhalted core cycles, which may impact the SMI cost.
+Please completely disable C-state 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..e437788 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,27 @@ __weak void arch_topdown_group_warn(void)
 {
 }
 
+static void smi_env_check(void)
+{
+	char *name;
+	size_t len;
+	int err;
+
+	err = sysfs__read_str(CPUIDLE_CUR_DRV, &name, &len);
+	if (err) {
+		pr_warning("Failed to read %s, err %d. Ignoring C-state status check.\n",
+			   CPUIDLE_CUR_DRV, err);
+		return;
+	}
+
+	if (strncmp(name, "none", 4)) {
+		pr_warning("Entering/exiting a C-state deeper than C0 may result inaccurate SMI cost.\n"
+			   "Please completely disable C-state, 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 +1218,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


                 reply	other threads:[~2019-04-26 12:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1556282703-120695-1-git-send-email-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@gmail.com \
    /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).