From patchwork Thu Jan 26 23:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3026C05027 for ; Thu, 26 Jan 2023 23:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GdRDedA4OgGa9BAAjL050gh4q/MvbPIDp+ebO9AUNnw=; b=34ulzRTiVi0RowHy8J5t+eq1rp OyK+8mVfC1Si71rYhMo1VGLs229IDk6ktZDoLj1Of/Mi8IErWlW5v55a1Cw/Io+nzWNLZNzu5zFPQ kjJuWtQwB+lq3Z3dy38wiGBp4V7ll7frQAR1qCsVpy2NypJ3+yfLOIUFshvLAESaGaN27qDsOxh2q ekq3HN5Ukoo/TlCr6h3tbwebeoEfk4FDJz4Gn8kAhS6o+Qz7Gha9QnU3CYAVCxhCk+roSrqfOgHxA 1n1bj/wgvy9Qm57oXZ992NR2Y+uK/a426KoPJEXWjosPnUGoFKW25/4MSTuRBE489BKSjd/izcMt8 vXtzEuqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBp4-00ClK5-CR; Thu, 26 Jan 2023 23:38:26 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoG-00Ckzo-LM for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:39 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-509ab88f98fso28353647b3.10 for ; Thu, 26 Jan 2023 15:37:35 -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=Lb47qkLvoEebhhojDCr1rxqXrzltddk6cGZI2dpzJd3CueV/osdasGcRBainaytYeh vY0h+edzNrODXVvCfiernbpPp8+Dchi7Kvwhfd2tTaMjxi+gaXydFRs0a7vwUYkR4vgI HP/THN4mcvWeMtBJvu3MeeRPSRLcMZMN0AzK0xt70yMwSpma+CSdjk5msFvJ7LlepJwV sSPQnkO/pdmj8uD17VuvsfEgDHwtfvL64rTVM7GcJd+HLQOjYnLGi5ng1mJESoHgxafl P/Zr8U0jGNDq5wOxVHYmpuvTaht7lmYEzffV9+3OrOs1SRkJL+kX+J/t4PPnMvNKl1LR 56UA== X-Gm-Message-State: AO0yUKXa7C95Jau2V9flPeV2EUeCxSURTWMRqFk7HOJBThkqGK9pjS7D ygtD5ers1qm4doBPkiyBcY6aukOs14dX 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153736_796545_B293E846 X-CRM114-Status: GOOD ( 24.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;