perf tools: Annotate fixes, stdio progress indication, debuginfo-client in more places
Arnaldo Carvalho de Melo
maintainerv7 cover perf tools: Annotate fixes, stdio progress indication, debuginfo-client in more places
Hi,
This came out of work on data type profiling, but none of it depends on that work and nothing in this series needs anything from it, so sending it separately.
The fixes:
- 'perf report -s type' spins forever on the dwz compressed debug info of zlib-ng (libz.so.1): die_collect_vars() saves a type DIE offset that is relative to the file the DIE lives in, the dwz alt file for types shared by several CUs, and resolving it in the main file parses whatever is at that offset, here a typedef whose DW_AT_type refers to itself, making the typedef/qualifier chase spin (patch 12), with the chases bounded so that other kinds of broken debug info don't hang perf either (patches 10, 11 and 13);
- the data type browser's samples view (-n) prints a local count that is initialized to zero and never updated, so every member has no samples (patch 7);
The features:
- 'perf report --progress' prints the current phase and how far along it is
to stderr (patch 8);
- the debuginfo of a DSO, and the kernel symbols, can be fetched keyed by the build ID recorded in perf.data using debuginfod (patch 1), with DEBUGINFOD_URLS set from /etc/debuginfod when needed (patch 2) and opt-outs that clear it for libdwfl's own client too;
- a slow fetch can be skipped ('s') or disabled for the session ('d'), with the progress shown on stderr or in a TUI window over the browser (patches 4 and 5; perf_config__set_variable() moves to util/config.c, patch 3);
- 'perf mem record' requests PERF_SAMPLE_CPU (patch 14) and uses the IBS swfilt filter when the kernel exposes it (patch 15).
Requires elfutils 0.160 for dwarf_cu_getdwarf(), so the libdw feature test probes for it and Makefile.config says 0.160: older versions now disable dwarf support with that message instead of failing to link.
What changed from v6 (d39be25e74340e7afa631ff40fa3810a205f04e7):
General: commit logs and code comments were made more concise throughout, following Namhyung Kim's review of the v6 posting [<[email protected]>]; no functional change.
PATCH 1/15, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod", was split [Namhyung Kim review of PATCH v6 2/12, <[email protected]>]: the fetch is patch 1, the DEBUGINFOD_URLS handling, now with the copy perf owns, is patch 2.
PATCH 12/15, "perf annotate-data: Resolve type DIEs in the debug file they came from", was split [Namhyung Kim review of PATCH v6 10/12, <[email protected]>]: the generic bound on the dwarf-aux type chases is patch 10, die_same_file()/die_get_type_die() and the elfutils 0.160 requirement are patch 11, the fix using them is patch 12, and the member nesting bound is the separate patch 13.
PATCH 3/15, "perf config: Move perf_config__set_variable() to util/config.c" [sashiko-bot review of the two v6 postings]:
- The system_config choice is derived from the file being rewritten, so
rewriting the system wide file doesn't truncate it;
- added the <limits.h> include for PATH_MAX;
- all config file access is serialized with a mutex.
PATCH 4/15, "perf debuginfo: Let the user skip and disable debuginfod fetches" [Namhyung Kim, <[email protected]>, and sashiko-bot]:
- The 's'/'d' keys are drained with read()s that return zero when nothing
was typed, so the fetch isn't held up waiting for a keypress;
- the disable empties the DEBUGINFOD_URLS copy perf owns, not a setenv() racing other threads' getenv()s.
PATCH 5/15, "perf debuginfo: Show the debuginfod fetch progress and keys in the TUI" [sashiko-bot]: the progress window clamps its width.
PATCH 6/15, "perf symbol: Fall back to fetching the vmlinux by build ID" [sashiko-bot]: mapping the x86-64 entry trampolines is idempotent.
PATCH 1/16, "perf test: Skip data_type_profiling when the PMU cannot record memory events", was merged upstream as 29f320d2 and is not part of this series anymore.
Patches 7, 8, 9, 14 and 15 have no content changes from v6, only the trimming.
What changed from v5 (ef0ac8e44d43d2aa86842d2f83ad41d1c058d949):
PATCH 2/9, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod", was split [Namhyung Kim review of PATCH v3 2/8, <[email protected]>]: the fetch stays in patch 2, the way to get out of a slow fetch, that was folded at the end of patch 2 in v5, is now patches 3 to 5, each separately cherry-pickable, and carrying on their own the answer to his "I'm not sure what would be the good default. But with this, it can slow down the process especially when the binary is not in the debuginfod": on by default, with the way to skip the one in progress and to disable the feature right where the wait is felt. Patch 3, "perf config: Move perf_config__set_variable() to util/config.c", is the prep patch, patch 4, "perf debuginfo: Let the user skip and disable debuginfod fetches", has the stdio 's'/'d' keys, and patch 5, "perf debuginfo:
Show the debuginfod fetch progress and keys in the TUI", the TUI window over the browser.
PATCH 4/12, "perf debuginfo: Let the user skip and disable debuginfod fetches" [that same review of the 'd' key semantics]:
- 'd' now writes core.debuginfod=false into the configuration file directly, the user's ~/.perfconfig or the one named by PERF_CONFIG, via perf_config__set_variable(), moved from builtin-config.c to util/config.c by the prep patch so that util/debuginfo.c can use it, and clears DEBUGINFOD_URLS so that libdwfl's own debuginfod client stops for the rest of the session too: in v5 it only disabled debuginfod for the rest of the session and pointed at 'perf config' to make that permanent.
PATCH 5/12, "perf debuginfo: Show the debuginfod fetch progress and keys in the TUI":
- The progress and the keys are no longer stdio-only: printing to stderr would garble the TUI browser display, so in v5 a fetch in progress in the TUI showed nothing and there was no way to skip or disable it, the thing that makes a slow fetch indistinguishable from a stuck perf. The TUI now draws a window over the browser with the fetch progress and drains the 's'/'d' keys from the TUI input queue: the TUI owns the terminal and its input queue, and the browser thread is the one doing the fetch, so nobody else is reading from it while the fetch blocks it. No terminal settings or signal dispositions are touched in that case, the terminal is the TUI's own and so are the SIGINT/SIGTERM handlers, that restore it before exiting.
- The slang calls stay in ui/tui/, behind the ui__key_pending()/ ui__key_read()/ui__progress_window()/ui__progress_window_end() primitives declared in ui/util.h and implemented in ui/tui/util.c, with inline stubs for builds without slang: the plan is to reduce the number of libraries perf needs to build, or swap slang for something else, such as ncurses, at some point, so nothing outside ui/ calls slang directly. The text in the window is word wrapped to the available columns, as constrained terminals, such as a smartphone running termux, crop the tail of a long line and would hide the 'd' option hint.
Patches 1, 3, 4, 5, 6, 7, 8 and 9 are unchanged from v5, renumbered as 1, 6, 7, 8, 9, 10, 11 and 12 with the split.
What changed from v4 (f801de4e80289566):
PATCH 1/8, "perf test: Skip data_type_profiling when the PMU cannot record memory events" [Namhyung Kim review of PATCH v3 1/8]:
- Namhyung suggested adding a fallback to the 'swfilt' term for ibs_op instead of only skipping the test on a PMU that refuses per-thread memory events. The new PATCH 9 does that for the ibs_op memory events, using the swfilt software privilege filter the kernel exposes as a format term since v6.14, which makes the per-thread 'perf mem record' the test does work on AMD; the skip stays for kernels without it. The term is in the event name even for records that end up without exclude bits, e.g. plain system wide ones: 'perf record' adds those bits itself when the first open fails with EACCES, after the name was built, and the retry only succeeds with the term already in the name:
$ perf record -v -e ibs_op/ldlat=0/ -- true
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples Failure to open event 'ibs_op/ldlat=0/u' on PMU 'ibs_op' which will be removed. Invalid event (ibs_op/ldlat=0/u) in per-thread mode, enable system wide with '-a'.
with no exclude bits the kernel discards nothing. The 'Test data symbol' shell test matches the event string, so its regex now accepts terms added after ldlat=150.
PATCH 2/8, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod" [sashiko-bot review of PATCH v4 2/8]:
- debuginfod__setup_urls_env() moved from util/debuginfo.c to util/util.c, next to perf_debuginfod_setup(), and its declaration from util/debuginfo.h to util/util.h: debuginfo.o is only built with CONFIG_LIBDW, so with libdebuginfod but without libdw the declaration was an empty stub and the setup was skipped exactly for build-id.c and probe-event.c, the debuginfod users that are built without libdw and that the commit message lists as reading DEBUGINFOD_URLS in every debuginfod_begin().
PATCH 8/8, "perf mem record: Request PERF_SAMPLE_CPU by default" [sashiko-bot review of PATCH v4 8/8]:
- The rec_argv array now reserves room for the fixed arguments __cmd_record() adds, up to eight with all the optional flags; a pre-existing under-allocation, the array was nine arguments per memory PMU plus the user arguments, and on a PMU with separate load and store events the four event arguments plus the fixed ones already filled it to the last slot, so this new --sample-cpu argument would write past it, e.g. with --phys-data --data-page-size --all-user.
Patches 1, 3, 4, 5, 6 and 7 are unchanged from v4: sashiko-bot found no issues in them.
What changed from v3 (2433e9f0bf86cfc3):
PATCH 2/8, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod" [sashiko-bot review of PATCH v3 2/8]:
- DEBUGINFOD_URLS is no longer set from the fetch path: setenv() is not thread safe and libdebuginfod reads it with getenv() in every debuginfod_begin(), which perf also does from build-id.c, probe-event.c and probe-finder.c, paths that don't go through the fetch lock, so a thread taking one of them could race with the setenv() a fetch was doing. This is now done from symbol__init(), before the threads are started, from the .urls files in /etc/debuginfod when it isn't set, and the pthread_once() and the call in debuginfod__fetch() are gone with it.
- The in-flight fetch wait was dead code and is gone: with debuginfod__fetch_lock held across the whole lookup and fetch, no second thread could ever see an entry being fetched, so the condition variable, the waiters and the publication dance could not run. debuginfo_lookup__new() became debuginfo_lookup__add(), called after a fetch that brought a file back: lookups remember only the successful fetches, one entry each, answered with a strdup() and re-fetched if that file goes away, and a request for a build ID being fetched waits for the lock and is answered from the misses list or from the entry, so a download still can't happen twice. debuginfod__missed_lock, always taken under the fetch lock, is gone with it.
PATCH 3/8, "perf symbol: Fall back to fetching the vmlinux by build ID" [sashiko-bot review of PATCH v3 3/8]:
- The check for a concurrent load, made after taking dso->lock back from the fetch, is now dso__has_symbols() and not dso__loaded():
dso__load() sets the latter even for an attempt that failed, so a thread whose fetch failed could make a thread whose fetch succeeded discard the vmlinux it just downloaded and carry on with an empty kernel dso, as loaded is set and nothing would try again.
PATCH 6/8, "perf scripts: Add perf-stuck, to tell where a running perf is stuck" [sashiko-bot review of PATCH v3 6/8]:
- The review asked whether the %s of a dwarf_diename() that returns NULL in perf-die-chain would abort the macro. Checked, not changed:
with GDB 17.2, printf prints "(null)" for a NULL char *, including for an inferior call returning one, and the macro carries on. The other %s in the file, dloc->ms->sym->name in perf-dso, can't be NULL
either: the only caller of find_data_type() dereferences ms->sym and ms->map to build the data_loc_info before that frame can exist, so no change there as well.
- Patches 1, 4, 5, 7 and 8 are unchanged from v3: sashiko-bot found no issues in them.
What changed from v2 (00cffc7df5abfa68):
PATCH 2/8, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod" [sashiko-bot review of PATCH v2 2/8]:
- The conditions to fetch, debuginfod being enabled, the build-id cache being on and the build ID not having been a miss already, are now looked at with the fetch lock held, as they are the state the fetch itself changes: deciding them outside the lock and fetching inside it let a second thread repeat the fetch the first one had just made, or repeat one that had just been turned off, and put the same build ID on the misses list twice.
- A build ID that is already being fetched is waited for, instead of fetched again: there was nothing that said "this one is in flight", so a second thread wanting it blocked on the fetch lock and then did its own complete fetch, which, while the first one is still running, is a second download of the same file, with a second client, a second progress line and a second turn at the terminal, for the same answer. It now sleeps on a condition variable and is woken with whatever the fetch settled: the file, when there is one, or the not available, when it found nothing or the user cancelled it, with no retry.
- And a fetch that brought a file back is remembered, so that the ones that need the same build ID later, e.g. annotating another symbol of the same DSO, are answered with a strdup() instead of another client:
the file stays in the debuginfod client cache, and its path is checked before being handed out, in case that cache gets cleaned from under us.
- The fetches are still one at a time, so a fetch for one build ID waits for a fetch for another one: the terminal mode, the signal dispositions, the progress line and the 's'/'d' keys are process global, and sharing them between concurrent fetches, refcounted, is left for later, noted in the code. It matters less than it sounds, now that the build IDs of a workload are answered from memory after the first pass over them.
PATCH 3/8, "perf symbol: Fall back to fetching the vmlinux by build ID" [sashiko-bot review of PATCH v2 3/8]:
- The fetch is no longer made with dso->lock held: dso__load() holds it across dso__load_kernel_sym(), and a fetch can block for a long time on the network, or on the terminal, waiting for the user, which would stall every other thread that needs the kernel dso. It is dropped just around the fetch, nothing of the dso is touched while it is, and the symbols are loaded with the lock held again, the same way dso__debuginfo() already does it for the debuginfo of a DSO. If another thread got the symbols for the dso in the meantime, the file that came back is not loaded a second time.
PATCH 5/8, "perf report: Add --progress option" [sashiko-bot review of PATCH v2 5/8]:
- A phase that starts when the progress stack is full is now just not shown, and its finish() is swallowed, instead of force completing the phase that encloses it to make room: that one still gets its own finish() later, which would then complete the phase above it, and so on, one premature completion per nesting level. Reproduced by building with STDIO_PROGRESS__MAX_DEPTH set to 1: v2 prints "Processing events... [100.0%]" while it is at 99.7%, before the nested phase even runs, v3 warns and keeps the outer phase to complete when it really does. With the 8 slots in the tree this cannot be hit, the phases perf has nest at most 2 deep, but the bookkeeping was wrong.
PATCH 6/8, "perf scripts: Add perf-stuck, to tell where a running perf is stuck" [sashiko-bot review of PATCH v2 6/8]:
- The perf-dso GDB macro read dloc->ms.map->dso->name and
dloc->ms.sym->name, but struct data_loc_info.ms is a
'struct map_symbol *', so GDB's C evaluator needs -> there: as it
was, 'perf-stuck.sh -g' would have failed to evaluate it. - The one pre-existing issue in PATCH 7/8, the unbounded member type chase in die_get_member_type() and the unbounded recursion in die_find_member(), is not addressed here, it went to the perf TODO list as item 180, as it is not on the path this series fixes.
Other changes since v2:
- PATCH 2/8: a refetch made because the cached file was cleaned from under us now updates the entry the same way the first fetch does, and an entry with no path and no error is fetched again instead of answered; as it was, the entry kept the first fetch's success with no path, so the later lookups it existed for returned success with a NULL path, which debuginfo__new_build_id() cannot open and the vmlinux fallback in PATCH 3 would take as a file that came back and dereference.
- PATCH 3/8: the commit message said the ignore_vmlinux_buildid that 'perf record' and 'perf probe' set internally is what keeps them away from the fallback, but 'perf probe' only sets it for the commands other than --list, --del and --add when given an offline vmlinux; the message now says that and that a 'perf probe' that does not set it, e.g. --funcs or --add without --vmlinux on a system with a restricted /proc/kallsyms, can have the kernel debuginfo fetched, like the other tools.
- PATCH 7/8: the kerneldoc of die_get_type_die() said the type would be looked up in the main file and then in the alt file, using the one that has a DIE with the saved tag, but the function deliberately resolves in only the file the offset was recorded as belonging to, with no fallback, and @from_alt was missing from the parameter list; it now describes that, and the die_collect_vars() and die_collect_global_vars() kerneldocs, which still said the type could be retrieved with dwarf_offdie() and the offset alone, now point at die_get_type_die().
- PATCH 7/8: the comment on the member->truncated flag said the browser reads it, but the browser picks between ';' and '{' from the children list, so a member cut by the nesting limit is drawn like a complete leaf; the comment now says the flag is for the JSON exporter added in a later series.
- PATCH 2/8: a search aborted by the user, with 's' or a signal, is now remembered for the rest of the session: the threads already waiting for that fetch were told there was nothing to share, but a request that arrived later started a new download of the same file, which the user may have skipped for being too big. debuginfod__misses now records such a cancellation as a cancellation, the 's' message says the build ID will not be fetched again in this session and the debug message tells a cancellation and a server miss apart. The lookup entry is also now allocated and published by a debuginfo_lookup__new() helper called before the fetch, instead of an allocation whose failure was only checked after it.
- Patches 1, 4 and 8 are unchanged from v2: sashiko-bot found no issues in them.
What changed from v1 (060dccedab1617dc):
PATCH 2/8, "perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod" [sashiko-bot review of PATCH 2/8]:
- Included <limits.h> for PATH_MAX, that was coming in through a glibc transitive include and fails to build with musl libc.
- debuginfod__setup_urls_env() now goes through pthread_once, so that the setenv() of DEBUGINFOD_URLS happens exactly once: setenv() is not thread safe and this is on the fetch path, which dso__debuginfo() deliberately takes outside dso__lock.
- The fetch now runs with debuginfod__fetch_lock held, so that the process global state it uses — the terminal settings, the SIGINT/ SIGTERM dispositions and the progress and cancellation state — is only ever touched by one fetch at a time. A second concurrent fetch would otherwise have taken the first one's raw mode as the state to restore, leaving the terminal broken when it was done, and would reset the cancellation state from under the fetch already in progress. Serializing also keeps two fetches from racing for the same keypresses and the same progress line, and a second fetch has nothing to gain from running in parallel with a first one reading the same kind of file off the same servers.
- An interrupt that lands after the fetch already succeeded is no longer swallowed: at that point the terminal and the signal dispositions are the original ones again, so the signal is re-raised, the same way the failure path does, instead of perf carrying on as if the user had not asked it to stop.
PATCH 6/8, "perf scripts: Add perf-stuck, to tell where a running perf is stuck" [sashiko-bot review of PATCH 6/8]:
- /proc/<pid>/stat is now parsed with the parenthesized command name removed first, so that a process with spaces in its name no longer shifts every field after it: watching a process named 'my sleep' used to report "sleep)" as its state and a garbage RSS.
- The CPU time is printed with awk's printf "%d" instead of relying on its default output format, that switches to scientific notation, which the bash arithmetic below cannot parse, once the sum of utime and stime goes past six digits, i.e. some 16 minutes of CPU at 100 Hz.
- The process can go away between the '-d /proc/<pid>' check and the read of /proc/<pid>/stat, so the read is now checked: a failed or empty one reports "process gone" instead of 'set -u' aborting the script on an unbound field, which is what would have hidden the very exit the script is meant to report.
- The command line printed when the script starts has its control characters stripped, so that a process started with escape sequences in its arguments, e.g. one replaying a log line, does not get them replayed on the terminal of whoever runs this.
- The two pre-existing issues sashiko-bot raised that are outside the scope of this series, the child entries and their hists arrays leaked by the data type browser teardown and the missing <stdio.h> and <stdlib.h> includes in ui/browsers/annotate-data.c, are recorded as items 178 and 179 of the perf TODO list for follow-up work.
- Patches 1, 3, 4, 5, 7 and 8 are unchanged from v1: sashiko-bot found no issues in them.
Arnaldo Carvalho de Melo (15):
perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod perf debuginfo: Set DEBUGINFOD_URLS from /etc/debuginfod when unset perf config: Move perf_config__set_variable() to util/config.c perf debuginfo: Let the user skip and disable debuginfod fetches perf debuginfo: Show the debuginfod fetch progress and keys in the TUI perf symbol: Fall back to fetching the vmlinux by build ID perf annotate-data: Show the sample count in the data-type browser perf report: Add --progress option
perf scripts: Add perf-stuck, to tell where a running perf is stuck perf dwarf-aux: Bound the type chases for broken debug info perf dwarf-aux: Add die_same_file() and die_get_type_die() perf annotate-data: Resolve type DIEs in the debug file they came from perf annotate-data: Bound the member nesting recursion perf mem record: Request PERF_SAMPLE_CPU by default
perf mem record: Use the IBS swfilt filter when available
tools/build/feature/test-libdw.c | 13 +- tools/perf/Documentation/perf-annotate.txt | 10 + tools/perf/Documentation/perf-config.txt | 19 + tools/perf/Documentation/perf-mem.txt | 4 + tools/perf/Documentation/perf-report.txt | 31 ++ tools/perf/Documentation/perf-top.txt | 16 + tools/perf/Makefile.config | 2 +- tools/perf/arch/x86/util/mem-events.c | 14 +- tools/perf/builtin-annotate.c | 3 + tools/perf/builtin-config.c | 70 +-- tools/perf/builtin-mem.c | 11 +- tools/perf/builtin-report.c | 17 + tools/perf/builtin-top.c | 7 + tools/perf/scripts/perf-stuck.gdb | 104 +++++ tools/perf/scripts/perf-stuck.sh | 194 +++++++++ tools/perf/tests/shell/test_data_symbol.sh | 6 +- tools/perf/ui/Build | 1 + tools/perf/ui/browsers/annotate-data.c | 2 +- tools/perf/ui/progress.h | 2 + tools/perf/ui/stdio/progress.c | 163 +++++++ tools/perf/ui/tui/util.c | 171 ++++++++ tools/perf/ui/util.h | 27 ++ tools/perf/util/annotate-data.c | 53 ++- tools/perf/util/annotate-data.h | 3 + tools/perf/util/config.c | 99 ++++- tools/perf/util/config.h | 2 + tools/perf/util/debuginfo.c | 481 +++++++++++++++++++++ tools/perf/util/debuginfo.h | 35 ++ tools/perf/util/dso.c | 10 + tools/perf/util/dwarf-aux.c | 150 ++++++- tools/perf/util/dwarf-aux.h | 17 + tools/perf/util/machine.c | 11 +- tools/perf/util/mem-events.c | 18 +- tools/perf/util/mem-events.h | 2 + tools/perf/util/ordered-events.c | 16 +- tools/perf/util/session.c | 12 +- tools/perf/util/symbol.c | 64 ++- tools/perf/util/symbol_conf.h | 1 + tools/perf/util/util.c | 151 ++++++- tools/perf/util/util.h | 9 + 40 files changed, 1887 insertions(+), 134 deletions(-) create mode 100644 tools/perf/scripts/perf-stuck.gdb create mode 100755 tools/perf/scripts/perf-stuck.sh create mode 100644 tools/perf/ui/stdio/progress.c
base-commit: 29f320d221c1c4c082c7eafb2251fedf8a4868ec
v6-head: d39be25e74340e7afa631ff40fa3810a205f04e7
v5-head: ef0ac8e44d43d2aa86842d2f83ad41d1c058d949
v4-head: f801de4e80289566670e6b735198606b672e74e8
v3-head: 2433e9f0bf86cfc3d9966b467042563596c9ebdb
v2-head: 00cffc7df5abfa6850beb360deb830d8495163ce
v1-head: 060dccedab1617dcbf6e2be64ed97afe3f3fac63 --
Arnaldo Carvalho de Melo
maintainerPATCH v7 1/15 perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod
From: Arnaldo Carvalho de Melo <[email protected]>
Add debuginfo__find_build_id(), which uses the debuginfod client to locate a debuginfo file keyed by the build ID - checking its local cache first and then the servers in DEBUGINFOD_URLS - and debuginfo__new_build_id(), which opens the DWARF in the file it finds. dso__debuginfo() falls back to it for DSOs whose debuginfo is not installed locally, e.g. the vmlinux of a kernel profiled on another machine or upgraded since, doing the fetch outside dso__lock.
Querying servers, possibly third party ones, sends the build IDs of the binaries being analysed off-box, and a fetch can take a while, so this is opt-out: --no-debuginfod, core.debuginfod=false, report.debuginfod/top.debuginfod, and off also when the build-id cache is disabled. Fetches are serialized and misses are remembered, as both the lookup state and the fetch interaction are process global.
--- tools/perf/Documentation/perf-annotate.txt | 8 + tools/perf/Documentation/perf-config.txt | 19 ++ tools/perf/Documentation/perf-report.txt | 12 + tools/perf/Documentation/perf-top.txt | 11 + tools/perf/builtin-annotate.c | 3 + tools/perf/builtin-report.c | 7 + tools/perf/builtin-top.c | 7 + tools/perf/util/config.c | 3 + tools/perf/util/debuginfo.c | 327 +++++++++++++++++++++ tools/perf/util/debuginfo.h | 35 +++ tools/perf/util/dso.c | 10 + tools/perf/util/symbol.c | 2 + tools/perf/util/symbol_conf.h | 1 + 13 files changed, 445 insertions(+)
tools/perf/Documentation/perf-annotate.txt +8 -0
@@ -58,6 +58,14 @@ OPTIONS --ignore-vmlinux:: Ignore vmlinux files. +--debuginfod:: +--no-debuginfod:: + Fetch debuginfo keyed by build ID from the debuginfod servers + configured in DEBUGINFOD_URLS, checking the local debuginfod + client cache first, when it is not available locally, on for + these commands by default. See the --debuginfod option of + 'perf report' for how to turn it off. + --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/Documentation/perf-config.txt +19 -0
@@ -216,6 +216,14 @@ core.*:: addr2line-timeout:: Sets a timeout (in milliseconds) for parsing 'addr2line' output. The default timeout is 5s. + debuginfod:: + When set to 'false', disable fetching debuginfo keyed by + build ID from the debuginfod servers configured in + DEBUGINFOD_URLS. It is on by default, can be overridden per + tool with the 'report.debuginfod' and 'top.debuginfod' + options and per invocation with --no-debuginfod; it is off + too when the local build-id cache is disabled, e.g. + 'buildid.dir' set to /dev/null. tui.*, gtk.*:: Subcommands that can be configured here are 'top', 'report' and 'annotate'.
@@ -562,6 +570,14 @@ report.*:: This option can change default stat behavior with empty results. If it's set true, 'perf report --stat' will not show 0 stats. + report.debuginfod:: + Fetch debuginfo keyed by build ID from the debuginfod + servers configured in DEBUGINFOD_URLS, checking the local + debuginfod client cache first, when it is not available + locally. On by default, set to 'false' to disable it for + 'perf report', globally with 'core.debuginfod=false' or per + invocation with --no-debuginfod. + top.*:: top.children:: Same as 'report.children'. So if it is enabled, the output of 'top'
@@ -569,6 +585,9 @@ top.*:: column by default. The default is 'true'. + top.debuginfod:: + Same as 'report.debuginfod', for 'perf top'. + top.call-graph:: This is identical to 'call-graph.record-mode', except it is applicable only for 'top' subcommand. This option ONLY setup
tools/perf/Documentation/perf-report.txt +12 -0
@@ -366,6 +366,18 @@ OPTIONS --ignore-vmlinux:: Ignore vmlinux files. +--debuginfod:: +--no-debuginfod:: + Fetch debuginfo keyed by build ID from the debuginfod servers + configured in DEBUGINFOD_URLS, checking the local debuginfod + client cache first, when it is not available locally, on for + these commands by default. It can be turned off per invocation + with --no-debuginfod, per tool with the "report.debuginfod" + config option or globally with "core.debuginfod" set to false. + It is disabled as well when the local build-id cache is turned + off, e.g. "buildid.dir" set to /dev/null, as that asks for + fetched files not to be kept on the box. + --kallsyms=<file>:: kallsyms pathname
tools/perf/Documentation/perf-top.txt +11 -0
@@ -83,6 +83,17 @@ Default is to monitor all CPUS. --ignore-vmlinux:: Ignore vmlinux files. +--debuginfod:: +--no-debuginfod:: + Fetch debuginfo keyed by build ID from the debuginfod servers + configured in DEBUGINFOD_URLS, checking the local debuginfod + client cache first, when it is not available locally, on for + these commands by default. Turn it off per invocation with + --no-debuginfod, with the "top.debuginfod" config option or + globally with "core.debuginfod" set to false. Disabled as well + when the build-id cache is off, e.g. "buildid.dir" set to + /dev/null. + --kallsyms=<file>:: kallsyms pathname
tools/perf/builtin-annotate.c +3 -0
@@ -733,6 +733,9 @@ int cmd_annotate(int argc, const char **argv)OPT_BOOLEAN (0 ,"stdio2" , &annotate.use_stdio2,"Use the stdio interface" ),OPT_BOOLEAN (0 ,"ignore-vmlinux" , &symbol_conf.ignore_vmlinux,"don't load vmlinux even if found" ), +OPT_BOOLEAN (0 ,"debuginfod" , &symbol_conf.debuginfod, +"fetch debuginfo keyed by build ID from the debuginfod " +"servers, on by default, use --no-debuginfod to turn off" ),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
tools/perf/builtin-report.c +7 -0
@@ -134,6 +134,10 @@ static int report__config(const char *var, const char *value, void *cb) symbol_conf.event_group =perf_config_bool (var, value);return 0 ; } +if (!strcmp (var,"report.debuginfod" )) { + symbol_conf.debuginfod =perf_config_bool (var, value); +return 0 ; + }if (!strcmp (var,"report.percent-limit" )) {double pcnt =strtof (value,NULL );
@@ -1346,6 +1350,9 @@ int cmd_report(int argc, const char **argv) "file", "vmlinux pathname"),OPT_BOOLEAN (0 ,"ignore-vmlinux" , &symbol_conf.ignore_vmlinux,"don't load vmlinux even if found" ), +OPT_BOOLEAN (0 ,"debuginfod" , &symbol_conf.debuginfod, +"fetch debuginfo keyed by build ID from the debuginfod " +"servers, on by default, use --no-debuginfod to turn off" ),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
tools/perf/builtin-top.c +7 -0
@@ -1436,6 +1436,10 @@ static int perf_top_config(const char *var, const char *value, void *cb __maybe_ symbol_conf.cumulate_callchain =perf_config_bool (var, value);return 0 ; } +if (!strcmp (var,"top.debuginfod" )) { + symbol_conf.debuginfod =perf_config_bool (var, value); +return 0 ; + }return 0 ; }
@@ -1508,6 +1512,9 @@ int cmd_top(int argc, const char **argv) "file", "vmlinux pathname"),OPT_BOOLEAN (0 ,"ignore-vmlinux" , &symbol_conf.ignore_vmlinux,"don't load vmlinux even if found" ), +OPT_BOOLEAN (0 ,"debuginfod" , &symbol_conf.debuginfod, +"fetch debuginfo keyed by build ID from the debuginfod " +"servers, on by default, use --no-debuginfod to turn off" ),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols,
tools/perf/util/config.c +3 -0
@@ -470,6 +470,9 @@ static int perf_default_core_config(const char *var, const char *value)if (!strcmp (var,"core.addr2line-disable-warn" )) symbol_conf.addr2line_disable_warn =perf_config_bool (var, value); +if (!strcmp (var,"core.debuginfod" )) + symbol_conf.debuginfod =perf_config_bool (var, value); +/* Add other config variables here. */ return 0 ; }
tools/perf/util/debuginfo.c +327 -0
349 lines not on this page · raw message
tools/perf/util/debuginfo.h +35 -0
@@ -5,6 +5,8 @@#include <errno.h> #include <linux/compiler.h> +struct build_id ; +#ifdef HAVE_LIBDW_SUPPORT #include "dwarf-aux.h"
@@ -54,6 +56,27 @@ static inline int debuginfo__get_text_offset(struct debuginfo *dbg __maybe_unuse#ifdef HAVE_DEBUGINFOD_SUPPORT int get_source_from_debuginfod (const char *raw_path,const char *sbuild_id,char **new_path); + +/* +* These need libdw to open the DWARF, so they live in debuginfo.o, +* built only with CONFIG_LIBDW. +*/ +#ifdef HAVE_LIBDW_SUPPORT +int debuginfo__find_build_id (const struct build_id *bid,char **path); +struct debuginfo *debuginfo__new_build_id (const struct build_id *bid); +#else +static inline int debuginfo__find_build_id (const struct build_id *bid__maybe_unused , +char **path__maybe_unused ) +{ +return -ENOTSUP ; +} + +static inline struct debuginfo * +debuginfo__new_build_id (const struct build_id *bid__maybe_unused ) +{ +return NULL ; +} +#endif /* HAVE_LIBDW_SUPPORT */ #else /* HAVE_DEBUGINFOD_SUPPORT */ static inline int get_source_from_debuginfod(const char *raw_path __maybe_unused, const char *sbuild_id __maybe_unused,
@@ -61,6 +84,18 @@ static inline int get_source_from_debuginfod(const char *raw_path __maybe_unused {return -ENOTSUP ; } + +static inline int debuginfo__find_build_id (const struct build_id *bid__maybe_unused , +char **path__maybe_unused ) +{ +return -ENOTSUP ; +} + +static inline struct debuginfo * +debuginfo__new_build_id (const struct build_id *bid__maybe_unused ) +{ +return NULL ; +}#endif /* HAVE_DEBUGINFOD_SUPPORT */ #endif /* _PERF_DEBUGINFO_H */
tools/perf/util/dso.c +10 -0
@@ -32,6 +32,7 @@#include "string2.h" #include "vdso.h" #include "annotate-data.h" +#include "debuginfo.h" #include "libdw.h" static const char *const debuglink_paths[] = {
@@ -2073,5 +2074,14 @@ struct debuginfo *dso__debuginfo(struct dso *dso)mutex_unlock (dso__lock (dso));free (name); + +/* +* The debuginfo for a DSO in the profile may not be installed locally, +* fall back to fetching it keyed by the build ID recorded in perf.data. +* Do it outside dso__lock, a fetch can take a while. +*/ +if (dinfo ==NULL ) + dinfo =debuginfo__new_build_id (dso__bid (dso)); +return dinfo; }
tools/perf/util/symbol.c +2 -0
@@ -76,6 +76,8 @@ struct symbol_conf symbol_conf = { .inline_name = true, .res_sample = 0, .addr2line_timeout_ms = 5 * 1000, + /* Fetching debuginfo by build ID, off via --no-debuginfod, etc */ + .debuginfod = true, };struct map_list_node {
tools/perf/util/symbol_conf.h +1 -0
@@ -45,6 +45,7 @@ struct symbol_conf { force, ignore_vmlinux, ignore_vmlinux_buildid, + debuginfod, show_kernel_path, use_modules, allow_aliases,
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 01/15] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Add
debuginfo__find_build_id(), which uses the debuginfod client to locate a debuginfo file keyed by the build ID - checking its local cache first and then the servers inDEBUGINFOD_URLS- anddebuginfo__new_build_id(), which opens the DWARF in the file it finds.dso__debuginfo()falls back to it for DSOs whose debuginfo is not installed locally, e.g. the vmlinux of a kernel profiled on another machine or upgraded since, doing the fetch outsidedso__lock.Querying servers, possibly third party ones, sends the build IDs of the binaries being analysed off-box, and a fetch can take a while, so this is opt-out: --no-debuginfod, core.debuginfod=false, report.debuginfod/top.debuginfod, and off also when the build-id cache is disabled. Fetches are serialized and misses are remembered, as both the lookup state and the fetch interaction are process global.
Quoted 2 lines
Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerRe: [PATCH 01/15] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod
In reply to Arnaldo Carvalho de MeloOn Thu, Sep 17, 2026 at 8:55 AM Arnaldo Carvalho de Melo <[email protected]> wrote:
[snip]
Quoted 11 lines
tools/perf/util/debuginfo.c +11
-0+/* +* The build IDs already fetched in this session, and the path of the file +* that came back for each, so that the repeated requests for the same build +* ID, dso__debuginfo() is called per symbol annotated, are answered with a +* strdup() instead of another client: the file is in the debuginfod client +* cache already and its path checked before being handed out, in case that +* cache is cleaned from under us. +* +* Guarded by debuginfod__fetch_lock. Only a fetch that brought a file back +* gets an entry: one that didn't is recorded in debuginfod__misses as a miss, +* and that is what keeps the rest of the session from asking for it again.
tools/perf/util/debuginfo.c struct debuginfo *debuginfo__new(const char *path) · line 270
Quoted 10 lines
tools/perf/util/debuginfo.c +10
-0+* Like debuginfod__misses this grows with the number of build IDs in the +* workload, one small entry each, and is not trimmed. +*/ +struct debuginfo_lookup { +struct list_head node; +struct build_id bid; +char *path; +}; + +static LIST_HEAD (debuginfo_lookups);
I'd still prefer keeping the debuginfos owned by the DSOs rather than having debuginfo use a global cache of debuginfos - I expect the debuginfos to have some non-trivial memory overhead. With the debuginfo in the DSO, when/if the DSO goes away we can reclaim all the memory without worrying about a separate global data structure. We can find DSOs in multiple ways with dsos__findnew_id:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dsos.c#n343
We match by name, but if those differ:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dsos.c#n117
We match by inode and/or build ID:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dso.c#n1473
So struct dsos is a build ID indexed store of DSOs and their owned debuginfo. We find DSOs off a machine, but I believe we always have access to the relevant struct machine. In the worst case for probes, for example, we need to set up a host machine. Using machines inherently provides some lock sharding, and they also have the ability to reclaim memory.
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 01/15] perf debuginfo: Fetch debuginfo keyed by build ID using debuginfod
Quoted 39 lines · Ian Rogers
On Thu, Sep 17, 2026 at 8:55 AM Arnaldo Carvalho de Melo <[email protected]> wrote:
[snip]
Quoted 11 lines
tools/perf/util/debuginfo.c +11
-0+/* +* The build IDs already fetched in this session, and the path of the file +* that came back for each, so that the repeated requests for the same build +* ID, dso__debuginfo() is called per symbol annotated, are answered with a +* strdup() instead of another client: the file is in the debuginfod client +* cache already and its path checked before being handed out, in case that +* cache is cleaned from under us. +* +* Guarded by debuginfod__fetch_lock. Only a fetch that brought a file back +* gets an entry: one that didn't is recorded in debuginfod__misses as a miss, +* and that is what keeps the rest of the session from asking for it again. tools/perf/util/debuginfo.c struct debuginfo *debuginfo__new(const char *path) · line 270
Quoted 10 lines
tools/perf/util/debuginfo.c +10
-0+* Like debuginfod__misses this grows with the number of build IDs in the +* workload, one small entry each, and is not trimmed. +*/ +struct debuginfo_lookup { +struct list_head node; +struct build_id bid; +char *path; +}; + +static LIST_HEAD (debuginfo_lookups);I'd still prefer keeping the debuginfos owned by the DSOs rather than having debuginfo use a global cache of debuginfos - I expect the debuginfos to have some non-trivial memory overhead. With the debuginfo in the DSO, when/if the DSO goes away we can reclaim all the memory without worrying about a separate global data structure. We can find DSOs in multiple ways with
dsos__findnew_id:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dsos.c#n343
We match by name, but if those differ:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dsos.c#n117
We match by inode and/or build ID:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/dso.c#n1473
Quoted 6 lines
So struct dsos is a build ID indexed store of DSOs and their owned debuginfo. We find DSOs off a machine, but I believe we always have access to the relevant struct machine. In the worst case for probes, for example, we need to set up a host machine. Using machines inherently provides some lock sharding, and they also have the ability to reclaim memory.
Working on it, no preference, so doing it the way you describe seems ok, will post later.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerPATCH v7 2/15 perf debuginfo: Set DEBUGINFOD_URLS from /etc/debuginfod when unset
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The debuginfod client fails when DEBUGINFOD_URLS isn't set even when what it wants is in its local cache, and the distro setup scripts that populate it from the files in /etc/debuginfod don't reach cron jobs, systemd services and CI, so set it from those .urls files from symbol__init(), before any thread that can call getenv() is started:setenv() is not thread safe and libdebuginfod reads the variable in every debuginfod_begin().
Install it via putenv() as a string perf owns, so that it can be emptied in place mid-session when the user disables debuginfod, and when debuginfod is off, with --no-debuginfod, core.debuginfod=false or by disabling the build-id cache, set the empty string, that both libdebuginfod and libdwfl's own client read as an opt-out, instead of exporting the variable for libdwfl to fetch behind perf's back. Tools that manage DEBUGINFOD_URLS themselves are left alone.
--- tools/perf/util/symbol.c | 7 ++ tools/perf/util/util.c | 151 +++++++++++++++++++++++++++++++++++++-- tools/perf/util/util.h | 9 +++ 3 files changed, 161 insertions(+), 6 deletions(-)
tools/perf/util/symbol.c +7 -0
@@ -2536,6 +2536,13 @@ int symbol__init(struct perf_env *env)if (symbol_conf.initialized)return 0 ; +/* +* Set DEBUGINFOD_URLS from the distro .urls files before any thread +* that getenv()s it is started: setenv() is not thread safe and +* libdebuginfod reads it in every debuginfod_begin(). +*/ +debuginfod__setup_urls_env (); + symbol_conf.priv_size =PERF_ALIGN (symbol_conf.priv_size,sizeof (u64));symbol__elf_init ();
tools/perf/util/util.c +145 -6
179 lines not on this page · raw message
tools/perf/util/util.h +9 -0
@@ -81,6 +81,15 @@ struct perf_debuginfod {bool set; };void perf_debuginfod_setup (struct perf_debuginfod *di); +void debuginfod__disable_urls_env (void ); + +#ifdef HAVE_DEBUGINFOD_SUPPORT +void debuginfod__setup_urls_env (void ); +#else +static inline void debuginfod__setup_urls_env (void ) +{ +} +#endif const char *perf_basename (const char *path);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 02/15] perf debuginfo: Set DEBUGINFOD_URLS from /etc/debuginfod when unset
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf debuginfo: bypass of /etc/debuginfod fallback for record/buildid-cache --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf debuginfo: bypass of /etc/debuginfod fallback for record/buildid-cache --
commit abf1731695e2130d2a1cbc46b0ed7ae8527966ac
Author: Arnaldo Carvalho de Melo <[email protected]>
perf debuginfo: Set DEBUGINFOD_URLS from /etc/debuginfod when unset
This commit allows perf to read DEBUGINFOD_URLS from the .urls files in /etc/debuginfod during early setup if the environment variable is not already configured. This aims to resolve debuginfod failures in environments like cron jobs, systemd services, or CI pipelines where distro setup scripts might not populate the environment.
tools/perf/util/util.c +0 -0
[ ... ]
Quoted 2 lines
void
perf_debuginfod_setup(struct perf_debuginfod *di){
[ ... ]
Quoted 7 lines
(quoted diff) +3
-4- if (!di->set) - setenv("DEBUGINFOD_URLS", "", 1); - else if (di->urls && strcmp(di->urls, "system")) - setenv("DEBUGINFOD_URLS", di->urls, 1); + if (!di->set) { + debuginfod__set_urls_env(""); + } else if (di->urls == NULL || !strcmp(di->urls, "system")) {
Review
Quoted 10 lines
(quoted diff) +8
-1+ const char *urls = getenv(DEBUGINFOD_URLS_ENV); + + if (urls != NULL) + debuginfod__set_urls_env(urls); + } else { + debuginfod__set_urls_env(di->urls); + } - pr_debug("DEBUGINFOD_URLS=%s\n", getenv("DEBUGINFOD_URLS")); + debuginfod__urls_set_by_tool = true;
[Severity: Medium]
When perf tools request debuginfod support with the default "system" URLs, and the environment variable is unset (urls == NULL), does unconditionally setting debuginfod__urls_set_by_tool to true here unintentionally lock out the fallback mechanism?
[ ... ]
Quoted 3 lines
(quoted diff) +3
-0+#ifdef HAVE_DEBUGINFOD_SUPPORT +/* + * The debuginfod client checks its local cache only as part of the
[ ... ]
Review
Quoted 13 lines
(quoted diff) +13
-0+void debuginfod__setup_urls_env(void) +{ + const char *env_urls; + char *urls = NULL; + DIR *dir; + struct dirent *dent; + + /* + * Tools that set DEBUGINFOD_URLS themselves already made their choice, + * leave it alone. + */ + if (debuginfod__urls_set_by_tool) + return;
[Severity: Medium]
Because debuginfod__urls_set_by_tool is flagged to true earlier in perf_debuginfod_setup(), will tools like perf record and perf buildid-cache that run with --debuginfod exit early here?
It looks like this sequence causes these tools to entirely bypass the new /etc/debuginfod fallback logic when DEBUGINFOD_URLS is unset, which seems to defeat the purpose of the patch for these subcommands.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Arnaldo Carvalho de Melo
maintainerPATCH v7 3/15 perf config: Move perf_config__set_variable() to util/config.c
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Move perf_config__set_variable() out of the 'perf config' builtin so that util/debuginfo.c can use it to write core.debuginfod=false when the user disables debuginfod for the rest of the session. The set_config() body becomes perf_config_set__write(), with the system_config choice as an argument, as the builtin's use_system_config/use_user_config statics are not available outside it, and it has to honour PERF_CONFIG and keep the entries marked as coming from the system config when rewriting the system wide file.
All config file access shares the static parser state and can now run on more than one thread, with the debuginfod fetch writing the config while perf top's display thread reads it, so serialize parsing and rewriting with a mutex.
--- tools/perf/builtin-config.c | 70 +-------------------------- tools/perf/util/config.c | 96 ++++++++++++++++++++++++++++++++++++- tools/perf/util/config.h | 2 + 3 files changed, 98 insertions(+), 70 deletions(-)
tools/perf/builtin-config.c +1 -69
@@ -41,37 +41,7 @@ static struct option config_options[] = {static int set_config (struct perf_config_set *set,const char *file_name) { -struct perf_config_section *section =NULL ; -struct perf_config_item *item =NULL ; -const char *first_line ="# this file is auto-generated." ; -FILE *fp; - -if (set ==NULL ) -return -1 ; - - fp =fopen (file_name,"w" ); -if (!fp) -return -1 ; - -fprintf (fp,"%s\n" , first_line); - -/* overwrite configvariables */ -perf_config_items__for_each_entry (&set->sections, section) { -if (!use_system_config && section->from_system_config) -continue ; -fprintf (fp,"[%s]\n" , section->name); - -perf_config_items__for_each_entry (§ion->items, item) { -if (!use_system_config && item->from_system_config) -continue ; -if (item->value) -fprintf (fp,"\t%s = %s\n" , - item->name, item->value); - } - } -fclose (fp); - -return 0 ; +return perf_config_set__write (set, file_name, use_system_config); }static int show_spec_config (struct perf_config_set *set,const char *var)
@@ -158,44 +128,6 @@ static int parse_config_arg(char *arg, char **var, char **value)return 0 ; } -int perf_config__set_variable (const char *var,const char *value) -{ -char path[PATH_MAX ]; -char *user_config =mkpath (path,sizeof (path),"%s/.perfconfig" ,getenv ("HOME" )); -const char *config_filename; -struct perf_config_set *set; -int ret =-1 ; - -if (use_system_config) - config_exclusive_filename =perf_etc_perfconfig (); -else if (use_user_config) - config_exclusive_filename = user_config; - -if (!config_exclusive_filename) - config_filename = user_config; -else - config_filename = config_exclusive_filename; - - set =perf_config_set__new (); -if (!set) - goto out_err; - -if (perf_config_set__collect (set, config_filename, var, value) <0 ) { -pr_err ("Failed to add '%s=%s'\n" , var, value); - goto out_err; - } - -if (set_config (set, config_filename) <0 ) { -pr_err ("Failed to set the configs on %s\n" , config_filename); - goto out_err; - } - - ret =0 ; -out_err: -perf_config_set__delete (set); -return ret; -} -int cmd_config (int argc,const char **argv) {int i, ret =-1 ;
tools/perf/util/config.c +95 -1
132 lines not on this page · raw message
tools/perf/util/config.h +2 -0
@@ -33,6 +33,8 @@ int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3);const char *perf_config_get (const char *name);int perf_config_set (struct perf_config_set *set,config_fn_t fn,void *data); +int perf_config_set__write (struct perf_config_set *set, +const char *file_name,bool system_config);int perf_config_int (int *dest,const char *,const char *);int perf_config_u8 (u8 *dest,const char *name,const char *value);int perf_config_u64 (u64 *dest,const char *,const char *);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 03/15] perf config: Move perf_config__set_variable() to util/config.c
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] perf config: data loss due to non-atomic read-modify-write in set_variable - [Medium] perf…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf config: data loss due to non-atomic read-modify-write in set_variable
- [Medium] perf config: memory leak due to lockless perf_etc_perfconfig() initialization --
commit 836076e44736c46148a07294c62bef2cd50992f3
Author: Arnaldo Carvalho de Melo <[email protected]>
perf config: Move perf_config__set_variable() to util/config.c
This commit moves perf_config__set_variable() to util/config.c so that other utilities can access it. It also serializes config parsing and rewriting with a mutex to support multithreaded access.
Quoted 3 lines
tools/perf/util/config.c +0
-0
[ ... ]
tools/perf/util/config.c static int collect_config(const char *var, const char *value, · line 794
Quoted 8 lines
tools/perf/util/config.c +3
-0@@ -776,8 +788,13 @@ static int collect_config(const char *var, const char *value,int perf_config_set__collect (struct perf_config_set *set,const char *file_name,const char *var,const char *value) { +int ret; + +pthread_mutex_lock (&config_mutex); config_file_name = file_name;
[Severity: Medium]
This is a pre-existing issue, but does assigning file_name to the static global config_file_name create a stack use-after-free risk?
In perf_config__set_variable(), the stack array path is used as the filename and passed into this function:
perf_config__set_variable() {
char path[PATH_MAX];
...
const char *config_filename = ... ?: mkpath(path, ...);
perf_config_set__collect(..., config_filename, ...);
}If the static pointer config_file_name isn't cleared after collecting, could a subsequent config parsing failure in bad_config() dereference this dangling stack pointer and cause a crash or output garbage?
Quoted 5 lines
tools/perf/util/config.c +3
-1-return collect_config (var, value, set); + ret =collect_config (var, value, set); +pthread_mutex_unlock (&config_mutex); +return ret; }
[ ... ]
Quoted 1 line
tools/perf/util/config.c +0
-0@@ -876,6 +893,83 @@ void perf_config__exit(void)
[ ... ]
tools/perf/util/config.c void perf_config__exit(void) · line 949
Quoted 11 lines
tools/perf/util/config.c +11
-0+int perf_config__set_variable (const char *var,const char *value) +{ +char path[PATH_MAX ]; +char *user_config =mkpath (path,sizeof (path),"%s/.perfconfig" ,getenv ("HOME" )); +const char *config_filename = config_exclusive_filename ?: user_config; +/* +* When rewriting the system wide file (e.g. with +* PERF_CONFIG=/etc/perfconfig) all entries are marked as coming from it +* and must be kept, or the file would be truncated down to its header. +*/ +bool system_config =strcmp (config_filename,perf_etc_perfconfig ()) ==0 ;
[Severity: Medium]
Can calling perf_etc_perfconfig() concurrently here lead to a memory leak?
Because perf_etc_perfconfig() checks !system_wide without holding config_mutex, multiple threads could bypass the check simultaneously and allocate redundant path strings via system_path(). This could cause all but the last allocated string to be leaked.
tools/perf/util/config.c void perf_config__exit(void) · line 962
Quoted 13 lines
tools/perf/util/config.c +13
-0+struct perf_config_set *set; +int ret =-1 ; + + set =perf_config_set__new (); +if (!set) + goto out_err; + +if (perf_config_set__collect (set, config_filename, var, value) <0 ) { +pr_err ("Failed to add '%s=%s'\n" , var, value); + goto out_err; + } + +if (perf_config_set__write (set, config_filename, system_config) <0 ) {
[Severity: Medium]
Can concurrent configuration updates overwrite each other here, causing data loss?
The sequence of perf_config_set__new(), perf_config_set__collect(), and perf_config_set__write() drops the config_mutex between each function call. This appears to break the atomicity of the read-modify-write cycle when multiple threads invoke perf_config__set_variable() at the same time.
Quoted 9 lines
tools/perf/util/config.c +9
-0+pr_err ("Failed to set the configs on %s\n" , config_filename); + goto out_err; + } + + ret =0 ; +out_err: +perf_config_set__delete (set); +return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Arnaldo Carvalho de Melo
maintainerPATCH v7 4/15 perf debuginfo: Let the user skip and disable debuginfod fetches
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
In the stdio case, while a fetch is in progress: 's' aborts it through the debuginfod client's progress callback and remembers the build ID, so that the rest of the session does not ask for it again; 'd' additionally disables debuginfod for the session, emptying the DEBUGINFOD_URLS copy perf owns (libdwfl's own client reads it in every query) and writing core.debuginfod=false to the config file with perf_config__set_variable(). SIGINT, SIGQUIT and SIGTERM are intercepted while the terminal is in raw mode and re-raised after it is restored.
The keys are drained with read()s that do not block: the terminal is in raw mode with VMIN and VTIME zero, so read() returns zero when nothing was typed and the callback returns to the client, which carries on with the fetch. In the TUI nothing is shown yet, that comes in the next patch.
--- tools/perf/Documentation/perf-annotate.txt | 4 +- tools/perf/Documentation/perf-report.txt | 11 +- tools/perf/Documentation/perf-top.txt | 10 +- tools/perf/util/debuginfo.c | 375 +++++++++++++++------ 4 files changed, 283 insertions(+), 117 deletions(-)
tools/perf/Documentation/perf-annotate.txt +3 -1
@@ -64,7 +64,9 @@ OPTIONS configured in DEBUGINFOD_URLS, checking the local debuginfod client cache first, when it is not available locally, on for these commands by default. See the --debuginfod option of - 'perf report' for how to turn it off. + 'perf report' for how to turn it off, including the 's' and + 'd' keys that skip a fetch in progress while 'perf' is + waiting for it. --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/Documentation/perf-report.txt +8 -3
@@ -374,9 +374,14 @@ OPTIONS these commands by default. It can be turned off per invocation with --no-debuginfod, per tool with the "report.debuginfod" config option or globally with "core.debuginfod" set to false. - It is disabled as well when the local build-id cache is turned - off, e.g. "buildid.dir" set to /dev/null, as that asks for - fetched files not to be kept on the box. + While a fetch is in progress, 's' skips the current fetch and + 'd' skips it and disables debuginfod for the rest of the + session, writing core.debuginfod=false to the configuration + file so that it stays disabled in the next runs too; in the + stdio interface the progress is a line on stderr. It is + disabled as well when the local build-id cache is turned off, + e.g. "buildid.dir" set to /dev/null, as that asks for fetched + files not to be kept on the box. --kallsyms=<file>:: kallsyms pathname
tools/perf/Documentation/perf-top.txt +7 -3
@@ -90,9 +90,13 @@ Default is to monitor all CPUS. client cache first, when it is not available locally, on for these commands by default. Turn it off per invocation with --no-debuginfod, with the "top.debuginfod" config option or - globally with "core.debuginfod" set to false. Disabled as well - when the build-id cache is off, e.g. "buildid.dir" set to - /dev/null. + globally with "core.debuginfod" set to false. While a fetch is + in progress, 's' skips the current fetch and 'd' skips it and + disables debuginfod for the rest of the session, writing + core.debuginfod=false to the configuration file so that it + stays disabled in the next runs too; in the stdio interface the + progress is a line on stderr. Disabled as well when the + build-id cache is off, e.g. "buildid.dir" set to /dev/null. --kallsyms=<file>:: kallsyms pathname
tools/perf/util/debuginfo.c +265 -110
509 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 04/15] perf debuginfo: Let the user skip and disable debuginfod fetches
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
From: Arnaldo Carvalho de Melo <[email protected]>
In the stdio case, while a fetch is in progress: 's' aborts it through the debuginfod client's progress callback and remembers the build ID, so that the rest of the session does not ask for it again; 'd' additionally disables debuginfod for the session, emptying the
DEBUGINFOD_URLScopy perf owns (libdwfl's own client reads it in every query) and writing core.debuginfod=false to the config file withperf_config__set_variable(). SIGINT, SIGQUIT and SIGTERM are intercepted while the terminal is in raw mode and re-raised after it is restored.
Quoted 8 lines
The keys are drained with read()s that do not block: the terminal is in raw mode with VMIN and VTIME zero, so
read()returns zero when nothing was typed and the callback returns to the client, which carries on with the fetch. In the TUI nothing is shown yet, that comes in the next patch.Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Arnaldo Carvalho de Melo
maintainerPATCH v7 5/15 perf debuginfo: Show the debuginfod fetch progress and keys in the TUI
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The stdio only fetch UI left a TUI fetch in progress with nothing on screen, indistinguishable from a stuck perf, with no way out of it. Draw a window over the browser with the fetch progress, and drain the 's'/'d' keys from the TUI input queue, through the new ui__key_pending()/ui__key_read()/ui__progress_window()/ ui__progress_window_end() primitives declared in ui/util.h and implemented in ui/tui/util.c, with no-ops for builds without slang:
slang stays behind the ui/ layer and callers stay free of #ifdefs.
The text is word wrapped to the available columns so that narrow terminals get the 'd' option hint too, and the width is clamped, never negative.
--- tools/perf/Documentation/perf-report.txt | 9 +- tools/perf/Documentation/perf-top.txt | 5 +- tools/perf/ui/tui/util.c | 171 +++++++++++++++++++++++ tools/perf/ui/util.h | 27 ++++ tools/perf/util/debuginfo.c | 97 +++++++------ 5 files changed, 254 insertions(+), 55 deletions(-)
tools/perf/Documentation/perf-report.txt +5 -4
@@ -378,10 +378,11 @@ OPTIONS 'd' skips it and disables debuginfod for the rest of the session, writing core.debuginfod=false to the configuration file so that it stays disabled in the next runs too; in the - stdio interface the progress is a line on stderr. It is - disabled as well when the local build-id cache is turned off, - e.g. "buildid.dir" set to /dev/null, as that asks for fetched - files not to be kept on the box. + stdio interface the progress is a line on stderr, in the TUI a + window over the browser. It is disabled as well when the local + build-id cache is turned off, e.g. "buildid.dir" set to + /dev/null, as that asks for fetched files not to be kept on the + box. --kallsyms=<file>:: kallsyms pathname
tools/perf/Documentation/perf-top.txt +3 -2
@@ -95,8 +95,9 @@ Default is to monitor all CPUS. disables debuginfod for the rest of the session, writing core.debuginfod=false to the configuration file so that it stays disabled in the next runs too; in the stdio interface the - progress is a line on stderr. Disabled as well when the - build-id cache is off, e.g. "buildid.dir" set to /dev/null. + progress is a line on stderr, in the TUI a window over the + browser. Disabled as well when the build-id cache is off, e.g. + "buildid.dir" set to /dev/null. --kallsyms=<file>:: kallsyms pathname
tools/perf/ui/tui/util.c +171 -0
186 lines not on this page · raw message
tools/perf/ui/util.h +27 -0
@@ -2,9 +2,36 @@#ifndef _PERF_UI_UTIL_H_#define _PERF_UI_UTIL_H_ 1 +#include <stdbool.h> #include <stdarg.h> +#include <linux/compiler.h> +#include <linux/types.h> int ui__getch (int delay_secs); + +/* +* The TUI owns the terminal and its input queue, so the rest of perf +* asks for the progress display and for pending keys through these, +* keeping slang behind the ui/ layer. Without slang they are no-ops, +* so callers stay free of #ifdefs. +*/ +#ifndef HAVE_SLANG_SUPPORT +/* No-ops without the TUI, keeping callers free of #ifdefs. */ +static inline bool ui__key_pending (void ) {return false; } +static inline int ui__key_read (void ) {return -1 ; } +static inline void ui__progress_window (const char *title__maybe_unused , +const char *text__maybe_unused , +u64 fetched__maybe_unused , +u64 total__maybe_unused ) {} +static inline void ui__progress_window_end (void ) {} +#else /* HAVE_SLANG_SUPPORT */ +bool ui__key_pending (void ); +int ui__key_read (void ); +void ui__progress_window (const char *title,const char *text, +u64 fetched,u64 total); +void ui__progress_window_end (void ); +#endif /* HAVE_SLANG_SUPPORT */ +int ui__popup_menu (int argc,char *const argv[],int *keyp);int ui__help_window (const char *text);int ui__dialog_yesno (const char *msg);
tools/perf/util/debuginfo.c +48 -49
142 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 05/15] perf debuginfo: Show the debuginfod fetch progress and keys in the TUI
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] perf tui: SLang data race and input corruption during concurrent debuginfod fetch --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf tui: SLang data race and input corruption during concurrent debuginfod fetch --
commit 8d18f5ec06006e4e275aaf1773a82812d40a2e7f
Author: Arnaldo Carvalho de Melo <[email protected]>
perf debuginfo: Show the debuginfod fetch progress and keys in the TUI
The stdio only fetch UI left a TUI fetch in progress with nothing on screen, indistinguishable from a stuck perf, with no way out of it. Draw a window over the browser with the fetch progress, and drain the 's'/'d' keys from the TUI input queue, through the new ui__key_pending()/ui__key_read()/ui__progress_window()/ ui__progress_window_end() primitives declared in ui/util.h and implemented in ui/tui/util.c, with no-ops for builds without slang:
slang stays behind the ui/ layer and callers stay free of #ifdefs.
Quoted 4 lines
tools/perf/ui/tui/util.c +0
-0
[ ... ]
Quoted 30 lines
tools/perf/ui/tui/util.c +30
-0+void ui__progress_window (const char *title,const char *text, +u64 fetched,u64 total) +{ +static char lines[PROGRESS_WINDOW_MAX_LINES ][256 ]; +char buf_cur[20 ], buf_tot[20 ], bytes[64 ]; +size_t len; +int y, height, nr_lines, inner, i; + +if (use_browser !=1 ) +return ; + +unit_number__scnprintf (buf_cur,sizeof (buf_cur), fetched); +if (total) { +unit_number__scnprintf (buf_tot,sizeof (buf_tot), total); +scnprintf (bytes,sizeof (bytes)," %s / %s fetched" , + buf_cur, buf_tot); + }else { +scnprintf (bytes,sizeof (bytes), +" %s fetched, size unknown" , buf_cur); + } + +if (progress_window__shown && !strcmp (bytes, progress_window__bytes)) +return ; + +scnprintf (progress_window__bytes,sizeof (progress_window__bytes), +"%s" , bytes); + progress_window__shown = true; + +ui__refresh_dimensions (false); +mutex_lock (&ui__lock);
tools/perf/ui/tui/util.c struct perf_error_ops perf_tui_eops = { · line 387
Quoted 10 lines
tools/perf/ui/tui/util.c +10
-0+/* +* SLsmg_write_nstring() takes the width as an unsigned int, so never +* let a narrow terminal make it negative. Clamp it. +*/ + inner = SLtt_Screen_Cols -2 ; +if (inner <0 ) + inner =0 ; +else if (inner >255 ) + inner =255 ; + nr_lines =progress_window__wrap (text, inner, lines);
[Severity: High]
Does this code introduce data races on the static buffers?
The ui__progress_window() function updates static variables like progress_window__bytes, progress_window__shown, and the static lines array before acquiring the ui__lock.
Since debuginfod fetch callbacks can execute on the process_thread while the display_thread is running, can concurrent updates corrupt these buffers and state flags?
[ ... ]
tools/perf/ui/tui/util.c struct perf_error_ops perf_tui_eops = { · line 440
Quoted 8 lines
tools/perf/ui/tui/util.c +8
-0+/* +* The keys typed while the fetch blocked the browser are in the TUI +* input queue: nobody else is reading it, drain them through these. +*/ +bool ui__key_pending (void ) +{ +return use_browser ==1 &&SLang_input_pending (0 ) >0 ; +}
[Severity: High]
Can calling this corrupt the terminal state when debuginfod fetches occur?
This calls SLang_input_pending() directly without synchronization. Since ui__key_pending() can be triggered via debuginfod__tui_poll_cancel_keys() from the process_thread during a background fetch, it can race with the display_thread running ui__getch().
Quoted 9 lines
tools/perf/ui/tui/util.c +5
-0+ +int ui__key_read (void ) +{ +return SLang_getkey (); +}tools/perf/util/debuginfo.c +0
-0
[ ... ]
tools/perf/util/debuginfo.c static void debuginfod__poll_cancel_keys(void) · line 234
Quoted 9 lines
tools/perf/util/debuginfo.c +9
-0+/* +* The browser thread is the one doing the fetch, so its input queue has +* the keys typed while it was busy, drain those. +*/ +static void debuginfod__tui_poll_cancel_keys (void ) +{ +while (ui__key_pending ()) +debuginfod__cancel_key (ui__key_read ()); +}
[Severity: High]
Does this loop silently drop any keystrokes other than 's' or 'd'?
When debuginfod__cancel_key() processes input, it only handles 's' and 'd', meaning any other keys read from the queue are discarded rather than being passed back to the TUI.
When this runs on the process_thread, could it drop user input intended for the display_thread?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Arnaldo Carvalho de Melo
maintainerPATCH v7 6/15 perf symbol: Fall back to fetching the vmlinux by build ID
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
A profile recorded on a kernel that is no longer installed, e.g. one processed on another machine or after a kernel upgrade, cannot have its kernel symbols resolved: /proc/kallsyms does not match it and the build-id cache may carry only a kallsyms copy with zeroed addresses. Fetch the vmlinux keyed by the build ID recorded in perf.data, using debuginfod, as a last resort when no local source was found, honoring symbol_conf.ignore_vmlinux and ignore_vmlinux_buildid like the other vmlinux sources.
The fetch runs with dso->lock dropped, like dso__debuginfo(), and the file is loaded with the lock held again, only if no other thread got the symbols meanwhile (dso__has_symbols(), not dso__loaded(): the latter is set even for failed attempts). With the lock dropped two threads can map the x86-64 entry trampolines at once, so that mapping is now idempotent.
--- tools/perf/util/machine.c | 11 ++++++-- tools/perf/util/symbol.c | 55 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-)
tools/perf/util/machine.c +9 -2
@@ -1139,12 +1139,19 @@ static int machine__map_x86_64_entry_trampolines_cb(struct map *map, void *data)if (!kmap || !is_entry_trampoline (kmap->name))return 0 ; + args->found = true; + +/* +* pgoff is a virtual address when the trampoline maps are created and +* a vmlinux offset once mapped, so a second pass, e.g. a concurrent +* dso__load() of the kernel dso, finds no map and has nothing to +* translate: leave the map alone, never dereference a NULL dest_map. +*/ dest_map =maps__find (args->kmaps,map__pgoff (map)); -if (RC_CHK_ACCESS (dest_map) !=RC_CHK_ACCESS (map)) +if (dest_map !=NULL &&RC_CHK_ACCESS (dest_map) !=RC_CHK_ACCESS (map))map__set_pgoff (map,map__map_ip (dest_map,map__pgoff (map)));map__put (dest_map); - args->found = true;return 0 ; }
tools/perf/util/symbol.c +54 -1
85 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 06/15] perf symbol: Fall back to fetching the vmlinux by build ID
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
From: Arnaldo Carvalho de Melo <[email protected]>
A profile recorded on a kernel that is no longer installed, e.g. one processed on another machine or after a kernel upgrade, cannot have its kernel symbols resolved:
/proc/kallsymsdoes not match it and the build-id cache may carry only a kallsyms copy with zeroed addresses. Fetch the vmlinux keyed by the build ID recorded in perf.data, using debuginfod, as a last resort when no local source was found, honoring symbol_conf.ignore_vmlinux andignore_vmlinux_buildidlike the other vmlinux sources.The fetch runs with
dso->lockdropped, likedso__debuginfo(), and the file is loaded with the lock held again, only if no other thread got the symbols meanwhile (dso__has_symbols(), notdso__loaded(): the latter is set even for failed attempts). With the lock dropped two threads can map the x86-64 entry trampolines at once, so that mapping is now idempotent.
Quoted 2 lines
Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Arnaldo Carvalho de Melo
maintainerPATCH v7 7/15 perf annotate-data: Show the sample count in the data-type browser
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The samples view (-n, annotate.show_nr_samples) prints a local nr_samples variable that is initialized to zero and never updated, so every member is listed as having no samples while the period and percent columns for the same entry are filled in. Print the histogram entry's own count instead.
--- tools/perf/ui/browsers/annotate-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/ui/browsers/annotate-data.c +1 -1
@@ -374,7 +374,7 @@ static void browser__write_overhead(struct ui_browser *uib,u64 period = hist->period;double percent = total->period ? (100.0 * period / total->period) :0 ;bool current =ui_browser__is_current_entry (uib, row); -int nr_samples =0 ; +int nr_samples = hist->nr_samples;ui_browser__set_percent_color (uib, percent, current);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 07/15] perf annotate-data: Show the sample count in the data-type browser
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
From: Arnaldo Carvalho de Melo <[email protected]>
The samples view (-n, annotate.show_nr_samples) prints a local
nr_samplesvariable that is initialized to zero and never updated, so every member is listed as having no samples while the period and percent columns for the same entry are filled in. Print the histogram entry's own count instead.Fixes d001c7a7f4736743 ("perf annotate-data: Add hist_entry__annotate_data_tui()")Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Arnaldo Carvalho de Melo
maintainerPATCH v7 8/15 perf report: Add --progress option
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Processing a large session with stdio output gives no feedback about which phase perf is in or how far along it is: the ui_progress updates are only shown by the TUI. Add --progress, installing a stdio backend for ui_progress (ui/stdio/progress.c) that prints the phase title, the percentage and the current/total counts to stderr:
Processing events... [ 42.3%] 317M / 746M Merging related events... [ 61.0%] 309026 / 506686
Phases can be nested, so the backend keeps track of the ones started so far to complete the right one on ui_progress__finish(). That requires init()/finish() to be paired, and the paths that returned early without the finish, in ordered-events.c and in the pipe and directory event processing, are fixed.
--- tools/perf/Documentation/perf-report.txt | 13 ++ tools/perf/builtin-report.c | 10 ++ tools/perf/ui/Build | 1 + tools/perf/ui/progress.h | 2 + tools/perf/ui/stdio/progress.c | 163 +++++++++++++++++++++++ tools/perf/util/ordered-events.c | 16 ++- tools/perf/util/session.c | 12 +- 7 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 tools/perf/ui/stdio/progress.c
tools/perf/Documentation/perf-report.txt +13 -0
@@ -29,6 +29,19 @@ OPTIONS --quiet:: Do not show any warnings or messages. (Suppress -v) +--progress:: + Show progress for each of the processing phases, printing the + percentage done and the current/total counts: the first phase + counts the bytes of the perf.data file processed so far, the + merge and sort phases count hist entries, e.g.: + + Processing events... [ 42.3%] 4G / 10G + Merging related events... [ 7.1%] 1024 / 14387 + Sorting events for output... [ 98.2%] 14132 / 14387 + + It is a no-op when using the TUI or GTK browsers, that already + present progress information. + -n:: --show-nr-samples:: Show the number of samples for each symbol
tools/perf/builtin-report.c +10 -0
@@ -87,6 +87,7 @@ struct report {bool use_gtk;#endif bool use_stdio; +bool progress;bool show_full_info;bool show_threads;bool inverted_callchain;
@@ -1374,6 +1375,8 @@ int cmd_report(int argc, const char **argv) "Use the stdio interface"),OPT_BOOLEAN (0 ,"weights" , &symbol_conf.annotate_weight,"Show or hide weight columns in annotation. Default show if non-zero." ), +OPT_BOOLEAN (0 ,"progress" , &report.progress, +"Show progress while processing the perf.data file" ),OPT_BOOLEAN (0 ,"header" , &report.header,"Show data header." ),OPT_BOOLEAN (0 ,"header-only" , &report.header_only, "Show only data header."),
@@ -1766,6 +1769,13 @@ int cmd_report(int argc, const char **argv)else use_browser =0 ; +/* +* For the stdio case: print the percentage of the perf.data file +* processed so far for each processing phase. +*/ +if (report.progress && use_browser ==0 ) +stdio_progress__init (); +if (report.data_type && use_browser ==1 ) { symbol_conf.annotate_data_member = true; symbol_conf.annotate_data_sample = true;
tools/perf/ui/Build +1 -0
@@ -4,6 +4,7 @@ perf-ui-y += progress.o perf-ui-y += util.o perf-ui-y += hist.o perf-ui-y += stdio/hist.o +perf-ui-y += stdio/progress.o CFLAGS_setup.o += -DLIBDIR="BUILD_STR($(LIBDIR))"
tools/perf/ui/progress.h +2 -0
@@ -23,6 +23,8 @@ void __ui_progress__init(struct ui_progress *p, u64 total,void ui_progress__update (struct ui_progress *p,u64 adv); +void stdio_progress__init (void ); +struct ui_progress_ops {void (*init)(struct ui_progress *p);void (*update)(struct ui_progress *p);
tools/perf/ui/stdio/progress.c new file +163 -0
163 lines not on this page · raw message
tools/perf/util/ordered-events.c +12 -4
@@ -237,14 +237,16 @@ static int do_flush(struct ordered_events *oe, bool show_progress)ui_progress__init (&prog, oe->nr_events,"Processing time ordered events..." );list_for_each_entry_safe (iter, tmp, head, list) { -if (session_done ()) -return 0 ; +if (session_done ()) { + ret =0 ; + goto out_progress; + }if (iter->timestamp > limit)break ; ret = oe->deliver (oe, iter);if (ret <0 ) -return ret; + goto out_progress;ordered_events__delete (oe, iter); oe->last_flush = iter->timestamp;
@@ -258,10 +260,16 @@ static int do_flush(struct ordered_events *oe, bool show_progress)else if (last_ts <= limit) oe->last = list_entry(head->prev, struct ordered_event, list); + ret =0 ; +out_progress: +/* +* Always pair ui_progress__init() with ui_progress__finish(), the +* stdio backend tracks the phases on a stack. +*/ if (show_progress)ui_progress__finish (); -return 0 ; +return ret; } static int __ordered_events__flush(struct ordered_events *oe, enum oe_flush how,
tools/perf/util/session.c +9 -3
@@ -3248,8 +3248,12 @@ static int __perf_session__process_pipe_events(struct perf_session *session) cur_size =sizeof (union perf_event ); buf =malloc (cur_size); -if (!buf) -return -errno; +if (!buf) { + err = -errno; +if (update_prog) +ui_progress__finish (); +return err; + }ordered_events__set_copy_on_queue (oe, true); more: event = buf;
@@ -3748,8 +3752,10 @@ static int __perf_session__process_dir_events(struct perf_session *session) } rd =calloc (nr_readers,sizeof (struct reader )); -if (!rd) +if (!rd) { +ui_progress__finish ();return -ENOMEM ; + } rd[0 ] = (struct reader ) { .fd =perf_data__fd (session->data),
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 08/15] perf report: Add --progress option
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Processing a large session with stdio output gives no feedback about which phase perf is in or how far along it is: the
ui_progressupdates are only shown by the TUI. Add --progress, installing a stdio backend forui_progress(ui/stdio/progress.c) that prints the phase title, the percentage and the current/total counts to stderr:Processing events... [ 42.3%] 317M / 746M Merging related events... [ 61.0%] 309026 / 506686
Quoted 8 lines
Phases can be nested, so the backend keeps track of the ones started so far to complete the right one on
ui_progress__finish(). That requires init()/finish() to be paired, and the paths that returned early without the finish, inordered-events.cand in the pipe and directory event processing, are fixed.Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Arnaldo Carvalho de Melo
maintainerPATCH v7 9/15 perf scripts: Add perf-stuck, to tell where a running perf is stuck
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
A perf that takes forever is hard to tell apart from one stuck in a loop, and when it is stuck there is no way to see where without attaching gdb and looking around. perf-stuck.sh samples a running process' /proc entries and its progress line at a fixed interval, and with -g runs gdb (perf-stuck.gdb, adding the perf-die-chain command) when no progress is made across two samples, printing the DIE chain a DWARF type chase is walking when it is stuck in one of those.
It is a prototype: the plan is to turn it into a first class 'perf stuck' command sampling a process from inside perf.
--- tools/perf/scripts/perf-stuck.gdb | 104 ++++++++++++++++ tools/perf/scripts/perf-stuck.sh | 194 ++++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 tools/perf/scripts/perf-stuck.gdb create mode 100755 tools/perf/scripts/perf-stuck.sh
tools/perf/scripts/perf-stuck.gdb new file +104 -0
@@ -0,0 +1,104 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# gdb commands for a perf that is stuck, used by perf-stuck.sh -g and usable +# directly: +# +# gdb -p $(pgrep -x perf) -batch -x perf-stuck.gdb -ex bt +# +# PROTOTYPE: part of the perf-stuck.sh stopgap, see the note at the start of +# that script: this wants to move into a first class 'perf stuck' command, +# which would print these DIE chains by itself, without gdb. +# +# The settings are the ones that keep a batch attach from stopping to ask +# questions (debuginfod, pagination) and that make the output readable. +# +# The commands are for the DWARF type chasers in util/dwarf-aux.c, the +# functions a data type profiling 'perf report -s type' spins in when a +# debug info file has a type chain that got into a cycle: +# +# perf-die-chain <function> <die variable> [iterations] +# perf-die-chain-all [iterations] +# perf-dso +# +# For each iteration of the chasing loop they print the DIE address, the +# CU it came from, its offset in the debug file, its tag and its name: a +# cycle shows up as the same handful of (addr, cu) pairs repeating, and a +# CU that changes from one iteration to the next means the chase is +# hopping between a debug file and its dwz common file. + +set pagination off +set confirm off +set debuginfod enabled off +set print pretty on +set height 0 +set width 0 + +define perf-die-chain + if $argc < 2 + printf "usage: perf-die-chain <function> <die variable> [iterations]\n" + else + frame function $arg0 + if $argc == 3 + set $perf_die_chain_n = $arg2 + else + set $perf_die_chain_n = 10 + end + set $perf_die_chain_head = $pc + set $perf_die_chain_i = 0 + while $perf_die_chain_i < $perf_die_chain_n + printf "chain[%d] die=%p addr=%p cu=%p off=0x%lx tag=%d name=%s\n", $perf_die_chain_i, $arg1, $arg1->addr, $arg1->cu, ((Dwarf_Off) dwarf_dieoffset($arg1)), ((int) dwarf_tag($arg1)), ((char *) dwarf_diename($arg1)) + until *$perf_die_chain_head + set $perf_die_chain_i = $perf_die_chain_i + 1 + end + end +end + +document perf-die-chain +Print the DIE chain being walked by a DWARF type chasing loop. +usage: perf-die-chain <function> <die variable> [iterations] + perf-die-chain die_get_pointer_type type_die + perf-die-chain __die_get_real_type vr_die + perf-die-chain die_get_real_type vr_die +end + +define perf-die-chain-all + if $argc == 0 + set $perf_die_chain_n = 10 + else + set $perf_die_chain_n = $arg0 + end + if $_any_caller_is("die_get_pointer_type", 20) + printf "stuck in die_get_pointer_type():\n" + perf-die-chain die_get_pointer_type type_die $perf_die_chain_n + else + if $_any_caller_is("__die_get_real_type", 20) + printf "stuck in __die_get_real_type():\n" + perf-die-chain __die_get_real_type vr_die $perf_die_chain_n + else + if $_any_caller_is("die_get_real_type", 20) + printf "stuck in die_get_real_type():\n" + perf-die-chain die_get_real_type vr_die $perf_die_chain_n + else + printf "not in a DWARF type chaser, try: bt\n" + end + end + end +end + +document perf-die-chain-all +Find which DWARF type chaser the process is in and print the DIE chain. +usage: perf-die-chain-all [iterations] +end + +define perf-dso + if $_any_caller_is("find_data_type", 20) + frame function find_data_type + printf "dso=%s ip=0x%lx sym=%s\n", dloc->ms->map->dso->name, dloc->ip, dloc->ms->sym->name + else + printf "not in find_data_type()\n" + end +end + +document perf-dso +Print the dso, ip and symbol of the data location being resolved. +end
tools/perf/scripts/perf-stuck.sh new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 09/15] perf scripts: Add perf-stuck, to tell where a running perf is stuck
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] perf/scripts: privilege escalation via unscoped pgrep in perf-stuck.sh - [Medium] perf/scripts…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] perf/scripts: privilege escalation via unscoped pgrep in perf-stuck.sh
- [Medium] perf/scripts: gdb script crashes on NULL dwarf_diename()
--
commit 31fcb1c1d74aa548fa6dd4ca2fccfd9cd7dfd922
Author: Arnaldo Carvalho de Melo <[email protected]>
perf scripts: Add perf-stuck, to tell where a running perf is stuck
This commit adds the perf-stuck.sh and perf-stuck.gdb scripts to sample a running process and determine if it is stuck in an unbounded loop or recursing. The script checks /proc/<pid> entries at a fixed interval and can optionally use gdb to dump the DIE chain being walked if the process is stuck in a DWARF type chasing loop.
Quoted 6 lines
tools/perf/scripts/perf-stuck.gdb new file +0
-0@@ -0,0 +1,104 @@
[ ... ]
Quoted 4 lines
tools/perf/scripts/perf-stuck.gdb new file +4
-0+define perf-die-chain + if $argc < 2 + printf "usage: perf-die-chain <function> <die variable> [iterations]\n" + else
tools/perf/scripts/perf-stuck.gdb line 49
Quoted 10 lines
tools/perf/scripts/perf-stuck.gdb new file +10
-0+ frame function $arg0 + if $argc == 3 + set $perf_die_chain_n = $arg2 + else + set $perf_die_chain_n = 10 + end + set $perf_die_chain_head = $pc + set $perf_die_chain_i = 0 + while $perf_die_chain_i < $perf_die_chain_n + printf "chain[%d] die=%p addr=%p cu=%p off=0x%lx tag=%d name=%s\n", $perf_die_chain_i, $arg1, $arg1->addr, $arg1->cu, ((Dwarf_Off) dwarf_dieoffset($arg1)), ((int) dwarf_tag($arg1)), ((char *) dwarf_diename($arg1))
[Severity: Medium]
Since pointer type DIEs lack a DW_AT_name attribute, dwarf_diename() will return NULL for them. Will GDB's printf with the %s format specifier evaluating a 0x0 pointer result in a "Cannot access memory at address 0x0" error, aborting the GDB batch script?
Quoted 5 lines
tools/perf/scripts/perf-stuck.gdb new file +5
-0+ until *$perf_die_chain_head + set $perf_die_chain_i = $perf_die_chain_i + 1 + end + end +end
[ ... ]
Quoted 6 lines
tools/perf/scripts/perf-stuck.sh new file +0
-0@@ -0,0 +1,194 @@
[ ... ]
tools/perf/scripts/perf-stuck.sh line 79
Quoted 4 lines
tools/perf/scripts/perf-stuck.sh new file +4
-0+if [[ "$1" =~ ^[0-9]+$ ]]; then + pid=$1 +else + pid=$(pgrep -x "$1" | head -1)
[Severity: High]
Since pgrep -x searches across all users, could an unprivileged user create a malicious process matching the target name (e.g. 'perf'), causing this to resolve to the attacker's PID instead of the legitimate root process if an administrator runs this script?
Quoted 2 lines
tools/perf/scripts/perf-stuck.sh new file +2
-0+ [ -n "$pid" ] || { echo "no process named '$1'"; exit 1; } +fi
[ ... ]
tools/perf/scripts/perf-stuck.sh line 180
Quoted 3 lines
tools/perf/scripts/perf-stuck.sh new file +3
-0+ if [ -n "$use_gdb" ] && [ -z "$gdb_done" ] && [ "$stuck" -ge 2 ]; then + gdb_log=$(mktemp /tmp/perf-stuck-gdb.XXXXXX) + gdb -p "$pid" -batch -x "$gdb_cmds" -ex bt \
[Severity: High]
If the PID was resolved to an attacker-controlled process, does invoking gdb as root on it allow local privilege escalation by executing arbitrary code via malicious DWARF debug info or GDB auto-load scripts?
Quoted 6 lines
tools/perf/scripts/perf-stuck.sh new file +6
-0+ -ex 'perf-die-chain-all' -ex perf-dso -ex detach > "$gdb_log" 2>&1 + gdb_done=1 + echo "... gdb output of $pid in $gdb_log" + fi + + prev_cpu=$cpu
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Arnaldo Carvalho de Melo
maintainerPATCH v7 10/15 perf dwarf-aux: Bound the type chases for broken debug info
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
A DIE that is not what it looks like, e.g. one parsed at an offset that is not the start of a DIE, can have a DW_AT_type that refers back to itself, making the typedef/qualifier chases in die_get_real_type() and die_get_pointer_type() spin forever, and the same for the type name recursion in die_get_typename_from_type(); 'perf report -s type' did exactly that on the dwz compressed debug info of zlib-ng (libz.so.1).
No sane chain of typedefs and qualifiers is 32 DIEs long, so give up on the type with a pr_debug instead of hanging.
--- tools/perf/util/dwarf-aux.c | 88 ++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 20 deletions(-)
tools/perf/util/dwarf-aux.c +68 -20
@@ -266,16 +266,29 @@ Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)return NULL ; } +/* +* A DIE that is not what it looks like, e.g. one parsed at an offset +* that is not the start of a DIE, can have a DW_AT_type that refers +* back to itself, making these chases spin forever: bound them and +* report, instead of hanging. +*/ +#define MAX_TYPE_CHASE 32 +/* Get a type die, but skip qualifiers */ Dwarf_Die *__die_get_real_type (Dwarf_Die *vr_die,Dwarf_Die *die_mem) { -int tag; +int tag, chase =0 ; do { vr_die = die_get_type(vr_die, die_mem); if (!vr_die) - break; + return NULL; tag = dwarf_tag(vr_die); + if (++chase > MAX_TYPE_CHASE) { + pr_debug("DWARF: qualifier chase limit reached at DIE 0x%lx\n", + (unsigned long)dwarf_dieoffset(vr_die)); + return NULL; + } } while (tag == DW_TAG_const_type || tag == DW_TAG_restrict_type || tag == DW_TAG_volatile_type ||
@@ -296,8 +309,15 @@ Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)*/ Dwarf_Die *die_get_real_type (Dwarf_Die *vr_die,Dwarf_Die *die_mem) { +int chase =0 ; +do { vr_die =__die_get_real_type (vr_die, die_mem); +if (++chase >MAX_TYPE_CHASE ) { +pr_debug ("DWARF: typedef chase limit reached at DIE 0x%lx\n" , + vr_die ? (unsigned long )dwarf_dieoffset (vr_die) :0 ); +return NULL ; + } }while (vr_die &&dwarf_tag (vr_die) == DW_TAG_typedef);return vr_die;
@@ -314,7 +334,7 @@ Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)*/ Dwarf_Die *die_get_pointer_type (Dwarf_Die *type_die,Dwarf_Die *die_mem) { -int tag; +int tag, chase =0 ; do { tag = dwarf_tag(type_die);
@@ -324,6 +344,11 @@ Dwarf_Die *die_get_pointer_type(Dwarf_Die *type_die, Dwarf_Die *die_mem) tag != DW_TAG_restrict_type && tag != DW_TAG_volatile_type && tag != DW_TAG_shared_type)return NULL ; +if (++chase >MAX_TYPE_CHASE ) { +pr_debug ("DWARF: pointer type chase limit reached at DIE 0x%lx\n" , + (unsigned long )dwarf_dieoffset (type_die)); +return NULL ; + } type_die =die_get_type (type_die, die_mem); }while (type_die);
@@ -1118,17 +1143,25 @@ Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, die_mem); } -/** -* die_get_typename_from_type - Get the name of given type DIE -* @type_die: a type DIE -* @buf: a strbuf for result type name -* -* Get the name of @type_die and stores it to @buf. Return 0 if succeeded. -* and Return -ENOENT if failed to find type name. -* Note that the result will stores typedef name if possible, and stores -* "*(function_type)" if the type is a function pointer. +/* +* The name follows DW_AT_type, so a self-referring DIE makes this +* recurse forever: bound it like the chases above. */ -int die_get_typename_from_type (Dwarf_Die *type_die,struct strbuf *buf) +static int __die_get_typename_from_type (Dwarf_Die *type_die,struct strbuf *buf, +int depth); + +static int __die_get_typename (Dwarf_Die *vr_die,struct strbuf *buf,int depth) +{ +Dwarf_Die type; + +if (__die_get_real_type (vr_die, &type) ==NULL ) +return -ENOENT ; + +return __die_get_typename_from_type (&type, buf, depth); +} + +static int __die_get_typename_from_type (Dwarf_Die *type_die,struct strbuf *buf, +int depth) {int tag, ret;const char *tmp ="" ;
@@ -1155,7 +1188,12 @@ int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)/* Write a base name */ return strbuf_addf (buf,"%s%s" , tmp, name ?:"" ); } - ret =die_get_typename (type_die, buf); +if (depth >=MAX_TYPE_CHASE ) { +pr_debug ("DWARF: type name recursion limit reached at DIE 0x%lx\n" , + (unsigned long )dwarf_dieoffset (type_die)); +return -ENOENT ; + } + ret =__die_get_typename (type_die, buf, depth +1 );if (ret <0 ) {/* void pointer has no type attribute */ if (tag == DW_TAG_pointer_type && ret == -ENOENT )
@@ -1166,6 +1204,21 @@ int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)return strbuf_addstr (buf, tmp); } +/** +* die_get_typename_from_type - Get the name of given type DIE +* @type_die: a type DIE +* @buf: a strbuf for result type name +* +* Get the name of @type_die and stores it to @buf. Return 0 if succeeded. +* and Return -ENOENT if failed to find type name. +* Note that the result will stores typedef name if possible, and stores +* "*(function_type)" if the type is a function pointer. +*/ +int die_get_typename_from_type (Dwarf_Die *type_die,struct strbuf *buf) +{ +return __die_get_typename_from_type (type_die, buf,0 ); +} +/** * die_get_typename - Get the name of given variable DIE * @vr_die: a variable DIE
@@ -1178,12 +1231,7 @@ int die_get_typename_from_type(Dwarf_Die *type_die, struct strbuf *buf)*/ int die_get_typename (Dwarf_Die *vr_die,struct strbuf *buf) { -Dwarf_Die type; - -if (__die_get_real_type (vr_die, &type) ==NULL ) -return -ENOENT ; - -return die_get_typename_from_type (&type, buf); +return __die_get_typename (vr_die, buf,0 ); }/**
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 10/15] perf dwarf-aux: Bound the type chases for broken debug info
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
From: Arnaldo Carvalho de Melo <[email protected]>
A DIE that is not what it looks like, e.g. one parsed at an offset that is not the start of a DIE, can have a
DW_AT_typethat refers back to itself, making the typedef/qualifier chases indie_get_real_type()anddie_get_pointer_type()spin forever, and the same for the type name recursion indie_get_typename_from_type(); 'perf report -s type' did exactly that on the dwz compressed debug info of zlib-ng (libz.so.1).
Quoted 5 lines
No sane chain of typedefs and qualifiers is 32 DIEs long, so give up on the type with a
pr_debuginstead of hanging.Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Arnaldo Carvalho de Melo
maintainerPATCH v7 11/15 perf dwarf-aux: Add die_same_file() and die_get_type_die()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
dwarf_dieoffset() is relative to the file the DIE is in, so an offset saved by die_collect_vars()/die_collect_global_vars() is only meaningful in that file: add die_same_file(), comparing the Dwarf each DIE's CU belongs to, to record which file that is, and die_get_type_die() to resolve the offset in it, with the saved tag as a sanity check. Resolving the offset in the main file instead parses whatever is at it when it came from the dwz common file.
dwarf_cu_getdwarf() is new in elfutils 0.160, so the libdw feature test probes for it and Makefile.config says 0.160.
--- tools/build/feature/test-libdw.c | 13 ++++++- tools/perf/Makefile.config | 2 +- tools/perf/util/dwarf-aux.c | 62 ++++++++++++++++++++++++++++++-- tools/perf/util/dwarf-aux.h | 17 +++++++++ 4 files changed, 90 insertions(+), 4 deletions(-)
tools/build/feature/test-libdw.c +12 -1
@@ -49,8 +49,19 @@ int test_elfutils(void)return 0 ; } +/* +* dwarf_cu_getdwarf() needs elfutils 0.160: take its address only, so +* that older versions fail the probe instead of the link. +*/ +int test_libdw_cu_getdwarf (void ) +{ +void *sym = (void *)dwarf_cu_getdwarf; + +return sym ==NULL ; +} +int main (void ) {return test_libdw () +test_libdw_unwind () +test_libdw_getlocations () + -test_libdw_getcfi () +test_elfutils (); +test_libdw_getcfi () +test_libdw_cu_getdwarf () +test_elfutils (); }
tools/perf/Makefile.config +1 -1
@@ -470,7 +470,7 @@ else else ifneq ($(feature-libdw), 1) ifndef NO_LIBDW - $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.157, disables dwarf support. Please install new elfutils-devel/libdw-dev) + $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.160, disables dwarf support. Please install new elfutils-devel/libdw-dev) NO_LIBDW := 1 endif endif # Dwarf support
tools/perf/util/dwarf-aux.c +60 -2
98 lines not on this page · raw message
tools/perf/util/dwarf-aux.h +17 -0
@@ -152,6 +152,8 @@ int die_get_scopes(Dwarf_Die *cu_die, Dwarf_Addr pc, Dwarf_Die **scopes);struct die_var_type {struct die_var_type *next;u64 die_off; +int die_tag; +bool from_alt;/* die_off is relative to the alt (dwz) file */ u64 addr;u64 end;/* end address of location range */ int reg;
@@ -183,6 +185,21 @@ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die, Dwarf_Addr addr,/* Save all variables and parameters in this scope */ void die_collect_vars (Dwarf_Die *sc_die,struct die_var_type **var_types); +/* +* Get the type DIE saved by die_collect_vars()/die_collect_global_vars(). +* +* Those save the dwarf_dieoffset() of the type DIE, which is relative +* to the file it lives in, so @from_alt, recorded when the offset was +* saved, says which file to resolve it in; @die_tag is a sanity check. +* Resolving an alt file offset in the main file parses whatever is at +* it, which is what hung 'perf report -s type'. +*/ +Dwarf_Die *die_get_type_die (Dwarf *dbg,u64 die_off,int die_tag,bool from_alt, +Dwarf_Die *die_mem); + +/* Whether two DIEs live in the same debug file */ +bool die_same_file (Dwarf_Die *die_a,Dwarf_Die *die_b); +/* Save all global variables in this CU */ void die_collect_global_vars (Dwarf_Die *cu_die,struct die_var_type **var_types);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 11/15] perf dwarf-aux: Add die_same_file() and die_get_type_die()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
From: Arnaldo Carvalho de Melo <[email protected]>
dwarf_dieoffset()is relative to the file the DIE is in, so an offset saved by die_collect_vars()/die_collect_global_vars() is only meaningful in that file: adddie_same_file(), comparing the Dwarf each DIE's CU belongs to, to record which file that is, anddie_get_type_die()to resolve the offset in it, with the saved tag as a sanity check. Resolving the offset in the main file instead parses whatever is at it when it came from the dwz common file.
Quoted 5 lines
dwarf_cu_getdwarf()is new in elfutils 0.160, so the libdw feature test probes for it and Makefile.config says 0.160.Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Arnaldo Carvalho de Melo
maintainerPATCH v7 12/15 perf annotate-data: Resolve type DIEs in the debug file they came from
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
'perf report -s type' hangs, burning all of a CPU with no output, when resolving a hist entry on the dwz compressed debug info of libz.so.1 (zlib-ng): die_collect_vars() saves the dwarf_dieoffset() of the type DIE, which is relative to the file it lives in - the dwz alt file for the types shared by more than one CU - and update_var_state() resolves that offset in the main debug file, where it parses whatever is at that offset, here a typedef whose DW_AT_type refers to itself, making the type chase spin forever.
Record whether the type DIE came from the alt file and resolve the offset with die_get_type_die() in that file, with no fallback:
resolving an alt file offset in the main file is exactly the misparse above.
--- tools/perf/util/annotate-data.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
tools/perf/util/annotate-data.c +15 -6
@@ -645,6 +645,8 @@ struct global_var_entry {u64 start;u64 end;u64 die_offset; +int die_tag; +bool from_alt;/* die_offset is relative to the alt (dwz) file */ };static int global_var_cmp (const void *_key,const struct rb_node *node)
@@ -682,7 +684,7 @@ static struct global_var_entry *global_var__find(struct data_loc_info *dloc, u64 }static bool global_var__add (struct data_loc_info *dloc,u64 addr, -const char *name,Dwarf_Die *type_die) +const char *name,Dwarf_Die *type_die,bool from_alt) {struct dso *dso =map__dso (dloc->ms->map);struct global_var_entry *gvar;
@@ -704,6 +706,8 @@ static bool global_var__add(struct data_loc_info *dloc, u64 addr, gvar->start = addr; gvar->end = addr + size; gvar->die_offset =dwarf_dieoffset (type_die); + gvar->die_tag =dwarf_tag (type_die); + gvar->from_alt = from_alt;rb_add (&gvar->node,dso__global_vars (dso), global_var_less);return true;
@@ -778,12 +782,14 @@ static void global_var__collect(struct data_loc_info *dloc)if (pos->reg !=-1 )continue ; -if (!dwarf_offdie (dwarf, pos->die_off, &type_die)) +if (!die_get_type_die (dwarf, pos->die_off, pos->die_tag, + pos->from_alt, &type_die))continue ;get_global_var_info (dloc, pos->addr, &var_name, &var_offset); -global_var__add (dloc, pos->addr, var_name, &type_die); +global_var__add (dloc, pos->addr, var_name, &type_die, + pos->from_alt); }delete_var_types (var_types);
@@ -808,7 +814,8 @@ bool get_global_var_type(Dwarf_Die *cu_die, struct data_loc_info *dloc, gvar =global_var__find (dloc, var_addr);if (gvar) { -if (!dwarf_offdie (dloc->di->dbg, gvar->die_offset, type_die)) +if (!die_get_type_die (dloc->di->dbg, gvar->die_offset, + gvar->die_tag, gvar->from_alt, type_die))return false; *var_offset = var_addr - gvar->start;
@@ -838,7 +845,8 @@ bool get_global_var_type(Dwarf_Die *cu_die, struct data_loc_info *dloc, ok:/* The address should point to the start of the variable */ -global_var__add (dloc, var_addr - *var_offset, var_name, type_die); +global_var__add (dloc, var_addr - *var_offset, var_name, type_die, + !die_same_file (cu_die, type_die));return true; }
@@ -893,7 +901,8 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlocontinue ; }/* Get the type DIE using the offset */ -if (!dwarf_offdie (dloc->di->dbg, var->die_off, &mem_die)) +if (!die_get_type_die (dloc->di->dbg, var->die_off, + var->die_tag, var->from_alt, &mem_die))continue ;if (var->reg ==DWARF_REG_FB || var->reg == fbreg || var->reg == state->stack_reg) {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 12/15] perf annotate-data: Resolve type DIEs in the debug file they came from
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
From: Arnaldo Carvalho de Melo <[email protected]>
'perf report -s type' hangs, burning all of a CPU with no output, when resolving a hist entry on the dwz compressed debug info of libz.so.1 (zlib-ng):
die_collect_vars()saves thedwarf_dieoffset()of the type DIE, which is relative to the file it lives in - the dwz alt file for the types shared by more than one CU - andupdate_var_state()resolves that offset in the main debug file, where it parses whatever is at that offset, here a typedef whoseDW_AT_typerefers to itself, making the type chase spin forever.Record whether the type DIE came from the alt file and resolve the offset with
die_get_type_die()in that file, with no fallback:
resolving an alt file offset in the main file is exactly the misparse above.
Quoted 4 lines
Fixes 06b2ce75386df04b ("perf annotate-data: Maintain variable type info")Fixes 55ee3d005d62279d ("perf annotate-data: Add a cache for global variable types")Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Arnaldo Carvalho de Melo
maintainerPATCH v7 13/15 perf annotate-data: Bound the member nesting recursion
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Members are added recursively, and the same kind of broken DIE can make a member's type point back at one of its own ancestors, recursing until the stack is gone; nothing usable comes out of nesting members 8 deep anyway, so stop there, marking the member as truncated (reported by the JSON exporter added in a later series) and giving up on member types that don't resolve.
--- tools/perf/util/annotate-data.c | 32 ++++++++++++++++++++++++++------ tools/perf/util/annotate-data.h | 3 +++ 2 files changed, 29 insertions(+), 6 deletions(-)
tools/perf/util/annotate-data.c +26 -6
@@ -221,6 +221,13 @@ static bool data_type_less(struct rb_node *node_a, const struct rb_node *node_b)return strcmp (a->self.type_name, b->self.type_name) <0 ; } +/* +* Members are added recursively; bound the nesting so that a broken +* type that points back at one of its own ancestors doesn't recurse +* until the stack is gone. +*/ +#define MAX_MEMBER_DEPTH 8 +/* Recursively add new members for struct/union */ static int __add_member_cb (Dwarf_Die *die,void *arg) {
@@ -235,6 +242,16 @@ static int __add_member_cb(Dwarf_Die *die, void *arg)if (dwarf_tag (die) != DW_TAG_member)return DIE_FIND_CB_SIBLING ; +if (__die_get_real_type (die, &member_type) ==NULL ) +return DIE_FIND_CB_SIBLING ; + +if (dwarf_tag (&member_type) == DW_TAG_typedef) { +if (die_get_real_type (&member_type, &die_mem) ==NULL ) +return DIE_FIND_CB_SIBLING ; + }else { + die_mem = member_type; + } + member =zalloc (sizeof (*member));if (member ==NULL )return DIE_FIND_CB_END ;
@@ -242,12 +259,6 @@ static int __add_member_cb(Dwarf_Die *die, void *arg)strbuf_init (&sb,32 );die_get_typename (die, &sb); -__die_get_real_type (die, &member_type); -if (dwarf_tag (&member_type) == DW_TAG_typedef) -die_get_real_type (&member_type, &die_mem); -else - die_mem = member_type; -if (dwarf_aggregate_size (&die_mem, &size) <0 ) size =0 ;
@@ -289,10 +300,19 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) } member->size = size; member->offset = loc + parent->offset; + member->depth = parent->depth +1 ;INIT_LIST_HEAD (&member->children);list_add_tail (&member->node, &parent->children); tag =dwarf_tag (&die_mem); +if (member->depth >=MAX_MEMBER_DEPTH ) { +/* Reported by the JSON exporter so consumers can tell a truncated tree. */ + member->truncated = true; +pr_debug_dtp ("member nesting limit reached at %s\n" , + member->type_name ?:"(unknown type)" ); +return DIE_FIND_CB_SIBLING ; + } +switch (tag) {case DW_TAG_structure_type:case DW_TAG_union_type:
tools/perf/util/annotate-data.h +3 -0
@@ -57,6 +57,9 @@ struct annotated_member {char *var_name;int offset;int size; +unsigned int depth; +/* Children not expanded because the nesting limit was reached */ +bool truncated; };/**
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 13/15] perf annotate-data: Bound the member nesting recursion
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Members are added recursively, and the same kind of broken DIE can make a member's type point back at one of its own ancestors, recursing until the stack is gone; nothing usable comes out of nesting members 8 deep anyway, so stop there, marking the member as truncated (reported by the JSON exporter added in a later series) and giving up on member types that don't resolve.
Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Arnaldo Carvalho de Melo
maintainerPATCH v7 14/15 perf mem record: Request PERF_SAMPLE_CPU by default
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The data type profiling per-sample stream keys cross-CPU contention on sample->cpu; without PERF_SAMPLE_CPU that field is the (u32)-1 "no CPU info" sentinel, so same-instance accesses from different cores are indistinguishable from same-CPU traffic. 'perf mem record' already passes -d (addr) and -W (weight) explicitly to the record parser, add --sample-cpu as well and document it in perf-mem(1).
The rec_argv array only had room for nine arguments per PMU plus the user arguments, not counting the up to eight __cmd_record() adds itself, which a new argument would overflow on PMUs with separate load and store events; reserve space for the fixed arguments too.
--- tools/perf/Documentation/perf-mem.txt | 4 ++++ tools/perf/builtin-mem.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-mem.txt +4 -0
@@ -14,6 +14,10 @@ DESCRIPTION ----------- "perf mem record" runs a command and gathers memory operation data from it, into perf.data. Perf record options are accepted and are passed through. +It also requests the address (-d), the weight (-W, where supported) and the +CPU id (--sample-cpu) of every sampled access by default; the CPU id is what +lets per-sample analysis tell reads and writes to the same data from +different cores apart from same-CPU traffic. "perf mem report" displays the result. It invokes perf report with the right set of options to display a memory access profile. By default, loads
tools/perf/builtin-mem.c +9 -2
@@ -99,8 +99,8 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem, argc =parse_options (argc, argv, options, record_usage,PARSE_OPT_KEEP_UNKNOWN ); -/* Max number of arguments multiplied by number of PMUs that can support them. */ - rec_argc = argc +9 * (perf_pmu__mem_events_num_mem_pmus (pmu) +1 ); +/* Max number of arguments per PMU plus the fixed ones added below. */ + rec_argc = argc +8 +9 * (perf_pmu__mem_events_num_mem_pmus (pmu) +1 );if (mem->cpu_list) rec_argc +=2 ;
@@ -135,6 +135,13 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem, rec_argv[i++] ="-d" ; +/* +* The data type profiling per-sample stream keys cross-CPU contention +* on sample->cpu; without PERF_SAMPLE_CPU it is the (u32)-1 'no CPU +* info' sentinel. +*/ + rec_argv[i++] ="--sample-cpu" ; +if (mem->phys_addr) rec_argv[i++] ="--phys-data" ;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 14/15] perf mem record: Request PERF_SAMPLE_CPU by default
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
From: Arnaldo Carvalho de Melo <[email protected]>
The data type profiling per-sample stream keys cross-CPU contention on
sample->cpu; withoutPERF_SAMPLE_CPUthat field is the (u32)-1 "no CPU info" sentinel, so same-instance accesses from different cores are indistinguishable from same-CPU traffic. 'perf mem record' already passes -d (addr) and -W (weight) explicitly to the record parser, add --sample-cpu as well and document it in perf-mem(1).
Quoted 7 lines
The
rec_argvarray only had room for nine arguments per PMU plus the user arguments, not counting the up to eight__cmd_record()adds itself, which a new argument would overflow on PMUs with separate load and store events; reserve space for the fixed arguments too.Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Arnaldo Carvalho de Melo
maintainerPATCH v7 15/15 perf mem record: Use the IBS swfilt filter when available
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
IBS events with exclude_{user,kernel} bits, as used for per-thread recording when kernel samples are not allowed, are rejected by the kernel on hardware without the privilege filter, so per-thread 'perf mem record' fails on AMD:
$ perf mem record -o /dev/null -- true Error: Failure to open event 'ibs_op/ldlat=0/u' on PMU 'ibs_op' which will be removed. Invalid event (ibs_op/ldlat=0/u) in per-thread mode, enable system wide with '-a'.
Kernel v6.14 added swfilt, a software privilege filter exposed as the 'swfilt' format term, making those events usable per-thread:
$ perf record -e ibs_op/ldlat=0,swfilt=1/ -- true
Give the ibs_op memory events a name variant with the swfilt term, used when the PMU exposes it, even when the record ends up without exclude
bits: 'perf record' adds those bits itself when the first open fails, after the name was built, and that retry needs the term. This makes the per-thread 'perf mem record' the data type profiling shell test does work on AMD kernels with swfilt, and the test's event regex is adjusted for the added term.
--- tools/perf/arch/x86/util/mem-events.c | 14 +++++++++++--- tools/perf/tests/shell/test_data_symbol.sh | 6 ++++-- tools/perf/util/mem-events.c | 18 ++++++++++++++---- tools/perf/util/mem-events.h | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-)
tools/perf/arch/x86/util/mem-events.c +11 -3
@@ -7,7 +7,10 @@#define MEM_LOADS_AUX 0x8203 -#define E (t, n, s, l, a) { .tag = t, .name = n, .event_name = s, .ldlat = l, .aux_event = a } +#define E_INIT (t, n, s, l, a, sf) { \ + .tag = t, .name = n, .event_name = s, .swfilt_name = sf, \ + .ldlat = l, .aux_event = a } +#define E (t, n, s, l, a) E_INIT(t, n, s, l, a, NULL)struct perf_mem_event perf_mem_events_intel[PERF_MEM_EVENTS__MAX ] = {E ("ldlat-loads" ,"%s/mem-loads,ldlat=%u/P" ,"mem-loads" , true,0 ),
@@ -21,14 +24,19 @@ struct perf_mem_event perf_mem_events_intel_aux[PERF_MEM_EVENTS__MAX] = { E(NULL, NULL, NULL, false, 0), }; +/* +* IBS events with exclude bits, as used for per-thread recording, are +* rejected without the swfilt software filter, so carry a name variant +* with the term, used when the PMU exposes it. +*/ struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX ] = {E (NULL ,NULL ,NULL , false,0 ),E (NULL ,NULL ,NULL , false,0 ), -E ("mem-ldst" ,"%s//" ,NULL , false,0 ), +E_INIT ("mem-ldst" ,"%s//" ,NULL , false,0 ,"%s/swfilt=1/" ), };struct perf_mem_event perf_mem_events_amd_ldlat[PERF_MEM_EVENTS__MAX ] = {E (NULL ,NULL ,NULL , false,0 ),E (NULL ,NULL ,NULL , false,0 ), -E ("mem-ldst" ,"%s/ldlat=%u/" ,NULL , true,0 ), +E_INIT ("mem-ldst" ,"%s/ldlat=%u/" ,NULL , true,0 ,"%s/ldlat=%u,swfilt=1/" ), };
tools/perf/tests/shell/test_data_symbol.sh +4 -2
@@ -65,15 +65,17 @@ if (($is_amd >= 1)); then # --ldlat on AMD: # o Zen4 and earlier uarch does not support ldlat # o Even on supported platforms, it's disabled (--ldlat=0) by default. + # o Kernels with the swfilt term add it even when ldlat is not + # supported, so only check ldlat when the term is present. ldlat=${BASH_REMATCH[1]} - if [[ -n $ldlat ]]; then + if [[ $ldlat == *ldlat=* ]]; then if ! [[ "$ldlat" =~ ldlat=0 ]]; then echo "ERROR: ldlat not initialized to 0?" exit 1 fi mem_events="$(perf mem record -v --ldlat=150 -e list 2>&1)" - if ! [[ "$mem_events" =~ ^mem-ldst.*ibs_op/ldlat=150/.*available ]]; then + if ! [[ "$mem_events" =~ ^mem-ldst.*ibs_op/ldlat=150[,/].*available ]]; then echo "ERROR: --ldlat not honored?" exit 1 fi
tools/perf/util/mem-events.c +14 -4
@@ -82,6 +82,7 @@ static const char *perf_pmu__mem_events_name(struct perf_pmu *pmu, int i, char *buf, size_t buf_size) {struct perf_mem_event *e; +const char *name;if (i >=PERF_MEM_EVENTS__MAX || !pmu)return NULL ;
@@ -90,24 +91,33 @@ static const char *perf_pmu__mem_events_name(struct perf_pmu *pmu, int i,if (!e || !e->name)return NULL ; +/* +* Use the swfilt variant when the PMU exposes the term: 'perf record' +* adds exclude bits itself when the first open fails, after this name +* was built, and that retry needs the term in the name. +*/ + name = e->name; +if (e->swfilt_name &&perf_pmu__has_format (pmu,"swfilt" )) + name = e->swfilt_name; +if (i ==PERF_MEM_EVENTS__LOAD || i ==PERF_MEM_EVENTS__LOAD_STORE ) {if (e->ldlat) {if (!e->aux_event) {/* ARM and Most of Intel */ scnprintf (buf, buf_size, - e->name, pmu->name, + name, pmu->name, perf_mem_events__loads_ldlat); }else {/* Intel with mem-loads-aux event */ scnprintf (buf, buf_size, - e->name, pmu->name, pmu->name, + name, pmu->name, pmu->name, perf_mem_events__loads_ldlat); } }else {if (!e->aux_event) {/* AMD and POWER */ scnprintf (buf, buf_size, - e->name, pmu->name); + name, pmu->name); }else {return NULL ; }
@@ -117,7 +127,7 @@ static const char *perf_pmu__mem_events_name(struct perf_pmu *pmu, int i,if (i ==PERF_MEM_EVENTS__STORE ) {scnprintf (buf, buf_size, - e->name, pmu->name); + name, pmu->name);return buf; }
tools/perf/util/mem-events.h +2 -0
@@ -11,6 +11,8 @@ struct perf_mem_event {u32 aux_event;const char *tag;const char *name; +/* Name with the swfilt software privilege filter, when supported. */ +const char *swfilt_name;const char *event_name; };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 15/15] perf mem record: Use the IBS swfilt filter when available
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 25 lines
From: Arnaldo Carvalho de Melo <[email protected]>
IBS events with exclude_{user,kernel} bits, as used for per-thread recording when kernel samples are not allowed, are rejected by the kernel on hardware without the privilege filter, so per-thread 'perf mem record' fails on AMD:
$ perf mem record -o /dev/null -- true Error: Failure to open event 'ibs_op/ldlat=0/u' on PMU 'ibs_op' which will be removed. Invalid event (ibs_op/ldlat=0/u) in per-thread mode, enable system wide with '-a'.Kernel v6.14 added swfilt, a software privilege filter exposed as the 'swfilt' format term, making those events usable per-thread:
$ perf record -e ibs_op/ldlat=0,swfilt=1/ -- trueGive the
ibs_opmemory events a name variant with the swfilt term, used when the PMU exposes it, even when the record ends up without exclude
bits: 'perf record' adds those bits itself when the first open fails, after the name was built, and that retry needs the term. This makes the per-thread 'perf mem record' the data type profiling shell test does work on AMD kernels with swfilt, and the test's event regex is adjusted for the added term.
Quoted 3 lines
Suggested-by Namhyung Kim <[email protected]>Assisted-by LLMSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15