You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/05/08 17:34:37 UTC

[incubator-nuttx] branch master updated: sched/group: addrenv: allocate current group for each cpu

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 22787ee109 sched/group: addrenv: allocate current group for each cpu
22787ee109 is described below

commit 22787ee109c3dbe5366408aa1a443b0efa8f1d8d
Author: Oki Minabe <mi...@gmail.com>
AuthorDate: Fri May 6 18:58:38 2022 +0900

    sched/group: addrenv: allocate current group for each cpu
    
    Summary:
    - In case of SMP and ADDRENV, allocate current group for each cpu
      - g_pid_current holds pid of the group and uses for addrenv switching
      - allocate g_group_current for each cpu in stead of g_pid_current
      - g_group_current is the array that pointed to the current task_group_s struct
    
    Impact:
    - ADDRENV=y and SMP=y
    
    Testing:
    - sabre-6quad:smp w/ qemu
    - sabre-6quad:knsh w/ qemu
    - sabre-6quad:knsh_smp w/ qemu (WIP)
    
    Signed-off-by: Oki Minabe <mi...@gmail.com>
---
 sched/group/group.h         |  8 ++++----
 sched/group/group_addrenv.c | 42 ++++++++++++++++--------------------------
 sched/group/group_leave.c   |  9 ++++++++-
 3 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/sched/group/group.h b/sched/group/group.h
index 3b9fa98daf..7d9403f143 100644
--- a/sched/group/group.h
+++ b/sched/group/group.h
@@ -52,14 +52,14 @@ extern FAR struct task_group_s *g_grouphead;
 #endif
 
 #ifdef CONFIG_ARCH_ADDRENV
-/* This variable holds the PID of the current task group.  This ID is
- * zero if the current task is a kernel thread that has no address
- * environment (other than the kernel context).
+/* This variable holds the current task group.  This pointer is NULL
+ * if the current task is a kernel thread that has no address environment
+ * (other than the kernel context).
  *
  * This must only be accessed with interrupts disabled.
  */
 
-extern pid_t g_pid_current;
+extern FAR struct task_group_s *g_group_current[CONFIG_SMP_NCPUS];
 #endif
 
 /****************************************************************************
diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c
index 06b95f557c..41cd4a0ce2 100644
--- a/sched/group/group_addrenv.c
+++ b/sched/group/group_addrenv.c
@@ -39,14 +39,14 @@
  * Public Data
  ****************************************************************************/
 
-/* This variable holds the PID of the current task group.  This ID is
- * zero if the current task is a kernel thread that has no address
- * environment (other than the kernel context).
+/* This variable holds the current task group.  This pointer is NULL
+ * if the current task is a kernel thread that has no address environment
+ * (other than the kernel context).
  *
  * This must only be accessed with interrupts disabled.
  */
 
-pid_t g_pid_current = INVALID_PROCESS_ID;
+FAR struct task_group_s *g_group_current[CONFIG_SMP_NCPUS];
 
 /****************************************************************************
  * Public Functions
@@ -85,7 +85,7 @@ int group_addrenv(FAR struct tcb_s *tcb)
   FAR struct task_group_s *group;
   FAR struct task_group_s *oldgroup;
   irqstate_t flags;
-  pid_t pid;
+  int cpu;
   int ret;
 
   /* NULL for the tcb means to use the TCB of the task at the head of the
@@ -111,34 +111,24 @@ int group_addrenv(FAR struct tcb_s *tcb)
       return OK;
     }
 
-  /* Get the PID of the group that needs the address environment */
-
-  pid = group->tg_pid;
-  DEBUGASSERT(pid != INVALID_PROCESS_ID);
-
   /* Are we going to change address environments? */
 
   flags = enter_critical_section();
-  if (pid != g_pid_current)
+
+  cpu = this_cpu();
+  oldgroup = g_group_current[cpu];
+  if (group != oldgroup)
     {
       /* Yes.. Is there a current address environment in place? */
 
-      if (g_pid_current != INVALID_PROCESS_ID)
+      if (oldgroup)
         {
-          /* Find the old group with this ID. */
-
-          oldgroup = group_findbypid(g_pid_current);
-          DEBUGASSERT(oldgroup &&
-                      (oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0);
-
-          if (oldgroup)
-            {
-              /* We need to flush the D-Cache and Invalidate the I-Cache for
-               * the group whose environment is disappearing.
-               */
+          /* We need to flush the D-Cache and Invalidate the I-Cache for
+           * the group whose environment is disappearing.
+           */
 
-              up_addrenv_coherent(&oldgroup->tg_addrenv);
-            }
+          DEBUGASSERT((oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0);
+          up_addrenv_coherent(&oldgroup->tg_addrenv);
         }
 
       /* Instantiate the new address environment (removing the old
@@ -155,7 +145,7 @@ int group_addrenv(FAR struct tcb_s *tcb)
 
       /* Save the new, current group */
 
-      g_pid_current = pid;
+      g_group_current[cpu] = group;
     }
 
   leave_critical_section(flags);
diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c
index 9cfe4f7fc1..935b3cfc91 100644
--- a/sched/group/group_leave.c
+++ b/sched/group/group_leave.c
@@ -130,6 +130,7 @@ static inline void group_release(FAR struct task_group_s *group)
 {
 #ifdef CONFIG_ARCH_ADDRENV
   save_addrenv_t oldenv;
+  int i;
 #endif
 
 #if CONFIG_TLS_TASK_NELEM > 0
@@ -248,7 +249,13 @@ static inline void group_release(FAR struct task_group_s *group)
 
   /* Mark no address environment */
 
-  g_pid_current = INVALID_PROCESS_ID;
+  for (i = 0; i < CONFIG_SMP_NCPUS; i++)
+    {
+      if (group == g_group_current[i])
+        {
+          g_group_current[i] = NULL;
+        }
+    }
 
   /* Restore the previous addrenv */