2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_setup.c
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2020-03-26 17:40:10 +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-03-11 23:19:01 +01:00
|
|
|
*
|
2020-03-26 17:40:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2020-03-26 17:40:10 +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-03-11 23:19:01 +01:00
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 23:19:01 +01:00
|
|
|
* Included Files
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
|
2007-03-11 23:19:01 +01:00
|
|
|
#include <sys/types.h>
|
2023-08-11 04:31:03 +02:00
|
|
|
#include <ctype.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <stdint.h>
|
2007-03-11 23:19:01 +01:00
|
|
|
#include <sched.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2007-03-11 23:19:01 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
|
2007-03-11 23:19:01 +01:00
|
|
|
#include <nuttx/arch.h>
|
2020-03-26 17:40:10 +01:00
|
|
|
#include <nuttx/sched.h>
|
2017-10-07 20:16:10 +02:00
|
|
|
#include <nuttx/signal.h>
|
2022-05-27 04:05:43 +02:00
|
|
|
#include <nuttx/tls.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 20:55:02 +02:00
|
|
|
#include "pthread/pthread.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-09 00:44:08 +02:00
|
|
|
#include "task/task.h"
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* Pre-processor Definitions
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2018-01-27 16:37:46 +01:00
|
|
|
|
2014-11-13 01:49:58 +01:00
|
|
|
/* This is an artificial limit to detect error conditions where an argv[]
|
|
|
|
* list is not properly terminated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_STACK_ARGS 256
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2016-02-07 00:44:41 +01:00
|
|
|
* Private Data
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
|
|
|
/* This is the name for un-named tasks */
|
|
|
|
|
2007-03-14 00:03:12 +01:00
|
|
|
static const char g_noname[] = "<noname>";
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 23:19:01 +01:00
|
|
|
* Private Functions
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_assign_pid
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function assigns the next unique task ID to a task.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-03-11 23:19:01 +01:00
|
|
|
* tcb - TCB of task
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-11 23:19:01 +01:00
|
|
|
* OK on success; ERROR on failure (errno is not set)
|
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
static int nxtask_assign_pid(FAR struct tcb_s *tcb)
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2021-10-14 05:03:07 +02:00
|
|
|
FAR struct tcb_s **pidhash;
|
2007-03-11 23:19:01 +01:00
|
|
|
pid_t next_pid;
|
|
|
|
int hash_ndx;
|
2023-04-04 23:40:04 +02:00
|
|
|
void *temp;
|
2021-06-15 10:45:40 +02:00
|
|
|
int i;
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2021-01-25 06:28:52 +01:00
|
|
|
/* NOTE:
|
2024-03-20 05:22:08 +01:00
|
|
|
* ERROR means that the nxsched_pidhash()[] table is completely full.
|
2021-01-25 06:28:52 +01:00
|
|
|
* We cannot allow another task to be started.
|
|
|
|
*/
|
|
|
|
|
2021-01-25 00:36:29 +01:00
|
|
|
/* Protect the following operation with a critical section
|
2024-03-20 05:22:08 +01:00
|
|
|
* because nxsched_pidhash() is accessed from an interrupt context
|
2007-03-11 23:19:01 +01:00
|
|
|
*/
|
|
|
|
|
2021-01-25 00:36:29 +01:00
|
|
|
irqstate_t flags = enter_critical_section();
|
2007-03-11 23:19:01 +01:00
|
|
|
|
|
|
|
/* We'll try every allowable pid */
|
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
retry:
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
/* Get the next process ID candidate */
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
next_pid = nxsched_lastpid() + 1;
|
|
|
|
for (i = 0; i < nxsched_npidhash(); i++)
|
2021-06-15 10:45:40 +02:00
|
|
|
{
|
2007-03-11 23:19:01 +01:00
|
|
|
/* Verify that the next_pid is in the valid range */
|
|
|
|
|
|
|
|
if (next_pid <= 0)
|
|
|
|
{
|
|
|
|
next_pid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the hash_ndx associated with the next_pid */
|
|
|
|
|
|
|
|
hash_ndx = PIDHASH(next_pid);
|
|
|
|
|
|
|
|
/* Check if there is a (potential) duplicate of this pid */
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
if (!nxsched_pidhash()[hash_ndx])
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2014-02-23 17:55:01 +01:00
|
|
|
/* Assign this PID to the task */
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
nxsched_pidhash()[hash_ndx] = tcb;
|
2007-03-11 23:19:01 +01:00
|
|
|
tcb->pid = next_pid;
|
2024-03-20 05:22:08 +01:00
|
|
|
nxsched_lastpid() = next_pid;
|
2014-02-23 17:55:01 +01:00
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
return OK;
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|
2021-06-15 10:45:40 +02:00
|
|
|
|
|
|
|
next_pid++;
|
|
|
|
}
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
/* If we get here, then the nxsched_pidhash()[] table is completely full.
|
|
|
|
* We will alloc new space and copy original nxsched_pidhash() to it to
|
2021-06-15 10:45:40 +02:00
|
|
|
* expand space.
|
|
|
|
*/
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
pidhash = kmm_zalloc(nxsched_npidhash() * 2 * sizeof(*pidhash));
|
2021-06-15 10:45:40 +02:00
|
|
|
if (pidhash == NULL)
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
nxsched_npidhash() *= 2;
|
2021-06-15 10:45:40 +02:00
|
|
|
|
|
|
|
/* All original pid and hash_ndx are mismatch,
|
|
|
|
* so we need to rebuild their relationship
|
|
|
|
*/
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
for (i = 0; i < nxsched_npidhash() / 2; i++)
|
2021-06-15 10:45:40 +02:00
|
|
|
{
|
2024-03-20 05:22:08 +01:00
|
|
|
hash_ndx = PIDHASH(nxsched_pidhash()[i]->pid);
|
2021-10-14 05:03:07 +02:00
|
|
|
DEBUGASSERT(pidhash[hash_ndx] == NULL);
|
2024-03-20 05:22:08 +01:00
|
|
|
pidhash[hash_ndx] = nxsched_pidhash()[i];
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
/* Release resource for original g_pidhash, using new g_pidhash */
|
|
|
|
|
2024-03-20 05:22:08 +01:00
|
|
|
temp = nxsched_pidhash();
|
|
|
|
nxsched_pidhash() = pidhash;
|
2023-04-04 23:40:04 +02:00
|
|
|
kmm_free(temp);
|
2021-06-15 10:45:40 +02:00
|
|
|
|
|
|
|
/* Let's try every allowable pid again */
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2021-06-15 10:45:40 +02:00
|
|
|
goto retry;
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
/****************************************************************************
|
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
|
|
|
* Name: nxtask_inherit_affinity
|
2016-02-20 00:33:35 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* exec(), task_create(), and vfork() all inherit the affinity mask from
|
|
|
|
* the parent thread. This is the default for pthread_create() as well
|
|
|
|
* but the affinity mask can be specified in the pthread attributes as
|
|
|
|
* well. pthread_setup() will have to fix up the affinity mask in this
|
|
|
|
* case.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-02-20 00:33:35 +01:00
|
|
|
* tcb - The TCB of the new task.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-02-21 18:27:55 +01:00
|
|
|
* The parent of the new task is the task at the head of the assigned task
|
|
|
|
* list for the current CPU.
|
2016-02-20 00:33:35 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
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
|
|
|
static inline void nxtask_inherit_affinity(FAR struct tcb_s *tcb)
|
2016-02-20 00:33:35 +01:00
|
|
|
{
|
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
|
|
|
tcb->affinity = rtcb->affinity;
|
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
# define nxtask_inherit_affinity(tcb)
|
2016-02-20 00:33:35 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-12 20:58:45 +01:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_save_parent
|
2013-01-12 20:58:45 +01:00
|
|
|
*
|
|
|
|
* Description:
|
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
|
|
|
* Save the task ID of the parent task in the child task's group and
|
|
|
|
* allocate a child status structure to catch the child task's exit
|
|
|
|
* status.
|
2013-01-12 20:58:45 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-23 23:23:46 +01:00
|
|
|
* tcb - The TCB of the new, child task.
|
|
|
|
* ttype - Type of the new thread: task, pthread, or kernel thread
|
2013-01-12 20:58:45 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The parent of the new task is the task at the head of the ready-to-run
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
2020-05-16 17:06:29 +02:00
|
|
|
static inline void nxtask_save_parent(FAR struct tcb_s *tcb, uint8_t ttype)
|
2013-01-12 20:58:45 +01:00
|
|
|
{
|
2016-09-06 18:28:19 +02:00
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL);
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2016-09-06 16:40:55 +02:00
|
|
|
/* Only newly created tasks (and kernel threads) have parents. None of
|
|
|
|
* this logic applies to pthreads with reside in the same group as the
|
|
|
|
* parent and share that same child/parent relationships.
|
2013-01-26 18:28:20 +01:00
|
|
|
*/
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2013-01-26 18:28:20 +01:00
|
|
|
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD)
|
2013-02-04 22:24:00 +01:00
|
|
|
#endif
|
2013-01-26 18:28:20 +01:00
|
|
|
{
|
2016-09-06 18:28:19 +02:00
|
|
|
/* Get the TCB of the parent task. In this case, the calling task. */
|
|
|
|
|
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
|
|
|
|
2021-03-03 18:11:40 +01:00
|
|
|
/* Save the PID of the parent tasks' task group in the child's task
|
2016-09-06 16:40:55 +02:00
|
|
|
* group. Copy the ID from the parent's task group structure to
|
|
|
|
* child's task group.
|
2013-01-26 18:28:20 +01:00
|
|
|
*/
|
2013-12-19 17:01:52 +01:00
|
|
|
|
2021-03-03 18:11:40 +01:00
|
|
|
tcb->group->tg_ppid = rtcb->group->tg_pid;
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2013-01-25 00:18:32 +01:00
|
|
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
2016-09-06 16:40:55 +02:00
|
|
|
/* Tasks can also suppress retention of their child status by applying
|
|
|
|
* the SA_NOCLDWAIT flag with sigaction().
|
2013-01-23 23:23:46 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-14 07:29:47 +02:00
|
|
|
if ((rtcb->group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0)
|
2013-01-23 23:23:46 +01:00
|
|
|
{
|
2016-09-06 16:40:55 +02:00
|
|
|
FAR struct child_status_s *child;
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2016-09-06 16:40:55 +02:00
|
|
|
/* Make sure that there is not already a structure for this PID in
|
|
|
|
* the parent TCB. There should not be.
|
|
|
|
*/
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
child = group_find_child(rtcb->group, tcb->pid);
|
2016-09-06 18:21:41 +02:00
|
|
|
DEBUGASSERT(child == NULL);
|
|
|
|
if (child == NULL)
|
2016-09-06 16:40:55 +02:00
|
|
|
{
|
|
|
|
/* Allocate a new status structure */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
child = group_alloc_child();
|
2016-09-06 16:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we successfully find/allocate the child status structure? */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2016-09-06 18:21:41 +02:00
|
|
|
DEBUGASSERT(child != NULL);
|
|
|
|
if (child != NULL)
|
2016-09-06 16:40:55 +02:00
|
|
|
{
|
|
|
|
/* Yes.. Initialize the structure */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2016-09-06 16:40:55 +02:00
|
|
|
child->ch_flags = ttype;
|
|
|
|
child->ch_pid = tcb->pid;
|
|
|
|
child->ch_status = 0;
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2016-09-06 16:40:55 +02:00
|
|
|
/* Add the entry into the group's list of children */
|
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
group_add_child(rtcb->group, child);
|
2016-09-06 16:40:55 +02:00
|
|
|
}
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
2016-09-06 18:21:41 +02:00
|
|
|
|
|
|
|
#else /* CONFIG_SCHED_CHILD_STATUS */
|
2016-09-06 16:40:55 +02:00
|
|
|
/* Child status is not retained. Simply keep track of the number
|
|
|
|
* child tasks created.
|
|
|
|
*/
|
2016-09-06 15:34:09 +02:00
|
|
|
|
2016-09-06 20:27:12 +02:00
|
|
|
DEBUGASSERT(rtcb->group->tg_nchildren < UINT16_MAX);
|
2016-09-06 16:28:31 +02:00
|
|
|
rtcb->group->tg_nchildren++;
|
2016-09-06 18:21:41 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
2016-09-06 20:27:12 +02:00
|
|
|
}
|
2013-01-12 20:58:45 +01:00
|
|
|
}
|
|
|
|
#else
|
2020-05-16 17:06:29 +02:00
|
|
|
# define nxtask_save_parent(tcb,ttype)
|
2013-01-12 20:58:45 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-18 01:38:05 +02:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_dup_dspace
|
2009-06-18 01:38:05 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* When a new task or thread is created from a PIC module, then that
|
|
|
|
* module (probably) intends the task or thread to execute in the same
|
|
|
|
* D-Space. This function will duplicate the D-Space for that purpose.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2009-06-18 01:38:05 +02:00
|
|
|
* tcb - The TCB of the new task.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2013-01-12 20:58:45 +01:00
|
|
|
* The parent of the new task is the task at the head of the ready-to-run
|
|
|
|
* list.
|
2009-06-18 01:38:05 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PIC
|
2020-05-16 17:06:29 +02:00
|
|
|
static inline void nxtask_dup_dspace(FAR struct tcb_s *tcb)
|
2009-06-18 01:38:05 +02:00
|
|
|
{
|
2016-02-07 00:44:41 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2009-06-18 01:38:05 +02:00
|
|
|
if (rtcb->dspace != NULL)
|
|
|
|
{
|
|
|
|
/* Copy the D-Space structure reference and increment the reference
|
|
|
|
* count on the memory. The D-Space memory will persist until the
|
2020-05-09 16:04:45 +02:00
|
|
|
* last thread exits (see nxsched_release_tcb()).
|
2009-06-18 01:38:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
tcb->dspace = rtcb->dspace;
|
|
|
|
tcb->dspace->crefs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2020-05-16 17:06:29 +02:00
|
|
|
# define nxtask_dup_dspace(tcb)
|
2009-06-18 01:38:05 +02:00
|
|
|
#endif
|
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxthread_setup_scheduler
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2013-02-04 22:24:00 +01:00
|
|
|
* This functions initializes the common portions of the Task Control Block
|
|
|
|
* (TCB) in preparation for starting a new thread.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2020-05-16 17:06:29 +02:00
|
|
|
* nxthread_setup_scheduler() is called from nxtask_setup_scheduler() and
|
|
|
|
* pthread_setup_scheduler().
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Address of the new task's TCB
|
|
|
|
* priority - Priority of the new task
|
2014-01-01 17:29:44 +01:00
|
|
|
* start - Thread startup routine
|
|
|
|
* entry - Thread user entry point
|
2013-01-23 23:23:46 +01:00
|
|
|
* ttype - Type of the new thread: task, pthread, or kernel thread
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-11 23:19:01 +01:00
|
|
|
* OK on success; ERROR on failure.
|
|
|
|
*
|
2009-06-18 01:38:05 +02:00
|
|
|
* This function can only failure is it is unable to assign a new, unique
|
|
|
|
* task ID to the TCB (errno is not set).
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, int priority,
|
|
|
|
start_t start, CODE void *entry,
|
|
|
|
uint8_t ttype)
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2022-12-07 12:39:42 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2009-12-13 19:01:46 +01:00
|
|
|
int ret;
|
2007-03-11 23:19:01 +01:00
|
|
|
|
|
|
|
/* Assign a unique task ID to the task. */
|
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
ret = nxtask_assign_pid(tcb);
|
2007-03-11 23:19:01 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Save task priority and entry point in the TCB */
|
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
tcb->sched_priority = (uint8_t)priority;
|
2016-10-01 19:38:22 +02:00
|
|
|
tcb->init_priority = (uint8_t)priority;
|
2009-03-09 00:33:41 +01:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2009-12-14 19:39:29 +01:00
|
|
|
tcb->base_priority = (uint8_t)priority;
|
2009-03-09 00:33:41 +01:00
|
|
|
#endif
|
2007-03-11 23:19:01 +01:00
|
|
|
tcb->start = start;
|
2013-02-04 22:24:00 +01:00
|
|
|
tcb->entry.main = (main_t)entry;
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2014-01-01 17:29:44 +01:00
|
|
|
/* Save the thread type. This setting will be needed in
|
2013-01-23 23:23:46 +01:00
|
|
|
* up_initial_state() is called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ttype &= TCB_FLAG_TTYPE_MASK;
|
|
|
|
tcb->flags &= ~TCB_FLAG_TTYPE_MASK;
|
|
|
|
tcb->flags |= ttype;
|
|
|
|
|
2021-01-19 08:15:13 +01:00
|
|
|
/* Set the appropriate scheduling policy in the TCB */
|
|
|
|
|
|
|
|
tcb->flags &= ~TCB_FLAG_POLICY_MASK;
|
|
|
|
#if CONFIG_RR_INTERVAL > 0
|
|
|
|
tcb->flags |= TCB_FLAG_SCHED_RR;
|
|
|
|
tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL);
|
|
|
|
#else
|
|
|
|
tcb->flags |= TCB_FLAG_SCHED_FIFO;
|
|
|
|
#endif
|
|
|
|
|
2013-01-25 00:18:32 +01:00
|
|
|
/* Save the task ID of the parent task in the TCB and allocate
|
|
|
|
* a child status structure.
|
|
|
|
*/
|
2013-01-12 20:58:45 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
nxtask_save_parent(tcb, ttype);
|
2013-01-12 20:58:45 +01:00
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* exec(), task_create(), and vfork() all inherit the affinity mask
|
|
|
|
* from the parent thread. This is the default for pthread_create()
|
|
|
|
* as well but the affinity mask can be specified in the pthread
|
|
|
|
* attributes as well. pthread_create() will have to fix up the
|
|
|
|
* affinity mask in this case.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
nxtask_inherit_affinity(tcb);
|
2016-02-20 00:33:35 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-10 19:31:08 +01:00
|
|
|
/* exec(), pthread_create(), task_create(), and vfork() all
|
|
|
|
* inherit the signal mask of the parent thread.
|
2007-03-29 15:34:37 +02:00
|
|
|
*/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2022-12-07 12:39:42 +01:00
|
|
|
tcb->sigprocmask = rtcb->sigprocmask;
|
2007-03-29 15:34:37 +02:00
|
|
|
|
|
|
|
/* Initialize the task state. It does not get a valid state
|
|
|
|
* until it is activated.
|
|
|
|
*/
|
|
|
|
|
2013-01-12 20:58:45 +01:00
|
|
|
tcb->task_state = TSTATE_TASK_INVALID;
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2009-06-18 01:38:05 +02:00
|
|
|
/* Clone the parent tasks D-Space (if it was running PIC). This
|
|
|
|
* must be done before calling up_initial_state() so that the
|
|
|
|
* state setup will take the PIC address base into account.
|
|
|
|
*/
|
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
nxtask_dup_dspace(tcb);
|
2009-06-18 01:38:05 +02:00
|
|
|
|
2007-03-11 23:19:01 +01:00
|
|
|
/* Initialize the processor-specific portion of the TCB */
|
|
|
|
|
|
|
|
up_initial_state(tcb);
|
|
|
|
|
|
|
|
/* Add the task to the inactive task list */
|
|
|
|
|
|
|
|
sched_lock();
|
2024-03-19 05:33:08 +01:00
|
|
|
dq_addfirst((FAR dq_entry_t *)tcb, list_inactivetasks());
|
2007-03-11 23:19:01 +01:00
|
|
|
tcb->task_state = TSTATE_TASK_INACTIVE;
|
|
|
|
sched_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-21 22:51:15 +01:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_setup_name
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Assign the task name.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-01-27 16:37:46 +01:00
|
|
|
* tcb - Address of the new task's TCB
|
|
|
|
* name - Name of the new task
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-03-21 22:51:15 +01:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2020-05-16 17:06:29 +02:00
|
|
|
static void nxtask_setup_name(FAR struct task_tcb_s *tcb,
|
|
|
|
FAR const char *name)
|
2013-03-21 22:51:15 +01:00
|
|
|
{
|
2023-08-11 04:31:03 +02:00
|
|
|
FAR char *dst = tcb->cmn.name;
|
|
|
|
int i;
|
|
|
|
|
2013-03-21 22:51:15 +01:00
|
|
|
/* Copy the name into the TCB */
|
|
|
|
|
2023-08-11 04:31:03 +02:00
|
|
|
for (i = 0; i < CONFIG_TASK_NAME_SIZE; i++)
|
|
|
|
{
|
|
|
|
char c = *name++;
|
|
|
|
|
|
|
|
if (c == '\0')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst++ = isspace(c) ? '_' : c;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst = '\0';
|
2013-03-21 22:51:15 +01:00
|
|
|
}
|
|
|
|
#else
|
2020-05-16 17:06:29 +02:00
|
|
|
# define nxtask_setup_name(t,n)
|
2013-03-21 22:51:15 +01:00
|
|
|
#endif /* CONFIG_TASK_NAME_SIZE */
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_setup_stackargs
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-16 18:05:46 +02:00
|
|
|
* This functions is called only from nxtask_setup_arguments() It will
|
|
|
|
* allocate space on the new task's stack and will copy the argv[] array
|
|
|
|
* and all strings to the task's stack where it is readily accessible to
|
|
|
|
* the task. Data on the stack, on the other hand, is guaranteed to be
|
2014-09-01 23:39:34 +02:00
|
|
|
* accessible no matter what privilege mode the task runs in.
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2021-06-15 07:28:40 +02:00
|
|
|
* tcb - Address of the new task's TCB
|
2022-01-23 23:01:49 +01:00
|
|
|
* argv - A pointer to an array of input parameters. The array should be
|
2021-06-15 07:28:40 +02:00
|
|
|
* terminated with a NULL argv[] value. If no parameters are
|
|
|
|
* required, argv may be NULL.
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2014-09-01 23:39:34 +02:00
|
|
|
* Zero (OK) on success; a negated errno on failure.
|
2013-03-21 22:51:15 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-15 07:45:33 +02:00
|
|
|
static int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
|
|
|
|
FAR const char *name,
|
|
|
|
FAR char * const argv[])
|
2013-03-21 22:51:15 +01:00
|
|
|
{
|
|
|
|
FAR char **stackargv;
|
|
|
|
FAR char *str;
|
|
|
|
size_t strtablen;
|
|
|
|
size_t argvlen;
|
|
|
|
int nbytes;
|
|
|
|
int argc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Get the size of the task name (including the NUL terminator) */
|
|
|
|
|
2021-06-15 07:28:40 +02:00
|
|
|
strtablen = (strlen(name) + 1);
|
2013-03-21 22:51:15 +01:00
|
|
|
|
|
|
|
/* Count the number of arguments and get the accumulated size of the
|
|
|
|
* argument strings (including the null terminators). The argument count
|
|
|
|
* does not include the task name in that will be in argv[0].
|
|
|
|
*/
|
|
|
|
|
|
|
|
argc = 0;
|
2017-03-04 15:49:24 +01:00
|
|
|
if (argv != NULL)
|
2013-03-21 22:51:15 +01:00
|
|
|
{
|
2014-11-13 01:49:58 +01:00
|
|
|
/* A NULL argument terminates the list */
|
2013-03-21 22:51:15 +01:00
|
|
|
|
2014-11-13 01:49:58 +01:00
|
|
|
while (argv[argc])
|
|
|
|
{
|
2014-11-13 13:44:15 +01:00
|
|
|
/* Add the size of this argument (with NUL terminator).
|
|
|
|
* Check each time if the accumulated size exceeds the
|
|
|
|
* size of the allocated stack.
|
|
|
|
*/
|
2013-03-21 22:51:15 +01:00
|
|
|
|
|
|
|
strtablen += (strlen(argv[argc]) + 1);
|
2022-05-31 10:58:07 +02:00
|
|
|
DEBUGASSERT(strtablen < tcb->cmn.adj_stack_size);
|
2014-11-13 14:44:45 +01:00
|
|
|
if (strtablen >= tcb->cmn.adj_stack_size)
|
2014-11-13 13:44:15 +01:00
|
|
|
{
|
2015-10-08 03:59:14 +02:00
|
|
|
return -ENAMETOOLONG;
|
2014-11-13 13:44:15 +01:00
|
|
|
}
|
2014-11-13 01:49:58 +01:00
|
|
|
|
|
|
|
/* Increment the number of args. Here is a sanity check to
|
|
|
|
* prevent running away with an unterminated argv[] list.
|
|
|
|
* MAX_STACK_ARGS should be sufficiently large that this never
|
|
|
|
* happens in normal usage.
|
|
|
|
*/
|
|
|
|
|
2022-05-31 10:58:07 +02:00
|
|
|
DEBUGASSERT(argc <= MAX_STACK_ARGS);
|
2014-11-13 01:49:58 +01:00
|
|
|
if (++argc > MAX_STACK_ARGS)
|
|
|
|
{
|
|
|
|
return -E2BIG;
|
|
|
|
}
|
2013-03-21 22:51:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a stack frame to hold argv[] array and the strings. NOTE
|
|
|
|
* that argc + 2 entries are needed: The number of arguments plus the
|
|
|
|
* task name plus a NULL argv[] entry to terminate the list.
|
|
|
|
*/
|
|
|
|
|
2021-06-15 07:28:40 +02:00
|
|
|
argvlen = (argc + 2) * sizeof(FAR char *);
|
2014-09-01 23:39:34 +02:00
|
|
|
stackargv = (FAR char **)up_stack_frame(&tcb->cmn, argvlen + strtablen);
|
2013-03-21 22:51:15 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(stackargv != NULL);
|
|
|
|
if (stackargv == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the address of the string table that will lie immediately after
|
|
|
|
* the argv[] array and mark it as a null string.
|
|
|
|
*/
|
|
|
|
|
2014-09-01 23:39:34 +02:00
|
|
|
str = (FAR char *)stackargv + argvlen;
|
2013-12-19 17:01:52 +01:00
|
|
|
|
2013-03-21 22:51:15 +01:00
|
|
|
/* Copy the task name. Increment str to skip over the task name and its
|
|
|
|
* NUL terminator in the string buffer.
|
|
|
|
*/
|
|
|
|
|
2021-06-15 07:28:40 +02:00
|
|
|
stackargv[0] = str;
|
|
|
|
nbytes = strlen(name) + 1;
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(str, name, strtablen);
|
2021-06-15 07:28:40 +02:00
|
|
|
str += nbytes;
|
2023-02-08 04:29:09 +01:00
|
|
|
strtablen -= nbytes;
|
2013-03-21 22:51:15 +01:00
|
|
|
|
|
|
|
/* Copy each argument */
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
/* Save the pointer to the location in the string buffer and copy
|
|
|
|
* the argument into the buffer. Increment str to skip over the
|
|
|
|
* argument and its NUL terminator in the string buffer.
|
|
|
|
*/
|
|
|
|
|
2021-06-15 07:28:40 +02:00
|
|
|
stackargv[i + 1] = str;
|
|
|
|
nbytes = strlen(argv[i]) + 1;
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(str, argv[i], strtablen);
|
2021-06-15 07:28:40 +02:00
|
|
|
str += nbytes;
|
2023-02-08 04:29:09 +01:00
|
|
|
strtablen -= nbytes;
|
2013-03-21 22:51:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put a terminator entry at the end of the argv[] array. Then save the
|
2020-02-23 09:50:23 +01:00
|
|
|
* argv[] array pointer in the TCB where it will be recovered later by
|
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
|
|
|
* nxtask_start().
|
2013-03-21 22:51:15 +01:00
|
|
|
*/
|
|
|
|
|
2021-06-15 07:28:40 +02:00
|
|
|
stackargv[argc + 1] = NULL;
|
2024-03-05 05:11:47 +01:00
|
|
|
|
|
|
|
tcb->cmn.group->tg_info->ta_argc = argc;
|
|
|
|
tcb->cmn.group->tg_info->ta_argv = stackargv;
|
2013-03-21 22:51:15 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_setup_scheduler
|
2013-02-04 22:24:00 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This functions initializes a Task Control Block (TCB) in preparation
|
|
|
|
* for starting a new task.
|
|
|
|
*
|
2020-05-25 23:30:40 +02:00
|
|
|
* nxtask_setup_scheduler() is called from nxtask_init() and
|
|
|
|
* nxtask_start().
|
2013-02-04 22:24:00 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Address of the new task's TCB
|
|
|
|
* priority - Priority of the new task
|
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
|
|
|
* start - Start-up function (probably nxtask_start())
|
2013-02-04 22:24:00 +01:00
|
|
|
* main - Application start point of the new task
|
|
|
|
* ttype - Type of the new thread: task or kernel thread
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-02-04 22:24:00 +01:00
|
|
|
* OK on success; ERROR on failure.
|
|
|
|
*
|
|
|
|
* This function can only failure is it is unable to assign a new, unique
|
|
|
|
* task ID to the TCB (errno is not set).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
int nxtask_setup_scheduler(FAR struct task_tcb_s *tcb, int priority,
|
|
|
|
start_t start, main_t main, uint8_t ttype)
|
2013-02-04 22:24:00 +01:00
|
|
|
{
|
|
|
|
/* Perform common thread setup */
|
|
|
|
|
2020-05-16 18:05:46 +02:00
|
|
|
return nxthread_setup_scheduler((FAR struct tcb_s *)tcb, priority,
|
|
|
|
start, (CODE void *)main, ttype);
|
2013-02-04 22:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: pthread_setup_scheduler
|
2013-02-04 22:24:00 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This functions initializes a Task Control Block (TCB) in preparation
|
|
|
|
* for starting a new pthread.
|
|
|
|
*
|
2020-05-16 17:06:29 +02:00
|
|
|
* pthread_setup_scheduler() is called from pthread_create(),
|
2013-02-04 22:24:00 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-01-27 16:37:46 +01:00
|
|
|
* tcb - Address of the new task's TCB
|
|
|
|
* priority - Priority of the new task
|
|
|
|
* start - Start-up function (probably pthread_start())
|
|
|
|
* entry - Entry point of the new pthread
|
|
|
|
* ttype - Type of the new thread: task, pthread, or kernel thread
|
2013-02-04 22:24:00 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-02-04 22:24:00 +01:00
|
|
|
* OK on success; ERROR on failure.
|
|
|
|
*
|
|
|
|
* This function can only failure is it is unable to assign a new, unique
|
|
|
|
* task ID to the TCB (errno is not set).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2020-05-16 17:06:29 +02:00
|
|
|
int pthread_setup_scheduler(FAR struct pthread_tcb_s *tcb, int priority,
|
|
|
|
start_t start, pthread_startroutine_t entry)
|
2013-02-04 22:24:00 +01:00
|
|
|
{
|
|
|
|
/* Perform common thread setup */
|
|
|
|
|
2020-05-16 18:05:46 +02:00
|
|
|
return nxthread_setup_scheduler((FAR struct tcb_s *)tcb, priority,
|
|
|
|
start, (CODE void *)entry,
|
|
|
|
TCB_FLAG_TTYPE_PTHREAD);
|
2013-02-04 22:24:00 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2020-05-16 17:06:29 +02:00
|
|
|
* Name: nxtask_setup_arguments
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2013-03-21 22:51:15 +01:00
|
|
|
* This functions sets up parameters in the Task Control Block (TCB) in
|
|
|
|
* preparation for starting a new thread.
|
|
|
|
*
|
2020-05-25 23:30:40 +02:00
|
|
|
* nxtask_setup_arguments() is called only from nxtask_init() and
|
2020-05-16 18:05:46 +02:00
|
|
|
* nxtask_start() to create a new task. In the "normal" case, the argv[]
|
|
|
|
* array is a structure in the TCB, the arguments are cloned via strdup.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2013-03-21 22:51:15 +01:00
|
|
|
* In the kernel build case, the argv[] array and all strings are copied
|
2014-01-01 17:29:44 +01:00
|
|
|
* to the task's stack. This is done because the TCB (and kernel allocated
|
2013-03-21 22:51:15 +01:00
|
|
|
* strings) are only accessible in kernel-mode. Data on the stack, on the
|
|
|
|
* other hand, is guaranteed to be accessible no matter what mode the
|
|
|
|
* task runs in.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2021-06-15 07:28:40 +02:00
|
|
|
* tcb - Address of the new task's TCB
|
|
|
|
* name - Name of the new task (not used)
|
|
|
|
* argv - A pointer to an array of input parameters. The array should be
|
|
|
|
* terminated with a NULL argv[] value. If no parameters are
|
|
|
|
* required, argv may be NULL.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-11 23:19:01 +01:00
|
|
|
* OK
|
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2021-06-15 07:45:33 +02:00
|
|
|
int nxtask_setup_arguments(FAR struct task_tcb_s *tcb,
|
|
|
|
FAR const char *name, FAR char * const argv[])
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2021-06-15 07:45:33 +02:00
|
|
|
/* Give a name to the unnamed tasks */
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
name = (FAR char *)g_noname;
|
|
|
|
}
|
|
|
|
|
2013-03-21 22:51:15 +01:00
|
|
|
/* Setup the task name */
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
nxtask_setup_name(tcb, name);
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2014-09-01 23:39:34 +02:00
|
|
|
/* Copy the argv[] array and all strings are to the task's stack. Data on
|
|
|
|
* the stack is guaranteed to be accessible by the ask no matter what
|
|
|
|
* privilege mode the task runs in.
|
2013-03-21 22:51:15 +01:00
|
|
|
*/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2021-06-15 07:45:33 +02:00
|
|
|
return nxtask_setup_stackargs(tcb, name, argv);
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|