Skip to contentSkip to conversation

perf: perf can not parser the backtrace of app in the 32bit system and 64bit kernel.

PATCH In review Jiping Ma 1 participant 3 messages Apr 29, 2020 – May 7, 2020

Subsystems (2)
lore
Share & tools
lore

Jiping Ma

author
#0 lore raw

PATCH 1/1 perf: perf can not parser the backtrace of app in the 32bit system and 64bit kernel.

Record PC value from regs[15], it should be regs[32], which cause perf parser the backtrace failed.

---
 arch/arm64/kernel/perf_regs.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/kernel/perf_regs.c +4 -0
index 0bbac61..04088e6 100644
@@ -32,6 +32,10 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 	if ((u32)idx == PERF_REG_ARM64_PC)
 		return regs->pc;
 
+	if (perf_reg_abi(current) == PERF_SAMPLE_REGS_ABI_32
+		&& idx == 15)
+		return regs->regs[PERF_REG_ARM64_PC];
+
 	return regs->regs[idx];
 }
 
Signature · 1 line
1.9.1
author
#1 lore raw

We test it as the following steps.

# gcc -g -mthumb -gdwarf -o test test.c
# export CALLGRAPH=dwarf
#(./perftest ./test profiling 1; cd ./profiling/; perf script)

Thanks,
Jiping

Quoted 23 lines · Jiping Ma

Record PC value from regs[15], it should be regs[32], which cause perf parser the backtrace failed.

---
  arch/arm64/kernel/perf_regs.c | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm64/kernel/perf_regs.c +4 -0
index 0bbac61..04088e6 100644
@@ -32,6 +32,10 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
  	if ((u32)idx == PERF_REG_ARM64_PC)
  		return regs->pc;
 
+	if (perf_reg_abi(current) == PERF_SAMPLE_REGS_ABI_32
+		&& idx == 15)
+		return regs->regs[PERF_REG_ARM64_PC];
+
  	return regs->regs[idx];
  }
 
author
#2 lore raw

Hi, Will

Please help to review the patch.

Thanks,
Jiping

Quoted 31 lines · Jiping Ma

We test it as the following steps.

# gcc -g -mthumb -gdwarf -o test test.c
# export CALLGRAPH=dwarf
#(./perftest ./test profiling 1; cd ./profiling/; perf script)

Thanks,
Jiping

Quoted 21 lines · Jiping Ma

Record PC value from regs[15], it should be regs[32], which cause perf parser the backtrace failed.

---
  arch/arm64/kernel/perf_regs.c | 4 ++++

  1 file changed, 4 insertions(+)
arch/arm64/kernel/perf_regs.c +0 -0
index 0bbac61..04088e6 100644
@@ -32,6 +32,10 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
       if ((u32)idx == PERF_REG_ARM64_PC)
           return regs->pc;

  +    if (perf_reg_abi(current) == PERF_SAMPLE_REGS_ABI_32 +        && idx == 15)
+        return regs->regs[PERF_REG_ARM64_PC];
+
      return regs->regs[idx];
  }