From patchwork Tue Sep 3 10:19:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30A56CD3420 for ; Tue, 3 Sep 2024 10:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eSIRbj8Rb/jfALOc0Otj8KTwtef0MK65RgsPT2QJ0Go=; b=VXGVDnRlWC+pW6MNwIGN4KH40e ne7MmhmOoXK/I7C6cKcoSwk1w2RJrun20EGNP2zju+bYmHX+7jnMONO7u+tQj7fTjHHMfnDvQA/cC 3y6uFWjmLMRNqueJC9hvSUIQsIur1ho5g+aR9Tg1H7IsfUuZk7mkb/ZjwbUHoVQ5w8tbq332Z6ynp MnSSCkDvNzMFBaGwWJUFK2mDhaLkfiw4prwDxQyGNPg/w2oju/+kR/ebq60yb1UCbCKvYtYBf/Npz JdLfZJKj+4gylCeTBpDLDKb27xOQld2PBdXuuirdIos820jFMsNUB6NNgNT76ueIOcJt3eh7ftIkC suxtXZDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQgd-0000000HKIL-1XKT; Tue, 03 Sep 2024 10:22:59 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQeQ-0000000HJg8-1N41 for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:20:45 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42c7856ed66so24884325e9.3 for ; Tue, 03 Sep 2024 03:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358840; x=1725963640; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eSIRbj8Rb/jfALOc0Otj8KTwtef0MK65RgsPT2QJ0Go=; b=fpbqyEUrVuJg4AEJFIWtOUTxPnggnWO+Zd9sYwW/twQv2M3AB9q+UNRfboYyk9NVQ3 Qd8wp4JtcOVSuEklnUKH3JlZAocY6+7ZBgJXPbUA6hucM2Gs1x92tmoIdCUB4Oq2yNPK 2/KbOM6jEHMX1sSrfDqUXz4C48a0yrNCnT3t1FUXGNQs+O0/+E8gc168h0Ue/DzdTvEw TZR9RYji9fDd1WRq/56VKJfra4wYZeKyIefAPjsi14DMfmyAkyBs2bokXX6XabzNFzXd gAniuIWGEYLPJA0G2e9nzcG5LvIZjeoaopRaALype1b8Gt3g6gHAkYp8/mK3QpuaaEfX tlYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358840; x=1725963640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eSIRbj8Rb/jfALOc0Otj8KTwtef0MK65RgsPT2QJ0Go=; b=e7FJzZnyepM/qqFF8omtgdomVpEAbAi7PW9JEOsTCYJnz/qAqbzdv/eAq+FG21TPJO dK0YRJGX32diOPzkjx52w+UwoC956QuJ7zutjbQR+Vw+tSXaEznvmaHxMvWvlxnUVLcN kASE+E+FHv+zaJQjxtu2Dq2MnAxADA+5uhDn8aGjZeTWzt9UKadv/861LX6CdDufGMRM VsfBGDBTpV5pWyeV7IiKpQSPat2F5+BAnIqKsePggd3Gubf2wH5efWZl7NO+vgQ0NIhW EFbf9X+wSgXAYfnys67dOq1XqzY3mpq/261l8TxHT9FDWQs8Rv+PdgwYt7Gl1vMZProW yjMA== X-Forwarded-Encrypted: i=1; AJvYcCXCsoTg1SIshthKu21qdpjSWE3+uRRqQUce0Its0o775WD2H7MHWffIT5DvkIJq6uU+dos+2TdF6G9izYQ+MQI2@lists.infradead.org X-Gm-Message-State: AOJu0Yx+B7xC+x45h50D/5cbXSUQkfzXi1mritbBZ0cbuT+450ObuVEX H/0kBTKrfVpP01SHE1i+ESLqfmd9MvjDKKxy/qIKoVPhsPkkLcfWsYa4sMCKKfg= X-Google-Smtp-Source: AGHT+IG0pGKyFxhUYIZxyizCprVXeOYwV9O/Cu8dGummQjlPHaKWHg/LIgIEa0ORW9lyqscxBKa+0Q== X-Received: by 2002:a05:600c:4f42:b0:427:d713:a5d3 with SMTP id 5b1f17b1804b1-42bb02eb478mr125076105e9.11.1725358840072; Tue, 03 Sep 2024 03:20:40 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:20:39 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Athira Rajeev , Dominique Martinet , Colin Ian King , Yang Jihong , Howard Chu , Ze Gao , Yunseong Kim , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/7] perf evsel: Add alternate_hw_config and use in evsel__match Date: Tue, 3 Sep 2024 11:19:45 +0100 Message-Id: <20240903102005.78049-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032042_510002_30F24A7B X-CRM114-Status: GOOD ( 24.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers There are cases where we want to match events like instructions and cycles with legacy hardware values, in particular in stat-shadow's hard coded metrics. An evsel's name isn't a good point of reference as it gets altered, strstr would be too imprecise and re-parsing the event from its name is silly. Instead, hold the legacy hardware event name, determined during parsing, in the evsel for this matching case. Inline evsel__match2 that is only used in builtin-diff. Signed-off-by: Ian Rogers Signed-off-by: James Clark --- tools/perf/builtin-diff.c | 6 ++-- tools/perf/util/evsel.c | 21 +++++++++++++ tools/perf/util/evsel.h | 19 ++---------- tools/perf/util/parse-events.c | 57 +++++++++++++++++++++------------- tools/perf/util/parse-events.h | 8 ++++- tools/perf/util/parse-events.y | 2 +- tools/perf/util/pmu.c | 6 +++- tools/perf/util/pmu.h | 2 +- 8 files changed, 76 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 23326dd20333..82fb7773e03e 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -469,13 +469,13 @@ static int diff__process_sample_event(const struct perf_tool *tool, static struct perf_diff pdiff; -static struct evsel *evsel_match(struct evsel *evsel, - struct evlist *evlist) +static struct evsel *evsel_match(struct evsel *evsel, struct evlist *evlist) { struct evsel *e; evlist__for_each_entry(evlist, e) { - if (evsel__match2(evsel, e)) + if ((evsel->core.attr.type == e->core.attr.type) && + (evsel->core.attr.config == e->core.attr.config)) return e; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 49cc71511c0c..2928c1f76dad 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -299,6 +299,7 @@ void evsel__init(struct evsel *evsel, evsel->pmu_name = NULL; evsel->group_pmu_name = NULL; evsel->skippable = false; + evsel->alternate_hw_config = PERF_COUNT_HW_MAX; } struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx) @@ -445,6 +446,8 @@ struct evsel *evsel__clone(struct evsel *orig) if (evsel__copy_config_terms(evsel, orig) < 0) goto out_err; + evsel->alternate_hw_config = orig->alternate_hw_config; + return evsel; out_err: @@ -1845,6 +1848,24 @@ static int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread) return 0; } +bool __evsel__match(const struct evsel *evsel, u32 type, u64 config) +{ + + u32 e_type = evsel->core.attr.type; + u64 e_config = evsel->core.attr.config; + + if (e_type != type) { + return type == PERF_TYPE_HARDWARE && evsel->pmu && evsel->pmu->is_core && + evsel->alternate_hw_config == config; + } + + if ((type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) && + perf_pmus__supports_extended_type()) + e_config &= PERF_HW_EVENT_MASK; + + return e_config == config; +} + int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 15acf293e12a..430441fdfbbc 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -102,6 +102,7 @@ struct evsel { int bpf_fd; struct bpf_object *bpf_obj; struct list_head config_terms; + u64 alternate_hw_config; }; /* @@ -388,26 +389,10 @@ u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sam struct tep_format_field *evsel__field(struct evsel *evsel, const char *name); struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *name); -static inline bool __evsel__match(const struct evsel *evsel, u32 type, u64 config) -{ - if (evsel->core.attr.type != type) - return false; - - if ((type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) && - perf_pmus__supports_extended_type()) - return (evsel->core.attr.config & PERF_HW_EVENT_MASK) == config; - - return evsel->core.attr.config == config; -} +bool __evsel__match(const struct evsel *evsel, u32 type, u64 config); #define evsel__match(evsel, t, c) __evsel__match(evsel, PERF_TYPE_##t, PERF_COUNT_##c) -static inline bool evsel__match2(struct evsel *e1, struct evsel *e2) -{ - return (e1->core.attr.type == e2->core.attr.type) && - (e1->core.attr.config == e2->core.attr.config); -} - int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread); int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread, bool scale); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index fab01ba54e34..d1355e492df3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -227,7 +227,7 @@ __add_event(struct list_head *list, int *idx, bool init_attr, const char *name, const char *metric_id, struct perf_pmu *pmu, struct list_head *config_terms, bool auto_merge_stats, - const char *cpu_list) + const char *cpu_list, u64 alternate_hw_config) { struct evsel *evsel; struct perf_cpu_map *cpus = pmu ? perf_cpu_map__get(pmu->cpus) : @@ -263,6 +263,7 @@ __add_event(struct list_head *list, int *idx, evsel->auto_merge_stats = auto_merge_stats; evsel->pmu = pmu; evsel->pmu_name = pmu ? strdup(pmu->name) : NULL; + evsel->alternate_hw_config = alternate_hw_config; if (name) evsel->name = strdup(name); @@ -285,16 +286,19 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, { return __add_event(/*list=*/NULL, &idx, attr, /*init_attr=*/false, name, metric_id, pmu, /*config_terms=*/NULL, - /*auto_merge_stats=*/false, /*cpu_list=*/NULL); + /*auto_merge_stats=*/false, /*cpu_list=*/NULL, + /*alternate_hw_config=*/PERF_COUNT_HW_MAX); } static int add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, const char *name, - const char *metric_id, struct list_head *config_terms) + const char *metric_id, struct list_head *config_terms, + u64 alternate_hw_config) { return __add_event(list, idx, attr, /*init_attr*/true, name, metric_id, /*pmu=*/NULL, config_terms, - /*auto_merge_stats=*/false, /*cpu_list=*/NULL) ? 0 : -ENOMEM; + /*auto_merge_stats=*/false, /*cpu_list=*/NULL, + alternate_hw_config) ? 0 : -ENOMEM; } static int add_event_tool(struct list_head *list, int *idx, @@ -314,7 +318,9 @@ static int add_event_tool(struct list_head *list, int *idx, evsel = __add_event(list, idx, &attr, /*init_attr=*/true, /*name=*/NULL, /*metric_id=*/NULL, /*pmu=*/NULL, /*config_terms=*/NULL, /*auto_merge_stats=*/false, - cpu_list); + cpu_list, + /*alternate_hw_config=*/PERF_COUNT_HW_MAX); + if (!evsel) return -ENOMEM; evsel->tool_event = tool_event; @@ -448,7 +454,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, static int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, struct perf_pmu *pmu, const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats); + bool auto_merge_stats, u64 alternate_hw_config); int parse_events_add_cache(struct list_head *list, int *idx, const char *name, struct parse_events_state *parse_state, @@ -474,7 +480,8 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name, */ ret = parse_events_add_pmu(parse_state, list, pmu, parsed_terms, - perf_pmu__auto_merge_stats(pmu)); + perf_pmu__auto_merge_stats(pmu), + /*alternate_hw_config=*/PERF_COUNT_HW_MAX); if (ret) return ret; continue; @@ -505,7 +512,8 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name, if (__add_event(list, idx, &attr, /*init_attr*/true, config_name ?: name, metric_id, pmu, &config_terms, /*auto_merge_stats=*/false, - /*cpu_list=*/NULL) == NULL) + /*cpu_list=*/NULL, + /*alternate_hw_config=*/PERF_COUNT_HW_MAX) == NULL) return -ENOMEM; free_config_terms(&config_terms); @@ -750,7 +758,7 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state, name = get_config_name(head_config); return add_event(list, &parse_state->idx, &attr, name, /*mertic_id=*/NULL, - &config_terms); + &config_terms, /*alternate_hw_config=*/PERF_COUNT_HW_MAX); } static int check_type_val(struct parse_events_term *term, @@ -1050,6 +1058,7 @@ static int config_term_pmu(struct perf_event_attr *attr, if (perf_pmu__have_event(pmu, term->config)) { term->type_term = PARSE_EVENTS__TERM_TYPE_USER; term->no_value = true; + term->alternate_hw_config = true; } else { attr->type = PERF_TYPE_HARDWARE; attr->config = term->val.num; @@ -1362,8 +1371,9 @@ static int __parse_events_add_numeric(struct parse_events_state *parse_state, name = get_config_name(head_config); metric_id = get_config_metric_id(head_config); ret = __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, name, - metric_id, pmu, &config_terms, /*auto_merge_stats=*/false, - /*cpu_list=*/NULL) ? 0 : -ENOMEM; + metric_id, pmu, &config_terms, /*auto_merge_stats=*/false, + /*cpu_list=*/NULL, /*alternate_hw_config=*/PERF_COUNT_HW_MAX + ) == NULL ? -ENOMEM : 0; free_config_terms(&config_terms); return ret; } @@ -1421,7 +1431,7 @@ static bool config_term_percore(struct list_head *config_terms) static int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, struct perf_pmu *pmu, const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats) + bool auto_merge_stats, u64 alternate_hw_config) { struct perf_event_attr attr; struct perf_pmu_info info; @@ -1458,7 +1468,7 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, /*init_attr=*/true, /*name=*/NULL, /*metric_id=*/NULL, pmu, /*config_terms=*/NULL, auto_merge_stats, - /*cpu_list=*/NULL); + /*cpu_list=*/NULL, alternate_hw_config); return evsel ? 0 : -ENOMEM; } @@ -1479,7 +1489,8 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, /* Look for event names in the terms and rewrite into format based terms. */ if (!parse_state->fake_pmu && perf_pmu__check_alias(pmu, &parsed_terms, - &info, &alias_rewrote_terms, err)) { + &info, &alias_rewrote_terms, + &alternate_hw_config, err)) { parse_events_terms__exit(&parsed_terms); return -EINVAL; } @@ -1525,7 +1536,8 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, evsel = __add_event(list, &parse_state->idx, &attr, /*init_attr=*/true, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, - &config_terms, auto_merge_stats, /*cpu_list=*/NULL); + &config_terms, auto_merge_stats, /*cpu_list=*/NULL, + alternate_hw_config); if (!evsel) { parse_events_terms__exit(&parsed_terms); return -ENOMEM; @@ -1551,7 +1563,7 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, } int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, + const char *event_name, u64 hw_config, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc_) { @@ -1604,7 +1616,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, auto_merge_stats = perf_pmu__auto_merge_stats(pmu); if (!parse_events_add_pmu(parse_state, list, pmu, - &parsed_terms, auto_merge_stats)) { + &parsed_terms, auto_merge_stats, hw_config)) { struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); @@ -1617,7 +1629,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, if (parse_state->fake_pmu) { if (!parse_events_add_pmu(parse_state, list, parse_state->fake_pmu, &parsed_terms, - /*auto_merge_stats=*/true)) { + /*auto_merge_stats=*/true, hw_config)) { struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); @@ -1658,7 +1670,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state /* Attempt to add to list assuming event_or_pmu is a PMU name. */ pmu = parse_state->fake_pmu ?: perf_pmus__find(event_or_pmu); if (pmu && !parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, - /*auto_merge_stats=*/false)) + /*auto_merge_stats=*/false, + /*alternate_hw_config=*/PERF_COUNT_HW_MAX)) return 0; pmu = NULL; @@ -1670,7 +1683,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, - auto_merge_stats)) { + auto_merge_stats, + /*alternate_hw_config=*/PERF_COUNT_HW_MAX)) { ok++; parse_state->wild_card_pmus = true; } @@ -1681,7 +1695,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state /* Failure to add, assume event_or_pmu is an event name. */ zfree(listp); - if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, const_parsed_terms, listp, loc)) + if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, PERF_COUNT_HW_MAX, + const_parsed_terms, listp, loc)) return 0; if (asprintf(&help, "Unable to find PMU or event on a PMU of '%s'", event_or_pmu) < 0) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index b735cd9e0acf..703cb6d9f970 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -127,6 +127,12 @@ struct parse_events_term { * value is assumed to be 1. An event name also has no value. */ bool no_value; + /** + * @alternate_hw_config: config is the event name but num is an + * alternate PERF_TYPE_HARDWARE config value which is often nice for the + * sake of quick matching. + */ + bool alternate_hw_config; }; struct parse_events_error { @@ -238,7 +244,7 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, struct perf_pmu *pmu); int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, + const char *event_name, u64 hw_config, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index b3c51f06cbdc..dcf47fabdfdd 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -292,7 +292,7 @@ PE_NAME sep_dc struct list_head *list; int err; - err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); + err = parse_events_multi_pmu_add(_parse_state, $1, PERF_COUNT_HW_MAX, NULL, &list, &@1); if (err < 0) { struct parse_events_state *parse_state = _parse_state; struct parse_events_error *error = parse_state->error; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0b38c51bd6eb..6f3ca69b71f1 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1602,7 +1602,7 @@ static int check_info_data(struct perf_pmu *pmu, */ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_terms, struct perf_pmu_info *info, bool *rewrote_terms, - struct parse_events_error *err) + u64 *alternate_hw_config, struct parse_events_error *err) { struct parse_events_term *term, *h; struct perf_pmu_alias *alias; @@ -1630,6 +1630,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_ NULL); return ret; } + *rewrote_terms = true; ret = check_info_data(pmu, alias, info, err, term->err_term); if (ret) @@ -1638,6 +1639,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_ if (alias->per_pkg) info->per_pkg = true; + if (term->alternate_hw_config) + *alternate_hw_config = term->val.num; + list_del_init(&term->list); parse_events_term__delete(term); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b2d3fd291f02..b5f65b705a1e 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -213,7 +213,7 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name); int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_terms, struct perf_pmu_info *info, bool *rewrote_terms, - struct parse_events_error *err); + u64 *alternate_hw_config, struct parse_events_error *err); int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb); void perf_pmu_format__set_value(void *format, int config, unsigned long *bits); From patchwork Tue Sep 3 10:19:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5846ECD3420 for ; Tue, 3 Sep 2024 10:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=FJ74+rjJNTGavuZ/TkbyW3SAdk TKqcUwuaHh8f4P0k9WjT74XhcavMaFgy9bkPW+IhwGXRpTp0XqWh3qLEyhgSRMKsplHRhdyFky1YB 3+pLwIIOo/793pn6HR5x7gkA8fxRRH7P0m+tg96+acJo9OquzRFbqsnLR8hltrmFU2k12Sl3kN8HT 1V8pLVYmCyxKsFj+gpYNqewIWP/WrgMwtr7hoe2fqKDSi97EeJF/idccDFtOOS1n+h/ZI++2XquEO Qw+rl8c9h8DmBAkKj02HC3rXTvc85p2lciCVVXaO9Av8Bg9lKK8M1HDkB0EpAfg0h75xcphOq+gL1 IRTYdjIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQhV-0000000HKPp-1GIV; Tue, 03 Sep 2024 10:23:53 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQef-0000000HJlL-3LG9 for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:20:59 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42bfb50e4e6so26189735e9.2 for ; Tue, 03 Sep 2024 03:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358856; x=1725963656; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=SUUBYbAde8cY0dOkHjwXBg43Oj3VurM3L+yok8sLJGlh2UndhjlXXFIjTrRG6pnpdz FbxSF5XVU24gBCmhtxYNfe93ItbkNvO13mNogO8zVW4vQJqR2RuaLErJVP225CVkm+BN NBFIvnJ60Myel5sVGhzJmBFxN5pcOWEg61BmGWkeJu9p6fqHv2KLcZsWRhDfVGZPzF/9 boPHzIN+rc/jt9aWDcGK1nJ83C5l5b/GEp73PFVDUoVydX2IUjartHWyjbpcOahsRO14 m61H/J5ReBgEO9GhyWNmw1Dl96Vjby4GRZmTBn2/wIZkHWpcQmnjfcPCrgtUdayzzHGv Q83g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358856; x=1725963656; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmc4eZ9qHbt1Etu8s5seKQefOAgzMufznEYvpOOaJRM=; b=W1WbpVSkVod7nEpq7n/0hzpJARu31SDWDNdUZAJlFNZAsE/ngmoGr45FvvDvw4BRru 7y7y+RPkX9XdH7b2AcKUJnUiRifBut4ZwPx2/ktxZtwWVDK4CK+/7PZIoK3tm42VA/kz qabrszFoa4e2laGaqFo6y6QIReonlHoZ2N6gNrKORgNzrIQtrjMsU0dMtaXiYz/rDa/z 637YoI1WuirryrP4qgFhSGP21uZthcEm//5tWaheeB2r/G8He2sJzv4t5p64ZY3zjmYt ma0b27VWEvc7dl5oB77U59QvWmRrDqKzQwQpiqap0kpYMnmyu0vRMvd1DO1/Mnki+U++ oFzA== X-Forwarded-Encrypted: i=1; AJvYcCX0i6ScbZYOMn2Obiexvj01tzyWjRSd5HZVdX7OJVgL2/+U91jmcWZWRGtzPll5slW9IHq9xfcByPFDgdAfjWA7@lists.infradead.org X-Gm-Message-State: AOJu0Yw4BMyojXntLBMgaVclNJOhH5R5Sqehc3iNwaJuYBVYkY6Uhiba 2cvbzdDUwY90gYJZCpRlmuALV1daQzO4yzyERVYj/ycLcYOXT/Mk0DdpQPdo8lU= X-Google-Smtp-Source: AGHT+IE7jzBD0pen5jDyTCNz7CgnW3/+BQRVINjMUCPDbK9LMa8UAc+AQGFy3tQ7x/fhG2OyC3gxqg== X-Received: by 2002:a05:600c:3104:b0:42b:a88f:f872 with SMTP id 5b1f17b1804b1-42bb27ba51bmr148445495e9.32.1725358855724; Tue, 03 Sep 2024 03:20:55 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:20:55 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Athira Rajeev , Colin Ian King , Yang Jihong , Howard Chu , Ze Gao , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 2/7] perf stat: Uniquify event name improvements Date: Tue, 3 Sep 2024 11:19:46 +0100 Message-Id: <20240903102005.78049-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032057_888428_6EEBE631 X-CRM114-Status: GOOD ( 25.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers Without aggregation on Intel: ``` $ perf stat -e instructions,cycles ... ``` Will use "cycles" for the name of the legacy cycles event but as "instructions" has a sysfs name it will and a "[cpu]" PMU suffix. This often breaks things as the space between the event and the PMU name look like an extra column. The existing uniquify logic was also uniquifying in cases when all events are core and not with uncore events, it was not correctly handling modifiers, etc. Change the logic so that an initial pass that can disable uniquification is run. For individual counters, disable uniquification in more cases such as for consistency with legacy events or for libpfm4 events. Don't use the "[pmu]" style suffix in uniquification, always use "pmu/.../". Change how modifiers/terms are handled in the uniquification so that they look like parse-able events. This fixes "102: perf stat metrics (shadow stat) test:" that has been failing due to "instructions [cpu]" breaking its column/awk logic when values aren't aggregated. This started happening when instructions could match a sysfs rather than a legacy event, so the fixes tag reflects this. Fixes: 617824a7f0f7 ("perf parse-events: Prefer sysfs/JSON hardware events over legacy") Signed-off-by: Ian Rogers [ Fix Intel TPEBS counting mode test ] Signed-off-by: James Clark --- .../perf/tests/shell/test_stat_intel_tpebs.sh | 11 +- tools/perf/util/stat-display.c | 101 ++++++++++++++---- 2 files changed, 85 insertions(+), 27 deletions(-) diff --git a/tools/perf/tests/shell/test_stat_intel_tpebs.sh b/tools/perf/tests/shell/test_stat_intel_tpebs.sh index c60b29add980..9a11f42d153c 100755 --- a/tools/perf/tests/shell/test_stat_intel_tpebs.sh +++ b/tools/perf/tests/shell/test_stat_intel_tpebs.sh @@ -8,12 +8,15 @@ grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel; exit 2; } # Use this event for testing because it should exist in all platforms event=cache-misses:R +# Hybrid platforms output like "cpu_atom/cache-misses/R", rather than as above +alt_name=/cache-misses/R + # Without this cmd option, default value or zero is returned -echo "Testing without --record-tpebs" -result=$(perf stat -e "$event" true 2>&1) -[[ "$result" =~ $event ]] || exit 1 +#echo "Testing without --record-tpebs" +#result=$(perf stat -e "$event" true 2>&1) +#[[ "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1 # In platforms that do not support TPEBS, it should execute without error. echo "Testing with --record-tpebs" result=$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1) -[[ "$result" =~ "perf record" && "$result" =~ $event ]] || exit 1 +[[ "$result" =~ "perf record" && "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ea96e4ebad8c..cbff43ff8d0f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -871,38 +871,66 @@ static void printout(struct perf_stat_config *config, struct outstate *os, static void uniquify_event_name(struct evsel *counter) { - char *new_name; - char *config; - int ret = 0; + const char *name, *pmu_name; + char *new_name, *config; + int ret; - if (counter->uniquified_name || counter->use_config_name || - !counter->pmu_name || !strncmp(evsel__name(counter), counter->pmu_name, - strlen(counter->pmu_name))) + /* The evsel was already uniquified. */ + if (counter->uniquified_name) return; - config = strchr(counter->name, '/'); + /* Avoid checking to uniquify twice. */ + counter->uniquified_name = true; + + /* The evsel has a "name=" config term or is from libpfm. */ + if (counter->use_config_name || counter->is_libpfm_event) + return; + + /* Legacy no PMU event, don't uniquify. */ + if (!counter->pmu || + (counter->pmu->type < PERF_TYPE_MAX && counter->pmu->type != PERF_TYPE_RAW)) + return; + + /* A sysfs or json event replacing a legacy event, don't uniquify. */ + if (counter->pmu->is_core && counter->alternate_hw_config != PERF_COUNT_HW_MAX) + return; + + name = evsel__name(counter); + pmu_name = counter->pmu->name; + /* Already prefixed by the PMU name. */ + if (!strncmp(name, pmu_name, strlen(pmu_name))) + return; + + config = strchr(name, '/'); if (config) { - if (asprintf(&new_name, - "%s%s", counter->pmu_name, config) > 0) { - free(counter->name); - counter->name = new_name; - } - } else { - if (evsel__is_hybrid(counter)) { - ret = asprintf(&new_name, "%s/%s/", - counter->pmu_name, counter->name); + int len = config - name; + + if (config[1] == '/') { + /* case: event// */ + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 2); } else { - ret = asprintf(&new_name, "%s [%s]", - counter->name, counter->pmu_name); + /* case: event/.../ */ + ret = asprintf(&new_name, "%s/%.*s,%s", pmu_name, len, name, config + 1); } + } else { + config = strchr(name, ':'); + if (config) { + /* case: event:.. */ + int len = config - name; - if (ret) { - free(counter->name); - counter->name = new_name; + ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 1); + } else { + /* case: event */ + ret = asprintf(&new_name, "%s/%s/", pmu_name, name); } } - - counter->uniquified_name = true; + if (ret > 0) { + free(counter->name); + counter->name = new_name; + } else { + /* ENOMEM from asprintf. */ + counter->uniquified_name = false; + } } static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) @@ -1559,6 +1587,31 @@ static void print_cgroup_counter(struct perf_stat_config *config, struct evlist print_metric_end(config, os); } +static void disable_uniquify(struct evlist *evlist) +{ + struct evsel *counter; + struct perf_pmu *last_pmu = NULL; + bool first = true; + + evlist__for_each_entry(evlist, counter) { + /* If PMUs vary then uniquify can be useful. */ + if (!first && counter->pmu != last_pmu) + return; + first = false; + if (counter->pmu) { + /* Allow uniquify for uncore PMUs. */ + if (!counter->pmu->is_core) + return; + /* Keep hybrid event names uniquified for clarity. */ + if (perf_pmus__num_core_pmus() > 1) + return; + } + } + evlist__for_each_entry_continue(evlist, counter) { + counter->uniquified_name = true; + } +} + void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, struct target *_target, struct timespec *ts, int argc, const char **argv) @@ -1572,6 +1625,8 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf .first = true, }; + disable_uniquify(evlist); + if (config->iostat_run) evlist->selected = evlist__first(evlist); From patchwork Tue Sep 3 10:19:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65E66CD3420 for ; Tue, 3 Sep 2024 10:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=i9l4tHuN7t4SNI6YhNdSB1M28rsHs7Kzf+ol95+ep+0=; b=dgJJMRdn3Xegfwbt4UwEZn31rF YCj8AmQYsSKObn3r75SsN8gJ+H/c5vyoB00rApMLoRvgNQJBiq9gHU3zX9+OaZ27ssubHoN2s6d5u PnmVpWhe5LUUAi3zCFgvFdZOAafR9YQiEBKpey4A2d8rx3jDgBvani38WySsYkRKHJAhQdg2TID/e T2rwD0BmY31RrGjCtuOtDzTn7OgrEjbRpxjyyn62ppHM1CY0HP7GYzn1Mq4OGzgLjG1jzFNYEt+fD UxC3+dr8QPaxkqDABUCrEe3ys884obki5wbXrUIKVkfdq+62ZmJifG8bNDZ4mkr4sPpbVdwXjoH9f v3Yv4/Xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQiO-0000000HKcL-2rDz; Tue, 03 Sep 2024 10:24:48 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQev-0000000HJqr-3Abj for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:21:16 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42bb7298bdeso57430175e9.1 for ; Tue, 03 Sep 2024 03:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358872; x=1725963672; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i9l4tHuN7t4SNI6YhNdSB1M28rsHs7Kzf+ol95+ep+0=; b=YGBr7y8uu/6xqL9amjWXiXo+GfjVhbkM7AXLS2sa6ky6+B3/GRm22ruziOyKnm4xsV VVm5a5fzOUozuyyIIFWNkO915BrkZJXlPRbyr866PaLhWJ+z8LOipbqW91PCUB2LHBts Rf45X9VWJfjF1tZMPX77hfeODZagcynxevVS4Lc8KTkD3ovx03M8ghvdCXl9l/0aXbTU QCe6JAJxK3ejRbBlQpXZnC6vP+Vj2EOHUk6a4jYBUxtaND5oLQuqluCaHXDsV+8OqxPj jIbwcxLAWs9h1O14oH6Gn43e2p3oQmmClX5kms1okTcIf4h2MuQcmWIqVxKRR3dlGLrj w3kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358872; x=1725963672; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i9l4tHuN7t4SNI6YhNdSB1M28rsHs7Kzf+ol95+ep+0=; b=OJYg6MT84IzquR0Rvd+Cb7j0z179VcxpfL9w9cUa1dQzSVtxIld8VSu+1CqmM2OTq2 4sHktceXFxJ7BmQNxGXJoESsyVDcYmsuLgp0bNsaOQBZyI0C0aKY9e4H29b0jhoBGrwA MU3DOgkNp2vslqq1xjfJw95YSmM2cdIdrclfOKM8gEA/vP3bkT5OcW3LSzpnCzp7bZZ/ LByM/D9O2tUrm9sp9FQxOkVl/jnVaPlY2N3RDiMFnwpijuxH0E/ltdf5kkCSKf51PuCA ONy5zPgK4u3NYqERTn814cJ8Azi793s0eEXWZUkm9Benox0WsQK/f6i++g0/EzKxb/3S wTwQ== X-Forwarded-Encrypted: i=1; AJvYcCWM3DnIztLky6u42w0D8hNT1LHb8/6DOjr1ZCVbqeMjE+OR9KFSrSl4YckUnQSPXJy6jUzeSYQ2g3Jm/slI8+yc@lists.infradead.org X-Gm-Message-State: AOJu0Yyuhfs4qqRpQOP6G+HKitHiQYxHOOx0SQHtYTEYWvTpBFeVwUlV 9eMkuWagdfxDB4VGXUgIxYE6LOWv24/iQUD1dwVu7g4j8Im8zqOhWujMCTq4niY= X-Google-Smtp-Source: AGHT+IH/AFRrH5kob7O8JXCX+Hj9posF1UFR0zTfkJP4Gd6atiSHi6A0vzZOqSRlRu5HAegKd/vC1Q== X-Received: by 2002:a05:600c:3b99:b0:426:62c5:4731 with SMTP id 5b1f17b1804b1-42bb01edd20mr150240375e9.29.1725358871867; Tue, 03 Sep 2024 03:21:11 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:21:11 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Colin Ian King , Athira Rajeev , Yang Jihong , Howard Chu , Ze Gao , Yunseong Kim , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/7] perf stat: Remove evlist__add_default_attrs use strings Date: Tue, 3 Sep 2024 11:19:47 +0100 Message-Id: <20240903102005.78049-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032113_950311_4CBEE57A X-CRM114-Status: GOOD ( 26.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers add_default_atttributes would add evsels by having pre-created perf_event_attr, however, this needed fixing for hybrid as the extended PMU type was necessary for each core PMU. The logic for this was in an arch specific x86 function and wasn't present for ARM, meaning that default events weren't being opened on all PMUs on ARM. Change the creation of the default events to use parse_events and strings as that will open the events on all PMUs. Rather than try to detect events on PMUs before parsing, parse the event but skip its output in stat-display. The previous order of hardware events was: cycles, stalled-cycles-frontend, stalled-cycles-backend, instructions. As instructions is a more fundamental concept the order is changed to: instructions, cycles, stalled-cycles-frontend, stalled-cycles-backend. Closes: https://lore.kernel.org/lkml/CAP-5=fVABSBZnsmtRn1uF-k-G1GWM-L5SgiinhPTfHbQsKXb_g@mail.gmail.com/ Signed-off-by: Ian Rogers [Don't display unsupported default events] Signed-off-by: James Clark --- tools/perf/arch/x86/util/evlist.c | 74 +------- tools/perf/builtin-stat.c | 291 ++++++++++++------------------ tools/perf/util/evlist.c | 43 ----- tools/perf/util/evlist.h | 12 -- tools/perf/util/stat-display.c | 8 + tools/perf/util/stat-shadow.c | 4 +- 6 files changed, 125 insertions(+), 307 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/evlist.c index cebdd483149e..3a4bf13b1759 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -1,78 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include "util/pmu.h" -#include "util/pmus.h" -#include "util/evlist.h" -#include "util/parse-events.h" -#include "util/event.h" +#include +#include "../../../util/evlist.h" +#include "../../../util/evsel.h" #include "topdown.h" #include "evsel.h" -static int ___evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - LIST_HEAD(head); - size_t i = 0; - - for (i = 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - if (perf_pmus__num_core_pmus() == 1) - return evlist__add_attrs(evlist, attrs, nr_attrs); - - for (i = 0; i < nr_attrs; i++) { - struct perf_pmu *pmu = NULL; - - if (attrs[i].type == PERF_TYPE_SOFTWARE) { - struct evsel *evsel = evsel__new(attrs + i); - - if (evsel == NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - continue; - } - - while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { - struct perf_cpu_map *cpus; - struct evsel *evsel; - - evsel = evsel__new(attrs + i); - if (evsel == NULL) - goto out_delete_partial_list; - evsel->core.attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; - cpus = perf_cpu_map__get(pmu->cpus); - evsel->core.cpus = cpus; - evsel->core.own_cpus = perf_cpu_map__get(cpus); - evsel->pmu_name = strdup(pmu->name); - list_add_tail(&evsel->core.node, &head); - } - } - - evlist__splice_list_tail(evlist, &head); - - return 0; - -out_delete_partial_list: - { - struct evsel *evsel, *n; - - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); - } - return -1; -} - -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - if (!nr_attrs) - return 0; - - return ___evlist__add_default_attrs(evlist, attrs, nr_attrs); -} - int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs) { if (topdown_sys_has_perf_metrics() && diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cf985cdb9a6e..6302822853b0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1814,130 +1814,25 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) } /* - * Add default attributes, if there were no attributes specified or + * Add default events, if there were no attributes specified or * if -d/--detailed, -d -d or -d -d -d is used: */ -static int add_default_attributes(void) +static int add_default_events(void) { - struct perf_event_attr default_attrs0[] = { - - { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK }, - { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES }, - { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS }, - { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS }, - - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES }, -}; - struct perf_event_attr frontend_attrs[] = { - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, -}; - struct perf_event_attr backend_attrs[] = { - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND }, -}; - struct perf_event_attr default_attrs1[] = { - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS }, - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, - { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES }, - -}; - -/* - * Detailed stats (-d), covering the L1 and last level data caches: - */ - struct perf_event_attr detailed_attrs[] = { - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_LL << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_LL << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, -}; - -/* - * Very detailed stats (-d -d), covering the instruction cache and the TLB caches: - */ - struct perf_event_attr very_detailed_attrs[] = { - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - -}; + const char *pmu = parse_events_option_args.pmu_filter ?: "all"; + struct parse_events_error err; + struct evlist *evlist = evlist__new(); + struct evsel *evsel; + int ret = 0; -/* - * Very, very detailed stats (-d -d -d), adding prefetch events: - */ - struct perf_event_attr very_very_detailed_attrs[] = { - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type = PERF_TYPE_HW_CACHE, - .config = - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, -}; + if (!evlist) + return -ENOMEM; - struct perf_event_attr default_null_attrs[] = {}; - const char *pmu = parse_events_option_args.pmu_filter ?: "all"; + parse_events_error__init(&err); /* Set attrs if no event is selected and !null_run: */ if (stat_config.null_run) - return 0; + goto out; if (transaction_run) { /* Handle -T as -M transaction. Once platform specific metrics @@ -1947,9 +1842,10 @@ static int add_default_attributes(void) */ if (!metricgroup__has_metric(pmu, "transaction")) { pr_err("Missing transaction metrics\n"); - return -1; + ret = -1; + goto out; } - return metricgroup__parse_groups(evsel_list, pmu, "transaction", + ret = metricgroup__parse_groups(evlist, pmu, "transaction", stat_config.metric_no_group, stat_config.metric_no_merge, stat_config.metric_no_threshold, @@ -1957,6 +1853,7 @@ static int add_default_attributes(void) stat_config.system_wide, stat_config.hardware_aware_grouping, &stat_config.metric_events); + goto out; } if (smi_cost) { @@ -1964,26 +1861,29 @@ static int add_default_attributes(void) if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) { pr_err("freeze_on_smi is not supported.\n"); - return -1; + ret = -1; + goto out; } if (!smi) { if (sysfs__write_int(FREEZE_ON_SMI_PATH, 1) < 0) { - fprintf(stderr, "Failed to set freeze_on_smi.\n"); - return -1; + pr_err("Failed to set freeze_on_smi.\n"); + ret = -1; + goto out; } smi_reset = true; } if (!metricgroup__has_metric(pmu, "smi")) { pr_err("Missing smi metrics\n"); - return -1; + ret = -1; + goto out; } if (!force_metric_only) stat_config.metric_only = true; - return metricgroup__parse_groups(evsel_list, pmu, "smi", + ret = metricgroup__parse_groups(evlist, pmu, "smi", stat_config.metric_no_group, stat_config.metric_no_merge, stat_config.metric_no_threshold, @@ -1991,6 +1891,7 @@ static int add_default_attributes(void) stat_config.system_wide, stat_config.hardware_aware_grouping, &stat_config.metric_events); + goto out; } if (topdown_run) { @@ -2003,21 +1904,23 @@ static int add_default_attributes(void) if (!max_level) { pr_err("Topdown requested but the topdown metric groups aren't present.\n" "(See perf list the metric groups have names like TopdownL1)\n"); - return -1; + ret = -1; + goto out; } if (stat_config.topdown_level > max_level) { pr_err("Invalid top-down metrics level. The max level is %u.\n", max_level); - return -1; - } else if (!stat_config.topdown_level) + ret = -1; + goto out; + } else if (!stat_config.topdown_level) { stat_config.topdown_level = 1; - + } if (!stat_config.interval && !stat_config.metric_only) { fprintf(stat_config.output, "Topdown accuracy may decrease when measuring long periods.\n" "Please print the result regularly, e.g. -I1000\n"); } str[8] = stat_config.topdown_level + '0'; - if (metricgroup__parse_groups(evsel_list, + if (metricgroup__parse_groups(evlist, pmu, str, /*metric_no_group=*/false, /*metric_no_merge=*/false, @@ -2025,41 +1928,49 @@ static int add_default_attributes(void) stat_config.user_requested_cpu_list, stat_config.system_wide, stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) - return -1; + &stat_config.metric_events) < 0) { + ret = -1; + goto out; + } } if (!stat_config.topdown_level) stat_config.topdown_level = 1; - if (!evsel_list->core.nr_entries) { + if (!evlist->core.nr_entries && !evsel_list->core.nr_entries) { /* No events so add defaults. */ if (target__has_cpu(&target)) - default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK; + ret = parse_events(evlist, "cpu-clock", &err); + else + ret = parse_events(evlist, "task-clock", &err); + if (ret) + goto out; + + ret = parse_events(evlist, + "context-switches," + "cpu-migrations," + "page-faults," + "instructions," + "cycles," + "stalled-cycles-frontend," + "stalled-cycles-backend," + "branches," + "branch-misses", + &err); + if (ret) + goto out; - if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0) - return -1; - if (perf_pmus__have_event("cpu", "stalled-cycles-frontend")) { - if (evlist__add_default_attrs(evsel_list, frontend_attrs) < 0) - return -1; - } - if (perf_pmus__have_event("cpu", "stalled-cycles-backend")) { - if (evlist__add_default_attrs(evsel_list, backend_attrs) < 0) - return -1; - } - if (evlist__add_default_attrs(evsel_list, default_attrs1) < 0) - return -1; /* * Add TopdownL1 metrics if they exist. To minimize * multiplexing, don't request threshold computation. */ if (metricgroup__has_metric(pmu, "Default")) { struct evlist *metric_evlist = evlist__new(); - struct evsel *metric_evsel; - - if (!metric_evlist) - return -1; + if (!metric_evlist) { + ret = -ENOMEM; + goto out; + } if (metricgroup__parse_groups(metric_evlist, pmu, "Default", /*metric_no_group=*/false, /*metric_no_merge=*/false, @@ -2067,43 +1978,65 @@ static int add_default_attributes(void) stat_config.user_requested_cpu_list, stat_config.system_wide, stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) - return -1; - - evlist__for_each_entry(metric_evlist, metric_evsel) { - metric_evsel->skippable = true; - metric_evsel->default_metricgroup = true; + &stat_config.metric_events) < 0) { + ret = -1; + goto out; } - evlist__splice_list_tail(evsel_list, &metric_evlist->core.entries); + + evlist__for_each_entry(metric_evlist, evsel) + evsel->default_metricgroup = true; + + evlist__splice_list_tail(evlist, &metric_evlist->core.entries); evlist__delete(metric_evlist); } - - /* Platform specific attrs */ - if (evlist__add_default_attrs(evsel_list, default_null_attrs) < 0) - return -1; } /* Detailed events get appended to the event list: */ - if (detailed_run < 1) - return 0; - - /* Append detailed run extra attributes: */ - if (evlist__add_default_attrs(evsel_list, detailed_attrs) < 0) - return -1; - - if (detailed_run < 2) - return 0; - - /* Append very detailed run extra attributes: */ - if (evlist__add_default_attrs(evsel_list, very_detailed_attrs) < 0) - return -1; - - if (detailed_run < 3) - return 0; - - /* Append very, very detailed run extra attributes: */ - return evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); + if (!ret && detailed_run >= 1) { + /* + * Detailed stats (-d), covering the L1 and last level data + * caches: + */ + ret = parse_events(evlist, + "L1-dcache-loads," + "L1-dcache-load-misses," + "LLC-loads," + "LLC-load-misses", + &err); + } + if (!ret && detailed_run >= 2) { + /* + * Very detailed stats (-d -d), covering the instruction cache + * and the TLB caches: + */ + ret = parse_events(evlist, + "L1-icache-loads," + "L1-icache-load-misses," + "dTLB-loads," + "dTLB-load-misses," + "iTLB-loads," + "iTLB-load-misses", + &err); + } + if (!ret && detailed_run >= 3) { + /* + * Very, very detailed stats (-d -d -d), adding prefetch events: + */ + ret = parse_events(evlist, + "L1-dcache-prefetches," + "L1-dcache-prefetch-misses", + &err); + } +out: + if (!ret) { + evlist__for_each_entry(evlist, evsel) + evsel->skippable = true; + } + parse_events_error__exit(&err); + evlist__splice_list_tail(evsel_list, &evlist->core.entries); + evlist__delete(evlist); + return ret; } static const char * const stat_record_usage[] = { @@ -2760,7 +2693,7 @@ int cmd_stat(int argc, const char **argv) } } - if (add_default_attributes()) + if (add_default_events()) goto out; if (stat_config.cgroup_list) { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index f14b7e6ff1dc..bace277fa77d 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -319,49 +319,6 @@ struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_wide) } #endif -int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs) -{ - struct evsel *evsel, *n; - LIST_HEAD(head); - size_t i; - - for (i = 0; i < nr_attrs; i++) { - evsel = evsel__new_idx(attrs + i, evlist->core.nr_entries + i); - if (evsel == NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - } - - evlist__splice_list_tail(evlist, &head); - - return 0; - -out_delete_partial_list: - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); - return -1; -} - -int __evlist__add_default_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs) -{ - size_t i; - - for (i = 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - return evlist__add_attrs(evlist, attrs, nr_attrs); -} - -__weak int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - if (!nr_attrs) - return 0; - - return __evlist__add_default_attrs(evlist, attrs, nr_attrs); -} - struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id) { struct evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index bcc1c6984bb5..371dc740ff7a 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -102,18 +102,6 @@ void evlist__delete(struct evlist *evlist); void evlist__add(struct evlist *evlist, struct evsel *entry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); -int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); - -int __evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, size_t nr_attrs); - -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs); - -#define evlist__add_default_attrs(evlist, array) \ - arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) - int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); int evlist__add_dummy(struct evlist *evlist); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index cbff43ff8d0f..5402998881c4 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -7,6 +7,7 @@ #include #include "color.h" #include "counts.h" +#include "debug.h" #include "evlist.h" #include "evsel.h" #include "stat.h" @@ -967,6 +968,13 @@ static bool should_skip_zero_counter(struct perf_stat_config *config, struct perf_cpu cpu; int idx; + /* + * Skip unsupported default events when not verbose. (default events + * are all marked 'skippable'). + */ + if (verbose == 0 && counter->skippable && !counter->supported) + return true; + /* * Skip value 0 when enabling --per-thread globally, * otherwise it will have too many 0 output. diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 6bb975e46de3..5548f751e56e 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -76,7 +76,7 @@ void perf_stat__reset_shadow_stats(void) memset(&ru_stats, 0, sizeof(ru_stats)); } -static enum stat_type evsel__stat_type(const struct evsel *evsel) +static enum stat_type evsel__stat_type(struct evsel *evsel) { /* Fake perf_hw_cache_op_id values for use with evsel__match. */ u64 PERF_COUNT_hw_cache_l1d_miss = PERF_COUNT_HW_CACHE_L1D | @@ -152,7 +152,7 @@ static const char *get_ratio_color(const double ratios[3], double val) static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type type) { - const struct evsel *cur; + struct evsel *cur; int evsel_ctx = evsel_context(evsel); evlist__for_each_entry(evsel->evlist, cur) { From patchwork Tue Sep 3 10:19:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 468EFCD3427 for ; Tue, 3 Sep 2024 10:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=ujWKWydQ8yy9S/xFkMXIK7RcaT IhugrV3eHC5AxQ2ITgBT0+PuKgndfNM8CZDq9IUyfc6xAda6fDt3NZzyNs6TugLBqC7IQuugwDcjZ 99lsJeECs0yZKlV1n35u7DTuqsEx4Kxlyv97TKcvncImSCUYcdHeG3oZU+FxmSJauwc1a5kLtivTl OvjyJY3x7ufuxn/rSkW+nxHo882htsD5R53Jaf8OQ+ZwpRz3xWMyvEjCABfspybNsB0PgeJpmpUTt MjVgiNJRoFoebGwrDRlxGXYZ/zC+WIAPRN+B2AA2rBJ1FIfiqG3LaCB9bzD8qiMP/Ag3XN8meuhTz gDyEDkWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQjG-0000000HKmQ-3qR0; Tue, 03 Sep 2024 10:25:42 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQfB-0000000HJv7-22yP for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:21:32 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42bbffe38e6so27254075e9.0 for ; Tue, 03 Sep 2024 03:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358888; x=1725963688; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=m3r9ohmqE2BOFrNn3rRBtCD6s5NPjIjcBDqN47DCyfxYmSz3+m793SklFwXkdtl0iA uGkjQblY7FhFeLpfPmHMybmp7oCmKH63iPbqqriYSRg5HJ1YP3HZnidpym0rcGoxm3WP VUdOldlEssC3n3rGvyBKOcUfm5WTXobTY8YiQqe8dq9agF4JBMLzo5y+CYlaKKbK6sc8 i1kNyi1l9qk8U/WAjaXeaJBQCf7ce3ovH5kYoXX+Q4b5niMsJnsxDXePa08FHi3LxAWf cRpyG06XriURpllTyH73zcA3uC9ol+E0UMxnB+GKTiolgYIK0bLlr6mulK9oNAfRXIei WxSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358888; x=1725963688; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=mjdW8bJkOt594eg9g5c3GbJBLhf+7L7hZO2N3QtlYsERDT387/Ys3z2kKNL9hh5jiN 1Ahme70VRj6sWsd5efqFt/ha+3piol/Zdo5Y49OlM4iTM8zptj8qJ3hyquFvK+U4jOGx A5mvs/LNhfupWqSN92iJtB+HI3eM7jIZcvoSysqwf3/ekfEZ9u+7O6AE2nNBxtxGCIsT crUYjOVhRLK6FXtzT9FRd+OY2DrbLO9c/nSxlSG3GbfS1oJzYUqJz6ylYeSXNbpRWagX c2NDRuxOBq2lj7MwOnzIVPlL1xpK+YgSWVKsml5Dk8JMGw7QpDHMEsZZV3uBjPyTgIBL gfOw== X-Forwarded-Encrypted: i=1; AJvYcCXllEeBRuQOTDXBwD6wSuoOqH99UTmY6oH6f7K5QNI+1h2fPRIhp2xVYq6VoHxDcJNZWVZSPcd9ZRC2f354EuZw@lists.infradead.org X-Gm-Message-State: AOJu0Yy2dLoR0Qww9EfdiQrTRIETx2nxA14UkTrudh122fxjQON+rKpy btEwLH4nmPIAOjP8ipzjAwLjVLuzbOefSyStvNdwV8sznBpG/huHUUnPZz/H6Lk= X-Google-Smtp-Source: AGHT+IG/0epOuRWCHiAJ1l6a7W+fQwq6asFnurcKDboZ9mI63Fa4LwFeUnVbm8GzqO8eC/s+nQeayA== X-Received: by 2002:a05:600c:444c:b0:427:ff3b:7a20 with SMTP id 5b1f17b1804b1-42bb27a9c9dmr134456525e9.27.1725358887488; Tue, 03 Sep 2024 03:21:27 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:21:27 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Colin Ian King , Athira Rajeev , Yang Jihong , Howard Chu , Ze Gao , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Tue, 3 Sep 2024 11:19:48 +0100 Message-Id: <20240903102005.78049-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032129_583961_92AD8134 X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers Use PMU interface to better detect core PMU for legacy events. Look for slots event on core PMU if it is appropriate for the event. Signed-off-by: Ian Rogers Signed-off-by: James Clark --- tools/perf/arch/x86/util/evsel.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c index 090d0f371891..1eaae8819c5e 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -21,7 +21,8 @@ void arch_evsel__set_sample_weight(struct evsel *evsel) /* Check whether the evsel's PMU supports the perf metrics */ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) { - const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu"; + struct perf_pmu *pmu; + u32 type = evsel->core.attr.type; /* * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU @@ -31,11 +32,31 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) * Checking both the PERF_TYPE_RAW type and the slots event * should be good enough to detect the perf metrics feature. */ - if ((evsel->core.attr.type == PERF_TYPE_RAW) && - perf_pmus__have_event(pmu_name, "slots")) - return true; +again: + switch (type) { + case PERF_TYPE_HARDWARE: + case PERF_TYPE_HW_CACHE: + type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; + if (type) + goto again; + break; + case PERF_TYPE_RAW: + break; + default: + return false; + } + + pmu = evsel->pmu; + if (pmu == &perf_pmu__fake) + pmu = NULL; - return false; + if (!pmu) { + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + if (pmu->type == PERF_TYPE_RAW) + break; + } + } + return pmu && perf_pmu__have_event(pmu, "slots"); } bool arch_evsel__must_be_in_group(const struct evsel *evsel) From patchwork Tue Sep 3 10:19:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03F03CD13CF for ; Tue, 3 Sep 2024 10:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dPRLI3dLgaJrVTirqvIrthtaYvhVH2kjttXOwkXzius=; b=tHYctNbQGyGg85KZWKVLTfLrGr 7JY4Aw+vUz1zGBPaCELsLGkLzpMrZdUp9AY0Ri7Bnff77o0F3blsKedUSMhhZgndFrz31r1IiMBdf i1KWxzSCuQAqXZ6Pxw5gP0dys7jC5mPd0n/1pL+xBZlMKjsxAMAoZhdKasMVR6JkKVtcxJ7LtmkW6 hSD9qz0EYqOYvzlhA7Wu4YoscvQIYkDaVfhTWD5IObWfPxV7mEK7zAlpbzASCgSIzd8DYTseLtMyw 8g++06Y6ASAzHQa8jW2k+ugT16by+rRGvzcGN5OW+Z9j7kUQaz8k367eAB+5r14InzWYPERS5IhTl AdBvR7zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQkA-0000000HL0N-0ur9; Tue, 03 Sep 2024 10:26:38 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQfR-0000000HK0x-1ucO for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:21:46 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-374b686d62dso1888655f8f.1 for ; Tue, 03 Sep 2024 03:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358903; x=1725963703; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dPRLI3dLgaJrVTirqvIrthtaYvhVH2kjttXOwkXzius=; b=NVzH9abgfbsUqmonDI5X+b9QwzqEJ06Dv9hNpnH50brq/MskaF+j1idutyT+gNDNQ4 83rDNSvvnu3Vck0+xe3eCgwjIKc5T/e93qfCM443VgaE4WRTCl17/ccEDgDREF0hueDZ cbfofep+Q6jy8ryrySyd9BnJ4gWgeDESHbQTKzOcOYZnP459smq88THG6kNW50VioJTW VuMIPxUhX7+yBdsYimLJdR/ZoXjRyVMt9MpBH/QvmdpzoEICwfyF/qsLhe2dZ6pzcma9 Vn4OjWiJK9WDnRPQrTAYiazd0YaXXpC75/78228OcAjf5Jna1w9aUed063tKo3zXTFuJ AjOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358903; x=1725963703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dPRLI3dLgaJrVTirqvIrthtaYvhVH2kjttXOwkXzius=; b=Od/nm9RXjh6a7EOt/rv6Bq8H9NXbwr4Jtr3j++fv+0DgPmNAMI/2nhM8w3UPXRub/n fmPrM4ON7nurefDsX0pjcCFnIAdQuR7/n4W9p0xiifmMzyDKUs5JHGglNkp5kk2tVRAR Znl/ErBxlSYqGPr98zg4wgmhCdEaFwLMOGsEgOvcb7yxv3WdGkih+ne4BnIOFL7heB1B 5jC9knmLo5839kBL8j4eB0eUiCrAaXJj87nUhAxpUMN4iaC4/xCLdyiwHa5bXHXNUsvj ylHg5aSW6vAFMQIAiShCFR7QfIqEitwe4w0RSH7h7zT00YAO7DkFI5O2kkpuOfQag28N y5zg== X-Forwarded-Encrypted: i=1; AJvYcCVQ82Re2P6h2HyoOR370GIZJzdLDMwJ5sNv7KjfXYXBXQBEX//p0JBEGY0FdbBf6irTGEJcBZXadZMuZN9ewUPA@lists.infradead.org X-Gm-Message-State: AOJu0Yx+zfNHLcoEmMNtFINnoDEgFsZ5kbg9STizSCC3DazgRimVmOTe 6zFCE9nFFd/LkiQFgjjpqZx6/q1I6MqM02kMkGCMdV5vo5fW8wSRjkmWdR2Zjso= X-Google-Smtp-Source: AGHT+IHOxoW3axJdVjogc1QXlOjZW0XIGVPmn4NB9SniypUZp+5w5VVfKsxZ6Me0N0djltfE/vtvfg== X-Received: by 2002:a5d:668c:0:b0:371:828a:741d with SMTP id ffacd0b85a97d-374bf05613amr6899318f8f.21.1725358903215; Tue, 03 Sep 2024 03:21:43 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:21:42 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Athira Rajeev , Dominique Martinet , Yang Jihong , Colin Ian King , Howard Chu , Ze Gao , Yunseong Kim , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 5/7] perf evsel: Remove pmu_name Date: Tue, 3 Sep 2024 11:19:49 +0100 Message-Id: <20240903102005.78049-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032145_513084_E5248752 X-CRM114-Status: GOOD ( 25.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Rogers "evsel->pmu_name" is only ever assigned a strdup of "pmu->name", a strdup of "evsel->pmu_name" or NULL. As such, prefer to use "pmu->name" directly and even to directly compare PMUs than PMU names. For safety, add some additional NULL tests. Signed-off-by: Ian Rogers [ Fix arm-spe.c usage of pmu_name ] Signed-off-by: James Clark --- tools/perf/arch/arm64/util/arm-spe.c | 4 ++-- tools/perf/arch/x86/util/evsel.c | 4 ++-- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/evlist.c | 3 ++- tools/perf/util/evsel.c | 7 ------- tools/perf/util/evsel.h | 3 +-- tools/perf/util/metricgroup.c | 4 ++-- tools/perf/util/parse-events.c | 1 - tools/perf/util/stat-shadow.c | 10 +++++----- tools/perf/util/stat.c | 2 +- 10 files changed, 16 insertions(+), 24 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 2be99fdf997d..59a85e6f3aa3 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -188,9 +188,9 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, evlist__for_each_entry(evlist, evsel) { if (evsel__is_aux_event(evsel)) { - if (!strstarts(evsel->pmu_name, ARM_SPE_PMU_NAME)) { + if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) { pr_err("Found unexpected auxtrace event: %s\n", - evsel->pmu_name); + evsel->pmu->name); return -EINVAL; } opts->full_auxtrace = true; diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c index 1eaae8819c5e..fe8a817d2061 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -84,7 +84,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size) return scnprintf(bf, size, "%s", event_name); return scnprintf(bf, size, "%s/%s/", - evsel->pmu_name ? evsel->pmu_name : "cpu", + evsel->pmu ? evsel->pmu->name : "cpu", event_name); } @@ -129,7 +129,7 @@ int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size) return 0; if (!evsel->core.attr.precise_ip && - !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3))) + !(evsel->pmu && !strncmp(evsel->pmu->name, "ibs", 3))) return 0; /* More verbose IBS errors. */ diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index edc2adcf1bae..c38fa4e16670 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -730,7 +730,7 @@ static int test__checkevent_pmu_events(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type || - strcmp(evsel->pmu_name, "cpu")); + strcmp(evsel->pmu->name, "cpu")); TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index bace277fa77d..2eb0a98ecb99 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2576,7 +2576,8 @@ void evlist__uniquify_name(struct evlist *evlist) else attributes = empty_attributes; - if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) { + if (asprintf(&new_name, "%s/%s/%s", pos->pmu ? "" : pos->pmu->name, + pos->name, attributes + 1)) { free(pos->name); pos->name = new_name; } else { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2928c1f76dad..082159fb2091 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -296,7 +296,6 @@ void evsel__init(struct evsel *evsel, evsel->metric_events = NULL; evsel->per_pkg_mask = NULL; evsel->collect_stat = false; - evsel->pmu_name = NULL; evsel->group_pmu_name = NULL; evsel->skippable = false; evsel->alternate_hw_config = PERF_COUNT_HW_MAX; @@ -394,11 +393,6 @@ struct evsel *evsel__clone(struct evsel *orig) if (evsel->group_name == NULL) goto out_err; } - if (orig->pmu_name) { - evsel->pmu_name = strdup(orig->pmu_name); - if (evsel->pmu_name == NULL) - goto out_err; - } if (orig->group_pmu_name) { evsel->group_pmu_name = strdup(orig->group_pmu_name); if (evsel->group_pmu_name == NULL) @@ -1497,7 +1491,6 @@ void evsel__exit(struct evsel *evsel) zfree(&evsel->group_name); zfree(&evsel->name); zfree(&evsel->filter); - zfree(&evsel->pmu_name); zfree(&evsel->group_pmu_name); zfree(&evsel->unit); zfree(&evsel->metric_id); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 430441fdfbbc..936aafb046b6 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -72,7 +72,6 @@ struct evsel { struct { char *name; char *group_name; - const char *pmu_name; const char *group_pmu_name; #ifdef HAVE_LIBTRACEEVENT struct tep_event *tp_format; @@ -184,7 +183,7 @@ struct evsel { unsigned long open_flags; int precise_ip_original; - /* for missing_features */ + /* The PMU the event is from. Used for missing_features, PMU name, etc. */ struct perf_pmu *pmu; /* For tool events */ diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 69f6a46402c3..bbbb2e7eb8db 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -297,8 +297,8 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, struct expr_id_data *val_ptr; /* Don't match events for the wrong hybrid PMU. */ - if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) && - strcmp(ev->pmu_name, pmu)) + if (!all_pmus && ev->pmu && evsel__is_hybrid(ev) && + strcmp(ev->pmu->name, pmu)) continue; /* * Check for duplicate events with the same name. For diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d1355e492df3..fa37567e0323 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -262,7 +262,6 @@ __add_event(struct list_head *list, int *idx, evsel->core.is_pmu_core = pmu ? pmu->is_core : false; evsel->auto_merge_stats = auto_merge_stats; evsel->pmu = pmu; - evsel->pmu_name = pmu ? strdup(pmu->name) : NULL; evsel->alternate_hw_config = alternate_hw_config; if (name) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 5548f751e56e..72275806e6e2 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -573,7 +573,7 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config, { bool need_full_name = perf_pmus__num_core_pmus() > 1; static const char *last_name; - static const char *last_pmu; + static const struct perf_pmu *last_pmu; char full_name[64]; /* @@ -584,21 +584,21 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config, * different metric events. */ if (last_name && !strcmp(last_name, name)) { - if (!need_full_name || !strcmp(last_pmu, evsel->pmu_name)) { + if (!need_full_name || last_pmu != evsel->pmu) { out->print_metricgroup_header(config, ctxp, NULL); return; } } - if (need_full_name) - scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu_name); + if (need_full_name && evsel->pmu) + scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu->name); else scnprintf(full_name, sizeof(full_name), "%s", name); out->print_metricgroup_header(config, ctxp, full_name); last_name = name; - last_pmu = evsel->pmu_name; + last_pmu = evsel->pmu; } /** diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 0bd5467389e4..7c2ccdcc3fdb 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -553,7 +553,7 @@ static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b) if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b)) return false; - return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); + return evsel_a->pmu != evsel_b->pmu; } static void evsel__merge_aliases(struct evsel *evsel) From patchwork Tue Sep 3 10:19:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52C94CD13CF for ; Tue, 3 Sep 2024 10:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FXow/HXS2t6eZsIhNK0KrvK5I+CXmczupsEF4/wQsaM=; b=oMXYe0oCvRXW96mjJqvKf6+HWv 4jvIG2IE2/LvBs0JayEEt0F0bflxhQSLdHjDztB4GQ0+qMjUcQSLdvRbV9QQ2ElV27UyI8mbdkzGI NlLe9sH0x9kc6BRdmHv4KFzknTG//Upgnnd7RqiJiJcNinl/ww4yzBE07HATIa5RgyQeTUbeg+GW9 80EqPQ/BxELRxURIU627eqWMIi9NoJ/HkwpMuorxP1kcoOuaXAaG3A6E6Bmk6bpJOHvQAZl0pBlyM NFs0uQnA0VbLsx5+YJCOds1WKX9vQHXuF0hfZ9NUeZdkFE3MdKLPsV5maU+uXcZI8mB0IC7QHo7f1 HJb5e/Yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQl2-0000000HL7H-0tFa; Tue, 03 Sep 2024 10:27:32 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQfg-0000000HK5Y-2Wav for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:22:01 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42bb72a5e0bso45220355e9.1 for ; Tue, 03 Sep 2024 03:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358919; x=1725963719; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FXow/HXS2t6eZsIhNK0KrvK5I+CXmczupsEF4/wQsaM=; b=mfmD0spUziX5sytp65j9JHr7/dJ4vKpLgBnEi9WX0Oy6k2SRcykPHkLfHWrZ/h+UnL e1plQ4nAuzaoz79eRAKn29+r3cfv9P2R6xBwon6cdYo/47DEm5Pq2pG6MhzbWqE4SDMS YKb7N7sQj8kDUKN4vQNpv6P7Z8BoxxfmCAlEbrU6/1J/mSCv3eTgVtb63cGYm0gq8b8/ P8r7jME6rltBVQyKtrbof3R6fNUcj5DGXo642N/xlVeNOH5Ig3Jum2edia0YB8LeasdU m+hK7z7GpkC4q+eBR2jMz57p1eQ355th+4rJqdMSRYdQUFgvTj4xe6vTdd3HEm6pX3uC tOog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358919; x=1725963719; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FXow/HXS2t6eZsIhNK0KrvK5I+CXmczupsEF4/wQsaM=; b=KYG8pENRxmM+Rb8sdwGjLfOQO//NpTml0qLgdlLTv1HWHpAwoVwKwpZbIipLfVfyB8 xjLEwjjceWDCoPRElapHdJ3UpIIereFiEcP4+4eUwfXrl1gz92KohW9OcT0zueWWon1O Gzpt2Mv7Lg3o6hb3csB8rkhZRBt0mSNJakImM9ZG8Ug/svenDDDG79QEZPb3CcF3PIO8 0Uno1uUF9cvKZJnr3RwcxfrlgBSKTl5TNZNt1flQSbFEctMtfp3C7Rc9bW1Edlxhduhl LhiVuE+mU90VgXfDbbilwo6K8RzGFITtLHHPUgmuA/OrbTP40ClS2FhbhaXMEBdQFP9d 0M9Q== X-Forwarded-Encrypted: i=1; AJvYcCVXei1REICScidwZA15AxT4rW0q9iQfsMHKIQIMoR+JVE9KwQPI+31nP08FK1kQ+3pggwclnVa+ZaqBf3y2HJ/L@lists.infradead.org X-Gm-Message-State: AOJu0Yxfh/tMmVUVwGhXEzZaQH/DTl+Pcn/GW6kva4RNSJ8jWhJ3+Q2z NTYdmM2WVyajf06LMvlO5ZvRcYI+krpDYfazP8tw//4I07LArOz9AUhpzPYlrJU= X-Google-Smtp-Source: AGHT+IHkBX4KzIJzZmErwYTrZ+5GhpDTKAgX+51Byz51rMyHGi/ROqeYUZBfKl487Mq1nQLo3tEQCg== X-Received: by 2002:a05:600c:1c1b:b0:426:6f27:379a with SMTP id 5b1f17b1804b1-42bb01b4c35mr118683625e9.13.1725358918867; Tue, 03 Sep 2024 03:21:58 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:21:58 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Yang Jihong , Colin Ian King , Athira Rajeev , Howard Chu , Ze Gao , Yunseong Kim , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 6/7] perf test: Make stat test work on DT devices Date: Tue, 3 Sep 2024 11:19:50 +0100 Message-Id: <20240903102005.78049-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032200_700800_E2CA139A X-CRM114-Status: GOOD ( 14.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PMUs aren't listed in /sys/devices/ on DT devices, so change the search directory to /sys/bus/event_source/devices which works everywhere. Also add armv8_cortex_* as a known PMU type to search for to make the test run on more devices. Signed-off-by: James Clark --- tools/perf/tests/shell/stat.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh index 3f1e67795490..525d0c44fdc6 100755 --- a/tools/perf/tests/shell/stat.sh +++ b/tools/perf/tests/shell/stat.sh @@ -117,16 +117,18 @@ test_cputype() { # Find a known PMU for cputype. pmu="" - for i in cpu cpu_atom armv8_pmuv3_0 + devs="/sys/bus/event_source/devices" + for i in $devs/cpu $devs/cpu_atom $devs/armv8_pmuv3_0 $devs/armv8_cortex_* do - if test -d "/sys/devices/$i" + i_base=$(basename "$i") + if test -d "$i" then - pmu="$i" + pmu="$i_base" break fi - if perf stat -e "$i/instructions/" true > /dev/null 2>&1 + if perf stat -e "$i_base/instructions/" true > /dev/null 2>&1 then - pmu="$i" + pmu="$i_base" break fi done From patchwork Tue Sep 3 10:19:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13788484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E274FCD13CF for ; Tue, 3 Sep 2024 10:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VJKJCBpUvVPcGAEYnax2qcSOD0MR4G3nPcSezle+qU4=; b=ED6c8BnYzSonU1cXi1QU2UnO+b 9dptQ5g+g8qEiF6Ili30XRpxXCezvhtzg8hxOFWZ+jv75Kzjd94dwTnfLaMwm47xqvzSruMrZhgL7 2GyYXcFXEur6ckd6gv9p9JTl5fygC46Y9DTV8pYEF0RYd/1bOgzRRY7boVIo7WMifgqUPmFtHXacC zfrCDlJ7ziqACPWN8hX/sKVsk+HQSLsyw4naQfhf5QAwvizUGCpA3+JCOfdK9EyL6oZUHTqx0OLfz 8yt+dhQgng2SQyfZvZFjzb+fOLVdjwTfLrVd6AwrqrsDefVUESdW+P805KFiCWf4Srpju2QtqH6TZ YcX7Gocg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQlt-0000000HLFX-1haV; Tue, 03 Sep 2024 10:28:25 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slQfw-0000000HKBZ-2LON for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 10:22:18 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42bbe908380so31051085e9.2 for ; Tue, 03 Sep 2024 03:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725358935; x=1725963735; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VJKJCBpUvVPcGAEYnax2qcSOD0MR4G3nPcSezle+qU4=; b=rQCIfM+oYmcRSq2yceQ4G2ml/q2N4ZDFUFkvrZlX/752XJBPdSgMMGNEzrV+8eAxdq URKcaXY+czr3iiF4hjEzBYuECt2DeKRMAED3o6OzGVLSTJuIOBR2um721rrq7cKF0Z0g 9PA1MEXERWH8xsASTUvbTSsZ5e10K4YkgArkuPg+RTIFY+WsfeUTr34UQ5emlnH62fCQ JXsGAUSaTzqJ+YCki/QQh2Nzg2RksBJBWCOMAKJl55Xa9WG4xK6snzvbYAqnuerJBCkE d/n3dsQgH61Dk6zJ6BPibo/1zZeL/EJwZ4M59xpHYxCYTOOLW7qQrxHlJq4P2OZTo8RI 2oyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725358935; x=1725963735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VJKJCBpUvVPcGAEYnax2qcSOD0MR4G3nPcSezle+qU4=; b=KQfTGMqR1bK2okc1GpAx7QHAq09uqCBQwfiMTy4ZUmqLzVGKM0VEULeS/jmmnkClj1 LU02gMMX7GwSzuM7xDQuCOUV6sDwfqX/ltINjdH6Dh1EjLEEhr6mxgl1S4pvIDVMEp/o saSYOmBOrlkICMNYD8SgwyL3qoCMO/Xn8PVR3P4j+p7uKNyiNGMuWm/6m4ff8TqcpxC+ rIKyvWHYO5anJz+BeO6yyb69PjRh+7zLV+GI5uI4t/+JutTDoyezZwuMTs21vS3JiRVA PbbtyjwRWb0xdhn8P1I3hmrOMu6m+17jaulmlJN6XO+TMOPJAb12ke3JZA5kHa6YrLhe vRBw== X-Forwarded-Encrypted: i=1; AJvYcCXFUvdpDy66ISswNQi1d2jXOnWidZiR6/+uKBkplqv8FVJ73eTVXxaqI1n8KwRHozz9I7G17d6hiOdmUDIJ0EP6@lists.infradead.org X-Gm-Message-State: AOJu0Yy2n+USPP4Ds1NP7QWatPhuHPmu1ssU2aIx+699RUo8gFs6v1F0 aTI5HnX58BZIS7HmSzmoEodo2Iay0/3dBtwJ6XpPWN0GJDnQtYmPnMd3wDgMvEg= X-Google-Smtp-Source: AGHT+IFgSoyyOtImdhFvpIkfkxAvYNeSg4DDCvj9dTZ/CYpAWzZrXxUx8ASLwX+TMI1prEH2Ay5XJA== X-Received: by 2002:a05:600c:3b1b:b0:42a:a6d2:328b with SMTP id 5b1f17b1804b1-42bdc64e691mr64706745e9.30.1725358934675; Tue, 03 Sep 2024 03:22:14 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e274ccsm168739995e9.37.2024.09.03.03.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 03:22:14 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Athira Rajeev , Colin Ian King , Yang Jihong , Howard Chu , Ze Gao , Yunseong Kim , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 7/7] perf test: Add a test for default perf stat command Date: Tue, 3 Sep 2024 11:19:51 +0100 Message-Id: <20240903102005.78049-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903102005.78049-1-james.clark@linaro.org> References: <20240903102005.78049-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_032216_664761_C704C526 X-CRM114-Status: GOOD ( 14.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Test that one cycles event is opened for each core PMU when "perf stat" is run without arguments. The event line can either be output as "pmu/cycles/" or just "cycles" if there is only one PMU. Include 2 spaces for padding in the one PMU case to avoid matching when the word cycles is included in metric descriptions. Signed-off-by: James Clark --- tools/perf/tests/shell/stat.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh index 525d0c44fdc6..5a2ca2bcf94d 100755 --- a/tools/perf/tests/shell/stat.sh +++ b/tools/perf/tests/shell/stat.sh @@ -148,6 +148,30 @@ test_cputype() { echo "cputype test [Success]" } +test_hybrid() { + # Test the default stat command on hybrid devices opens one cycles event for + # each CPU type. + echo "hybrid test" + + # Count the number of core PMUs, assume minimum of 1 + pmus=$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l) + if [ "$pmus" -lt 1 ] + then + pmus=1 + fi + + # Run default Perf stat + cycles_events=$(perf stat -- true 2>&1 | grep -E "/cycles/| cycles " | wc -l) + + if [ "$pmus" -ne "$cycles_events" ] + then + echo "hybrid test [Found $pmus PMUs but $cycles_events cycles events. Failed]" + err=1 + return + fi + echo "hybrid test [Success]" +} + test_default_stat test_stat_record_report test_stat_record_script @@ -155,4 +179,5 @@ test_stat_repeat_weak_groups test_topdown_groups test_topdown_weak_groups test_cputype +test_hybrid exit $err