From mboxrd@z Thu Jan 1 00:00:00 1970 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 83ED0C00144 for ; Fri, 29 Jul 2022 07:44:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235175AbiG2Hor (ORCPT ); Fri, 29 Jul 2022 03:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235023AbiG2HoY (ORCPT ); Fri, 29 Jul 2022 03:44:24 -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 3CC04814BF for ; Fri, 29 Jul 2022 00:44:23 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3238ce833beso20326217b3.11 for ; Fri, 29 Jul 2022 00:44:23 -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=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=L9UT7pFKEMv8kmhKTFboeMQHgbNjypzxWtClefHRJXeuk7El88DNhUGL4PqSb2pxBt UUcOzUDVOnbLXDk7ADQF8gwzoy0tFbnIJQoWp00c6r1J4xo8jWshWT4mpOhestPPnV2m 31p0htLfJiSCQ2GcnIhA8XjMPzhJ6UF1OOS72tmsudDUX5X5uOjGU4aDnEPbBzQtFfPR h9/FepigXVjZTiyqlOKgRSaq9TO9PIy2rPBTb5Jiuxn3ceLTiENmnJj2kVS37+Xg+5sN C+JZfVZ4SXaxQMf/IsC0qlPUQKGYUPG8J+i1wpIpv4uwKIjNgz+tD/cTlkJWh3krAyHJ duMg== 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=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=cIo6NY6WIGoUfZdE1CsXixOg7nMZ8Xm8ISYV7v16+4ndF18YqLKkRWJb5xhszpmWms euaI+6qTBdCjePKikC3yzOSFtmGesxlfxITIDRazZXU4HDWOyuJ6WisC8xj7YDs1o/Q7 jhmDU0ZbGEPUNjN2WiR6LcD+AMJu9oEiTgtAOPR42U+ZkNcfFpSL+uzp3LM4IIUacRly YhU41idizI/HcDY7tljk4enfMwgw+1VUj3/dSprqwpEp6jgVx4cawYe9UkwDIthjM+aU RhAXQzyRzMGF7YRluouTcDX4DtqwRDUsx5cYPCPsZ+3rdgfpJHvKkera51ilI9Xqzm7T QUFw== X-Gm-Message-State: ACgBeo1cGq+HHGOqW3ad9f2I1IxR5iX/pClN+6MC+NGhsFVmMpFiP+dY rA4yvlELIPYdqmGwyqU+wbnxAlS1M/VI X-Google-Smtp-Source: AA6agR4lvVMHfSoejMkozQjmS9qJTDKTwsU5cAD6r+dvPCEB7yVOfvYBAS7Y09yz2U8G7/kdQP/Wm9mQYGrh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:41d6:0:b0:673:817c:e163 with SMTP id o205-20020a2541d6000000b00673817ce163mr1461338yba.561.1659080662475; Fri, 29 Jul 2022 00:44:22 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:42 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-9-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 08/17] perf pmu-events: Hide pmu_sys_event_tables 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move usage of the table to pmu-events.c so it may be hidden. By abstracting the table the implementation can later be changed. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 37 ++++++++++++++++++- tools/perf/pmu-events/jevents.py | 45 ++++++++++++++++++++++-- tools/perf/pmu-events/pmu-events.h | 11 +++--- tools/perf/tests/pmu-events.c | 14 +------- tools/perf/util/pmu.c | 27 -------------- tools/perf/util/pmu.h | 2 -- 6 files changed, 84 insertions(+), 52 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 4182a986f505..216ea0482c37 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -6,6 +6,8 @@ * The test cpu/soc is provided for testing. */ #include "pmu-events/pmu-events.h" +#include +#include static const struct pmu_event pme_test_soc_cpu[] = { { @@ -145,7 +147,12 @@ static const struct pmu_event pme_test_soc_sys[] = { }, }; -const struct pmu_sys_events pmu_sys_event_tables[] = { +struct pmu_sys_events { + const char *name; + const struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { { .table = pme_test_soc_sys, .name = "pme_test_soc_sys", @@ -154,3 +161,31 @@ const struct pmu_sys_events pmu_sys_event_tables[] = { .table = 0 }, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 30e0e792221a..dd21bc9eeeed 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -370,8 +370,14 @@ def print_mapping_table(archs: Sequence[str]) -> None: def print_system_mapping_table() -> None: """C struct mapping table array for tables from /sys directories.""" - _args.output_file.write( - '\nconst struct pmu_sys_events pmu_sys_event_tables[] = {\n') + _args.output_file.write(""" +struct pmu_sys_events { +\tconst char *name; +\tconst struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { +""") for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ \t\t.table = {tblname}, @@ -382,6 +388,34 @@ def print_system_mapping_table() -> None: \t\t.table = 0 \t}, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} """) @@ -413,7 +447,12 @@ def main() -> None: 'output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout) _args = ap.parse_args() - _args.output_file.write("#include \"pmu-events/pmu-events.h\"\n") + _args.output_file.write(""" +#include "pmu-events/pmu-events.h" +#include +#include + +""") archs = [] for item in os.scandir(_args.starting_dir): if not item.is_dir(): diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index a491b117c8ac..2386212b1df0 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -43,16 +43,15 @@ struct pmu_events_map { const struct pmu_event *table; }; -struct pmu_sys_events { - const char *name; - const struct pmu_event *table; -}; - /* * Global table mapping each known CPU for the architecture to its * table of PMU events. */ extern const struct pmu_events_map pmu_events_map[]; -extern const struct pmu_sys_events pmu_sys_event_tables[]; + +const struct pmu_event *find_sys_events_table(const char *name); + +typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, void *data); +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); #endif diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 82192f1a7bf7..a39a2c99ede6 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -286,18 +286,6 @@ static const struct pmu_events_map *__test_pmu_get_events_map(void) return NULL; } -static const struct pmu_event *__test_pmu_get_sys_events_table(void) -{ - const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; - - for ( ; tables->name; tables++) { - if (!strcmp("pme_test_soc_sys", tables->name)) - return tables->table; - } - - return NULL; -} - static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2) { if (!is_same(e1->name, e2->name)) { @@ -451,7 +439,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); + const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); const struct pmu_events_map *map = __test_pmu_get_events_map(); const struct pmu_event *table; int map_events = 0, expected_events; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0112e1c36418..d8717c4548a4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -868,33 +868,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) pmu_add_cpu_aliases_map(head, pmu, map); } -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data) -{ - int i = 0; - - while (1) { - const struct pmu_sys_events *event_table; - int j = 0; - - event_table = &pmu_sys_event_tables[i++]; - - if (!event_table->table) - break; - - while (1) { - const struct pmu_event *pe = &event_table->table[j++]; - int ret; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - - ret = fn(pe, data); - if (ret) - break; - } - } -} - struct pmu_sys_event_iter_data { struct list_head *head; struct perf_pmu *pmu; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 4b45fd8da5a3..7e667eec2a01 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -133,8 +133,6 @@ const struct pmu_events_map *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); -typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data); -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data); int perf_pmu__convert_scale(const char *scale, char **end, double *sval); int perf_pmu__caps_parse(struct perf_pmu *pmu); -- 2.37.1.455.g008518b4e5-goog From mboxrd@z Thu Jan 1 00:00:00 1970 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 DC13DC19F2B for ; Fri, 29 Jul 2022 07:48:25 +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=5E4ItD8Td2jdojn/rBkUf4boccnlsfv/f8JPr1x3zIk=; b=Ty/nxmxjEvVzkGq2eOoVDzsTPh 6fOvU6DTFBEY7kF3DALuiFuf2AqQLgE/Ta/67sRnqhIssCg9sjSJef5lgwwbp+5nYvXNknUhUwpyL cj35QxTTf29Cxg2w0ZYOYZZiR76VB2zf2huuwCJKbVOAMqeGMDW4KaSGE2DwlN5sdbJ45T1aWJObc EKK9PiJejiVgiSFdTCd2aI+6XL165P2Oq0m0KsaFXFv1r5B+sHNlgtSFB0X8WWUWiya1tBeeNDWWu sRjVeYVzAitXPfi/O7MxAzgZ3UaoYilZb9SM4KIgkUd6YltL9wgNhlKx9EfPDnSQv9rRNbvIWQ4Wr dTs7Ry4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKiM-002kYy-9l; Fri, 29 Jul 2022 07:47:18 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfX-002j93-UV for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:25 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31f46b4759bso36510597b3.0 for ; Fri, 29 Jul 2022 00:44:23 -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=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=L9UT7pFKEMv8kmhKTFboeMQHgbNjypzxWtClefHRJXeuk7El88DNhUGL4PqSb2pxBt UUcOzUDVOnbLXDk7ADQF8gwzoy0tFbnIJQoWp00c6r1J4xo8jWshWT4mpOhestPPnV2m 31p0htLfJiSCQ2GcnIhA8XjMPzhJ6UF1OOS72tmsudDUX5X5uOjGU4aDnEPbBzQtFfPR h9/FepigXVjZTiyqlOKgRSaq9TO9PIy2rPBTb5Jiuxn3ceLTiENmnJj2kVS37+Xg+5sN C+JZfVZ4SXaxQMf/IsC0qlPUQKGYUPG8J+i1wpIpv4uwKIjNgz+tD/cTlkJWh3krAyHJ duMg== 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=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=hslxldq2tkEvhM14xPtLlRk0XMEUEJ5wwV4D6yVpqDBHmbdzzoZF7SVXOTcygyiFhe CZPsAAnBtORG6kXr/gu8vvgsV15AQFSTQeJWT0SA+sXsic3rEfhLKWeOuhfTa2Q3QUqf 0z2Qy+qhUm3UshGgsGatdvICizAF0f9kwUMqMVdO8da3AY/HfroPy/agxzY26oSrDEG7 QPOiSHq5WUL8Dt05oFhdqLr5XXmep/US2VSG/k8CnFGvsOQTJ72Ga8Ln9ggNf/6eBg2s 6pRXVS5bGGXLCH6ruhVp8uQzX/4YffrbzUskeZe1hrCzN/KXiJNA/5E2C9YIDJxGOPaH kHeQ== X-Gm-Message-State: ACgBeo3yZeNMg5nvsabipBd1f5F8v5Esg/CgEdE8IPDxD6DfRLJQondR mP92v/VFHOf5yWfG7090cH8m4MZPebAB X-Google-Smtp-Source: AA6agR4lvVMHfSoejMkozQjmS9qJTDKTwsU5cAD6r+dvPCEB7yVOfvYBAS7Y09yz2U8G7/kdQP/Wm9mQYGrh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:41d6:0:b0:673:817c:e163 with SMTP id o205-20020a2541d6000000b00673817ce163mr1461338yba.561.1659080662475; Fri, 29 Jul 2022 00:44:22 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:42 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-9-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 08/17] perf pmu-events: Hide pmu_sys_event_tables 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004424_039183_FC9A29BB X-CRM114-Status: GOOD ( 21.05 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move usage of the table to pmu-events.c so it may be hidden. By abstracting the table the implementation can later be changed. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 37 ++++++++++++++++++- tools/perf/pmu-events/jevents.py | 45 ++++++++++++++++++++++-- tools/perf/pmu-events/pmu-events.h | 11 +++--- tools/perf/tests/pmu-events.c | 14 +------- tools/perf/util/pmu.c | 27 -------------- tools/perf/util/pmu.h | 2 -- 6 files changed, 84 insertions(+), 52 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 4182a986f505..216ea0482c37 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -6,6 +6,8 @@ * The test cpu/soc is provided for testing. */ #include "pmu-events/pmu-events.h" +#include +#include static const struct pmu_event pme_test_soc_cpu[] = { { @@ -145,7 +147,12 @@ static const struct pmu_event pme_test_soc_sys[] = { }, }; -const struct pmu_sys_events pmu_sys_event_tables[] = { +struct pmu_sys_events { + const char *name; + const struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { { .table = pme_test_soc_sys, .name = "pme_test_soc_sys", @@ -154,3 +161,31 @@ const struct pmu_sys_events pmu_sys_event_tables[] = { .table = 0 }, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 30e0e792221a..dd21bc9eeeed 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -370,8 +370,14 @@ def print_mapping_table(archs: Sequence[str]) -> None: def print_system_mapping_table() -> None: """C struct mapping table array for tables from /sys directories.""" - _args.output_file.write( - '\nconst struct pmu_sys_events pmu_sys_event_tables[] = {\n') + _args.output_file.write(""" +struct pmu_sys_events { +\tconst char *name; +\tconst struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { +""") for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ \t\t.table = {tblname}, @@ -382,6 +388,34 @@ def print_system_mapping_table() -> None: \t\t.table = 0 \t}, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} """) @@ -413,7 +447,12 @@ def main() -> None: 'output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout) _args = ap.parse_args() - _args.output_file.write("#include \"pmu-events/pmu-events.h\"\n") + _args.output_file.write(""" +#include "pmu-events/pmu-events.h" +#include +#include + +""") archs = [] for item in os.scandir(_args.starting_dir): if not item.is_dir(): diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index a491b117c8ac..2386212b1df0 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -43,16 +43,15 @@ struct pmu_events_map { const struct pmu_event *table; }; -struct pmu_sys_events { - const char *name; - const struct pmu_event *table; -}; - /* * Global table mapping each known CPU for the architecture to its * table of PMU events. */ extern const struct pmu_events_map pmu_events_map[]; -extern const struct pmu_sys_events pmu_sys_event_tables[]; + +const struct pmu_event *find_sys_events_table(const char *name); + +typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, void *data); +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); #endif diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 82192f1a7bf7..a39a2c99ede6 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -286,18 +286,6 @@ static const struct pmu_events_map *__test_pmu_get_events_map(void) return NULL; } -static const struct pmu_event *__test_pmu_get_sys_events_table(void) -{ - const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; - - for ( ; tables->name; tables++) { - if (!strcmp("pme_test_soc_sys", tables->name)) - return tables->table; - } - - return NULL; -} - static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2) { if (!is_same(e1->name, e2->name)) { @@ -451,7 +439,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); + const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); const struct pmu_events_map *map = __test_pmu_get_events_map(); const struct pmu_event *table; int map_events = 0, expected_events; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0112e1c36418..d8717c4548a4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -868,33 +868,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) pmu_add_cpu_aliases_map(head, pmu, map); } -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data) -{ - int i = 0; - - while (1) { - const struct pmu_sys_events *event_table; - int j = 0; - - event_table = &pmu_sys_event_tables[i++]; - - if (!event_table->table) - break; - - while (1) { - const struct pmu_event *pe = &event_table->table[j++]; - int ret; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - - ret = fn(pe, data); - if (ret) - break; - } - } -} - struct pmu_sys_event_iter_data { struct list_head *head; struct perf_pmu *pmu; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 4b45fd8da5a3..7e667eec2a01 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -133,8 +133,6 @@ const struct pmu_events_map *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); -typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data); -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data); int perf_pmu__convert_scale(const char *scale, char **end, double *sval); int perf_pmu__caps_parse(struct perf_pmu *pmu); -- 2.37.1.455.g008518b4e5-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel