[Patch v2 2/5] perf c2c: Fix top-level histogram ownership check

From: Dapeng Mi

Date: Sun Nov 08 2026 - 19:52:31 EST


The function set_node_width() incorrectly determined whether a c2c
histogram entry belonged to the top-level cacheline view by checking
if &c2c.hists equals c2c_he->hists.

This comparison is always false for top-level entries because
c2c_he->hists is only assigned for lazily-created sub-histograms in
he__get_c2c_hists(). Top-level entries are instead stored under
he->hists, which points to the embedded struct hists inside c2c.hists.

Add a dedicated helper, c2c_he__is_main_hist(), to check whether a
c2c_hist_entry belongs to the top-level histogram tree and use it to
update the node width accordingly for top-level cachelines view or
per-cacheline view.

Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address")
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
tools/perf/builtin-c2c.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index f51fa23f3bf1..a0c9afddbe98 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2233,11 +2233,19 @@ static inline bool is_valid_hist_entry(struct hist_entry *he)
return has_record;
}

+static inline bool c2c_he__is_main_hist(struct c2c_hist_entry *c2c_he)
+{
+ struct hists *hists = c2c_he->he.hists;
+
+ return hists &&
+ container_of(hists, struct c2c_hists, hists) == &c2c.hists;
+}
+
static void set_node_width(struct c2c_hist_entry *c2c_he, int len)
{
struct c2c_dimension *dim;

- dim = &c2c.hists == c2c_he->hists ?
+ dim = c2c_he__is_main_hist(c2c_he) ?
&dim_dcacheline_node : &dim_offset_node;

if (len > dim->width)
--
2.34.1