mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
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 <matteo.golin@gmail.com>
This commit is contained in:
parent
d48b45000d
commit
7289c27a85
3 changed files with 32 additions and 13 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue