linux/tools/perf/util
Ian Rogers 7b6dd7a923 perf pmu: Assume sysfs events are always the same case
Perf event names aren't case sensitive. For sysfs events the entire
directory of events is read then iterated comparing names in a case
insensitive way, most often to see if an event is present.

Consider:

  $ perf stat -e inst_retired.any true

The event inst_retired.any may be present in any PMU, so every PMU's
sysfs events are loaded and then searched with strcasecmp to see if
any match. This event is only present on the cpu PMU as a JSON event
so a lot of events were loaded from sysfs unnecessarily just to prove
an event didn't exist there.

This change avoids loading all the events by assuming sysfs event
names are always either lower or uppercase. It uses file exists and
only loads the events when the desired event is present.

For the example above, the number of openat calls measured by 'perf
trace' on a tigerlake laptop goes from 325 down to 255. The reduction
will be larger for machines with many PMUs, particularly replicated
uncore PMUs.

Ensure pmu_aliases_parse() is called before all uses of the aliases
list, but remove some "pmu->sysfs_aliases_loaded" tests as they are now
part of the function.

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Bjorn Helgaas <bhelgaas@google.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: Jonathan Corbet <corbet@lwn.net>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: https://lore.kernel.org/r/20240502213507.2339733-7-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-05-03 17:08:20 -03:00
..
arm-spe-decoder
bpf_skel Merge remote-tracking branch 'torvalds/master' into perf-tools-next 2024-04-22 13:35:18 -03:00
cs-etm-decoder
hisi-ptt-decoder
include tools headers: Update the copy of x86's mem{cpy,set}_64.S used in 'perf bench' 2024-01-30 11:31:15 -03:00
intel-pt-decoder perf intel-pt: Fix unassigned instruction op (discovered by MemorySanitizer) 2024-04-26 22:13:10 -03:00
libunwind
perf-regs-arch perf parse-regs: Always build perf register functions 2024-02-15 13:48:20 -08:00
scripting-engines perf cpumap: Use perf_cpu_map__for_each_cpu when possible 2024-03-21 10:41:28 -03:00
addr_location.c
addr_location.h
affinity.c
affinity.h
amd-sample-raw.c
annotate-data.c perf annotate-data: Check kind of stack variables 2024-05-02 11:06:23 -03:00
annotate-data.h perf annotate-data: Add hist_entry__annotate_data_tui() 2024-04-12 12:02:06 -03:00
annotate.c perf annotate-data: Check if 'struct annotation_source' was allocated on 'perf report' TUI 2024-04-26 22:07:21 -03:00
annotate.h perf annotate: Move 'start' field struct to 'struct annotated_source' 2024-04-08 17:43:20 -03:00
archinsn.h
arm-spe.c
arm-spe.h
arm64-frame-pointer-unwind-support.c
arm64-frame-pointer-unwind-support.h
auxtrace.c perf cpumap: Clean up use of perf_cpu_map__has_any_cpu_or_is_empty 2024-03-21 10:41:28 -03:00
auxtrace.h
block-info.c
block-info.h
block-range.c
block-range.h
bpf-event.c perf maps: Get map before returning in maps__find 2024-02-12 12:35:26 -08:00
bpf-event.h perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-03 17:54:54 -03:00
bpf-filter.c
bpf-filter.h
bpf-filter.l
bpf-filter.y
bpf-prologue.h
bpf-utils.c
bpf-utils.h
bpf_counter.c
bpf_counter.h
bpf_counter_cgroup.c
bpf_ftrace.c
bpf_kwork.c perf cpumap: Use perf_cpu_map__for_each_cpu when possible 2024-03-21 10:41:28 -03:00
bpf_kwork_top.c perf cpumap: Use perf_cpu_map__for_each_cpu when possible 2024-03-21 10:41:28 -03:00
bpf_lock_contention.c perf machine: Move machine's threads into its own abstraction 2024-03-03 22:51:44 -08:00
bpf_map.c
bpf_map.h
bpf_off_cpu.c
branch.c
branch.h
Build perf util: Add shellcheck to generate-cmdlist.sh 2024-04-12 17:54:02 -03:00
build-id.c perf dsos: Switch more loops to dsos__for_each_dso() 2024-04-12 12:04:13 -03:00
build-id.h perf dsos: Attempt to better abstract DSOs internals 2024-04-12 12:04:13 -03:00
cache.h
cacheline.c
cacheline.h
call-path.c
call-path.h
callchain.c perf maps: Hide maps internals 2024-02-12 12:35:41 -08:00
callchain.h
cap.c
cap.h
cgroup.c
cgroup.h
clockid.c
clockid.h
cloexec.c
cloexec.h
color.c
color.h
color_config.c
comm.c
comm.h
compress.h
config.c
config.h
copyfile.c
copyfile.h
counts.c
counts.h
cpu-set-sched.h
cpumap.c perf cpumap: Use perf_cpu_map__for_each_cpu when possible 2024-03-21 10:41:28 -03:00
cpumap.h perf stat: Support per-cluster aggregation 2024-02-09 14:59:53 -08:00
cputopo.c
cputopo.h
cs-etm-base.c
cs-etm.c
cs-etm.h
data-convert-bt.c
data-convert-json.c perf data convert: Fix segfault when converting to json when cpu_desc isn't set 2024-02-26 08:30:17 -08:00
data-convert.h
data.c perf data: Minor code style alignment cleanup 2024-01-22 12:08:21 -08:00
data.h perf data: Minor code style alignment cleanup 2024-01-22 12:08:21 -08:00
db-export.c perf db-export: Fix missing reference count get in call_path_from_sample() 2024-01-04 18:29:17 -03:00
db-export.h
debug.c perf annotate-data: Add debug messages 2024-03-21 10:41:28 -03:00
debug.h perf annotate-data: Add debug messages 2024-03-21 10:41:28 -03:00
debuginfo.c
debuginfo.h
demangle-cxx.cpp
demangle-cxx.h
demangle-java.c
demangle-java.h
demangle-ocaml.c
demangle-ocaml.h
demangle-rust.c
demangle-rust.h
disasm.c perf annotate: Update DSO binary type when trying build-id 2024-04-26 22:12:55 -03:00
disasm.h perf annotate: Split out util/disasm.c 2024-04-03 11:48:57 -03:00
dlfilter.c
dlfilter.h
dso.c perf dso: Move dso functions out of dsos.c 2024-04-12 12:04:13 -03:00
dso.h perf dso: Move dso functions out of dsos.c 2024-04-12 12:04:13 -03:00
dsos.c perf dsos: Switch more loops to dsos__for_each_dso() 2024-04-12 12:04:13 -03:00
dsos.h perf dsos: Switch more loops to dsos__for_each_dso() 2024-04-12 12:04:13 -03:00
dump-insn.c
dump-insn.h perf script: Add capstone support for '-F +brstackdisasm' 2024-04-05 10:43:07 -03:00
dwarf-aux.c perf dwarf-aux: Add die_collect_global_vars() 2024-05-02 10:45:30 -03:00
dwarf-aux.h perf dwarf-aux: Add die_collect_global_vars() 2024-05-02 10:45:30 -03:00
dwarf-regs.c perf dwarf-regs: Add get_dwarf_regnum() 2023-12-23 10:56:05 -03:00
env.c perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-03 17:54:54 -03:00
env.h perf stat: Support per-cluster aggregation 2024-02-09 14:59:53 -08:00
event.c perf maps: Get map before returning in maps__find 2024-02-12 12:35:26 -08:00
event.h
events_stats.h
evlist.c perf evlist: Fix evlist__new_default() for > 1 core PMU 2024-01-30 11:40:28 -03:00
evlist.h
evsel.c perf evsel: Fix duplicate initialization of data->id in evsel__parse_sample() 2024-02-01 22:11:45 -08:00
evsel.h perf util: Add evsel__taskstate() to parse the task state info instead 2024-01-22 23:02:37 -08:00
evsel_config.h
evsel_fprintf.c
evsel_fprintf.h
evswitch.c
evswitch.h
expr.c perf expr: Fix "has_event" function for metric style events 2024-02-13 13:48:06 -08:00
expr.h
expr.l perf expr: Allow NaN to be a valid number 2024-02-13 13:47:08 -08:00
expr.y
find-map.c
fncache.c
fncache.h
ftrace.h
genelf.c
genelf.h perf genelf: Fix compiling with libelf on rv32 2024-04-18 22:22:51 -03:00
genelf_debug.c
generate-cmdlist.sh
get_current_dir_name.c
get_current_dir_name.h
hashmap.c
hashmap.h
header.c perf env: Avoid recursively taking env->bpf_progs.lock 2024-01-03 17:54:54 -03:00
header.h
help-unknown-cmd.c perf help: Lower levenshtein penality for deleting character 2024-03-21 13:54:40 -03:00
help-unknown-cmd.h
hisi-ptt.c
hisi-ptt.h
hist.c perf hist: Add weight fields to hist entry stats 2024-04-17 12:21:39 -03:00
hist.h perf report: Add weight[123] output fields 2024-04-17 12:21:39 -03:00
intel-bts.c
intel-bts.h
intel-pt.c perf intel-pt: Fix unassigned instruction op (discovered by MemorySanitizer) 2024-04-26 22:13:10 -03:00
intel-pt.h
intlist.c
intlist.h
iostat.c
iostat.h
jit.h
jitdump.c
jitdump.h
kvm-stat.h
kwork.h
levenshtein.c
levenshtein.h
lock-contention.h
lzma.c
machine.c perf dsos: Switch more loops to dsos__for_each_dso() 2024-04-12 12:04:13 -03:00
machine.h perf dsos: Attempt to better abstract DSOs internals 2024-04-12 12:04:13 -03:00
map.c perf dsos: Tidy reference counting and locking 2024-04-12 12:04:13 -03:00
map.h perf map: Add map__objdump_2rip() 2024-03-21 10:41:28 -03:00
map_symbol.c
map_symbol.h
maps.c perf maps: Remove check_invariants() from maps__lock() 2024-05-02 16:35:47 -03:00
maps.h perf maps: Locking tidy up of nr_maps 2024-02-12 12:35:41 -08:00
mem-events.c perf mem: Clean up perf_pmus__num_mem_pmus() 2024-01-24 14:05:22 -08:00
mem-events.h perf mem: Clean up perf_pmus__num_mem_pmus() 2024-01-24 14:05:22 -08:00
mem2node.c
mem2node.h
memswap.c
memswap.h
metricgroup.c perf stat: Add new field in stat_config to enable hardware aware grouping 2024-04-18 22:22:51 -03:00
metricgroup.h perf stat: Add new field in stat_config to enable hardware aware grouping 2024-04-18 22:22:51 -03:00
mmap.c
mmap.h
mutex.c
mutex.h
namespaces.c
namespaces.h
off_cpu.h
ordered-events.c
ordered-events.h
parse-branch-options.c
parse-branch-options.h
parse-events.c perf test pmu: Refactor format test and exposed test APIs 2024-05-03 17:08:20 -03:00
parse-events.h perf test pmu: Refactor format test and exposed test APIs 2024-05-03 17:08:20 -03:00
parse-events.l perf parse-events: Tidy the setting of the default event name 2024-04-26 22:07:21 -03:00
parse-events.y perf parse-events: Tidy the setting of the default event name 2024-04-26 22:07:21 -03:00
parse-regs-options.c perf parse-regs: Introduce a weak function arch__sample_reg_masks() 2024-02-15 13:48:36 -08:00
parse-regs-options.h
parse-sublevel-options.c
parse-sublevel-options.h
path.c
path.h
perf-hooks-list.h
perf-hooks.c
perf-hooks.h
PERF-VERSION-GEN
perf_api_probe.c
perf_api_probe.h
perf_event_attr_fprintf.c perf tools: Add/use PMU reverse lookup from config to name 2024-03-21 13:53:45 -03:00
perf_regs.c perf parse-regs: Introduce a weak function arch__sample_reg_masks() 2024-02-15 13:48:36 -08:00
perf_regs.h perf parse-regs: Introduce a weak function arch__sample_reg_masks() 2024-02-15 13:48:36 -08:00
pfm.c
pfm.h
pmu.c perf pmu: Assume sysfs events are always the same case 2024-05-03 17:08:20 -03:00
pmu.h perf test pmu: Refactor format test and exposed test APIs 2024-05-03 17:08:20 -03:00
pmu.l
pmu.y
pmus.c perf test pmu: Refactor format test and exposed test APIs 2024-05-03 17:08:20 -03:00
pmus.h perf test pmu: Refactor format test and exposed test APIs 2024-05-03 17:08:20 -03:00
print-events.c perf list: Give more details about raw event encodings 2024-03-21 10:41:29 -03:00
print-events.h
print_binary.c
print_binary.h
print_insn.c perf script: Consolidate capstone print functions 2024-04-08 17:42:27 -03:00
print_insn.h perf script: Consolidate capstone print functions 2024-04-08 17:42:27 -03:00
probe-event.c perf probe-event: Better error message for a too-long probe name 2024-04-18 22:22:51 -03:00
probe-event.h
probe-file.c
probe-file.h
probe-finder.c
probe-finder.h
pstack.c
pstack.h
python-ext-sources perf evsel: Rename get_states() to parse_task_states() and make it public 2024-02-01 22:10:27 -08:00
python.c perf tools: Add/use PMU reverse lookup from config to name 2024-03-21 13:53:45 -03:00
rb_resort.h perf trace: Ignore thread hashing in summary 2024-03-03 22:51:18 -08:00
rblist.c
rblist.h
record.c perf cpumap: Clean up use of perf_cpu_map__has_any_cpu_or_is_empty 2024-03-21 10:41:28 -03:00
record.h
rlimit.c
rlimit.h
rwsem.c
rwsem.h
s390-cpumcf-kernel.h
s390-cpumsf-kernel.h
s390-cpumsf.c
s390-cpumsf.h
s390-sample-raw.c
sample-raw.c
sample-raw.h
sample.h
session.c perf dsos: Attempt to better abstract DSOs internals 2024-04-12 12:04:13 -03:00
session.h perf dsos: Attempt to better abstract DSOs internals 2024-04-12 12:04:13 -03:00
setns.c
setup.py perf evsel: Rename get_states() to parse_task_states() and make it public 2024-02-01 22:10:27 -08:00
sharded_mutex.c
sharded_mutex.h
sideband_evlist.c
smt.c
smt.h
sort.c perf report: Add weight[123] output fields 2024-04-17 12:21:39 -03:00
sort.h perf report: Add weight[123] output fields 2024-04-17 12:21:39 -03:00
spark.c
spark.h
srccode.c
srccode.h
srcline.c perf srcline: Add missed addr2line closes 2024-02-09 20:43:13 -08:00
srcline.h
stat-display.c perf stat: Fix metric-only aggregation index 2024-02-22 08:57:29 -08:00
stat-shadow.c perf metrics: Compute unmerged uncore metrics individually 2024-02-22 08:57:09 -08:00
stat.c perf cpumap: Clean up use of perf_cpu_map__has_any_cpu_or_is_empty 2024-03-21 10:41:28 -03:00
stat.h perf stat: Add new field in stat_config to enable hardware aware grouping 2024-04-18 22:22:51 -03:00
strbuf.c
strbuf.h
stream.c
stream.h
strfilter.c
strfilter.h
string.c
string2.h
strlist.c
strlist.h
svghelper.c perf cpumap: Use perf_cpu_map__for_each_cpu when possible 2024-03-21 10:41:28 -03:00
svghelper.h
symbol-elf.c perf maps: Get map before returning in maps__find_by_name 2024-02-12 12:35:33 -08:00
symbol-minimal.c
symbol.c perf tools: Fixup module symbol end address properly 2024-02-16 16:07:28 -08:00
symbol.h
symbol_conf.h perf annotate: Add --data-type option 2023-12-23 22:39:43 -03:00
symbol_fprintf.c
symsrc.h
synthetic-events.c perf tools: Fix calloc() arguments to address error introduced in gcc-14 2024-01-26 12:56:01 -03:00
synthetic-events.h
syscalltbl.c
syscalltbl.h
target.c
target.h
term.c
term.h
thread-stack.c
thread-stack.h
thread.c perf machine: Move machine's threads into its own abstraction 2024-03-03 22:51:44 -08:00
thread.h perf machine: Move machine's threads into its own abstraction 2024-03-03 22:51:44 -08:00
thread_map.c perf thread_map: Skip exited threads when scanning /proc 2024-02-22 09:11:03 -08:00
thread_map.h
threads.c perf threads: Switch from rbtree to hashmap 2024-03-03 22:52:04 -08:00
threads.h perf threads: Reduce table size from 256 to 8 2024-03-03 22:52:13 -08:00
time-utils.c
time-utils.h
tool.h
top.c
top.h
topdown.c
topdown.h
trace-event-info.c
trace-event-parse.c perf evsel: Rename get_states() to parse_task_states() and make it public 2024-02-01 22:10:27 -08:00
trace-event-read.c
trace-event-scripting.c
trace-event.c
trace-event.h perf evsel: Rename get_states() to parse_task_states() and make it public 2024-02-01 22:10:27 -08:00
tracepoint.c
tracepoint.h
trigger.h
tsc.c
tsc.h
units.c
units.h
unwind-libdw.c perf maps: Hide maps internals 2024-02-12 12:35:41 -08:00
unwind-libdw.h
unwind-libunwind-local.c perf maps: Hide maps internals 2024-02-12 12:35:41 -08:00
unwind-libunwind.c perf maps: Hide maps internals 2024-02-12 12:35:41 -08:00
unwind.h
usage.c
util.c perf list: Add scandirat compatibility function 2024-02-22 09:11:41 -08:00
util.h perf list: Add scandirat compatibility function 2024-02-22 09:11:41 -08:00
values.c
values.h perf hist: Move histogram related code to hist.h 2024-04-17 12:21:39 -03:00
vdso.c perf dsos: Tidy reference counting and locking 2024-04-12 12:04:13 -03:00
vdso.h
zlib.c
zstd.c