forked from nuttx/nuttx-update
sched/spawn: Support task_spawnattr_[set|get]stackaddr
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
b9b032af72
commit
64e7833cbc
14 changed files with 68 additions and 25 deletions
|
@ -134,6 +134,9 @@ pointer to a write-able instance of :c:struct:`binfmt_s`.
|
||||||
|
|
||||||
uint8_t priority; /* Task execution priority */
|
uint8_t priority; /* Task execution priority */
|
||||||
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
FAR void *stackaddr; /* Task stack address */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
Where the types ``binfmt_ctor_t`` and ``binfmt_dtor_t`` define the type
|
Where the types ``binfmt_ctor_t`` and ``binfmt_dtor_t`` define the type
|
||||||
|
|
|
@ -70,6 +70,9 @@ int binfmt_dumpmodule(FAR const struct binary_s *bin)
|
||||||
binfo(" addrenv: %p\n", bin->addrenv);
|
binfo(" addrenv: %p\n", bin->addrenv);
|
||||||
#endif
|
#endif
|
||||||
binfo(" stacksize: %zd\n", bin->stacksize);
|
binfo(" stacksize: %zd\n", bin->stacksize);
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
binfo(" stackaddr: %p\n", bin->stackaddr);
|
||||||
|
#endif
|
||||||
binfo(" unload: %p\n", bin->unload);
|
binfo(" unload: %p\n", bin->unload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,13 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||||
{
|
{
|
||||||
bin->stacksize = attr->stacksize;
|
bin->stacksize = attr->stacksize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
if (attr->stackaddr != NULL)
|
||||||
|
{
|
||||||
|
bin->stackaddr = attr->stackaddr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable pre-emption so that the executed module does
|
/* Disable pre-emption so that the executed module does
|
||||||
|
|
|
@ -120,6 +120,7 @@ int exec_module(FAR const struct binary_s *binp,
|
||||||
save_addrenv_t oldenv;
|
save_addrenv_t oldenv;
|
||||||
FAR void *vheap;
|
FAR void *vheap;
|
||||||
#endif
|
#endif
|
||||||
|
FAR void *stackaddr = NULL;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -189,14 +190,18 @@ int exec_module(FAR const struct binary_s *binp,
|
||||||
|
|
||||||
/* Initialize the task */
|
/* Initialize the task */
|
||||||
|
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
stackaddr = binp->stackaddr;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argv && argv[0])
|
if (argv && argv[0])
|
||||||
{
|
{
|
||||||
ret = nxtask_init(tcb, argv[0], binp->priority, NULL,
|
ret = nxtask_init(tcb, argv[0], binp->priority, stackaddr,
|
||||||
binp->stacksize, binp->entrypt, &argv[1], envp);
|
binp->stacksize, binp->entrypt, &argv[1], envp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = nxtask_init(tcb, filename, binp->priority, NULL,
|
ret = nxtask_init(tcb, filename, binp->priority, stackaddr,
|
||||||
binp->stacksize, binp->entrypt, argv, envp);
|
binp->stacksize, binp->entrypt, argv, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1603,7 +1603,7 @@ static void uart_launch_worker(void *arg)
|
||||||
#ifdef CONFIG_TTY_LAUNCH_ENTRY
|
#ifdef CONFIG_TTY_LAUNCH_ENTRY
|
||||||
nxtask_create(CONFIG_TTY_LAUNCH_ENTRYNAME,
|
nxtask_create(CONFIG_TTY_LAUNCH_ENTRYNAME,
|
||||||
CONFIG_TTY_LAUNCH_PRIORITY,
|
CONFIG_TTY_LAUNCH_PRIORITY,
|
||||||
CONFIG_TTY_LAUNCH_STACKSIZE,
|
NULL, CONFIG_TTY_LAUNCH_STACKSIZE,
|
||||||
CONFIG_TTY_LAUNCH_ENTRYPOINT,
|
CONFIG_TTY_LAUNCH_ENTRYPOINT,
|
||||||
argv, NULL);
|
argv, NULL);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -98,6 +98,10 @@ struct binary_s
|
||||||
uint8_t priority; /* Task execution priority */
|
uint8_t priority; /* Task execution priority */
|
||||||
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
||||||
|
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
FAR void *stackaddr; /* Task stack address */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Unload module callback */
|
/* Unload module callback */
|
||||||
|
|
||||||
CODE int (*unload)(FAR struct binary_s *bin);
|
CODE int (*unload)(FAR struct binary_s *bin);
|
||||||
|
|
|
@ -60,7 +60,7 @@ extern "C"
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* name - Name of the new task
|
* name - Name of the new task
|
||||||
* priority - Priority of the new task
|
* priority - Priority of the new task
|
||||||
* stack_ptr - Stack buffer of the new task
|
* stack_addr - Stack buffer of the new task
|
||||||
* stack_size - Stack size of the new task
|
* stack_size - Stack size of the new task
|
||||||
* entry - Entry point of a new task
|
* entry - Entry point of a new task
|
||||||
* arg - A pointer to an array of input parameters. The array
|
* arg - A pointer to an array of input parameters. The array
|
||||||
|
@ -75,7 +75,7 @@ extern "C"
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int kthread_create_with_stack(FAR const char *name, int priority,
|
int kthread_create_with_stack(FAR const char *name, int priority,
|
||||||
FAR void *stack_ptr, int stack_size,
|
FAR void *stack_addr, int stack_size,
|
||||||
main_t entry, FAR char * const argv[]);
|
main_t entry, FAR char * const argv[]);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -947,8 +947,8 @@ void nxtask_uninit(FAR struct task_tcb_s *tcb);
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxtask_create(FAR const char *name,
|
int nxtask_create(FAR const char *name, int priority,
|
||||||
int priority, int stack_size, main_t entry,
|
FAR void *stack_addr, int stack_size, main_t entry,
|
||||||
FAR char * const argv[], FAR char * const envp[]);
|
FAR char * const argv[], FAR char * const envp[]);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -221,6 +221,9 @@ extern "C"
|
||||||
#ifndef CONFIG_BUILD_KERNEL
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
int task_create(FAR const char *name, int priority, int stack_size,
|
int task_create(FAR const char *name, int priority, int stack_size,
|
||||||
main_t entry, FAR char * const argv[]);
|
main_t entry, FAR char * const argv[]);
|
||||||
|
int task_create_with_stack(FAR const char *name, int priority,
|
||||||
|
FAR void *stack_addr, int stack_size,
|
||||||
|
main_t entry, FAR char * const argv[]);
|
||||||
#endif
|
#endif
|
||||||
int task_delete(pid_t pid);
|
int task_delete(pid_t pid);
|
||||||
int task_restart(pid_t pid);
|
int task_restart(pid_t pid);
|
||||||
|
|
|
@ -102,5 +102,9 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
|
||||||
|
|
||||||
attr->stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
|
attr->stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
|
||||||
|
|
||||||
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
|
attr->stackaddr = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,11 +262,11 @@ static inline void nx_start_application(void)
|
||||||
# ifdef CONFIG_BUILD_PROTECTED
|
# ifdef CONFIG_BUILD_PROTECTED
|
||||||
DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
|
DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
|
||||||
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
|
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
|
||||||
CONFIG_INIT_STACKSIZE,
|
NULL, CONFIG_INIT_STACKSIZE,
|
||||||
USERSPACE->us_entrypoint, argv, NULL);
|
USERSPACE->us_entrypoint, argv, NULL);
|
||||||
# else
|
# else
|
||||||
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
|
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
|
||||||
CONFIG_INIT_STACKSIZE,
|
NULL, CONFIG_INIT_STACKSIZE,
|
||||||
CONFIG_INIT_ENTRYPOINT, argv, NULL);
|
CONFIG_INIT_ENTRYPOINT, argv, NULL);
|
||||||
# endif
|
# endif
|
||||||
DEBUGASSERT(ret > 0);
|
DEBUGASSERT(ret > 0);
|
||||||
|
|
|
@ -298,7 +298,7 @@ extern volatile spinlock_t g_cpu_tasklistlock;
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
||||||
FAR void *stack_ptr, int stack_size, main_t entry,
|
FAR void *stack_addr, int stack_size, main_t entry,
|
||||||
FAR char * const argv[], FAR char * const envp[]);
|
FAR char * const argv[], FAR char * const envp[]);
|
||||||
|
|
||||||
/* Task list manipulation functions */
|
/* Task list manipulation functions */
|
||||||
|
|
|
@ -55,7 +55,8 @@
|
||||||
* name - Name of the new task
|
* name - Name of the new task
|
||||||
* ttype - Type of the new task
|
* ttype - Type of the new task
|
||||||
* priority - Priority of the new task
|
* priority - Priority of the new task
|
||||||
* stack_size - size (in bytes) of the stack needed
|
* stack_addr - Address of the stack needed
|
||||||
|
* stack_size - Size (in bytes) of the stack needed
|
||||||
* entry - Entry point of a new task
|
* entry - Entry point of a new task
|
||||||
* arg - A pointer to an array of input parameters. The array
|
* arg - A pointer to an array of input parameters. The array
|
||||||
* should be terminated with a NULL argv[] value. If no
|
* should be terminated with a NULL argv[] value. If no
|
||||||
|
@ -71,7 +72,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
||||||
FAR void *stack_ptr, int stack_size, main_t entry,
|
FAR void *stack_addr, int stack_size, main_t entry,
|
||||||
FAR char * const argv[], FAR char * const envp[])
|
FAR char * const argv[], FAR char * const envp[])
|
||||||
{
|
{
|
||||||
FAR struct task_tcb_s *tcb;
|
FAR struct task_tcb_s *tcb;
|
||||||
|
@ -93,7 +94,7 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
||||||
|
|
||||||
/* Initialize the task */
|
/* Initialize the task */
|
||||||
|
|
||||||
ret = nxtask_init(tcb, name, priority, stack_ptr, stack_size,
|
ret = nxtask_init(tcb, name, priority, stack_addr, stack_size,
|
||||||
entry, argv, envp);
|
entry, argv, envp);
|
||||||
if (ret < OK)
|
if (ret < OK)
|
||||||
{
|
{
|
||||||
|
@ -137,7 +138,8 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* name - Name of the new task
|
* name - Name of the new task
|
||||||
* priority - Priority of the new task
|
* priority - Priority of the new task
|
||||||
* stack_size - size (in bytes) of the stack needed
|
* stack_addr - Address of the stack needed
|
||||||
|
* stack_size - Size (in bytes) of the stack needed
|
||||||
* entry - Entry point of a new task
|
* entry - Entry point of a new task
|
||||||
* arg - A pointer to an array of input parameters. The array
|
* arg - A pointer to an array of input parameters. The array
|
||||||
* should be terminated with a NULL argv[] value. If no
|
* should be terminated with a NULL argv[] value. If no
|
||||||
|
@ -152,11 +154,11 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxtask_create(FAR const char *name,
|
int nxtask_create(FAR const char *name, int priority,
|
||||||
int priority, int stack_size, main_t entry,
|
FAR void *stack_addr, int stack_size, main_t entry,
|
||||||
FAR char * const argv[], FAR char * const envp[])
|
FAR char * const argv[], FAR char * const envp[])
|
||||||
{
|
{
|
||||||
return nxthread_create(name, TCB_FLAG_TTYPE_TASK, priority, NULL,
|
return nxthread_create(name, TCB_FLAG_TTYPE_TASK, priority, stack_addr,
|
||||||
stack_size, entry, argv, envp ? envp : environ);
|
stack_size, entry, argv, envp ? envp : environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,10 +195,12 @@ int nxtask_create(FAR const char *name,
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_BUILD_KERNEL
|
#ifndef CONFIG_BUILD_KERNEL
|
||||||
int task_create(FAR const char *name, int priority,
|
int task_create_with_stack(FAR const char *name, int priority,
|
||||||
int stack_size, main_t entry, FAR char * const argv[])
|
FAR void *stack_addr, int stack_size,
|
||||||
|
main_t entry, FAR char * const argv[])
|
||||||
{
|
{
|
||||||
int ret = nxtask_create(name, priority, stack_size, entry, argv, NULL);
|
int ret = nxtask_create(name, priority, stack_addr,
|
||||||
|
stack_size, entry, argv, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
set_errno(-ret);
|
set_errno(-ret);
|
||||||
|
@ -205,6 +209,13 @@ int task_create(FAR const char *name, int priority,
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int task_create(FAR const char *name, int priority,
|
||||||
|
int stack_size, main_t entry, FAR char * const argv[])
|
||||||
|
{
|
||||||
|
return task_create_with_stack(name, priority, NULL,
|
||||||
|
stack_size, entry, argv);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -218,7 +229,7 @@ int task_create(FAR const char *name, int priority,
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* name - Name of the new task
|
* name - Name of the new task
|
||||||
* priority - Priority of the new task
|
* priority - Priority of the new task
|
||||||
* stack_ptr - Stack buffer of the new task
|
* stack_addr - Stack buffer of the new task
|
||||||
* stack_size - Stack size of the new task
|
* stack_size - Stack size of the new task
|
||||||
* entry - Entry point of a new task
|
* entry - Entry point of a new task
|
||||||
* arg - A pointer to an array of input parameters. The array
|
* arg - A pointer to an array of input parameters. The array
|
||||||
|
@ -233,11 +244,11 @@ int task_create(FAR const char *name, int priority,
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int kthread_create_with_stack(FAR const char *name, int priority,
|
int kthread_create_with_stack(FAR const char *name, int priority,
|
||||||
FAR void *stack_ptr, int stack_size,
|
FAR void *stack_addr, int stack_size,
|
||||||
main_t entry, FAR char * const argv[])
|
main_t entry, FAR char * const argv[])
|
||||||
{
|
{
|
||||||
return nxthread_create(name, TCB_FLAG_TTYPE_KERNEL, priority,
|
return nxthread_create(name, TCB_FLAG_TTYPE_KERNEL, priority,
|
||||||
stack_ptr, stack_size, entry, argv, NULL);
|
stack_addr, stack_size, entry, argv, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -92,6 +92,7 @@ static int nxtask_spawn_exec(FAR pid_t *pidp, FAR const char *name,
|
||||||
main_t entry, FAR const posix_spawnattr_t *attr,
|
main_t entry, FAR const posix_spawnattr_t *attr,
|
||||||
FAR char * const *argv, FAR char * const envp[])
|
FAR char * const *argv, FAR char * const envp[])
|
||||||
{
|
{
|
||||||
|
FAR void *stackaddr = NULL;
|
||||||
size_t stacksize;
|
size_t stacksize;
|
||||||
int priority;
|
int priority;
|
||||||
int pid;
|
int pid;
|
||||||
|
@ -110,6 +111,7 @@ static int nxtask_spawn_exec(FAR pid_t *pidp, FAR const char *name,
|
||||||
{
|
{
|
||||||
priority = attr->priority;
|
priority = attr->priority;
|
||||||
stacksize = attr->stacksize;
|
stacksize = attr->stacksize;
|
||||||
|
stackaddr = attr->stackaddr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -129,7 +131,8 @@ static int nxtask_spawn_exec(FAR pid_t *pidp, FAR const char *name,
|
||||||
|
|
||||||
/* Start the task */
|
/* Start the task */
|
||||||
|
|
||||||
pid = nxtask_create(name, priority, stacksize, entry, argv, envp);
|
pid = nxtask_create(name, priority, stackaddr,
|
||||||
|
stacksize, entry, argv, envp);
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
ret = pid;
|
ret = pid;
|
||||||
|
@ -405,7 +408,7 @@ int task_spawn(FAR const char *name, main_t entry,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
proxy = nxtask_create("nxtask_spawn_proxy", param.sched_priority,
|
proxy = nxtask_create("nxtask_spawn_proxy", param.sched_priority,
|
||||||
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE,
|
NULL, CONFIG_POSIX_SPAWN_PROXY_STACKSIZE,
|
||||||
nxtask_spawn_proxy, NULL, NULL);
|
nxtask_spawn_proxy, NULL, NULL);
|
||||||
if (proxy < 0)
|
if (proxy < 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue