From nobody Fri Dec 19 06:39:15 2025 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 9932A1EB5F9; Mon, 10 Mar 2025 22:49:27 +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=1741646967; cv=none; b=JtWBghp1f5cu8OBy7szXYzIkEa8Awzz/kIJIqWUiDA3V/MLC5xlyVS45IYBUAnZBihH3NBoFDcC7ncq2yb+ShjdO/JLy0p4Js0918ZQrcRgAgp4vjkmc3XGlcpj/G7PeHkm59rP2xlUCr66qOVz+5tm9ok0ulhRLzYA2T5wBhfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646967; c=relaxed/simple; bh=LyTo7sFjnogmd09szBPpG47+nMOqHTi8i38MCphK5zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rx5SVbPb2NmNApvgQHdJVcXIYrgl8GNzEK+kl8a9H0pH/Gx2PR/uD3ligSRrJGXMqqenqRkTtcQxH31NUIa1dVyxqvOD6NR+4HVVHhUv2Zw9RUmiK1HQfUSi/2yjLV4AkQDWDpAH54gQRGX3M6eVNwV/Mb4JCBfPqfZzN+xPEic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i7bt1CAV; 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="i7bt1CAV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0F42C4CEEA; Mon, 10 Mar 2025 22:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646967; bh=LyTo7sFjnogmd09szBPpG47+nMOqHTi8i38MCphK5zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i7bt1CAVIcnTclypz5WXR70I6FWAZweVJBk0jJcoJInqwtaApCH6VM0w9JYOfbGZY IyJYnDkdpMFXaVVKJFGDWB1OfvFKISv8XIrJdJCutpUMS4J6cLIwehDLwzxjOA0tay 05kWQ4dFDG7tfZ/lRZ0s0V/0rKIeKG5kU1Hsih3VTC/hauczESMTrjqqH8ggyuVyqq hUqQdYtHC6GZHWlIjO/giuJsnECj9NxomydMSwh3SzOkeZKUwqUiRn1siv/0IQOWDw 7orQfy0wBdJc6Nf0nZ8zwE8EtKMo8PYYPZwsGuaPg2Tijz04t0PVMKw66aGzNzRGqB goss0WhiWfQpA== 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 v2 1/7] perf annotate-data: Add annotated_data_type__get_member_name() Date: Mon, 10 Mar 2025 15:49:19 -0700 Message-ID: <20250310224925.799005-2-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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)" Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 34 ++++++++++++++++++++++++++++ tools/perf/util/annotate-data.h | 13 +++++++++++ tools/perf/util/sort.c | 39 ++++++--------------------------- 3 files changed, 54 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..541fee1a5f0a7af2 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -227,8 +227,13 @@ void annotated_data_type__tree_delete(struct rb_root *= root); /* Release all global variable information in the tree */ void global_var_type__tree_delete(struct rb_root *root); =20 +/* Print data type annotation (including members) on stdout */ int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el); =20 +/* Get name of member field at the given offset in the data type */ +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, @@ -276,6 +281,14 @@ static inline int hist_entry__annotate_data_tty(struct= hist_entry *he __maybe_un return -1; } =20 +static inline int annotated_data_type__get_member_name(struct annotated_da= ta_type *adt __maybe_unused, + char *buf __maybe_unused, + size_t sz __maybe_unused, + int member_offset __maybe_unused) +{ + return -1; +} + #endif /* HAVE_LIBDW_SUPPORT */ =20 #ifdef HAVE_SLANG_SUPPORT 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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 BBAC51EE029; Mon, 10 Mar 2025 22:49:27 +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=1741646967; cv=none; b=D2NaH5riHS1bUwAN5n7yTe/S7mwpq2NtTB1CFaoHk7AaZGL8MNVr37gtiJb/DIhwcyA79pEdjr53fqE6+cm1ZQs6PCNRHiD0n+ziSnIz6GX+FGRe4lUc11+Q5tlCh6XX0Q2rV1t61WVzo5oYTt3ZMdg+v+OwCRagiyZSbwXBm+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646967; c=relaxed/simple; bh=vjxhXZObDe/YGwl7C2BasihkJhsbIAq/zZ7sz4JcQp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uD1JATG2eyyR3qY4qjMXzGs2ssrhQTBXlYvd0xAuV+GHessa1i+U9Yd51LS2vWyjlcYecOnEhruErbAmySDLf8NJeBpAi1JKfEoM7x+Vz2y5u/3K1X4x7Oe+eWZA/g2deIgWm8iP/OuomPdGIP0w/ur4dLgTOFeZpfnkgd1BROk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sffrUcAb; 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="sffrUcAb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB59C4CEEF; Mon, 10 Mar 2025 22:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646967; bh=vjxhXZObDe/YGwl7C2BasihkJhsbIAq/zZ7sz4JcQp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sffrUcAbIGzVjO+aAJZave71WeFm8bAdWZ/QVR36wwb4w2MJQ3PFsqSdf8qGzfUp1 NwcuQp5Mie8kYJTNND0R8KZcIxonY8pBKG6VITWhUo34iqIc1AJf0cGbYgX3kp3Z4W FMJOTrKQPToRtl9ZlQA26fS4Pvy8eAI11JbB9SpIoBJJwKeXakPDryi+KYI6LU6sCk w1jwFzk7G1c5qrxhM6yRLMh8+/ICyWI4Mpmqw6/8brG1XTb20wVVOwSxZ6ZKrlV3LG mLt6biR33nMGmtzLAD71Ex/JfUVJRtM1C8lPLUI1s6fV52eeVs/7+CUFjTUYFxgglv Zky4JZGy1aVhA== 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 v2 2/7] perf annotate: Remove unused len parameter from annotation_line__print() Date: Mon, 10 Mar 2025 15:49:20 -0700 Message-ID: <20250310224925.799005-3-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 ACE4B2144AE; Mon, 10 Mar 2025 22:49:28 +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=1741646968; cv=none; b=Jb3JUF7Oyo9ctBPS09v0YjO5mvjkSsNzkmxH8kq4od422bo8qtDu7wWzOeaZO3HGrTFyygdKVuO+Yb2ABtdEKGGjtPYboabiH43XY0J13bIUd+0LDDLt34bgtC4/SfuxTmzqHISZMxugiZvPs8wbvxLXrtv03XHkFG7N2j5xCpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646968; c=relaxed/simple; bh=1nZKc+HMzsTs1mIFuu7S1fF5pLgo23yrQCVk/XD/6nM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+2DVm0GE8Ib1W39S2ep0c7TCnNPXpkcWcZaFSOqQPotT8W234acCRvs8YT9CpaKtj1qCLb8cXYy1LpjFPOVRXKkS3YpEWFnO3wBGomieadnB2GV1JyMXCbvOnxz3HgqbzAP56FeLhhiIOZ3kc/pz0/2IPEvHQguQDqymezuGjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A0PHWdKU; 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="A0PHWdKU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDB5AC4CEEA; Mon, 10 Mar 2025 22:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646968; bh=1nZKc+HMzsTs1mIFuu7S1fF5pLgo23yrQCVk/XD/6nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0PHWdKUdBuU+jLgMQFbOYy/x5YvhYqQUzjE/j6GGHgNTcGcxj8mBx26GwrBsGDcP HmEfKd8oIy4kSfF1+R2/wrQGTxs91aVlll8xtmBC6GRdddRqgrqL+zgpS4vvIQdVkf CP3wc1hK/BvE9Beak0fMy82Bm+x1PCPOkUf59THxvxfG8RPQNPjT/7a3iTUxv3I/NI cwAJZxIv7Umk8mVjjNRK4Y9Mh9W3RVAFvutRFNA1kYfbDKXDN6quslrbRd7TlAKe4s IggrEjhvoX0sEgvJDoO/fDicx2Zfh1XOsNLLqMkC+leWopj2qIsjgvFaIiMnRFfpCZ Z/ddQTuHipYRw== 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 v2 3/7] perf annotate: Pass annotation_options to annotation_line__print() Date: Mon, 10 Mar 2025 15:49:21 -0700 Message-ID: <20250310224925.799005-4-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 1E7AC21ADCC; Mon, 10 Mar 2025 22:49:28 +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=1741646969; cv=none; b=HTYkEpVZz97lNjGAA/g6sswBRgwujA+wUaHbe7Qzsg8qCLgsIGqml7cU/AkRnufVS6ljxkfjMjMtfnw/ZchdvUaqO7uBkxeFAvJ1c80r+9aROkCFWo9Vejet4tBXuZy9i4NMXxAWbKScf58Nu3i3Fpve4QGSERRFtXWwt1F3wcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646969; c=relaxed/simple; bh=M3HsrNuURILy6ovhYItEkb433ba3Fj/afsxb5W1iB3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SdIFPOkvBy6JsCt2D3bsgGvEJKUOfVmOP+ALzXy2wr4zEwFjVImwYYM0jexhkjVeet3FRIp4kc8WpjQXlQVj05LXVxE2QLyve0nk1Lz3XXGbmG3m971V6zgYHwzKzlVVc6Y6uHZ1+lKMO6nTItnKyabLdefnz95FIEN47WRHRhI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h95WlioU; 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="h95WlioU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48C5BC4CEED; Mon, 10 Mar 2025 22:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646968; bh=M3HsrNuURILy6ovhYItEkb433ba3Fj/afsxb5W1iB3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h95WlioUBkwWrUpY/aSqcxMJQvxLhy2CusrjV5V6PgUUSmpxrbM2VhkUOMleLQHPh ox9LsD+0Bb5+HSdCpmUHN7bM9xtNHDK802xd4V3yZZ6jlwoPTmTRwBv8PDRfUXJJaQ HEjGKoxyquwbAbyDKzNx00+kB185zWFFgJxSzRc5IW6QeKNWDquwMm3LEQeljMiknY JVoCeRu5rv9nzvAN03IZJ690rSICJ6gmiVnnsRblzXjLIDJGW+KPu64ZKmNkvtbHnP A/i9SWThXbpX5bMtM1Fk9IuXtq7LTJJhs3DZdwBrN3B2EqJ809M/k+OyHcoz1a64NC EN0VpL0eOmmww== 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 v2 4/7] perf annotate: Pass hist_entry to annotate functions Date: Mon, 10 Mar 2025 15:49:22 -0700 Message-ID: <20250310224925.799005-5-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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 2c41d3aea46b204b..1061f4eebc3f6414 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 30a344afd91a5865..4eda409bfe0ea859 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -456,7 +456,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); @@ -465,9 +464,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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 B6BC422171E; Mon, 10 Mar 2025 22:49:29 +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=1741646969; cv=none; b=sPlmU2fgMgGpdZf8cqSjghuhDeekuQRDGM7+pvATm55s/v/j48Qv0PIlPYNOYx624SMsxfVCMM50/DUPJ1NdfnrRaTIQVysxsK5YhAfWs/ADEkFGBVWJI/RXp2+g7YfCZYURWRlV8BXI7WnsO36/CpaaQRR8bvqJ6u+p0F+nMvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646969; c=relaxed/simple; bh=yC3jyht6Qf2EHmpXnSyTmnCZv5pR8We4zv+2ttrDcVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bK91RjawxDnzzrbGWcnHEMvAHu4bmVhJLin6shDMYHowya5dZA1t1ns2djwTKbObDI/bt1XeYERo0UAN9MCKml2RAewoCdFCWAMRuPecvomExIHxm0Q7MoJVsOkOi3er0eJKTYPDyVRMwMwUtoY7PVBKJpo45sDu8fJK+0xk1q4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kgelEORX; 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="kgelEORX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE498C4AF09; Mon, 10 Mar 2025 22:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646969; bh=yC3jyht6Qf2EHmpXnSyTmnCZv5pR8We4zv+2ttrDcVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgelEORXqSg58sokwIt+cRtzDHeY91JYQcxs6+C0+Cm9ok8O2fAJAJbdNi1sHrHJU n9FlESvUxGHgwI9tjlWNm9IciBTLLaP8aI0XBbPNSmPF3TSiXIGEq8ysoxxvvlJwWa 3Srb7EkymDxs4MkgjNaUgPYs+mhTz6HLzHb7H9AliU1TR1bbvaGHOyhkOBVJTjygyf f2UI23eyI0epB4YXgVYo9K7HlNORZaoXxbQ13Esjd3cRojAry1ciZK9ZcE+DMte9Dk 0Ezr5rqn4PBMaLQSP0e6QmURIVka6GXKNil99z4MUbNBMVOx5PubPDxirt2PGB3XX8 WBhmcM+8GZy9w== 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 v2 5/7] perf annotate: Factor out __hist_entry__get_data_type() Date: Mon, 10 Mar 2025 15:49:23 -0700 Message-ID: <20250310224925.799005-6-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 DA86A22173D; Mon, 10 Mar 2025 22:49:29 +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=1741646969; cv=none; b=d0IZs34fXRNMePmjBa38KjC3OjUhab+eU927y5KpeiJitt+P4ctGg47bYUtqWLZ9m6Qb8piqDkFklnIqZAWZJxsFTTvqlWkNRFqhzfROgI/FZg2yeHCN7GQER1OAhQjiJBdY88lH35nD/GL2gvXA0HIBN6JD0ebV9cQyfcRaiCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646969; c=relaxed/simple; bh=rRoUd6tc+/G0sMXTFIDgeSq+7nNRMG/V3IoW7k2ManE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PEy4HO2L6CgLIsHYh0DwrDuWBUXAmxpCKxUHkCvdJr4vGjiPSYfcH8xEe9299v9o8yx9uDQm9L29eslQsK5/gt3JC9AI1A6FpLtdlZO6gLT8CVJgBIbMAIPRKRxgAemvwhn2xgkfzFMuBZbyiW2kn8JbpZmKvWDqUdhqBU9Pn4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OvCJe8pI; 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="OvCJe8pI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DE30C4CEF0; Mon, 10 Mar 2025 22:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646969; bh=rRoUd6tc+/G0sMXTFIDgeSq+7nNRMG/V3IoW7k2ManE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvCJe8pIUPR4S3D/LNQorA/J794pAOGM2SCddU7yM24EjIRXQNXbILoLhoxCn+XbW T5EAGw95ya1MaIfdoYoL56VEkWqI9sQOdTwkONmyHAufnRD4rJ1pHLPSiFTI2ATQVk uII26XjUvu2CG6ZFWaWyKdICpZyQsGbzfRncA0Ao1a28kJwwqjLvxpJkW3yrXA1QqZ dIB4UPPQOqIt0nJrcENk71eJnoLmjR4bUKT1N+MdqWE3ZB/0y6ruXLDQM0+gGOEZSn urNc25H+rNXTP9OsJokLnGqkgQqmbfH42c7pgKRX6hBvuC8MBhAvGPBt/kgzYszzJR s8mGLw+ptnIIQ== 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 v2 6/7] perf annotate: Implement code + data type annotation Date: Mon, 10 Mar 2025 15:49:24 -0700 Message-ID: <20250310224925.799005-7-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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 4eda409bfe0ea859..0e6e3f60a897b850 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.49.0.rc0.332.g42c0ae87b1-goog From nobody Fri Dec 19 06:39:15 2025 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 CAD912222B6; Mon, 10 Mar 2025 22:49:30 +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=1741646970; cv=none; b=C3kVRIdSYJFV6qJAw4cQ+/fRc0bKTg0jrTrcJjBrh5SrcjP7gCDSTsKyb4BZGyq6SvY9wpomZrOZ3UmA5hx+0x9WR8VFk+1vYQHRnSN1QPVxoVOUrCwypuRMya9BLIVRnOrY9mMSWW/6cMQfuZA+Ok76LvoUa9ZHoXues9dIO1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741646970; c=relaxed/simple; bh=HNvlfHR0V2pVFGt4EwvjDo5lzoBJpIAbkVn4yuVk7c8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HjoFODkkgV95654lV/maKFHT4ogjl7Xm1mQl6HfzgfyQSx+Uro8fWz/2QMZw+Hd+52nMIQwuLPbNks9yHpAfcGgoBKg+5GiULitF0nNplPzLn9I1HT4ptmUtdwn7cnsZkXkdVnXTNb2qTAByTFXfTidx+V2Bi7di3SDMUP2JjJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mFkVjW+E; 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="mFkVjW+E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1450C4CEE5; Mon, 10 Mar 2025 22:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741646970; bh=HNvlfHR0V2pVFGt4EwvjDo5lzoBJpIAbkVn4yuVk7c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mFkVjW+EUyIibem3KxbHb4Y3ynTsDQrVjImpYrIc/rnu0hzNMifxAvd2hUK0jE4uu QsQoV2hYJCfddWygWbz+MDL1Sln6lIfGIONjqrT7N5GcPfQysxvo9f+js/VvXtQ9Zt yT2TKICOQFXGB6HSYQUEO6sD7AJxFIwYy+4XloKdXjhy6E1ab8Ejw0DT0jR77fyjNl Rp+DLaJD0A9HsIFUaFLqTg90lv0WqjhRoqBlLMZ63ml8wfTZS8fA6lKNTi45pX0O6b CyqB7eE5zbOH7AcgRpejSt2BybXDjqLSPftMMgLbP7FglJk7/eu+q0Y4iE4o3tvVyL r+bFx7/8d1uYQ== 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 v2 7/7] perf annotate: Add --code-with-type option. Date: Mon, 10 Mar 2025 15:49:25 -0700 Message-ID: <20250310224925.799005-8-namhyung@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250310224925.799005-1-namhyung@kernel.org> References: <20250310224925.799005-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 Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- 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.49.0.rc0.332.g42c0ae87b1-goog