Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf pmu: Make pmu_event tables const.

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
47f572aa 857974a6

+39 -39
+1 -1
tools/perf/arch/powerpc/util/header.c
··· 40 40 return bufp; 41 41 } 42 42 43 - int arch_get_runtimeparam(struct pmu_event *pe) 43 + int arch_get_runtimeparam(const struct pmu_event *pe) 44 44 { 45 45 int count; 46 46 char path[PATH_MAX] = "/devices/hv_24x7/interface/";
+1 -1
tools/perf/pmu-events/jevents.c
··· 362 362 363 363 static void print_events_table_prefix(FILE *fp, const char *tblname) 364 364 { 365 - fprintf(fp, "struct pmu_event %s[] = {\n", tblname); 365 + fprintf(fp, "static const struct pmu_event %s[] = {\n", tblname); 366 366 close_table = 1; 367 367 } 368 368
+2 -2
tools/perf/pmu-events/pmu-events.h
··· 41 41 const char *cpuid; 42 42 const char *version; 43 43 const char *type; /* core, uncore etc */ 44 - struct pmu_event *table; 44 + const struct pmu_event *table; 45 45 }; 46 46 47 47 struct pmu_sys_events { 48 48 const char *name; 49 - struct pmu_event *table; 49 + const struct pmu_event *table; 50 50 }; 51 51 52 52 /*
+8 -8
tools/perf/tests/pmu-events.c
··· 256 256 return NULL; 257 257 } 258 258 259 - static struct pmu_event *__test_pmu_get_sys_events_table(void) 259 + static const struct pmu_event *__test_pmu_get_sys_events_table(void) 260 260 { 261 261 const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; 262 262 ··· 268 268 return NULL; 269 269 } 270 270 271 - static int compare_pmu_events(struct pmu_event *e1, const struct pmu_event *e2) 271 + static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2) 272 272 { 273 273 if (!is_same(e1->name, e2->name)) { 274 274 pr_debug2("testing event e1 %s: mismatched name string, %s vs %s\n", ··· 420 420 /* Verify generated events from pmu-events.c are as expected */ 421 421 static int test_pmu_event_table(void) 422 422 { 423 - struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); 423 + const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); 424 424 const struct pmu_events_map *map = __test_pmu_get_events_map(); 425 - struct pmu_event *table; 425 + const struct pmu_event *table; 426 426 int map_events = 0, expected_events; 427 427 428 428 /* ignore 3x sentinels */ ··· 774 774 return ret; 775 775 } 776 776 777 - static int check_parse_cpu(const char *id, bool same_cpu, struct pmu_event *pe) 777 + static int check_parse_cpu(const char *id, bool same_cpu, const struct pmu_event *pe) 778 778 { 779 779 struct parse_events_error error = { .idx = 0, }; 780 780 ··· 838 838 all = true; 839 839 hashmap__for_each_entry_safe(pctx->ids, cur, cur_tmp, bkt) { 840 840 struct metric_ref *ref; 841 - struct pmu_event *pe; 841 + const struct pmu_event *pe; 842 842 843 843 pe = metricgroup__find_metric(cur->key, map); 844 844 if (!pe) ··· 887 887 { 888 888 const struct pmu_events_map *cpus_map = pmu_events_map__find(); 889 889 const struct pmu_events_map *map; 890 - struct pmu_event *pe; 890 + const struct pmu_event *pe; 891 891 int i, j, k; 892 892 int ret = 0; 893 893 struct expr_parse_ctx *ctx; ··· 1028 1028 static int test_parsing_fake(void) 1029 1029 { 1030 1030 const struct pmu_events_map *map; 1031 - struct pmu_event *pe; 1031 + const struct pmu_event *pe; 1032 1032 unsigned int i, j; 1033 1033 int err = 0; 1034 1034
+18 -18
tools/perf/util/metricgroup.c
··· 427 427 return false; 428 428 } 429 429 430 - static bool match_pe_metric(struct pmu_event *pe, const char *metric) 430 + static bool match_pe_metric(const struct pmu_event *pe, const char *metric) 431 431 { 432 432 return match_metric(pe->metric_group, metric) || 433 433 match_metric(pe->metric_name, metric); ··· 511 511 putchar('\n'); 512 512 } 513 513 514 - static int metricgroup__print_pmu_event(struct pmu_event *pe, 514 + static int metricgroup__print_pmu_event(const struct pmu_event *pe, 515 515 bool metricgroups, char *filter, 516 516 bool raw, bool details, 517 517 struct rblist *groups, ··· 586 586 bool details; 587 587 }; 588 588 589 - typedef int (*metricgroup_sys_event_iter_fn)(struct pmu_event *pe, void *); 589 + typedef int (*metricgroup_sys_event_iter_fn)(const struct pmu_event *pe, void *); 590 590 591 591 struct metricgroup_iter_data { 592 592 metricgroup_sys_event_iter_fn fn; 593 593 void *data; 594 594 }; 595 595 596 - static int metricgroup__sys_event_iter(struct pmu_event *pe, void *data) 596 + static int metricgroup__sys_event_iter(const struct pmu_event *pe, void *data) 597 597 { 598 598 struct metricgroup_iter_data *d = data; 599 599 struct perf_pmu *pmu = NULL; ··· 612 612 return 0; 613 613 } 614 614 615 - static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data) 615 + static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, void *data) 616 616 { 617 617 struct metricgroup_print_sys_idata *d = data; 618 618 ··· 624 624 bool raw, bool details) 625 625 { 626 626 const struct pmu_events_map *map = pmu_events_map__find(); 627 - struct pmu_event *pe; 627 + const struct pmu_event *pe; 628 628 int i; 629 629 struct rblist groups; 630 630 struct rb_node *node, *next; ··· 756 756 " echo 1 > /proc/sys/kernel/nmi_watchdog\n"); 757 757 } 758 758 759 - static bool metricgroup__has_constraint(struct pmu_event *pe) 759 + static bool metricgroup__has_constraint(const struct pmu_event *pe) 760 760 { 761 761 if (!pe->metric_constraint) 762 762 return false; ··· 770 770 return false; 771 771 } 772 772 773 - int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused) 773 + int __weak arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused) 774 774 { 775 775 return 1; 776 776 } ··· 785 785 }; 786 786 787 787 static int __add_metric(struct list_head *metric_list, 788 - struct pmu_event *pe, 788 + const struct pmu_event *pe, 789 789 bool metric_no_group, 790 790 int runtime, 791 791 struct metric **mp, ··· 909 909 (match_metric(__pe->metric_group, __metric) || \ 910 910 match_metric(__pe->metric_name, __metric))) 911 911 912 - struct pmu_event *metricgroup__find_metric(const char *metric, 913 - const struct pmu_events_map *map) 912 + const struct pmu_event *metricgroup__find_metric(const char *metric, 913 + const struct pmu_events_map *map) 914 914 { 915 - struct pmu_event *pe; 915 + const struct pmu_event *pe; 916 916 int i; 917 917 918 918 map_for_each_event(pe, i, map) { ··· 968 968 } 969 969 970 970 static int add_metric(struct list_head *metric_list, 971 - struct pmu_event *pe, 971 + const struct pmu_event *pe, 972 972 bool metric_no_group, 973 973 struct metric **mp, 974 974 struct expr_id *parent, ··· 993 993 all = true; 994 994 hashmap__for_each_entry(m->pctx->ids, cur, bkt) { 995 995 struct expr_id *parent; 996 - struct pmu_event *pe; 996 + const struct pmu_event *pe; 997 997 998 998 pe = metricgroup__find_metric(cur->key, map); 999 999 if (!pe) ··· 1040 1040 } 1041 1041 1042 1042 static int add_metric(struct list_head *metric_list, 1043 - struct pmu_event *pe, 1043 + const struct pmu_event *pe, 1044 1044 bool metric_no_group, 1045 1045 struct metric **m, 1046 1046 struct expr_id *parent, ··· 1070 1070 return ret; 1071 1071 } 1072 1072 1073 - static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, 1073 + static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe, 1074 1074 void *data) 1075 1075 { 1076 1076 struct metricgroup_add_iter_data *d = data; ··· 1102 1102 const struct pmu_events_map *map) 1103 1103 { 1104 1104 struct expr_ids ids = { .cnt = 0, }; 1105 - struct pmu_event *pe; 1105 + const struct pmu_event *pe; 1106 1106 struct metric *m; 1107 1107 LIST_HEAD(list); 1108 1108 int i, ret; ··· 1286 1286 bool metricgroup__has_metric(const char *metric) 1287 1287 { 1288 1288 const struct pmu_events_map *map = pmu_events_map__find(); 1289 - struct pmu_event *pe; 1289 + const struct pmu_event *pe; 1290 1290 int i; 1291 1291 1292 1292 if (!map)
+3 -3
tools/perf/util/metricgroup.h
··· 43 43 bool metric_no_group, 44 44 bool metric_no_merge, 45 45 struct rblist *metric_events); 46 - struct pmu_event *metricgroup__find_metric(const char *metric, 47 - const struct pmu_events_map *map); 46 + const struct pmu_event *metricgroup__find_metric(const char *metric, 47 + const struct pmu_events_map *map); 48 48 int metricgroup__parse_groups_test(struct evlist *evlist, 49 49 const struct pmu_events_map *map, 50 50 const char *str, ··· 55 55 void metricgroup__print(bool metrics, bool groups, char *filter, 56 56 bool raw, bool details); 57 57 bool metricgroup__has_metric(const char *metric); 58 - int arch_get_runtimeparam(struct pmu_event *pe __maybe_unused); 58 + int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused); 59 59 void metricgroup__rblist_exit(struct rblist *metric_events); 60 60 61 61 int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
+4 -4
tools/perf/util/pmu.c
··· 315 315 } 316 316 317 317 static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, 318 - char *desc, char *val, struct pmu_event *pe) 318 + char *desc, char *val, const struct pmu_event *pe) 319 319 { 320 320 struct parse_events_term *term; 321 321 struct perf_pmu_alias *alias; ··· 834 834 i = 0; 835 835 while (1) { 836 836 const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu"; 837 - struct pmu_event *pe = &map->table[i++]; 837 + const struct pmu_event *pe = &map->table[i++]; 838 838 const char *pname = pe->pmu ? pe->pmu : cpu_name; 839 839 840 840 if (!pe->name) { ··· 882 882 break; 883 883 884 884 while (1) { 885 - struct pmu_event *pe = &event_table->table[j++]; 885 + const struct pmu_event *pe = &event_table->table[j++]; 886 886 int ret; 887 887 888 888 if (!pe->name && !pe->metric_group && !pe->metric_name) ··· 900 900 struct perf_pmu *pmu; 901 901 }; 902 902 903 - static int pmu_add_sys_aliases_iter_fn(struct pmu_event *pe, void *data) 903 + static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, void *data) 904 904 { 905 905 struct pmu_sys_event_iter_data *idata = data; 906 906 struct perf_pmu *pmu = idata->pmu;
+1 -1
tools/perf/util/pmu.h
··· 127 127 bool pmu_uncore_alias_match(const char *pmu_name, const char *name); 128 128 void perf_pmu_free_alias(struct perf_pmu_alias *alias); 129 129 130 - typedef int (*pmu_sys_event_iter_fn)(struct pmu_event *pe, void *data); 130 + typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data); 131 131 void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data); 132 132 int perf_pmu__convert_scale(const char *scale, char **end, double *sval); 133 133
+1 -1
tools/perf/util/s390-sample-raw.c
··· 140 140 int rc, event_nr, wanted = get_counterset_start(set) + nr; 141 141 142 142 if (map) { 143 - struct pmu_event *evp = map->table; 143 + const struct pmu_event *evp = map->table; 144 144 145 145 for (; evp->name || evp->event || evp->desc; ++evp) { 146 146 if (evp->name == NULL || evp->event == NULL)