sim: fix nuttx consumes much CPU time
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
758668d11a
commit
87a92d995f
@ -122,6 +122,20 @@ static inline void sim_timer_current(struct timespec *ts)
|
|||||||
ts->tv_nsec = nsec;
|
ts->tv_nsec = nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sim_reset_alarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Reset the alarm to MAX
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline void sim_reset_alarm(struct timespec *alarm)
|
||||||
|
{
|
||||||
|
alarm->tv_sec = UINT_MAX;
|
||||||
|
alarm->tv_nsec = NSEC_PER_SEC - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: sim_update_hosttimer
|
* Name: sim_update_hosttimer
|
||||||
*
|
*
|
||||||
@ -217,8 +231,6 @@ static void sim_process_tick(sq_entry_t *entry)
|
|||||||
|
|
||||||
DEBUGASSERT(priv != NULL);
|
DEBUGASSERT(priv != NULL);
|
||||||
|
|
||||||
if (priv->callback)
|
|
||||||
{
|
|
||||||
struct timespec current;
|
struct timespec current;
|
||||||
|
|
||||||
sim_timer_current(¤t);
|
sim_timer_current(¤t);
|
||||||
@ -227,6 +239,10 @@ static void sim_process_tick(sq_entry_t *entry)
|
|||||||
return; /* Alarm doesn't expire yet */
|
return; /* Alarm doesn't expire yet */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sim_reset_alarm(&priv->alarm);
|
||||||
|
|
||||||
|
if (priv->callback)
|
||||||
|
{
|
||||||
/* Sample and nullify BEFORE executing callback (in case the callback
|
/* Sample and nullify BEFORE executing callback (in case the callback
|
||||||
* restarts the oneshot).
|
* restarts the oneshot).
|
||||||
*/
|
*/
|
||||||
@ -355,9 +371,7 @@ static int sim_cancel(struct oneshot_lowerhalf_s *lower,
|
|||||||
sim_timer_current(¤t);
|
sim_timer_current(¤t);
|
||||||
clock_timespec_subtract(&priv->alarm, ¤t, ts);
|
clock_timespec_subtract(&priv->alarm, ¤t, ts);
|
||||||
|
|
||||||
priv->alarm.tv_sec = UINT_MAX;
|
sim_reset_alarm(&priv->alarm);
|
||||||
priv->alarm.tv_nsec = NSEC_PER_SEC - 1;
|
|
||||||
|
|
||||||
sim_update_hosttimer();
|
sim_update_hosttimer();
|
||||||
|
|
||||||
priv->callback = NULL;
|
priv->callback = NULL;
|
||||||
@ -505,7 +519,6 @@ void up_timer_initialize(void)
|
|||||||
|
|
||||||
void sim_timer_update(void)
|
void sim_timer_update(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SIM_WALLTIME_SLEEP
|
|
||||||
static uint64_t until;
|
static uint64_t until;
|
||||||
|
|
||||||
/* Wait a bit so that the timing is close to the correct rate. */
|
/* Wait a bit so that the timing is close to the correct rate. */
|
||||||
@ -513,6 +526,7 @@ void sim_timer_update(void)
|
|||||||
until += NSEC_PER_TICK;
|
until += NSEC_PER_TICK;
|
||||||
host_sleepuntil(until);
|
host_sleepuntil(until);
|
||||||
|
|
||||||
|
#ifdef CONFIG_SIM_WALLTIME_SLEEP
|
||||||
sim_timer_update_internal();
|
sim_timer_update_internal();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user