2016-02-10 20:49:27 +01:00
|
|
|
/****************************************************************************
|
2019-02-04 23:20:35 +01:00
|
|
|
* sched/init/nx_smpstart.c
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
2019-02-04 23:20:35 +01:00
|
|
|
* Copyright (C) 2016, 2019 Gregory Nutt. All rights reserved.
|
2016-02-10 20:49:27 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2016-02-11 21:11:26 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <queue.h>
|
2016-02-10 20:49:27 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
2016-02-11 21:11:26 +01:00
|
|
|
#include <nuttx/sched.h>
|
2016-05-17 20:06:32 +02:00
|
|
|
#include <nuttx/sched_note.h>
|
2016-02-10 20:49:27 +01:00
|
|
|
|
2016-02-11 21:11:26 +01:00
|
|
|
#include "group/group.h"
|
|
|
|
#include "sched/sched.h"
|
2016-02-11 19:18:54 +01:00
|
|
|
#include "init/init.h"
|
2016-02-10 20:49:27 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-03-12 22:29:33 +01:00
|
|
|
* Public Functions
|
2016-02-10 20:49:27 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-02-04 23:20:35 +01:00
|
|
|
* Name: nx_idle_trampoline
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-03-13 14:16:56 +01:00
|
|
|
* This is the common start-up logic for the IDLE task for CPUs 1 through
|
|
|
|
* (CONFIG_SMP_NCPUS-1). Having a start-up function such as this for the
|
|
|
|
* IDLE is not really an architectural necessity. It is used only for
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* symmetry with now other threads are started (see nxtask_start() and
|
2016-03-13 14:16:56 +01:00
|
|
|
* pthread_start()).
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-03-13 14:16:56 +01:00
|
|
|
* None.
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This function does not return.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-04 23:20:35 +01:00
|
|
|
void nx_idle_trampoline(void)
|
2016-03-12 22:29:33 +01:00
|
|
|
{
|
2016-03-17 16:49:43 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
2016-03-13 14:16:56 +01:00
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Announce that the IDLE task has started */
|
|
|
|
|
|
|
|
sched_note_start(tcb);
|
|
|
|
#endif
|
|
|
|
|
2016-03-13 14:16:56 +01:00
|
|
|
/* Then transfer control to the IDLE task */
|
2016-03-12 22:29:33 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nx_idle_task(0, NULL);
|
2016-03-12 22:29:33 +01:00
|
|
|
|
|
|
|
/* The IDLE task should never return */
|
|
|
|
|
2018-08-24 14:21:15 +02:00
|
|
|
DEBUGPANIC();
|
2016-03-12 22:29:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-02-04 23:20:35 +01:00
|
|
|
* Name: nx_idle_task
|
2016-03-12 22:29:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the common IDLE task for CPUs 1 through (CONFIG_SMP_NCPUS-1).
|
2019-02-04 23:20:35 +01:00
|
|
|
* It is equivalent to the CPU 0 IDLE logic in nx_start.c
|
2016-03-12 22:29:33 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard task arguments.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This function does not return.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-04 23:20:35 +01:00
|
|
|
int nx_idle_task(int argc, FAR char *argv[])
|
2016-02-10 20:49:27 +01:00
|
|
|
{
|
2016-02-11 19:18:54 +01:00
|
|
|
/* Enter the IDLE loop */
|
2016-02-11 15:01:09 +01:00
|
|
|
|
2016-06-12 00:42:42 +02:00
|
|
|
sinfo("CPU%d: Beginning Idle Loop\n", this_cpu());
|
2016-02-17 02:33:22 +01:00
|
|
|
|
2016-02-10 20:49:27 +01:00
|
|
|
for (; ; )
|
|
|
|
{
|
|
|
|
/* Perform any processor-specific idle state operations */
|
|
|
|
|
|
|
|
up_idle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-02-04 23:20:35 +01:00
|
|
|
* Name: nx_smp_start
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-19 19:19:43 +02:00
|
|
|
* In an SMP configuration, only one CPU is initially active (CPU 0).
|
|
|
|
* System initialization occurs on that single thread. At the completion
|
|
|
|
* of the initialization of the OS, just before beginning normal
|
|
|
|
* multitasking, the additional CPUs would be started by calling this
|
|
|
|
* function.
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-09-14 14:55:45 +02:00
|
|
|
* Zero on success; a negated errno value on failure.
|
2016-02-10 20:49:27 +01:00
|
|
|
*
|
2016-02-11 21:11:26 +01:00
|
|
|
* Assumption:
|
|
|
|
* Runs before the full initialization sequence has completed. Runs after
|
|
|
|
* all OS facilities are set up, but before multi-tasking has been started.
|
|
|
|
*
|
2016-02-10 20:49:27 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-04 23:20:35 +01:00
|
|
|
int nx_smp_start(void)
|
2016-02-10 20:49:27 +01:00
|
|
|
{
|
|
|
|
int ret;
|
2016-02-11 21:11:26 +01:00
|
|
|
int cpu;
|
|
|
|
|
2016-03-12 22:29:33 +01:00
|
|
|
/* Create a stack for all CPU IDLE threads (except CPU0 which already has
|
|
|
|
* a stack).
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++)
|
|
|
|
{
|
|
|
|
FAR struct tcb_s *tcb = current_task(cpu);
|
|
|
|
DEBUGASSERT(tcb != NULL);
|
|
|
|
|
2016-05-13 19:39:42 +02:00
|
|
|
ret = up_cpu_idlestack(cpu, tcb, CONFIG_SMP_IDLETHREAD_STACKSIZE);
|
2016-03-12 22:29:33 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
serr("ERROR: Failed to allocate stack for CPU%d\n", cpu);
|
2016-03-12 22:29:33 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2016-05-22 23:01:49 +02:00
|
|
|
|
|
|
|
/* Reinitialize the processor-specific portion of the TCB. This is
|
|
|
|
* the second time this has been called for this CPU, but the stack
|
|
|
|
* was not yet initialized on the first call so we need to do it
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_initial_state(tcb);
|
2016-03-12 22:29:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Then start all of the other CPUs after we have completed the memory
|
|
|
|
* allocations. CPU0 is already running.
|
|
|
|
*/
|
2016-02-10 20:49:27 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
for (cpu = 1; cpu < CONFIG_SMP_NCPUS; cpu++)
|
2016-02-10 20:49:27 +01:00
|
|
|
{
|
2016-03-12 22:29:33 +01:00
|
|
|
/* Start the CPU */
|
2016-02-11 21:11:26 +01:00
|
|
|
|
2016-03-12 22:29:33 +01:00
|
|
|
ret = up_cpu_start(cpu);
|
2016-02-10 20:49:27 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
serr("ERROR: Failed to start CPU%d: %d\n", cpu, ret);
|
2016-02-10 20:49:27 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SMP */
|