]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf pmu: Make pmu_event tables const.
authorIan Rogers <irogers@google.com>
Fri, 15 Oct 2021 17:21:15 +0000 (10:21 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 Oct 2021 13:32:33 +0000 (10:32 -0300)
Make lookup nature of data structures clearer through their type. Reduce
scope of architecture specific pmu_event tables by making them static.

Suggested-by: John Garry <john.garry@huawei.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/powerpc/util/header.c
tools/perf/pmu-events/jevents.c
tools/perf/pmu-events/pmu-events.h
tools/perf/tests/pmu-events.c
tools/perf/util/metricgroup.c
tools/perf/util/metricgroup.h
tools/perf/util/pmu.c
tools/perf/util/pmu.h
tools/perf/util/s390-sample-raw.c

index 58b2d610aadbfd0b4d14ffb82835ebeac81d55d3..e8fe36b10d20c52b46f9dc5708dde8b10545e967 100644 (file)
@@ -40,7 +40,7 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
        return bufp;
 }
 
-int arch_get_runtimeparam(struct pmu_event *pe)
+int arch_get_runtimeparam(const struct pmu_event *pe)
 {
        int count;
        char path[PATH_MAX] = "/devices/hv_24x7/interface/";
index cff06604f1692d52ddc67084e4fb54534276fd58..26b0ba6b63951ac2cba66e33bd28d0e03387b6a9 100644 (file)
@@ -362,7 +362,7 @@ static int close_table;
 
 static void print_events_table_prefix(FILE *fp, const char *tblname)
 {
-       fprintf(fp, "struct pmu_event %s[] = {\n", tblname);
+       fprintf(fp, "static const struct pmu_event %s[] = {\n", tblname);
        close_table = 1;
 }
 
index f6c9c9fc4ab27d0a2d25f50b909ddcdb57f6880e..6efe73976440bcda0eef768da01fdfb34abbeaa5 100644 (file)
@@ -41,12 +41,12 @@ struct pmu_events_map {
        const char *cpuid;
        const char *version;
        const char *type;               /* core, uncore etc */
-       struct pmu_event *table;
+       const struct pmu_event *table;
 };
 
 struct pmu_sys_events {
        const char *name;
-       struct pmu_event *table;
+       const struct pmu_event *table;
 };
 
 /*
index c0f8b61871c889c90c7f2b98ded5145445ee4d38..cc5cea141bebe5865bada74b83fd1ab0627a6df6 100644 (file)
@@ -256,7 +256,7 @@ static const struct pmu_events_map *__test_pmu_get_events_map(void)
        return NULL;
 }
 
-static struct pmu_event *__test_pmu_get_sys_events_table(void)
+static const struct pmu_event *__test_pmu_get_sys_events_table(void)
 {
        const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
 
@@ -268,7 +268,7 @@ static struct pmu_event *__test_pmu_get_sys_events_table(void)
        return NULL;
 }
 
-static int compare_pmu_events(struct pmu_event *e1, const struct pmu_event *e2)
+static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2)
 {
        if (!is_same(e1->name, e2->name)) {
                pr_debug2("testing event e1 %s: mismatched name string, %s vs %s\n",
@@ -420,9 +420,9 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias,
 /* Verify generated events from pmu-events.c are as expected */
 static int test_pmu_event_table(void)
 {
-       struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table();
+       const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table();
        const struct pmu_events_map *map = __test_pmu_get_events_map();
-       struct pmu_event *table;
+       const struct pmu_event *table;
        int map_events = 0, expected_events;
 
        /* ignore 3x sentinels */
@@ -774,7 +774,7 @@ static int check_parse_id(const char *id, struct parse_events_error *error,
        return ret;
 }
 
-static int check_parse_cpu(const char *id, bool same_cpu, struct pmu_event *pe)
+static int check_parse_cpu(const char *id, bool same_cpu, const struct pmu_event *pe)
 {
        struct parse_events_error error = { .idx = 0, };
 
@@ -838,7 +838,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx,
                all = true;
                hashmap__for_each_entry_safe(pctx->ids, cur, cur_tmp, bkt) {
                        struct metric_ref *ref;
-                       struct pmu_event *pe;
+                       const struct pmu_event *pe;
 
                        pe = metricgroup__find_metric(cur->key, map);
                        if (!pe)
@@ -887,7 +887,7 @@ static int test_parsing(void)
 {
        const struct pmu_events_map *cpus_map = pmu_events_map__find();
        const struct pmu_events_map *map;
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        int i, j, k;
        int ret = 0;
        struct expr_parse_ctx *ctx;
@@ -1028,7 +1028,7 @@ out:
 static int test_parsing_fake(void)
 {
        const struct pmu_events_map *map;
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        unsigned int i, j;
        int err = 0;
 
index 74ea0a3540ce1944fa62c6baf46e50a28302ab94..b60ccbbf08297d069246a160491b3c883b1ff73b 100644 (file)
@@ -427,7 +427,7 @@ static bool match_metric(const char *n, const char *list)
        return false;
 }
 
-static bool match_pe_metric(struct pmu_event *pe, const char *metric)
+static bool match_pe_metric(const struct pmu_event *pe, const char *metric)
 {
        return match_metric(pe->metric_group, metric) ||
               match_metric(pe->metric_name, metric);
@@ -511,7 +511,7 @@ static void metricgroup__print_strlist(struct strlist *metrics, bool raw)
                putchar('\n');
 }
 
-static int metricgroup__print_pmu_event(struct pmu_event *pe,
+static int metricgroup__print_pmu_event(const struct pmu_event *pe,
                                        bool metricgroups, char *filter,
                                        bool raw, bool details,
                                        struct rblist *groups,
@@ -586,14 +586,14 @@ struct metricgroup_print_sys_idata {
        bool details;
 };
 
-typedef int (*metricgroup_sys_event_iter_fn)(struct pmu_event *pe, void *);
+typedef int (*metricgroup_sys_event_iter_fn)(const struct pmu_event *pe, void *);
 
 struct metricgroup_iter_data {
        metricgroup_sys_event_iter_fn fn;
        void *data;
 };
 
-static int metricgroup__sys_event_iter(struct pmu_event *pe, void *data)
+static int metricgroup__sys_event_iter(const struct pmu_event *pe, void *data)
 {
        struct metricgroup_iter_data *d = data;
        struct perf_pmu *pmu = NULL;
@@ -612,7 +612,7 @@ static int metricgroup__sys_event_iter(struct pmu_event *pe, void *data)
        return 0;
 }
 
-static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data)
+static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, void *data)
 {
        struct metricgroup_print_sys_idata *d = data;
 
@@ -624,7 +624,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
                        bool raw, bool details)
 {
        const struct pmu_events_map *map = pmu_events_map__find();
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        int i;
        struct rblist groups;
        struct rb_node *node, *next;
@@ -756,7 +756,7 @@ static void metricgroup___watchdog_constraint_hint(const char *name, bool foot)
                   "    echo 1 > /proc/sys/kernel/nmi_watchdog\n");
 }
 
-static bool metricgroup__has_constraint(struct pmu_event *pe)
+static bool metricgroup__has_constraint(const struct pmu_event *pe)
 {
        if (!pe->metric_constraint)
                return false;
@@ -770,7 +770,7 @@ static bool metricgroup__has_constraint(struct pmu_event *pe)
        return false;
 }
 
-int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
+int __weak arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused)
 {
        return 1;
 }
@@ -785,7 +785,7 @@ struct metricgroup_add_iter_data {
 };
 
 static int __add_metric(struct list_head *metric_list,
-                       struct pmu_event *pe,
+                       const struct pmu_event *pe,
                        bool metric_no_group,
                        int runtime,
                        struct metric **mp,
@@ -909,10 +909,10 @@ static int __add_metric(struct list_head *metric_list,
                    (match_metric(__pe->metric_group, __metric) ||      \
                     match_metric(__pe->metric_name, __metric)))
 
-struct pmu_event *metricgroup__find_metric(const char *metric,
-                                          const struct pmu_events_map *map)
+const struct pmu_event *metricgroup__find_metric(const char *metric,
+                                                const struct pmu_events_map *map)
 {
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        int i;
 
        map_for_each_event(pe, i, map) {
@@ -968,7 +968,7 @@ static int recursion_check(struct metric *m, const char *id, struct expr_id **pa
 }
 
 static int add_metric(struct list_head *metric_list,
-                     struct pmu_event *pe,
+                     const struct pmu_event *pe,
                      bool metric_no_group,
                      struct metric **mp,
                      struct expr_id *parent,
@@ -993,7 +993,7 @@ static int __resolve_metric(struct metric *m,
                all = true;
                hashmap__for_each_entry(m->pctx->ids, cur, bkt) {
                        struct expr_id *parent;
-                       struct pmu_event *pe;
+                       const struct pmu_event *pe;
 
                        pe = metricgroup__find_metric(cur->key, map);
                        if (!pe)
@@ -1040,7 +1040,7 @@ static int resolve_metric(bool metric_no_group,
 }
 
 static int add_metric(struct list_head *metric_list,
-                     struct pmu_event *pe,
+                     const struct pmu_event *pe,
                      bool metric_no_group,
                      struct metric **m,
                      struct expr_id *parent,
@@ -1070,7 +1070,7 @@ static int add_metric(struct list_head *metric_list,
        return ret;
 }
 
-static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
+static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe,
                                                  void *data)
 {
        struct metricgroup_add_iter_data *d = data;
@@ -1102,7 +1102,7 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
                                   const struct pmu_events_map *map)
 {
        struct expr_ids ids = { .cnt = 0, };
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        struct metric *m;
        LIST_HEAD(list);
        int i, ret;
@@ -1286,7 +1286,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist,
 bool metricgroup__has_metric(const char *metric)
 {
        const struct pmu_events_map *map = pmu_events_map__find();
-       struct pmu_event *pe;
+       const struct pmu_event *pe;
        int i;
 
        if (!map)
index c931596557bf8aea40b54c552c808034c2d191da..88ba939a3082c81ba21a56ce790ff2cd661228f0 100644 (file)
@@ -43,8 +43,8 @@ int metricgroup__parse_groups(const struct option *opt,
                              bool metric_no_group,
                              bool metric_no_merge,
                              struct rblist *metric_events);
-struct pmu_event *metricgroup__find_metric(const char *metric,
-                                          const struct pmu_events_map *map);
+const struct pmu_event *metricgroup__find_metric(const char *metric,
+                                                const struct pmu_events_map *map);
 int metricgroup__parse_groups_test(struct evlist *evlist,
                                   const struct pmu_events_map *map,
                                   const char *str,
@@ -55,7 +55,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist,
 void metricgroup__print(bool metrics, bool groups, char *filter,
                        bool raw, bool details);
 bool metricgroup__has_metric(const char *metric);
-int arch_get_runtimeparam(struct pmu_event *pe __maybe_unused);
+int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused);
 void metricgroup__rblist_exit(struct rblist *metric_events);
 
 int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
index c04a89cc7cef94e18979855e4b0fd603851127cb..cdd6c3f6caf130adcb68426b851c508ad535e90b 100644 (file)
@@ -315,7 +315,7 @@ static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
 }
 
 static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
-                                char *desc, char *val, struct pmu_event *pe)
+                                char *desc, char *val, const struct pmu_event *pe)
 {
        struct parse_events_term *term;
        struct perf_pmu_alias *alias;
@@ -834,7 +834,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
        i = 0;
        while (1) {
                const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu";
-               struct pmu_event *pe = &map->table[i++];
+               const struct pmu_event *pe = &map->table[i++];
                const char *pname = pe->pmu ? pe->pmu : cpu_name;
 
                if (!pe->name) {
@@ -882,7 +882,7 @@ void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data)
                        break;
 
                while (1) {
-                       struct pmu_event *pe = &event_table->table[j++];
+                       const struct pmu_event *pe = &event_table->table[j++];
                        int ret;
 
                        if (!pe->name && !pe->metric_group && !pe->metric_name)
@@ -900,7 +900,7 @@ struct pmu_sys_event_iter_data {
        struct perf_pmu *pmu;
 };
 
-static int pmu_add_sys_aliases_iter_fn(struct pmu_event *pe, void *data)
+static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, void *data)
 {
        struct pmu_sys_event_iter_data *idata = data;
        struct perf_pmu *pmu = idata->pmu;
index dd5cdde6a3d0907f375919d5686af7391faa61da..cc9f9e00134725ca1e9258bb3ea6516fe5d8fdbb 100644 (file)
@@ -127,7 +127,7 @@ 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)(struct pmu_event *pe, void *data);
+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);
 
index 13f33d1ddb7847784733fb3403f1b0e9110689db..cd3a34840389eaecf0273cfc0ade4d0f5c847814 100644 (file)
@@ -140,7 +140,7 @@ static const char *get_counter_name(int set, int nr, const struct pmu_events_map
        int rc, event_nr, wanted = get_counterset_start(set) + nr;
 
        if (map) {
-               struct pmu_event *evp = map->table;
+               const struct pmu_event *evp = map->table;
 
                for (; evp->name || evp->event || evp->desc; ++evp) {
                        if (evp->name == NULL || evp->event == NULL)