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/07/27 23:37:30 UTC

[incubator-nuttx] branch master updated (a58193a -> 78862c5)

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/incubator-nuttx.git.


    from a58193a  arch: imxrt: Fix style violations in imxrt_enet.c
     new f2446ec  arch/sim: unify the prefix(g_cpu_) for SMP related variables
     new 71a9d24  arch/sim: Replace sigprocmask with pthread_sigmask in main thread
     new 53f33a7  arch/sim: Synchronize the creation of idle thread by semaphore
     new 78862c5  arch/sim: Fix the wrong sleep time calculation in sim_idle_trampoline

The 4 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/up_simsmp.c | 68 ++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 41 deletions(-)


[incubator-nuttx] 03/04: arch/sim: Synchronize the creation of idle thread by semaphore

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/incubator-nuttx.git

commit 53f33a7ea264f1c07bc2d4835614ab7114954ad7
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jul 25 23:22:28 2020 +0800

    arch/sim: Synchronize the creation of idle thread by semaphore
    
    it's wrong to synchronize with mutex here
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_simsmp.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 68c8469..7c78005 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -39,6 +39,7 @@
 
 #include <stdint.h>
 #include <pthread.h>
+#include <semaphore.h>
 #include <signal.h>
 #include <errno.h>
 
@@ -63,8 +64,8 @@ typedef unsigned char spinlock_t;
 
 struct sim_cpuinfo_s
 {
-  int cpu;                /* CPU number */
-  pthread_mutex_t mutex;  /* For synchronization */
+  int cpu;    /* CPU number */
+  sem_t done; /* For synchronization */
 };
 
 /****************************************************************************
@@ -159,7 +160,7 @@ static void *sim_idle_trampoline(void *arg)
 
   /* Let up_cpu_start() continue */
 
-  pthread_mutex_unlock(&cpuinfo->mutex);
+  sem_post(&cpuinfo->done);
 
   /* 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 definition.
@@ -344,19 +345,10 @@ int up_cpu_start(int cpu)
   /* Initialize the CPU info */
 
   cpuinfo.cpu = cpu;
-  ret = pthread_mutex_init(&cpuinfo.mutex, NULL);
+  ret = sem_init(&cpuinfo.done, 0, 0);
   if (ret != 0)
     {
-      return -ret;  /* REVISIT:  That is a host errno value. */
-    }
-
-  /* Lock the mutex */
-
-  ret = pthread_mutex_lock(&cpuinfo.mutex);
-  if (ret != 0)
-    {
-      ret = -ret;  /* REVISIT: This is a host errno value. */
-      goto errout_with_mutex;
+      return -errno;  /* REVISIT:  That is a host errno value. */
     }
 
   /* Start the CPU emulation thread.  This is analogous to starting the CPU
@@ -368,24 +360,19 @@ int up_cpu_start(int cpu)
   if (ret != 0)
     {
       ret = -ret;  /* REVISIT:  That is a host errno value. */
-      goto errout_with_lock;
+      goto errout_with_sem;
     }
 
-  /* Try to lock the mutex again.  This will block until the pthread unlocks
-   * the mutex.
-   */
+  /* This will block until the pthread post the semaphore */
 
-  ret = pthread_mutex_lock(&cpuinfo.mutex);
+  ret = sem_wait(&cpuinfo.done);
   if (ret != 0)
     {
-      ret = -ret;  /* REVISIT:  That is a host errno value. */
+      ret = -errno;  /* REVISIT:  That is a host errno value. */
     }
 
-errout_with_lock:
-  pthread_mutex_unlock(&cpuinfo.mutex);
-
-errout_with_mutex:
-  pthread_mutex_destroy(&cpuinfo.mutex);
+errout_with_sem:
+  sem_destroy(&cpuinfo.done);
   return ret;
 }
 


[incubator-nuttx] 04/04: arch/sim: Fix the wrong sleep time calculation in sim_idle_trampoline

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/incubator-nuttx.git

commit 78862c51dceda641edfdc00a57e66d2825f63e67
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jul 25 23:31:54 2020 +0800

    arch/sim: Fix the wrong sleep time calculation in sim_idle_trampoline
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_simsmp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 7c78005..2584347 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -135,6 +135,9 @@ void sched_note_cpu_resume(struct tcb_s *tcb, int cpu);
 static void *sim_idle_trampoline(void *arg)
 {
   struct sim_cpuinfo_s *cpuinfo = (struct sim_cpuinfo_s *)arg;
+#ifdef CONFIG_SIM_WALLTIME
+  uint64_t now = 0;
+#endif
   sigset_t set;
   int ret;
 
@@ -173,8 +176,6 @@ static void *sim_idle_trampoline(void *arg)
   for (; ; )
     {
 #ifdef CONFIG_SIM_WALLTIME
-      uint64_t now = 0;
-
       /* Wait a bit so that the timing is close to the correct rate. */
 
       now += 1000 * CONFIG_USEC_PER_TICK;


[incubator-nuttx] 01/04: arch/sim: unify the prefix(g_cpu_) for SMP related variables

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/incubator-nuttx.git

commit f2446ecb901da1d0d509376cdb1ddeb7d972cc96
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jul 25 23:10:21 2020 +0800

    arch/sim: unify the prefix(g_cpu_) for SMP related variables
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_simsmp.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 669562d..22f68a5 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -37,8 +37,6 @@
  * Included Files
  ****************************************************************************/
 
-#define _GNU_SOURCE 1
-
 #include <stdint.h>
 #include <pthread.h>
 #include <signal.h>
@@ -73,8 +71,8 @@ struct sim_cpuinfo_s
  * Private Data
  ****************************************************************************/
 
-static pthread_key_t          g_cpukey;
-static pthread_t              g_sim_cputhread[CONFIG_SMP_NCPUS];
+static pthread_key_t g_cpu_key;
+static pthread_t     g_cpu_thread[CONFIG_SMP_NCPUS];
 
 /* These spinlocks are used in the SMP configuration in order to implement
  * up_cpu_pause().  The protocol for CPUn to pause CPUm is as follows
@@ -139,9 +137,9 @@ static void *sim_idle_trampoline(void *arg)
   sigset_t set;
   int ret;
 
-  /* Set the CPU number zero for the CPU thread */
+  /* Set the CPU number for the CPU thread */
 
-  ret = pthread_setspecific(g_cpukey,
+  ret = pthread_setspecific(g_cpu_key,
                            (const void *)((uintptr_t)cpuinfo->cpu));
   if (ret != 0)
     {
@@ -207,7 +205,7 @@ static void *sim_idle_trampoline(void *arg)
 
 static void sim_handle_signal(int signo, siginfo_t *info, void *context)
 {
-  int cpu = (int)((uintptr_t)pthread_getspecific(g_cpukey));
+  int cpu = (int)((uintptr_t)pthread_getspecific(g_cpu_key));
 
   up_cpu_paused(cpu);
 }
@@ -237,11 +235,11 @@ void sim_cpu0_start(void)
   sigset_t set;
   int ret;
 
-  g_sim_cputhread[0] = pthread_self();
+  g_cpu_thread[0] = pthread_self();
 
   /* Create the pthread key */
 
-  ret = pthread_key_create(&g_cpukey, NULL);
+  ret = pthread_key_create(&g_cpu_key, NULL);
   if (ret != 0)
     {
       return;
@@ -249,7 +247,7 @@ void sim_cpu0_start(void)
 
   /* Set the CPU number zero for the CPU thread */
 
-  ret = pthread_setspecific(g_cpukey, (const void *)0);
+  ret = pthread_setspecific(g_cpu_key, (const void *)0);
   if (ret != 0)
     {
       return;
@@ -301,7 +299,7 @@ void sim_cpu0_start(void)
 
 int up_cpu_index(void)
 {
-  void *value = pthread_getspecific(g_cpukey);
+  void *value = pthread_getspecific(g_cpu_key);
   return (int)((uintptr_t)value);
 }
 
@@ -365,7 +363,7 @@ int up_cpu_start(int cpu)
    * in a multi-CPU hardware model.
    */
 
-  ret = pthread_create(&g_sim_cputhread[cpu],
+  ret = pthread_create(&g_cpu_thread[cpu],
                        NULL, sim_idle_trampoline, &cpuinfo);
   if (ret != 0)
     {
@@ -426,7 +424,7 @@ int up_cpu_pause(int cpu)
 
   /* Signal the CPU thread */
 
-  pthread_kill(g_sim_cputhread[cpu], SIGUSR1);
+  pthread_kill(g_cpu_thread[cpu], SIGUSR1);
 
   /* Spin, waiting for the thread to pause */
 


[incubator-nuttx] 02/04: arch/sim: Replace sigprocmask with pthread_sigmask in main thread

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/incubator-nuttx.git

commit 71a9d2402de505ea7d1f8f556b1fdbf2f85f1111
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Jul 25 23:25:34 2020 +0800

    arch/sim: Replace sigprocmask with pthread_sigmask in main thread
    
    like other idle thread
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_simsmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c
index 22f68a5..68c8469 100644
--- a/arch/sim/src/sim/up_simsmp.c
+++ b/arch/sim/src/sim/up_simsmp.c
@@ -270,7 +270,7 @@ void sim_cpu0_start(void)
   sigemptyset(&set);
   sigaddset(&set, SIGUSR1);
 
-  ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
+  ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
   if (ret < 0)
     {
       return;