From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9A219AA4E for ; Tue, 10 Sep 2024 15:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981436; cv=none; b=mZHYLsOEjH8F/WIipPZ+0k2AG3XOr2f6L84t6oMdpWqcLSQNqlHKSWDGpNGTQlPHExR3r5WcQsuMC/7+zg9zEbmmQQH/ch2vm3PYWZRudSo/C4Z/lXDVRdSJGH99dsfAt02QJi3vjpEqtN0sL/cG7NQOIvRxtHx1+pvZE7DeSNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981436; c=relaxed/simple; bh=NpCDCVBfp4mVilGImegEzHAS8ACJOntFrnoaLEahByQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cJ4jQc0Lut0jc7YI+iapS2+2mfr4eJCp3m1Cs4B+ssfCnyCsZt7DXYkdTfv3ZREanmVooSXDCk+4DqviTQA0Xqqy9yLQsxl5SlnxqgwmeTHXjFZjjHAa65ePJi31aTEU8uQ2AKwK0dQF+zSq99tQYp9F0ljG+PsThnFL544GqEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kjfbioHq; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kjfbioHq" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cae4eb026so33242535e9.0 for ; Tue, 10 Sep 2024 08:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981433; x=1726586233; darn=vger.kernel.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=/LnLVZ/Dm0FJpsXVTAhvzfHs1a08JLpOgMy3Uo/rdZ4=; b=kjfbioHq7VhbFdrIJI7Xw5V+pmgRLbU7hXTfshH1jaONleSru/qYB2d93GOuNwZjaH UEVOSJ8J3yRsPZrK22lKYWiNmyppP/mZahNvlvvlrDopgzvhD99UlMLW8NpvZBOU2XdO 0Mq0DS/vfhg7yiEoQMrD5cp6GmOoGxk22mdBz+23KtNCrVR8XEl0tVHL/rlywcC/IxIW UqIIlOc27ms2cxH0iSAg5EMgp27ByGfsRAWUImH7gykxqIgQBN0S0fzsl9hGfiwp76DJ PJBwzSir4mIAuPOwEUiwDGgDP43+YDAAVpGWYTwizyVbCz4wsUpQuHg17Hi6PGFvNb9L 1K6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981433; x=1726586233; 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=/LnLVZ/Dm0FJpsXVTAhvzfHs1a08JLpOgMy3Uo/rdZ4=; b=teSLNdHpmvxJvK78rBC6DImE/mOIBizim2tGlJrD8SM9zEaigPLD7dvG1ksUj60+Bm AN307Y+zie/yj0sI8FCxCZY8rgTOgWst8wC/N4Mwt2DNxYesXAwbtYmD48kex0ua8cJy sbvSAIgU93YyA7BCucattEpklUHgvi6eovDKocDbZ9aMm/HxneEyeDffdziguLG15jIG 5Sx8+aBefPFwyNG0AubFiOI/3k2GvbEPvvpyQdTf787ATNx4HYfEytHmgSf7gmFiIIuV W1dvRldekPcGriCzHlfr/vHPWEOZY1Tjp81ihs8fwK26bk1kWXVb/W8UWa9x+cYOOGRd xAYA== X-Forwarded-Encrypted: i=1; AJvYcCWuVYBT/9V793VSNy15TAPgGYOiVRn7/HvgfGub0BAMYBvqtTHM5J4ba3ZHmwxHh3mc0K8IwiPaBkt+jWs=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5nkub2fiMhLZAzBdtSX3odbZKbx9nJ4k2jbk1sZlhGVE31Acp Vm/0GwHeWbmWWwJp0DHNCyHuXO9268HYgy7XcR8SC6xJPJrCU96QKphBWjaMN5A= X-Google-Smtp-Source: AGHT+IGqAtn2U57/E2cy1g/CVTVsfzKI2z41EoD86mTuyKtzz41F6SUmpJnEIF9HK5v8+KL3uaX4Qw== X-Received: by 2002:adf:9b93:0:b0:374:c040:b015 with SMTP id ffacd0b85a97d-3788969b7dbmr9589905f8f.57.1725981432577; Tue, 10 Sep 2024 08:17:12 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:17:12 -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 , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/7] perf evsel: Add alternate_hw_config and use in evsel__match Date: Tue, 10 Sep 2024 16:16:19 +0100 Message-Id: <20240910151640.907359-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Acked-by: Namhyung Kim Signed-off-by: Ian Rogers Signed-off-by: James Clark Acked-by: Kan Liang --- tools/perf/builtin-diff.c | 6 ++-- tools/perf/util/evsel.c | 21 +++++++++++++ tools/perf/util/evsel.h | 19 ++---------- tools/perf/util/parse-events.c | 56 +++++++++++++++++++++------------- 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, 75 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 pe= rf_tool *tool, =20 static struct perf_diff pdiff; =20 -static struct evsel *evsel_match(struct evsel *evsel, - struct evlist *evlist) +static struct evsel *evsel_match(struct evsel *evsel, struct evlist *evlis= t) { struct evsel *e; =20 evlist__for_each_entry(evlist, e) { - if (evsel__match2(evsel, e)) + if ((evsel->core.attr.type =3D=3D e->core.attr.type) && + (evsel->core.attr.config =3D=3D e->core.attr.config)) return e; } =20 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 =3D NULL; evsel->group_pmu_name =3D NULL; evsel->skippable =3D false; + evsel->alternate_hw_config =3D PERF_COUNT_HW_MAX; } =20 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; =20 + evsel->alternate_hw_config =3D orig->alternate_hw_config; + return evsel; =20 out_err: @@ -1845,6 +1848,24 @@ static int evsel__read_tool(struct evsel *evsel, int= cpu_map_idx, int thread) return 0; } =20 +bool __evsel__match(const struct evsel *evsel, u32 type, u64 config) +{ + + u32 e_type =3D evsel->core.attr.type; + u64 e_config =3D evsel->core.attr.config; + + if (e_type !=3D type) { + return type =3D=3D PERF_TYPE_HARDWARE && evsel->pmu && evsel->pmu->is_co= re && + evsel->alternate_hw_config =3D=3D config; + } + + if ((type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYPE_HW_CACHE) && + perf_pmus__supports_extended_type()) + e_config &=3D PERF_HW_EVENT_MASK; + + return e_config =3D=3D 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; }; =20 /* @@ -388,26 +389,10 @@ u64 format_field__intval(struct tep_format_field *fie= ld, struct perf_sample *sam struct tep_format_field *evsel__field(struct evsel *evsel, const char *nam= e); struct tep_format_field *evsel__common_field(struct evsel *evsel, const ch= ar *name); =20 -static inline bool __evsel__match(const struct evsel *evsel, u32 type, u64= config) -{ - if (evsel->core.attr.type !=3D type) - return false; - - if ((type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYPE_HW_CACHE) && - perf_pmus__supports_extended_type()) - return (evsel->core.attr.config & PERF_HW_EVENT_MASK) =3D=3D config; - - return evsel->core.attr.config =3D=3D config; -} +bool __evsel__match(const struct evsel *evsel, u32 type, u64 config); =20 #define evsel__match(evsel, t, c) __evsel__match(evsel, PERF_TYPE_##t, PER= F_COUNT_##c) =20 -static inline bool evsel__match2(struct evsel *e1, struct evsel *e2) -{ - return (e1->core.attr.type =3D=3D e2->core.attr.type) && - (e1->core.attr.config =3D=3D e2->core.attr.config); -} - int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread); =20 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 f5eb1af8302c..3db402f2461a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -228,7 +228,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, - struct perf_cpu_map *cpu_list) + struct perf_cpu_map *cpu_list, u64 alternate_hw_config) { struct evsel *evsel; struct perf_cpu_map *cpus =3D perf_cpu_map__is_empty(cpu_list) && pmu ? p= mu->cpus : cpu_list; @@ -264,6 +264,7 @@ __add_event(struct list_head *list, int *idx, evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; evsel->pmu_name =3D pmu ? strdup(pmu->name) : NULL; + evsel->alternate_hw_config =3D alternate_hw_config; =20 if (name) evsel->name =3D strdup(name); @@ -286,16 +287,19 @@ struct evsel *parse_events__add_event(int idx, struct= perf_event_attr *attr, { return __add_event(/*list=3D*/NULL, &idx, attr, /*init_attr=3D*/false, na= me, metric_id, pmu, /*config_terms=3D*/NULL, - /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL); + /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL, + /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); } =20 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=3D*/NULL, config_terms, - /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; + /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL, + alternate_hw_config) ? 0 : -ENOMEM; } =20 static int add_event_tool(struct list_head *list, int *idx, @@ -315,7 +319,8 @@ static int add_event_tool(struct list_head *list, int *= idx, evsel =3D __add_event(list, idx, &attr, /*init_attr=3D*/true, /*name=3D*/= NULL, /*metric_id=3D*/NULL, /*pmu=3D*/NULL, /*config_terms=3D*/NULL, /*auto_merge_stats=3D*/false, - cpu_list); + cpu_list, + /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); perf_cpu_map__put(cpu_list); if (!evsel) return -ENOMEM; @@ -450,7 +455,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); =20 int parse_events_add_cache(struct list_head *list, int *idx, const char *n= ame, struct parse_events_state *parse_state, @@ -476,7 +481,8 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, */ ret =3D 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=3D*/PERF_COUNT_HW_MAX); if (ret) return ret; continue; @@ -507,7 +513,8 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, =20 if (__add_event(list, idx, &attr, /*init_attr*/true, config_name ?: name, metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL) =3D=3D NULL) + /*cpu_list=3D*/NULL, + /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX) =3D=3D NULL) return -ENOMEM; =20 free_config_terms(&config_terms); @@ -772,7 +779,7 @@ int parse_events_add_breakpoint(struct parse_events_sta= te *parse_state, name =3D get_config_name(head_config); =20 return add_event(list, &parse_state->idx, &attr, name, /*mertic_id=3D*/NU= LL, - &config_terms); + &config_terms, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); } =20 static int check_type_val(struct parse_events_term *term, @@ -1072,6 +1079,7 @@ static int config_term_pmu(struct perf_event_attr *at= tr, if (perf_pmu__have_event(pmu, term->config)) { term->type_term =3D PARSE_EVENTS__TERM_TYPE_USER; term->no_value =3D true; + term->alternate_hw_config =3D true; } else { attr->type =3D PERF_TYPE_HARDWARE; attr->config =3D term->val.num; @@ -1384,8 +1392,9 @@ static int __parse_events_add_numeric(struct parse_ev= ents_state *parse_state, name =3D get_config_name(head_config); metric_id =3D get_config_metric_id(head_config); ret =3D __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, na= me, - metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; + metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, + /*cpu_list=3D*/NULL, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX + ) =3D=3D NULL ? -ENOMEM : 0; free_config_terms(&config_terms); return ret; } @@ -1443,7 +1452,7 @@ static bool config_term_percore(struct list_head *con= fig_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; @@ -1480,7 +1489,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, /*init_attr=3D*/true, /*name=3D*/NULL, /*metric_id=3D*/NULL, pmu, /*config_terms=3D*/NULL, auto_merge_stats, - /*cpu_list=3D*/NULL); + /*cpu_list=3D*/NULL, alternate_hw_config); return evsel ? 0 : -ENOMEM; } =20 @@ -1501,7 +1510,8 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, =20 /* 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; } @@ -1547,7 +1557,8 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, evsel =3D __add_event(list, &parse_state->idx, &attr, /*init_attr=3D*/tru= e, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, - &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL); + &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL, + alternate_hw_config); if (!evsel) { parse_events_terms__exit(&parsed_terms); return -ENOMEM; @@ -1573,7 +1584,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, } =20 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_) { @@ -1626,7 +1637,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 auto_merge_stats =3D 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; =20 strbuf_init(&sb, /*hint=3D*/ 0); @@ -1639,7 +1650,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 if (parse_state->fake_pmu) { if (!parse_events_add_pmu(parse_state, list, parse_state->fake_pmu, &par= sed_terms, - /*auto_merge_stats=3D*/true)) { + /*auto_merge_stats=3D*/true, hw_config)) { struct strbuf sb; =20 strbuf_init(&sb, /*hint=3D*/ 0); @@ -1680,7 +1691,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pars= e_events_state *parse_state /* Attempt to add to list assuming event_or_pmu is a PMU name. */ pmu =3D parse_state->fake_pmu ?: perf_pmus__find(event_or_pmu); if (pmu && !parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_t= erms, - /*auto_merge_stats=3D*/false)) + /*auto_merge_stats=3D*/false, + /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX)) return 0; =20 pmu =3D NULL; @@ -1692,7 +1704,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pars= e_events_state *parse_state =20 if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, - auto_merge_stats)) { + auto_merge_stats, + /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX)) { ok++; parse_state->wild_card_pmus =3D true; } @@ -1703,7 +1716,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pars= e_events_state *parse_state =20 /* 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_t= erms, listp, loc)) + if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, PERF_COUNT_HW_= MAX, + const_parsed_terms, listp, loc)) return 0; =20 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 68bfea9ffa70..3e97b40be359 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; }; =20 struct parse_events_error { @@ -238,7 +244,7 @@ struct evsel *parse_events__add_event(int idx, struct p= erf_event_attr *attr, struct perf_pmu *pmu); =20 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); =20 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; =20 - err =3D parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); + err =3D parse_events_multi_pmu_add(_parse_state, $1, PERF_COUNT_HW_MAX, N= ULL, &list, &@1); if (err < 0) { struct parse_events_state *parse_state =3D _parse_state; struct parse_events_error *error =3D parse_state->error; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ef8ab918eaeb..f6bf41abb8ff 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1601,7 +1601,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; @@ -1629,6 +1629,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ NULL); return ret; } + *rewrote_terms =3D true; ret =3D check_info_data(pmu, alias, info, err, term->err_term); if (ret) @@ -1637,6 +1638,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ if (alias->per_pkg) info->per_pkg =3D true; =20 + if (term->alternate_hw_config) + *alternate_hw_config =3D 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 *st= ate, pmu_event_callback cb); =20 void perf_pmu_format__set_value(void *format, int config, unsigned long *b= its); --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 050B319995B for ; Tue, 10 Sep 2024 15:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981454; cv=none; b=WK2t++fNpESoLFutR1H7F4Rhz5N4cK9ytMdMtlB1FyNIEp/6K5NwRp1vwOvjyQ1rCtOfxxi4WSzVZWfkF5JBV6SY6JXnexNUckrwhcNeIpWoC29rOcEV4PdXvFhfOABrESqPqIT22aCyVG66Aw4pGDCHb9W8BxR0LO5Z0qqu42k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981454; c=relaxed/simple; bh=ZO0cjcf70UOuKOoHRZFkYxmjxvF57AkLik+p1Nx6jLA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NNO2wOvcsasOalYMU1QXxg4/gTCLvwW3lYT0PU6fVkv/hjz2cDkfZlO0fHO4kvo7hgGGP2hQrRHYRlhSwWjHu1O7KhDCk00tR+K3KY2LDOac5FreKNQominB8Dqn86hCy6N5JkK96dyKgG4xGMcUDOROP1qMK7RjwC9BOKYSN9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=NMPHWh4k; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NMPHWh4k" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42cb806623eso8512245e9.2 for ; Tue, 10 Sep 2024 08:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981451; x=1726586251; darn=vger.kernel.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=NFDCbwWLYHtewDSmMSa5dxxCwM5A38zDayLzJ0EVNJs=; b=NMPHWh4kiXh+gb9EsHf3I9mSIZVJUTVw4QR291TzaBPRhtgTqh8IHX48e3SiUozNgI FbfQQ7cCIlyMSXRR+bSY7kBMctQ7zgMdzVT3kwwT/SgJ+Ymm6Kj65HB8vf20FlEuXZ0C 58eZTY0PJD4kUHO4zhhRqhKJnXD6sXGdf23ySzWHWwRFqXOstve/zP3Ma+rfNjQ0jQHI s5o04BsoF8dd9VRR37/72jPkKKBgdRZi0cl1sO3sMZkcz0xUt/w25hZ4QiYTDQeUz5QV l+T0PqPpfwPsP7inekR+Oq9c30lGYP7sRk2N2RO9zjiqn5VPtxeAhuk5yO8gjdfd1h1d 6eaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981451; x=1726586251; 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=NFDCbwWLYHtewDSmMSa5dxxCwM5A38zDayLzJ0EVNJs=; b=WUMaMY4c/N0K0wD7Cwb4pdpZCP5mRgbX9KoB2IyZacwBEWYuSi3B/8AisE9+E5uGzf MKb9Dz74oxR+l3+39Lka7OIhqm7Elb6YaZP/MUyZDJZI8JIEk9AdC4jYenwt1OuxzKk8 eewy7i+2qaGeRkUijFJifuqyYYfd9CJ4u8qibIdUzarQsoBc4WNCDiM9QAvp6NBHFoSz E6HEoiqlAy47JWLnisjsEk09VUds3DGYhAR2Jj4riPM0iZ/f2QEge2hgMKXd4l2WWAdy mRYOXW3GT0qKGF2hNVBN6BqiErQKQYbzGG3VnN+7Ruxsiz0I8BCmXNGrvJApP3nqa36c YWvA== X-Forwarded-Encrypted: i=1; AJvYcCWFHgVHd3qKVpvYeqAgMYQeMXKsjVdW1lOU/qUIsEMLHrvG5+tLjWliREw9H2O2SsAAJkCEwMJnGWMbQkw=@vger.kernel.org X-Gm-Message-State: AOJu0YyVhQ2irn/jUDGwIa2cQuWWkE5fFIi6XZs0dmZsUDPKVUlMQmKM PdqFZbzCC2Y2KPMUe0NS7qNlktKi9ZlWwSoyKNfYl/7vwTcMgWbt48O/RqmtJOQ= X-Google-Smtp-Source: AGHT+IHGOqmfICWBH72NIu+jj0wdIAL5x8avGpXcKrAFVtiPuEoZPA6ZZQtEfVUU25gZymM2vqN12A== X-Received: by 2002:a05:600c:35cc:b0:42c:bfd6:9d4d with SMTP id 5b1f17b1804b1-42ccd30c326mr270615e9.2.1725981450497; Tue, 10 Sep 2024 08:17:30 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:17:29 -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 , Athira Rajeev , Colin Ian King , Howard Chu , Ze Gao , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/7] perf stat: Uniquify event name improvements Date: Tue, 10 Sep 2024 16:16:20 +0100 Message-Id: <20240910151640.907359-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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") Acked-by: Namhyung Kim Signed-off-by: Ian Rogers [ Fix Intel TPEBS counting mode test ] Signed-off-by: James Clark Acked-by: Kan Liang --- .../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/t= ests/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=3Dcache-misses:R =20 +# Hybrid platforms output like "cpu_atom/cache-misses/R", rather than as a= bove +alt_name=3D/cache-misses/R + # Without this cmd option, default value or zero is returned -echo "Testing without --record-tpebs" -result=3D$(perf stat -e "$event" true 2>&1) -[[ "$result" =3D~ $event ]] || exit 1 +#echo "Testing without --record-tpebs" +#result=3D$(perf stat -e "$event" true 2>&1) +#[[ "$result" =3D~ $event || "$result" =3D~ $alt_name ]] || exit 1 =20 # In platforms that do not support TPEBS, it should execute without error. echo "Testing with --record-tpebs" result=3D$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1) -[[ "$result" =3D~ "perf record" && "$result" =3D~ $event ]] || exit 1 +[[ "$result" =3D~ "perf record" && "$result" =3D~ $event || "$result" =3D~= $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, =20 static void uniquify_event_name(struct evsel *counter) { - char *new_name; - char *config; - int ret =3D 0; + const char *name, *pmu_name; + char *new_name, *config; + int ret; =20 - if (counter->uniquified_name || counter->use_config_name || - !counter->pmu_name || !strncmp(evsel__name(counter), counter->pmu_nam= e, - strlen(counter->pmu_name))) + /* The evsel was already uniquified. */ + if (counter->uniquified_name) return; =20 - config =3D strchr(counter->name, '/'); + /* Avoid checking to uniquify twice. */ + counter->uniquified_name =3D true; + + /* The evsel has a "name=3D" 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 !=3D 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 !=3D PERF_COUNT= _HW_MAX) + return; + + name =3D evsel__name(counter); + pmu_name =3D counter->pmu->name; + /* Already prefixed by the PMU name. */ + if (!strncmp(name, pmu_name, strlen(pmu_name))) + return; + + config =3D strchr(name, '/'); if (config) { - if (asprintf(&new_name, - "%s%s", counter->pmu_name, config) > 0) { - free(counter->name); - counter->name =3D new_name; - } - } else { - if (evsel__is_hybrid(counter)) { - ret =3D asprintf(&new_name, "%s/%s/", - counter->pmu_name, counter->name); + int len =3D config - name; + + if (config[1] =3D=3D '/') { + /* case: event// */ + ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 2); } else { - ret =3D asprintf(&new_name, "%s [%s]", - counter->name, counter->pmu_name); + /* case: event/.../ */ + ret =3D asprintf(&new_name, "%s/%.*s,%s", pmu_name, len, name, config += 1); } + } else { + config =3D strchr(name, ':'); + if (config) { + /* case: event:.. */ + int len =3D config - name; =20 - if (ret) { - free(counter->name); - counter->name =3D new_name; + ret =3D asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config += 1); + } else { + /* case: event */ + ret =3D asprintf(&new_name, "%s/%s/", pmu_name, name); } } - - counter->uniquified_name =3D true; + if (ret > 0) { + free(counter->name); + counter->name =3D new_name; + } else { + /* ENOMEM from asprintf. */ + counter->uniquified_name =3D false; + } } =20 static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *= config) @@ -1559,6 +1587,31 @@ static void print_cgroup_counter(struct perf_stat_co= nfig *config, struct evlist print_metric_end(config, os); } =20 +static void disable_uniquify(struct evlist *evlist) +{ + struct evsel *counter; + struct perf_pmu *last_pmu =3D NULL; + bool first =3D true; + + evlist__for_each_entry(evlist, counter) { + /* If PMUs vary then uniquify can be useful. */ + if (!first && counter->pmu !=3D last_pmu) + return; + first =3D 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 =3D 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, st= ruct perf_stat_config *conf .first =3D true, }; =20 + disable_uniquify(evlist); + if (config->iostat_run) evlist->selected =3D evlist__first(evlist); =20 --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4778199958 for ; Tue, 10 Sep 2024 15:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981472; cv=none; b=EEzEnOy4E/h431MHRBsmoQHSDuTynAvQlvByEXUCMt+3bjfT0TzftkqjbqzCjOQHOfu4cSAyTluBzBP/9p4/w/gEOWkDUCCZlaprqPZuF7aUE9iPfElv2yT4AIB4+QZw4TVJuIJ4qsjpawlPT60XPEiC5SnPnp0u74MRbeTUf7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981472; c=relaxed/simple; bh=jN1GZFeCTZXfRuDUnEMpkBYWF2lt7rqCCZEFipQEfxg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kM8hCksep1EWX++2zw6LhTi7vYDjq1UIToH8Rp+FdetjiZAs3YzpH18imBxr2JOoFliMOUUQlcYqhMQWhi18Zjt3TlszHSmbXz4lXDT6SjOZ6Fkzau1az42EaDEjF7US2UE0emiRG/irQEzKC7I4dTgFKIDgzEaTiKh3VuyeN8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=eScFeO8y; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eScFeO8y" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-428e1915e18so48581015e9.1 for ; Tue, 10 Sep 2024 08:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981468; x=1726586268; darn=vger.kernel.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=8obcz6EEHU0Z0kerHYVFWB7iJXABtv+kvQ69UsUTapg=; b=eScFeO8yhxUfEXzxZ2Gnx5yYNZ8keF19vg28IbxboCHCqEN/Lshk4Uc+tT33nkjWPK K4VW7ZRnoFjwyibn471ThNqlJiJKsyNIOU4Zcc5er0yAvlF/qiIOymj71vod6kaMWV/3 Ji5OY6hsccPffqaJp6P48qRMzqTjQ8dlXGG/oCLn1NRzUUonhkL/tPkF1vwaB4DCBxfg k+jl/AsgdNHuEjH0uP1z6eeSimY5KFLy0pQTNypqMT5IaKvNVTNpJlJMryQb91CUZcS1 vb7SrIlwk+xgZHBF4wDfG7VxSDnVWOEgklrUDz8cqfZb0+fo0ZsX6UW60D2VOD5qP8/S j0nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981468; x=1726586268; 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=8obcz6EEHU0Z0kerHYVFWB7iJXABtv+kvQ69UsUTapg=; b=aDCbYA1085Thk3J+bDOGAS1IhK4GMyCkmcvT6Y3gO3BtC9g+NpcCgjYPBTqW9icyfW kDpgwe1f2nrC1pviqHz3DySGBkiNMTt4e+LAYJjVeDAakFLD3noWIUkU7lbiIQdA7lZ4 PJ494l7zitc0LNNO9GqVLrpSWoAyaG5qvpN0JVvXv3qB3QeAyQ3i8x22WumERi582Sl8 Qdy4pPCvCiHlIQXcujFIvfiSLRAugmXaVoVVbYPWSrO2l3OLLFf5v7C99xgOs1orVU8P VEiWwkwJfEBsmiae0iNJxPTE84yHfB8Lrm1wcluOk6aFvmjpmqs/67NJwjbqTwDYV+93 7FeA== X-Forwarded-Encrypted: i=1; AJvYcCVX9OPnHeK43gyU1hnR7PVMM2v3c4VYOx344qbGJeXhgo5FJELIFlCnWWu9Cdt+2wpupzBJg/UW6b6HveM=@vger.kernel.org X-Gm-Message-State: AOJu0YzNPrTWphJzp+5cRUkQ/9FMYBQRMWYY3+Tn1APX//yANthKrdgr 3k4XZxaHCBLDvJCz1ZTyiDdSAz8U7S+7tk0P2oHIOGz8ErvoJ/ZGnS/ay1fEBRY= X-Google-Smtp-Source: AGHT+IHBosBYHbscfXArXSavcU076BXchMLneb5hcn0/19lLgw8kvPy7hrdXRGVTOc0ys/MXNU/iig== X-Received: by 2002:a05:6000:25a:b0:371:9360:c4a8 with SMTP id ffacd0b85a97d-378895b7966mr7283314f8f.6.1725981467805; Tue, 10 Sep 2024 08:17:47 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:17:47 -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 , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 3/7] perf stat: Remove evlist__add_default_attrs use strings Date: Tue, 10 Sep 2024 16:16:21 +0100 Message-Id: <20240910151640.907359-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3DfVABSBZnsmtRn1uF-k-G1GWM-L5Sgi= inhPTfHbQsKXb_g@mail.gmail.com/ Acked-by: Namhyung Kim Signed-off-by: Ian Rogers [Don't display unsupported default events] Signed-off-by: James Clark Acked-by: Kan Liang --- 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/e= vlist.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" =20 -static int ___evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - LIST_HEAD(head); - size_t i =3D 0; - - for (i =3D 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - if (perf_pmus__num_core_pmus() =3D=3D 1) - return evlist__add_attrs(evlist, attrs, nr_attrs); - - for (i =3D 0; i < nr_attrs; i++) { - struct perf_pmu *pmu =3D NULL; - - if (attrs[i].type =3D=3D PERF_TYPE_SOFTWARE) { - struct evsel *evsel =3D evsel__new(attrs + i); - - if (evsel =3D=3D NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - continue; - } - - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - struct perf_cpu_map *cpus; - struct evsel *evsel; - - evsel =3D evsel__new(attrs + i); - if (evsel =3D=3D NULL) - goto out_delete_partial_list; - evsel->core.attr.config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; - cpus =3D perf_cpu_map__get(pmu->cpus); - evsel->core.cpus =3D cpus; - evsel->core.own_cpus =3D perf_cpu_map__get(cpus); - evsel->pmu_name =3D 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 pe= rf_stat *st) } =20 /* - * 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[] =3D { - - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_TASK_CLOCK }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_CONTEXT_SWITCH= ES }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_CPU_MIGRATIONS= }, - { .type =3D PERF_TYPE_SOFTWARE, .config =3D PERF_COUNT_SW_PAGE_FAULTS }, - - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_CPU_CYCLES }, -}; - struct perf_event_attr frontend_attrs[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_STALLED_CYCLES= _FRONTEND }, -}; - struct perf_event_attr backend_attrs[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_STALLED_CYCLES= _BACKEND }, -}; - struct perf_event_attr default_attrs1[] =3D { - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_INSTRUCTIONS = }, - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_BRANCH_INSTRUC= TIONS }, - { .type =3D PERF_TYPE_HARDWARE, .config =3D PERF_COUNT_HW_BRANCH_MISSES = }, - -}; - -/* - * Detailed stats (-d), covering the L1 and last level data caches: - */ - struct perf_event_attr detailed_attrs[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_LL << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - 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[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1I << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_DTLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_ITLB << 0 | - (PERF_COUNT_HW_CACHE_OP_READ << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, - -}; + const char *pmu =3D parse_events_option_args.pmu_filter ?: "all"; + struct parse_events_error err; + struct evlist *evlist =3D evlist__new(); + struct evsel *evsel; + int ret =3D 0; =20 -/* - * Very, very detailed stats (-d -d -d), adding prefetch events: - */ - struct perf_event_attr very_very_detailed_attrs[] =3D { - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) }, - - { .type =3D PERF_TYPE_HW_CACHE, - .config =3D - PERF_COUNT_HW_CACHE_L1D << 0 | - (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) | - (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) }, -}; + if (!evlist) + return -ENOMEM; =20 - struct perf_event_attr default_null_attrs[] =3D {}; - const char *pmu =3D parse_events_option_args.pmu_filter ?: "all"; + parse_events_error__init(&err); =20 /* Set attrs if no event is selected and !null_run: */ if (stat_config.null_run) - return 0; + goto out; =20 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 =3D -1; + goto out; } - return metricgroup__parse_groups(evsel_list, pmu, "transaction", + ret =3D 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; } =20 if (smi_cost) { @@ -1964,26 +1861,29 @@ static int add_default_attributes(void) =20 if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) { pr_err("freeze_on_smi is not supported.\n"); - return -1; + ret =3D -1; + goto out; } =20 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 =3D -1; + goto out; } smi_reset =3D true; } =20 if (!metricgroup__has_metric(pmu, "smi")) { pr_err("Missing smi metrics\n"); - return -1; + ret =3D -1; + goto out; } =20 if (!force_metric_only) stat_config.metric_only =3D true; =20 - return metricgroup__parse_groups(evsel_list, pmu, "smi", + ret =3D 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; } =20 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 =3D -1; + goto out; } if (stat_config.topdown_level > max_level) { pr_err("Invalid top-down metrics level. The max level is %u.\n", max_le= vel); - return -1; - } else if (!stat_config.topdown_level) + ret =3D -1; + goto out; + } else if (!stat_config.topdown_level) { stat_config.topdown_level =3D 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] =3D stat_config.topdown_level + '0'; - if (metricgroup__parse_groups(evsel_list, + if (metricgroup__parse_groups(evlist, pmu, str, /*metric_no_group=3D*/false, /*metric_no_merge=3D*/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 =3D -1; + goto out; + } } =20 if (!stat_config.topdown_level) stat_config.topdown_level =3D 1; =20 - 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 =3D PERF_COUNT_SW_CPU_CLOCK; + ret =3D parse_events(evlist, "cpu-clock", &err); + else + ret =3D parse_events(evlist, "task-clock", &err); + if (ret) + goto out; + + ret =3D 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; =20 - 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 =3D evlist__new(); - struct evsel *metric_evsel; - - if (!metric_evlist) - return -1; =20 + if (!metric_evlist) { + ret =3D -ENOMEM; + goto out; + } if (metricgroup__parse_groups(metric_evlist, pmu, "Default", /*metric_no_group=3D*/false, /*metric_no_merge=3D*/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 =3D true; - metric_evsel->default_metricgroup =3D true; + &stat_config.metric_events) < 0) { + ret =3D -1; + goto out; } - evlist__splice_list_tail(evsel_list, &metric_evlist->core.entries); + + evlist__for_each_entry(metric_evlist, evsel) + evsel->default_metricgroup =3D 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; } =20 /* Detailed events get appended to the event list: */ =20 - 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 >=3D 1) { + /* + * Detailed stats (-d), covering the L1 and last level data + * caches: + */ + ret =3D parse_events(evlist, + "L1-dcache-loads," + "L1-dcache-load-misses," + "LLC-loads," + "LLC-load-misses", + &err); + } + if (!ret && detailed_run >=3D 2) { + /* + * Very detailed stats (-d -d), covering the instruction cache + * and the TLB caches: + */ + ret =3D 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 >=3D 3) { + /* + * Very, very detailed stats (-d -d -d), adding prefetch events: + */ + ret =3D parse_events(evlist, + "L1-dcache-prefetches," + "L1-dcache-prefetch-misses", + &err); + } +out: + if (!ret) { + evlist__for_each_entry(evlist, evsel) + evsel->skippable =3D true; + } + parse_events_error__exit(&err); + evlist__splice_list_tail(evsel_list, &evlist->core.entries); + evlist__delete(evlist); + return ret; } =20 static const char * const stat_record_usage[] =3D { @@ -2760,7 +2693,7 @@ int cmd_stat(int argc, const char **argv) } } =20 - if (add_default_attributes()) + if (add_default_events()) goto out; =20 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 =20 -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 =3D 0; i < nr_attrs; i++) { - evsel =3D evsel__new_idx(attrs + i, evlist->core.nr_entries + i); - if (evsel =3D=3D 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_a= ttr *attrs, size_t nr_attrs) -{ - size_t i; - - for (i =3D 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); =20 -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); =20 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; =20 + /* + * Skip unsupported default events when not verbose. (default events + * are all marked 'skippable'). + */ + if (verbose =3D=3D 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)); } =20 -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 =3D PERF_COUNT_HW_CACHE_L1D | @@ -152,7 +152,7 @@ static const char *get_ratio_color(const double ratios[= 3], double val) =20 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 =3D evsel_context(evsel); =20 evlist__for_each_entry(evsel->evlist, cur) { --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDFB4188CC1 for ; Tue, 10 Sep 2024 15:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981488; cv=none; b=OrnBVHdlXgb7tNHirsgSsHtBcAr0h88nWPi1UMvYCeTKFezDVIziplBzsK3Y9yWXIQXMi6UqAzNQi0ZaTqpDnVJG37gnGyh53NIK3GPek6bmIbBk2UtbIBC3l5w4s2wxKzMOY2sc9NqpCFAgEiCAQfKrBcczRiqpL6UHnMdJXUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981488; c=relaxed/simple; bh=q1Kxi5uJOOpz5sbB76n+6+jBjcdqXi06psYDtou9fos=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HpWxRyz7vf88FDT6qi7pfGT4VJle808DbtaxmG+KVN6f8hX7PeJIIIUiFr8Ib6BNWR5Isai2xAmObdGyltWQ5DOjJMX81afv+tDSsFHcbPkkGOpc8ttGz+2vAD1MhZ9G0Q0VBH7kSs+KwNVlUNWZGxCmOcth9W54i+0cOGtvUlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=T+3ErAcR; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="T+3ErAcR" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42cafda818aso31608825e9.2 for ; Tue, 10 Sep 2024 08:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981485; x=1726586285; darn=vger.kernel.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=SbXzulT1hvclpO2gUzyU2PPxHH5lSuW+E82Abjkw8Ls=; b=T+3ErAcRB58eHpW+R4OcC853JipIUWmTl+xfQgvf7WP1JQo5WHM9H3WGSaG4uXp1vQ hJWXkvEW6KzHkltpROPsuXr2eN8UPpk5XkyIXxWCR1tx0lbNgg24rSyoZJ/OBhTHPioT GIh25zuVU5qC5G7N2weWrw+1qHgT0a4Q5nI5rAtcJ17VPvXhFL4PuJbXvOJCMopyJrOK AjEFLL+PRUTE8qF6JpQVXDB2utl0s33yquNYMQIAwDqoPl4iutuOk+6JfxHIAiGAT7RB gRdGqlU1cacR+5nnsNZVzfAH+P+CpqcUzbTPheEhf8RAhkuq1xVLIdJ1x56FGJXItxX4 WhTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981485; x=1726586285; 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=SbXzulT1hvclpO2gUzyU2PPxHH5lSuW+E82Abjkw8Ls=; b=cKkKmI0EuxAV8rlAYpYTBXMmheTt3i8xa3hbQjuPXH8EajCyEdaoc/uSyXajb9aRt4 F6kM6vA7kxUwyzSA6lpLO1a2eo6Ndjg0gJcGjUp99FQOW9huKEgCIOQHHrAHBgxnvWko +l22JsZDb7zn4ONorvh0WwEI2pYnCAu+rGdqkqaxjauKdF+jJhPDOLiosJUtrbi/ZVg5 4FvvQq46UFdl5SWF7begkiOwoSz0kdISJPzX7dVLIKV80lF6KPrPa7NN9sXT+5DXu3y6 O2QgzWBHeNR86kVLPIdYD0bRI2x6GmTLPl18rS8Bj3OkwhyVaHqBoIJO2q91lJxLN4u7 nwaQ== X-Forwarded-Encrypted: i=1; AJvYcCXfQXWYuHM3oXtcHw7tJHK24Ala5Y3MgxN4RFFYRxX41iPMMJvQV2/TQ6hXrwNayubThTa7R6a8Xg4lVnM=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ6LZkj8Be0/ep4r8T06uFykgnjxVDz4ESmtDHw+fU+X9iINXH THPSz4sRsleuTwrPQcMSowCuOUPvaJW+/+JCPHh2ujMqiIWM8fcYL3ulFdqEXys= X-Google-Smtp-Source: AGHT+IGLuI3uuWRzeekOoiV/Leqs/HePhibFQkWY9zQigVvbRn3rucJiuFLpiP3IkkkJklG+SpMqAg== X-Received: by 2002:a05:600c:a4c:b0:426:602d:a246 with SMTP id 5b1f17b1804b1-42c9f9d842cmr118945155e9.32.1725981484964; Tue, 10 Sep 2024 08:18:04 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:18:04 -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 v7 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Tue, 10 Sep 2024 16:16:22 +0100 Message-Id: <20240910151640.907359-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Acked-by: Namhyung Kim Signed-off-by: Ian Rogers Signed-off-by: James Clark Acked-by: Kan Liang --- 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/ev= sel.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 =3D evsel->pmu_name ? evsel->pmu_name : "cpu"; + struct perf_pmu *pmu; + u32 type =3D evsel->core.attr.type; =20 /* * 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 *ev= sel) * 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 =3D=3D 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 =3D evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; + if (type) + goto again; + break; + case PERF_TYPE_RAW: + break; + default: + return false; + } + + pmu =3D evsel->pmu; + if (pmu =3D=3D &perf_pmu__fake) + pmu =3D NULL; =20 - return false; + if (!pmu) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + if (pmu->type =3D=3D PERF_TYPE_RAW) + break; + } + } + return pmu && perf_pmu__have_event(pmu, "slots"); } =20 bool arch_evsel__must_be_in_group(const struct evsel *evsel) --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0139C188CC1 for ; Tue, 10 Sep 2024 15:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981505; cv=none; b=aUsExyfQTH3XCl0VXFuN5urMe/dxEQd2e1nPWPbxSp86iVAJNDB2R9etCcvIUR6CcoXcPzv4jcJTOnsQgt6EyWha0swcmco7Xgc4i7spvAEoEV5LErdnHsSQ/R8gBA2cqmQzYuVDXUt9qRM1ZfIyrv+M1nqT7dn5Uqwsbh1KiLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981505; c=relaxed/simple; bh=uZORX5Z4Hom0H1Rz6xv3ETNi/JNd+24VDkWbazKW1ig=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HckPkHzAfma8dQUdMYobXFdPUCLYAVXzpIJ1dLOFoiYshQzJH4wdQhkIn3F4ZGAOgSfPHVIImD//rlDK7HdOwSIgNPuiYcJRIOYZn/BkaUKefnXpQ5xQospgeKpsgUByqQgK2CZvLPdEh5YXu7zGLZ8baW1Qzl1jnM21YPJgHZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=r3RfgSuU; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="r3RfgSuU" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-374bfc395a5so3405276f8f.0 for ; Tue, 10 Sep 2024 08:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981502; x=1726586302; darn=vger.kernel.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=g8NhH4cLyJdMPKno/pyxaINagAni1zbV6XKosaHRnjk=; b=r3RfgSuUFqBZcp2Vr5MFD5o7iL+YtmTYbFRysIDLw8x2TMyMtcGGV9PgLSNzUiyYOr 47jw6aGgiozCcApLwShYCCI0ouj1actD2bR0io1iEKgMQ3LV084y3xlh0iXZ1STEaraP qliIjX53vjkxRrqNjhnHMvD1+UFz0jOEs4AvoBqotqc1UMoMfIcbxQC5ik3ODLK2mRVH yeZjxPiL9RX1aaG9SWkAECjFMOJr36ZAdmkTPZ0tTAKcXu62/we5AMi+N/kF8GjKRaoZ p4Qk0rfp7VT2QrADJh2JK30jgyC2la+Sv02aFPf4b4r5PI6h9kvc9LcEHke/2BGwlhrl +HEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981502; x=1726586302; 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=g8NhH4cLyJdMPKno/pyxaINagAni1zbV6XKosaHRnjk=; b=w3awizTygye/RDIODC+ESqTkQLkQYFHFz0/IibLwD8n0tFsymUegZV/UpRlghZIGdO 2HAtQVffGfyDHB0+pgutdLjiV4/YC0bby1qX0yF01A2PtQCHe6f7vMGqRRZJPE8V4CDv Xa4LfDrK3HEBsXlKsS51u0Kt3xY4asTz0f20V/jLKDUXhGLyOQbx7SnzGZTTktQ+8ktC 5fYvohiO06VT6lT4EYq9BkVnxkvwrKRg7la7dA+6Ln6USDHfavY8iLkFnrE/xY0xhuic FxEcATJwbVlbUCYegMoNQAQhJyeko3r+CZxRMAuH1OAvY38jVfL0VT181HP1j0tZqt6R O/rA== X-Forwarded-Encrypted: i=1; AJvYcCVGVgQXp7eTVO0U9w3cPtZE87fzpNw4M17eXqpcWB8mPAV1jVBI3tLKkrIVvO/H5akz7WZIaLWRA6XFFPM=@vger.kernel.org X-Gm-Message-State: AOJu0YzjPS0J78+2CHB25E2Kw6dWcSP4mubtwPslEbU6FTBZTAbSeFPt wwr+WcasextozL7E5gdw8sP1nDb1d9xbYM1g/v0CD7tw+PWRWYpobSjh3iz46c8= X-Google-Smtp-Source: AGHT+IGVydiv3lO6lRO3jNqvMFWGGUzCe8fr2SCXgIVNrBURyV1JvQv+cbY7YgpL1u+7E3klqY/zlQ== X-Received: by 2002:a5d:4cc5:0:b0:371:6fc7:d45d with SMTP id ffacd0b85a97d-378a89fd663mr1974341f8f.2.1725981502163; Tue, 10 Sep 2024 08:18:22 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:18:21 -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 , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 5/7] perf evsel: Remove pmu_name Date: Tue, 10 Sep 2024 16:16:23 +0100 Message-Id: <20240910151640.907359-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Acked-by: Namhyung Kim Signed-off-by: Ian Rogers [ Fix arm-spe.c usage of pmu_name and empty PMU name ] Signed-off-by: James Clark Acked-by: Kan Liang --- 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/u= til/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_re= cord *itr, =20 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 =3D true; diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.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, si= ze_t size) return scnprintf(bf, size, "%s", event_name); =20 return scnprintf(bf, size, "%s/%s/", - evsel->pmu_name ? evsel->pmu_name : "cpu", + evsel->pmu ? evsel->pmu->name : "cpu", event_name); } =20 @@ -129,7 +129,7 @@ int arch_evsel__open_strerror(struct evsel *evsel, char= *msg, size_t size) return 0; =20 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; =20 /* More verbose IBS errors. */ diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 639e65a9bf61..dbb80db63184 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -731,7 +731,7 @@ static int test__checkevent_pmu_events(struct evlist *e= vlist) =20 TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D 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..4835d5aa5c48 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 =3D empty_attributes; =20 - 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 =3D 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 =3D NULL; evsel->per_pkg_mask =3D NULL; evsel->collect_stat =3D false; - evsel->pmu_name =3D NULL; evsel->group_pmu_name =3D NULL; evsel->skippable =3D false; evsel->alternate_hw_config =3D PERF_COUNT_HW_MAX; @@ -394,11 +393,6 @@ struct evsel *evsel__clone(struct evsel *orig) if (evsel->group_name =3D=3D NULL) goto out_err; } - if (orig->pmu_name) { - evsel->pmu_name =3D strdup(orig->pmu_name); - if (evsel->pmu_name =3D=3D NULL) - goto out_err; - } if (orig->group_pmu_name) { evsel->group_pmu_name =3D strdup(orig->group_pmu_name); if (evsel->group_pmu_name =3D=3D 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; =20 - /* for missing_features */ + /* The PMU the event is from. Used for missing_features, PMU name, etc. */ struct perf_pmu *pmu; =20 /* 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; =20 /* 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 3db402f2461a..cf3b37547221 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -263,7 +263,6 @@ __add_event(struct list_head *list, int *idx, evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; - evsel->pmu_name =3D pmu ? strdup(pmu->name) : NULL; evsel->alternate_hw_config =3D alternate_hw_config; =20 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 =3D 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]; =20 /* @@ -584,21 +584,21 @@ static void perf_stat__print_metricgroup_header(struc= t 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 !=3D evsel->pmu) { out->print_metricgroup_header(config, ctxp, NULL); return; } } =20 - 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->nam= e); else scnprintf(full_name, sizeof(full_name), "%s", name); =20 out->print_metricgroup_header(config, ctxp, full_name); =20 last_name =3D name; - last_pmu =3D evsel->pmu_name; + last_pmu =3D evsel->pmu; } =20 /** 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, stru= ct evsel *evsel_b) if (evsel__is_clock(evsel_a) !=3D evsel__is_clock(evsel_b)) return false; =20 - return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); + return evsel_a->pmu !=3D evsel_b->pmu; } =20 static void evsel__merge_aliases(struct evsel *evsel) --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 805B9188CC1 for ; Tue, 10 Sep 2024 15:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981523; cv=none; b=qFvwMkzAOlZdRRAuui8JlOmyg9SS/FnZeRXNsXODDdM6pvUEnRkV1ovvgbaKZUl5vuVJJ+A3Y+KemTJsQuHZR3WjhvmD2HqOYWB3vgeRv1YKDgQTxJSPA5uKU3I1Tzvo605L6LlB2MAMjM35VQcfhPAjfd3EcglkelJdH8MtKBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981523; c=relaxed/simple; bh=hd7oyorl4TOQWVxg+vhsoBj05DEdVB7R33IhLz/6S/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bto6b41b8mYyGL8JHrk/isX6u0UJOXaRBJo2U6fNEmMyZzhK0okYiNvI5HK0vJpJfWhMZWAfTwvFBnkdnFswaI5hJDryGTdG41tI2YmDPK6FJd+PxJkIy6qqMWDwnztGcvhJhK2JC+JcPF0gD67qR346i/kyWK4JWhYCsigTMig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=fZ1QPh7W; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fZ1QPh7W" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-374c1963cb6so3562235f8f.3 for ; Tue, 10 Sep 2024 08:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981520; x=1726586320; darn=vger.kernel.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=ZV/wWyP/OuoFa1Q1XSAgXw1mLQzgLi2JT0YhtXRGetA=; b=fZ1QPh7WHjyKH+VrNKGazUVUSD+fGshtPmNA+qVsDwEFqoYBTyUitvY76gznjJ03eX g+iSoSU6EIwwc/Ggp60IzInmrQolcI/nScRJB9vGNdOybhEJLy3JUBraSrtmoFFo5JpO gRJtNYehkRZIE8Wth2xbUz64b0pK9AM72Fh+zUt0ExpVzbzMU6slNyXW6O9r60HT+kU1 NscqMDFRct4iyULzmT2bL0hiBidXv79Ns4j5tu3INC5sKE8woKBq10AwbYFGtIvx5/6h Lzbu0UWsW3yA+JZaMRtYdq6xQcnVz9KSHl+JfrQ6RCdz7ZPsR9W3Bo71t0hu3oBC3OQY U/Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981520; x=1726586320; 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=ZV/wWyP/OuoFa1Q1XSAgXw1mLQzgLi2JT0YhtXRGetA=; b=bo50R9J2egy9qoKRgWz31b1tsjxIH/aVkN3OANiK7ZSBVsVbwwSwTCaKY6EFE/QWSo vhG3n8vIValSc2WbICDuuYjCkq8MTH46RycoC52io+c9B03c7BHrw+27X3tcwl3Jb9TX /XdLrXU33/Hdr53N4+kRgz25SQxqWB9I9QFaQvLovfSVMsjvfUhrbyqFGI7AOZy+wIj+ 5gIq/+LwbZqmuHkSXl9snzv9jSjEGxIda9r+gtHhKax9/E58Pr7FoORbntGqgBi/T0En cN08tAriwn54w4TfBHeGt6b5DJHHqQy1j4BGZrIxemslla3778TvH56TeU71DA4j7bmx wgEw== X-Forwarded-Encrypted: i=1; AJvYcCW812wehbsE7rKDJFs7as/4yp9GSufmreil0JZBIuo6RN7eyZog5agGJ9c1NBrTfYisN8qoviJWiEZEb04=@vger.kernel.org X-Gm-Message-State: AOJu0YziVfuAfEbM0le+DCJ+eLNpM2SBqO1cfphl+ZbXRphMUkF2/mTm H4Kc9xyXeLR9TOS4ET9aBPukw7eJuScdOt50Y9k2qEhrV58YUKEdgdyqDxL3QPw= X-Google-Smtp-Source: AGHT+IFvmRJ3kwcH44X8tEVQpW/XuglOxSPCkP6MHjK2ehbvCFJ8Z5bWzyalPeu3oqnDHG3TOgB6LQ== X-Received: by 2002:adf:e544:0:b0:368:445e:91cc with SMTP id ffacd0b85a97d-378895c9deemr10636514f8f.21.1725981519545; Tue, 10 Sep 2024 08:18:39 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:18:38 -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 , Yanteng Si , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 6/7] perf test: Make stat test work on DT devices Date: Tue, 10 Sep 2024 16:16:24 +0100 Message-Id: <20240910151640.907359-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Acked-by: Namhyung Kim Signed-off-by: James Clark Acked-by: Kan Liang --- 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() { =20 # Find a known PMU for cputype. pmu=3D"" - for i in cpu cpu_atom armv8_pmuv3_0 + devs=3D"/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=3D$(basename "$i") + if test -d "$i" then - pmu=3D"$i" + pmu=3D"$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=3D"$i" + pmu=3D"$i_base" break fi done --=20 2.34.1 From nobody Sat Nov 30 07:23:28 2024 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11036199FA9 for ; Tue, 10 Sep 2024 15:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981539; cv=none; b=CGcJ/scQ9bbD1s8FaTYH5MxfFRWGpOXeAVIOJxYp3kNs4TGNufipgOwwEJfdCXkQzh/QIkWw6oC8+QaF6yBHwCc+e3puHWDT/nfSEMoed8xX/dZJ+GqvcyvRoR5X/07/2+uQi+qRCj1OcWeo21q703Y62ByffudNkZiQGjqylJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981539; c=relaxed/simple; bh=B7L8eicaLL/uQdqZZRGKF332ltFTMFjZxuNmtoxY+qE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OjrubYfKtbHk1CpDDrKj8qeXPoiBTADvBD6OfFaXsTD49JX72+5Zs4FjjlcKz2aKelMC1PzTxYzbaNxcBZyVqZhkAdYlUcKBJvi5GekBVC2M6Le+Fsem5N3XVfV15EsxR1M0LBDkhXHEZn+iwOAZGR3bgRC8weXHBqKOUSUjPjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gEr7/BtE; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gEr7/BtE" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-374c326c638so4231297f8f.2 for ; Tue, 10 Sep 2024 08:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981536; x=1726586336; darn=vger.kernel.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=gzYejL55jw2kalTO5A0DRq7hhLyM8T3G+Vfejwo9sVk=; b=gEr7/BtE13W5sDCDX8u125oEB9fkDvvPXsLSfAqeMfWLFDS9sELGm/hWoFEhk2gyGJ Mrm5gubKEpHrCNNWb1a0Fh87VCIRU5yluJ4jWaz7RTPhWlLYm1SYM1jL7LOMA5I/Pxhy b+wYVSJHf9okd75fb1jgxAjuHljf42J4Z2eB3gCthb1EU0GVSCkuCsupTH412I5f1zna huWrggSs5ffDt2GFyp8TmCpQy8y6qdimvTOK+AM+zVJneZ0naKMZ15bFLlR+i6wXMxYg mJBbEDQiFIGgkDfQl4NcCEkVn5ltkwpZBDuS1bwx0FMTQ6CLn71Ho1ukT7mkoTyVNy8r qCvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981536; x=1726586336; 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=gzYejL55jw2kalTO5A0DRq7hhLyM8T3G+Vfejwo9sVk=; b=l59V1rzqS9nYfBoWYbAleHTNB/lKd0aGjw99ZYy0T5m4+yrbQ4tldvtYljfgouT8tV wHJb6QUEoq1F6UJZXaF6G+Chz/8KXj5Rk431ug3rqnrb/IjV9KYdjLKiJldZejZ+98Rt AoCgyNuK/K6o0Tw7yEv3rgJ/fcjyVgh1w77ffpIhEl5g0bQfXFHU/ZjjIRiBhmqd1iQT QZ/jO8a1XIndepxY8EJZFU80XPkXr8aWZ2IdNMRxl7BaMmfMQh5lbsDIzkoTCG9yXdGa oF183mTcnfdFHwM+wEquAP5jhnqeDrU1Wy6tSH0VdZBDC+kvVYRhlhmtB/XMav0Kp5/r /uTg== X-Forwarded-Encrypted: i=1; AJvYcCU+v1nO7ZGymcALhTYGUtEbKlwg1xLlBuL4p7+MEEMZTzjLUoCRDOJGDwEdUsB+r+RQOGcwER0eGcV9dcI=@vger.kernel.org X-Gm-Message-State: AOJu0YxWPqSORTtuKuNSOd+zCbqHPlLdgRpReqiEefcGAa2mkEehrq/6 smkX6o3auGpug10uAp5bbDRskCCI6RJCbCFeuyeTYLAYBkq/yxHXZstsIBgT7yM= X-Google-Smtp-Source: AGHT+IHy/RhwX57CcCqc82tipU7Ic/6+Q/to0vq5e7VGq8SEkdeQH7tu0qUqClXsdQ0xyoyauIPQiA== X-Received: by 2002:a05:6000:d05:b0:374:b399:ad6e with SMTP id ffacd0b85a97d-378895f20damr9927699f8f.35.1725981536253; Tue, 10 Sep 2024 08:18:56 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:18: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 , Athira Rajeev , Dominique Martinet , Yang Jihong , Colin Ian King , Howard Chu , Ze Gao , Yanteng Si , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 7/7] perf test: Add a test for default perf stat command Date: Tue, 10 Sep 2024 16:16:25 +0100 Message-Id: <20240910151640.907359-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Acked-by: Namhyung Kim Signed-off-by: James Clark Acked-by: Kan Liang --- 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]" } =20 +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=3D$(ls /sys/bus/event_source/devices/*/cpus 2>/dev/null | wc -l) + if [ "$pmus" -lt 1 ] + then + pmus=3D1 + fi + + # Run default Perf stat + cycles_events=3D$(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=3D1 + 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 --=20 2.34.1