From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: "Ian Rogers" <irogers@google.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Namhyung Kim" <namhyung@kernel.org>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Jiri Olsa" <jolsa@kernel.org>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"James Clark" <james.clark@linaro.org>,
"Andi Kleen" <ak@linux.intel.com>,
"Dmitry Vyukov" <dvyukov@google.com>,
"Krzysztof Łopatowski" <krzysztof.m.lopatowski@gmail.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
"Weilin Wang" <weilin.wang@intel.com>
Subject: Re: [PATCH v1 1/2] perf callchain lbr: Make the leaf IP that of the sample
Date: Mon, 9 Feb 2026 08:43:41 +0800 [thread overview]
Message-ID: <d3f95dcc-4b55-4110-86be-a79f68fab7b9@linux.intel.com> (raw)
In-Reply-To: <aYZYrxyg7MTepxKQ@x1>
On 2/7/2026 5:10 AM, Arnaldo Carvalho de Melo wrote:
> On Fri, Feb 06, 2026 at 09:44:04AM +0800, Mi, Dapeng wrote:
>> On 2/6/2026 4:56 AM, Ian Rogers wrote:
>>> The current IP of a leaf function when reported from a perf record
>>> with "--call-graph lbr" is the "to" field of the LBR branch stack
>>> record. The sample for the event being recorded may be further into
>>> the function and there may be inlining information associated with
>>> it. Rather than use the branch stack "to" field in this case switch to
>>> the callchain appending the sample->ip and thereby allowing the inline
>>> information to show.
>>>
>>> Before this change:
>>> ```
>>> $ perf record --call-graph lbr perf test -w inlineloop
>>> ...
>>> $ perf script --fields +srcline
>>> ...
>>> perf-inlineloop 467586 4649.344493: 950905 cpu_core/cycles/P:
>>> 55dfda2829c0 parent+0x0 (perf)
>>> inlineloop.c:31
>>> 55dfda282a96 inlineloop+0x86 (perf)
>>> inlineloop.c:47
>>> 55dfda236420 run_workload+0x59 (perf)
>>> builtin-test.c:715
>>> 55dfda236b03 cmd_test+0x413 (perf)
>>> builtin-test.c:825
>>> ...
>>> ```
>>>
>>> After this change:
>>> ```
>>> $ perf record --call-graph lbr perf test -w inlineloop
>>> ...
>>> $ perf script --fields +srcline
>>> ...
>>> perf-inlineloop 529703 11878.680815: 950905 cpu_core/cycles/P:
>>> 555ce86be9e6 leaf+0x26
>>> inlineloop.c:20 (inlined)
>>> 555ce86be9e6 middle+0x26
>>> inlineloop.c:27 (inlined)
>>> 555ce86be9e6 parent+0x26 (perf)
>>> inlineloop.c:32
>>> 555ce86bea96 inlineloop+0x86 (perf)
>>> inlineloop.c:47
>>> 555ce8672420 run_workload+0x59 (perf)
>>> builtin-test.c:715
>>> 555ce8672b03 cmd_test+0x413 (perf)
>>> builtin-test.c:825
>>> ...
>>> ```
>>>
>>> Signed-off-by: Ian Rogers <irogers@google.com>
>>> ---
>>> tools/perf/util/machine.c | 20 ++++++++++++++++----
>>> 1 file changed, 16 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
>>> index 5b0f5a48ffd4..e76f8c86e62a 100644
>>> --- a/tools/perf/util/machine.c
>>> +++ b/tools/perf/util/machine.c
>>> @@ -2423,8 +2423,14 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
>>> }
>>>
>>> if (callee) {
>>> - /* Add LBR ip from first entries.to */
>>> - ip = entries[0].to;
>>> + /*
>>> + * Set the (first) leaf function's IP to sample->ip (the
>>> + * location of the sample) but if not recorded use entries.to
>>> + */
>>> + if (sample->ip)
>>> + ip = sample->ip;
>>> + else
>>> + ip = entries[0].to;
>>> flags = &entries[0].flags;
>>> *branch_from = entries[0].from;
>>> err = add_callchain_ip(thread, cursor, parent,
>>> @@ -2477,8 +2483,14 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
>>> }
>>>
>>> if (lbr_nr > 0) {
>>> - /* Add LBR ip from first entries.to */
>>> - ip = entries[0].to;
>>> + /*
>>> + * Set the (first) leaf function's IP to sample->ip (the
>>> + * location of the sample) but if not recorded use entries.to
>>> + */
>>> + if (sample->ip)
>>> + ip = sample->ip;
>>> + else
>>> + ip = entries[0].to;
>>> flags = &entries[0].flags;
>>> *branch_from = entries[0].from;
>>> err = add_callchain_ip(thread, cursor, parent,
>> LGTM. Thanks.
> Next time please express that with an Acked-by, that way b4 will collect
> it.
>
> I'm adding it this time:
>
> Acked-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>
> ok?
Yeah. Thanks.
>
> - Arnaldo
>
>
prev parent reply other threads:[~2026-02-09 0:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-05 20:56 [PATCH v1 1/2] perf callchain lbr: Make the leaf IP that of the sample Ian Rogers
2026-02-05 20:56 ` [PATCH v1 2/2] perf test addr2line_inlines: Ensure inline information shows on LBR leaves Ian Rogers
2026-02-06 0:10 ` [PATCH v1 1/2] perf callchain lbr: Make the leaf IP that of the sample Andi Kleen
2026-02-06 1:44 ` Mi, Dapeng
2026-02-06 21:10 ` Arnaldo Carvalho de Melo
2026-02-09 0:43 ` Mi, Dapeng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d3f95dcc-4b55-4110-86be-a79f68fab7b9@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dvyukov@google.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=krzysztof.m.lopatowski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=weilin.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox