From: Tengda Wu <wutengda@huaweicloud.com>
To: Ian Rogers <irogers@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
james.clark@linaro.org, xueshuai@linux.alibaba.com,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
leo.yan@linux.dev, Li Huafei <lihuafei1@huawei.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>,
Zecheng Li <zli94@ncsu.edu>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH v5 07/26] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64
Date: Fri, 11 Sep 2026 09:47:58 +0800 [thread overview]
Message-ID: <0ef7dbfd-3bd6-40bb-b42a-a81edd2ba468@huaweicloud.com> (raw)
In-Reply-To: <CAP-5=fUAtw6-waqmF4RJFGZ__J=DSzbNLNsOfWekj378_PnrdQ@mail.gmail.com>
On 2026/9/9 2:08, Ian Rogers wrote:
> On Tue, Sep 8, 2026 at 6:01 AM Tengda Wu <wutengda@huaweicloud.com> wrote:
>>
>> The current arm64 DWARF register lookup relies on 'aarch64_regstr_tbl',
>> a static string table. While this works for kprobe-tracer where register
>> names start with '%', it is insufficient for parsing register numbers
>> directly from raw instructions (e.g., extracting '6' from 'x6' or 'w6')
>> during annotation.
>>
>> Since get_dwarf_regnum() is currently used only by 'perf annotate' and
>> does not affect kprobe-tracer, replace the limited table-based lookup
>> with a programmatic implementation in __get_dwarf_regnum_arm64(). This
>> allows resolving arm64 register names (x0-x30, w0-w30, sp, etc.) directly
>> into their corresponding DWARF register numbers.
>>
>> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
>> ---
>> .../util/dwarf-regs-arch/dwarf-regs-arm64.c | 22 +++++++++++++++++++
>> tools/perf/util/dwarf-regs.c | 2 +-
>> tools/perf/util/include/dwarf-regs.h | 1 +
>> 3 files changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/util/dwarf-regs-arch/dwarf-regs-arm64.c b/tools/perf/util/dwarf-regs-arch/dwarf-regs-arm64.c
>> index 593ca7d4fccc..720c863d1869 100644
>> --- a/tools/perf/util/dwarf-regs-arch/dwarf-regs-arm64.c
>> +++ b/tools/perf/util/dwarf-regs-arch/dwarf-regs-arm64.c
>> @@ -1,5 +1,8 @@
>> // SPDX-License-Identifier: GPL-2.0
>> #include <errno.h>
>> +#include <ctype.h>
>> +#include <stdlib.h>
>> +#include <string.h>
>> #include <dwarf-regs.h>
>> #include "../../../arch/arm64/include/uapi/asm/perf_regs.h"
>>
>> @@ -10,3 +13,22 @@ int __get_dwarf_regnum_for_perf_regnum_arm64(int perf_regnum)
>>
>> return perf_regnum;
>> }
>> +
>> +int __get_dwarf_regnum_arm64(const char *name)
>> +{
>> + int reg;
>> +
>> + if (!strcmp(name, "sp"))
>> + return 31;
>> +
>> + if (*name != 'x' && *name != 'w')
>> + return -ENOENT;
>> +
>> + name++;
>> + if (!isdigit(*name))
>> + return -ENOENT;
>> +
>> + reg = strtol(name, NULL, 10);
>
> Nit: perhaps this can be a little faster and ensure correct string termination?
> ```
> if (!isdigit(name[0])) {
> return -ENOENT;
> } else if (isdigit(name[1]) && name[2] == '\0') {
> reg = (name[1] - ' 0') * 10 + name[2] - '0';
> } else if (name[1] == '\0) {
> reg = name[1] - '0';
> } else {
> return -ENOENT;
> }
> ```
> Everything else looks good to me.
>
> Thanks,
> Ian
>
Sure, Ian. Thanks for the review. I'll make the change in v6.
Thanks,
Tengda
>> +
>> + reg = strtol(name, NULL, 10);
>> +
>> + return reg >= 0 && reg <= 30 ? reg : -ENOENT;
>> +}
>> diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c
>> index 797f455eba0d..bacf5c13c3bc 100644
>> --- a/tools/perf/util/dwarf-regs.c
>> +++ b/tools/perf/util/dwarf-regs.c
>> @@ -114,7 +114,7 @@ int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags)
>> reg = _get_dwarf_regnum(arm_regstr_tbl, name);
>> break;
>> case EM_AARCH64:
>> - reg = _get_dwarf_regnum(aarch64_regstr_tbl, name);
>> + reg = __get_dwarf_regnum_arm64(name);
>> break;
>> case EM_CSKY:
>> reg = __get_csky_regnum(name, flags);
>> diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h
>> index 46a764cf322f..a25f038bbff2 100644
>> --- a/tools/perf/util/include/dwarf-regs.h
>> +++ b/tools/perf/util/include/dwarf-regs.h
>> @@ -105,6 +105,7 @@ int __get_dwarf_regnum_x86_64(const char *name);
>> int __get_dwarf_regnum_for_perf_regnum_i386(int perf_regnum);
>> int __get_dwarf_regnum_for_perf_regnum_x86_64(int perf_regnum);
>>
>> +int __get_dwarf_regnum_arm64(const char *name);
>> int __get_dwarf_regnum_for_perf_regnum_arm(int perf_regnum);
>> int __get_dwarf_regnum_for_perf_regnum_arm64(int perf_regnum);
>>
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2026-09-11 1:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 13:00 [PATCH v5 00/26] perf arm64: Support data type profiling Tengda Wu
2026-09-08 13:00 ` [PATCH v5 01/26] perf capstone: Symbolize address operands to match objdump on arm64 Tengda Wu
2026-09-08 13:00 ` [PATCH v5 02/26] perf llvm: Fix arm64 adrp instruction disassembly mismatch with objdump Tengda Wu
2026-09-08 13:00 ` [PATCH v5 03/26] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-09-08 13:01 ` [PATCH v5 04/26] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-09-08 13:01 ` [PATCH v5 05/26] perf annotate: Normalize arch__dwarf_regnum() error return values Tengda Wu
2026-09-08 13:01 ` [PATCH v5 06/26] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-09-08 13:01 ` [PATCH v5 07/26] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-09-08 18:08 ` Ian Rogers
2026-09-11 1:47 ` Tengda Wu [this message]
2026-09-08 13:01 ` [PATCH v5 08/26] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-09-08 13:01 ` [PATCH v5 09/26] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-09-08 13:01 ` [PATCH v5 10/26] perf annotate: Default to --itrace=i1i for data type profiling Tengda Wu
2026-09-08 13:01 ` [PATCH v5 11/26] perf arm-spe: Set default synthesized event period to 1 Tengda Wu
2026-09-08 13:01 ` [PATCH v5 12/26] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-09-08 13:01 ` [PATCH v5 13/26] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-09-08 13:01 ` [PATCH v5 14/26] perf annotate-data: Add arch_get_reg_offset helper Tengda Wu
2026-09-08 13:01 ` [PATCH v5 15/26] perf annotate-arm64: Track return type after call instructions Tengda Wu
2026-09-08 13:01 ` [PATCH v5 16/26] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-09-08 13:01 ` [PATCH v5 17/26] perf annotate-arm64: Support store " Tengda Wu
2026-09-08 13:01 ` [PATCH v5 18/26] perf annotate-data: Expand type_state_reg imm_value to u64 Tengda Wu
2026-09-08 13:01 ` [PATCH v5 19/26] perf annotate-data: Track imm_value for stack variables Tengda Wu
2026-09-08 13:01 ` [PATCH v5 20/26] perf annotate-x86: Delete stale stack state on store of untracked register Tengda Wu
2026-09-08 13:01 ` [PATCH v5 21/26] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-09-08 13:01 ` [PATCH v5 22/26] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-09-08 13:01 ` [PATCH v5 23/26] perf annotate-arm64: Support 'add' " Tengda Wu
2026-09-08 13:18 ` [PATCH v5 00/26] perf arm64: Support data type profiling Tengda Wu
-- strict thread matches above, loose matches on Subject: below --
2026-09-08 13:05 Tengda Wu
2026-09-08 13:05 ` [PATCH v5 07/26] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-09-08 13:21 ` sashiko-bot
2026-09-09 15:03 ` 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=0ef7dbfd-3bd6-40bb-b42a-a81edd2ba468@huaweicloud.com \
--to=wutengda@huaweicloud.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--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=namhyung@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=xueshuai@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).