From 7e63b0b28857acf50dcfb48aa6ab920e5b55f949 Mon Sep 17 00:00:00 2001
From: xuanlin Last Updated: August 10, 2018 Last Updated: August 25, 2018
NuttX RTOS Porting Guide
-
Device Driver Bottom Half. - The higher priority worker thread is intended to serve as the bottom half for device drivers. As a consequence it must run at a very high, fixed priority rivalling the priority of the interrupt handler itself. Typically, the high priority work queue should be the highest priority thread in your system (the default priority is 224). + The high-priority worker thread is intended to serve as the bottom half for device drivers. As a consequence it must run at a very high, fixed priority rivalling the priority of the interrupt handler itself. Typically, the high priority work queue should be the highest priority thread in your system (the default priority is 224). +
++ Thread Pool. + The work queues can be configured to support multiple, low-priority threads. This is essentially a thread pool that provides multi-threaded servicing of the queue work. This breaks the strict serialization of the "queue" (and hence, the work queue is no longer a queue at all). +
++ Multiple worker threads are required to support, for example, I/O operations that stall waiting for input. If there is only a single thread, then the entire work queue processing would stall in such cases. + Such behavior is necessary to support asynchronous I/O, AIO, for example.
Compared to the Low Priority Kernel Work Queue.
- For less critical, lower priority, application oriented worker thread support, consider enabling the lower priority work queue. The lower priority work queue runs at a lower priority, of course, but has the added advantage that it supports priority inheritance (if <config> CONFIG_PRIORITY_INHERITANCE is also selected): The priority of the lower priority worker thread can then be adjusted to match the highest priority client.
+ For less critical, lower priority, application oriented worker thread support, consider enabling the lower priority work queue. The lower priority work queue runs at a lower priority, of course, but has the added advantage that it supports priority inheritance (if CONFIG_PRIORITY_INHERITANCE=y
is also selected): The priority of the lower priority worker thread can then be adjusted to match the highest priority client.
Configuration Options. @@ -3021,11 +3029,12 @@ typedef uint32_t wdparm_t;
CONFIG_SCHED_HPWORK
.
Enables the hight priority work queue.
CONFIG_SCHED_HPNTHREADS
.
+ The number of threads in the high-priority queue's thread pool. Default: 1
+ CONFIG_SCHED_HPWORKPRIORITY
.
The execution priority of the high-priority worker thread. Default: 224
CONFIG_SCHED_HPWORKPERIOD
.
- How often the worker thread re-checks for work in units of microseconds. This work period is really only necessary if the high priority thread is performing periodic garbage collection. The worker thread will be awakened immediately with it is queued work to be done. If the high priority worker thread is performing garbage collection, then the default is 50*1000 (50 MS). Otherwise, if the lower priority worker thread is performing garbage collection, the default is 100*1000.
CONFIG_SCHED_HPWORKSTACKSIZE
.
The stack size allocated for the worker thread in bytes. Default: 2048.
Compared to the High Priority Work Queue. - The lower priority work queue runs at a lower priority than the high priority work queue, of course, and so is inappropriate to serve as a driver bottom half. The lower priority work queue has the other advantages, however, that make it better suited for some tasks: + The lower priority work queue runs at a lower priority than the high priority work queue, of course, and so is inappropriate to serve as a driver bottom half. + It is, otherwise, very similar to the high priority work queue and most of the discussion above for the high priority work queue applies equally here. + The lower priority work queue does have one important, however, that make it better suited for some tasks: +
+Priority Inheritance. + The lower priority worker thread(s) support priority inheritance (if <config> CONFIG_PRIORITY_INHERITANCE is also selected): The priority of the lower priority worker thread can then be adjusted to match the highest priority client. +
++ NOTE: This priority inheritance feature is not automatic. The lower priority worker thread will always a fixed priority unless additional logic implements that calls+lpwork_boostpriority()
to raise the priority of the lower priority worker thread (typically called before scheduling the work) and then calls the matchinglpwork_restorepriority()
when the work is completed (typically called within the work handler at the completion of the work). Currently, only the NuttX asynchronous I/O logic uses this dynamic prioritization feature. +
+ The higher priority worker thread, on the other hand, is intended to serve as the bottom half for device drivers. As a consequence must run at a very high, fixed priority. Typically, it should be the highest priority thread in your system.
-Priority Inheritance. - The lower priority worker thread(s) support priority inheritance (if <config> CONFIG_PRIORITY_INHERITANCE is also selected): The priority of the lower priority worker thread can then be adjusted to match the highest priority client. -
-- NOTE: This priority inheritance feature is not automatic. The lower priority worker thread will always a fixed priority unless additional logic implements that calls-lpwork_boostpriority()
to raise the priority of the lower priority worker thread (typically called before scheduling the work) and then calls the matchinglpwork_restorepriority()
when the work is completed (typically called within the work handler at the completion of the work). Currently, only the NuttX asynchronous I/O logic uses this dynamic prioritization feature. -
- The higher priority worker thread, on the other hand, is intended to serve as the bottom half for device drivers. As a consequence must run at a very high, fixed priority. Typically, it should be the highest priority thread in your system. -
-- Thread Pool. - The low-priority work queue can be configured to support multiple, low-priority threads. This is essentially a thread pool that provides multi-threaded servicing of the low-priority work thread. This breaks the strict serialization of the "queue" (and hence, the low-priority work queue is no longer a queue at all). -
-- Multiple worker threads are required to support, for example, I/O operations that stall waiting for input. If there is only a single thread, then the entire low-priority queue processing would stall in such cases. Such behavior is necessary to support asynchronous I/O, AIO, for example. -
-Configuration Options.
@@ -3079,16 +3077,13 @@ typedef uint32_t wdparm_t; If CONFIG_SCHED_LPWORK is selected then a lower-priority work queue will be enabled.CONFIG_SCHED_LPNTHREADS
.
- The number of thread in the low-priority queue's thread pool. Default: 1
+ The number of threads in the low-priority queue's thread pool. Default: 1
CONFIG_SCHED_LPWORKPRIORITY
.
The minimum execution priority of the lower priority worker thread. The priority of the all worker threads start at this priority. If priority inheritance is in effect, the priority may be boosted from this level. Default: 50.
CONFIG_SCHED_LPWORKPRIOMAX
.
- The maximum execution priority of the lower priority worker thread. Lower priority worker threads will be started at CONFIG_SCHED_LPWORKPRIORITY
but their priority may be boosted due to priority inheritance. The boosted priority of the low priority worker thread will not, however, ever exceedCONFIG_SCHED_LPWORKPRIOMAX
. This limit would be necessary, for example, if the higher priority worker thread were to defer work to the lower priority thread. Clearly, in such a case, you would want to limit the maximum priority of the lower priority work thread. Default: 176.
- CONFIG_SCHED_LPWORKPERIOD
.
- How often the lower priority worker thread checks for garbage collection in units of microseconds. Default: 50*1000 (50 MS).
+ The maximum execution priority of the lower priority worker thread. Lower priority worker threads will be started at CONFIG_SCHED_LPWORKPRIORITY
but their priority may be boosted due to priority inheritance. The boosted priority of the low priority worker thread will not, however, ever exceed CONFIG_SCHED_LPWORKPRIOMAX
. This limit would be necessary, for example, if the higher priority worker thread were to defer work to the lower priority thread. Clearly, in such a case, you would want to limit the maximum priority of the lower priority work thread. Default: 176.
CONFIG_SCHED_LPWORKSTACKSIZE
.
The stack size allocated for the lower priority worker thread. Default: 2048.
@@ -3112,8 +3107,6 @@ typedef uint32_t wdparm_t;
If CONFIG_LIB_USRWORK is also defined then the user-mode work queue will be enabled.
CONFIG_LIB_USRWORKPRIORITY
.
The execution priority of the user-mode priority worker thread. Default: 100
- CONFIG_LIB_USRWORKPERIOD
- How often the lower priority worker thread is awakened in units of microseconds. Default: 100*1000 (100 MS).
CONFIG_LIB_USRWORKSTACKSIZE
.
The stack size allocated for the lower priority worker thread. Default: 2048.
diff --git a/configs/b-l475e-iot01a/spirit-6lowpan/defconfig b/configs/b-l475e-iot01a/spirit-6lowpan/defconfig
index 7d7a6c0c21..0c1bcf905d 100644
--- a/configs/b-l475e-iot01a/spirit-6lowpan/defconfig
+++ b/configs/b-l475e-iot01a/spirit-6lowpan/defconfig
@@ -76,7 +76,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/b-l475e-iot01a/spirit-starhub/defconfig b/configs/b-l475e-iot01a/spirit-starhub/defconfig
index 88c8a2da80..52cd7f2a69 100644
--- a/configs/b-l475e-iot01a/spirit-starhub/defconfig
+++ b/configs/b-l475e-iot01a/spirit-starhub/defconfig
@@ -67,7 +67,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/b-l475e-iot01a/spirit-starpoint/defconfig b/configs/b-l475e-iot01a/spirit-starpoint/defconfig
index 1921381f42..3029bd1d3c 100644
--- a/configs/b-l475e-iot01a/spirit-starpoint/defconfig
+++ b/configs/b-l475e-iot01a/spirit-starpoint/defconfig
@@ -78,7 +78,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig
index 483e192cb8..7394e0ad12 100644
--- a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig
+++ b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig
@@ -94,7 +94,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/clicker2-stm32/mrf24j40-starhub/defconfig b/configs/clicker2-stm32/mrf24j40-starhub/defconfig
index 71c1968a2c..61c8e42196 100644
--- a/configs/clicker2-stm32/mrf24j40-starhub/defconfig
+++ b/configs/clicker2-stm32/mrf24j40-starhub/defconfig
@@ -79,7 +79,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/clicker2-stm32/mrf24j40-starpoint/defconfig b/configs/clicker2-stm32/mrf24j40-starpoint/defconfig
index 6c6bb42238..8b52de4bc4 100644
--- a/configs/clicker2-stm32/mrf24j40-starpoint/defconfig
+++ b/configs/clicker2-stm32/mrf24j40-starpoint/defconfig
@@ -96,7 +96,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/clicker2-stm32/xbee-6lowpan/defconfig b/configs/clicker2-stm32/xbee-6lowpan/defconfig
index b717f73d1e..b3b87e4a8a 100644
--- a/configs/clicker2-stm32/xbee-6lowpan/defconfig
+++ b/configs/clicker2-stm32/xbee-6lowpan/defconfig
@@ -90,7 +90,6 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
diff --git a/configs/freedom-k66f/netnsh/defconfig b/configs/freedom-k66f/netnsh/defconfig
index 1bb2557624..2af3cb7c95 100644
--- a/configs/freedom-k66f/netnsh/defconfig
+++ b/configs/freedom-k66f/netnsh/defconfig
@@ -66,7 +66,6 @@ CONFIG_RR_INTERVAL=200
CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
diff --git a/configs/freedom-k66f/nsh/defconfig b/configs/freedom-k66f/nsh/defconfig
index 272933e657..ee263ecf05 100644
--- a/configs/freedom-k66f/nsh/defconfig
+++ b/configs/freedom-k66f/nsh/defconfig
@@ -86,7 +86,6 @@ CONFIG_RTC_HIRES=y
CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SERIAL_TERMIOS=y
diff --git a/configs/lc823450-xgevk/bt/defconfig b/configs/lc823450-xgevk/bt/defconfig
index d61d4bba7f..a6aa231f5a 100644
--- a/configs/lc823450-xgevk/bt/defconfig
+++ b/configs/lc823450-xgevk/bt/defconfig
@@ -145,7 +145,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
diff --git a/configs/lc823450-xgevk/krndis/defconfig b/configs/lc823450-xgevk/krndis/defconfig
index 78af095ba9..41f2a1d890 100644
--- a/configs/lc823450-xgevk/krndis/defconfig
+++ b/configs/lc823450-xgevk/krndis/defconfig
@@ -153,7 +153,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
diff --git a/configs/lc823450-xgevk/rndis/defconfig b/configs/lc823450-xgevk/rndis/defconfig
index 5a7e41716a..524d18adba 100644
--- a/configs/lc823450-xgevk/rndis/defconfig
+++ b/configs/lc823450-xgevk/rndis/defconfig
@@ -150,7 +150,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
diff --git a/configs/lpcxpresso-lpc54628/README.txt b/configs/lpcxpresso-lpc54628/README.txt
index c9b3cbb524..97d17d4a38 100644
--- a/configs/lpcxpresso-lpc54628/README.txt
+++ b/configs/lpcxpresso-lpc54628/README.txt
@@ -422,7 +422,6 @@ Configurations
CONFIG_SCHED_WORKQUEUE=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=224
- CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKSTACKSIZE=2048
CONFIG_MMCSD=y
diff --git a/configs/mikroe-stm32f4/fulldemo/defconfig b/configs/mikroe-stm32f4/fulldemo/defconfig
index 6e20b899ee..19e40ec6b9 100644
--- a/configs/mikroe-stm32f4/fulldemo/defconfig
+++ b/configs/mikroe-stm32f4/fulldemo/defconfig
@@ -114,7 +114,6 @@ CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=20000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=4
diff --git a/configs/mikroe-stm32f4/kostest/defconfig b/configs/mikroe-stm32f4/kostest/defconfig
index 77f8ceee30..65a942d3db 100644
--- a/configs/mikroe-stm32f4/kostest/defconfig
+++ b/configs/mikroe-stm32f4/kostest/defconfig
@@ -63,7 +63,6 @@ CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=20000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=4
diff --git a/configs/olimexino-stm32/smallnsh/defconfig b/configs/olimexino-stm32/smallnsh/defconfig
index 1245c40237..392e5ada44 100644
--- a/configs/olimexino-stm32/smallnsh/defconfig
+++ b/configs/olimexino-stm32/smallnsh/defconfig
@@ -67,7 +67,6 @@ CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=100000
CONFIG_SCHED_HPWORKSTACKSIZE=758
CONFIG_SDCLONE_DISABLE=y
CONFIG_STACK_COLORATION=y
diff --git a/configs/same70-xplained/mrf24j40-starhub/defconfig b/configs/same70-xplained/mrf24j40-starhub/defconfig
index ebc0079cb1..1f629fe9bc 100644
--- a/configs/same70-xplained/mrf24j40-starhub/defconfig
+++ b/configs/same70-xplained/mrf24j40-starhub/defconfig
@@ -110,7 +110,6 @@ CONFIG_SAMV7_SPI0=y
CONFIG_SAMV7_UART3=y
CONFIG_SAMV7_XDMAC=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
CONFIG_SCHED_WAITPID=y
diff --git a/configs/samv71-xult/mrf24j40-starhub/defconfig b/configs/samv71-xult/mrf24j40-starhub/defconfig
index a8ceffb2dd..3ff7ecb263 100644
--- a/configs/samv71-xult/mrf24j40-starhub/defconfig
+++ b/configs/samv71-xult/mrf24j40-starhub/defconfig
@@ -118,7 +118,6 @@ CONFIG_SAMV7_SPI0=y
CONFIG_SAMV7_UART3=y
CONFIG_SAMV7_XDMAC=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=160
CONFIG_SCHED_WAITPID=y
diff --git a/configs/stm32f4discovery/hciuart/defconfig b/configs/stm32f4discovery/hciuart/defconfig
index f1e725c7f9..9ba279f823 100644
--- a/configs/stm32f4discovery/hciuart/defconfig
+++ b/configs/stm32f4discovery/hciuart/defconfig
@@ -56,7 +56,6 @@ CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
-CONFIG_SCHED_HPWORKPERIOD=50000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index 7eb249de23..c0e91057eb 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -62,7 +62,6 @@ CONFIG_RAM_SIZE=245760
CONFIG_RAM_START=0x20010000
CONFIG_RAW_BINARY=y
CONFIG_SCHED_HPWORK=y
-CONFIG_SCHED_HPWORKPERIOD=5000
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1800
CONFIG_SCHED_INSTRUMENTATION=y
diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h
index 1566638ce9..029d9b8b92 100644
--- a/include/nuttx/wqueue.h
+++ b/include/nuttx/wqueue.h
@@ -1,7 +1,8 @@
/****************************************************************************
* include/nuttx/wqueue.h
*
- * Copyright (C) 2009, 2011-2014, 2017 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011-2014, 2017-2018 Gregory Nutt. All rights
+ * reserved.
* Author: Gregory Nutt