summaryrefslogtreecommitdiff
path: root/nuttx
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
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')
-rw-r--r--nuttx/include/nuttx/wqueue.h23
-rw-r--r--nuttx/libc/wqueue/Make.defs4
-rw-r--r--nuttx/libc/wqueue/work_usrstart.c115
-rw-r--r--nuttx/libc/wqueue/work_usrthread.c48
-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
8 files changed, 202 insertions, 234 deletions
diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h
index 8af1c938f..e572493fa 100644
--- a/nuttx/include/nuttx/wqueue.h
+++ b/nuttx/include/nuttx/wqueue.h
@@ -344,29 +344,6 @@ extern "C"
void work_process(FAR struct wqueue_s *wqueue);
/****************************************************************************
- * Name: work_usrthread
- *
- * Description:
- * This is the worker thread that performs the actions placed on the user
- * work queue.
- *
- * This is a user mode work queue. It must be used by applications for
- * miscellaneous operations. The user work thread must be started by
- * application start-up logic by calling work_usrstart().
- *
- * Input parameters:
- * argc, argv (not used)
- *
- * Returned Value:
- * Does not return
- *
- ****************************************************************************/
-
-#if defined(CONFIG_SCHED_USRWORK) && !defined(__KERNEL__)
-int work_usrthread(int argc, char *argv[]);
-#endif
-
-/****************************************************************************
* Name: work_usrstart
*
* Description:
diff --git a/nuttx/libc/wqueue/Make.defs b/nuttx/libc/wqueue/Make.defs
index 87c5437e3..2b953626e 100644
--- a/nuttx/libc/wqueue/Make.defs
+++ b/nuttx/libc/wqueue/Make.defs
@@ -40,10 +40,10 @@ ifeq ($(CONFIG_SCHED_WORKQUEUE),y)
CSRCS += work_process.c work_queue.c work_cancel.c work_signal.c
ifeq ($(CONFIG_BUILD_PROTECTED),y)
-CSRCS += work_usrstart.c work_usrthread.c
+CSRCS += work_usrthread.c
else
ifeq ($(CONFIG_BUILD_KERNEL),y)
-CSRCS += work_usrstart.c work_usrthread.c
+CSRCS += work_usrthread.c
endif
endif
diff --git a/nuttx/libc/wqueue/work_usrstart.c b/nuttx/libc/wqueue/work_usrstart.c
deleted file mode 100644
index 00264cbe8..000000000
--- a/nuttx/libc/wqueue/work_usrstart.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
- * libc/wqueue/work_usrstart.c
- *
- * Copyright (C) 2013 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gnutt@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sched.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/wqueue.h>
-
-#if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__) && \
- defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_SCHED_USRWORK)
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Type Declarations
- ****************************************************************************/
-
-/****************************************************************************
- * Public Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Private Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-/****************************************************************************
- * Name: work_usrstart
- *
- * Description:
- * Start the user 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_usrstart(void)
-{
- /* Start a user-mode worker thread for use by applications. */
-
- svdbg("Starting user-mode worker thread\n");
-
- g_usrwork[USRWORK].pid = task_create("usrwork",
- CONFIG_SCHED_USRWORKPRIORITY,
- CONFIG_SCHED_USRWORKSTACKSIZE,
- (main_t)work_usrthread,
- (FAR char * const *)NULL);
-
- DEBUGASSERT(g_usrwork[USRWORK].pid > 0);
- if (g_usrwork[USRWORK].pid < 0)
- {
- int errcode = errno;
- DEBUGASSERT(errcode > 0);
-
- sdbg("task_create failed: %d\n", errcode);
- return -errcode;
- }
-
- return g_usrwork[USRWORK].pid;
-}
-
-#endif /* CONFIG_BUILD_PROTECTED && !__KERNEL__ CONFIG_SCHED_WORKQUEUE && CONFIG_SCHED_USRWORK */
diff --git a/nuttx/libc/wqueue/work_usrthread.c b/nuttx/libc/wqueue/work_usrthread.c
index f46924a06..b20babcea 100644
--- a/nuttx/libc/wqueue/work_usrthread.c
+++ b/nuttx/libc/wqueue/work_usrthread.c
@@ -39,6 +39,8 @@
#include <nuttx/config.h>
+#include <debug.h>
+
#include <nuttx/wqueue.h>
#if defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_SCHED_USRWORK) && \
@@ -87,7 +89,7 @@ extern struct wqueue_s g_usrwork;
*
****************************************************************************/
-int work_usrthread(int argc, char *argv[])
+static int work_usrthread(int argc, char *argv[])
{
/* Loop forever */
@@ -103,4 +105,48 @@ int work_usrthread(int argc, char *argv[])
return OK; /* To keep some compilers happy */
}
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: work_usrstart
+ *
+ * Description:
+ * Start the user 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_usrstart(void)
+{
+ /* Start a user-mode worker thread for use by applications. */
+
+ svdbg("Starting user-mode worker thread\n");
+
+ g_usrwork.pid = task_create("uwork",
+ CONFIG_SCHED_USRWORKPRIORITY,
+ CONFIG_SCHED_USRWORKSTACKSIZE,
+ (main_t)work_usrthread,
+ (FAR char * const *)NULL);
+
+ DEBUGASSERT(g_usrwork.pid > 0);
+ if (g_usrwork.pid < 0)
+ {
+ int errcode = errno;
+ DEBUGASSERT(errcode > 0);
+
+ sdbg("task_create failed: %d\n", errcode);
+ return -errcode;
+ }
+
+ return g_usrwork.pid;
+}
+
#endif /* CONFIG_SCHED_WORKQUEUE && CONFIG_SCHED_USRWORK && !__KERNEL__*/
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 */