* [PATCH] perf hist: Fix branch_info index for sample weight
@ 2026-11-04 9:02 Gu Bin
2026-11-04 9:05 ` sashiko-bot
2026-11-04 9:22 ` James Clark
0 siblings, 2 replies; 3+ messages in thread
From: Gu Bin @ 2026-11-04 9:02 UTC (permalink / raw)
To: acme
Cc: peterz, mingo, namhyung, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, james.clark, linux-perf-users,
linux-kernel
iter_add_next_branch_entry() is called once per branch and uses &bi[i]
for the hist entry, but reads the weight from bi->flags.cycles (i.e.
bi[0]) for every branch, so every entry is weighted with the first
branch's cycle count. This is incorrect when the branch stack contains
more than one entry with different cycle counts, as the weight of each
hist entry fails to reflect the cycles of its own branch.
Use bi[i].flags.cycles, as the surrounding code already does.
Fixes: 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
tools/perf/util/hist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e75a4fcce975..364754e9d12a 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1055,7 +1055,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
* and not events sampled. Thus we use a pseudo period of 1.
*/
sample->period = 1;
- sample->weight = bi->flags.cycles ? bi->flags.cycles : 1;
+ sample->weight = bi[i].flags.cycles ? bi[i].flags.cycles : 1;
he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, NULL,
sample, true);
--
2.55.0.windows.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf hist: Fix branch_info index for sample weight
2026-11-04 9:02 [PATCH] perf hist: Fix branch_info index for sample weight Gu Bin
@ 2026-11-04 9:05 ` sashiko-bot
2026-11-04 9:22 ` James Clark
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-04 9:05 UTC (permalink / raw)
To: Gu Bin; +Cc: linux-perf-users
> iter_add_next_branch_entry() is called once per branch and uses &bi[i]
> for the hist entry, but reads the weight from bi->flags.cycles (i.e.
> bi[0]) for every branch, so every entry is weighted with the first
> branch's cycle count. This is incorrect when the branch stack contains
> more than one entry with different cycle counts, as the weight of each
> hist entry fails to reflect the cycles of its own branch.
>
> Use bi[i].flags.cycles, as the surrounding code already does.
>
> Fixes: 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104090229.1870-1-gubin@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf hist: Fix branch_info index for sample weight
2026-11-04 9:02 [PATCH] perf hist: Fix branch_info index for sample weight Gu Bin
2026-11-04 9:05 ` sashiko-bot
@ 2026-11-04 9:22 ` James Clark
1 sibling, 0 replies; 3+ messages in thread
From: James Clark @ 2026-11-04 9:22 UTC (permalink / raw)
To: Gu Bin
Cc: peterz, mingo, namhyung, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, linux-perf-users, linux-kernel,
Arnaldo Carvalho de Melo
On 04/11/2026 09:02, Gu Bin wrote:
> iter_add_next_branch_entry() is called once per branch and uses &bi[i]
> for the hist entry, but reads the weight from bi->flags.cycles (i.e.
> bi[0]) for every branch, so every entry is weighted with the first
> branch's cycle count. This is incorrect when the branch stack contains
> more than one entry with different cycle counts, as the weight of each
> hist entry fails to reflect the cycles of its own branch.
>
> Use bi[i].flags.cycles, as the surrounding code already does.
>
> Fixes: 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
> ---
> tools/perf/util/hist.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index e75a4fcce975..364754e9d12a 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -1055,7 +1055,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
> * and not events sampled. Thus we use a pseudo period of 1.
> */
> sample->period = 1;
> - sample->weight = bi->flags.cycles ? bi->flags.cycles : 1;
> + sample->weight = bi[i].flags.cycles ? bi[i].flags.cycles : 1;
>
> he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, NULL,
> sample, true);
Reviewed-by: James Clark <james.clark@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-04 9:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 9:02 [PATCH] perf hist: Fix branch_info index for sample weight Gu Bin
2026-11-04 9:05 ` sashiko-bot
2026-11-04 9:22 ` James Clark
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.