mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Modularize starting of worker threads to better isolate individual initialization characteristics
This commit is contained in:
+33
-59
@@ -117,24 +117,10 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If NuttX is built as a separately compiled module, then the config.h header
|
||||
* file should contain the address of the entry point (or path to the file)
|
||||
* that will perform the application-level initialization.
|
||||
*/
|
||||
/* In the protected build (only) we also need to start the user work queue */
|
||||
|
||||
/* Customize some strings */
|
||||
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
# ifdef CONFIG_SCHED_HPWORK
|
||||
# if defined(CONFIG_SCHED_LPWORK)
|
||||
# define HPWORKNAME "hpwork"
|
||||
# define LPWORKNAME "lpwork"
|
||||
# elif defined(CONFIG_SCHED_USRWORK)
|
||||
# define HPWORKNAME "knlwork"
|
||||
# else
|
||||
# define HPWORKNAME "work"
|
||||
# endif
|
||||
# endif
|
||||
#if !defined(CONFIG_BUILD_PROTECTED)
|
||||
# undef CONFIG_SCHED_USRWORK
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -211,47 +197,35 @@ static inline void os_pgworker(void)
|
||||
#ifdef CONFIG_SCHED_WORKQUEUE
|
||||
static inline void os_workqueues(void)
|
||||
{
|
||||
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_SCHED_USRWORK)
|
||||
int taskid;
|
||||
#ifdef CONFIG_SCHED_USRWORK
|
||||
pid_t pid;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_HPWORK
|
||||
/* Start the high-priority worker thread to support device driver lower
|
||||
* halves.
|
||||
*/
|
||||
|
||||
(void)work_hpstart();
|
||||
|
||||
#endif /* CONFIG_SCHED_HPWORK */
|
||||
|
||||
#ifdef CONFIG_SCHED_LPWORK
|
||||
svdbg("Starting high-priority kernel worker thread\n");
|
||||
#else
|
||||
svdbg("Starting kernel worker thread\n");
|
||||
#endif
|
||||
|
||||
g_hpwork.pid = kernel_thread(HPWORKNAME, CONFIG_SCHED_WORKPRIORITY,
|
||||
CONFIG_SCHED_WORKSTACKSIZE,
|
||||
(main_t)work_hpthread,
|
||||
(FAR char * const *)NULL);
|
||||
DEBUGASSERT(g_hpwork.pid > 0);
|
||||
|
||||
/* Start a lower priority worker thread for other, non-critical continuation
|
||||
/* Start the low-priority worker thread for other, non-critical continuation
|
||||
* tasks
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_SCHED_LPWORK
|
||||
|
||||
svdbg("Starting low-priority kernel worker thread\n");
|
||||
|
||||
g_lpwork.pid = kernel_thread(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY,
|
||||
CONFIG_SCHED_LPWORKSTACKSIZE,
|
||||
(main_t)work_lpthread,
|
||||
(FAR char * const *)NULL);
|
||||
DEBUGASSERT(g_lpwork.pid > 0);
|
||||
(void)work_lpstart();
|
||||
|
||||
#endif /* CONFIG_SCHED_LPWORK */
|
||||
#endif /* CONFIG_SCHED_HPWORK */
|
||||
|
||||
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_SCHED_USRWORK)
|
||||
#ifdef CONFIG_SCHED_USRWORK
|
||||
/* Start the user-space work queue */
|
||||
|
||||
DEBUGASSERT(USERSPACE->work_usrstart != NULL);
|
||||
taskid = USERSPACE->work_usrstart();
|
||||
DEBUGASSERT(taskid > 0);
|
||||
UNUSED(taskid);
|
||||
pid = USERSPACE->work_usrstart();
|
||||
DEBUGASSERT(pid > 0);
|
||||
UNUSED(pid);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -278,7 +252,7 @@ static inline void os_workqueues(void)
|
||||
#if defined(CONFIG_INIT_ENTRYPOINT)
|
||||
static inline void os_do_appstart(void)
|
||||
{
|
||||
int taskid;
|
||||
int pid;
|
||||
|
||||
#ifdef CONFIG_BOARD_INITIALIZE
|
||||
/* Perform any last-minute, board-specific initialization, if so
|
||||
@@ -298,16 +272,16 @@ static inline void os_do_appstart(void)
|
||||
|
||||
#ifdef CONFIG_BUILD_PROTECTED
|
||||
DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
|
||||
taskid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE, USERSPACE->us_entrypoint,
|
||||
(FAR char * const *)NULL);
|
||||
pid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE, USERSPACE->us_entrypoint,
|
||||
(FAR char * const *)NULL);
|
||||
#else
|
||||
taskid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE,
|
||||
(main_t)CONFIG_USER_ENTRYPOINT,
|
||||
(FAR char * const *)NULL);
|
||||
pid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE,
|
||||
(main_t)CONFIG_USER_ENTRYPOINT,
|
||||
(FAR char * const *)NULL);
|
||||
#endif
|
||||
ASSERT(taskid > 0);
|
||||
ASSERT(pid > 0);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_INIT_FILEPATH)
|
||||
@@ -389,16 +363,16 @@ static int os_start_task(int argc, FAR char **argv)
|
||||
static inline void os_start_application(void)
|
||||
{
|
||||
#ifdef CONFIG_BOARD_INITTHREAD
|
||||
int taskid;
|
||||
int pid;
|
||||
|
||||
/* Do the board/application initialization on a separate thread of
|
||||
* execution.
|
||||
*/
|
||||
|
||||
taskid = kernel_thread("AppBringUp", CONFIG_BOARD_INITTHREAD_PRIORITY,
|
||||
CONFIG_BOARD_INITTHREAD_STACKSIZE,
|
||||
(main_t)os_start_task, (FAR char * const *)NULL);
|
||||
ASSERT(taskid > 0);
|
||||
pid = kernel_thread("AppBringUp", CONFIG_BOARD_INITTHREAD_PRIORITY,
|
||||
CONFIG_BOARD_INITTHREAD_STACKSIZE,
|
||||
(main_t)os_start_task, (FAR char * const *)NULL);
|
||||
ASSERT(pid > 0);
|
||||
|
||||
#else
|
||||
/* Do the board/application initialization on this thread of execution. */
|
||||
|
||||
@@ -39,7 +39,11 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
@@ -96,7 +100,7 @@ struct wqueue_s g_hpwork;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int work_hpthread(int argc, char *argv[])
|
||||
static int work_hpthread(int argc, char *argv[])
|
||||
{
|
||||
/* Loop forever */
|
||||
|
||||
@@ -123,4 +127,47 @@ int work_hpthread(int argc, char *argv[])
|
||||
return OK; /* To keep some compilers happy */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_hpstart
|
||||
*
|
||||
* Description:
|
||||
* Start the high-priority, kernel-mode work queue.
|
||||
*
|
||||
* Input parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* The task ID of the worker thread is returned on success. A negated
|
||||
* errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int work_hpstart(void)
|
||||
{
|
||||
/* Start the high-priority, kernel mode worker thread */
|
||||
|
||||
svdbg("Starting high-priority kernel worker thread\n");
|
||||
|
||||
g_hpwork.pid = kernel_thread(HPWORKNAME, CONFIG_SCHED_WORKPRIORITY,
|
||||
CONFIG_SCHED_WORKSTACKSIZE,
|
||||
(main_t)work_hpthread,
|
||||
(FAR char * const *)NULL);
|
||||
|
||||
DEBUGASSERT(g_hpwork.pid > 0);
|
||||
if (g_hpwork.pid < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
DEBUGASSERT(errcode > 0);
|
||||
|
||||
slldbg("kernel_thread failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
return g_hpwork.pid;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE && CONFIG_SCHED_HPWORK*/
|
||||
|
||||
@@ -39,7 +39,11 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "wqueue/wqueue.h"
|
||||
@@ -95,7 +99,7 @@ struct wqueue_s g_lpwork;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int work_lpthread(int argc, char *argv[])
|
||||
static int work_lpthread(int argc, char *argv[])
|
||||
{
|
||||
/* Loop forever */
|
||||
|
||||
@@ -120,4 +124,47 @@ int work_lpthread(int argc, char *argv[])
|
||||
return OK; /* To keep some compilers happy */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_lpstart
|
||||
*
|
||||
* Description:
|
||||
* Start the low-priority, kernel-mode worker thread(s)
|
||||
*
|
||||
* Input parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* The task ID of the worker thread is returned on success. A negated
|
||||
* errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int work_lpstart(void)
|
||||
{
|
||||
/* Start the low-priority, kernel mode worker thread(s) */
|
||||
|
||||
svdbg("Starting low-priority kernel worker thread\n");
|
||||
|
||||
g_lpwork.pid = kernel_thread(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY,
|
||||
CONFIG_SCHED_LPWORKSTACKSIZE,
|
||||
(main_t)work_lpthread,
|
||||
(FAR char * const *)NULL);
|
||||
|
||||
DEBUGASSERT(g_lpwork.pid > 0);
|
||||
if (g_lpwork.pid < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
DEBUGASSERT(errcode > 0);
|
||||
|
||||
slldbg("kernel_thread failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
return g_lpwork.pid;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE && CONFIG_SCHED_LPWORK */
|
||||
|
||||
+25
-33
@@ -48,6 +48,19 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Customize kernel thread names */
|
||||
|
||||
#ifdef CONFIG_SCHED_HPWORK
|
||||
# if defined(CONFIG_SCHED_LPWORK)
|
||||
# define HPWORKNAME "hpwork"
|
||||
# define LPWORKNAME "lpwork"
|
||||
# elif defined(CONFIG_SCHED_USRWORK)
|
||||
# define HPWORKNAME "kwork"
|
||||
# else
|
||||
# define HPWORKNAME "work"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
@@ -73,62 +86,41 @@ extern struct wqueue_s g_lpwork;
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_hpthread
|
||||
* Name: work_hpstart
|
||||
*
|
||||
* Description:
|
||||
* This is the worker thread that performs the actions placed on the high
|
||||
* priority work queue.
|
||||
*
|
||||
* This, along with the lower priority worker thread(s) are the kernel
|
||||
* mode work queues (also build in the flat build). One of these threads
|
||||
* also performs periodic garbage collection (that would otherwise be
|
||||
* performed by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined).
|
||||
* That will be the higher priority worker thread only if a lower priority
|
||||
* worker thread is available.
|
||||
*
|
||||
* All kernel mode worker threads are started by the OS during normal
|
||||
* bring up. This entry point is referenced by OS internally and should
|
||||
* not be accessed by application logic.
|
||||
* Start the high-priority, kernel-mode work queue.
|
||||
*
|
||||
* Input parameters:
|
||||
* argc, argv (not used)
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Does not return
|
||||
* The task ID of the worker thread is returned on success. A negated
|
||||
* errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SCHED_HPWORK
|
||||
int work_hpthread(int argc, char *argv[]);
|
||||
int work_hpstart(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: work_lpthread
|
||||
* Name: work_lpstart
|
||||
*
|
||||
* Description:
|
||||
* These are the worker thread(s) that performs the actions placed on the
|
||||
* low priority work queue.
|
||||
*
|
||||
* These, along with the higher priority worker thread are the kernel mode
|
||||
* work queues (also build in the flat build). One of these threads also
|
||||
* performs periodic garbage collection (that would otherwise be performed
|
||||
* by the idle thread if CONFIG_SCHED_WORKQUEUE is not defined). That will
|
||||
* be the lower priority worker thread if it is available.
|
||||
*
|
||||
* All kernel mode worker threads are started by the OS during normal
|
||||
* bring up. This entry point is referenced by OS internally and should
|
||||
* not be accessed by application logic.
|
||||
* Start the low-priority, kernel-mode worker thread(s)
|
||||
*
|
||||
* Input parameters:
|
||||
* argc, argv (not used)
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Does not return
|
||||
* The task ID of the worker thread is returned on success. A negated
|
||||
* errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SCHED_LPWORK
|
||||
int work_lpthread(int argc, char *argv[]);
|
||||
int work_lpstart(void);
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
Reference in New Issue
Block a user