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. */ + /* We need to flush the D-Cache and Invalidate the I-Cache for + * the group whose environment is disappearing. + */ - 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. - */ - - 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 */