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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7289c27a8 testing/{ostest,sched/smp}: Remove BOARD_LOOPSPERMSEC 
references
7289c27a8 is described below

commit 7289c27a8509c4943ee359644067b9e9326e93eb
Author: Matteo Golin <[email protected]>
AuthorDate: Thu Feb 5 15:15:25 2026 -0500

    testing/{ostest,sched/smp}: Remove BOARD_LOOPSPERMSEC references
    
    In an effort to avoid unexpected behaviour from users not calibrating
    BOARD_LOOPSPERMSEC, a compilation error occurs when it is undefined. On
    some systems, this is allowed (those that use timer implementations
    instead of busy-looping for delays). In these cases, we should busy-loop
    using the clock time instead of relying on a possibly
    undefined/uncalibrated macro.
    
    Signed-off-by: Matteo Golin <[email protected]>
---
 testing/ostest/sporadic.c    | 14 ++++++++++----
 testing/ostest/sporadic2.c   | 16 +++++++++++-----
 testing/sched/smp/smp_main.c | 15 +++++++++++----
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/testing/ostest/sporadic.c b/testing/ostest/sporadic.c
index 5e6986ba7..98a8d755f 100644
--- a/testing/ostest/sporadic.c
+++ b/testing/ostest/sporadic.c
@@ -65,13 +65,19 @@ static time_t g_start_time;
 
 static void my_mdelay(unsigned int milliseconds)
 {
-  volatile unsigned int i;
-  volatile unsigned int j;
+  struct timespec start;
+  struct timespec cur;
+  struct timespec diff;
 
-  for (i = 0; i < milliseconds; i++)
+  clock_gettime(CLOCK_MONOTONIC, &start);
+
+  for (; ; )
     {
-      for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++)
+      clock_gettime(CLOCK_MONOTONIC, &cur);
+      clock_timespec_subtract(&cur, &start, &diff);
+      if (diff.tv_sec * 1000 + diff.tv_nsec / 1000000 > milliseconds)
         {
+          break;
         }
     }
 }
diff --git a/testing/ostest/sporadic2.c b/testing/ostest/sporadic2.c
index acc7f34e1..494dc8b29 100644
--- a/testing/ostest/sporadic2.c
+++ b/testing/ostest/sporadic2.c
@@ -80,13 +80,19 @@ static int32_t g_ms_cnt2[2] =
 
 static void my_mdelay(unsigned int milliseconds)
 {
-  volatile unsigned int i;
-  volatile unsigned int j;
+  struct timespec start;
+  struct timespec cur;
+  struct timespec diff;
 
-  for (i = 0; i < milliseconds; i++)
+  clock_gettime(CLOCK_MONOTONIC, &start);
+
+  for (; ; )
     {
-      for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++)
+      clock_gettime(CLOCK_MONOTONIC, &cur);
+      clock_timespec_subtract(&cur, &start, &diff);
+      if (diff.tv_sec * 1000 + diff.tv_nsec / 1000000 > milliseconds)
         {
+          break;
         }
     }
 }
@@ -172,7 +178,7 @@ static void sporadic_test_case(int32_t budget_1_ns, int32_t 
budget_2_ns)
 
   sem_init(&g_sporadic_sem, 0, 0);
 
-  /* initilize global worker-thread millisecons-counters */
+  /* Initialize global worker-thread milliseconds-counters */
 
   g_ms_cnt1[PRIO_HI_NDX] = 0;
   g_ms_cnt1[PRIO_LO_NDX] = 0;
diff --git a/testing/sched/smp/smp_main.c b/testing/sched/smp/smp_main.c
index 8c3b94e7e..98f1894db 100644
--- a/testing/sched/smp/smp_main.c
+++ b/testing/sched/smp/smp_main.c
@@ -27,6 +27,7 @@
 #include <sched.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
 #include <unistd.h>
 #include <pthread.h>
 #include <string.h>
@@ -87,13 +88,19 @@ static void show_cpu_conditional(FAR const char *caller, 
int threadno)
 
 static void hog_milliseconds(unsigned int milliseconds)
 {
-  volatile unsigned int i;
-  volatile unsigned int j;
+  struct timespec start;
+  struct timespec cur;
+  struct timespec diff;
 
-  for (i = 0; i < milliseconds; i++)
+  clock_gettime(CLOCK_MONOTONIC, &start);
+
+  for (; ; )
     {
-      for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++)
+      clock_gettime(CLOCK_MONOTONIC, &cur);
+      clock_timespec_subtract(&cur, &start, &diff);
+      if (diff.tv_sec * 1000 + diff.tv_nsec / 1000000 > milliseconds)
         {
+          break;
         }
     }
 }

Reply via email to