2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 23:30:59 +02:00
|
|
|
* sched/init/os_start.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2016-02-05 15:34:03 +01:00
|
|
|
* Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved.
|
2012-03-04 00:18:34 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-01-09 02:13:24 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/lib/lib.h>
|
|
|
|
#include <nuttx/mm/mm.h>
|
|
|
|
#include <nuttx/mm/shm.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/sched_note.h>
|
|
|
|
#include <nuttx/syslog/syslog.h>
|
2018-08-23 17:09:39 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <nuttx/init.h>
|
|
|
|
|
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "signal/signal.h"
|
|
|
|
#include "wdog/wdog.h"
|
|
|
|
#include "semaphore/semaphore.h"
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2017-08-15 01:19:27 +02:00
|
|
|
# include "mqueue/mqueue.h"
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2017-08-15 01:19:27 +02:00
|
|
|
# include "pthread/pthread.h"
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
#include "clock/clock.h"
|
|
|
|
#include "timer/timer.h"
|
|
|
|
#include "irq/irq.h"
|
2013-01-26 00:21:27 +01:00
|
|
|
#ifdef HAVE_TASK_GROUP
|
2017-08-15 01:19:27 +02:00
|
|
|
# include "group/group.h"
|
2013-01-26 00:21:27 +01:00
|
|
|
#endif
|
2017-08-15 01:19:27 +02:00
|
|
|
#include "init/init.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* This set of all CPUs */
|
|
|
|
|
|
|
|
# define SCHED_ALL_CPUS ((1 << CONFIG_SMP_NCPUS) - 1)
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/* Task Lists ***************************************************************/
|
2012-07-14 21:30:31 +02:00
|
|
|
/* The state of a task is indicated both by the task_state field of the TCB
|
|
|
|
* and by a series of task lists. All of these tasks lists are declared
|
|
|
|
* below. Although it is not always necessary, most of these lists are
|
|
|
|
* prioritized so that common list handling logic can be used (only the
|
2016-02-10 18:45:26 +01:00
|
|
|
* g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists
|
|
|
|
* need to be prioritized).
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-10 18:45:26 +01:00
|
|
|
/* This is the list of all tasks that are ready to run. This is a
|
|
|
|
* prioritized list with head of the list holding the highest priority
|
2017-08-15 01:19:27 +02:00
|
|
|
* (unassigned) task. In the non-SMP case, the head of this list is the
|
2016-02-10 18:45:26 +01:00
|
|
|
* currently active task and the tail of this list, the lowest priority
|
|
|
|
* task, is always the IDLE task.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_readytorun;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-10 18:45:26 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* In order to support SMP, the function of the g_readytorun list changes,
|
2017-08-15 01:19:27 +02:00
|
|
|
* The g_readytorun is still used but in the SMP case it will contain only:
|
2016-02-10 18:45:26 +01:00
|
|
|
*
|
|
|
|
* - Only tasks/threads that are eligible to run, but not currently running,
|
|
|
|
* and
|
|
|
|
* - Tasks/threads that have not been assigned to a CPU.
|
|
|
|
*
|
2018-01-13 22:38:55 +01:00
|
|
|
* Otherwise, the TCB will be retained in an assigned task list,
|
2016-02-10 18:45:26 +01:00
|
|
|
* g_assignedtasks. As its name suggests, on 'g_assignedtasks queue for CPU
|
|
|
|
* 'n' would contain only tasks/threads that are assigned to CPU 'n'. Tasks/
|
|
|
|
* threads would be assigned a particular CPU by one of two mechanisms:
|
|
|
|
*
|
|
|
|
* - (Semi-)permanently through an RTOS interfaces such as
|
|
|
|
* pthread_attr_setaffinity(), or
|
|
|
|
* - Temporarily through scheduling logic when a previously unassigned task
|
|
|
|
* is made to run.
|
|
|
|
*
|
|
|
|
* Tasks/threads that are assigned to a CPU via an interface like
|
|
|
|
* pthread_attr_setaffinity() would never go into the g_readytorun list, but
|
|
|
|
* would only go into the g_assignedtasks[n] list for the CPU 'n' to which
|
|
|
|
* the thread has been assigned. Hence, the g_readytorun list would hold
|
|
|
|
* only unassigned tasks/threads.
|
|
|
|
*
|
|
|
|
* Like the g_readytorun list in in non-SMP case, each g_assignedtask[] list
|
|
|
|
* is prioritized: The head of the list is the currently active task on this
|
|
|
|
* CPU. Tasks after the active task are ready-to-run and assigned to this
|
|
|
|
* CPU. The tail of this assigned task list, the lowest priority task, is
|
|
|
|
* always the CPU's IDLE task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
volatile dq_queue_t g_assignedtasks[CONFIG_SMP_NCPUS];
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This is the list of all tasks that are ready-to-run, but cannot be placed
|
|
|
|
* in the g_readytorun list because: (1) They are higher priority than the
|
|
|
|
* currently active task at the head of the g_readytorun list, and (2) the
|
|
|
|
* currently active task has disabled pre-emption.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_pendingtasks;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a semaphore */
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingforsemaphore;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a signal */
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingforsignal;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a message
|
|
|
|
* queue to become non-empty.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingformqnotempty;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a message
|
|
|
|
* queue to become non-full.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingformqnotfull;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2010-08-14 03:56:13 +02:00
|
|
|
/* This is the list of all tasks that are blocking waiting for a page fill */
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING
|
|
|
|
volatile dq_queue_t g_waitingforfill;
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* This the list of all tasks that have been initialized, but not yet
|
|
|
|
* activated. NOTE: This is the only list that is not prioritized.
|
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_inactivetasks;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-13 22:38:55 +01:00
|
|
|
/* These are lists of delayed memory deallocations that need to be handled
|
2013-03-10 16:32:33 +01:00
|
|
|
* within the IDLE loop or worker thread. These deallocations get queued
|
|
|
|
* by sched_kufree and sched_kfree() if the OS needs to deallocate memory
|
|
|
|
* while it is within an interrupt handler.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2014-08-29 22:47:22 +02:00
|
|
|
#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \
|
|
|
|
defined(CONFIG_MM_KERNEL_HEAP)
|
2013-03-10 16:32:33 +01:00
|
|
|
volatile sq_queue_t g_delayed_kfree;
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-09-07 22:40:18 +02:00
|
|
|
#ifndef CONFIG_BUILD_KERNEL
|
|
|
|
/* REVISIT: It is not safe to defer user allocation in the kernel mode
|
|
|
|
* build. Why? Because the correct user context will not be in place
|
|
|
|
* when these deferred de-allocations are performed. In order to make this
|
|
|
|
* work, we would need to do something like: (1) move g_delayed_kufree
|
|
|
|
* into the group structure, then traverse the groups to collect garbage
|
|
|
|
* on a group-by-group basis.
|
|
|
|
*/
|
|
|
|
|
|
|
|
volatile sq_queue_t g_delayed_kufree;
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* This is the value of the last process ID assigned to a task */
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile pid_t g_lastpid;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* The following hash table is used for two things:
|
2007-03-01 22:05:55 +01:00
|
|
|
*
|
2016-02-11 15:06:33 +01:00
|
|
|
* 1. This hash table greatly speeds the determination of a new unique
|
|
|
|
* process ID for a task, and
|
2007-02-18 00:21:28 +01:00
|
|
|
* 2. Is used to quickly map a process ID into a TCB.
|
2007-03-01 22:05:55 +01:00
|
|
|
*
|
2016-10-26 20:29:36 +02:00
|
|
|
* It has the side effects of using more memory and limiting
|
2007-03-01 22:05:55 +01:00
|
|
|
* the number of tasks to CONFIG_MAX_TASKS.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2014-08-08 23:30:59 +02:00
|
|
|
struct pidhash_s g_pidhash[CONFIG_MAX_TASKS];
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-11 15:06:33 +01:00
|
|
|
/* This is a table of task lists. This table is indexed by the task stat
|
|
|
|
* enumeration type (tstate_t) and provides a pointer to the associated
|
|
|
|
* static task list (if there is one) as well as a a set of attribute flags
|
2018-01-13 15:34:58 +01:00
|
|
|
* indicating properties of the list, for example, if the list is an
|
2016-02-11 15:06:33 +01:00
|
|
|
* ordered list or not.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2014-08-08 23:30:59 +02:00
|
|
|
const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] =
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_TASK_INVALID */
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{ /* TSTATE_TASK_PENDING */
|
|
|
|
&g_pendingtasks,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
},
|
2016-02-12 15:15:16 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_TASK_READYTORUN */
|
|
|
|
&g_readytorun,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
},
|
|
|
|
{ /* TSTATE_TASK_ASSIGNED */
|
|
|
|
g_assignedtasks,
|
2016-02-12 15:15:16 +01:00
|
|
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED | TLIST_ATTR_RUNNABLE
|
2016-02-11 15:06:33 +01:00
|
|
|
},
|
|
|
|
{ /* TSTATE_TASK_RUNNING */
|
|
|
|
g_assignedtasks,
|
2016-02-12 15:15:16 +01:00
|
|
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_INDEXED | TLIST_ATTR_RUNNABLE
|
2016-02-11 15:06:33 +01:00
|
|
|
},
|
|
|
|
#else
|
2016-02-12 15:15:16 +01:00
|
|
|
{ /* TSTATE_TASK_READYTORUN */
|
|
|
|
&g_readytorun,
|
|
|
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE
|
|
|
|
},
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_TASK_RUNNING */
|
|
|
|
&g_readytorun,
|
2016-02-12 15:15:16 +01:00
|
|
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE
|
2016-02-11 15:06:33 +01:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{ /* TSTATE_TASK_INACTIVE */
|
|
|
|
&g_inactivetasks,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
{ /* TSTATE_WAIT_SEM */
|
|
|
|
&g_waitingforsemaphore,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
}
|
2007-03-17 23:43:36 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_WAIT_SIG */
|
|
|
|
&g_waitingforsignal,
|
|
|
|
0
|
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_WAIT_MQNOTEMPTY */
|
|
|
|
&g_waitingformqnotempty,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
},
|
|
|
|
{ /* TSTATE_WAIT_MQNOTFULL */
|
|
|
|
&g_waitingformqnotfull,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2010-08-14 03:56:13 +02:00
|
|
|
#ifdef CONFIG_PAGING
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
2016-02-11 15:06:33 +01:00
|
|
|
{ /* TSTATE_WAIT_PAGEFILL */
|
|
|
|
&g_waitingforfill,
|
|
|
|
TLIST_ATTR_PRIORITIZED
|
|
|
|
}
|
2010-08-14 03:56:13 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* This is the current initialization state. The level of initialization
|
|
|
|
* is only important early in the start-up sequence when certain OS or
|
|
|
|
* hardware resources may not yet be available to the kernel logic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t g_os_initstate; /* See enum os_initstate_e */
|
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2016-02-13 16:04:54 +01:00
|
|
|
* Private Data
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2018-01-13 15:34:58 +01:00
|
|
|
/* This is an array of task control block (TCB) for the IDLE thread of each
|
2016-02-13 16:04:54 +01:00
|
|
|
* CPU. For the non-SMP case, this is a a single TCB; For the SMP case,
|
|
|
|
* there is one TCB per CPU. NOTE: The system boots on CPU0 into the IDLE
|
|
|
|
* task. The IDLE task later starts the other CPUs and spawns the user
|
|
|
|
* initialization task. That user initialization task is responsible for
|
|
|
|
* bringing up the rest of the system.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static struct task_tcb_s g_idletcb[CONFIG_SMP_NCPUS];
|
|
|
|
#else
|
|
|
|
static struct task_tcb_s g_idletcb[1];
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
/* This is the name of the idle task */
|
|
|
|
|
2017-08-12 19:24:11 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE <= 0 || !defined(CONFIG_SMP)
|
2016-02-11 21:11:26 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-13 16:04:54 +01:00
|
|
|
static const char g_idlename[] = "CPU Idle";
|
2016-02-11 21:11:26 +01:00
|
|
|
#else
|
2016-02-11 19:18:54 +01:00
|
|
|
static const char g_idlename[] = "Idle Task";
|
2016-02-11 21:11:26 +01:00
|
|
|
#endif
|
2017-08-12 19:24:11 +02:00
|
|
|
#endif
|
2007-03-01 22:05:55 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* This the IDLE idle threads argument list. NOTE: Normally the argument
|
|
|
|
* list is created on the stack prior to starting the task. We have to
|
|
|
|
* do things s little differently here for the IDLE tasks.
|
|
|
|
*/
|
2014-09-02 00:49:42 +02:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static FAR char *g_idleargv[CONFIG_SMP_NCPUS][2];
|
|
|
|
#else
|
2016-02-13 17:48:30 +01:00
|
|
|
static FAR char *g_idleargv[1][2];
|
2016-02-13 16:04:54 +01:00
|
|
|
#endif
|
2014-09-02 00:49:42 +02:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: os_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to initialize the operating system and to spawn
|
2014-08-08 23:30:59 +02:00
|
|
|
* the user initialization thread of execution. This is the initial entry
|
|
|
|
* point into NuttX
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2014-08-08 23:30:59 +02:00
|
|
|
* Does not return.
|
2012-07-14 21:30:31 +02:00
|
|
|
*
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
void os_start(void)
|
|
|
|
{
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
int cpu;
|
|
|
|
#else
|
|
|
|
# define cpu 0
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
int i;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
sinfo("Entry\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* Boot up is complete */
|
|
|
|
|
|
|
|
g_os_initstate = OSINIT_BOOT;
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize RTOS Data ***************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize all task lists */
|
|
|
|
|
|
|
|
dq_init(&g_readytorun);
|
|
|
|
dq_init(&g_pendingtasks);
|
|
|
|
dq_init(&g_waitingforsemaphore);
|
2007-03-17 23:43:36 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_waitingforsignal);
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_waitingformqnotfull);
|
|
|
|
dq_init(&g_waitingformqnotempty);
|
2010-08-14 03:56:13 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PAGING
|
|
|
|
dq_init(&g_waitingforfill);
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_inactivetasks);
|
2014-08-29 22:47:22 +02:00
|
|
|
#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \
|
|
|
|
defined(CONFIG_MM_KERNEL_HEAP)
|
2013-03-10 16:32:33 +01:00
|
|
|
sq_init(&g_delayed_kfree);
|
|
|
|
#endif
|
2015-09-07 22:40:18 +02:00
|
|
|
#ifndef CONFIG_BUILD_KERNEL
|
|
|
|
sq_init(&g_delayed_kufree);
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-10 22:43:05 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
|
|
|
|
{
|
|
|
|
dq_init(&g_assignedtasks[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the logic that determine unique process IDs. */
|
|
|
|
|
|
|
|
g_lastpid = 0;
|
2007-03-01 22:05:55 +01:00
|
|
|
for (i = 0; i < CONFIG_MAX_TASKS; i++)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
g_pidhash[i].tcb = NULL;
|
|
|
|
g_pidhash[i].pid = INVALID_PROCESS_ID;
|
|
|
|
}
|
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Initialize the IDLE task TCB *******************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++, g_lastpid++)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
FAR dq_queue_t *tasklist;
|
2016-02-17 02:33:22 +01:00
|
|
|
int hashndx;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Assign the process ID(s) of ZERO to the idle task(s) */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-17 02:33:22 +01:00
|
|
|
hashndx = PIDHASH(g_lastpid);
|
|
|
|
g_pidhash[hashndx].tcb = &g_idletcb[cpu].cmn;
|
|
|
|
g_pidhash[hashndx].pid = g_lastpid;
|
2016-02-11 15:06:33 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Initialize a TCB for this thread of execution. NOTE: The default
|
|
|
|
* value for most components of the g_idletcb are zero. The entire
|
|
|
|
* structure is set to zero. Then only the (potentially) non-zero
|
|
|
|
* elements are initialized. NOTE: The idle task is the only task in
|
|
|
|
* that has pid == 0 and sched_priority == 0.
|
|
|
|
*/
|
|
|
|
|
2017-02-16 23:10:09 +01:00
|
|
|
memset((void *)&g_idletcb[cpu], 0, sizeof(struct task_tcb_s));
|
2016-02-16 01:35:05 +01:00
|
|
|
g_idletcb[cpu].cmn.pid = g_lastpid;
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idletcb[cpu].cmn.task_state = TSTATE_TASK_RUNNING;
|
|
|
|
|
|
|
|
/* Set the entry point. This is only for debug purposes. NOTE: that
|
|
|
|
* the start_t entry point is not saved. That is acceptable, however,
|
|
|
|
* becaue it can be used only for restarting a task: The IDLE task
|
|
|
|
* cannot be restarted.
|
|
|
|
*/
|
2016-02-11 15:06:33 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2016-02-13 16:04:54 +01:00
|
|
|
if (cpu > 0)
|
|
|
|
{
|
2016-03-12 22:29:33 +01:00
|
|
|
g_idletcb[cpu].cmn.start = os_idle_trampoline;
|
|
|
|
g_idletcb[cpu].cmn.entry.main = os_idle_task;
|
2016-02-13 16:04:54 +01:00
|
|
|
}
|
|
|
|
else
|
2016-02-16 23:43:19 +01:00
|
|
|
#endif
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
2016-03-12 22:29:33 +01:00
|
|
|
g_idletcb[cpu].cmn.start = (start_t)os_start;
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idletcb[cpu].cmn.entry.main = (main_t)os_start;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Set the task flags to indicate that this is a kernel thread and, if
|
2016-02-20 00:33:35 +01:00
|
|
|
* configured for SMP, that this task is locked to this CPU.
|
2016-02-13 16:04:54 +01:00
|
|
|
*/
|
2013-03-22 00:37:11 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-12-10 00:10:59 +01:00
|
|
|
g_idletcb[cpu].cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_NONCANCELABLE |
|
2016-12-09 17:31:40 +01:00
|
|
|
TCB_FLAG_CPU_LOCKED);
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idletcb[cpu].cmn.cpu = cpu;
|
|
|
|
#else
|
2016-12-09 17:31:40 +01:00
|
|
|
g_idletcb[cpu].cmn.flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_NONCANCELABLE);
|
2016-02-13 16:04:54 +01:00
|
|
|
#endif
|
2013-03-22 00:37:11 +01:00
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Set the affinity mask to allow the thread to run on all CPUs. No,
|
|
|
|
* this IDLE thread can only run on its assigned CPU. That is
|
|
|
|
* enforced by the TCB_FLAG_CPU_LOCKED which overrides the affinity
|
|
|
|
* mask. This is essential because all tasks inherit the affinity
|
|
|
|
* mask from their parent and, ultimately, the parent of all tasks is
|
|
|
|
* the IDLE task.
|
|
|
|
*/
|
|
|
|
|
2017-08-15 01:19:27 +02:00
|
|
|
g_idletcb[cpu].cmn.affinity = SCHED_ALL_CPUS;
|
2016-02-20 00:33:35 +01:00
|
|
|
#endif
|
2016-02-13 16:04:54 +01:00
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-02-20 00:33:35 +01:00
|
|
|
/* Set the IDLE task name */
|
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
# ifdef CONFIG_SMP
|
|
|
|
snprintf(g_idletcb[cpu].cmn.name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", cpu);
|
|
|
|
# else
|
|
|
|
strncpy(g_idletcb[cpu].cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE);
|
|
|
|
g_idletcb[cpu].cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Configure the task name in the argument list. The IDLE task does
|
|
|
|
* not really have an argument list, but this name is still useful
|
|
|
|
* for things like the NSH PS command.
|
|
|
|
*
|
|
|
|
* In the kernel mode build, the arguments are saved on the task's
|
|
|
|
* stack and there is no support that yet.
|
|
|
|
*/
|
2013-03-22 00:37:11 +01:00
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idleargv[cpu][0] = g_idletcb[cpu].cmn.name;
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idleargv[cpu][0] = (FAR char *)g_idlename;
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif /* CONFIG_TASK_NAME_SIZE */
|
2016-02-13 16:04:54 +01:00
|
|
|
g_idleargv[cpu][1] = NULL;
|
|
|
|
g_idletcb[cpu].argv = &g_idleargv[cpu][0];
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Then add the idle task's TCB to the head of the corrent ready to
|
|
|
|
* run list.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-10 22:43:05 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-13 16:04:54 +01:00
|
|
|
tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING, cpu);
|
2016-02-10 22:43:05 +01:00
|
|
|
#else
|
2016-02-13 16:04:54 +01:00
|
|
|
tasklist = TLIST_HEAD(TSTATE_TASK_RUNNING);
|
2016-02-10 22:43:05 +01:00
|
|
|
#endif
|
2016-02-13 16:04:54 +01:00
|
|
|
dq_addfirst((FAR dq_entry_t *)&g_idletcb[cpu], tasklist);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Initialize the processor-specific portion of the TCB */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
up_initial_state(&g_idletcb[cpu].cmn);
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-05-18 16:21:28 +02:00
|
|
|
/* Task lists are initialized */
|
|
|
|
|
|
|
|
g_os_initstate = OSINIT_TASKLISTS;
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize RTOS facilities *********************************************/
|
2014-09-29 14:50:48 +02:00
|
|
|
/* Initialize the semaphore facility. This has to be done very early
|
|
|
|
* because many subsystems depend upon fully functional semaphores.
|
2012-08-26 23:35:14 +02:00
|
|
|
*/
|
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_initialize();
|
2012-08-26 23:35:14 +02:00
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
#if defined(MM_KERNEL_USRHEAP_INIT) || defined(CONFIG_MM_KERNEL_HEAP) || \
|
|
|
|
defined(CONFIG_MM_PGALLOC)
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the memory manager */
|
|
|
|
|
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR void *heap_start;
|
2007-02-18 00:21:28 +01:00
|
|
|
size_t heap_size;
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2014-09-02 19:22:09 +02:00
|
|
|
#ifdef MM_KERNEL_USRHEAP_INIT
|
2013-03-09 22:12:20 +01:00
|
|
|
/* Get the user-mode heap from the platform specific code and configure
|
|
|
|
* the user-mode memory allocator.
|
|
|
|
*/
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
up_allocate_heap(&heap_start, &heap_size);
|
2013-03-09 22:12:20 +01:00
|
|
|
kumm_initialize(heap_start, heap_size);
|
2014-08-31 20:50:05 +02:00
|
|
|
#endif
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2014-08-31 20:50:05 +02:00
|
|
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
2013-03-09 22:12:20 +01:00
|
|
|
/* Get the kernel-mode heap from the platform specific code and configure
|
|
|
|
* the kernel-mode memory allocator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_allocate_kheap(&heap_start, &heap_size);
|
2011-04-05 19:33:50 +02:00
|
|
|
kmm_initialize(heap_start, heap_size);
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif
|
2014-08-25 19:18:32 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_MM_PGALLOC
|
|
|
|
/* If there is a page allocator in the configuration, then get the page
|
|
|
|
* heap information from the platform-specific code and configure the
|
|
|
|
* page allocator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_allocate_pgheap(&heap_start, &heap_size);
|
|
|
|
mm_pginitialize(heap_start, heap_size);
|
|
|
|
#endif
|
2013-03-09 22:12:20 +01:00
|
|
|
}
|
2014-11-25 21:10:35 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* The memory manager is available */
|
|
|
|
|
|
|
|
g_os_initstate = OSINIT_MEMORY;
|
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
2013-01-23 00:42:51 +01:00
|
|
|
/* Initialize tasking data structures */
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
|
|
|
if (task_initialize != NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
task_initialize();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the interrupt handling subsystem (if included) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (irq_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
irq_initialize();
|
|
|
|
}
|
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
/* Initialize the watchdog facility (if included in the link) */
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
|
|
|
if (wd_initialize != NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
wd_initialize();
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the POSIX timer facility (if included in the link) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (clock_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
clock_initialize();
|
|
|
|
}
|
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
#ifndef CONFIG_DISABLE_POSIX_TIMERS
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-03-21 18:21:26 +01:00
|
|
|
if (timer_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-03-21 18:21:26 +01:00
|
|
|
timer_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-03-21 18:21:26 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the signal facility (if in link) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
if (nxsig_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
nxsig_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the named message queue facility (if in link) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2017-10-09 17:06:46 +02:00
|
|
|
if (nxmq_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2017-10-09 17:06:46 +02:00
|
|
|
nxmq_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the thread-specific data facility (if in link) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (pthread_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
pthread_initialize();
|
|
|
|
}
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the file system (needed to support device drivers) */
|
|
|
|
|
2014-10-06 19:45:35 +02:00
|
|
|
fs_initialize();
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-02-14 01:32:15 +01:00
|
|
|
#ifdef CONFIG_NET
|
2015-02-14 13:36:53 +01:00
|
|
|
/* Initialize the networking system. Network initialization is
|
|
|
|
* performed in two steps: (1) net_setup() initializes static
|
|
|
|
* configuration of the network support. This must be done prior
|
|
|
|
* to registering network drivers by up_initialize(). This step
|
|
|
|
* cannot require upon any hardware-depending features such as
|
|
|
|
* timers or interrupts.
|
2015-02-14 01:39:43 +01:00
|
|
|
*/
|
2015-02-14 01:32:15 +01:00
|
|
|
|
2015-02-14 13:36:53 +01:00
|
|
|
net_setup();
|
2015-02-14 01:32:15 +01:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* The processor specific details of running the operating system
|
|
|
|
* will be handled here. Such things as setting up interrupt
|
|
|
|
* service routines and starting the clock are some of the things
|
|
|
|
* that are different for each processor and hardware platform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_initialize();
|
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* Hardware resources are available */
|
|
|
|
|
|
|
|
g_os_initstate = OSINIT_HARDWARE;
|
|
|
|
|
2015-02-14 13:36:53 +01:00
|
|
|
#ifdef CONFIG_NET
|
|
|
|
/* Complete initialization the networking system now that interrupts
|
|
|
|
* and timers have been configured by up_initialize().
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_initialize();
|
|
|
|
#endif
|
|
|
|
|
2014-09-23 16:46:31 +02:00
|
|
|
#ifdef CONFIG_MM_SHM
|
|
|
|
/* Initialize shared memory support */
|
|
|
|
|
|
|
|
shm_initialize();
|
|
|
|
#endif
|
|
|
|
|
2014-09-11 17:00:10 +02:00
|
|
|
/* Initialize the C libraries. This is done last because the libraries
|
|
|
|
* may depend on the above.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2014-09-11 17:00:10 +02:00
|
|
|
lib_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-23 17:09:39 +02:00
|
|
|
#ifndef CONFIG_BINFMT_DISABLE
|
|
|
|
/* Initialize the binfmt system */
|
|
|
|
|
|
|
|
binfmt_initialize();
|
|
|
|
#endif
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* IDLE Group Initialization **********************************************/
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Announce that the CPU0 IDLE task has started */
|
|
|
|
|
|
|
|
sched_note_start(&g_idletcb[0].cmn);
|
2016-02-13 16:04:54 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Initialize the IDLE group for the IDLE task of each CPU */
|
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
|
|
|
|
#endif
|
|
|
|
{
|
2013-03-12 22:53:18 +01:00
|
|
|
#ifdef HAVE_TASK_GROUP
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Allocate the IDLE group */
|
2014-09-03 22:58:24 +02:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
DEBUGVERIFY(group_allocate(&g_idletcb[cpu], g_idletcb[cpu].cmn.flags));
|
2013-03-12 22:53:18 +01:00
|
|
|
#endif
|
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
|
2016-02-13 16:04:54 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2017-08-15 01:19:27 +02:00
|
|
|
if (cpu > 0)
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
|
|
|
/* Clone stdout, stderr, stdin from the CPU0 IDLE task. */
|
|
|
|
|
|
|
|
DEBUGVERIFY(group_setuptaskfiles(&g_idletcb[cpu]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Create stdout, stderr, stdin on the CPU0 IDLE task. These
|
|
|
|
* will be inherited by all of the threads created by the CPU0
|
|
|
|
* IDLE task.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
DEBUGVERIFY(group_setupidlefiles(&g_idletcb[cpu]));
|
|
|
|
}
|
2013-09-27 21:11:34 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-03 22:58:24 +02:00
|
|
|
#ifdef HAVE_TASK_GROUP
|
2016-02-13 16:04:54 +01:00
|
|
|
/* Complete initialization of the IDLE group. Suppress retention
|
|
|
|
* of child status in the IDLE group.
|
|
|
|
*/
|
2013-01-27 20:17:56 +01:00
|
|
|
|
2016-02-13 16:04:54 +01:00
|
|
|
DEBUGVERIFY(group_initialize(&g_idletcb[cpu]));
|
|
|
|
g_idletcb[cpu].cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT;
|
2013-01-27 20:17:56 +01:00
|
|
|
#endif
|
2016-06-21 15:52:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start SYSLOG ***********************************************************/
|
|
|
|
/* Late initialization of the system logging device. Some SYSLOG channel
|
|
|
|
* must be initialized late in the initialization sequence because it may
|
|
|
|
* depend on having IDLE task file structures setup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
syslog_initialize(SYSLOG_INIT_LATE);
|
2013-01-27 20:17:56 +01:00
|
|
|
|
2016-02-10 20:49:27 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Start all CPUs *********************************************************/
|
|
|
|
|
2016-02-15 18:07:42 +01:00
|
|
|
/* A few basic sanity checks */
|
|
|
|
|
2016-02-11 21:11:26 +01:00
|
|
|
DEBUGASSERT(this_cpu() == 0 && CONFIG_MAX_TASKS > CONFIG_SMP_NCPUS);
|
2016-02-15 18:07:42 +01:00
|
|
|
|
|
|
|
/* Take the memory manager semaphore on this CPU so that it will not be
|
|
|
|
* available on the other CPUs until we have finished initialization.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGVERIFY(kmm_trysemaphore());
|
|
|
|
|
|
|
|
/* Then start the other CPUs */
|
|
|
|
|
2016-03-12 22:29:33 +01:00
|
|
|
DEBUGVERIFY(os_smp_start());
|
2016-02-10 20:49:27 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Bring Up the System ****************************************************/
|
2016-02-05 15:34:03 +01:00
|
|
|
/* The OS is fully initialized and we are beginning multi-tasking */
|
|
|
|
|
|
|
|
g_os_initstate = OSINIT_OSREADY;
|
|
|
|
|
2011-03-12 18:49:47 +01:00
|
|
|
/* Create initial tasks and bring-up the system */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-13 18:32:37 +01:00
|
|
|
DEBUGVERIFY(os_bringup());
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-15 18:07:42 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Let other threads have access to the memory manager */
|
|
|
|
|
|
|
|
kmm_givesemaphore();
|
|
|
|
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* The IDLE Loop **********************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
/* When control is return to this point, the system is idle. */
|
|
|
|
|
2016-06-12 00:42:42 +02:00
|
|
|
sinfo("CPU0: Beginning Idle Loop\n");
|
2015-10-08 03:59:14 +02:00
|
|
|
for (; ; )
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2009-11-06 01:44:22 +01:00
|
|
|
/* Perform garbage collection (if it is not being done by the worker
|
|
|
|
* thread). This cleans-up memory de-allocations that were queued
|
|
|
|
* because they could not be freed in that execution context (for
|
2009-11-05 23:58:36 +01:00
|
|
|
* example, if the memory was freed from an interrupt handler).
|
2007-03-14 19:58:21 +01:00
|
|
|
*/
|
2009-11-06 01:44:22 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_SCHED_WORKQUEUE
|
|
|
|
/* We must have exclusive access to the memory manager to do this
|
|
|
|
* BUT the idle task cannot wait on a semaphore. So we only do
|
|
|
|
* the cleanup now if we can get the semaphore -- this should be
|
|
|
|
* possible because if the IDLE thread is running, no other task is!
|
2014-11-20 13:58:19 +01:00
|
|
|
*
|
|
|
|
* WARNING: This logic could have undesirable side-effects if priority
|
|
|
|
* inheritance is enabled. Imaginee the possible issues if the
|
|
|
|
* priority of the IDLE thread were to get boosted! Moral: If you
|
|
|
|
* use priority inheritance, then you should also enable the work
|
|
|
|
* queue so that is done in a safer context.
|
2009-11-06 01:44:22 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-17 02:33:22 +01:00
|
|
|
if (sched_have_garbage() && kmm_trysemaphore() == 0)
|
2009-11-06 01:44:22 +01:00
|
|
|
{
|
2016-02-17 02:33:22 +01:00
|
|
|
sched_garbage_collection();
|
2011-04-05 19:33:50 +02:00
|
|
|
kmm_givesemaphore();
|
2009-11-06 01:44:22 +01:00
|
|
|
}
|
2009-11-05 23:58:36 +01:00
|
|
|
#endif
|
2007-03-14 19:58:21 +01:00
|
|
|
|
|
|
|
/* Perform any processor-specific idle state operations */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
up_idle();
|
|
|
|
}
|
|
|
|
}
|