diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/util/annotate-arch/annotate-arm64.c index bd060a823b76..270f35876511 100644 --- a/tools/perf/util/annotate-arch/annotate-arm64.c +++ b/tools/perf/util/annotate-arch/annotate-arm64.c @@ -12,6 +12,7 @@ #include "../disasm.h" #include "../annotate-data.h" #include "../debug.h" +#include "../dso.h" #include "../map.h" #include "../symbol.h" @@ -727,13 +728,23 @@ static int propagate_load_reg_state(struct type_state *state, u64 ip = dloc->ms->sym->start + dl->al.offset; u64 addr = src_tsr->imm_value + reg_offset; int offset; + u8 kind; + const char *var_name = NULL; + + /* it might be per-cpu offset */ + if (dso__kernel(map__dso(dloc->ms->map)) && + get_global_var_info(dloc, addr, &var_name, &offset) && + !strcmp(var_name, "__per_cpu_offset")) + kind = TSR_KIND_PERCPU_BASE; + else + kind = TSR_KIND_TYPE; if (!get_global_var_type(cu_die, dloc, ip, addr, &offset, &type_die) || !die_get_member_type(&type_die, offset, &type_die)) return -1; tsr->type = type_die; - tsr->kind = TSR_KIND_TYPE; + tsr->kind = kind; tsr->offset = 0; tsr->imm_value = 0; tsr->ok = true; @@ -749,6 +760,12 @@ static int propagate_load_reg_state(struct type_state *state, return 0; } + /* + * If src_tsr->kind is TSR_KIND_PERCPU_BASE, treat it as an array. + * No special handling is needed here; just fall through to retry + * and resolve the type from the second register. + */ + load_non_regoff: /* Try another register if any */ if (src->multi_regs && src->reg1 != src->reg2 && sreg != src->reg2 && @@ -1046,6 +1063,12 @@ static void update_add_insn_state(struct type_state *state, return; } + /* + * If src_tsr->kind is TSR_KIND_PERCPU_BASE, treat it as an array. + * No special handling is needed here; just fall through to retry + * and resolve the type from the second register. + */ + add_non_regoff: /* Try another register if any */ if (src->multi_regs && src->reg1 != src->reg2 && sreg != src->reg2 && diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index 43cd09c0662a..b3de1ca688a2 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1307,13 +1307,17 @@ int arch_get_reg_offset(const struct arch *arch, struct annotated_op_loc *op_loc /* * For register-based addressing without shift/extension, - * reg2 may be a constant offset. Use its value as the offset - * from the base register. + * derive the offset from the type of reg2. */ reg2 = op_loc->reg1 == breg ? op_loc->reg2 : op_loc->reg1; - if (has_reg_type(state, reg2) && state->regs[reg2].ok && - state->regs[reg2].kind == TSR_KIND_CONST) { - *offset = (s64)state->regs[reg2].imm_value; + if (has_reg_type(state, reg2) && state->regs[reg2].ok) { + if (state->regs[reg2].kind == TSR_KIND_CONST) + *offset = (s64)state->regs[reg2].imm_value; + else if (state->regs[reg2].kind == TSR_KIND_PERCPU_BASE) + *offset = 0; /* it does not contribute to the offset */ + else + return -1; + return 0; } @@ -1448,11 +1452,31 @@ static enum type_match_result check_matching_type(struct type_state *state, } if (state->regs[reg].kind == TSR_KIND_PERCPU_BASE) { - u64 var_addr = (s64) offset; + u64 var_addr; int var_offset; pr_debug_dtp("percpu var"); + if (arch__is_arm64(dloc->arch)) { + int reg2; + + if (!retry || !dloc->op->multi_regs || + dloc->op->reg1 == dloc->op->reg2 || + dloc->op->extend_type || dloc->op->shift_type) + return PERF_TMR_BAIL_OUT; + + reg2 = dloc->op->reg2; + if (!has_reg_type(state, reg2) || !state->regs[reg2].ok) + return PERF_TMR_NO_TYPE; + + pr_debug_dtp(" : retry\n"); + retry = false; + reg = reg2; + goto again; + } + + var_addr = (s64) offset; + if (dloc->op->multi_regs) { int reg2 = dloc->op->reg2;