Messages in this thread | | | From | Huacai Chen <> | Date | Tue, 18 Apr 2023 09:14:51 +0800 | Subject | Re: [PATCH V2] tools/perf: Add basic support for LoongArch |
| |
On Mon, Apr 17, 2023 at 5:22 PM Youling Tang <tangyouling@loongson.cn> wrote: > > /* snip */ > > >>>> --- /dev/null > >>>> +++ b/tools/perf/arch/loongarch/util/dwarf-regs.c > >>>> @@ -0,0 +1,44 @@ > >>>> +// SPDX-License-Identifier: GPL-2.0 > >>>> +/* > >>>> + * dwarf-regs.c : Mapping of DWARF debug register numbers into > >>>> register names. > >>>> + * > >>>> + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited > >>>> + */ > >>>> + > >>>> +#include <stdio.h> > >>>> +#include <errno.h> /* for EINVAL */ > >>>> +#include <string.h> /* for strcmp */ > >>>> +#include <dwarf-regs.h> > >>>> + > >>>> +struct pt_regs_dwarfnum { > >>>> + const char *name; > >>>> + unsigned int dwarfnum; > >>>> +}; > >>>> + > >>>> +static struct pt_regs_dwarfnum loongarch_gpr_table[] = { > >>>> + {"$0", 0}, {"$1", 1}, {"$2", 2}, {"$3", 3}, > >>>> + {"$4", 4}, {"$5", 5}, {"$6", 6}, {"$7", 7}, > >>>> + {"$8", 8}, {"$9", 9}, {"$10", 10}, {"$11", 11}, > >>>> + {"$12", 12}, {"$13", 13}, {"$14", 14}, {"$15", 15}, > >>>> + {"$16", 16}, {"$17", 17}, {"$18", 18}, {"$19", 19}, > >>>> + {"$20", 20}, {"$21", 21}, {"$22", 22}, {"$23", 23}, > >>>> + {"$24", 24}, {"$25", 25}, {"$26", 26}, {"$27", 27}, > >>>> + {"$28", 28}, {"$29", 29}, {"$30", 30}, {"$31", 31}, > >>>> + {NULL, 0} > >>>> +}; > >>> Do you need to change it to the following: > >>> > >>> #define GPR_DWARFNUM_NAME(num) {.name = __stringify($r##num), .dwarfnum > >>> = num} > >>> #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} > >>> > >>> static const struct pt_regs_dwarfnum regdwarfnum_table[] = { > >>> GPR_DWARFNUM_NAME(0), > >>> GPR_DWARFNUM_NAME(1), > >>> GPR_DWARFNUM_NAME(2), > >>> GPR_DWARFNUM_NAME(3), > >>> GPR_DWARFNUM_NAME(4), > >>> GPR_DWARFNUM_NAME(5), > >>> GPR_DWARFNUM_NAME(6), > >>> GPR_DWARFNUM_NAME(7), > >>> GPR_DWARFNUM_NAME(8), > >>> GPR_DWARFNUM_NAME(9), > >>> GPR_DWARFNUM_NAME(10), > >>> GPR_DWARFNUM_NAME(11), > >>> GPR_DWARFNUM_NAME(12), > >>> GPR_DWARFNUM_NAME(13), > >>> GPR_DWARFNUM_NAME(14), > >>> GPR_DWARFNUM_NAME(15), > >>> GPR_DWARFNUM_NAME(16), > >>> GPR_DWARFNUM_NAME(17), > >>> GPR_DWARFNUM_NAME(18), > >>> GPR_DWARFNUM_NAME(19), > >>> GPR_DWARFNUM_NAME(20), > >>> GPR_DWARFNUM_NAME(21), > >>> GPR_DWARFNUM_NAME(22), > >>> GPR_DWARFNUM_NAME(23), > >>> GPR_DWARFNUM_NAME(24), > >>> GPR_DWARFNUM_NAME(25), > >>> GPR_DWARFNUM_NAME(26), > >>> GPR_DWARFNUM_NAME(27), > >>> GPR_DWARFNUM_NAME(28), > >>> GPR_DWARFNUM_NAME(29), > >>> REG_DWARFNUM_NAME(30), > >>> REG_DWARFNUM_NAME(31), > >>> REG_DWARFNUM_END, > >>> }; > >>> > >>> At the same time, "$rx" is used in __perf_reg_name_loongarch and > >>> loongarch_regstr_tbl, which is consistent with assembly. > >> OK, I will use the "$rx" format, but I don't want to use macros. > > Use the "rx" format to make regs_query_register_offset consistent with > > arch/loongarch/kernel/ptrace.c (that is, the names in > > loongarch_gpr_table and regoffset_table are consistent) > > If we want to be consistent with the usage of `trace probe`, we should > use "%rx". OK, make sense.
Huacai > > eg: > # echo "p:myuprobe /tmp/test:0x4194 %r4 %r5" > uprobe_events > > parse_probe_arg() > case '%': regs_query_register_offset() > > Youling. > > > > Youling. > >> > >> Huacai > >>> > >>>> + > >>>> +const char *get_arch_regstr(unsigned int n) > >>>> +{ > >>>> + n %= 32; > >>>> + return loongarch_gpr_table[n].name; > >>>> +} > >>>> + > >>>> +int regs_query_register_offset(const char *name) > >>>> +{ > >>>> + const struct pt_regs_dwarfnum *roff; > >>>> + > >>>> + for (roff = loongarch_gpr_table; roff->name != NULL; roff++) > >>>> + if (!strcmp(roff->name, name)) > >>>> + return roff->dwarfnum; > >>>> + return -EINVAL; > >>>> +} > > > >
| |