SMP: Simplified SMP interfaces

This commit is contained in:
Gregory Nutt 2016-03-12 15:29:33 -06:00
parent 320b70ebad
commit 79c1fa5bd7
5 changed files with 83 additions and 22 deletions

2
arch

@ -1 +1 @@
Subproject commit 211160ebe8733a5456a49b88ef4c27482690b5d6 Subproject commit 9336bbac1c82d417d65d0a973359e4fad25e2dd1

View File

@ -1743,7 +1743,6 @@ int up_cpu_index(void);
* cpu - The index of the CPU being started. This will be a numeric * cpu - The index of the CPU being started. This will be a numeric
* value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU
* 0 is already active) * 0 is already active)
* idletask - The entry point to the IDLE task.
* *
* Returned Value: * Returned Value:
* Zero on success; a negated errno value on failure. * Zero on success; a negated errno value on failure.
@ -1751,7 +1750,7 @@ int up_cpu_index(void);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
int up_cpu_start(int cpu, main_t idletask); int up_cpu_start(int cpu);
#endif #endif
/**************************************************************************** /****************************************************************************

View File

@ -65,7 +65,7 @@
void os_start(void); void os_start(void);
/**************************************************************************** /****************************************************************************
* Name: os_smpstart * Name: os_smp_start
* *
* Description: * Description:
* In an SMP configution, only one CPU is initially active (CPU 0). System * In an SMP configution, only one CPU is initially active (CPU 0). System
@ -82,11 +82,11 @@ void os_start(void);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
int os_smpstart(void); int os_smp_start(void);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: os_idletask * Name: os_idle_trampoline
* *
* Description: * Description:
* This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1).
@ -101,7 +101,26 @@ int os_smpstart(void);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
int os_idletask(int argc, FAR char *argv[]); void os_idle_trampoline(void);
#endif
/****************************************************************************
* Name: os_idle_task
*
* Description:
* This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1).
* It is equivalent to the CPU 0 IDLE logic in os_start.c
*
* Input Parameters:
* Standard task arguments.
*
* Returned Value:
* This function does not return.
*
****************************************************************************/
#ifdef CONFIG_SMP
int os_idle_task(int argc, FAR char *argv[]);
#endif #endif
/**************************************************************************** /****************************************************************************

View File

@ -42,7 +42,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include <queue.h> #include <queue.h>
#include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
@ -74,11 +73,11 @@ static const char g_idlename[] = "CPUn Idle"
#endif #endif
/**************************************************************************** /****************************************************************************
* Private Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: os_idletask * Name: os_idle_trampoline
* *
* Description: * Description:
* This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1). * This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1).
@ -92,7 +91,33 @@ static const char g_idlename[] = "CPUn Idle"
* *
****************************************************************************/ ****************************************************************************/
int os_idletask(int argc, FAR char *argv[]) void os_idle_trampoline(void)
{
/* Transfer control to the IDLE task */
(void)os_idle_task(0, NULL);
/* The IDLE task should never return */
PANIC();
}
/****************************************************************************
* Name: os_idle_task
*
* Description:
* This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1).
* It is equivalent to the CPU 0 IDLE logic in os_start.c
*
* Input Parameters:
* Standard task arguments.
*
* Returned Value:
* This function does not return.
*
****************************************************************************/
int os_idle_task(int argc, FAR char *argv[])
{ {
/* Enter the IDLE loop */ /* Enter the IDLE loop */
@ -133,11 +158,7 @@ int os_idletask(int argc, FAR char *argv[])
} }
/**************************************************************************** /****************************************************************************
* Public Functions * Name: os_smp_start
****************************************************************************/
/****************************************************************************
* Name: os_smpstart
* *
* Description: * Description:
* In an SMP configution, only one CPU is initially active (CPU 0). System * In an SMP configution, only one CPU is initially active (CPU 0). System
@ -157,18 +178,38 @@ int os_idletask(int argc, FAR char *argv[])
* *
****************************************************************************/ ****************************************************************************/
int os_smpstart(void) int os_smp_start(void)
{ {
int ret; int ret;
int cpu; int cpu;
/* CPU0 is already running. Start the remaining CPUs */ /* Create a stack for all CPU IDLE threads (except CPU0 which already has
* a stack).
*/
for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++) for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++)
{ {
/* And start the CPU. */ FAR struct tcb_s *tcb = current_task(cpu);
DEBUGASSERT(tcb != NULL);
ret = up_cpu_start(cpu, os_idletask); ret = up_create_stack(tcb, CONFIG_SMP_IDLETHREAD_STACKSIZE,
TCB_FLAG_TTYPE_KERNEL);
if (ret < 0)
{
sdbg("ERROR: Failed to allocate stack for CPU%d\n", cpu);
return ret;
}
}
/* Then start all of the other CPUs after we have completed the memory
* allocations. CPU0 is already running.
*/
for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++)
{
/* Start the CPU */
ret = up_cpu_start(cpu);
if (ret < 0) if (ret < 0)
{ {
sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret); sdbg("ERROR: Failed to start CPU%d: %d\n", cpu, ret);

View File

@ -453,11 +453,13 @@ void os_start(void)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
if (cpu > 0) if (cpu > 0)
{ {
g_idletcb[cpu].cmn.entry.main = os_idletask; g_idletcb[cpu].cmn.start = os_idle_trampoline;
g_idletcb[cpu].cmn.entry.main = os_idle_task;
} }
else else
#endif #endif
{ {
g_idletcb[cpu].cmn.start = (start_t)os_start;
g_idletcb[cpu].cmn.entry.main = (main_t)os_start; g_idletcb[cpu].cmn.entry.main = (main_t)os_start;
} }
@ -762,7 +764,7 @@ void os_start(void)
/* Then start the other CPUs */ /* Then start the other CPUs */
DEBUGVERIFY(os_smpstart()); DEBUGVERIFY(os_smp_start());
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */