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

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

commit 633014b6b162d23d396117e7369c0a9f0cb7f300
Author: yinshengkai <[email protected]>
AuthorDate: Tue Dec 24 17:04:45 2024 +0800

    clock: fix perf_gettime race condition
    
    Move hardware perf counter read after spinlock acquisition to prevent
    reading stale values due to concurrent overflow updates.
    
    Signed-off-by: yinshengkai <[email protected]>
---
 sched/clock/clock_perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sched/clock/clock_perf.c b/sched/clock/clock_perf.c
index 372b0d8d788..50ab97d25ad 100644
--- a/sched/clock/clock_perf.c
+++ b/sched/clock/clock_perf.c
@@ -94,8 +94,8 @@ void perf_init(void)
 clock_t perf_gettime(void)
 {
   FAR struct perf_s *perf = &g_perf;
-  clock_t now = up_perf_gettime();
   irqstate_t flags = spin_lock_irqsave(&perf->lock);
+  clock_t now = up_perf_gettime();
   clock_t result;
 
   /* Check if overflow */

Reply via email to