diff --git a/testing/ostest/sporadic.c b/testing/ostest/sporadic.c index 5e6986ba774..98a8d755f7b 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 acc7f34e164..494dc8b2977 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 8c3b94e7e6c..98f1894db45 100644 --- a/testing/sched/smp/smp_main.c +++ b/testing/sched/smp/smp_main.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -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; } } }