From nobody Wed Dec 31 10:33:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A235C4332F for ; Fri, 3 Nov 2023 19:19:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377692AbjKCTTT (ORCPT ); Fri, 3 Nov 2023 15:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377348AbjKCTTQ (ORCPT ); Fri, 3 Nov 2023 15:19:16 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DE2D52; Fri, 3 Nov 2023 12:19:13 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-28019b66ad5so2185244a91.3; Fri, 03 Nov 2023 12:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699039152; x=1699643952; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=nmFivyb8v0w5waZiQyZwSre0AC5T9ucB7JHzxYcIEWg=; b=ZBQLddQpdCTqY/cW+KhwQ4H6ogZHJNLCGit/1eMGPq8wjALl32YNTM77Jii2FaDxdh mDNEt2AJNKdwzMi2Ahi1wlfzUjGXHpfugRwiv9V/lJIMHUis8kzUOrXfBeebP3M5w7or sRIPHd8aJG8hSpgL/Jb/oR6unDrYKY/a/USxHrb7cbcgAESMLGMYtM2hiK8YLfknejvi yYPSUplylecyOsiJ14Cb81EjeF/YrwGkxFmZHVhtK+LhGtZZUofVOTUEkzuXi1t0Xt9w GkjE6H/tX1VOKA4/5zNuqQ3KcEqIO+LZBp8o9Q9OcUQ5N7I/uctPI4eLJYLK9YoSwf9W rEog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699039152; x=1699643952; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nmFivyb8v0w5waZiQyZwSre0AC5T9ucB7JHzxYcIEWg=; b=gAdpBZBJxTIgg2YSzf6bsJ3VVqrJI4DOlSZZBKppt3gmyTj7m4fQzidOjxok+2gGhB IDpjiDeHT1+kWVXtrq/wZQOFOaAZXMMTxCk4+HQvpJt+vxHTJt4JA9zSCjfx5KuU1Z+n 2WmJ7MEPjE4+WoCyRcfoF0GCoPH1LXOxlX0EvlFjEgBi30+EELe2APHR5g/ixvPpYZwg d/GA6a7lxKiSIU17VgL74T1mQriOaEMzgWtqvRfDehDZoQqZd0W+qh5gYq+lxotgOVw6 WTuoVzLSTr72sR+K2mwyPWIcfzfhvnU8mPXhCyHKnLUcLlApNX9Z0TDs0C335udlqcNm tBwA== X-Gm-Message-State: AOJu0Ywe2mXp4tZgLlQZQhffuWQdcn8N89rNgelvf5jyig1RmKEiiYRd DoC7litacMGS1jZj/AdBiRc= X-Google-Smtp-Source: AGHT+IEQS+c5IhRpfmWeduPais44QF4qkKenzqWpssZ6zHdRe1JannrnYvlKxZx2VjwPiKthPB2STg== X-Received: by 2002:a17:90a:53c7:b0:27d:63c:34f2 with SMTP id y65-20020a17090a53c700b0027d063c34f2mr21148621pjh.41.1699039152460; Fri, 03 Nov 2023 12:19:12 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:8234:4ed3:2635:c9d6]) by smtp.gmail.com with ESMTPSA id y17-20020a17090aca9100b0027cf4c554dasm1761349pjt.11.2023.11.03.12.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:19:12 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/5] perf annotate: Split struct cycles_info Date: Fri, 3 Nov 2023 12:19:03 -0700 Message-ID: <20231103191907.54531-2-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231103191907.54531-1-namhyung@kernel.org> References: <20231103191907.54531-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The cycles info is used only when branch stack is provided. Split them into a separate struct and lazy allocate them to save some memory. Signed-off-by: Namhyung Kim --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate.c | 34 ++++++++++++++++++------------- tools/perf/util/annotate.h | 14 ++++++++----- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index ccdb2cd11fbf..d2470f87344d 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -337,7 +337,7 @@ static void annotate_browser__calc_percent(struct annot= ate_browser *browser, max_percent =3D percent; } =20 - if (max_percent < 0.01 && pos->al.ipc =3D=3D 0) { + if (max_percent < 0.01 && (!pos->al.cycles || pos->al.cycles->ipc =3D=3D= 0)) { RB_CLEAR_NODE(&pos->al.rb_node); continue; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 82956adf9963..3e7f75827270 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1100,8 +1100,8 @@ static void annotation__count_and_fill(struct annotat= ion *notes, u64 start, u64 for (offset =3D start; offset <=3D end; offset++) { struct annotation_line *al =3D notes->offsets[offset]; =20 - if (al && al->ipc =3D=3D 0.0) { - al->ipc =3D ipc; + if (al && al->cycles && al->cycles->ipc =3D=3D 0.0) { + al->cycles->ipc =3D ipc; cover_insn++; } } @@ -1134,13 +1134,18 @@ void annotation__compute_ipc(struct annotation *not= es, size_t size) if (ch && ch->cycles) { struct annotation_line *al; =20 + al =3D notes->offsets[offset]; + if (al && al->cycles =3D=3D NULL) { + al->cycles =3D zalloc(sizeof(*al->cycles)); + if (al->cycles =3D=3D NULL) + continue; + } if (ch->have_start) annotation__count_and_fill(notes, ch->start, offset, ch); - al =3D notes->offsets[offset]; if (al && ch->num_aggr) { - al->cycles =3D ch->cycles_aggr / ch->num_aggr; - al->cycles_max =3D ch->cycles_max; - al->cycles_min =3D ch->cycles_min; + al->cycles->avg =3D ch->cycles_aggr / ch->num_aggr; + al->cycles->max =3D ch->cycles_max; + al->cycles->min =3D ch->cycles_min; } notes->have_cycles =3D true; } @@ -1225,6 +1230,7 @@ static void annotation_line__exit(struct annotation_l= ine *al) { zfree_srcline(&al->path); zfree(&al->line); + zfree(&al->cycles); } =20 static size_t disasm_line_size(int nr) @@ -3083,8 +3089,8 @@ static void __annotation_line__write(struct annotatio= n_line *al, struct annotati int printed; =20 if (first_line && (al->offset =3D=3D -1 || percent_max =3D=3D 0.0)) { - if (notes->have_cycles) { - if (al->ipc =3D=3D 0.0 && al->cycles =3D=3D 0) + if (notes->have_cycles && al->cycles) { + if (al->cycles->ipc =3D=3D 0.0 && al->cycles->avg =3D=3D 0) show_title =3D true; } else show_title =3D true; @@ -3121,17 +3127,17 @@ static void __annotation_line__write(struct annotat= ion_line *al, struct annotati } =20 if (notes->have_cycles) { - if (al->ipc) - obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->ipc); + if (al->cycles && al->cycles->ipc) + obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->cycles->ipc); else if (!show_title) obj__printf(obj, "%*s", ANNOTATION__IPC_WIDTH, " "); else obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC"); =20 if (!notes->options->show_minmax_cycle) { - if (al->cycles) + if (al->cycles && al->cycles->avg) obj__printf(obj, "%*" PRIu64 " ", - ANNOTATION__CYCLES_WIDTH - 1, al->cycles); + ANNOTATION__CYCLES_WIDTH - 1, al->cycles->avg); else if (!show_title) obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " "); @@ -3145,8 +3151,8 @@ static void __annotation_line__write(struct annotatio= n_line *al, struct annotati =20 scnprintf(str, sizeof(str), "%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")", - al->cycles, al->cycles_min, - al->cycles_max); + al->cycles->avg, al->cycles->min, + al->cycles->max); =20 obj__printf(obj, "%*s ", ANNOTATION__MINMAX_CYCLES_WIDTH - 1, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 962780559176..16d27952fd5c 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -130,6 +130,13 @@ struct annotation_data { struct sym_hist_entry he; }; =20 +struct cycles_info { + float ipc; + u64 avg; + u64 max; + u64 min; +}; + struct annotation_line { struct list_head node; struct rb_node rb_node; @@ -137,12 +144,9 @@ struct annotation_line { char *line; int line_nr; char *fileloc; - int jump_sources; - float ipc; - u64 cycles; - u64 cycles_max; - u64 cycles_min; char *path; + struct cycles_info *cycles; + int jump_sources; u32 idx; int idx_asm; int data_nr; --=20 2.42.0.869.gea05f2083d-goog From nobody Wed Dec 31 10:33:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98510C4332F for ; Fri, 3 Nov 2023 19:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377799AbjKCTTX (ORCPT ); Fri, 3 Nov 2023 15:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377625AbjKCTTR (ORCPT ); Fri, 3 Nov 2023 15:19:17 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2368D51; Fri, 3 Nov 2023 12:19:14 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2800229592aso2910505a91.2; Fri, 03 Nov 2023 12:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699039154; x=1699643954; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=p81VExfcUaNmCxAHoWTaVuTmx9UKE2MbB9qc5+7i1FA=; b=U4px96Dy5xkb2Cgo6VfV+ESE7qHzcnHzORzjHnAENiBBi7d5q/jIe1Y+Y+YAX3f01F ViRCQsKS5fMIk90jueDUOqwaOfILh8fir7SkLdYe2K70fcAP3DAP0sNjKQOhDgsev1ZE PkvnaCfH7IlwY00ua/dJLy+Y8NYn0l0ufW0qHdN1ye24dwSjYIaWYmYPZUZ5dlcJejNc 1GYh3JI/c+dLW6jLxm6ZBu8/H/tpuGBvEwI++EaIh3hoPgqXY6Xgv8dbalEHx8elHv6a UjehwjMAwDpF4d2JCENH0bFwKHUzOORSirlYQPpX51iuYFSivJ/0zflhOJEZD9VJ/54H YrkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699039154; x=1699643954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p81VExfcUaNmCxAHoWTaVuTmx9UKE2MbB9qc5+7i1FA=; b=hfbXl7DkRX0eJOqLsPjuCoLwJHC5P4gOG+gFF8Svn0HbYyLZ++xnwe+GuKN8YECiGo xVFQgMhJr1aCjPswRyW612s0/xivSL5fQ2BbbV0edfC6NR87ft7Kzn4OsnMDnuQ5WLaJ vzOesgGiW6cIAGIxJ9TiPk8D/D9Mmoqw+gvWaslVIvBbrEvrlQihvOKE7Cb2iDycUJdL N0tSu/O3XbvbIBp4QTA18dDNsHWE9dwvAxZjAQxSm8WXibJmyiO7T4ymsI0klzEZm2EL KfDd6UFaYC5pBiGGZ8Y4o0MVplFR6/1WQwVgbOWX2FVa6tCztXwdlhCl1vEjUAzQqKUX 4hUQ== X-Gm-Message-State: AOJu0YzPtxoMZp/dL2WXxV0P8O5sDjXM3lk4vm5X2lQ7d2crJ94fnbhL Tg/x4hSV47kcXsyGuFWmQp0= X-Google-Smtp-Source: AGHT+IHeowwUS+fhUg4ThgUnGCW0jbCN20wjzT6JQ0JvQWEIXBI1dIq1B6POYNwGRgNAXBZHIfxz2g== X-Received: by 2002:a17:90b:1286:b0:280:3370:edb5 with SMTP id fw6-20020a17090b128600b002803370edb5mr13753143pjb.3.1699039154235; Fri, 03 Nov 2023 12:19:14 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:8234:4ed3:2635:c9d6]) by smtp.gmail.com with ESMTPSA id y17-20020a17090aca9100b0027cf4c554dasm1761349pjt.11.2023.11.03.12.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:19:13 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/5] perf annotate: Split struct annotated_branch Date: Fri, 3 Nov 2023 12:19:04 -0700 Message-ID: <20231103191907.54531-3-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231103191907.54531-1-namhyung@kernel.org> References: <20231103191907.54531-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The cycles info is only meaningful when sample has branch stacks. To save the memory for normal cases, move those fields to annotated_branch and dynamically allocate it when needed. Also move cycles_hist from annotated_source as it's related here. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 97 ++++++++++++++++++++---------------- tools/perf/util/annotate.h | 17 ++++--- tools/perf/util/block-info.c | 4 +- tools/perf/util/sort.c | 14 +++--- 4 files changed, 72 insertions(+), 60 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3e7f75827270..2fa1ce3a0858 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -810,7 +810,6 @@ static __maybe_unused void annotated_source__delete(str= uct annotated_source *src if (src =3D=3D NULL) return; zfree(&src->histograms); - zfree(&src->cycles_hist); free(src); } =20 @@ -845,18 +844,6 @@ static int annotated_source__alloc_histograms(struct a= nnotated_source *src, return src->histograms ? 0 : -1; } =20 -/* The cycles histogram is lazily allocated. */ -static int symbol__alloc_hist_cycles(struct symbol *sym) -{ - struct annotation *notes =3D symbol__annotation(sym); - const size_t size =3D symbol__size(sym); - - notes->src->cycles_hist =3D calloc(size, sizeof(struct cyc_hist)); - if (notes->src->cycles_hist =3D=3D NULL) - return -1; - return 0; -} - void symbol__annotate_zero_histograms(struct symbol *sym) { struct annotation *notes =3D symbol__annotation(sym); @@ -865,9 +852,10 @@ void symbol__annotate_zero_histograms(struct symbol *s= ym) if (notes->src !=3D NULL) { memset(notes->src->histograms, 0, notes->src->nr_histograms * notes->src->sizeof_sym_hist); - if (notes->src->cycles_hist) - memset(notes->src->cycles_hist, 0, - symbol__size(sym) * sizeof(struct cyc_hist)); + } + if (notes->branch && notes->branch->cycles_hist) { + memset(notes->branch->cycles_hist, 0, + symbol__size(sym) * sizeof(struct cyc_hist)); } annotation__unlock(notes); } @@ -958,23 +946,33 @@ static int __symbol__inc_addr_samples(struct map_symb= ol *ms, return 0; } =20 +static struct annotated_branch *annotation__get_branch(struct annotation *= notes) +{ + if (notes =3D=3D NULL) + return NULL; + + if (notes->branch =3D=3D NULL) + notes->branch =3D zalloc(sizeof(*notes->branch)); + + return notes->branch; +} + static struct cyc_hist *symbol__cycles_hist(struct symbol *sym) { struct annotation *notes =3D symbol__annotation(sym); + struct annotated_branch *branch; =20 - if (notes->src =3D=3D NULL) { - notes->src =3D annotated_source__new(); - if (notes->src =3D=3D NULL) - return NULL; - goto alloc_cycles_hist; - } + branch =3D annotation__get_branch(notes); + if (branch =3D=3D NULL) + return NULL; + + if (branch->cycles_hist =3D=3D NULL) { + const size_t size =3D symbol__size(sym); =20 - if (!notes->src->cycles_hist) { -alloc_cycles_hist: - symbol__alloc_hist_cycles(sym); + branch->cycles_hist =3D calloc(size, sizeof(struct cyc_hist)); } =20 - return notes->src->cycles_hist; + return branch->cycles_hist; } =20 struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) @@ -1083,6 +1081,14 @@ static unsigned annotation__count_insn(struct annota= tion *notes, u64 start, u64 return n_insn; } =20 +static void annotated_branch__delete(struct annotated_branch *branch) +{ + if (branch) { + free(branch->cycles_hist); + free(branch); + } +} + static void annotation__count_and_fill(struct annotation *notes, u64 start= , u64 end, struct cyc_hist *ch) { unsigned n_insn; @@ -1091,6 +1097,7 @@ static void annotation__count_and_fill(struct annotat= ion *notes, u64 start, u64 =20 n_insn =3D annotation__count_insn(notes, start, end); if (n_insn && ch->num && ch->cycles) { + struct annotated_branch *branch; float ipc =3D n_insn / ((double)ch->cycles / (double)ch->num); =20 /* Hide data when there are too many overlaps. */ @@ -1106,10 +1113,11 @@ static void annotation__count_and_fill(struct annot= ation *notes, u64 start, u64 } } =20 - if (cover_insn) { - notes->hit_cycles +=3D ch->cycles; - notes->hit_insn +=3D n_insn * ch->num; - notes->cover_insn +=3D cover_insn; + branch =3D annotation__get_branch(notes); + if (cover_insn && branch) { + branch->hit_cycles +=3D ch->cycles; + branch->hit_insn +=3D n_insn * ch->num; + branch->cover_insn +=3D cover_insn; } } } @@ -1118,19 +1126,19 @@ void annotation__compute_ipc(struct annotation *not= es, size_t size) { s64 offset; =20 - if (!notes->src || !notes->src->cycles_hist) + if (!notes->branch || !notes->branch->cycles_hist) return; =20 - notes->total_insn =3D annotation__count_insn(notes, 0, size - 1); - notes->hit_cycles =3D 0; - notes->hit_insn =3D 0; - notes->cover_insn =3D 0; + notes->branch->total_insn =3D annotation__count_insn(notes, 0, size - 1); + notes->branch->hit_cycles =3D 0; + notes->branch->hit_insn =3D 0; + notes->branch->cover_insn =3D 0; =20 annotation__lock(notes); for (offset =3D size - 1; offset >=3D 0; --offset) { struct cyc_hist *ch; =20 - ch =3D ¬es->src->cycles_hist[offset]; + ch =3D ¬es->branch->cycles_hist[offset]; if (ch && ch->cycles) { struct annotation_line *al; =20 @@ -1147,7 +1155,6 @@ void annotation__compute_ipc(struct annotation *notes= , size_t size) al->cycles->max =3D ch->cycles_max; al->cycles->min =3D ch->cycles_min; } - notes->have_cycles =3D true; } } annotation__unlock(notes); @@ -1305,6 +1312,7 @@ int disasm_line__scnprintf(struct disasm_line *dl, ch= ar *bf, size_t size, bool r void annotation__exit(struct annotation *notes) { annotated_source__delete(notes->src); + annotated_branch__delete(notes->branch); } =20 static struct sharded_mutex *sharded_mutex; @@ -3058,13 +3066,14 @@ static void disasm_line__write(struct disasm_line *= dl, struct annotation *notes, static void ipc_coverage_string(char *bf, int size, struct annotation *not= es) { double ipc =3D 0.0, coverage =3D 0.0; + struct annotated_branch *branch =3D annotation__get_branch(notes); =20 - if (notes->hit_cycles) - ipc =3D notes->hit_insn / ((double)notes->hit_cycles); + if (branch && branch->hit_cycles) + ipc =3D branch->hit_insn / ((double)branch->hit_cycles); =20 - if (notes->total_insn) { - coverage =3D notes->cover_insn * 100.0 / - ((double)notes->total_insn); + if (branch && branch->total_insn) { + coverage =3D branch->cover_insn * 100.0 / + ((double)branch->total_insn); } =20 scnprintf(bf, size, "(Average IPC: %.2f, IPC Coverage: %.1f%%)", @@ -3089,7 +3098,7 @@ static void __annotation_line__write(struct annotatio= n_line *al, struct annotati int printed; =20 if (first_line && (al->offset =3D=3D -1 || percent_max =3D=3D 0.0)) { - if (notes->have_cycles && al->cycles) { + if (notes->branch && al->cycles) { if (al->cycles->ipc =3D=3D 0.0 && al->cycles->avg =3D=3D 0) show_title =3D true; } else @@ -3126,7 +3135,7 @@ static void __annotation_line__write(struct annotatio= n_line *al, struct annotati } } =20 - if (notes->have_cycles) { + if (notes->branch) { if (al->cycles && al->cycles->ipc) obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->cycles->ipc); else if (!show_title) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 16d27952fd5c..9c199629305d 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -271,17 +271,20 @@ struct annotated_source { struct list_head source; int nr_histograms; size_t sizeof_sym_hist; - struct cyc_hist *cycles_hist; struct sym_hist *histograms; }; =20 -struct LOCKABLE annotation { - u64 max_coverage; - u64 start; +struct annotated_branch { u64 hit_cycles; u64 hit_insn; unsigned int total_insn; unsigned int cover_insn; + struct cyc_hist *cycles_hist; +}; + +struct LOCKABLE annotation { + u64 max_coverage; + u64 start; struct annotation_options *options; struct annotation_line **offsets; int nr_events; @@ -297,8 +300,8 @@ struct LOCKABLE annotation { u8 max_addr; u8 max_ins_name; } widths; - bool have_cycles; struct annotated_source *src; + struct annotated_branch *branch; }; =20 static inline void annotation__init(struct annotation *notes __maybe_unuse= d) @@ -312,10 +315,10 @@ bool annotation__trylock(struct annotation *notes) EX= CLUSIVE_TRYLOCK_FUNCTION(tr =20 static inline int annotation__cycles_width(struct annotation *notes) { - if (notes->have_cycles && notes->options->show_minmax_cycle) + if (notes->branch && notes->options->show_minmax_cycle) return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH; =20 - return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WI= DTH : 0; + return notes->branch ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH := 0; } =20 static inline int annotation__pcnt_width(struct annotation *notes) diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c index 591fc1edd385..08f82c1f166c 100644 --- a/tools/perf/util/block-info.c +++ b/tools/perf/util/block-info.c @@ -129,9 +129,9 @@ int block_info__process_sym(struct hist_entry *he, stru= ct block_hist *bh, al.sym =3D he->ms.sym; =20 notes =3D symbol__annotation(he->ms.sym); - if (!notes || !notes->src || !notes->src->cycles_hist) + if (!notes || !notes->branch || !notes->branch->cycles_hist) return 0; - ch =3D notes->src->cycles_hist; + ch =3D notes->branch->cycles_hist; for (unsigned int i =3D 0; i < symbol__size(he->ms.sym); i++) { if (ch[i].num_aggr) { struct block_info *bi; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 80e4f6132740..27b123ccd2d1 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -583,21 +583,21 @@ static int hist_entry__sym_ipc_snprintf(struct hist_e= ntry *he, char *bf, { =20 struct symbol *sym =3D he->ms.sym; - struct annotation *notes; + struct annotated_branch *branch; double ipc =3D 0.0, coverage =3D 0.0; char tmp[64]; =20 if (!sym) return repsep_snprintf(bf, size, "%-*s", width, "-"); =20 - notes =3D symbol__annotation(sym); + branch =3D symbol__annotation(sym)->branch; =20 - if (notes->hit_cycles) - ipc =3D notes->hit_insn / ((double)notes->hit_cycles); + if (branch && branch->hit_cycles) + ipc =3D branch->hit_insn / ((double)branch->hit_cycles); =20 - if (notes->total_insn) { - coverage =3D notes->cover_insn * 100.0 / - ((double)notes->total_insn); + if (branch && branch->total_insn) { + coverage =3D branch->cover_insn * 100.0 / + ((double)branch->total_insn); } =20 snprintf(tmp, sizeof(tmp), "%-5.2f [%5.1f%%]", ipc, coverage); --=20 2.42.0.869.gea05f2083d-goog From nobody Wed Dec 31 10:33:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C377CC4332F for ; Fri, 3 Nov 2023 19:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377820AbjKCTT2 (ORCPT ); Fri, 3 Nov 2023 15:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377743AbjKCTTU (ORCPT ); Fri, 3 Nov 2023 15:19:20 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C32B2D52; Fri, 3 Nov 2023 12:19:16 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6c32a20d5dbso2112239b3a.1; Fri, 03 Nov 2023 12:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699039156; x=1699643956; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=AH4BcY7OvGureCnoDMX8kWZUMRQnOTP14Xx7SauGIbU=; b=azA0sIVneDywctYo2jY4jPEDJtUdR/5InVa3QcVMn2IcvR0AcbIiz+wpKVUH5yUlqe jDVTY/OIt3iiFudRFRf6TUQXpTNadnNLlijWfVvL6LxuDIrOa4tnGBCAesnsHpRYJ1+0 NrGkAHyqzMluQfUikv6dsXpol/2wBnAZl/o8yfHcYcG29M4i32SnPmjlOxMTFuNRx+VS 5wTnbjrWAxuT0Sa83x9YjNzH6ihQcmXi/EsuFZ9VeN9yycpPsuIVUwkcIcgxZvVYYez5 8R8K1jLw2bYC1w5zRluaw8cxXewrm3GmagOzVM03DQbO3GZHuAB7ONJULruto41RaDDi blJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699039156; x=1699643956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AH4BcY7OvGureCnoDMX8kWZUMRQnOTP14Xx7SauGIbU=; b=ItGSrusWZMuKrZH2OIcMzRzaBfZmmuy8RGclR0RvxmRy1eJWqKYtjrwH8DSi0HBIbP OVwZboHSPRWMgjjoVY35NNjtwQEZb55NBHnkqHoBvBWMcW1TwtAJdgnlMduLFqEGlpwU hoqLNjK3fLonjDorwDRjTJomhtg8wpA5rN8OZiv/iQkUxOpDhRntaLA7wQHm7Bgg3ip1 R1rqIUAd38RNqmX/NK51IFO/qoWUTTqyGhXbyvDKnV57PXQXZfNJn+cEl8qUTAnHkY7G EnPLS1CsAHThUyelyiO43XIm5NpjV2NtmNkc+2O/G4+JV/yMJ/iUHjRSvuzjFpFxJinQ zdaA== X-Gm-Message-State: AOJu0YwsjGjBYGL5ZewTlcLze5K6/l3H4FJtVmi0rkIc1HuOz/RkKiZR /gMGKRfaKbwKEZSWqmOJULQ= X-Google-Smtp-Source: AGHT+IHhmu+BSJ+beLNYHoa11WKmqC01tMVUpm8pBESM0YRlkuJxHaMyZ3JX5qJN0pgnpHDwF3DOyw== X-Received: by 2002:a05:6a20:1456:b0:174:63a9:2aa with SMTP id a22-20020a056a20145600b0017463a902aamr23165230pzi.18.1699039156199; Fri, 03 Nov 2023 12:19:16 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:8234:4ed3:2635:c9d6]) by smtp.gmail.com with ESMTPSA id y17-20020a17090aca9100b0027cf4c554dasm1761349pjt.11.2023.11.03.12.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:19:15 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/5] perf annotate: Move max_coverage to annotated_branch Date: Fri, 3 Nov 2023 12:19:05 -0700 Message-ID: <20231103191907.54531-4-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231103191907.54531-1-namhyung@kernel.org> References: <20231103191907.54531-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The max_coverage is only used when branch stack info is available so it'd be natural to move to the annotated_branch. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 7 +++++-- tools/perf/util/annotate.c | 2 +- tools/perf/util/annotate.h | 4 +++- tools/perf/util/block-range.c | 7 ++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index aeeb801f1ed7..a9129b51d511 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -94,6 +94,7 @@ static void process_basic_block(struct addr_map_symbol *s= tart, struct annotation *notes =3D sym ? symbol__annotation(sym) : NULL; struct block_range_iter iter; struct block_range *entry; + struct annotated_branch *branch; =20 /* * Sanity; NULL isn't executable and the CPU cannot execute backwards @@ -105,6 +106,8 @@ static void process_basic_block(struct addr_map_symbol = *start, if (!block_range_iter__valid(&iter)) return; =20 + branch =3D annotation__get_branch(notes); + /* * First block in range is a branch target. */ @@ -118,8 +121,8 @@ static void process_basic_block(struct addr_map_symbol = *start, entry->coverage++; entry->sym =3D sym; =20 - if (notes) - notes->max_coverage =3D max(notes->max_coverage, entry->coverage); + if (branch) + branch->max_coverage =3D max(branch->max_coverage, entry->coverage); =20 } while (block_range_iter__next(&iter)); =20 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2fa1ce3a0858..92a9adf9d5eb 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -946,7 +946,7 @@ static int __symbol__inc_addr_samples(struct map_symbol= *ms, return 0; } =20 -static struct annotated_branch *annotation__get_branch(struct annotation *= notes) +struct annotated_branch *annotation__get_branch(struct annotation *notes) { if (notes =3D=3D NULL) return NULL; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 9c199629305d..d8a221591926 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -280,10 +280,10 @@ struct annotated_branch { unsigned int total_insn; unsigned int cover_insn; struct cyc_hist *cycles_hist; + u64 max_coverage; }; =20 struct LOCKABLE annotation { - u64 max_coverage; u64 start; struct annotation_options *options; struct annotation_line **offsets; @@ -356,6 +356,8 @@ static inline struct annotation *symbol__annotation(str= uct symbol *sym) int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_= sample *sample, struct evsel *evsel); =20 +struct annotated_branch *annotation__get_branch(struct annotation *notes); + int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct addr_map_symbol *start, unsigned cycles); diff --git a/tools/perf/util/block-range.c b/tools/perf/util/block-range.c index 680e92774d0c..15c42196c24c 100644 --- a/tools/perf/util/block-range.c +++ b/tools/perf/util/block-range.c @@ -311,6 +311,7 @@ struct block_range_iter block_range__create(u64 start, = u64 end) double block_range__coverage(struct block_range *br) { struct symbol *sym; + struct annotated_branch *branch; =20 if (!br) { if (block_ranges.blocks) @@ -323,5 +324,9 @@ double block_range__coverage(struct block_range *br) if (!sym) return -1; =20 - return (double)br->coverage / symbol__annotation(sym)->max_coverage; + branch =3D symbol__annotation(sym)->branch; + if (!branch) + return -1; + + return (double)br->coverage / branch->max_coverage; } --=20 2.42.0.869.gea05f2083d-goog From nobody Wed Dec 31 10:33:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94E3EC4332F for ; Fri, 3 Nov 2023 19:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377746AbjKCTTd (ORCPT ); Fri, 3 Nov 2023 15:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377769AbjKCTTV (ORCPT ); Fri, 3 Nov 2023 15:19:21 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5BCD67; Fri, 3 Nov 2023 12:19:18 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-280351c32afso2252119a91.1; Fri, 03 Nov 2023 12:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699039158; x=1699643958; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=rK7/Vu7YH8dZxR5x2CkJTVBZe4LUtXaxIieL0X9K9+w=; b=OUVIj6nutYLvkTNbu/HiCVV59r2nyqy9PwZZGAR+Oevagbe6yOo13pvId/mM9ppaah 4G46XqE3SIfjbo8sXhnoYRGZ/d1otp/W4oc58n17Lhlw3dr2ay4TGNcpzw8LreM/5KH6 LnfeymqyKK52qSBc4tj1ysBMLK1LyZG3NpLdIeZJU6ntkaSHPLQCe7DodL9793HNdNwF fCogd2zB4+h0qKoeb2hLoESRylDMto8TAdGSlROawvtRO5+KGwg28acEGI+XcsvO/0+j MrOcCXe/SeLDcpvE5ZSgA0AKcGOf/nO1GqayGdijV8vlfEdEUaJsxel1Zjb/0rzYv1FU ltcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699039158; x=1699643958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rK7/Vu7YH8dZxR5x2CkJTVBZe4LUtXaxIieL0X9K9+w=; b=MMfTko1HdB6feTD27fE5NYyOTuLvzImlhqFS3tFPD+YKK0TxE2rreoTK6sPlbkKDxR H/pB5xP9uEH8rPuz405c24ls95XrSDOTCWfZnuNsVB8VkIS7YvEJ01DgX1uLWH/7Oidi Gy4IyO4KgWzgZzlamjRZH8LOINbn1hCoEQQqG5qvrIeZsdfLZ2NGofwVztTBbuFoEyYy sNUICyLrGV0M0GelFiAf2QCl5ICm0ElaK7lO11b0qda6SfVCJdC9AudN87uAAPXHj5KK qe7S+Ke8H9ayPa0CDuytcHVxJSIulIU/+aem5joVD3t9EoMQxO2s/3yecEJms2+FOb0W RNwA== X-Gm-Message-State: AOJu0Yxs2sbpNIL9dSJcxaJ/pMT9PFkGZmbsM7CwX1w3aTwV2YfgSU6H yxOPONT5dQq0jDX/ElOaHjw= X-Google-Smtp-Source: AGHT+IH8AEftuzhnRZq6j8WASpQ5uF86n3+LgN7ATj0vN3yrfJWEQxf5B9O7Lu2uonOZPCiS6vbcaA== X-Received: by 2002:a17:90b:111:b0:27d:97e5:f3fa with SMTP id p17-20020a17090b011100b0027d97e5f3famr20695564pjz.29.1699039157504; Fri, 03 Nov 2023 12:19:17 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:8234:4ed3:2635:c9d6]) by smtp.gmail.com with ESMTPSA id y17-20020a17090aca9100b0027cf4c554dasm1761349pjt.11.2023.11.03.12.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:19:17 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: [PATCH 4/5] perf annotate: Move some fields to annotated_source Date: Fri, 3 Nov 2023 12:19:06 -0700 Message-ID: <20231103191907.54531-5-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231103191907.54531-1-namhyung@kernel.org> References: <20231103191907.54531-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some fields in the struct annotation are only used with annotated_source so better to be moved there in order to reduce memory consumption for other symbols. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/ui/browsers/annotate.c | 12 ++++++------ tools/perf/util/annotate.c | 17 +++++++++-------- tools/perf/util/annotate.h | 14 +++++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index d2470f87344d..1b42db70c998 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -384,7 +384,7 @@ static bool annotate_browser__toggle_source(struct anno= tate_browser *browser) if (al->idx_asm < offset) offset =3D al->idx; =20 - browser->b.nr_entries =3D notes->nr_entries; + browser->b.nr_entries =3D notes->src->nr_entries; notes->options->hide_src_code =3D false; browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.top_idx =3D al->idx - offset; @@ -402,7 +402,7 @@ static bool annotate_browser__toggle_source(struct anno= tate_browser *browser) if (al->idx_asm < offset) offset =3D al->idx_asm; =20 - browser->b.nr_entries =3D notes->nr_asm_entries; + browser->b.nr_entries =3D notes->src->nr_asm_entries; notes->options->hide_src_code =3D true; browser->b.seek(&browser->b, -offset, SEEK_CUR); browser->b.top_idx =3D al->idx_asm - offset; @@ -435,7 +435,7 @@ static void ui_browser__init_asm_mode(struct ui_browser= *browser) { struct annotation *notes =3D browser__annotation(browser); ui_browser__reset_index(browser); - browser->nr_entries =3D notes->nr_asm_entries; + browser->nr_entries =3D notes->src->nr_asm_entries; } =20 static int sym_title(struct symbol *sym, struct map *map, char *title, @@ -860,7 +860,7 @@ static int annotate_browser__run(struct annotate_browse= r *browser, browser->b.height, browser->b.index, browser->b.top_idx, - notes->nr_asm_entries); + notes->src->nr_asm_entries); } continue; case K_ENTER: @@ -991,8 +991,8 @@ int symbol__tui_annotate(struct map_symbol *ms, struct = evsel *evsel, =20 ui_helpline__push("Press ESC to exit"); =20 - browser.b.width =3D notes->max_line_len; - browser.b.nr_entries =3D notes->nr_entries; + browser.b.width =3D notes->src->max_line_len; + browser.b.nr_entries =3D notes->src->nr_entries; browser.b.entries =3D ¬es->src->source, browser.b.width +=3D 18; /* Percentage */ =20 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 92a9adf9d5eb..ee7b8e1848a8 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2808,19 +2808,20 @@ void annotation__mark_jump_targets(struct annotatio= n *notes, struct symbol *sym) void annotation__set_offsets(struct annotation *notes, s64 size) { struct annotation_line *al; + struct annotated_source *src =3D notes->src; =20 - notes->max_line_len =3D 0; - notes->nr_entries =3D 0; - notes->nr_asm_entries =3D 0; + src->max_line_len =3D 0; + src->nr_entries =3D 0; + src->nr_asm_entries =3D 0; =20 - list_for_each_entry(al, ¬es->src->source, node) { + list_for_each_entry(al, &src->source, node) { size_t line_len =3D strlen(al->line); =20 - if (notes->max_line_len < line_len) - notes->max_line_len =3D line_len; - al->idx =3D notes->nr_entries++; + if (src->max_line_len < line_len) + src->max_line_len =3D line_len; + al->idx =3D src->nr_entries++; if (al->offset !=3D -1) { - al->idx_asm =3D notes->nr_asm_entries++; + al->idx_asm =3D src->nr_asm_entries++; /* * FIXME: short term bandaid to cope with assembly * routines that comes with labels in the same column diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index d8a221591926..022fa7ea0f22 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -268,10 +268,13 @@ struct cyc_hist { * returns. */ struct annotated_source { - struct list_head source; - int nr_histograms; - size_t sizeof_sym_hist; - struct sym_hist *histograms; + struct list_head source; + size_t sizeof_sym_hist; + struct sym_hist *histograms; + int nr_histograms; + int nr_entries; + int nr_asm_entries; + u16 max_line_len; }; =20 struct annotated_branch { @@ -289,9 +292,6 @@ struct LOCKABLE annotation { struct annotation_line **offsets; int nr_events; int max_jump_sources; - int nr_entries; - int nr_asm_entries; - u16 max_line_len; struct { u8 addr; u8 jumps; --=20 2.42.0.869.gea05f2083d-goog From nobody Wed Dec 31 10:33:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93F99C4167B for ; Fri, 3 Nov 2023 19:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377348AbjKCTTf (ORCPT ); Fri, 3 Nov 2023 15:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377584AbjKCTTW (ORCPT ); Fri, 3 Nov 2023 15:19:22 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 093FDD47; Fri, 3 Nov 2023 12:19:20 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5b9390d6bd3so2854620a12.0; Fri, 03 Nov 2023 12:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699039159; x=1699643959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Yywd3J3GcYpfirf/JYhCRxsuOyV95p1XP5rtxGSf9EM=; b=e4W/fqFkWAz4fEzVc6Obpe4io6nSui3BtbmMuby3Auqc4FjX7kMdN7qzSEvrgwAYdI VzpF6O0vtI8fb9QDl4rQWAjt5PdUhwdGWTThZIVQMItOv9bjio9A/KXHOKnFzB+4gMUM 2QGpO60Ead+yfyl2dQwI85yPOi2lDhJ0jqDMiNvU6L/BXl1SYyjNRnu3bTGGuF/C7Oh4 vl/VhlSeG+R+yLtCKSo7/bLLWUzVMC4BVgowxLrWdHAGuMhpzJRbdmL3Fs4AjvWziklM Sv8Eik4qnGG1lGn19Zl497jMrdqEdbL+PSPpiDSEzYaqSi88eZIkNxmQqAUjosawBlxQ tpYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699039159; x=1699643959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Yywd3J3GcYpfirf/JYhCRxsuOyV95p1XP5rtxGSf9EM=; b=RGcdlg/z7PSEcFwcQowGvtFNTRF6nNFZrfzQ+P2NT1KGn15BvRLhKra0GBKxX3vcNo HR2H6cM2D9JTd1qViJJEPol2PnZ4da5QnN8EjCxihdqt3j9inGSldUq+1l6H05QsTpGt Qcmr0ReuSWs4lqluHlZiD0/OH9NXMmYcJ94BRluv5PhDX5f5NZD5hxZYI/3WWt8kiftg 42MlvTr2UZdbMMnl6QRCz3/xv7eR0EvvcJ+Kl3f1PAuIJzLRMW6PAIj4kp8tuUtoZt2d PDg5ViLh0BZ/oRV1G/3j9eeP/TYh73pRTFJQcZeHyL/Vus7SlEod5+O17cF+0A7xd4Uk UEMw== X-Gm-Message-State: AOJu0YycPvXIlmNpWSgxf4lYKpEbQQtoZO4La+sxntu8t0fkaW3Zy6R7 0OnWp7nwsbRHOcjdkP1wx/Q= X-Google-Smtp-Source: AGHT+IFxhZpWmVOdbuEsPwWDwQZXJocc3phYGH/SVnXxwUfQ6Y4n3hxpLdA1QsZfB9KRopeL3nMu3Q== X-Received: by 2002:a17:90a:9a5:b0:280:47ba:767a with SMTP id 34-20020a17090a09a500b0028047ba767amr4592811pjo.16.1699039159289; Fri, 03 Nov 2023 12:19:19 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:8234:4ed3:2635:c9d6]) by smtp.gmail.com with ESMTPSA id y17-20020a17090aca9100b0027cf4c554dasm1761349pjt.11.2023.11.03.12.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:19:18 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: [PATCH 5/5] perf annotate: Move offsets to annotated_source Date: Fri, 3 Nov 2023 12:19:07 -0700 Message-ID: <20231103191907.54531-6-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231103191907.54531-1-namhyung@kernel.org> References: <20231103191907.54531-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The offsets array keeps pointers to struct annotation_line which is available in the annotated_source. Let's move it to there. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/ui/browsers/annotate.c | 4 ++-- tools/perf/util/annotate.c | 18 +++++++++--------- tools/perf/util/annotate.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 1b42db70c998..163f916fff68 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -188,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct = ui_browser *browser) * name right after the '<' token and probably treating this like a * 'call' instruction. */ - target =3D notes->offsets[cursor->ops.target.offset]; + target =3D notes->src->offsets[cursor->ops.target.offset]; if (target =3D=3D NULL) { ui_helpline__printf("WARN: jump target inconsistency, press 'o', notes->= offsets[%#x] =3D NULL\n", cursor->ops.target.offset); @@ -1006,6 +1006,6 @@ int symbol__tui_annotate(struct map_symbol *ms, struc= t evsel *evsel, =20 out_free_offsets: if(not_annotated) - zfree(¬es->offsets); + zfree(¬es->src->offsets); return ret; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index ee7b8e1848a8..8ab2e1cf63ea 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1075,7 +1075,7 @@ static unsigned annotation__count_insn(struct annotat= ion *notes, u64 start, u64 u64 offset; =20 for (offset =3D start; offset <=3D end; offset++) { - if (notes->offsets[offset]) + if (notes->src->offsets[offset]) n_insn++; } return n_insn; @@ -1105,7 +1105,7 @@ static void annotation__count_and_fill(struct annotat= ion *notes, u64 start, u64 return; =20 for (offset =3D start; offset <=3D end; offset++) { - struct annotation_line *al =3D notes->offsets[offset]; + struct annotation_line *al =3D notes->src->offsets[offset]; =20 if (al && al->cycles && al->cycles->ipc =3D=3D 0.0) { al->cycles->ipc =3D ipc; @@ -1142,7 +1142,7 @@ void annotation__compute_ipc(struct annotation *notes= , size_t size) if (ch && ch->cycles) { struct annotation_line *al; =20 - al =3D notes->offsets[offset]; + al =3D notes->src->offsets[offset]; if (al && al->cycles =3D=3D NULL) { al->cycles =3D zalloc(sizeof(*al->cycles)); if (al->cycles =3D=3D NULL) @@ -2783,7 +2783,7 @@ void annotation__mark_jump_targets(struct annotation = *notes, struct symbol *sym) return; =20 for (offset =3D 0; offset < size; ++offset) { - struct annotation_line *al =3D notes->offsets[offset]; + struct annotation_line *al =3D notes->src->offsets[offset]; struct disasm_line *dl; =20 dl =3D disasm_line(al); @@ -2791,7 +2791,7 @@ void annotation__mark_jump_targets(struct annotation = *notes, struct symbol *sym) if (!disasm_line__is_valid_local_jump(dl, sym)) continue; =20 - al =3D notes->offsets[dl->ops.target.offset]; + al =3D notes->src->offsets[dl->ops.target.offset]; =20 /* * FIXME: Oops, no jump target? Buggy disassembler? Or do we @@ -2830,7 +2830,7 @@ void annotation__set_offsets(struct annotation *notes= , s64 size) * E.g. copy_user_generic_unrolled */ if (al->offset < size) - notes->offsets[al->offset] =3D al; + notes->src->offsets[al->offset] =3D al; } else al->idx_asm =3D -1; } @@ -3263,8 +3263,8 @@ int symbol__annotate2(struct map_symbol *ms, struct e= vsel *evsel, size_t size =3D symbol__size(sym); int nr_pcnt =3D 1, err; =20 - notes->offsets =3D zalloc(size * sizeof(struct annotation_line *)); - if (notes->offsets =3D=3D NULL) + notes->src->offsets =3D zalloc(size * sizeof(struct annotation_line *)); + if (notes->src->offsets =3D=3D NULL) return ENOMEM; =20 if (evsel__is_group_event(evsel)) @@ -3290,7 +3290,7 @@ int symbol__annotate2(struct map_symbol *ms, struct e= vsel *evsel, return 0; =20 out_free_offsets: - zfree(¬es->offsets); + zfree(¬es->src->offsets); return err; } =20 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 022fa7ea0f22..ddadece4cd5a 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -271,6 +271,7 @@ struct annotated_source { struct list_head source; size_t sizeof_sym_hist; struct sym_hist *histograms; + struct annotation_line **offsets; int nr_histograms; int nr_entries; int nr_asm_entries; @@ -289,7 +290,6 @@ struct annotated_branch { struct LOCKABLE annotation { u64 start; struct annotation_options *options; - struct annotation_line **offsets; int nr_events; int max_jump_sources; struct { --=20 2.42.0.869.gea05f2083d-goog