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:49 UTC

[nuttx] branch master updated (7347684e5f -> 87a92d995f)

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from 7347684e5f mempool:fix bug when list needs to be protected by a lock
     new 758668d11a sim: remove sim_saveusercontext() return value
     new 87a92d995f sim: fix nuttx consumes much CPU time

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/sim/src/sim/sim_doirq.c           |  4 +++-
 arch/sim/src/sim/sim_internal.h        | 21 +++++++++++---------
 arch/sim/src/sim/sim_oneshot.c         | 36 +++++++++++++++++++++++-----------
 arch/sim/src/sim/sim_saveusercontext.c |  6 +++++-
 arch/sim/src/sim/sim_switchcontext.c   |  7 ++++++-
 5 files changed, 51 insertions(+), 23 deletions(-)


[nuttx] 01/02: sim: remove sim_saveusercontext() return value

Posted by ma...@apache.org.
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 758668d11a00ddcd2df86dbf7be3a94aa8581384
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Feb 10 16:12:46 2023 +0800

    sim: remove sim_saveusercontext() return value
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/sim/src/sim/sim_doirq.c           |  4 +++-
 arch/sim/src/sim/sim_internal.h        | 21 ++++++++++++---------
 arch/sim/src/sim/sim_saveusercontext.c |  6 +++++-
 arch/sim/src/sim/sim_switchcontext.c   |  7 ++++++-
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/arch/sim/src/sim/sim_doirq.c b/arch/sim/src/sim/sim_doirq.c
index a84c90622c..4cf7c1f68c 100644
--- a/arch/sim/src/sim/sim_doirq.c
+++ b/arch/sim/src/sim/sim_doirq.c
@@ -43,12 +43,14 @@ void *sim_doirq(int irq, void *context)
 
   xcpt_reg_t tmp[XCPTCONTEXT_REGS];
   void *regs = (void *)tmp;
+  int ret;
 
   /* CURRENT_REGS non-zero indicates that we are processing an interrupt.
    * CURRENT_REGS is also used to manage interrupt level context switches.
    */
 
-  if (sim_saveusercontext(regs) == 0)
+  sim_saveusercontext(regs, ret);
+  if (ret == 0)
     {
       CURRENT_REGS = regs;
 
diff --git a/arch/sim/src/sim/sim_internal.h b/arch/sim/src/sim/sim_internal.h
index 71a91a8839..e498c987b5 100644
--- a/arch/sim/src/sim/sim_internal.h
+++ b/arch/sim/src/sim/sim_internal.h
@@ -85,17 +85,20 @@
 #define sim_savestate(regs) sim_copyfullstate(regs, (xcpt_reg_t *)CURRENT_REGS)
 #define sim_restorestate(regs) (CURRENT_REGS = regs)
 
-#define sim_saveusercontext(saveregs)                           \
-    ({                                                          \
-       irqstate_t flags = up_irq_flags();                       \
-       xcpt_reg_t *env = saveregs;                              \
-       uint32_t *val = (uint32_t *)&env[JB_FLAG];               \
+#define sim_saveusercontext(saveregs, ret)                      \
+    do                                                          \
+      {                                                         \
+        irqstate_t flags = up_irq_flags();                      \
+        xcpt_reg_t *env = saveregs;                             \
+        uint32_t *val = (uint32_t *)&env[JB_FLAG];              \
                                                                 \
-       val[0] = flags & UINT32_MAX;                             \
-       val[1] = (flags >> 32) & UINT32_MAX;                     \
+        val[0] = flags & UINT32_MAX;                            \
+        val[1] = (flags >> 32) & UINT32_MAX;                    \
                                                                 \
-       setjmp(saveregs);                                        \
-    })
+        ret = setjmp(saveregs);                                 \
+      }                                                         \
+    while (0)
+
 #define sim_fullcontextrestore(restoreregs)                     \
     do                                                          \
       {                                                         \
diff --git a/arch/sim/src/sim/sim_saveusercontext.c b/arch/sim/src/sim/sim_saveusercontext.c
index df99e8a157..95b9a7292f 100644
--- a/arch/sim/src/sim/sim_saveusercontext.c
+++ b/arch/sim/src/sim/sim_saveusercontext.c
@@ -48,5 +48,9 @@
 
 int up_saveusercontext(void *saveregs)
 {
-  return sim_saveusercontext(saveregs);
+  int ret;
+
+  sim_saveusercontext(saveregs, ret);
+
+  return ret;
 }
diff --git a/arch/sim/src/sim/sim_switchcontext.c b/arch/sim/src/sim/sim_switchcontext.c
index 3ecb284d71..182d1a375b 100644
--- a/arch/sim/src/sim/sim_switchcontext.c
+++ b/arch/sim/src/sim/sim_switchcontext.c
@@ -53,6 +53,8 @@
 
 void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
 {
+  int ret;
+
   sinfo("Unblocking TCB=%p\n", tcb);
 
   /* Update scheduler parameters */
@@ -80,6 +82,8 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
       /* Then switch contexts */
 
       sim_restorestate(tcb->xcp.regs);
+
+      return;
     }
 
   /* Copy the exception context into the TCB of the task that was
@@ -87,7 +91,8 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
    * then this is really the previously running task restarting!
    */
 
-  else if (!sim_saveusercontext(rtcb->xcp.regs))
+  sim_saveusercontext(rtcb->xcp.regs, ret);
+  if (ret == 0)
     {
       sinfo("New Active Task TCB=%p\n", tcb);
 


[nuttx] 02/02: sim: fix nuttx consumes much CPU time

Posted by ma...@apache.org.
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(&current);
+  if (clock_timespec_compare(&priv->alarm, &current) > 0)
     {
-      struct timespec current;
+      return; /* Alarm doesn't expire yet */
+    }
 
-      sim_timer_current(&current);
-      if (clock_timespec_compare(&priv->alarm, &current) > 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(&current);
   clock_timespec_subtract(&priv->alarm, &current, 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
 }