This is an automated email from the ASF dual-hosted git repository.

anchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4ed1da42ec528b993e2aa53bc41e0d3c985c58cc
Author: tengshuangshuang <[email protected]>
AuthorDate: Thu Aug 20 22:47:04 2026 +0800

    tricore/perf: fix critmon timestamps corrupted by CCNT SOVF bit
    
    up_perf_gettime() returned the raw 32-bit CCNT value; its sticky
    overflow flag (bit 31) collided with the overflow extension bit in
    perf_gettime(), making timestamps go backwards on every counter wrap
    and critmon show bogus multi-second values. Mask the overflow flag
    with CCNT_VALUE_MASK derived from CONFIG_ARCH_PERF_COUNT_BITWIDTH.
    
    Signed-off-by: tengshuangshuang <[email protected]>
---
 arch/tricore/src/common/tricore_perf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/tricore/src/common/tricore_perf.c 
b/arch/tricore/src/common/tricore_perf.c
index 03d7f0e2082..200a74875c6 100644
--- a/arch/tricore/src/common/tricore_perf.c
+++ b/arch/tricore/src/common/tricore_perf.c
@@ -39,6 +39,12 @@
 
 #define CCTRL_COUNT_ENABLE (1 << 1)
 
+#ifdef CONFIG_ARCH_PERF_COUNT_BITWIDTH
+#  define CCNT_VALUE_MASK ((1UL << CONFIG_ARCH_PERF_COUNT_BITWIDTH) - 1UL)
+#else
+#  define CCNT_VALUE_MASK 0x7ffffffful
+#endif
+
 #ifdef CONFIG_ARCH_PERF_EVENTS
 
 /****************************************************************************
@@ -90,7 +96,7 @@ unsigned long up_perf_getfreq(void)
 
 clock_t up_perf_gettime(void)
 {
-  return (clock_t)tricore_mfcr(CPU_CCNT);
+  return (clock_t)(tricore_mfcr(CPU_CCNT) & CCNT_VALUE_MASK);
 }
 
 void up_perf_convert(clock_t elapsed, struct timespec *ts)

Reply via email to