]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf sched: Fix idle-hist callchain display using wrong rb_first variant
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 7 Jun 2026 00:49:16 +0000 (21:49 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 18:23:53 +0000 (15:23 -0300)
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@kernel.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-sched.c

index caf05863a54e5eac4a8164c54c595ee1ae811d3e..5f16caebd9645da0ec4fa23d875d901c73bf48e1 100644 (file)
@@ -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,