2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2019-02-04 23:20:35 +01:00
|
|
|
* sched/init/nx_start.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
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>
|
2019-02-18 23:25:08 +01:00
|
|
|
#include <nuttx/board.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/net/net.h>
|
2020-02-17 18:08:08 +01:00
|
|
|
#include <nuttx/mm/iob.h>
|
2023-04-13 15:25:22 +02:00
|
|
|
#include <nuttx/mm/kmap.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <nuttx/mm/mm.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
2022-02-24 08:12:51 +01:00
|
|
|
#include <nuttx/pgalloc.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <nuttx/sched_note.h>
|
2023-02-22 04:08:22 +01:00
|
|
|
#include <nuttx/trace.h>
|
2018-08-23 17:09:39 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2022-03-11 15:52:32 +01:00
|
|
|
#include <nuttx/drivers/drivers.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
#include <nuttx/init.h>
|
2024-05-30 08:36:15 +02:00
|
|
|
#include <nuttx/lib/math32.h>
|
2017-08-15 01:19:27 +02:00
|
|
|
|
sched/pthread/join: refactor pthread join to support join task
1. add support to join main task
| static pthread_t self;
|
| static void *join_task(void *arg)
| {
| int ret;
| ret = pthread_join(self, NULL); <--- /* Fix Task could not be joined */
| return NULL;
| }
|
| int main(int argc, char *argv[])
| {
| pthread_t thread;
|
| self = pthread_self();
|
| pthread_create(&thread, NULL, join_task, NULL);
| sleep(1);
|
| pthread_exit(NULL);
| return 0;
| }
2. Detach active thread will not alloc for additional join, just update the task flag.
3. Remove the return value waiting lock logic (data_sem),
the return value will be stored in the waiting tcb.
4. Revise the return value of pthread_join(), consistent with linux
e.g:
Joining a detached and canceled thread should return EINVAL, not ESRCH
https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_join.html
[EINVAL]
The value specified by thread does not refer to a joinable thread.
NOTE:
This PR will not increase stack usage, but struct tcb_s will increase 32 bytes.
Signed-off-by: chao an <anchao@lixiang.com>
2024-03-12 08:10:11 +01:00
|
|
|
#include "task/task.h"
|
2017-08-15 01:19:27 +02:00
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "signal/signal.h"
|
|
|
|
#include "semaphore/semaphore.h"
|
2022-03-11 21:01:19 +01:00
|
|
|
#include "mqueue/mqueue.h"
|
2022-10-19 16:28:43 +02:00
|
|
|
#include "mqueue/msg.h"
|
2017-08-15 01:19:27 +02:00
|
|
|
#include "clock/clock.h"
|
|
|
|
#include "timer/timer.h"
|
|
|
|
#include "irq/irq.h"
|
2019-02-11 19:09:26 +01:00
|
|
|
#include "group/group.h"
|
2017-08-15 01:19:27 +02:00
|
|
|
#include "init/init.h"
|
2023-10-27 15:57:33 +02:00
|
|
|
#include "instrument/instrument.h"
|
2022-06-05 16:18:05 +02:00
|
|
|
#include "tls/tls.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This set of all CPUs */
|
|
|
|
|
2021-07-15 13:46:07 +02:00
|
|
|
#define SCHED_ALL_CPUS ((1 << CONFIG_SMP_NCPUS) - 1)
|
2016-02-20 00:33:35 +01:00
|
|
|
|
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 ***************************************************************/
|
2019-06-30 18:35:10 +02:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_readytorun;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-10 18:45:26 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2021-07-10 03:01:20 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_assignedtasks[CONFIG_SMP_NCPUS];
|
2024-01-10 09:03:08 +01:00
|
|
|
FAR struct tcb_s *g_delivertasks[CONFIG_SMP_NCPUS];
|
2021-07-10 03:01:20 +02:00
|
|
|
#endif
|
2018-11-15 14:11:51 +01:00
|
|
|
|
|
|
|
/* g_running_tasks[] holds a references to the running task for each cpu.
|
|
|
|
* It is valid only when up_interrupt_context() returns true.
|
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct tcb_s *g_running_tasks[CONFIG_SMP_NCPUS];
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
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 signal */
|
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_waitingforsignal;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-02-29 20:21:23 +01:00
|
|
|
#ifdef CONFIG_LEGACY_PAGING
|
2010-08-14 03:56:13 +02:00
|
|
|
/* This is the list of all tasks that are blocking waiting for a page fill */
|
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_waitingforfill;
|
2010-08-14 03:56:13 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
2020-04-09 14:46:24 +02:00
|
|
|
/* This is the list of all tasks that have been stopped
|
2020-10-29 05:53:41 +01:00
|
|
|
* via SIGSTOP or SIGTSTP
|
2020-04-09 14:46:24 +02:00
|
|
|
*/
|
2018-08-30 18:27:18 +02:00
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_stoppedtasks;
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
|
|
|
|
2023-07-03 13:24:13 +02:00
|
|
|
/* This list of all tasks that have been initialized, but not yet
|
2007-02-18 00:21:28 +01:00
|
|
|
* activated. NOTE: This is the only list that is not prioritized.
|
|
|
|
*/
|
|
|
|
|
2022-08-29 10:39:43 +02:00
|
|
|
dq_queue_t g_inactivetasks;
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-10-14 05:03:07 +02:00
|
|
|
FAR struct tcb_s **g_pidhash;
|
2021-06-15 10:45:40 +02:00
|
|
|
volatile int g_npidhash;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2023-07-03 13:24:13 +02:00
|
|
|
/* This is a table of task lists. This table is indexed by the task state
|
2016-02-11 15:06:33 +01:00
|
|
|
* enumeration type (tstate_t) and provides a pointer to the associated
|
2023-07-03 13:24:13 +02:00
|
|
|
* static task list (if there is one) as well as 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
|
|
|
*/
|
|
|
|
|
2024-03-22 03:55:38 +01:00
|
|
|
struct tasklist_s g_tasklisttable[NUM_TASK_STATES];
|
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.
|
|
|
|
*/
|
|
|
|
|
sched: change nxsched_islocked_global to nxsched_islocked_tcb
reason:
1 To improve efficiency, we mimic Linux's behavior where preemption disabling is only applicable to the current CPU and does not affect other CPUs.
2 In the future, we will implement "spinlock+sched_lock", and use it extensively. Under such circumstances, if preemption is still globally disabled, it will seriously impact the scheduling efficiency.
3 We have removed g_cpu_lockset and used irqcount in order to eliminate the dependency of schedlock on critical sections in the future, simplify the logic, and further enhance the performance of sched_lock.
4 We set lockcount to 1 in order to lock scheduling on all CPUs during startup, without the need to provide additional functions to disable scheduling on other CPUs.
5 Cpu1~n must wait for cpu0 to enter the idle state before enabling scheduling because it prevents CPUs1~n from competing with cpu0 for the memory manager mutex, which could cause the cpu0 idle task to enter a wait state and trigger an assert.
size nuttx
before:
text data bss dec hex filename
265396 51057 63646 380099 5ccc3 nuttx
after:
text data bss dec hex filename
265184 51057 63642 379883 5cbeb nuttx
size -216
Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
-mon chardev=con,mode=readline -kernel ./nuttx
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-05-13 13:33:01 +02:00
|
|
|
volatile uint8_t g_nx_initstate; /* See enum nx_initstate_e */
|
2016-02-05 15:34:03 +01:00
|
|
|
|
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
|
|
|
****************************************************************************/
|
2019-11-09 15:15:12 +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
|
|
|
*/
|
|
|
|
|
2024-06-25 07:57:35 +02:00
|
|
|
struct tcb_s g_idletcb[CONFIG_SMP_NCPUS];
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
/* This is the name of the idle task */
|
|
|
|
|
2024-06-09 03:35:34 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0 && !defined(CONFIG_SMP)
|
2023-08-11 04:31:03 +02:00
|
|
|
static const char g_idlename[] = "Idle_Task";
|
2017-08-12 19:24:11 +02:00
|
|
|
#endif
|
2007-03-01 22:05:55 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2024-03-22 02:19:34 +01:00
|
|
|
* Private Functions
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-03-22 03:55:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: tasklist_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialization of table of task lists.This table is indexed by the
|
|
|
|
* task state enumeration type (tstate_t) and provides a pointer to
|
|
|
|
* the associated static task list (if there is one) as well as a set
|
|
|
|
* of attribute flags indicating properties of the list, for example,
|
|
|
|
* if the list is an ordered list or not.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void tasklist_initialize(void)
|
|
|
|
{
|
|
|
|
FAR struct tasklist_s *tlist = (FAR void *)&g_tasklisttable;
|
|
|
|
|
|
|
|
/* TSTATE_TASK_INVALID */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_INVALID].list = NULL;
|
|
|
|
tlist[TSTATE_TASK_INVALID].attr = 0;
|
|
|
|
|
|
|
|
/* TSTATE_TASK_PENDING */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_PENDING].list = list_pendingtasks();
|
|
|
|
tlist[TSTATE_TASK_PENDING].attr = TLIST_ATTR_PRIORITIZED;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
/* TSTATE_TASK_READYTORUN */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_READYTORUN].list = list_readytorun();
|
|
|
|
tlist[TSTATE_TASK_READYTORUN].attr = TLIST_ATTR_PRIORITIZED;
|
|
|
|
|
|
|
|
/* TSTATE_TASK_ASSIGNED */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_ASSIGNED].list = list_assignedtasks(0);
|
|
|
|
tlist[TSTATE_TASK_ASSIGNED].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_INDEXED |
|
|
|
|
TLIST_ATTR_RUNNABLE;
|
|
|
|
|
|
|
|
/* TSTATE_TASK_RUNNING */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_RUNNING].list = list_assignedtasks(0);
|
|
|
|
tlist[TSTATE_TASK_RUNNING].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_INDEXED |
|
|
|
|
TLIST_ATTR_RUNNABLE;
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* TSTATE_TASK_READYTORUN */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_READYTORUN].list = list_readytorun();
|
|
|
|
tlist[TSTATE_TASK_READYTORUN].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_RUNNABLE;
|
|
|
|
|
|
|
|
/* TSTATE_TASK_RUNNING */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_RUNNING].list = list_readytorun();
|
|
|
|
tlist[TSTATE_TASK_RUNNING].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_RUNNABLE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TSTATE_TASK_INACTIVE */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_INACTIVE].list = list_inactivetasks();
|
|
|
|
tlist[TSTATE_TASK_INACTIVE].attr = 0;
|
|
|
|
|
|
|
|
/* TSTATE_WAIT_SEM */
|
|
|
|
|
|
|
|
tlist[TSTATE_WAIT_SEM].list = (FAR void *)offsetof(sem_t, waitlist);
|
|
|
|
tlist[TSTATE_WAIT_SEM].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_OFFSET;
|
|
|
|
|
|
|
|
/* TSTATE_WAIT_SIG */
|
|
|
|
|
|
|
|
tlist[TSTATE_WAIT_SIG].list = list_waitingforsignal();
|
|
|
|
tlist[TSTATE_WAIT_SIG].attr = 0;
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
|
|
|
|
|
|
|
/* TSTATE_WAIT_MQNOTEMPTY */
|
|
|
|
|
|
|
|
tlist[TSTATE_WAIT_MQNOTEMPTY].list =
|
|
|
|
(FAR void *)offsetof(struct mqueue_inode_s, cmn.waitfornotempty);
|
|
|
|
tlist[TSTATE_WAIT_MQNOTEMPTY].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_OFFSET;
|
|
|
|
|
|
|
|
/* TSTATE_WAIT_MQNOTFULL */
|
|
|
|
|
|
|
|
tlist[TSTATE_WAIT_MQNOTFULL].list =
|
|
|
|
(FAR void *)offsetof(struct mqueue_inode_s, cmn.waitfornotfull);
|
|
|
|
tlist[TSTATE_WAIT_MQNOTFULL].attr = TLIST_ATTR_PRIORITIZED |
|
|
|
|
TLIST_ATTR_OFFSET;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LEGACY_PAGING
|
|
|
|
|
|
|
|
/* TSTATE_WAIT_PAGEFILL */
|
|
|
|
|
|
|
|
tlist[TSTATE_WAIT_PAGEFILL].list = list_waitingforfill();
|
|
|
|
tlist[TSTATE_WAIT_PAGEFILL].attr = TLIST_ATTR_PRIORITIZED;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
|
|
|
|
|
|
|
/* TSTATE_TASK_STOPPED */
|
|
|
|
|
|
|
|
tlist[TSTATE_TASK_STOPPED].list = list_stoppedtasks();
|
|
|
|
tlist[TSTATE_TASK_STOPPED].attr = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2024-03-22 02:19:34 +01:00
|
|
|
* Name: idle_task_initialize
|
2012-07-14 21:30:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2024-03-22 02:19:34 +01:00
|
|
|
* IDLE Task Initialization
|
2012-07-14 21:30:31 +02:00
|
|
|
*
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-03-22 02:19:34 +01:00
|
|
|
static void idle_task_initialize(void)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
FAR struct tcb_s *tcb;
|
2024-03-22 02:19:34 +01:00
|
|
|
FAR dq_queue_t *tasklist;
|
2007-02-18 00:21:28 +01:00
|
|
|
int i;
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
memset(g_idletcb, 0, sizeof(g_idletcb));
|
2021-07-10 03:01:20 +02:00
|
|
|
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
2024-03-22 02:19:34 +01:00
|
|
|
tcb = &g_idletcb[i];
|
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.
|
|
|
|
*/
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->pid = i;
|
|
|
|
tcb->task_state = TSTATE_TASK_RUNNING;
|
sched: change nxsched_islocked_global to nxsched_islocked_tcb
reason:
1 To improve efficiency, we mimic Linux's behavior where preemption disabling is only applicable to the current CPU and does not affect other CPUs.
2 In the future, we will implement "spinlock+sched_lock", and use it extensively. Under such circumstances, if preemption is still globally disabled, it will seriously impact the scheduling efficiency.
3 We have removed g_cpu_lockset and used irqcount in order to eliminate the dependency of schedlock on critical sections in the future, simplify the logic, and further enhance the performance of sched_lock.
4 We set lockcount to 1 in order to lock scheduling on all CPUs during startup, without the need to provide additional functions to disable scheduling on other CPUs.
5 Cpu1~n must wait for cpu0 to enter the idle state before enabling scheduling because it prevents CPUs1~n from competing with cpu0 for the memory manager mutex, which could cause the cpu0 idle task to enter a wait state and trigger an assert.
size nuttx
before:
text data bss dec hex filename
265396 51057 63646 380099 5ccc3 nuttx
after:
text data bss dec hex filename
265184 51057 63642 379883 5cbeb nuttx
size -216
Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
-mon chardev=con,mode=readline -kernel ./nuttx
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-05-13 13:33:01 +02:00
|
|
|
tcb->lockcount = 1;
|
2016-02-13 16:04:54 +01:00
|
|
|
|
|
|
|
/* Set the entry point. This is only for debug purposes. NOTE: that
|
|
|
|
* the start_t entry point is not saved. That is acceptable, however,
|
2020-02-23 09:50:23 +01:00
|
|
|
* because it can be used only for restarting a task: The IDLE task
|
2016-02-13 16:04:54 +01:00
|
|
|
* cannot be restarted.
|
|
|
|
*/
|
2016-02-11 15:06:33 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2021-07-10 03:01:20 +02:00
|
|
|
if (i > 0)
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->start = nx_idle_trampoline;
|
|
|
|
tcb->entry.main = (main_t)nx_idle_trampoline;
|
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
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->start = nx_start;
|
|
|
|
tcb->entry.main = (main_t)nx_start;
|
2016-02-13 16:04:54 +01:00
|
|
|
}
|
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
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->flags = (TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_CPU_LOCKED);
|
|
|
|
tcb->cpu = i;
|
2013-03-22 00:37:11 +01:00
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->affinity =
|
2023-04-19 05:00:57 +02:00
|
|
|
(cpu_set_t)(CONFIG_SMP_DEFAULT_CPUSET & SCHED_ALL_CPUS);
|
2021-07-15 13:46:07 +02:00
|
|
|
#else
|
2024-05-17 00:11:52 +02:00
|
|
|
tcb->flags = TCB_FLAG_TTYPE_KERNEL;
|
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
|
2024-05-17 00:11:52 +02:00
|
|
|
snprintf(tcb->name, CONFIG_TASK_NAME_SIZE, "CPU%d IDLE", i);
|
2016-02-13 16:04:54 +01:00
|
|
|
# else
|
2024-05-17 00:11:52 +02:00
|
|
|
strlcpy(tcb->name, g_idlename, CONFIG_TASK_NAME_SIZE);
|
2016-02-13 16:04:54 +01:00
|
|
|
# endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif /* CONFIG_TASK_NAME_SIZE */
|
|
|
|
|
2019-08-04 22:50:28 +02:00
|
|
|
/* Then add the idle task's TCB to the head of the current ready to
|
2016-02-13 16:04:54 +01:00
|
|
|
* run list.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-10 22:43:05 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2024-05-17 00:11:52 +02:00
|
|
|
tasklist = TLIST_HEAD(tcb, i);
|
2016-02-10 22:43:05 +01:00
|
|
|
#else
|
2024-05-17 00:11:52 +02:00
|
|
|
tasklist = TLIST_HEAD(tcb);
|
2016-02-10 22:43:05 +01:00
|
|
|
#endif
|
2024-03-22 02:19:34 +01:00
|
|
|
dq_addfirst((FAR dq_entry_t *)tcb, tasklist);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-15 14:11:51 +01:00
|
|
|
/* Mark the idle task as the running task */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
g_running_tasks[i] = tcb;
|
2024-03-22 02:19:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: idle_group_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* IDLE Group Initialization
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void idle_group_initialize(void)
|
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
FAR struct tcb_s *tcb;
|
2024-03-22 02:19:34 +01:00
|
|
|
int hashndx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Assign the process ID(s) of ZERO to the idle task(s) */
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
|
|
|
|
{
|
|
|
|
tcb = &g_idletcb[i];
|
|
|
|
|
|
|
|
hashndx = PIDHASH(i);
|
2024-05-17 00:11:52 +02:00
|
|
|
g_pidhash[hashndx] = tcb;
|
2024-03-22 02:19:34 +01:00
|
|
|
|
|
|
|
/* Allocate the IDLE group */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
DEBUGVERIFY(
|
|
|
|
group_initialize((FAR struct task_tcb_s *)tcb, tcb->flags));
|
2024-03-22 02:19:34 +01:00
|
|
|
|
|
|
|
/* Initialize the task join */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
nxtask_joininit(tcb);
|
2024-03-22 02:19:34 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Create a stack for all CPU IDLE threads (except CPU0 which already
|
|
|
|
* has a stack).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
DEBUGVERIFY(up_cpu_idlestack(i, tcb, CONFIG_IDLETHREAD_STACKSIZE));
|
2024-03-22 02:19:34 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize the processor-specific portion of the TCB */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
up_initial_state(tcb);
|
2024-03-22 02:19:34 +01:00
|
|
|
|
|
|
|
/* Initialize the thread local storage */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
tls_init_info(tcb);
|
2024-03-22 02:19:34 +01:00
|
|
|
|
|
|
|
/* Complete initialization of the IDLE group. Suppress retention
|
|
|
|
* of child status in the IDLE group.
|
|
|
|
*/
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
group_postinitialize((FAR struct task_tcb_s *)tcb);
|
|
|
|
tcb->group->tg_flags = GROUP_FLAG_NOCLDWAIT | GROUP_FLAG_PRIVILEGED;
|
2016-02-13 16:04:54 +01:00
|
|
|
}
|
2024-03-22 02:19:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nx_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to initialize the operating system and to spawn
|
|
|
|
* the user initialization thread of execution. This is the initial entry
|
|
|
|
* point into NuttX.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Does not return.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nx_start(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sinfo("Entry\n");
|
|
|
|
|
|
|
|
/* Boot up is complete */
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_BOOT;
|
2024-03-22 02:19:34 +01:00
|
|
|
|
2024-03-22 03:55:38 +01:00
|
|
|
/* Initialize task list table *********************************************/
|
|
|
|
|
|
|
|
tasklist_initialize();
|
|
|
|
|
2024-03-22 02:19:34 +01:00
|
|
|
/* Initialize the IDLE task TCB *******************************************/
|
|
|
|
|
|
|
|
idle_task_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-05-18 16:21:28 +02:00
|
|
|
/* Task lists are initialized */
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_TASKLISTS;
|
2016-05-18 16:21:28 +02:00
|
|
|
|
2024-07-06 13:04:04 +02:00
|
|
|
/* Initialize RTOS Data ***************************************************/
|
|
|
|
|
|
|
|
drivers_early_initialize();
|
|
|
|
|
|
|
|
sched_trace_begin();
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize RTOS facilities *********************************************/
|
2019-02-19 00:36:11 +01:00
|
|
|
|
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
|
|
|
|
2020-05-07 21:06:05 +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 */
|
|
|
|
|
2020-03-09 14:07:59 +01:00
|
|
|
{
|
|
|
|
FAR void *heap_start;
|
|
|
|
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
|
2020-03-09 14:07:59 +01:00
|
|
|
/* Get the user-mode heap from the platform specific code and configure
|
|
|
|
* the user-mode memory allocator.
|
|
|
|
*/
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2020-03-09 14:07:59 +01:00
|
|
|
up_allocate_heap(&heap_start, &heap_size);
|
|
|
|
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
|
2020-03-09 14:07:59 +01:00
|
|
|
/* Get the kernel-mode heap from the platform specific code and
|
|
|
|
* configure the kernel-mode memory allocator.
|
|
|
|
*/
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2020-03-09 14:07:59 +01:00
|
|
|
up_allocate_kheap(&heap_start, &heap_size);
|
|
|
|
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
|
2020-03-09 14:07:59 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
2014-08-25 19:18:32 +02:00
|
|
|
|
2020-03-09 14:07:59 +01:00
|
|
|
up_allocate_pgheap(&heap_start, &heap_size);
|
|
|
|
mm_pginitialize(heap_start, heap_size);
|
2014-08-25 19:18:32 +02:00
|
|
|
#endif
|
2020-03-09 14:07:59 +01:00
|
|
|
}
|
2020-05-07 21:06:05 +02:00
|
|
|
#endif
|
2020-04-29 21:21:23 +02:00
|
|
|
|
2023-04-13 15:25:22 +02:00
|
|
|
#ifdef CONFIG_MM_KMAP
|
|
|
|
/* Initialize the kernel dynamic mapping module */
|
|
|
|
|
|
|
|
kmm_map_initialize();
|
|
|
|
#endif
|
|
|
|
|
2021-06-25 16:07:23 +02:00
|
|
|
#ifdef CONFIG_ARCH_HAVE_EXTRA_HEAPS
|
|
|
|
/* Initialize any extra heap. */
|
|
|
|
|
|
|
|
up_extraheaps_init();
|
2014-11-25 21:10:35 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-02-17 18:08:08 +01:00
|
|
|
#ifdef CONFIG_MM_IOB
|
|
|
|
/* Initialize IO buffering */
|
|
|
|
|
|
|
|
iob_initialize();
|
|
|
|
#endif
|
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
/* Initialize the logic that determine unique process IDs. */
|
|
|
|
|
2024-05-30 08:36:15 +02:00
|
|
|
g_npidhash = 1 << LOG2_CEIL(CONFIG_PID_INITIAL_COUNT);
|
2024-06-06 10:49:50 +02:00
|
|
|
while (g_npidhash <= CONFIG_SMP_NCPUS)
|
2021-06-15 10:45:40 +02:00
|
|
|
{
|
2024-06-06 10:49:50 +02:00
|
|
|
g_npidhash <<= 1;
|
2021-06-15 10:45:40 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_pidhash = kmm_zalloc(sizeof(*g_pidhash) * g_npidhash);
|
|
|
|
DEBUGASSERT(g_pidhash);
|
2021-06-15 10:45:40 +02:00
|
|
|
|
2021-07-15 12:25:48 +02:00
|
|
|
/* IDLE Group Initialization **********************************************/
|
|
|
|
|
2024-03-22 02:19:34 +01:00
|
|
|
idle_group_initialize();
|
2021-06-15 10:45:40 +02:00
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_lastpid = CONFIG_SMP_NCPUS - 1;
|
2021-06-15 10:45:40 +02:00
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* The memory manager is available */
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_MEMORY;
|
2016-02-05 15:34:03 +01:00
|
|
|
|
2013-01-23 00:42:51 +01:00
|
|
|
/* Initialize tasking data structures */
|
|
|
|
|
2022-08-16 06:20:39 +02:00
|
|
|
task_initialize();
|
2013-01-23 00:42:51 +01:00
|
|
|
|
2023-10-27 15:57:33 +02:00
|
|
|
/* Initialize the instrument function */
|
|
|
|
|
|
|
|
instrument_initialize();
|
|
|
|
|
2020-09-17 06:49:02 +02:00
|
|
|
/* Initialize the file system (needed to support device drivers) */
|
|
|
|
|
|
|
|
fs_initialize();
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the interrupt handling subsystem (if included) */
|
|
|
|
|
2022-08-16 06:20:39 +02:00
|
|
|
irq_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the POSIX timer facility (if included in the link) */
|
|
|
|
|
2022-08-16 06:20:39 +02:00
|
|
|
clock_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
#ifndef CONFIG_DISABLE_POSIX_TIMERS
|
2022-08-16 06:20:39 +02:00
|
|
|
timer_initialize();
|
2007-03-21 18:21:26 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the signal facility (if in link) */
|
|
|
|
|
2022-08-16 06:20:39 +02:00
|
|
|
nxsig_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-11-16 11:20:31 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the named message queue facility (if in link) */
|
|
|
|
|
2022-08-16 06:20:39 +02:00
|
|
|
nxmq_initialize();
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-02-14 01:32:15 +01:00
|
|
|
#ifdef CONFIG_NET
|
2018-11-09 20:54:55 +01:00
|
|
|
/* Initialize the networking system */
|
2015-02-14 01:32:15 +01:00
|
|
|
|
2018-11-09 20:54:55 +01:00
|
|
|
net_initialize();
|
2015-02-14 01:32:15 +01:00
|
|
|
#endif
|
|
|
|
|
2022-03-11 21:10:24 +01:00
|
|
|
#ifndef CONFIG_BINFMT_DISABLE
|
|
|
|
/* Initialize the binfmt system */
|
|
|
|
|
|
|
|
binfmt_initialize();
|
|
|
|
#endif
|
|
|
|
|
2019-02-19 00:36:11 +01:00
|
|
|
/* Initialize Hardware Facilities *****************************************/
|
|
|
|
|
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();
|
2022-04-11 13:44:26 +02:00
|
|
|
|
|
|
|
/* Initialize common drivers */
|
|
|
|
|
|
|
|
drivers_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-02-18 23:25:08 +01:00
|
|
|
#ifdef CONFIG_BOARD_EARLY_INITIALIZE
|
2019-02-18 22:32:00 +01:00
|
|
|
/* Call the board-specific up_initialize() extension to support
|
|
|
|
* early initialization of board-specific drivers and resources
|
|
|
|
* that cannot wait until board_late_initialize.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 23:25:08 +01:00
|
|
|
board_early_initialize();
|
2019-02-18 22:32:00 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-18 23:25:08 +01:00
|
|
|
/* Hardware resources are now available */
|
2016-02-05 15:34:03 +01:00
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_HARDWARE;
|
2016-02-05 15:34:03 +01:00
|
|
|
|
2019-02-19 00:36:11 +01:00
|
|
|
/* Setup for Multi-Tasking ************************************************/
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Announce that the CPU0 IDLE task has started */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
sched_note_start(&g_idletcb[0]);
|
2016-02-13 16:04:54 +01:00
|
|
|
|
2021-07-15 12:25:48 +02:00
|
|
|
/* Initialize stdio for the IDLE task of each CPU */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2021-07-10 03:01:20 +02:00
|
|
|
for (i = 0; i < CONFIG_SMP_NCPUS; i++)
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
2021-07-10 03:01:20 +02:00
|
|
|
if (i > 0)
|
2016-02-13 16:04:54 +01:00
|
|
|
{
|
|
|
|
/* Clone stdout, stderr, stdin from the CPU0 IDLE task. */
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
DEBUGVERIFY(group_setuptaskfiles(
|
|
|
|
(FAR struct task_tcb_s *)&g_idletcb[i], NULL, true));
|
2016-02-13 16:04:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
2023-10-15 08:27:39 +02:00
|
|
|
DEBUGVERIFY(group_setupidlefiles());
|
2016-02-13 16:04:54 +01:00
|
|
|
}
|
2016-06-21 15:52:24 +02: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 */
|
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
DEBUGASSERT(this_cpu() == 0);
|
2016-02-15 18:07:42 +01:00
|
|
|
|
|
|
|
/* Then start the other CPUs */
|
|
|
|
|
2019-02-04 23:20:35 +01:00
|
|
|
DEBUGVERIFY(nx_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 ****************************************************/
|
2019-06-30 18:35:10 +02:00
|
|
|
|
2016-02-05 15:34:03 +01:00
|
|
|
/* The OS is fully initialized and we are beginning multi-tasking */
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_OSREADY;
|
2016-02-05 15:34:03 +01:00
|
|
|
|
2011-03-12 18:49:47 +01:00
|
|
|
/* Create initial tasks and bring-up the system */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-02-04 23:20:35 +01:00
|
|
|
DEBUGVERIFY(nx_bringup());
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-02-21 11:14:10 +01:00
|
|
|
/* Enter to idleloop */
|
|
|
|
|
2024-06-06 10:49:50 +02:00
|
|
|
g_nx_initstate = OSINIT_IDLELOOP;
|
2022-02-21 11:14:10 +01:00
|
|
|
|
2021-06-03 14:57:10 +02:00
|
|
|
/* Let other threads have access to the memory manager */
|
|
|
|
|
2023-02-22 04:08:22 +01:00
|
|
|
sched_trace_end();
|
2021-06-03 14:57:10 +02:00
|
|
|
sched_unlock();
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* The IDLE Loop **********************************************************/
|
2019-06-30 18:35:10 +02:00
|
|
|
|
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");
|
2023-05-16 14:02:22 +02:00
|
|
|
#ifndef CONFIG_DISABLE_IDLE_LOOP
|
2015-10-08 03:59:14 +02:00
|
|
|
for (; ; )
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
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();
|
|
|
|
}
|
2023-05-16 14:02:22 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|