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/10/25 22:37:08 UTC

[incubator-nuttx] branch revert-1914-sene/arch_sim_improve_cpu_pausereq created (now eec2990)

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

masayuki pushed a change to branch revert-1914-sene/arch_sim_improve_cpu_pausereq
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


      at eec2990  Revert "arch/sim: Make the SIGUSR1 host signal to use the NuttX irq logic"

This branch includes the following new commits:

     new eec2990  Revert "arch/sim: Make the SIGUSR1 host signal to use the NuttX irq logic"

The 1 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.



[incubator-nuttx] 01/01: Revert "arch/sim: Make the SIGUSR1 host signal to use the NuttX irq logic"

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch revert-1914-sene/arch_sim_improve_cpu_pausereq
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit eec2990b82e238ffb8399f5bbd14ae506f651196
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Mon Oct 26 07:36:58 2020 +0900

    Revert "arch/sim: Make the SIGUSR1 host signal to use the NuttX irq logic"
    
    This reverts commit d6210fcd84dfd7b3bc3bac6cd6d3ee00c4f92239.
---
 arch/sim/include/arch.h         | 33 +++++++++++++++++++++++++
 arch/sim/src/sim/up_internal.h  |  1 -
 arch/sim/src/sim/up_simsmp.c    | 55 +++++++++++++++++++++++++++++++++++++++--
 arch/sim/src/sim/up_smpsignal.c | 45 ---------------------------------
 4 files changed, 86 insertions(+), 48 deletions(-)

diff --git a/arch/sim/include/arch.h b/arch/sim/include/arch.h
index 3fca681..4798968 100644
--- a/arch/sim/include/arch.h
+++ b/arch/sim/include/arch.h
@@ -41,6 +41,14 @@
 #define __ARCH_SIM_INCLUDE_ARCH_H
 
 /****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
  * Inline functions
  ****************************************************************************/
 
@@ -53,4 +61,29 @@ static inline uintptr_t sim_getsp(void)
   return (uintptr_t)__builtin_frame_address(0);
 }
 
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __ARCH_SIM_INCLUDE_ARCH_H */
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index ac7d221..2741c64 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -242,7 +242,6 @@ void sim_cpu0_start(void);
 void up_cpu_started(void);
 int up_cpu_paused(int cpu);
 struct tcb_s *up_this_task(void);
-int up_cpu_set_pause_handler(int irq);
 #endif
 
 /* up_oneshot.c *************************************************************/
diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 478b4d7..56f8ac6 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -123,6 +123,7 @@ static void *sim_idle_trampoline(void *arg)
 #ifdef CONFIG_SIM_WALLTIME
   uint64_t now = 0;
 #endif
+  sigset_t set;
   int ret;
 
   /* Set the CPU number for the CPU thread */
@@ -136,7 +137,14 @@ static void *sim_idle_trampoline(void *arg)
 
   /* Make sure the SIGUSR1 is not masked */
 
-  up_cpu_set_pause_handler(SIGUSR1);
+  sigemptyset(&set);
+  sigaddset(&set, SIGUSR1);
+
+  ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+  if (ret < 0)
+    {
+      return NULL;
+    }
 
   /* Let up_cpu_start() continue */
 
@@ -173,6 +181,28 @@ static void *sim_idle_trampoline(void *arg)
 }
 
 /****************************************************************************
+ * Name: sim_handle_signal
+ *
+ * Description:
+ *   This is the SIGUSR signal handler.  It implements the core logic of
+ *   up_cpu_pause() on the thread of execution the simulated CPU.
+ *
+ * Input Parameters:
+ *   arg - Standard sigaction arguments
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void sim_handle_signal(int signo, siginfo_t *info, void *context)
+{
+  int cpu = (int)((uintptr_t)pthread_getspecific(g_cpu_key));
+
+  up_cpu_paused(cpu);
+}
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -193,6 +223,8 @@ static void *sim_idle_trampoline(void *arg)
 
 void sim_cpu0_start(void)
 {
+  struct sigaction act;
+  sigset_t set;
   int ret;
 
   g_cpu_thread[0] = pthread_self();
@@ -215,7 +247,26 @@ void sim_cpu0_start(void)
 
   /* Register the common signal handler for all threads */
 
-  up_cpu_set_pause_handler(SIGUSR1);
+  act.sa_sigaction = sim_handle_signal;
+  act.sa_flags     = SA_SIGINFO;
+  sigemptyset(&act.sa_mask);
+
+  ret = sigaction(SIGUSR1, &act, NULL);
+  if (ret < 0)
+    {
+      return;
+    }
+
+  /* Make sure the SIGUSR1 is not masked */
+
+  sigemptyset(&set);
+  sigaddset(&set, SIGUSR1);
+
+  ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+  if (ret < 0)
+    {
+      return;
+    }
 }
 
 /****************************************************************************
diff --git a/arch/sim/src/sim/up_smpsignal.c b/arch/sim/src/sim/up_smpsignal.c
index 7417a87..0179bbc 100644
--- a/arch/sim/src/sim/up_smpsignal.c
+++ b/arch/sim/src/sim/up_smpsignal.c
@@ -47,32 +47,6 @@
 #include "up_internal.h"
 
 /****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: sim_cpupause_handler
- *
- * Description:
- *   This is the SIGUSR signal handler.  It implements the core logic of
- *   up_cpu_pause() on the thread of execution the simulated CPU.
- *
- * Input Parameters:
- *   irq - the interrupt number
- *   context  - not used
- *   arg      - not used
- *
- * Returned Value:
- *   In case of success OK (0) is returned otherwise a negative value.
- *
- ****************************************************************************/
-
-static int sim_cpupause_handler(int irq, FAR void *context, FAR void *arg)
-{
-  return up_cpu_paused(this_cpu());
-}
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -230,22 +204,3 @@ struct tcb_s *up_this_task(void)
 {
   return this_task();
 }
-
-/****************************************************************************
- * Name: up_cpu_set_pause_handler
- *
- * Description:
- *   Attach the CPU pause request interrupt to the NuttX logic.
- *
- * Input Parameters:
- *   irq - the SIGUSR1 interrupt number
- *
- * Returned Value:
- *   On success returns OK (0), otherwise a negative value.
- ****************************************************************************/
-
-int up_cpu_set_pause_handler(int irq)
-{
-  up_enable_irq(irq);
-  return irq_attach(irq, sim_cpupause_handler, NULL);
-}