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

Configure Feed

Select the types of activity you want to include in your feed.

perf pmu-events: Add pmu_events_table__find_event()

jevents stores events sorted by name. Add a find function that will
binary search event names avoiding the need to linearly search through
events.

Add a test in tests/pmu-events.c. If the PMU or event aren't found -1000
is returned. If the event is found but no callback function given, 0 is
returned.

This allows the find function also act as a test for existence.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-9-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
3d504549 e3edd6cf

+90
+16
tools/perf/pmu-events/empty-pmu-events.c
··· 282 282 return 0; 283 283 } 284 284 285 + int pmu_events_table__find_event(const struct pmu_events_table *table, 286 + struct perf_pmu *pmu, 287 + const char *name, 288 + pmu_event_iter_fn fn, 289 + void *data) 290 + { 291 + for (const struct pmu_event *pe = &table->entries[0]; pe->name; pe++) { 292 + if (pmu && !pmu__name_match(pmu, pe->pmu)) 293 + continue; 294 + 295 + if (!strcasecmp(pe->name, name)) 296 + return fn(pe, table, data); 297 + } 298 + return -1000; 299 + } 300 + 285 301 int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, 286 302 void *data) 287 303 {
+64
tools/perf/pmu-events/jevents.py
··· 825 825 return 0; 826 826 } 827 827 828 + static int pmu_events_table__find_event_pmu(const struct pmu_events_table *table, 829 + const struct pmu_table_entry *pmu, 830 + const char *name, 831 + pmu_event_iter_fn fn, 832 + void *data) 833 + { 834 + struct pmu_event pe = { 835 + .pmu = &big_c_string[pmu->pmu_name.offset], 836 + }; 837 + int low = 0, high = pmu->num_entries - 1; 838 + 839 + while (low <= high) { 840 + int cmp, mid = (low + high) / 2; 841 + 842 + decompress_event(pmu->entries[mid].offset, &pe); 843 + 844 + if (!pe.name && !name) 845 + goto do_call; 846 + 847 + if (!pe.name && name) { 848 + low = mid + 1; 849 + continue; 850 + } 851 + if (pe.name && !name) { 852 + high = mid - 1; 853 + continue; 854 + } 855 + 856 + cmp = strcasecmp(pe.name, name); 857 + if (cmp < 0) { 858 + low = mid + 1; 859 + continue; 860 + } 861 + if (cmp > 0) { 862 + high = mid - 1; 863 + continue; 864 + } 865 + do_call: 866 + return fn ? fn(&pe, table, data) : 0; 867 + } 868 + return -1000; 869 + } 870 + 828 871 int pmu_events_table__for_each_event(const struct pmu_events_table *table, 829 872 struct perf_pmu *pmu, 830 873 pmu_event_iter_fn fn, ··· 886 843 return ret; 887 844 } 888 845 return 0; 846 + } 847 + 848 + int pmu_events_table__find_event(const struct pmu_events_table *table, 849 + struct perf_pmu *pmu, 850 + const char *name, 851 + pmu_event_iter_fn fn, 852 + void *data) 853 + { 854 + for (size_t i = 0; i < table->num_pmus; i++) { 855 + const struct pmu_table_entry *table_pmu = &table->pmus[i]; 856 + const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset]; 857 + int ret; 858 + 859 + if (!pmu__name_match(pmu, pmu_name)) 860 + continue; 861 + 862 + ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data); 863 + if (ret != -1000) 864 + return ret; 865 + } 866 + return -1000; 889 867 } 890 868 891 869 static int pmu_metrics_table__for_each_metric_pmu(const struct pmu_metrics_table *table,
+5
tools/perf/pmu-events/pmu-events.h
··· 81 81 struct perf_pmu *pmu, 82 82 pmu_event_iter_fn fn, 83 83 void *data); 84 + int pmu_events_table__find_event(const struct pmu_events_table *table, 85 + struct perf_pmu *pmu, 86 + const char *name, 87 + pmu_event_iter_fn fn, 88 + void *data); 84 89 int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, 85 90 void *data); 86 91
+5
tools/perf/tests/pmu-events.c
··· 546 546 547 547 pmu_add_cpu_aliases_table(pmu, table); 548 548 549 + res = pmu_events_table__find_event(table, pmu, "bp_l1_btb_correct", NULL, NULL); 550 + if (res != 0) { 551 + pr_debug("Missing test event in test architecture"); 552 + return res; 553 + } 549 554 for (; *test_event_table; test_event_table++) { 550 555 struct perf_pmu_test_event test_event = **test_event_table; 551 556 struct pmu_event const *event = &test_event.event;