summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-10-10 09:34:03 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-10-10 09:38:28 -0600
commit6c1b5b7358c89907d4de7b9d433993ef7a5c9325 (patch)
treeda5861abed2ed00ffd6c89da95203386ed843d10 /nuttx/sched
parentcebd34bc8c6a04b2cdc5671feb533526c4478ac7 (diff)
downloadnuttx-6c1b5b7358c89907d4de7b9d433993ef7a5c9325.tar.gz
nuttx-6c1b5b7358c89907d4de7b9d433993ef7a5c9325.tar.bz2
nuttx-6c1b5b7358c89907d4de7b9d433993ef7a5c9325.zip
Modularize starting of worker threads to better isolate individual initialization characteristics
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/init/os_bringup.c90
-rw-r--r--nuttx/sched/wqueue/kwork_hpthread.c49
-rw-r--r--nuttx/sched/wqueue/kwork_lpthread.c49
-rw-r--r--nuttx/sched/wqueue/wqueue.h58
4 files changed, 153 insertions, 93 deletions
diff --git a/nuttx/sched/init/os_bringup.c b/nuttx/sched/init/os_bringup.c
index b4a5537d5..09f31d2e0 100644
--- a/nuttx/sched/init/os_bringup.c
+++ b/nuttx/sched/init/os_bringup.c
@@ -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
-#ifdef CONFIG_SCHED_LPWORK
- svdbg("Starting high-priority kernel worker thread\n");
-#else
- svdbg("Starting kernel worker thread\n");
-#endif
+ /* Start the high-priority worker thread to support device driver lower
+ * halves.
+ */
- 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);
+ (void)work_hpstart();
- /* Start a lower priority worker thread for other, non-critical continuation
- * tasks
- */
+#endif /* CONFIG_SCHED_HPWORK */
#ifdef CONFIG_SCHED_LPWORK
+ /* Start the low-priority worker thread for other, non-critical continuation
+ * tasks
+ */
- 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. */
diff --git a/nuttx/sched/wqueue/kwork_hpthread.c b/nuttx/sched/wqueue/kwork_hpthread.c
index 88b2e502d..45c700431 100644
--- a/nuttx/sched/wqueue/kwork_hpthread.c
+++ b/nuttx/sched/wqueue/kwork_hpthread.c
@@ -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*/
diff --git a/nuttx/sched/wqueue/kwork_lpthread.c b/nuttx/sched/wqueue/kwork_lpthread.c
index c3991dc4d..96fd1a68d 100644
--- a/nuttx/sched/wqueue/kwork_lpthread.c
+++ b/nuttx/sched/wqueue/kwork_lpthread.c
@@ -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 */
diff --git a/nuttx/sched/wqueue/wqueue.h b/nuttx/sched/wqueue/wqueue.h
index 1c1127ee8..0c95b8501 100644
--- a/nuttx/sched/wqueue/wqueue.h
+++ b/nuttx/sched/wqueue/wqueue.h
@@ -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 */