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 2020/11/13 06:38:49 UTC

[incubator-nuttx] 01/03: sched: task: Fix nxtask_exit() for SMP

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

masayuki pushed a commit to branch releases/10.0
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit d51e7361f611e40f933689fe382a4f5713e915d0
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Mon Nov 9 16:31:57 2020 +0900

    sched: task: Fix nxtask_exit() for SMP
    
    Summary:
    - I noticed that nxsched_merge_pending() is called outside a critical section
    - The issue happens if a new rtcb does not hold a critical section
    - Actually, global IRQ control is done in nxsched_resume_scheduler() in nxtask_exit()
    - However, nxsched_merge_pending() was called after calling nxsched_resume_scheduler()
    - This commit fixes the issue by moving nxsched_merge_pending() before the function
    - NOTE: the sequence was changed for SMP but works for non-SMP as well
    
    Impact:
    - This commit affects both SMP and non-SMP
    
    Testing:
    - Tested with ostest with the following configurations
    - spresense:wifi_smp (NCPUS=2 and 4)
    - spresense:wifi (non SMP)
    - sabre-6quad:smp (QEMU)
    - esp32-core:smp (QEMU)
    - maix-bit:smp (QEMU)
    - sim:smp
    - lc823450-xgevk:rndis
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 sched/task/task_exit.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c
index 6607f49..d570e45 100644
--- a/sched/task/task_exit.c
+++ b/sched/task/task_exit.c
@@ -102,6 +102,15 @@ int nxtask_exit(void)
 
   nxsched_remove_readytorun(dtcb);
 
+  /* If there are any pending tasks, then add them to the ready-to-run
+   * task list now
+   */
+
+  if (g_pendingtasks.head != NULL)
+    {
+      nxsched_merge_pending();
+    }
+
   /* Get the new task at the head of the ready to run list */
 
 #ifdef CONFIG_SMP
@@ -190,14 +199,5 @@ int nxtask_exit(void)
     }
 #endif
 
-  /* If there are any pending tasks, then add them to the ready-to-run
-   * task list now
-   */
-
-  if (g_pendingtasks.head != NULL)
-    {
-      nxsched_merge_pending();
-    }
-
   return ret;
 }