Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1495245ybh; Thu, 23 Jul 2020 10:13:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj0MFooMtwgun6UWXG7MJtnvY8ZKSNfsswLC2gsktbbvXxQ064+PQIZFCQ2sLqZWuA4zkP X-Received: by 2002:a17:907:2170:: with SMTP id rl16mr5594916ejb.422.1595524406260; Thu, 23 Jul 2020 10:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595524406; cv=none; d=google.com; s=arc-20160816; b=J5lgzXeByF/Ktcs+iH8QvNSsTjr66yppaqZz8l9IWMDxCuF1+r6YmVWukqzaZsW+/6 vHZcc1T/E6h8ae0fO5X9TOAqwudcMVl9RulF45bsfdZVAeKEcI1BcPxgkaeaylzVlAn8 tdhOrZLZ56BPiX8qX2OWfbeY/0/mzhfRrXeFd37Asdd6/bfPSIO8CGd+LVAWIcgQHFjp ip4rPOp4cIXVkaGNZ4+KNjA0WNm3bzr5jhMEiqjNYFhjzlUXV1YUVY/UUiS/31mnLmUs X2dtZYbjNCpOheIzfxkzlLi1EXK9Kyd0NMXSWnVQpSTmv076Xgq83zFEBI6SHnsJWhR7 mISw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=MvK8XRHWlMXopQx5/9+Yj2Lo+XtqW4gRba3kQtjeUJQ=; b=Yp3ZGehg2X6E25lnpIXjzPiupfnmHmlXXY7NaylNuCE/Ng8YtsNJkTo7tqKe9ch79P PM4sd+Cu9KcuTLKqJZ2X4TZwF/3qPyd8LLCGKUmaicmC6FO3KY4uB4ZpLcYkDo8WqMmH 9s2tQuTlLpbxHGiD1OvJKuXNkQE9adA1uM0ZIIGclXVR/s0wKg28wm/cF1kP/3WQKs11 zb4OS+XQIxqv27QUx8xRGtGy/K8udWPIUWQrMQMjSSxwUO5/B1KWRFAaZcvdCRUTTA/A nnXBz28YaHKD0nYh8izL0wq9+KK/yv+DMMtqmPeNqlxDj5fJhfOMljRpgeZPmFVj/vvH rYlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q22si2412681ejx.87.2020.07.23.10.13.03; Thu, 23 Jul 2020 10:13:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730138AbgGWRMK (ORCPT + 99 others); Thu, 23 Jul 2020 13:12:10 -0400 Received: from mga05.intel.com ([192.55.52.43]:6620 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728867AbgGWRMA (ORCPT ); Thu, 23 Jul 2020 13:12:00 -0400 IronPort-SDR: Wl5yuD45WskL4lhuse5VdPaYNT1gMT1iIOG9X70mDuGh1oGGzz7g5VxNUpQFFLAMuKdq3Ax2oV LmmfVbrp37/Q== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="235456880" X-IronPort-AV: E=Sophos;i="5.75,387,1589266800"; d="scan'208";a="235456880" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2020 10:11:55 -0700 IronPort-SDR: 5kALMA9XdNjpg2/BQaifeWNnRDX3BVy9b/gZb86aBnEMLegmHDBCT+20QLl1iNnwwlNsNCPjI4 SE5TvR+2Jt+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,387,1589266800"; d="scan'208";a="488904323" Received: from labuser-ice-lake-client-platform.jf.intel.com ([10.54.55.65]) by fmsmga005.fm.intel.com with ESMTP; 23 Jul 2020 10:11:55 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, acme@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: jolsa@kernel.org, eranian@google.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, like.xu@linux.intel.com, Kan Liang Subject: [PATCH V7 13/14] perf, tools, stat: Check Topdown Metric group Date: Thu, 23 Jul 2020 10:11:16 -0700 Message-Id: <20200723171117.9918-14-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200723171117.9918-1-kan.liang@linux.intel.com> References: <20200723171117.9918-1-kan.liang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang The slots event is required in a Topdown Metric group. Add a check to examine the Topdown Metric group. Error out if there is no slots event detected. Only check the group on the platform which using topdown_metric_attrs, e.g. Ice Lake. Signed-off-by: Kan Liang --- tools/perf/builtin-stat.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 078ea1485317..9886aef78440 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1441,6 +1441,72 @@ static int topdown_filter_events(const char **attr, char **str, bool use_group) return 0; } +/* Event encoding for Topdown Metric events */ +#define TOPDOWN_SLOTS 0x0400 +#define TOPDOWN_RETIRE 0x8000 +#define TOPDOWN_BAD_SPEC 0x8100 +#define TOPDOWN_FE_BOUND 0x8200 +#define TOPDOWN_BE_BOUND 0x8300 + +static bool is_topdown_metric_event(struct evsel *counter) +{ + if (!counter->pmu_name) + return false; + + if (strcmp(counter->pmu_name, "cpu")) + return false; + + if ((counter->core.attr.config == TOPDOWN_RETIRE) || + (counter->core.attr.config == TOPDOWN_BAD_SPEC) || + (counter->core.attr.config == TOPDOWN_FE_BOUND) || + (counter->core.attr.config == TOPDOWN_BE_BOUND)) + return true; + + return false; +} + +static bool is_topdown_slots_event(struct evsel *counter) +{ + if (!counter->pmu_name) + return false; + + if (strcmp(counter->pmu_name, "cpu")) + return false; + + if (counter->core.attr.config == TOPDOWN_SLOTS) + return true; + + return false; +} + +static bool topdown_check_group_member(void) +{ + struct evsel *counter, *leader, *member; + bool has_slots; + + if (!pmu_have_event("cpu", topdown_metric_attrs[0])) + return true; + + evlist__for_each_entry(evsel_list, counter) { + if (!is_topdown_metric_event(counter)) + continue; + + leader = counter->leader; + has_slots = false; + + for_each_group_evsel(member, leader) { + if (is_topdown_slots_event(member)) + has_slots = true; + counter = member; + } + + if (!has_slots) + return false; + } + + return true; +} + __weak bool arch_topdown_check_group(bool *warn) { *warn = false; @@ -2024,6 +2090,12 @@ int cmd_stat(int argc, const char **argv) (const char **) stat_usage, PARSE_OPT_STOP_AT_NON_OPTION); perf_stat__collect_metric_expr(evsel_list); + + if (!topdown_check_group_member()) { + fprintf(stderr, "Topdown group must include slots event\n"); + goto out; + } + perf_stat__init_shadow_stats(); if (stat_config.csv_sep) { -- 2.17.1