From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796458861; b=HHZa/sL2FxPLSFjpTMdbKRUU7/sY62WC5ZPiay8lv5iO0hMB+gS6bdpF8sHXNRAb9AgM r/NodysAXmFotxgguQXrm/TLjAjA74WNE7v7ChaN1syHy5cQjjlaPnAL0Lp3tpG4zAkcV 03pLS2QU2F17BuTPDFRKww+IsFpungsT1JD47NqUHa2BOprxvRQ9R3BagrCcf6y1c0raP 6/5s2eJunWoIbjxlj/CboVHVlMRAFwgAiAY7pViwzUU/hBgCraO/ydN4k8NcwFuf4k7iw QOq+vbjaqEfQVAx9Fmn8VioQivaXzJCkihk9E9ObTuEtAhFFariaXLrGR5r6ayz+3rA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796458861; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=WM7CL21+uChdEh2Rw08HnEcz5Yxo+ffKrHjkTrRsO9E=; b=nBn+1sn0XSo90Hm6hKznATykDVjSFBsElr9BxkTJB8shkwvasEww9d/WTCDE7Jp5d3u9 GIbYavAYPywWtpd2oLK6SSADGxW8rqLELPHL5O+3O77YcG0QdgVqoJ4bYxVjljmgP9I7P lN/ZsKinqIIfboXM8m925w4Y7g9cQkMwfXSyqyqomzisE6BNNlhPt/v2okly0VckbfruZ t4sCW0xIL7RsOqGZWZvHJv5IFam2Xk6vRwIJ4pMWsxN5hQhHo3NYdMgFrAc7UVOXF/kzA 7ztx14FfaORbFfndthBfW+YyMhem7gqkxfo/mNW7nXGgBC/SHYArTZTtcWH91VAHv5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbUHnzBi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65540606A338; Sat, 5 Dec 2026 08:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbUHnzBi Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC91F1F00936; Sat, 5 Dec 2026 08:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796458861; bh=WM7CL21+uChdEh2Rw08HnEcz5Yxo+ffKrHjkTrRsO9E=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=NbUHnzBimOYZkoeo+6O8f23Q5M1yPN6CWq13polh5v+SYs+KSFeSSGHRUnfWvBWD4 PiPJ2WPP2zlOdFZZnk5kEy2+871Z46hXie+mVqNR99ba1DbEYwYS6Ylz116utDG3qe q0P+arS5cJOZMOcVcpsOKxJ8UuWt9ZFhsjtwCPeY+dgj5Kbwd2KwaKYmMj+zYwsNOh zIhgDIQ2MOCLAlgefWKGAALxXNgDDZ13zY8c79RXrUz9tP3w6QjLt2iqRjKY0/GQOy fB2M799W2x28/OXb0SQZ5gwU7eFuSW1XZLCa93F1yHAEvxgRqnh9xPCyc3a64IIeE1 mMkFuxYXUaRSg== Date: Sat, 5 Dec 2026 00:20:59 -0800 From: Namhyung Kim To: Tabby Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`? Message-ID: References: X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Hello, On Thu, Nov 26, 2026 at 10:29:32AM -0800, Tabby wrote: > Hi, > > While using perf for userspace time-based profiling > (speedscope/Firefox Profiler stack charts), I noticed an issue where > `perf record -g` traces have incorrectly reconstructed stack traces > when I run `perf script` and import the profiling trace into a > time-axis viewer. > > For instance, when I run `perf record -e sched:sched_switch -e > cycles/freq=99/ -g htop`, I get extra and missing stack frames when > viewing the trace with `perf script` or `perf report`. Interestingly > the perf.data file *does* have enough information to reconstruct > proper call stacks, and `samply import` performs this but `perf > report/script` does not. > > ## Debugging > > I initially suspected that perf failed to query all necessary debug > info. Running `DEBUGINFOD_VERBOSE=1 perf script` shows that perf is > querying debuginfod for every build ID found in `perf buildid-list`, > but still outputs inaccurate frames from `-g/--call-graph fp` stacks. > I do not know if perf can't find downloaded debug info, can't find > on-disk binaries, or has an algorithmic deficiency. > > I took a look at the call stack captured by `sched:sched_switch`, > where htop blocks on user input within wgetch. > > - `perf script` reports the blocking call stack as `_start > > __libc_start_main > call_init > unknown > CommandLine_run > > Platform_done > LibSensors_cleanup > ScreenManager_run > wgetch > > [unknown] > __poll > syscall_cancel > internal_syscall_cancel.` This > has both missing and incorrect stack frames; notably in the source > code, `CommandLine_run()` directly calls `ScreenManager_run()` without > the intermediate frames. > > - If I run `perf report` and view the call chain from `_start`, it > reports the extraneous stack frames as `Platform_done (inlined)` and > `LibSensors_cleanup (inlined)`. Expanding further, it reports that > `wgetch` calls an unbranched chain of `0x7ffb69c4ada2 > __poll > > syscall_cancel (inlined) > internal_syscall_cancel (inlined)`. Here it > fails to resolve wgetch's function calls (whereas gdb and `layout src` > reports that wgetch calls _nc_wgetch > check_mouse_activity > > _nc_timed_wait > poll`. > > - If I run `samply import perf.data` on the same capture, and load the > trace in Firefox Profiler, I see `start > _libc_start_main_impl > > _libc_start_call_main > CommandLine_run > ScreenManager_run > wgetch > > nc_wgetch > check_mouse_activity > _GI___poll > syscall_cancel > > internal_syscall_cancel`. This shows that `samply import` and the > Firefox Profiler it spawns knows to omit the false frames between > CommandLine_run and ScreenManager_run, and properly resolves the > frames between wgetch and ...poll... This call stack is also > comparable to what gdb reports. > > - - Unfortunately samply is not a full replacement as-is, because it > only includes the first `-e` (I've reported to Samply and not heard > back yet) and doesn't symbolize in-kernel stack frames. > > Is there an explanation or possible solution for this issue? IIUC you used frame-pointer based callchains then debug info won't help the unwinding itself (it's already done in the kernel) but perf may add inlined functions in the middle using the debug info. I don't know what samply does but I guess it reads samples from the data file. Then it's strange it sees different call stacks. > > Kernel: 7.3.5-arch1-1 (64-bit) Can you please share your perf version as well? Is it the same when you run the latest version (in perf-tools-next)? Thanks, Namhyung > > ## Prior art > > It does seem that perf unwinding is a subject in flux. > https://lore.kernel.org/linux-perf-users/CAP-5=fWkUW787c4dGx9rccucqD67dfRgwBB_SoCxFnfZXtXP-w@mail.gmail.com/T/#t > indicates that in-kernel DWARF unwinding is being proposed, but it > presumably will not be ready for some months.