From nobody Fri May 8 09:57:42 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14761C433F5 for ; Sat, 7 May 2022 05:34:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445661AbiEGFiI (ORCPT ); Sat, 7 May 2022 01:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238607AbiEGFiF (ORCPT ); Sat, 7 May 2022 01:38:05 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F011AF2B for ; Fri, 6 May 2022 22:34:17 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2f7ee6bc6ddso81927357b3.1 for ; Fri, 06 May 2022 22:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=uRh0OB02KtllfhwOU5rNTHuECFQjo2cJmquafVll4ec=; b=pVoNB23y4+g9luuKLXC4ta6e0auBYD5qdn/1MBw3kb77j11MMrluzqYTFaywGg/sNM LMP3PJ18B0K0+ol5tVmMt2+oCumV8oPmZGM/UFFul6WCCbsJl9xl8WTsNqi/eyAySCyr NhsA8j4mp82GyrR/nSDgHvjRDAFbOtFoQs6Zk602FIG+AGQViIMDBzH7aN5Pisd+MwSJ yGA2USLQfgy4Y04zIxapDexhC52fT74QocwtosFdE1ahCggAKP5kyxXLKFJcyRYx9xWU HX7ZiE9Sh5xz2BEtVZg+Q+75cWK0Tmfn48141m1lzPDYAcBssW3EASXrDQPlL8IATDb5 bXLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uRh0OB02KtllfhwOU5rNTHuECFQjo2cJmquafVll4ec=; b=P0aNXpaeRpvEdfWew7iBmHPjJBmOE9vbqyDyqF8LKl5eFH2CBbiVDvZeqifsLeRyVW aRoc3aqSLDGr2/06N76iega0CciL5lEqB2HTVD2ABH/8DUMbB1Lold05SJOhGDtw/aWy 395UuxJ2vzqxeXWcSKEiEIhDi/MCpQxLMmjMIuQqTFSGqGKpQZawkfgwe5J/6lmjOHmL OfMEL4nqUTGxXfMDQBZ3JDADQMRRTNYnVF9j3blbfzAA4qzIVCrvmJhU3JDP3R6G4c46 QWmx89m4OfOU2Hca74yyrrPW37vjjhz8E16Lnf0WPq2i0UX+UswjBI7GxTZb6Q11wZhG LCJw== X-Gm-Message-State: AOAM531xzQw2f9w5/gxRnb53aPALtwcKFMpkW6bvJWpUx0+ugBBB0dpQ M6L+fRaudmccnFVKwAKzi6umWi0AbjHM X-Google-Smtp-Source: ABdhPJxvl48EoT2c9kzdVHWoEtdZ2kR0mwbTeQ1roYREq5YMMgO7PckMiVZI20NEnzyV8HtexzEi0QP1EbCj X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:bf2a:2f64:a273:3573]) (user=irogers job=sendgmr) by 2002:a81:8102:0:b0:2f8:f5fb:b805 with SMTP id r2-20020a818102000000b002f8f5fbb805mr5725063ywf.128.1651901657117; Fri, 06 May 2022 22:34:17 -0700 (PDT) Date: Fri, 6 May 2022 22:34:06 -0700 In-Reply-To: <20220507053410.3798748-1-irogers@google.com> Message-Id: <20220507053410.3798748-2-irogers@google.com> Mime-Version: 1.0 References: <20220507053410.3798748-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 1/5] Revert "perf stat: Support metrics with hybrid events" From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Riccardo Mancini , Kim Phillips , Madhavan Srinivasan , Shunsuke Nakamura , Florian Fischer , Andi Kleen , John Garry , Zhengjun Xing , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit 60344f1a9a597f2e0efcd57df5dad0b42da15e21. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 263 +++------------------------------ tools/perf/util/stat-display.c | 8 +- 2 files changed, 22 insertions(+), 249 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 126a43a8917e..d8492e339521 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -141,11 +141,6 @@ struct metric { * output. */ const char *metric_unit; - /** - * The name of the CPU such as "cpu_core" or "cpu_atom" in hybrid systems - * and "NULL" in non-hybrid systems. - */ - const char *pmu_name; /** Optional null terminated array of referenced metrics. */ struct metric_ref *metric_refs; /** @@ -220,7 +215,6 @@ static struct metric *metric__new(const struct pmu_even= t *pe, } m->metric_expr =3D pe->metric_expr; m->metric_unit =3D pe->unit; - m->pmu_name =3D pe->pmu; m->pctx->runtime =3D runtime; m->has_constraint =3D metric_no_group || metricgroup__has_constraint(pe); m->metric_refs =3D NULL; @@ -256,12 +250,10 @@ static bool contains_metric_id(struct evsel **metric_= events, int num_events, * @ids: the metric IDs to match. * @metric_evlist: the list of perf events. * @out_metric_events: holds the created metric events array. - * @pmu_name: the name of the CPU. */ static int setup_metric_events(struct hashmap *ids, struct evlist *metric_evlist, - struct evsel ***out_metric_events, - const char *pmu_name) + struct evsel ***out_metric_events) { struct evsel **metric_events; const char *metric_id; @@ -294,10 +286,6 @@ static int setup_metric_events(struct hashmap *ids, * about this event. */ if (hashmap__find(ids, metric_id, (void **)&val_ptr)) { - if (evsel__is_hybrid(ev) && pmu_name && - strcmp(pmu_name, ev->pmu_name)) { - continue; - } metric_events[matched_events++] =3D ev; =20 if (matched_events >=3D ids_size) @@ -736,8 +724,7 @@ static int decode_all_metric_ids(struct evlist *perf_ev= list, const char *modifie static int metricgroup__build_event_string(struct strbuf *events, const struct expr_parse_ctx *ctx, const char *modifier, - bool has_constraint, - const char *pmu_name) + bool has_constraint) { struct hashmap_entry *cur; size_t bkt; @@ -819,18 +806,12 @@ static int metricgroup__build_event_string(struct str= buf *events, if (no_group) { /* Strange case of a metric of just duration_time. */ ret =3D strbuf_addf(events, "duration_time"); - } else if (!has_constraint) { - ret =3D strbuf_addf(events, "}:W"); - if (pmu_name) - ret =3D strbuf_addf(events, "#%s", pmu_name); - ret =3D strbuf_addf(events, ",duration_time"); - } else + } else if (!has_constraint) + ret =3D strbuf_addf(events, "}:W,duration_time"); + else ret =3D strbuf_addf(events, ",duration_time"); - } else if (!no_group && !has_constraint) { + } else if (!no_group && !has_constraint) ret =3D strbuf_addf(events, "}:W"); - if (pmu_name) - ret =3D strbuf_addf(events, "#%s", pmu_name); - } =20 return ret; #undef RETURN_IF_NON_ZERO @@ -1169,13 +1150,11 @@ static int metric_list_cmp(void *priv __maybe_unuse= d, const struct list_head *l, * @metric_list: The list that the metric or metric group are added to. * @map: The map that is searched for metrics, most commonly the table for= the * architecture perf is running upon. - * @pmu_name: the name of the CPU. */ -static int metricgroup__add_metric(const char *metric_name, - const char *modifier, bool metric_no_group, +static int metricgroup__add_metric(const char *metric_name, const char *mo= difier, + bool metric_no_group, struct list_head *metric_list, - const struct pmu_events_map *map, - const char *pmu_name) + const struct pmu_events_map *map) { const struct pmu_event *pe; LIST_HEAD(list); @@ -1188,8 +1167,6 @@ static int metricgroup__add_metric(const char *metric= _name, */ map_for_each_metric(pe, i, map, metric_name) { has_match =3D true; - if (pmu_name && pe->pmu && strcmp(pmu_name, pe->pmu)) - continue; ret =3D add_metric(&list, pe, modifier, metric_no_group, /*root_metric=3D*/NULL, /*visited_metrics=3D*/NULL, map); @@ -1238,12 +1215,10 @@ static int metricgroup__add_metric(const char *metr= ic_name, * @metric_list: The list that metrics are added to. * @map: The map that is searched for metrics, most commonly the table for= the * architecture perf is running upon. - * @pmu_name: the name of the CPU. */ static int metricgroup__add_metric_list(const char *list, bool metric_no_g= roup, struct list_head *metric_list, - const struct pmu_events_map *map, - const char *pmu_name) + const struct pmu_events_map *map) { char *list_itr, *list_copy, *metric_name, *modifier; int ret, count =3D 0; @@ -1260,7 +1235,7 @@ static int metricgroup__add_metric_list(const char *l= ist, bool metric_no_group, =20 ret =3D metricgroup__add_metric(metric_name, modifier, metric_no_group, metric_list, - map, pmu_name); + map); if (ret =3D=3D -EINVAL) pr_err("Cannot find metric or group `%s'\n", metric_name); =20 @@ -1335,183 +1310,6 @@ static int build_combined_expr_ctx(const struct lis= t_head *metric_list, return ret; } =20 -static char *get_metric_pmus(char *orig_str, struct strbuf *metric_pmus) -{ - char *llist, *nlist, *p1, *p2, *new_str =3D NULL; - int ret; - struct strbuf new_events; - - if (!strchr(orig_str, '#')) { - /* - * pmu name is added after '#'. If no '#' found, - * don't need to process pmu. - */ - return strdup(orig_str); - } - - nlist =3D strdup(orig_str); - if (!nlist) - return new_str; - - ret =3D strbuf_init(&new_events, 100); - if (ret) - goto err_out; - - ret =3D strbuf_grow(metric_pmus, 100); - if (ret) - goto err_out; - - llist =3D nlist; - while ((p1 =3D strsep(&llist, ",")) !=3D NULL) { - p2 =3D strchr(p1, '#'); - if (p2) { - *p2 =3D 0; - ret =3D strbuf_addf(&new_events, "%s,", p1); - if (ret) - goto err_out; - - ret =3D strbuf_addf(metric_pmus, "%s,", p2 + 1); - if (ret) - goto err_out; - - } else { - ret =3D strbuf_addf(&new_events, "%s,", p1); - if (ret) - goto err_out; - } - } - - new_str =3D strdup(new_events.buf); - if (new_str) { - /* Remove last ',' */ - new_str[strlen(new_str) - 1] =3D 0; - } -err_out: - free(nlist); - strbuf_release(&new_events); - return new_str; -} - -static void set_pmu_unmatched_events(struct evlist *evlist, int group_idx, - char *pmu_name, - unsigned long *evlist_removed) -{ - struct evsel *evsel, *pos; - int i =3D 0, j =3D 0; - - /* - * Move to the first evsel of a given group - */ - evlist__for_each_entry(evlist, evsel) { - if (evsel__is_group_leader(evsel) && - evsel->core.nr_members >=3D 1) { - if (i < group_idx) { - j +=3D evsel->core.nr_members; - i++; - continue; - } - } - } - - i =3D 0; - evlist__for_each_entry(evlist, evsel) { - if (i < j) { - i++; - continue; - } - - /* - * Now we are at the first evsel in the group - */ - for_each_group_evsel(pos, evsel) { - if (evsel__is_hybrid(pos) && - strcmp(pos->pmu_name, pmu_name)) { - set_bit(pos->core.idx, evlist_removed); - } - } - break; - } -} - -static void remove_pmu_umatched_events(struct evlist *evlist, char *metric= _pmus) -{ - struct evsel *evsel, *tmp, *new_leader =3D NULL; - unsigned long *evlist_removed; - char *llist, *nlist, *p1; - bool need_new_leader =3D false; - int i =3D 0, new_nr_members =3D 0; - - nlist =3D strdup(metric_pmus); - if (!nlist) - return; - - evlist_removed =3D bitmap_zalloc(evlist->core.nr_entries); - if (!evlist_removed) { - free(nlist); - return; - } - - llist =3D nlist; - while ((p1 =3D strsep(&llist, ",")) !=3D NULL) { - if (strlen(p1) > 0) { - /* - * p1 points to the string of pmu name, e.g. "cpu_atom". - * The metric group string has pmu suffixes, e.g. - * "{inst_retired.any,cpu_clk_unhalted.thread}:W#cpu_core, - * {cpu_clk_unhalted.core,inst_retired.any_p}:W#cpu_atom" - * By counting the pmu name, we can know the index of - * group. - */ - set_pmu_unmatched_events(evlist, i++, p1, - evlist_removed); - } - } - - evlist__for_each_entry_safe(evlist, tmp, evsel) { - if (test_bit(evsel->core.idx, evlist_removed)) { - if (!evsel__is_group_leader(evsel)) { - if (!need_new_leader) { - if (new_leader) - new_leader->core.leader->nr_members--; - else - evsel->core.leader->nr_members--; - } else - new_nr_members--; - } else { - /* - * If group leader is to remove, we need to - * prepare a new leader and adjust all group - * members. - */ - need_new_leader =3D true; - new_nr_members =3D - evsel->core.leader->nr_members - 1; - } - - evlist__remove(evlist, evsel); - evsel__delete(evsel); - } else { - if (!evsel__is_group_leader(evsel)) { - if (need_new_leader) { - need_new_leader =3D false; - new_leader =3D evsel; - new_leader->core.leader =3D - &new_leader->core; - new_leader->core.nr_members =3D - new_nr_members; - } else if (new_leader) - evsel->core.leader =3D &new_leader->core; - } else { - need_new_leader =3D false; - new_leader =3D NULL; - } - } - } - - bitmap_free(evlist_removed); - free(nlist); -} - /** * parse_ids - Build the event string for the ids and parse them creating = an * evlist. The encoded metric_ids are decoded. @@ -1521,18 +1319,14 @@ static void remove_pmu_umatched_events(struct evlis= t *evlist, char *metric_pmus) * @modifier: any modifiers added to the events. * @has_constraint: false if events should be placed in a weak group. * @out_evlist: the created list of events. - * @pmu_name: the name of the CPU. */ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, struct expr_parse_ctx *ids, const char *modifier, - bool has_constraint, struct evlist **out_evlist, - const char *pmu_name) + bool has_constraint, struct evlist **out_evlist) { struct parse_events_error parse_error; struct evlist *parsed_evlist; struct strbuf events =3D STRBUF_INIT; - struct strbuf metric_pmus =3D STRBUF_INIT; - char *nlist =3D NULL; int ret; =20 *out_evlist =3D NULL; @@ -1559,7 +1353,7 @@ static int parse_ids(bool metric_no_merge, struct per= f_pmu *fake_pmu, ids__insert(ids->ids, tmp); } ret =3D metricgroup__build_event_string(&events, ids, modifier, - has_constraint, pmu_name); + has_constraint); if (ret) return ret; =20 @@ -1570,20 +1364,11 @@ static int parse_ids(bool metric_no_merge, struct p= erf_pmu *fake_pmu, } pr_debug("Parsing metric events '%s'\n", events.buf); parse_events_error__init(&parse_error); - nlist =3D get_metric_pmus(events.buf, &metric_pmus); - if (!nlist) { - ret =3D -ENOMEM; - goto err_out; - } - ret =3D __parse_events(parsed_evlist, nlist, &parse_error, fake_pmu); + ret =3D __parse_events(parsed_evlist, events.buf, &parse_error, fake_pmu); if (ret) { parse_events_error__print(&parse_error, events.buf); goto err_out; } - - if (metric_pmus.alloc) - remove_pmu_umatched_events(parsed_evlist, metric_pmus.buf); - ret =3D decode_all_metric_ids(parsed_evlist, modifier); if (ret) goto err_out; @@ -1591,12 +1376,9 @@ static int parse_ids(bool metric_no_merge, struct pe= rf_pmu *fake_pmu, *out_evlist =3D parsed_evlist; parsed_evlist =3D NULL; err_out: - if (nlist) - free(nlist); parse_events_error__exit(&parse_error); evlist__delete(parsed_evlist); strbuf_release(&events); - strbuf_release(&metric_pmus); return ret; } =20 @@ -1615,8 +1397,7 @@ static int parse_groups(struct evlist *perf_evlist, c= onst char *str, if (metric_events_list->nr_entries =3D=3D 0) metricgroup__rblist_init(metric_events_list); ret =3D metricgroup__add_metric_list(str, metric_no_group, - &metric_list, map, - perf_evlist->hybrid_pmu_name); + &metric_list, map); if (ret) goto out; =20 @@ -1632,8 +1413,7 @@ static int parse_groups(struct evlist *perf_evlist, c= onst char *str, ret =3D parse_ids(metric_no_merge, fake_pmu, combined, /*modifier=3D*/NULL, /*has_constraint=3D*/true, - &combined_evlist, - perf_evlist->hybrid_pmu_name); + &combined_evlist); } if (combined) expr__ctx_free(combined); @@ -1670,9 +1450,6 @@ static int parse_groups(struct evlist *perf_evlist, c= onst char *str, continue; =20 if (expr__subset_of_ids(n->pctx, m->pctx)) { - if (m->pmu_name && n->pmu_name - && strcmp(m->pmu_name, n->pmu_name)) - continue; pr_debug("Events in '%s' fully contained within '%s'\n", m->metric_name, n->metric_name); metric_evlist =3D n->evlist; @@ -1682,16 +1459,14 @@ static int parse_groups(struct evlist *perf_evlist,= const char *str, } } if (!metric_evlist) { - ret =3D parse_ids(metric_no_merge, fake_pmu, m->pctx, - m->modifier, m->has_constraint, - &m->evlist, m->pmu_name); + ret =3D parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, + m->has_constraint, &m->evlist); if (ret) goto out; =20 metric_evlist =3D m->evlist; } - ret =3D setup_metric_events(m->pctx->ids, metric_evlist, - &metric_events, m->pmu_name); + ret =3D setup_metric_events(m->pctx->ids, metric_evlist, &metric_events); if (ret) { pr_debug("Cannot resolve IDs for %s: %s\n", m->metric_name, m->metric_expr); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 13f705737367..98669ca5a86b 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -539,8 +539,7 @@ static void aggr_update_shadow(struct perf_stat_config = *config, } } =20 -static void uniquify_event_name(struct evsel *counter, - struct perf_stat_config *stat_config) +static void uniquify_event_name(struct evsel *counter) { char *new_name; char *config; @@ -559,8 +558,7 @@ static void uniquify_event_name(struct evsel *counter, counter->name =3D new_name; } } else { - if (perf_pmu__has_hybrid() && - stat_config->metric_events.nr_entries =3D=3D 0) { + if (perf_pmu__has_hybrid()) { ret =3D asprintf(&new_name, "%s/%s/", counter->pmu_name, counter->name); } else { @@ -634,7 +632,7 @@ static bool collect_data(struct perf_stat_config *confi= g, struct evsel *counter, return false; cb(config, counter, data, true); if (config->no_merge || hybrid_merge(counter, config, false)) - uniquify_event_name(counter, config); + uniquify_event_name(counter); else if (counter->auto_merge_stats || hybrid_merge(counter, config, true)) collect_all_aliases(config, counter, cb, data); return true; --=20 2.36.0.512.ge40c2bad7a-goog From nobody Fri May 8 09:57:42 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C392EC433EF for ; Sat, 7 May 2022 05:34:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445678AbiEGFiO (ORCPT ); Sat, 7 May 2022 01:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445612AbiEGFiG (ORCPT ); Sat, 7 May 2022 01:38:06 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F18DAE for ; Fri, 6 May 2022 22:34:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b11-20020a5b008b000000b00624ea481d55so7927008ybp.19 for ; Fri, 06 May 2022 22:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=X0A48L0REIgxolXCeCwJBynKB3Io0hAXROJKBMA9IuU=; b=aqUn+PVzh65+R5Qpx9MvkBp1exKVHZMeHzuMLx5HUe+JchuFz1Pg0Xuvju6snBsdr3 hT3LmX4kgUggfCB7eqBJm5N5QFU61wvahiVjvoziweJHPQAY0j82w3JKl18NNjWCyWFg rxAP6BZwJ/2Ho9woQz4hTTwOhzEM4FrCBaQHHvy5+ZegwDOue/9y/bWVFDlHgT1bLn14 iw3sWf4C99DleXzmhSPQmgQyHnhh6FcY4JenjUzvpHWU/0RslkJQIeRN+f4chOWTw+0+ zGqCkKwddPUBqeWqkwrIDMQ7mtztpadekc+wWgnCtPAlZVUzkuhPG7bDC/JtIInj3xLs /+gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=X0A48L0REIgxolXCeCwJBynKB3Io0hAXROJKBMA9IuU=; b=WtcPEYLFpJ4EjyXGenBNMhNZBd3VjIgRRsEHf9ogB/u0P60u12wA+1Zy/BXP/JMpl0 sokqtdk3fCIxWCRpArKqlOwEX99jFaPhHqp3+NdawDfH60OxGm9bURCLttNybe+XEWE2 mbfFHGeuVJiK4SImsOajdZvPjAFrHkZOYW1O2/rAhB9q7RJsSMeHaqJ2tsjydHRTNRPn /kYrHRKlY48mGNgfuul0D88o+30oD4DlWfmkoUDzFqx7kWGe0G1qMSldS/28c8CSbpOe DWdq9jTDGuHD9pQcRZ+BpZZpUZ86nJxANEL7yEq1PhS51Cqh5Z6OJ8VfbbD4yz4YR2kA +ovQ== X-Gm-Message-State: AOAM532HVlqs2C/z6AitSVPj9QcQxncB4ZAgkD/BhVNS5eeIuOl/+UnD K4oBUgSQPH8d8uYQzd/jZnlNdY4SMjPh X-Google-Smtp-Source: ABdhPJwPy24ZCHaXbuLNgP6AHb1xL58dIzYVg9Q0+xV4il+Ytzc0T3cj4NVTJpsEBfbp2IRMVZawJza4S5Bs X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:bf2a:2f64:a273:3573]) (user=irogers job=sendgmr) by 2002:a81:1196:0:b0:2f8:ccab:8807 with SMTP id 144-20020a811196000000b002f8ccab8807mr5576891ywr.58.1651901659386; Fri, 06 May 2022 22:34:19 -0700 (PDT) Date: Fri, 6 May 2022 22:34:07 -0700 In-Reply-To: <20220507053410.3798748-1-irogers@google.com> Message-Id: <20220507053410.3798748-3-irogers@google.com> Mime-Version: 1.0 References: <20220507053410.3798748-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 2/5] perf evsel: Constify a few arrays From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Riccardo Mancini , Kim Phillips , Madhavan Srinivasan , Shunsuke Nakamura , Florian Fischer , Andi Kleen , John Garry , Zhengjun Xing , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove public definition of evsel__tool_names. Signed-off-by: Ian Rogers --- tools/perf/tests/evsel-roundtrip-name.c | 2 +- tools/perf/util/evsel.c | 14 +++++++------- tools/perf/util/evsel.h | 11 +++++------ tools/perf/util/parse-events.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evs= el-roundtrip-name.c index fdbf17642e45..9d3c64974f77 100644 --- a/tools/perf/tests/evsel-roundtrip-name.c +++ b/tools/perf/tests/evsel-roundtrip-name.c @@ -64,7 +64,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) return ret; } =20 -static int __perf_evsel__name_array_test(const char *names[], int nr_names, +static int __perf_evsel__name_array_test(const char *const names[], int nr= _names, int distance) { int i, err; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d38722560e80..cdeace24d9be 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -486,7 +486,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const c= har *name, int idx) return ERR_PTR(err); } =20 -const char *evsel__hw_names[PERF_COUNT_HW_MAX] =3D { +const char *const evsel__hw_names[PERF_COUNT_HW_MAX] =3D { "cycles", "instructions", "cache-references", @@ -571,7 +571,7 @@ static int evsel__hw_name(struct evsel *evsel, char *bf= , size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -const char *evsel__sw_names[PERF_COUNT_SW_MAX] =3D { +const char *const evsel__sw_names[PERF_COUNT_SW_MAX] =3D { "cpu-clock", "task-clock", "page-faults", @@ -597,7 +597,7 @@ static int evsel__sw_name(struct evsel *evsel, char *bf= , size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -const char *evsel__tool_names[PERF_TOOL_MAX] =3D { +static const char *const evsel__tool_names[PERF_TOOL_MAX] =3D { "duration_time", "user_time", "system_time", @@ -633,7 +633,7 @@ static int evsel__bp_name(struct evsel *evsel, char *bf= , size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES] = =3D { +const char *const evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIA= SES] =3D { { "L1-dcache", "l1-d", "l1d", "L1-data", }, { "L1-icache", "l1-i", "l1i", "L1-instruction", }, { "LLC", "L2", }, @@ -643,13 +643,13 @@ const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][= EVSEL__MAX_ALIASES] =3D { { "node", }, }; =20 -const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIA= SES] =3D { +const char *const evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MA= X_ALIASES] =3D { { "load", "loads", "read", }, { "store", "stores", "write", }, { "prefetch", "prefetches", "speculative-read", "speculative-load", }, }; =20 -const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__= MAX_ALIASES] =3D { +const char *const evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][E= VSEL__MAX_ALIASES] =3D { { "refs", "Reference", "ops", "access", }, { "misses", "miss", }, }; @@ -665,7 +665,7 @@ const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_= RESULT_MAX][EVSEL__MAX_AL * L1I : Read and prefetch only * ITLB and BPU : Read-only */ -static unsigned long evsel__hw_cache_stat[C(MAX)] =3D { +static const unsigned long evsel__hw_cache_stat[C(MAX)] =3D { [C(L1D)] =3D (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), [C(L1I)] =3D (CACHE_READ | CACHE_PREFETCH), [C(LL)] =3D (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 45d674812239..a017781cdd47 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -257,12 +257,11 @@ static inline bool evsel__is_bpf(struct evsel *evsel) =20 #define EVSEL__MAX_ALIASES 8 =20 -extern const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALI= ASES]; -extern const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__M= AX_ALIASES]; -extern const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][= EVSEL__MAX_ALIASES]; -extern const char *evsel__hw_names[PERF_COUNT_HW_MAX]; -extern const char *evsel__sw_names[PERF_COUNT_SW_MAX]; -extern const char *evsel__tool_names[PERF_TOOL_MAX]; +extern const char *const evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__M= AX_ALIASES]; +extern const char *const evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EV= SEL__MAX_ALIASES]; +extern const char *const evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT= _MAX][EVSEL__MAX_ALIASES]; +extern const char *const evsel__hw_names[PERF_COUNT_HW_MAX]; +extern const char *const evsel__sw_names[PERF_COUNT_SW_MAX]; extern char *evsel__bpf_counter_events; bool evsel__match_bpf_counter_events(const char *name); =20 diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 937f6c9434a2..30a9d915853d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -426,7 +426,7 @@ static int add_event_tool(struct list_head *list, int *= idx, return 0; } =20 -static int parse_aliases(char *str, const char *names[][EVSEL__MAX_ALIASES= ], int size) +static int parse_aliases(char *str, const char *const names[][EVSEL__MAX_A= LIASES], int size) { int i, j; int n, longest =3D -1; --=20 2.36.0.512.ge40c2bad7a-goog From nobody Fri May 8 09:57:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADEC4C433F5 for ; Sat, 7 May 2022 05:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445637AbiEGFiT (ORCPT ); Sat, 7 May 2022 01:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445646AbiEGFiI (ORCPT ); Sat, 7 May 2022 01:38:08 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2F61AF2B for ; Fri, 6 May 2022 22:34:22 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f7c5767f0fso81648797b3.4 for ; Fri, 06 May 2022 22:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bC1QHjSh76vc80FlT0i5N7y28Ax7j34T16/yRj6HA+0=; b=oWrrJYfi4mSyNnigslp/Ljzj5jwsZOXef5S2Xitv76+Yg4pNuRBkjeHnBnRYrzOiRj olpfao1Dj1bvWXUUb+Rb5ZD/dxl5QMZiDdY9s3nbgdaYMCXD1kvEsSgg9EL9hUaATDr9 LaAgNz6aCcSUD4jhpvLCHibTz833BzVq50KeRbJphbEoarx0hnAuPxIa4qd3Zld9o1yc EOfr2lEj5hS3ZaPjsfKSp+FZkXXZ9Xl6K7f4R7pOFq6jdD9lMT3cZ0IZi/21X7vNqA9y gwJ3it3T6hdGx7tECRS+elHiRkg9Cz6gjMc7fTGR+wFoa4bBmB+MH/tdNxsgEPD0sBBU 9usQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bC1QHjSh76vc80FlT0i5N7y28Ax7j34T16/yRj6HA+0=; b=HHi3NHCmRvNtx6mVewZs3t1wgDySYxAomifbPdUTwSw6Aqi35nBA9V0bvAOgK+v3z+ zur57QH5qpPsGW55w0qtGlTuWrPqYuowjN80XOlt6AwZeefdfaH62Ji3TT2MojiJzoi9 9zK+ZOWewOsVp0goWlUMyiHd+cqpp9aCD/eG9s8W2yh29asKiV/uQgels8sy0tvVrVHg YUMO2NYp/Eu+7ApylDbfwrllx3tlcFXd1NxaxzmlI3rY7VM0GQSuVA2zj+W1MXKfs8+j RoQH39rOh9g3SIF3ttJx8N4oJigrgScsuNVJSrZCqtu4EJBr+BqjS/iAh4Soj/DjsJN5 pmLQ== X-Gm-Message-State: AOAM530hDMRdzUwjAKHfVUDOYL0XcU2FnY/u3l+/A1kAXEt69q9el8Wm 2Wh2llNzI0UfnnfAxEpqYzjSF1fV3KBJ X-Google-Smtp-Source: ABdhPJwO7GsLd8OXvckEIq11DT8kc48Y/O5PqTlQpGkNGjd49wNqJ814A7t8+kvYK0vJusFrrAlr0gi4e/LQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:bf2a:2f64:a273:3573]) (user=irogers job=sendgmr) by 2002:a81:4754:0:b0:2f9:1974:5fa7 with SMTP id u81-20020a814754000000b002f919745fa7mr5517646ywa.513.1651901661720; Fri, 06 May 2022 22:34:21 -0700 (PDT) Date: Fri, 6 May 2022 22:34:08 -0700 In-Reply-To: <20220507053410.3798748-1-irogers@google.com> Message-Id: <20220507053410.3798748-4-irogers@google.com> Mime-Version: 1.0 References: <20220507053410.3798748-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 3/5] perf evsel: Add tool event helpers From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Riccardo Mancini , Kim Phillips , Madhavan Srinivasan , Shunsuke Nakamura , Florian Fischer , Andi Kleen , John Garry , Zhengjun Xing , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert to and from a string. Fix evsel__tool_name as array is off-by-1. Support more than just duration_time as a metric-id. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 41 +++++++++++++++++++++++++++++++---------- tools/perf/util/evsel.h | 11 +++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index cdeace24d9be..5fd7924f8eb3 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -59,6 +59,33 @@ struct perf_missing_features perf_missing_features; =20 static clockid_t clockid; =20 +static const char *const perf_tool_event__tool_names[PERF_TOOL_MAX] =3D { + NULL, + "duration_time", + "user_time", + "system_time", +}; + +const char *perf_tool_event__to_str(enum perf_tool_event ev) +{ + if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + return perf_tool_event__tool_names[ev]; + + return NULL; +} + +enum perf_tool_event perf_tool_event__from_str(const char *str) +{ + int i; + + perf_tool_event__for_each_event(i) { + if (!strcmp(str, perf_tool_event__tool_names[i])) + return i; + } + return PERF_TOOL_NONE; +} + + static int evsel__no_extra_init(struct evsel *evsel __maybe_unused) { return 0; @@ -597,15 +624,9 @@ static int evsel__sw_name(struct evsel *evsel, char *b= f, size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -static const char *const evsel__tool_names[PERF_TOOL_MAX] =3D { - "duration_time", - "user_time", - "system_time", -}; - static int evsel__tool_name(enum perf_tool_event ev, char *bf, size_t size) { - return scnprintf(bf, size, "%s", evsel__tool_names[ev]); + return scnprintf(bf, size, "%s", perf_tool_event__to_str(ev)); } =20 static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) @@ -758,7 +779,7 @@ const char *evsel__name(struct evsel *evsel) break; =20 case PERF_TYPE_SOFTWARE: - if (evsel->tool_event) + if (evsel__is_tool(evsel)) evsel__tool_name(evsel->tool_event, bf, sizeof(bf)); else evsel__sw_name(evsel, bf, sizeof(bf)); @@ -791,8 +812,8 @@ const char *evsel__metric_id(const struct evsel *evsel) if (evsel->metric_id) return evsel->metric_id; =20 - if (evsel->core.attr.type =3D=3D PERF_TYPE_SOFTWARE && evsel->tool_event) - return "duration_time"; + if (evsel__is_tool(evsel)) + return perf_tool_event__to_str(evsel->tool_event); =20 return "unknown"; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a017781cdd47..d4b04537ce6d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -36,6 +36,12 @@ enum perf_tool_event { PERF_TOOL_MAX, }; =20 +const char *perf_tool_event__to_str(enum perf_tool_event ev); +enum perf_tool_event perf_tool_event__from_str(const char *str); + +#define perf_tool_event__for_each_event(ev) \ + for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + /** struct evsel - event selector * * @evlist - evlist this evsel is in, if it is in one. @@ -269,6 +275,11 @@ int __evsel__hw_cache_type_op_res_name(u8 type, u8 op,= u8 result, char *bf, size const char *evsel__name(struct evsel *evsel); const char *evsel__metric_id(const struct evsel *evsel); =20 +static inline bool evsel__is_tool(const struct evsel *evsel) +{ + return evsel->tool_event !=3D PERF_TOOL_NONE; +} + const char *evsel__group_name(struct evsel *evsel); int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); =20 --=20 2.36.0.512.ge40c2bad7a-goog From nobody Fri May 8 09:57:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 454CCC433EF for ; Sat, 7 May 2022 05:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445727AbiEGFi0 (ORCPT ); Sat, 7 May 2022 01:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445612AbiEGFiP (ORCPT ); Sat, 7 May 2022 01:38:15 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D277B2408A for ; Fri, 6 May 2022 22:34:24 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 9-20020a250909000000b006484b89c979so7826655ybj.21 for ; Fri, 06 May 2022 22:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7BccLGFbnzxgEz6sHuW6w+xF3bfVrTq5a9IERbkhU7Q=; b=RkL0pa87fsjXuMFKkX4QrTiVPsgv3eVh3ignPmfTAqCB4NGjec3442fQ9T7slD2j28 zTWog8mY+oEByKHjcDyzKCs3NL/AqstetnUe2NVPiS/0YwgMtElYPYULCAAY886Zd+oT XDJrPS1YeSBMp8ScLBQGJ3o7HW3U9vngEwXbhXJhKP65F7wq+WybP2MyCczffaXuj07v JGLhWFYSFFttYWTAhzCJgiYQxAi/zs3WF37aMVOccmnR3Te3lhOpSSJ8CpZ5oTCqFgAy rBH0V+yE8mXwzDdDxdqPn0fjrsnukboahKOKWuOO1E52lg4Yo5aKgMYnzYqro+qUnvMo dLGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7BccLGFbnzxgEz6sHuW6w+xF3bfVrTq5a9IERbkhU7Q=; b=8N6UrPcbm+nH+K7mUttSt/DdnCXATBIpZW0JDMfD4ZJjsz8xK9iOu4hjN6HimcFf9L Hyv/4XiAgaTYklg6WsOPNorVbiJKFREMocHQ+zPP0k2EeQKGDnOJkBDqynUMSin4Q27+ LtAJRLDz2CHWSpqn2xj+DKwZx2oGp0IeyVwSmz0KWT1AybfQrcgwvHztshD+Q70Xj6nv xlxaPHB/+HjMx2YtZktx4bF1u+yDv4PkOnMehNgIEyjLf+ESYnAIoGfzPZTc73sCePSA aN0+c510A51zd44IyHWh4xz2oyh8vwv0x9wnXPze2KA8UhKfvEkgvXs8bjCSEpl8Skf9 Tejg== X-Gm-Message-State: AOAM532ktdI6BDwGlashwnGGaAwCA03LH1fVkC+vKEP1TFMLqoZdyXGZ FumSa9SrZc4sdwpElDX0jnX7HstSzUwz X-Google-Smtp-Source: ABdhPJwHS2vHsogko5eYvlKiFMT2M+HKgGmnh026VsFjlc0DEeLQohnX5ZX/K1VEx7OwEJkQoUUg0+gjBcPk X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:bf2a:2f64:a273:3573]) (user=irogers job=sendgmr) by 2002:a25:ba07:0:b0:64a:1a32:6ef6 with SMTP id t7-20020a25ba07000000b0064a1a326ef6mr4915646ybg.308.1651901664027; Fri, 06 May 2022 22:34:24 -0700 (PDT) Date: Fri, 6 May 2022 22:34:09 -0700 In-Reply-To: <20220507053410.3798748-1-irogers@google.com> Message-Id: <20220507053410.3798748-5-irogers@google.com> Mime-Version: 1.0 References: <20220507053410.3798748-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 4/5] perf metrics: Support all tool events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Riccardo Mancini , Kim Phillips , Madhavan Srinivasan , Shunsuke Nakamura , Florian Fischer , Andi Kleen , John Garry , Zhengjun Xing , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously duration_time was hard coded, which was ok until commit b03b89b35003 ("perf stat: Add user_time and system_time events") added additional tool events. Do for all tool events what was previously done just for duration_time. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 87 ++++++++++++++++++++--------------- tools/perf/util/stat-shadow.c | 27 +++++++++-- 2 files changed, 75 insertions(+), 39 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index d8492e339521..7a5f488aef02 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -728,22 +728,23 @@ static int metricgroup__build_event_string(struct str= buf *events, { struct hashmap_entry *cur; size_t bkt; - bool no_group =3D true, has_duration =3D false; + bool no_group =3D true, has_tool_events =3D false; + bool tool_events[PERF_TOOL_MAX] =3D {false}; int ret =3D 0; =20 #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) =20 hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *sep, *rsep, *id =3D cur->key; + enum perf_tool_event ev; =20 pr_debug("found event %s\n", id); - /* - * Duration time maps to a software event and can make - * groups not count. Always use it outside a - * group. - */ - if (!strcmp(id, "duration_time")) { - has_duration =3D true; + + /* Always move tool events outside of the group. */ + ev =3D perf_tool_event__from_str(id); + if (ev !=3D PERF_TOOL_NONE) { + has_tool_events =3D true; + tool_events[ev] =3D true; continue; } /* Separate events with commas and open the group if necessary. */ @@ -802,16 +803,25 @@ static int metricgroup__build_event_string(struct str= buf *events, RETURN_IF_NON_ZERO(ret); } } - if (has_duration) { - if (no_group) { - /* Strange case of a metric of just duration_time. */ - ret =3D strbuf_addf(events, "duration_time"); - } else if (!has_constraint) - ret =3D strbuf_addf(events, "}:W,duration_time"); - else - ret =3D strbuf_addf(events, ",duration_time"); - } else if (!no_group && !has_constraint) + if (!no_group && !has_constraint) { ret =3D strbuf_addf(events, "}:W"); + RETURN_IF_NON_ZERO(ret); + } + if (has_tool_events) { + int i; + + perf_tool_event__for_each_event(i) { + if (tool_events[i]) { + if (!no_group) { + ret =3D strbuf_addch(events, ','); + RETURN_IF_NON_ZERO(ret); + } + no_group =3D false; + ret =3D strbuf_addstr(events, perf_tool_event__to_str(i)); + RETURN_IF_NON_ZERO(ret); + } + } + } =20 return ret; #undef RETURN_IF_NON_ZERO @@ -1117,7 +1127,7 @@ static int metricgroup__add_metric_sys_event_iter(con= st struct pmu_event *pe, =20 /** * metric_list_cmp - list_sort comparator that sorts metrics with more eve= nts to - * the front. duration_time is excluded from the count. + * the front. tool events are excluded from the count. */ static int metric_list_cmp(void *priv __maybe_unused, const struct list_he= ad *l, const struct list_head *r) @@ -1125,15 +1135,19 @@ static int metric_list_cmp(void *priv __maybe_unuse= d, const struct list_head *l, const struct metric *left =3D container_of(l, struct metric, nd); const struct metric *right =3D container_of(r, struct metric, nd); struct expr_id_data *data; - int left_count, right_count; + int i, left_count, right_count; =20 left_count =3D hashmap__size(left->pctx->ids); - if (!expr__get_id(left->pctx, "duration_time", &data)) - left_count--; + perf_tool_event__for_each_event(i) { + if (!expr__get_id(left->pctx, perf_tool_event__to_str(i), &data)) + left_count--; + } =20 right_count =3D hashmap__size(right->pctx->ids); - if (!expr__get_id(right->pctx, "duration_time", &data)) - right_count--; + perf_tool_event__for_each_event(i) { + if (!expr__get_id(right->pctx, perf_tool_event__to_str(i), &data)) + right_count--; + } =20 return right_count - left_count; } @@ -1331,26 +1345,27 @@ static int parse_ids(bool metric_no_merge, struct p= erf_pmu *fake_pmu, =20 *out_evlist =3D NULL; if (!metric_no_merge || hashmap__size(ids->ids) =3D=3D 0) { - char *tmp; + int i; /* - * We may fail to share events between metrics because - * duration_time isn't present in one metric. For example, a - * ratio of cache misses doesn't need duration_time but the same - * events may be used for a misses per second. Events without - * sharing implies multiplexing, that is best avoided, so place - * duration_time in every group. + * We may fail to share events between metrics because a tool + * event isn't present in one metric. For example, a ratio of + * cache misses doesn't need duration_time but the same events + * may be used for a misses per second. Events without sharing + * implies multiplexing, that is best avoided, so place + * all tool events in every group. * * Also, there may be no ids/events in the expression parsing * context because of constant evaluation, e.g.: * event1 if #smt_on else 0 - * Add a duration_time event to avoid a parse error on an empty - * string. + * Add a tool event to avoid a parse error on an empty string. */ - tmp =3D strdup("duration_time"); - if (!tmp) - return -ENOMEM; + perf_tool_event__for_each_event(i) { + char *tmp =3D strdup(perf_tool_event__to_str(i)); =20 - ids__insert(ids->ids, tmp); + if (!tmp) + return -ENOMEM; + ids__insert(ids->ids, tmp); + } } ret =3D metricgroup__build_event_string(&events, ids, modifier, has_constraint); diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index ea4c35e4f1da..979c8cb918f7 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -833,10 +833,31 @@ static int prepare_metric(struct evsel **metric_event= s, u64 metric_total =3D 0; int source_count; =20 - if (!strcmp(metric_events[i]->name, "duration_time")) { - stats =3D &walltime_nsecs_stats; - scale =3D 1e-9; + if (evsel__is_tool(metric_events[i])) { source_count =3D 1; + switch (metric_events[i]->tool_event) { + case PERF_TOOL_DURATION_TIME: + stats =3D &walltime_nsecs_stats; + scale =3D 1e-9; + break; + case PERF_TOOL_USER_TIME: + stats =3D &ru_stats.ru_utime_usec_stat; + scale =3D 1e-6; + break; + case PERF_TOOL_SYSTEM_TIME: + stats =3D &ru_stats.ru_stime_usec_stat; + scale =3D 1e-6; + break; + case PERF_TOOL_NONE: + pr_err("Invalid tool event 'none'"); + abort(); + case PERF_TOOL_MAX: + pr_err("Invalid tool event 'max'"); + abort(); + default: + pr_err("Unknown tool event '%s'", evsel__name(metric_events[i])); + abort(); + } } else { v =3D saved_value_lookup(metric_events[i], cpu_map_idx, false, STAT_NONE, 0, st, --=20 2.36.0.512.ge40c2bad7a-goog From nobody Fri May 8 09:57:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA2EEC433F5 for ; Sat, 7 May 2022 05:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351853AbiEGFib (ORCPT ); Sat, 7 May 2022 01:38:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445700AbiEGFiP (ORCPT ); Sat, 7 May 2022 01:38:15 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07CD62E9C9 for ; Fri, 6 May 2022 22:34:27 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d22-20020a25add6000000b00645d796034fso7924622ybe.2 for ; Fri, 06 May 2022 22:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gcYqxh5Opd0xAIFhaLkZah3tm02tWS5shPMbttMBo+g=; b=OnrkBF4dkwel0INnFUUcNVkb1EKQgMi0hW09jwwmgo7gvI6olx/BA6l1AI6K++mpdA DYmcc8BR+m+PzPqydc2PH/dNeYUrtqeF59dozpzYMjXLemLHEz20g44T5v4fVVJ6xlT+ 2qanIV7H5X/ebzeKqG0pbmOx0mW/X1I9JQVxucBNiuoA+Ae3YwByERX6W9Puwy2Ib3l7 oZqjjXAzSb/dyIjAm9DiWXrbmLwm8xkeduwne8gpSd21D17SFAzfiAIMOy4vEoLm74+E 7v/GiEVs1lRzthBjIF5ISeRvBQ+KjnyWhgXxY5CPeWwRpxI9uLg2gmfh2QshX0HRueMR n2Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gcYqxh5Opd0xAIFhaLkZah3tm02tWS5shPMbttMBo+g=; b=iUCLPCiYLzIPebfIQc29L8QZ0QmFTX7oJEYfTKgCaNpaHfH7ETXU8i4PSdGvWn9Ui1 4jVTVBoQBvYNH98W6j0coPFU1b+8IqKvJ3PdpXhvXMnuAFWBKnnG7bUHrSwEhxpkar3P 33QuTd9oTtGc8OE7IkHefOleeDfzBEUBrHAnoIuSiuzZfE0Ri8yPB50CBKIvdts5/uBl Oq1gTDLM/u8SaVHl7ecUvBXH3rwZUEtFj7W8MUdU4XeU+b5svD/zJBle/KduxKaBtj9y S17hZrHZFGJa/pwBZbe7zSwRHxRtX+Z9S1vQMI+sXE+2bksN+27R1X6MghuLUfscsbel QSVQ== X-Gm-Message-State: AOAM532OVYx2U7BQ6oE6JGs5PWh1pnB00ZDhMFOwDZfboomjhcVhNniq 9Wwh+VRaj87uUk8SJLisGiWSELw7H6lC X-Google-Smtp-Source: ABdhPJy+ol5pg1dvBrK0DPVgxRFflJxJDWSHXGQ63hSGPzT5cMTf0CHJZqkefT5JBX8KkSYr5hUeEYIGSCgn X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:bf2a:2f64:a273:3573]) (user=irogers job=sendgmr) by 2002:a5b:603:0:b0:648:507a:b9f8 with SMTP id d3-20020a5b0603000000b00648507ab9f8mr4905887ybq.497.1651901666173; Fri, 06 May 2022 22:34:26 -0700 (PDT) Date: Fri, 6 May 2022 22:34:10 -0700 In-Reply-To: <20220507053410.3798748-1-irogers@google.com> Message-Id: <20220507053410.3798748-6-irogers@google.com> Mime-Version: 1.0 References: <20220507053410.3798748-1-irogers@google.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog Subject: [PATCH 5/5] perf metrics: Don't add all tool events for sharing From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Riccardo Mancini , Kim Phillips , Madhavan Srinivasan , Shunsuke Nakamura , Florian Fischer , Andi Kleen , John Garry , Zhengjun Xing , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tool events are added to the set of events for parsing so that having a tool event in a metric doesn't inhibit event sharing of events between metrics. All tool events were added but this meant unused tool events would be counted. Reduce this set of tool events to just those present in the overall metric list. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 45 ++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 7a5f488aef02..ee8fcfa115e5 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1283,6 +1283,30 @@ static void metricgroup__free_metrics(struct list_he= ad *metric_list) } } =20 +/** + * find_tool_events - Search for the pressence of tool events in metric_li= st. + * @metric_list: List to take metrics from. + * @tool_events: Array of false values, indices corresponding to tool even= ts set + * to true if tool event is found. + */ +static void find_tool_events(const struct list_head *metric_list, + bool tool_events[PERF_TOOL_MAX]) +{ + struct metric *m; + + list_for_each_entry(m, metric_list, nd) { + int i; + + perf_tool_event__for_each_event(i) { + struct expr_id_data *data; + + if (!tool_events[i] && + !expr__get_id(m->pctx, perf_tool_event__to_str(i), &data)) + tool_events[i] =3D true; + } + } +} + /** * build_combined_expr_ctx - Make an expr_parse_ctx with all has_constraint * metric IDs, as the IDs are held in a set, @@ -1332,11 +1356,14 @@ static int build_combined_expr_ctx(const struct lis= t_head *metric_list, * @ids: the event identifiers parsed from a metric. * @modifier: any modifiers added to the events. * @has_constraint: false if events should be placed in a weak group. + * @tool_events: entries set true if the tool event of index could be pres= ent in + * the overall list of metrics. * @out_evlist: the created list of events. */ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, struct expr_parse_ctx *ids, const char *modifier, - bool has_constraint, struct evlist **out_evlist) + bool has_constraint, const bool tool_events[PERF_TOOL_MAX], + struct evlist **out_evlist) { struct parse_events_error parse_error; struct evlist *parsed_evlist; @@ -1360,11 +1387,13 @@ static int parse_ids(bool metric_no_merge, struct p= erf_pmu *fake_pmu, * Add a tool event to avoid a parse error on an empty string. */ perf_tool_event__for_each_event(i) { - char *tmp =3D strdup(perf_tool_event__to_str(i)); + if (tool_events[i]) { + char *tmp =3D strdup(perf_tool_event__to_str(i)); =20 - if (!tmp) - return -ENOMEM; - ids__insert(ids->ids, tmp); + if (!tmp) + return -ENOMEM; + ids__insert(ids->ids, tmp); + } } } ret =3D metricgroup__build_event_string(&events, ids, modifier, @@ -1407,6 +1436,7 @@ static int parse_groups(struct evlist *perf_evlist, c= onst char *str, struct evlist *combined_evlist =3D NULL; LIST_HEAD(metric_list); struct metric *m; + bool tool_events[PERF_TOOL_MAX] =3D {false}; int ret; =20 if (metric_events_list->nr_entries =3D=3D 0) @@ -1422,12 +1452,15 @@ static int parse_groups(struct evlist *perf_evlist,= const char *str, if (!metric_no_merge) { struct expr_parse_ctx *combined =3D NULL; =20 + find_tool_events(&metric_list, tool_events); + ret =3D build_combined_expr_ctx(&metric_list, &combined); =20 if (!ret && combined && hashmap__size(combined->ids)) { ret =3D parse_ids(metric_no_merge, fake_pmu, combined, /*modifier=3D*/NULL, /*has_constraint=3D*/true, + tool_events, &combined_evlist); } if (combined) @@ -1475,7 +1508,7 @@ static int parse_groups(struct evlist *perf_evlist, c= onst char *str, } if (!metric_evlist) { ret =3D parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, - m->has_constraint, &m->evlist); + m->has_constraint, tool_events, &m->evlist); if (ret) goto out; =20 --=20 2.36.0.512.ge40c2bad7a-goog