Skip to contentSkip to conversation

arm: arch_timer: prevent recursive function tracing

PATCH In review Lee Yongjun 2 participants 2 messages Sep 29 – Oct 13 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: arch_timer: prevent recursive function tracing

Function tracing uses timer_get_us() to obtain timestamps for trace records. On ARMv7 systems using the architectural timer, the timer_get_us() call path reaches get_ticks() and get_tbclk().

When built with FTRACE=1, both functions are instrumented with __cyg_profile_func_enter() and __cyg_profile_func_exit(). This causes the tracing code to be re-entered while obtaining a timestamp and results in:

trace: recursion detected, disabling

Mark get_ticks() and get_tbclk() as notrace so they are excluded from function instrumentation.

Before this change, tracing is disabled by recursion. After this change, tracing remains enabled and function calls are recorded normally.

Tested on QEMU ARM virt with:

qemu-system-arm -machine virt -nographic -bios u-boot.bin

---
 arch/arm/cpu/armv7/arch_timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/cpu/armv7/arch_timer.c +2 -2
index 36c557d4a8f..579b6feb1b8 100644
@@ -37,7 +37,7 @@ int timer_init(void)
 	return 0;
 }
 
-unsigned long long get_ticks(void)
+unsigned long long notrace get_ticks(void)
 {
 	ulong nowl, nowu;
 
@@ -57,7 +57,7 @@ ulong timer_get_boot_us(void)
 	return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
 }
 
-ulong get_tbclk(void)
+ulong notrace get_tbclk(void)
 {
 	return gd->arch.timer_rate_hz;
 }
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Lee Yongjun

Function tracing uses timer_get_us() to obtain timestamps for trace records. On ARMv7 systems using the architectural timer, the timer_get_us() call path reaches get_ticks() and get_tbclk().

When built with FTRACE=1, both functions are instrumented with __cyg_profile_func_enter() and __cyg_profile_func_exit(). This causes the tracing code to be re-entered while obtaining a timestamp and results in:

[...]

Applied to u-boot/main, thanks!

[1/1] arm: arch_timer: prevent recursive function tracing

      commit: 7b1b8fc581a9d4907968cdbf8fb6296f616d56f0
Signature · 1 line
Tom