You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2023/02/13 09:41:51 UTC
[nuttx] 02/02: sim: fix nuttx consumes much CPU time
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 87a92d995fe1a13ef96c031cbc71f69584119eec
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Feb 10 22:54:55 2023 +0800
sim: fix nuttx consumes much CPU time
Signed-off-by: ligd <li...@xiaomi.com>
---
arch/sim/src/sim/sim_oneshot.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/arch/sim/src/sim/sim_oneshot.c b/arch/sim/src/sim/sim_oneshot.c
index 113843fefc..df89fd8ae3 100644
--- a/arch/sim/src/sim/sim_oneshot.c
+++ b/arch/sim/src/sim/sim_oneshot.c
@@ -122,6 +122,20 @@ static inline void sim_timer_current(struct timespec *ts)
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
*
@@ -217,16 +231,18 @@ static void sim_process_tick(sq_entry_t *entry)
DEBUGASSERT(priv != NULL);
- if (priv->callback)
+ struct timespec current;
+
+ sim_timer_current(¤t);
+ if (clock_timespec_compare(&priv->alarm, ¤t) > 0)
{
- struct timespec current;
+ return; /* Alarm doesn't expire yet */
+ }
- sim_timer_current(¤t);
- if (clock_timespec_compare(&priv->alarm, ¤t) > 0)
- {
- return; /* Alarm doesn't expire yet */
- }
+ sim_reset_alarm(&priv->alarm);
+ if (priv->callback)
+ {
/* Sample and nullify BEFORE executing callback (in case the callback
* restarts the oneshot).
*/
@@ -355,9 +371,7 @@ static int sim_cancel(struct oneshot_lowerhalf_s *lower,
sim_timer_current(¤t);
clock_timespec_subtract(&priv->alarm, ¤t, ts);
- priv->alarm.tv_sec = UINT_MAX;
- priv->alarm.tv_nsec = NSEC_PER_SEC - 1;
-
+ sim_reset_alarm(&priv->alarm);
sim_update_hosttimer();
priv->callback = NULL;
@@ -505,7 +519,6 @@ void up_timer_initialize(void)
void sim_timer_update(void)
{
-#ifdef CONFIG_SIM_WALLTIME_SLEEP
static uint64_t until;
/* 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;
host_sleepuntil(until);
+#ifdef CONFIG_SIM_WALLTIME_SLEEP
sim_timer_update_internal();
#endif
}