Re: [PATCH 06/11] perf sched: Fix idle-hist callchain display using wrong rb_first variant

From: Ian Rogers

Date: Mon Jun 08 2026 - 18:00:01 EST


On Mon, Jun 8, 2026 at 1:18 PM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> timehist_print_idlehist_callchain() calls rb_first_cached() on
> sorted_root, but the sort function (callchain_param.sort) populates it
> via rb_insert_color() on the plain rb_root member — not the cached
> variant. This means rb_leftmost is never set, so rb_first_cached()
> always returns NULL and the entire callchain summary is silently
> dropped from --idle-hist output.
>
> The original code in ba957ebb54893aca ("perf sched timehist: Show
> callchains for idle stat") was correct — it used struct rb_root and
> rb_first(). The bug was introduced when sorted_root was converted to
> rb_root_cached without converting the sort insertion path to use
> rb_insert_color_cached().
>
> Use rb_first(&root->rb_root) to match how the tree was populated.
>
> Fixes: cb4c13a5137766c3 ("perf sched: Use cached rbtrees")
> Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Assisted-by: Claude Opus 4.6 <noreply@xxxxxxxxxxxxx>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

Acked-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> ---
> tools/perf/builtin-sched.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index ded511d8518803a0..85f11d388392d316 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -3130,7 +3130,8 @@ static size_t timehist_print_idlehist_callchain(struct rb_root_cached *root)
> size_t ret = 0;
> FILE *fp = stdout;
> struct callchain_node *chain;
> - struct rb_node *rb_node = rb_first_cached(root);
> + /* sort() uses rb_insert_color() on rb_root, not rb_root_cached */
> + struct rb_node *rb_node = rb_first(&root->rb_root);
>
> printf(" %16s %8s %s\n", "Idle time (msec)", "Count", "Callchains");
> printf(" %.16s %.8s %.50s\n", graph_dotted_line, graph_dotted_line,
> --
> 2.54.0
>