Re: [PATCH 2/9] perf thread-stack: Report branch stack hw_idx as not available

Adrian Hunter <[email protected]>
Newsgroups org.kernel.vger.linux-perf-users,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-doc
Organization Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki
Message-ID <[email protected]>
On 11/08/2026 18:58, Adrian Hunter wrote:
> On 03/08/2026 12:06, Amir Ayupov wrote:
>> thread_stack__br_sample() and thread_stack__br_sample_late() fill a
>> caller-supplied branch_stack that is typically allocated with zalloc(),
>> leaving hw_idx as 0. Zero is a valid hardware index, so consumers that
>> honour PERF_SAMPLE_BRANCH_HW_INDEX see a reconstructed branch stack
>> claiming to start at LBR TOS entry 0.
>>
>> These branch stacks are reconstructed from instruction trace and have no
>> hardware index at all. Set hw_idx to -1ULL, which is the established way
>> to say "not available" and matches what intel-pt and cs-etm already put
>> in the branch stacks they synthesise directly.
>>
>> Signed-off-by: Amir Ayupov <[email protected]>
> 
> Fixes tag?
> 
> Otherwise:
> 
> Reviewed-by: Adrian Hunter <[email protected]>

On second thoughts, it seems that hw_idx is only used for stitching
LBRs which is anyway disabled by default and only enabled by --stitch-lbr.

Setting -1ULL will prevent has_stitched_lbr() making a match, but we can
rely on the user to decide that for themselves via --stitch-lbr.

So, in fact, it doesn't look like this change should be needed?

> 
>> ---
>>  tools/perf/util/thread-stack.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
>> index c5ce741b07446..1a3dffa83bde2 100644
>> --- a/tools/perf/util/thread-stack.c
>> +++ b/tools/perf/util/thread-stack.c
>> @@ -624,6 +624,7 @@ void thread_stack__br_sample(struct thread *thread, int cpu,
>>  	unsigned int nr;
>>  
>>  	dst->nr = 0;
>> +	dst->hw_idx = -1ULL;
>>  
>>  	if (!ts)
>>  		return;
>> @@ -686,6 +687,7 @@ void thread_stack__br_sample_late(struct thread *thread, int cpu,
>>  	bool start = false;
>>  
>>  	dst->nr = 0;
>> +	dst->hw_idx = -1ULL;
>>  
>>  	if (!ts)
>>  		return;
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.