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 203A1C05027 for ; Thu, 26 Jan 2023 23:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233463AbjAZXiO (ORCPT ); Thu, 26 Jan 2023 18:38:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbjAZXiE (ORCPT ); Thu, 26 Jan 2023 18:38:04 -0500 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 443E26DFE2 for ; Thu, 26 Jan 2023 15:37:36 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4c8e781bc0aso37719667b3.22 for ; Thu, 26 Jan 2023 15:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VKGQ3UMcGBfYsEagUEP2tt2hFRwSrRyVp71e2QE2hiM=; b=aV7vKVkhORJ2QG8ykWx6y2ItWk9jTsmmbc4n9E21UNeXKoEDgAIOeZzZ/LdZO1RQN3 FrU2ZAREeD3okbeK80SPEWl6FOC0UFYNlgqNBP9OxKiOdY9vHI+0knTbXwfgHVDzB7tC WU/38NdEoKBs6fetvNwIcoIOhBK64V1h5Ge2iTLfLiuE0kXkH3/X4jLoJNYcwrTHM10C x50TP+xn+lh7A/DbX6ln4q/qIbsoTFxrv7TWodicY2vbc+ZYcM+d7okP/m7gCt1G+dlH nQKhYLdlydtCydVyf2r8lHmmaOEWu/nfHje+JHRu3RcAXwI5WF5g9qbO4/FhOEa5UOTa W2rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VKGQ3UMcGBfYsEagUEP2tt2hFRwSrRyVp71e2QE2hiM=; b=CvJ+34tiEVoUb5kFINQBA0BPsKcBaKd1fmMwxtMniwTgungzVSu8+x77mpIbRo/Fp7 7UkFNRjrE/J7GW7p2zsXkxZTEW+3IWoXDQOG4+79z0uczcGTrwM011KEAkq6S3BPnzXT Lky7pQVq36LGvpp1VG2dlhgs5iofZC2G+iPrTwISsj7tlcQvyvUtqf5JwkFxE4GecsCP GJH7r6IxHMdTu7qpLCLazT4ob8/KioNSsYFArEfICEmnEJeOstBkOaqlh3sSlT6p9JdJ qCozL+iLc4nEVW8TThKKFESO0A8ipkSgbmtzFG5rPwwzIx0LVA7N8EXTb4ZL+irRVH7F VDhg== X-Gm-Message-State: AO0yUKXXa4pbNUKaDimDpmF2bm3by7Za7hvxpxWUfl0cJIhe2Fdy0dpw lh0j7PqJRmFqXuvqaOgtCZwPlZzmplWo X-Google-Smtp-Source: AK7set8gWwYykkaFWU14EGjYcNcEBDVQZrbnovUFySkGKnETHkfL8FsYFRudVpYUi1imLlkceh4e3ToiALuL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a05:690c:607:b0:506:c9b7:ae6f with SMTP id bq7-20020a05690c060700b00506c9b7ae6fmr928091ywb.310.1674776255242; Thu, 26 Jan 2023 15:37:35 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:35 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-6-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 05/15] perf pmu-events: Separate the metrics from events for no jevents From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Separate the event and metric table when building without jevents. Add find_core_metrics_table and perf_pmu__find_metrics_table while renaming existing utilities to be event specific, so that users can find the right table for their need. Reviewed-by: John Garry --- tools/perf/pmu-events/empty-pmu-events.c | 88 ++++++++++++++++++------ tools/perf/pmu-events/jevents.py | 7 +- tools/perf/pmu-events/pmu-events.h | 4 +- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/util/pmu.c | 4 +- 6 files changed, 79 insertions(+), 28 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 4e39d1a8d6d6..10bd4943ebf8 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -11,7 +11,7 @@ #include #include -static const struct pmu_event pme_test_soc_cpu[] = { +static const struct pmu_event pmu_events__test_soc_cpu[] = { { .name = "l3_cache_rd", .event = "event=0x40", @@ -105,6 +105,14 @@ static const struct pmu_event pme_test_soc_cpu[] = { .desc = "L2 BTB Correction", .topic = "branch", }, + { + .name = 0, + .event = 0, + .desc = 0, + }, +}; + +static const struct pmu_metric pmu_metrics__test_soc_cpu[] = { { .metric_expr = "1 / IPC", .metric_name = "CPI", @@ -170,9 +178,8 @@ static const struct pmu_event pme_test_soc_cpu[] = { .metric_name = "L1D_Cache_Fill_BW", }, { - .name = 0, - .event = 0, - .desc = 0, + .metric_expr = 0, + .metric_name = 0, }, }; @@ -197,7 +204,8 @@ struct pmu_metrics_table { struct pmu_events_map { const char *arch; const char *cpuid; - const struct pmu_events_table table; + const struct pmu_events_table event_table; + const struct pmu_metrics_table metric_table; }; /* @@ -208,12 +216,14 @@ static const struct pmu_events_map pmu_events_map[] = { { .arch = "testarch", .cpuid = "testcpu", - .table = { pme_test_soc_cpu }, + .event_table = { pmu_events__test_soc_cpu }, + .metric_table = { pmu_metrics__test_soc_cpu }, }, { .arch = 0, .cpuid = 0, - .table = { 0 }, + .event_table = { 0 }, + .metric_table = { 0 }, }, }; @@ -259,12 +269,9 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data) { - for (const struct pmu_event *pe = &table->entries[0]; pe->name || pe->metric_expr; pe++) { - int ret; + for (const struct pmu_event *pe = &table->entries[0]; pe->name; pe++) { + int ret = fn(pe, table, data); - if (!pe->name) - continue; - ret = fn(pe, table, data); if (ret) return ret; } @@ -276,19 +283,44 @@ int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, pmu_ { struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable; - for (const struct pmu_metric *pm = &table->entries[0]; pm->name || pm->metric_expr; pm++) { - int ret; + for (const struct pmu_metric *pm = &table->entries[0]; pm->metric_expr; pm++) { + int ret = fn(pm, etable, data); - if (!pm->metric_expr) - continue; - ret = fn(pm, etable, data); if (ret) return ret; } return 0; } -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) +{ + const struct pmu_events_table *table = NULL; + char *cpuid = perf_pmu__getcpuid(pmu); + int i; + + /* on some platforms which uses cpus map, cpuid can be NULL for + * PMUs other than CORE PMUs. + */ + if (!cpuid) + return NULL; + + i = 0; + for (;;) { + const struct pmu_events_map *map = &pmu_events_map[i++]; + + if (!map->cpuid) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = &map->event_table; + break; + } + } + free(cpuid); + return table; +} + +const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) { const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); @@ -308,7 +340,7 @@ const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = &map->table; + table = (const struct pmu_events_table *)&map->metric_table; break; } } @@ -322,7 +354,18 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return &tables->table; + return &tables->event_table; + } + return NULL; +} + +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return (const struct pmu_events_table *)&tables->metric_table; } return NULL; } @@ -330,7 +373,7 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->event_table, fn, data); if (ret) return ret; @@ -343,7 +386,8 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + int ret = pmu_events_table_for_each_metric( + (const struct pmu_events_table *)&tables->metric_table, fn, data); if (ret) return ret; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 858787a12302..8df14ab14fcf 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -625,7 +625,7 @@ int pmu_events_table_for_each_metric(const struct pmu_events_table *table, return 0; } -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) { const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); @@ -663,6 +663,11 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch return NULL; } +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +{ + return (struct pmu_events_table *)find_core_events_table(arch, cpuid); +} + int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 45c0f508af23..e2cd3e61acef 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -63,8 +63,10 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_ev int pmu_events_table_for_each_metric(const struct pmu_events_table *table, pmu_metric_iter_fn fn, void *data); -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu); +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); +const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index 51fb5f34c1dd..4f3195b84463 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -186,7 +186,7 @@ static int expand_metric_events(void) TEST_ASSERT_VAL("failed to get evlist", evlist); rblist__init(&metric_events); - pme_test = find_core_events_table("testarch", "testcpu"); + pme_test = find_core_metrics_table("testarch", "testcpu"); ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str, false, false, &metric_events); if (ret < 0) { diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 21b7ac00d798..6c527cd805fe 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -96,7 +96,7 @@ static int __compute_metric(const char *name, struct value *vals, runtime_stat__init(&st); /* Parse the metric into metric_events list. */ - pme_test = find_core_events_table("testarch", "testcpu"); + pme_test = find_core_metrics_table("testarch", "testcpu"); err = metricgroup__parse_groups_test(evlist, pme_test, name, false, false, &metric_events); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8abf5b8439a7..3a67b17b4a16 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -663,7 +663,7 @@ char *perf_pmu__getcpuid(struct perf_pmu *pmu) __weak const struct pmu_events_table *pmu_events_table__find(void) { - return perf_pmu__find_table(NULL); + return perf_pmu__find_events_table(NULL); } /* @@ -794,7 +794,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) { const struct pmu_events_table *table; - table = perf_pmu__find_table(pmu); + table = perf_pmu__find_events_table(pmu); if (!table) return; -- 2.39.1.456.gfc5497dd1b-goog