From: Namhyung Kim <namhyung@kernel.org>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
leo.yan@linux.dev, Li Huafei <lihuafei1@huawei.com>,
Ian Rogers <irogers@google.com>,
Kim Phillips <kim.phillips@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Bill Wendling <morbo@google.com>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Zecheng Li <zli94@ncsu.edu>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH v2 04/16] perf annotate-arm64: Handle load and store instructions
Date: Tue, 7 Apr 2026 00:09:18 -0700 [thread overview]
Message-ID: <adStnrfA6IxkOfRN@z2> (raw)
In-Reply-To: <20260403094800.1418825-5-wutengda@huaweicloud.com>
On Fri, Apr 03, 2026 at 09:47:48AM +0000, Tengda Wu wrote:
> Add ldst_ops to handle load and store instructions in order to parse
> the data types and offsets associated with PMU events for memory access
> instructions. There are many variants of load and store instructions in
> ARM64, making it difficult to match all of these instruction names
> completely. Therefore, only the instruction prefixes are matched. The
> prefix 'ld|st' covers most of the memory access instructions, 'cas|swp'
> matches atomic instructions, and 'prf' matches memory prefetch
> instructions.
>
> Signed-off-by: Li Huafei <lihuafei1@huawei.com>
> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
> ---
> .../perf/util/annotate-arch/annotate-arm64.c | 72 +++++++++++++++++++
> 1 file changed, 72 insertions(+)
>
> diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/util/annotate-arch/annotate-arm64.c
> index 4c42323b0c18..8209faaa6086 100644
> --- a/tools/perf/util/annotate-arch/annotate-arm64.c
> +++ b/tools/perf/util/annotate-arch/annotate-arm64.c
> @@ -3,7 +3,9 @@
> #include <errno.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <ctype.h>
> #include <linux/zalloc.h>
> +#include <linux/string.h>
> #include <regex.h>
> #include "../annotate.h"
> #include "../disasm.h"
> @@ -12,6 +14,7 @@ struct arch_arm64 {
> struct arch arch;
> regex_t call_insn;
> regex_t jump_insn;
> + regex_t ldst_insn; /* load and store instruction */
> };
>
> static bool arm64__check_multi_regs(const char *op)
> @@ -114,6 +117,59 @@ static const struct ins_ops arm64_mov_ops = {
> .scnprintf = mov__scnprintf,
> };
>
> +static int arm64_ldst__parse(const struct arch *arch __maybe_unused,
The 'arch' is used. :)
> + struct ins_operands *ops,
> + struct map_symbol *ms __maybe_unused,
> + struct disasm_line *dl __maybe_unused)
> +{
> + char *s, *target;
> +
> + /*
> + * The part starting from the memory access annotation '[' is parsed
> + * as 'target', while the part before it is parsed as 'source'.
It'd be nice if you can show some examples. So it always looks like:
LDR x1, [x2, #4]
STR x1, [x3], #8
Right? What about other instructions?
> + */
> + target = s = strchr(ops->raw, arch->objdump.memory_ref_char);
> + if (!s)
> + return -1;
> +
> + while (s > ops->raw && *s != ',')
> + --s;
> +
> + if (s == ops->raw)
> + return -1;
> +
> + *s = '\0';
> + ops->source.raw = strdup(ops->raw);
> +
> + *s = ',';
> + if (!ops->source.raw)
> + return -1;
> +
> + ops->source.multi_regs = arm64__check_multi_regs(ops->source.raw);
Probably it's better to set ops->source.mem_ref to false. Then you
won't need to set multi_regs.
Thanks,
Namhyung
> +
> + ops->target.raw = strdup(target);
> + if (!ops->target.raw) {
> + zfree(&ops->source.raw);
> + return -1;
> + }
> + ops->target.mem_ref = true;
> + ops->target.multi_regs = arm64__check_multi_regs(ops->target.raw);
> +
> + return 0;
> +}
> +
> +static int arm64_ldst__scnprintf(const struct ins *ins, char *bf, size_t size,
> + struct ins_operands *ops, int max_ins_name)
> +{
> + return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name,
> + ops->source.raw, ops->target.raw);
> +}
> +
> +static struct ins_ops arm64_ldst_ops = {
> + .parse = arm64_ldst__parse,
> + .scnprintf = arm64_ldst__scnprintf,
> +};
> +
> static const struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
> {
> struct arch_arm64 *arm = container_of(arch, struct arch_arm64, arch);
> @@ -124,6 +180,8 @@ static const struct ins_ops *arm64__associate_instruction_ops(struct arch *arch,
> ops = &jump_ops;
> else if (!regexec(&arm->call_insn, name, 2, match, 0))
> ops = &call_ops;
> + else if (!regexec(&arm->ldst_insn, name, 2, match, 0))
> + ops = &arm64_ldst_ops;
> else if (!strcmp(name, "ret"))
> ops = &ret_ops;
> else
> @@ -148,6 +206,8 @@ const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id,
> arch->id = *id;
> arch->objdump.comment_char = '/';
> arch->objdump.skip_functions_char = '+';
> + arch->objdump.memory_ref_char = '[';
> + arch->objdump.imm_char = '#';
> arch->associate_instruction_ops = arm64__associate_instruction_ops;
>
> /* bl, blr */
> @@ -161,8 +221,20 @@ const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id,
> if (err)
> goto out_free_call;
>
> + /*
> + * The ARM64 architecture has many variants of load/store instructions.
> + * It is quite challenging to match all of them completely. Here, we
> + * only match the prefixes of these instructions.
> + */
> + err = regcomp(&arm->ldst_insn, "^(ld|st|cas|prf|swp)",
> + REG_EXTENDED);
> + if (err)
> + goto out_free_jump;
> +
> return arch;
>
> +out_free_jump:
> + regfree(&arm->jump_insn);
> out_free_call:
> regfree(&arm->call_insn);
> out_free_arm:
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-04-07 7:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 9:47 [PATCH v2 00/16] perf arm64: Support data type profiling Tengda Wu
2026-04-03 9:47 ` [PATCH v2 01/16] perf llvm: Fix arm64 adrp instruction disassembly mismatch with objdump Tengda Wu
2026-04-03 9:47 ` [PATCH v2 02/16] perf capstone: Fix arm64 jump/adrp " Tengda Wu
2026-04-07 6:43 ` Namhyung Kim
2026-04-03 9:47 ` [PATCH v2 03/16] perf annotate-arm64: Generalize arm64_mov__parse to support standard operands Tengda Wu
2026-04-07 6:58 ` Namhyung Kim
2026-04-03 9:47 ` [PATCH v2 04/16] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-04-07 7:09 ` Namhyung Kim [this message]
2026-04-03 9:47 ` [PATCH v2 05/16] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-04-03 9:47 ` [PATCH v2 06/16] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-04-03 9:47 ` [PATCH v2 07/16] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-04-07 7:26 ` Namhyung Kim
2026-04-03 9:47 ` [PATCH v2 08/16] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-04-03 9:47 ` [PATCH v2 09/16] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-04-03 9:47 ` [PATCH v2 10/16] perf annotate-arm64: Support store " Tengda Wu
2026-04-03 9:47 ` [PATCH v2 11/16] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-04-03 9:47 ` [PATCH v2 12/16] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-04-03 9:47 ` [PATCH v2 13/16] perf annotate-arm64: Support 'add' " Tengda Wu
2026-04-03 9:47 ` [PATCH v2 14/16] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-04-03 9:47 ` [PATCH v2 15/16] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-04-03 9:48 ` [PATCH v2 16/16] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-04-07 6:31 ` [PATCH v2 00/16] perf arm64: Support data type profiling Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adStnrfA6IxkOfRN@z2 \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=kim.phillips@arm.com \
--cc=leo.yan@linux.dev \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=wutengda@huaweicloud.com \
--cc=zli94@ncsu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox