diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index f9456ef2b2f..6f39c907b3d 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -94,6 +94,10 @@ ifeq ($(CONFIG_SMP),y) CSRCS += up_smpsignal.c up_cpuidlestack.c REQUIREDOBJS += up_smpsignal$(OBJEXT) HOSTCFLAGS += -DCONFIG_SMP=1 -DCONFIG_SMP_NCPUS=$(CONFIG_SMP_NCPUS) + HOSTCFLAGS += -DCONFIG_USEC_PER_TICK=$(CONFIG_USEC_PER_TICK) +ifeq ($(CONFIG_SIM_WALLTIME),y) + HOSTCFLAGS += -DCONFIG_SIM_WALLTIME=1 +endif HOSTSRCS += up_simsmp.c STDLIBS += -lpthread endif diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index aa061261ef4..a775ad1cf57 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -98,6 +98,7 @@ volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS]; void nx_start(void); void up_cpu_started(void); int up_cpu_paused(int cpu); +void host_sleepuntil(uint64_t nsec); /**************************************************************************** * Private Functions @@ -162,9 +163,18 @@ static void *sim_idle_trampoline(void *arg) for (; ; ) { +#ifdef CONFIG_SIM_WALLTIME + uint64_t now = 0; + + /* Wait a bit so that the timing is close to the correct rate. */ + + now += 1000 * CONFIG_USEC_PER_TICK; + host_sleepuntil(now); +#else /* Give other pthreads/CPUs a shot */ pthread_yield(); +#endif } return NULL;