From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65833C10F11 for ; Wed, 24 Apr 2019 15:47:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4067220878 for ; Wed, 24 Apr 2019 15:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731758AbfDXPrL (ORCPT ); Wed, 24 Apr 2019 11:47:11 -0400 Received: from mga18.intel.com ([134.134.136.126]:29462 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727327AbfDXPrK (ORCPT ); Wed, 24 Apr 2019 11:47:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Apr 2019 08:47:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,390,1549958400"; d="scan'208";a="164464018" Received: from otc-lr-04.jf.intel.com ([10.54.39.156]) by fmsmga002.fm.intel.com with ESMTP; 24 Apr 2019 08:47:09 -0700 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 Subject: [PATCH] perf stat: Add hint for SMI cost measurement Date: Wed, 24 Apr 2019 08:46:32 -0700 Message-Id: <1556120792-35415-1-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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 Signed-off-by: Kan Liang --- 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