From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3467823535E; Mon, 3 Mar 2025 17:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023489; cv=none; b=uQDALAtBe48V65+AlLheuw6tNx2fOHum6cmueDJKTvYR1a26Lmn2R8LQ+tnTHZQ/1+Q/HiI7PdXYnJfGwJPQGF0NF9Rv3Kog/YZdsCtFDOfpAyaDSpmHcILwD0nj7i/ePBt6AyHQG/oR8zjjrl+TiUlEVE9yhY/S4uLEDA+JBKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023489; c=relaxed/simple; bh=GDpi9wNiAD/cO0cZVgUO/Tf4xH/dw8B2UZS8sd2EcQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bOsGFeMn0FXxWPk3WJVwXaToYJ1MdlO2ALXU6X/0iUjg+I7YUdHALMf0n/p5o88c1f3QHxT7vISgav33oP1T+QFhq543M3skea2UDFikwmX1re6de3v9iaOAE4q5kB8+tgvLNOeqhImluO9R+XydT5r2QFEpVJWX9wVQ+J9F/qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=In1dfOKg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="In1dfOKg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58D5FC4CEE6; Mon, 3 Mar 2025 17:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023488; bh=GDpi9wNiAD/cO0cZVgUO/Tf4xH/dw8B2UZS8sd2EcQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=In1dfOKgPdJSkiMYLN6fAtBX2t//ojs1J1nkD+skN0Mkso0/mFwZFPqFlAI22kkfh 0n3ro6hfUlGzXalaHbssDVu/hAnqIU/rD5RwXfGtnfPzsGd17xG86gZEfY2oiXXcR2 Gt35ykYKw0ByPm8oiCh35CEj6xIZBYTGQ0cnXSz02jJEmgkSLjiZ/Iq76fz0bUA4cw nK2DYeGS+8Qx1+IapjlYIktsyPfhYsBuVOKzT6iI6OJwIZnat93n15YWsf02AFhWTN /MTBnU1Fp81xOYj8GHdLWQHxJoMtRHZqkXkBfU6xbMm1+pU7vYlrfLenCW/Nv26MTA h5i83tzVFldww== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 1/7] perf annotate-data: Add annotated_data_type__get_member_name() Date: Mon, 3 Mar 2025 09:38:01 -0800 Message-ID: <20250303173807.1765098-2-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out a function to get the name of member field at the given offset. This will be used in other places. Also update the output of typeoff sort key a little bit. As we know that some special types like (stack operation), (stack canary) and (unknown) won't have fields, skip printing the offset and field. For example, the following change is expected. "(stack operation) +0 (no field)" =3D=3D> "(stack operation)" Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/annotate-data.c | 34 ++++++++++++++++++++++++++++ tools/perf/util/annotate-data.h | 3 +++ tools/perf/util/sort.c | 39 ++++++--------------------------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index eaf96fa80c830d05..1ef2edbc71d91a50 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -314,6 +314,40 @@ static void delete_members(struct annotated_member *me= mber) } } =20 +static int fill_member_name(char *buf, size_t sz, struct annotated_member = *m, + int offset, bool first) +{ + struct annotated_member *child; + + if (list_empty(&m->children)) + return 0; + + list_for_each_entry(child, &m->children, node) { + int len; + + if (offset < child->offset || offset >=3D child->offset + child->size) + continue; + + /* It can have anonymous struct/union members */ + if (child->var_name) { + len =3D scnprintf(buf, sz, "%s%s", + first ? "" : ".", child->var_name); + first =3D false; + } else { + len =3D 0; + } + + return fill_member_name(buf + len, sz - len, child, offset, first) + len; + } + return 0; +} + +int annotated_data_type__get_member_name(struct annotated_data_type *adt, + char *buf, size_t sz, int member_offset) +{ + return fill_member_name(buf, sz, &adt->self, member_offset, /*first=3D*/t= rue); +} + static struct annotated_data_type *dso__findnew_data_type(struct dso *dso, Dwarf_Die *type_die) { diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 98c80b2268dde889..c9a1678a8a32518c 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -229,6 +229,9 @@ void global_var_type__tree_delete(struct rb_root *root); =20 int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el); =20 +int annotated_data_type__get_member_name(struct annotated_data_type *adt, + char *buf, size_t sz, int member_offset); + bool has_reg_type(struct type_state *state, int reg); struct type_state_stack *findnew_stack_state(struct type_state *state, int offset, u8 kind, diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 2b6023de7a53ae2e..6f7696b11b97a9f9 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -2403,44 +2403,19 @@ sort__typeoff_sort(struct hist_entry *left, struct = hist_entry *right) return left->mem_type_off - right->mem_type_off; } =20 -static void fill_member_name(char *buf, size_t sz, struct annotated_member= *m, - int offset, bool first) -{ - struct annotated_member *child; - - if (list_empty(&m->children)) - return; - - list_for_each_entry(child, &m->children, node) { - if (child->offset <=3D offset && offset < child->offset + child->size) { - int len =3D 0; - - /* It can have anonymous struct/union members */ - if (child->var_name) { - len =3D scnprintf(buf, sz, "%s%s", - first ? "" : ".", child->var_name); - first =3D false; - } - - fill_member_name(buf + len, sz - len, child, offset, first); - return; - } - } -} - static int hist_entry__typeoff_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width __maybe_unused) { struct annotated_data_type *he_type =3D he->mem_type; char buf[4096]; =20 - buf[0] =3D '\0'; - if (list_empty(&he_type->self.children)) - snprintf(buf, sizeof(buf), "no field"); - else - fill_member_name(buf, sizeof(buf), &he_type->self, - he->mem_type_off, true); - buf[4095] =3D '\0'; + if (he_type =3D=3D &unknown_type || he_type =3D=3D &stackop_type || + he_type =3D=3D &canary_type) + return repsep_snprintf(bf, size, "%s", he_type->self.type_name); + + if (!annotated_data_type__get_member_name(he_type, buf, sizeof(buf), + he->mem_type_off)) + scnprintf(buf, sizeof(buf), "no field"); =20 return repsep_snprintf(bf, size, "%s +%#x (%s)", he_type->self.type_name, he->mem_type_off, buf); --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AEB42356B3; Mon, 3 Mar 2025 17:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; cv=none; b=ficnG43rO4ezUnUqrZ7Qz+9uXTeDIt9UPmh23m0t3K07eyZJRV0m+KRiLxkZJLiAq6rD/TYKAw2s9RQKWToSWrCsoUPoRApMYGTu9EtzpncUJMuLSvFFJkoj8GMipaIqAtnjuBxWJsYQpEV5PZ4eIoyyqXjT3ps/hpVZStp+5+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; c=relaxed/simple; bh=4Xm6O4mqOxp36iPtkQwrOmQo86Nd/MpTLAxMfwDI5/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hu+msSWx4fhpin8XFrFDF2PLC5mpBMLRXIdebwpVoqILDDKvW7tCj8Y4CDo+uG3k6qDijwApNHf34qZmcjD5V6Z4nI9b+Vu/+Yl+Z2a7/FdwPbHmhV2Zbn9ohxME8KHoC+eJzhbaHH3za912se9bxY4Po4zgcsNDqj2Rdnnw2WY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nX4C6Ugy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nX4C6Ugy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4E67C4CEE5; Mon, 3 Mar 2025 17:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023489; bh=4Xm6O4mqOxp36iPtkQwrOmQo86Nd/MpTLAxMfwDI5/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nX4C6UgyT6wVb3cteQawxmmu+DoK4x7ThQvJVVl8n52WUa5LKPFVrVqb7M2F73tlR LAWtZRHM6uR2ZKhbhO0pdtJECjAjGc/Rzug9qsdnF6fokIK3CqJ5NZxI/dNzqwqBqY w1Rg3TV/36zO6Ybh1kFbyMbhXro74mvWnthEWMnYdBTpFPmReDNuMbiapAbGjFOsAB 2LDK3aWjfrdooFzbZWzndaFpM32ArsgbqCd1++4c58SdKWJpqlEXkVqWNzkPh8nL5W IqfIbj7QontYeLX7s8rlzj/I8eDxuR5PL9p5fNGvssKtXr+I3e8tbiLqzJMkAN7spV 1R3kHWDw8fNZg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 2/7] perf annotate: Remove unused len parameter from annotation_line__print() Date: Mon, 3 Mar 2025 09:38:02 -0800 Message-ID: <20250303173807.1765098-3-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's not used anywhere, let's get rid of it. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/annotate.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 31bb326b07a68e46..2e0f70b4872b475a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -760,7 +760,7 @@ static int disasm_line__print(struct disasm_line *dl, u= 64 start, int addr_fmt_wi =20 static int annotation_line__print(struct annotation_line *al, struct symbol *sym, u64= start, - struct evsel *evsel, u64 len, int min_pcnt, int printed, + struct evsel *evsel, int min_pcnt, int printed, int max_lines, struct annotation_line *queue, int addr_fmt_width, int percent_type) { @@ -796,7 +796,7 @@ annotation_line__print(struct annotation_line *al, stru= ct symbol *sym, u64 start list_for_each_entry_from(queue, ¬es->src->source, node) { if (queue =3D=3D al) break; - annotation_line__print(queue, sym, start, evsel, len, + annotation_line__print(queue, sym, start, evsel, 0, 0, 1, NULL, addr_fmt_width, percent_type); } @@ -1183,7 +1183,6 @@ int symbol__annotate_printf(struct map_symbol *ms, st= ruct evsel *evsel) int printed =3D 2, queue_len =3D 0, addr_fmt_width; int more =3D 0; bool context =3D opts->context; - u64 len; int width =3D annotation__pcnt_width(notes); int graph_dotted_len; char buf[512]; @@ -1197,8 +1196,6 @@ int symbol__annotate_printf(struct map_symbol *ms, st= ruct evsel *evsel) else d_filename =3D basename(filename); =20 - len =3D symbol__size(sym); - if (evsel__is_group_event(evsel)) { evsel__group_desc(evsel, buf, sizeof(buf)); evsel_name =3D buf; @@ -1227,7 +1224,7 @@ int symbol__annotate_printf(struct map_symbol *ms, st= ruct evsel *evsel) queue_len =3D 0; } =20 - err =3D annotation_line__print(pos, sym, start, evsel, len, + err =3D annotation_line__print(pos, sym, start, evsel, opts->min_pcnt, printed, opts->max_lines, queue, addr_fmt_width, opts->percent_type); =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AE1D2356B2; Mon, 3 Mar 2025 17:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; cv=none; b=nqguEjQf22wG3QdCzKTPgaBVoCurYKO71lijKcNQwBq3QQ7bPagz2jji2GPzzV6B34VX+vodRmXmOKo6ZiR6+auvZiO5gW2aFaBffnQVKKYF5DPH2hVTdY0Nb3N5EsQCYLJOlLEsds5FqkjZsByvpWo8O5tQ8zpYmG9j7AN5muY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; c=relaxed/simple; bh=LJUeiD3dxtTUXh14ZH5BcFePQBSylKZpbtVbu33MvF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PQYpP5Jfp1Muf9vTbatnTSQ6NU4gXtQ9jPMicQ8ZwvDIWbTLe9KXaxcl9J6tH3yhcaP8ke15l90AZ0svAMoaEsnvdleTgAzWHFeQVQXrEdFwxSnAZSnz/stTzyhOog2joQ5YdVV2fFGdYPsxR9Dx6mVnxVGQnVmUIMn4Pnmw63g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2Pf8tVi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l2Pf8tVi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DDF3C4CED6; Mon, 3 Mar 2025 17:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023489; bh=LJUeiD3dxtTUXh14ZH5BcFePQBSylKZpbtVbu33MvF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l2Pf8tVizzK9CCZ1XjgBjghmErQ3CjAheyqFhhfsUHrfVz2LiGkIFDs49ysMNwdsK oLgp9lWR0D8bXZLoFOmF8rzR3VtfSh0vj31KdhW2m//GnNMh4qQoaJS1MS69sv0fl1 E+QypuIbI77j9hQN3C+Rn5kwrMVY26vq/Th1nAJQ6LqzRyNWxC4opAcyQZamyhFnFS DL3MSednB4zfQXRKI5TpyE+fdIq8LFO7OLmL3X37rkAS/+4a/hEA+qa5ayW47NNk7a RJYSQEwz6v0XVPJuHuB8IA2eM1FqQ586xDTAwFvryVApW0L72PDugZTA9M39poLMyT KJO575VWBjVxA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 3/7] perf annotate: Pass annotation_options to annotation_line__print() Date: Mon, 3 Mar 2025 09:38:03 -0800 Message-ID: <20250303173807.1765098-4-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The annotation_line__print() has many arguments. But min_percent, max_lines and percent_type are from struct annotaion_options. So let's pass a pointer to the option instead of passing them separately to reduce the number of function arguments. Actually it has a recursive call if 'queue' is set. Add a new option instance to pass different values for the case. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/annotate.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e0f70b4872b475a..469fcc945126f4f7 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -760,13 +760,14 @@ static int disasm_line__print(struct disasm_line *dl,= u64 start, int addr_fmt_wi =20 static int annotation_line__print(struct annotation_line *al, struct symbol *sym, u64= start, - struct evsel *evsel, int min_pcnt, int printed, - int max_lines, struct annotation_line *queue, int addr_fmt_width, - int percent_type) + struct evsel *evsel, struct annotation_options *opts, + int printed, struct annotation_line *queue, int addr_fmt_width) { struct disasm_line *dl =3D container_of(al, struct disasm_line, al); struct annotation *notes =3D symbol__annotation(sym); static const char *prev_line; + int max_lines =3D opts->max_lines; + int percent_type =3D opts->percent_type; =20 if (al->offset !=3D -1) { double max_percent =3D 0.0; @@ -786,19 +787,25 @@ annotation_line__print(struct annotation_line *al, st= ruct symbol *sym, u64 start if (al->data_nr > nr_percent) nr_percent =3D al->data_nr; =20 - if (max_percent < min_pcnt) + if (max_percent < opts->min_pcnt) return -1; =20 if (max_lines && printed >=3D max_lines) return 1; =20 if (queue !=3D NULL) { + struct annotation_options queue_opts =3D { + .max_lines =3D 1, + .percent_type =3D percent_type, + }; + list_for_each_entry_from(queue, ¬es->src->source, node) { if (queue =3D=3D al) break; annotation_line__print(queue, sym, start, evsel, - 0, 0, 1, NULL, addr_fmt_width, - percent_type); + &queue_opts, /*printed=3D*/0, + /*queue=3D*/NULL, + addr_fmt_width); } } =20 @@ -1225,8 +1232,7 @@ int symbol__annotate_printf(struct map_symbol *ms, st= ruct evsel *evsel) } =20 err =3D annotation_line__print(pos, sym, start, evsel, - opts->min_pcnt, printed, opts->max_lines, - queue, addr_fmt_width, opts->percent_type); + opts, printed, queue, addr_fmt_width); =20 switch (err) { case 0: --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B92F423642B; Mon, 3 Mar 2025 17:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; cv=none; b=gmA1pIbHpSsgIFfjsshALEFWlVxwlT8VrHVPqmuSgPQTPSqM3/5YGQ+XMwiXqG0XFES/47KSgzla1e0P51XBO/H0P1hwwBS0/J35OurhhpuiY0FkhPknZRaTqOqaDSfT8GuRx6oadlOXmefIRlncG8cqIy3GYaNnKB7o6szohmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023490; c=relaxed/simple; bh=rEbIym+iIuWU2V96v1iq1VdffvNBW+fmK+sk80Yhyj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=exzzHQBULBZnD8hz3bgOGRm8MInjZCfRIZkHjOkhmrSuqFqo/CCmIfUrvGCoxuo3M5zCPvY/YUtzJlEB8+6bKtFjkEsdSw5gLSuiyizZDoeHSJKrKDwTxi7rjG4chxCbNT4h7vVBS7zJS9qHHDJyQiwGM/BbF6kSc23FRFZeKYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jNgDaZtj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jNgDaZtj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC1F1C4CEEB; Mon, 3 Mar 2025 17:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023490; bh=rEbIym+iIuWU2V96v1iq1VdffvNBW+fmK+sk80Yhyj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jNgDaZtj0AcPTVP3P37yOdCwUYc0FHHecKZ51VKrsAhtulLU92WQYxpEwcnv4Kh8s 9EyjoVgRIFpHgYNYxY2FEtuC6ATJ5QC6xFiIo5BK6f6eoCHF4GaTay4j3I6UrhcLGR 3jYs+np72d/wYgpGRKQfnFiZ5xa6wIMdgUd2antbaxr7w3+VkHFpXjNi+J3I8fnH0B zupZXYckSnasNycFzsspzLeYiDgDsK4439/gyznfnnxNDWv9mwvBg/P9D1a54FB6OB 0z9o6WMqNorNtIGbHcAc18VcHZfMcOWKSZMDdajAj3+U/vnhSRQbwFzg2x4zeULnzb ztgaCzvQag5rw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 4/7] perf annotate: Pass hist_entry to annotate functions Date: Mon, 3 Mar 2025 09:38:04 -0800 Message-ID: <20250303173807.1765098-5-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's a prepartion to support code annotation and data type annotation at the same time. Data type annotation needs more information in the hist_entry so it needs to be passed deeper. Also rename a function with the same name in the builtin-annotate.c to hist_entry__stdio_annotate since it matches better to the command line option. And change the condition inside to be simpler. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/builtin-annotate.c | 10 +++++----- tools/perf/builtin-top.c | 2 +- tools/perf/util/annotate.c | 11 +++++++---- tools/perf/util/annotate.h | 7 +++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 836ae0122dabd0ea..966950c38306d6ea 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -321,14 +321,14 @@ static int process_feature_event(struct perf_session = *session, return 0; } =20 -static int hist_entry__tty_annotate(struct hist_entry *he, +static int hist_entry__stdio_annotate(struct hist_entry *he, struct evsel *evsel, struct perf_annotate *ann) { - if (!ann->use_stdio2) - return symbol__tty_annotate(&he->ms, evsel); + if (ann->use_stdio2) + return hist_entry__tty_annotate2(he, evsel); =20 - return symbol__tty_annotate2(&he->ms, evsel); + return hist_entry__tty_annotate(he, evsel); } =20 static void print_annotate_data_stat(struct annotated_data_stat *s) @@ -541,7 +541,7 @@ static void hists__find_annotations(struct hists *hists, if (next !=3D NULL) nd =3D next; } else { - hist_entry__tty_annotate(he, evsel, ann); + hist_entry__stdio_annotate(he, evsel, ann); nd =3D rb_next(nd); } } diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e1115b8317a0fe3d..7395fdef718d432d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -263,7 +263,7 @@ static void perf_top__show_details(struct perf_top *top) printf("Showing %s for %s\n", evsel__name(top->sym_evsel), symbol->name); printf(" Events Pcnt (>=3D%d%%)\n", annotate_opts.min_pcnt); =20 - more =3D symbol__annotate_printf(&he->ms, top->sym_evsel); + more =3D hist_entry__annotate_printf(he, top->sym_evsel); =20 if (top->evlist->enabled) { if (top->zero) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 469fcc945126f4f7..029e47a521caf1af 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1174,8 +1174,9 @@ static int annotated_source__addr_fmt_width(struct li= st_head *lines, u64 start) return 0; } =20 -int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel) +int hist_entry__annotate_printf(struct hist_entry *he, struct evsel *evsel) { + struct map_symbol *ms =3D &he->ms; struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; struct dso *dso =3D map__dso(map); @@ -1600,8 +1601,9 @@ static void symbol__calc_lines(struct map_symbol *ms,= struct rb_root *root) annotation__calc_lines(notes, ms, root); } =20 -int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel) +int hist_entry__tty_annotate2(struct hist_entry *he, struct evsel *evsel) { + struct map_symbol *ms =3D &he->ms; struct dso *dso =3D map__dso(ms->map); struct symbol *sym =3D ms->sym; struct rb_root source_line =3D RB_ROOT; @@ -1635,8 +1637,9 @@ int symbol__tty_annotate2(struct map_symbol *ms, stru= ct evsel *evsel) return 0; } =20 -int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel) +int hist_entry__tty_annotate(struct hist_entry *he, struct evsel *evsel) { + struct map_symbol *ms =3D &he->ms; struct dso *dso =3D map__dso(ms->map); struct symbol *sym =3D ms->sym; struct rb_root source_line =3D RB_ROOT; @@ -1660,7 +1663,7 @@ int symbol__tty_annotate(struct map_symbol *ms, struc= t evsel *evsel) print_summary(&source_line, dso__long_name(dso)); } =20 - symbol__annotate_printf(ms, evsel); + hist_entry__annotate_printf(he, evsel); =20 annotated_source__purge(symbol__annotation(sym)->src); =20 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 98db1b88daf43e13..4fba7cde4968db74 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -455,7 +455,6 @@ enum symbol_disassemble_errno { =20 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *= buf, size_t buflen); =20 -int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel); void symbol__annotate_zero_histogram(struct symbol *sym, struct evsel *evs= el); void symbol__annotate_decay_histogram(struct symbol *sym, struct evsel *ev= sel); void annotated_source__purge(struct annotated_source *as); @@ -464,9 +463,9 @@ int map_symbol__annotation_dump(struct map_symbol *ms, = struct evsel *evsel); =20 bool ui__has_annotation(void); =20 -int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel); - -int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel); +int hist_entry__annotate_printf(struct hist_entry *he, struct evsel *evsel= ); +int hist_entry__tty_annotate(struct hist_entry *he, struct evsel *evsel); +int hist_entry__tty_annotate2(struct hist_entry *he, struct evsel *evsel); =20 #ifdef HAVE_SLANG_SUPPORT int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel, --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC0132153DA; Mon, 3 Mar 2025 17:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023491; cv=none; b=BlACDCZ/SzFYqMzJO3JGkesipR4AG/V76RB/Sd+uMlDNnFdfaJPU+iCXc9e/IFrVHNm710kzpwdyUeFk/zMxB35SXdMF/qcc23rltQm7eIBqfb/9Pus6koZ4Mlo+BhZqedpA1du30ozMKFadXhobYwBaHr4MR1J4WwhiiuPhw3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023491; c=relaxed/simple; bh=IzsVT4D7lKAXXVXm5+ZrHMmiCtYtaaf7NJrpUczKObw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CFekbyio7fHOG1S7Zq1JqbVnaqDYOO+G6TmhWtSc8GMB80Cmim9eECYL070ZxkB0wHze1M5r0mMi1rcHtArqW8N/BC7u8X1Ui0efQKpvxUnYDO/HAu/j/c4AjIZE+4SfeGoBDQE5gnUiY77Sz2vBYlfcEsJMbWoMYtE12nEfblc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=arAZjL8O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="arAZjL8O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 672E1C4CED6; Mon, 3 Mar 2025 17:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023490; bh=IzsVT4D7lKAXXVXm5+ZrHMmiCtYtaaf7NJrpUczKObw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=arAZjL8Oj+0MnftXGof345T53okmD8nhVezUbk69sPIxt4C1FEVMYkxTfouSM9XOL ovbq76Fz0Np42Ru7DaJOa6OS92kyqWcVsNODi6ew8BGsMxd6gSW6IddyMDCKLAIoB0 WB4GUebHVt86nrRXW0/iH84SDPvdpPKOHfKi+l+i4xa+q1TOwl04DlmIlUNWDypK5j Ps7uKuGNDnrjRitghEeAW05w2+okzoRJY+vSW8KiNYP28TKOFe6tO3yYaUbg9B1bAk 35mGKr++PligrKw00VWNmLiufqeL+B/6xyKJIVitYPUIBKb1qvAtb/aC0qkTfrWgHH 7kyprtWDZm0tQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 5/7] perf annotate: Factor out __hist_entry__get_data_type() Date: Mon, 3 Mar 2025 09:38:05 -0800 Message-ID: <20250303173807.1765098-6-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" So that it can only handle a single disasm_linme and hopefully make the code simpler. This is also a preparation to be called from different places later. The NO_TYPE macro was added to distinguish when it failed or needs retry. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/annotate.c | 170 +++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 75 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 029e47a521caf1af..8a67340a64b94c39 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -87,6 +87,8 @@ struct annotated_data_type canary_type =3D { }, }; =20 +#define NO_TYPE ((struct annotated_data_type *)-1UL) + /* symbol histogram: key =3D offset << 16 | evsel->core.idx */ static size_t sym_hist_hash(long key, void *ctx __maybe_unused) { @@ -2649,6 +2651,92 @@ void debuginfo_cache__delete(void) di_cache.dbg =3D NULL; } =20 +static struct annotated_data_type * +__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, + struct debuginfo *dbg, struct disasm_line *dl, + int *type_offset) +{ + struct map_symbol *ms =3D &he->ms; + struct annotated_insn_loc loc; + struct annotated_op_loc *op_loc; + struct annotated_data_type *mem_type; + struct annotated_item_stat *istat; + int i; + + istat =3D annotate_data_stat(&ann_insn_stat, dl->ins.name); + if (istat =3D=3D NULL) { + ann_data_stat.no_insn++; + return NO_TYPE; + } + + if (annotate_get_insn_location(arch, dl, &loc) < 0) { + ann_data_stat.no_insn_ops++; + istat->bad++; + return NO_TYPE; + } + + if (is_stack_operation(arch, dl)) { + istat->good++; + *type_offset =3D 0; + return &stackop_type; + } + + for_each_insn_op_loc(&loc, i, op_loc) { + struct data_loc_info dloc =3D { + .arch =3D arch, + .thread =3D he->thread, + .ms =3D ms, + .ip =3D ms->sym->start + dl->al.offset, + .cpumode =3D he->cpumode, + .op =3D op_loc, + .di =3D dbg, + }; + + if (!op_loc->mem_ref && op_loc->segment =3D=3D INSN_SEG_NONE) + continue; + + /* PC-relative addressing */ + if (op_loc->reg1 =3D=3D DWARF_REG_PC) { + dloc.var_addr =3D annotate_calc_pcrel(ms, dloc.ip, + op_loc->offset, dl); + } + + /* This CPU access in kernel - pretend PC-relative addressing */ + if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") && + op_loc->segment =3D=3D INSN_SEG_X86_GS && op_loc->imm) { + dloc.var_addr =3D op_loc->offset; + op_loc->reg1 =3D DWARF_REG_PC; + } + + mem_type =3D find_data_type(&dloc); + + if (mem_type =3D=3D NULL && is_stack_canary(arch, op_loc)) { + istat->good++; + *type_offset =3D 0; + return &canary_type; + } + + if (mem_type) + istat->good++; + else + istat->bad++; + + if (symbol_conf.annotate_data_sample) { + struct evsel *evsel =3D hists_to_evsel(he->hists); + + annotated_data_type__update_samples(mem_type, evsel, + dloc.type_offset, + he->stat.nr_events, + he->stat.period); + } + *type_offset =3D dloc.type_offset; + return mem_type ?: NO_TYPE; + } + + /* retry with a fused instruction */ + return NULL; +} + /** * hist_entry__get_data_type - find data type for given hist entry * @he: hist entry @@ -2664,12 +2752,9 @@ struct annotated_data_type *hist_entry__get_data_typ= e(struct hist_entry *he) struct evsel *evsel =3D hists_to_evsel(he->hists); struct arch *arch; struct disasm_line *dl; - struct annotated_insn_loc loc; - struct annotated_op_loc *op_loc; struct annotated_data_type *mem_type; struct annotated_item_stat *istat; u64 ip =3D he->ip; - int i; =20 ann_data_stat.total++; =20 @@ -2721,77 +2806,10 @@ struct annotated_data_type *hist_entry__get_data_ty= pe(struct hist_entry *he) } =20 retry: - istat =3D annotate_data_stat(&ann_insn_stat, dl->ins.name); - if (istat =3D=3D NULL) { - ann_data_stat.no_insn++; - return NULL; - } - - if (annotate_get_insn_location(arch, dl, &loc) < 0) { - ann_data_stat.no_insn_ops++; - istat->bad++; - return NULL; - } - - if (is_stack_operation(arch, dl)) { - istat->good++; - he->mem_type_off =3D 0; - return &stackop_type; - } - - for_each_insn_op_loc(&loc, i, op_loc) { - struct data_loc_info dloc =3D { - .arch =3D arch, - .thread =3D he->thread, - .ms =3D ms, - /* Recalculate IP for LOCK prefix or insn fusion */ - .ip =3D ms->sym->start + dl->al.offset, - .cpumode =3D he->cpumode, - .op =3D op_loc, - .di =3D di_cache.dbg, - }; - - if (!op_loc->mem_ref && op_loc->segment =3D=3D INSN_SEG_NONE) - continue; - - /* Recalculate IP because of LOCK prefix or insn fusion */ - ip =3D ms->sym->start + dl->al.offset; - - /* PC-relative addressing */ - if (op_loc->reg1 =3D=3D DWARF_REG_PC) { - dloc.var_addr =3D annotate_calc_pcrel(ms, dloc.ip, - op_loc->offset, dl); - } - - /* This CPU access in kernel - pretend PC-relative addressing */ - if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") && - op_loc->segment =3D=3D INSN_SEG_X86_GS && op_loc->imm) { - dloc.var_addr =3D op_loc->offset; - op_loc->reg1 =3D DWARF_REG_PC; - } - - mem_type =3D find_data_type(&dloc); - - if (mem_type =3D=3D NULL && is_stack_canary(arch, op_loc)) { - istat->good++; - he->mem_type_off =3D 0; - return &canary_type; - } - - if (mem_type) - istat->good++; - else - istat->bad++; - - if (symbol_conf.annotate_data_sample) { - annotated_data_type__update_samples(mem_type, evsel, - dloc.type_offset, - he->stat.nr_events, - he->stat.period); - } - he->mem_type_off =3D dloc.type_offset; - return mem_type; - } + mem_type =3D __hist_entry__get_data_type(he, arch, di_cache.dbg, dl, + &he->mem_type_off); + if (mem_type) + return mem_type =3D=3D NO_TYPE ? NULL : mem_type; =20 /* * Some instructions can be fused and the actual memory access came @@ -2811,7 +2829,9 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) } =20 ann_data_stat.no_mem_ops++; - istat->bad++; + istat =3D annotate_data_stat(&ann_insn_stat, dl->ins.name); + if (istat) + istat->bad++; return NULL; } =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4C2423907E; Mon, 3 Mar 2025 17:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023491; cv=none; b=Yfjze8ZX1xTok9v9B1F/3JS/toRf0BChgMK7UUqbX5pWxyR3PT3jZlAgg3FxuCHstL1c+LmCuk+1s0qAsQPTOey/xNpskAmdj8ckT1+co1k9cfVRL2ZFlG4+VKnHH7ybdnGV6Xg2mmd24l4G02QtyhZJtN0/7wHCjSf9QuvKkWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023491; c=relaxed/simple; bh=famquw8nYkbZxiu+CNFHV8taHaNDrhKSZuh6JvxAAas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T4eRP4oF+8erpJ+nv0b6uorRPbGxKsMjB2gT85MHEnFigc9HC+0Yii0g4cEgHB7JDT/M+noU5cBa/YGZo+Ke8/y3icLsmC7zxxhvjQcevezbsmKwxq/ZOk5Cl9fdH9pOCfcrC9KUmVuDmx06+HIFwAS3DPkXfay/XOYCPmjU73s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bNPQER4Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bNPQER4Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E54E4C4CEE6; Mon, 3 Mar 2025 17:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023491; bh=famquw8nYkbZxiu+CNFHV8taHaNDrhKSZuh6JvxAAas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bNPQER4Yu064hP2ExPwZX8dUlj8Op3aYOXKPc22OYWMvHSKF0e5xKC83JXxw4FN5K WqklQRn0wfQqQkR5Tdfg64lyGTgaIS4HN2XfnUFy5ELYLEKfwsVBBVbcu0CZcongft cx+t/+iAm6g9LyLOfo8rz+sT67786ojmlyAOE1zaqsHu6XmS6/5OKuoUF12++B8nhV Cdp7h5YUposCFjQlPXtcJ06Ctj9cVCSfa0FgmCgpqUFujs8EAsDqKCBolK7vWRjUKm VhZK0hscCbUM/egtTmqoLCI7H2Dx0hkLNvy3wfUTU0J3NIUnz5UKct/AEcdFY3V6IY rbhX6B7oAFarQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 6/7] perf annotate: Implement code + data type annotation Date: Mon, 3 Mar 2025 09:38:06 -0800 Message-ID: <20250303173807.1765098-7-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sometimes it's useful to see both instructions and their data type together. Let's extend the annotate code to use data type profiling functions. To make it easy to pass more argument, introduce a struct to carry necessary information together. Also add a new annotation_option called 'code_with_type' to control the behavior. This is not enabled yet but it'll be set later from the command line. For simplicity, this is implemented for --stdio only. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/annotate.c | 73 ++++++++++++++++++++++++++++++-------- tools/perf/util/annotate.h | 1 + 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 8a67340a64b94c39..1e59b9e5339d393b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -760,11 +760,26 @@ static int disasm_line__print(struct disasm_line *dl,= u64 start, int addr_fmt_wi return 0; } =20 +static struct annotated_data_type * +__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, + struct debuginfo *dbg, struct disasm_line *dl, + int *type_offset); + +struct annotation_print_data { + struct hist_entry *he; + struct evsel *evsel; + struct arch *arch; + struct debuginfo *dbg; + u64 start; + int addr_fmt_width; +}; + static int -annotation_line__print(struct annotation_line *al, struct symbol *sym, u64= start, - struct evsel *evsel, struct annotation_options *opts, - int printed, struct annotation_line *queue, int addr_fmt_width) +annotation_line__print(struct annotation_line *al, struct annotation_print= _data *apd, + struct annotation_options *opts, int printed, + struct annotation_line *queue) { + struct symbol *sym =3D apd->he->ms.sym; struct disasm_line *dl =3D container_of(al, struct disasm_line, al); struct annotation *notes =3D symbol__annotation(sym); static const char *prev_line; @@ -804,10 +819,8 @@ annotation_line__print(struct annotation_line *al, str= uct symbol *sym, u64 start list_for_each_entry_from(queue, ¬es->src->source, node) { if (queue =3D=3D al) break; - annotation_line__print(queue, sym, start, evsel, - &queue_opts, /*printed=3D*/0, - /*queue=3D*/NULL, - addr_fmt_width); + annotation_line__print(queue, apd, &queue_opts, + /*printed=3D*/0, /*queue=3D*/NULL); } } =20 @@ -832,7 +845,31 @@ annotation_line__print(struct annotation_line *al, str= uct symbol *sym, u64 start =20 printf(" : "); =20 - disasm_line__print(dl, start, addr_fmt_width); + disasm_line__print(dl, apd->start, apd->addr_fmt_width); + + if (opts->code_with_type && apd->dbg) { + struct annotated_data_type *data_type; + int offset =3D 0; + + data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, + apd->dbg, dl, &offset); + if (data_type && data_type !=3D NO_TYPE) { + char buf[4096]; + + printf("\t\t# data-type: %s", + data_type->self.type_name); + + if (data_type !=3D &stackop_type && + data_type !=3D &canary_type) + printf(" +%#x", offset); + + if (annotated_data_type__get_member_name(data_type, + buf, + sizeof(buf), + offset)) + printf(" (%s)", buf); + } + } =20 /* * Also color the filename and line if needed, with @@ -858,7 +895,8 @@ annotation_line__print(struct annotation_line *al, stru= ct symbol *sym, u64 start if (!*al->line) printf(" %*s:\n", width, " "); else - printf(" %*s: %-*d %s\n", width, " ", addr_fmt_width, al->line_nr, al->= line); + printf(" %*s: %-*d %s\n", width, " ", apd->addr_fmt_width, + al->line_nr, al->line); } =20 return 0; @@ -1189,8 +1227,12 @@ int hist_entry__annotate_printf(struct hist_entry *h= e, struct evsel *evsel) struct sym_hist *h =3D annotation__histogram(notes, evsel); struct annotation_line *pos, *queue =3D NULL; struct annotation_options *opts =3D &annotate_opts; - u64 start =3D map__rip_2objdump(map, sym->start); - int printed =3D 2, queue_len =3D 0, addr_fmt_width; + struct annotation_print_data apd =3D { + .he =3D he, + .evsel =3D evsel, + .start =3D map__rip_2objdump(map, sym->start), + }; + int printed =3D 2, queue_len =3D 0; int more =3D 0; bool context =3D opts->context; int width =3D annotation__pcnt_width(notes); @@ -1224,7 +1266,10 @@ int hist_entry__annotate_printf(struct hist_entry *h= e, struct evsel *evsel) if (verbose > 0) symbol__annotate_hits(sym, evsel); =20 - addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->source, = start); + apd.addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->sour= ce, + apd.start); + evsel__get_arch(evsel, &apd.arch); + apd.dbg =3D debuginfo__new(filename); =20 list_for_each_entry(pos, ¬es->src->source, node) { int err; @@ -1234,8 +1279,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) queue_len =3D 0; } =20 - err =3D annotation_line__print(pos, sym, start, evsel, - opts, printed, queue, addr_fmt_width); + err =3D annotation_line__print(pos, &apd, opts, printed, queue); =20 switch (err) { case 0: @@ -1266,6 +1310,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) } } =20 + debuginfo__delete(apd.dbg); free(filename); =20 return more; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 4fba7cde4968db74..03a7cc24058ff5a2 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -55,6 +55,7 @@ struct annotation_options { show_asm_raw, show_br_cntr, annotate_src, + code_with_type, full_addr; u8 offset_level; u8 disassemblers[MAX_DISASSEMBLERS]; --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:37:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A1632397AA; Mon, 3 Mar 2025 17:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023492; cv=none; b=dI+HQkx/vycmTOJTHZGdQ27FMZfwTDKLswxtTPyn4nUtbp2LkoLicCV0SajTM9D6OShS2ZAY9YZazjyo19G2OU5zRKJ7NdaCUgY93tLNODtTfl/PcVkVmzcdclkjSUEK1sz3EjoZ7V+efOrt+UuJDMgWdSMUQSB0R+5DnmmNqZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741023492; c=relaxed/simple; bh=zvJuD9IQBZxuLiwJIKQJHoFj6naa/SXfsleK9VlqYZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e1aWL7UAcLhikFdEB1j9L8+ToLr8JsHgqGaSdSLy74cWEzL5Ffi4dM7bB+KkWrxe4su8wnxm6GyxIb4bSE4Tzw22abZxSQ10PHgs3+G7O9twOnNLGui7ZEb545PC78DQFOLFKc4XoKt/5wF3LSYBCbFgQhuUpHEdMahbCVeCwrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m3imuJU5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m3imuJU5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B017C4CEEA; Mon, 3 Mar 2025 17:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741023491; bh=zvJuD9IQBZxuLiwJIKQJHoFj6naa/SXfsleK9VlqYZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3imuJU5lltIyd6z0maI7yQaoD2/qW0nDgyRmPIz7tHsWA/gaXxtZsmnC4fHWNqKg Sg9D3QOZ0kDpMxV1ZbMJMqw2lwUAwaOasxhcOXwJdThL0Gt0BF+Jg+3g/Z2v9+9sHM kjQLq8D0CmTBTnc4r9ftUhchr+hDJZiUmFvWXs10h23WRlpobdY/2uX1ldCoFlZwrT dekCO96Cd2BYjteMWb5N/jVLynEt16DdmiFS4UVV1fyPape2900tPUevIgRYWz+wsD zHRMk3vtwrvqMZSPJGGmwoybewCbpehe2beNuF+dL3RUNUrN00pVOdRDGDQaT0TqRi 8sw45kFaC4ovw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 7/7] perf annotate: Add --code-with-type option. Date: Mon, 3 Mar 2025 09:38:07 -0800 Message-ID: <20250303173807.1765098-8-namhyung@kernel.org> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog In-Reply-To: <20250303173807.1765098-1-namhyung@kernel.org> References: <20250303173807.1765098-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This option is to show data type info in the regular (code) annotation. It tries to find data type for each (memory) instruction in the function. It'd be useful to see function-level memory access pattern and also to debug the data type profiling result. The output would be added at the end of the line and have "# data-type:" prefix. For now, it only works with --stdio mode for simplicity. I can work on enabling it for TUI later. $ perf annotate --stdio --code-with-type Percent | Source code & Disassembly of vmlinux for cpu/mem-loads/pp= k (253 samples, percent: local period) -------------------------------------------------------------------------= -------------------------------------- : 0 0xffffffff81baa000 : 0.00 : ffffffff81baa000: pushq %r12 # data-ty= pe: (stack operation) 0.00 : ffffffff81baa002: pushq %rbp # data-ty= pe: (stack operation) 0.00 : ffffffff81baa003: pushq %rbx # data-ty= pe: (stack operation) 0.00 : ffffffff81baa004: subq $0x8, %rsp 18.00 : ffffffff81baa008: movl %gs:0x7e48893d(%rip), %ebx = # 0x3294c # data-type: struct pcpu_hot +0xc (c= pu_number) 12.58 : ffffffff81baa00f: movl %gs:0x7e488932(%rip), %eax = # 0x32948 # data-type: struct pcpu_hot +0x8 (p= reempt_count) 0.00 : ffffffff81baa016: testl $0x7fffffff, %eax 0.00 : ffffffff81baa01b: je 0xffffffff81baa02c 0.00 : ffffffff81baa01d: addq $0x8, %rsp 0.00 : ffffffff81baa021: movl %ebx, %eax 14.19 : ffffffff81baa023: popq %rbx # data-ty= pe: (stack operation) 18.86 : ffffffff81baa024: popq %rbp # data-ty= pe: (stack operation) 12.10 : ffffffff81baa025: popq %r12 # data-ty= pe: (stack operation) 17.78 : ffffffff81baa027: jmp 0xffffffff81bc1170 <__x86_r= eturn_thunk> 6.49 : ffffffff81baa02c: callq *0xc9139e(%rip) # 0xffffff= ff8283b3d0 # data-type: (stack operation) 0.00 : ffffffff81baa032: testb $0x2, %ah 0.00 : ffffffff81baa035: je 0xffffffff81baa01d 0.00 : ffffffff81baa037: movq %rdi, %rbp 0.00 : ffffffff81baa03a: movq %gs:0x32940, %rax #= data-type: struct pcpu_hot +0 (current_task) 0.00 : ffffffff81baa043: testb $0x4, 0x2f(%rax) #= data-type: struct task_struct +0x2f (flags) 0.00 : ffffffff81baa047: je 0xffffffff81baa052 0.00 : ffffffff81baa049: cmpl $0x1, 0x3d0(%rax) #= data-type: struct task_struct +0x3d0 (nr_cpus_allowed) 0.00 : ffffffff81baa050: je 0xffffffff81baa01d 0.00 : ffffffff81baa052: movq %gs:0x32940, %r12 #= data-type: struct pcpu_hot +0 (current_task) 0.00 : ffffffff81baa05b: cmpw $0x0, 0x7f0(%r12) #= data-type: struct task_struct +0x7f0 (migration_disabled) 0.00 : ffffffff81baa065: movq %rsi, (%rsp) 0.00 : ffffffff81baa069: jne 0xffffffff81baa01d 0.00 : ffffffff81baa06b: movl 0xe8dd13(%rip), %eax # 0xf= fffffff82a37d84 # data-type: enum system_states +0 0.00 : ffffffff81baa071: testl %eax, %eax 0.00 : ffffffff81baa073: je 0xffffffff81baa01d 0.00 : ffffffff81baa075: incl %gs:0x7e4888cc(%rip) # 0x3= 2948 # data-type: struct pcpu_hot +0x8 (preempt_c= ount) 0.00 : ffffffff81baa07c: movq $-0x7e14a100, %rdi 0.00 : ffffffff81baa083: callq 0xffffffff81148c40 <__print= k_ratelimit> # data-type: (stack operation) 0.00 : ffffffff81baa088: testl %eax, %eax 0.00 : ffffffff81baa08a: je 0xffffffff81baa0d5 0.00 : ffffffff81baa08c: movl 0x958(%r12), %r9d #= data-type: struct task_struct +0x958 (pid) 0.00 : ffffffff81baa094: movq (%rsp), %rdx #= data-type: char* +0 0.00 : ffffffff81baa098: movq %rbp, %rsi 0.00 : ffffffff81baa09b: leaq 0xb88(%r12), %r8 #= data-type: struct task_struct +0xb88 (comm) 0.00 : ffffffff81baa0a3: movl %gs:0x7e48889e(%rip), %ecx = # 0x32948 # data-type: struct pcpu_hot +0x8 (p= reempt_count) 0.00 : ffffffff81baa0aa: andl $0x7fffffff, %ecx 0.00 : ffffffff81baa0b0: movq $-0x7dd3cdf0, %rdi 0.00 : ffffffff81baa0b7: subl $0x1, %ecx 0.00 : ffffffff81baa0ba: callq 0xffffffff81149340 <_printk= > # data-type: (stack operation) 0.00 : ffffffff81baa0bf: movq 0x20(%rsp), %rsi 0.00 : ffffffff81baa0c4: movq $-0x7ddb8c7e, %rdi 0.00 : ffffffff81baa0cb: callq 0xffffffff81149340 <_printk= > # data-type: (stack operation) 0.00 : ffffffff81baa0d0: callq 0xffffffff81b7ab60 # data-type: (stack operation) 0.00 : ffffffff81baa0d5: decl %gs:0x7e48886c(%rip) # 0x3= 2948 # data-type: struct pcpu_hot +0x8 (preempt_c= ount) 0.00 : ffffffff81baa0dc: jmp 0xffffffff81baa01d Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/Documentation/perf-annotate.txt | 4 ++++ tools/perf/builtin-annotate.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Docume= ntation/perf-annotate.txt index 156c5f37b05141ca..46090c5b42b4762f 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt @@ -168,6 +168,10 @@ include::itrace.txt[] --skip-empty:: Do not display empty (or dummy) events. =20 +--code-with-type:: + Show data type info in code annotation (for memory instructions only). + Currently it only works with --stdio option. + =20 SEE ALSO -------- diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 966950c38306d6ea..9833c2c82a2fee46 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -788,6 +788,8 @@ int cmd_annotate(int argc, const char **argv) "Show instruction stats for the data type annotation"), OPT_BOOLEAN(0, "skip-empty", &symbol_conf.skip_empty, "Do not display empty (or dummy) events in the output"), + OPT_BOOLEAN(0, "code-with-type", &annotate_opts.code_with_type, + "Show data type info in code annotation (memory instructions only)"), OPT_END() }; int ret; @@ -913,6 +915,13 @@ int cmd_annotate(int argc, const char **argv) annotate_opts.annotate_src =3D false; symbol_conf.annotate_data_member =3D true; symbol_conf.annotate_data_sample =3D true; + } else if (annotate_opts.code_with_type) { + symbol_conf.annotate_data_member =3D true; + + if (!annotate.use_stdio) { + pr_err("--code-with-type only works with --stdio.\n"); + goto out_delete; + } } =20 setup_browser(true); --=20 2.48.1.711.g2feabab25a-goog