You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/09 13:38:53 UTC

[incubator-nuttx] 06/07: arch/sim: fix up_idle call the wrong pthread_yield version

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

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

commit 599f05c4b40ed66c10ce77e26bda887ec998875c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Feb 9 14:36:02 2020 +0800

    arch/sim: fix up_idle call the wrong pthread_yield version
    
    The logic want the host version but link to NuttX version
    
    Change-Id: I41d7d294d38c9ef6fbbf0f63268fffe637099eb1
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/Makefile           |  4 +-
 arch/sim/src/sim/up_idle.c      | 35 -----------------
 arch/sim/src/sim/up_internal.h  |  9 +----
 arch/sim/src/sim/up_simsmp.c    | 24 ++++++------
 arch/sim/src/sim/up_smphook.c   | 85 -----------------------------------------
 arch/sim/src/sim/up_smpsignal.c | 20 ++++++++++
 6 files changed, 36 insertions(+), 141 deletions(-)

diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
index 6e05767..3ea0c70 100644
--- a/arch/sim/src/Makefile
+++ b/arch/sim/src/Makefile
@@ -89,8 +89,8 @@ ifeq ($(CONFIG_SPINLOCK),y)
 endif
 
 ifeq ($(CONFIG_SMP),y)
-  CSRCS += up_smpsignal.c up_smphook.c up_cpuidlestack.c
-  REQUIREDOBJS += up_smpsignal$(OBJEXT) up_smphook$(OBJEXT)
+  CSRCS += up_smpsignal.c up_cpuidlestack.c
+  REQUIREDOBJS += up_smpsignal$(OBJEXT)
   HOSTCFLAGS += -DCONFIG_SMP=1 -DCONFIG_SMP_NCPUS=$(CONFIG_SMP_NCPUS)
   HOSTSRCS += up_simsmp.c
   STDLIBS += -lpthread
diff --git a/arch/sim/src/sim/up_idle.c b/arch/sim/src/sim/up_idle.c
index 1848d45..2b53cbf 100644
--- a/arch/sim/src/sim/up_idle.c
+++ b/arch/sim/src/sim/up_idle.c
@@ -40,15 +40,10 @@
 
 #include <nuttx/config.h>
 
-#include <pthread.h>
 #include <time.h>
 
 #include <nuttx/arch.h>
 
-#ifdef CONFIG_SMP
-#  include <nuttx/spinlock.h>
-#endif
-
 #include "up_internal.h"
 
 /****************************************************************************
@@ -94,26 +89,6 @@ extern void up_x11update(void);
 
 void up_idle(void)
 {
-#ifdef CONFIG_SMP
-  /* In the SMP configuration, only one CPU should do these operations.  It
-   * should not matter which, however.
-   */
-
-  static volatile spinlock_t lock SP_SECTION = SP_UNLOCKED;
-
-  /* The one that gets the lock is the one that executes the IDLE operations */
-
-  if (up_testset(&lock) != SP_UNLOCKED)
-    {
-      /* We didn't get it... Give other pthreads/CPUs a shot and try again
-       * later.
-       */
-
-      pthread_yield();
-      return;
-    }
-#endif
-
 #ifdef CONFIG_SCHED_TICKLESS
   /* Driver the simulated interval timer */
 
@@ -192,14 +167,4 @@ void up_idle(void)
     }
 #endif
 #endif
-
-#ifdef CONFIG_SMP
-  /* Release the spinlock */
-
-  lock = SP_UNLOCKED;
-
-  /* Give other pthreads/CPUs a shot */
-
-  pthread_yield();
-#endif
 }
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 2be6e0b..6f90e2d 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -245,14 +245,7 @@ void sim_cpu0_start(void);
 /* up_smpsignal.c ***********************************************************/
 
 #ifdef CONFIG_SMP
-void sim_cpu_pause(int cpu, FAR volatile spinlock_t *wait,
-                   FAR volatile unsigned char *paused);
-#endif
-
-/* up_smphook.c *************************************************************/
-
-#ifdef CONFIG_SMP
-void sim_smp_hook(void);
+void up_cpu_started(void);
 #endif
 
 /* up_tickless.c ************************************************************/
diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index a314418..5b67954 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -61,10 +61,6 @@
 
 typedef unsigned char spinlock_t;
 
-/* Task entry point type */
-
-typedef int (*main_t)(int argc, char **argv);
-
 struct sim_cpuinfo_s
 {
   int cpu;                /* CPU number */
@@ -99,9 +95,9 @@ volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS];
  * NuttX domain function prototypes
  ****************************************************************************/
 
-void nx_start(void) __attribute__ ((noreturn));
-void up_cpu_paused(int cpu);
-void sim_smp_hook(void);
+void nx_start(void);
+void up_cpu_started(void);
+int up_cpu_paused(int cpu);
 
 /****************************************************************************
  * Private Functions
@@ -156,14 +152,20 @@ static void *sim_idle_trampoline(void *arg)
 
   pthread_mutex_unlock(&cpuinfo->mutex);
 
-  /* Give control to the IDLE task via the nasty little sim_smp_hook().
-   * sim_smp_hook() is logically a part of this function but needs to be
+  /* up_cpu_started() is logically a part of this function but needs to be
    * inserted in the path because in needs to access NuttX domain definitions.
    */
 
-  sim_smp_hook();
+  up_cpu_started();
 
-  /* The IDLE task will not return.  This is just to keep the compiler happy */
+  /* The idle Loop */
+
+  for (; ; )
+    {
+      /* Give other pthreads/CPUs a shot */
+
+      pthread_yield();
+    }
 
   return NULL;
 }
diff --git a/arch/sim/src/sim/up_smphook.c b/arch/sim/src/sim/up_smphook.c
deleted file mode 100644
index e94625c..0000000
--- a/arch/sim/src/sim/up_smphook.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
- * arch/sim/src/sim/up_simhook.c
- *
- *   Copyright (C) 2016 Gregory Nutt. All rights reserved.
- *   Author: Gregory Nutt <gn...@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- *    used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <assert.h>
-
-#include <nuttx/sched.h>
-
-#include "sched/sched.h"
-
-#ifdef CONFIG_SMP
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: sim_smp_hook
- *
- * Description:
- *   This is a mindless little hook between sim_idle_trampoline() and the
- *   real IDLE task logic.  This is only needed because we need to access
- *   elements of the TCB in the simulation domain but sim_idle_trampoline()
- *   lies in the host domain.
- *
- * Input Parameters:
- *   None
- *
- * Returned Value:
- *   None (should not return)
- *
- ****************************************************************************/
-
-void sim_smp_hook(void)
-{
-  struct tcb_s *tcb = this_task();
-  DEBUGASSERT(tcb != NULL && tcb->start != NULL);
-
-  /* Transfer control to the "real" thread start-up routine */
-
-  tcb->start();
-
-  /* That function should not return. */
-
-  DEBUGPANIC();
-}
-
-#endif /* CONFIG_SMP */
diff --git a/arch/sim/src/sim/up_smpsignal.c b/arch/sim/src/sim/up_smpsignal.c
index da1d8bb..126269c 100644
--- a/arch/sim/src/sim/up_smpsignal.c
+++ b/arch/sim/src/sim/up_smpsignal.c
@@ -40,6 +40,7 @@
 #include <nuttx/config.h>
 
 #include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
 #include <nuttx/spinlock.h>
 
 #include "sched/sched.h"
@@ -158,4 +159,23 @@ int up_cpu_paused(int cpu)
   return OK;
 }
 
+/****************************************************************************
+ * Name: up_cpu_started
+ *
+ * Description:
+ *   Notify the current cpu start sucessfully.
+ *
+ ****************************************************************************/
+
+void up_cpu_started(void)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION
+  FAR struct tcb_s *tcb = this_task();
+
+  /* Announce that the IDLE task has started */
+
+  sched_note_start(tcb);
+#endif
+}
+
 #endif /* CONFIG_SMP */