summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-11-18 00:08:41 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-11-18 00:08:41 +0000
commit0618b39e4c2bd27666efb9e6c41781182ca32d22 (patch)
treea0c1103b3a3d4912848541cb87285c6c7c7bbd1b
parenteb308862f72d775fa499b6f69013f84b573f3826 (diff)
downloadnuttx-0618b39e4c2bd27666efb9e6c41781182ca32d22.tar.gz
nuttx-0618b39e4c2bd27666efb9e6c41781182ca32d22.tar.bz2
nuttx-0618b39e4c2bd27666efb9e6c41781182ca32d22.zip
Fix issues related to work queue timing
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2270 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/Documentation/NuttxPortingGuide.html2
-rw-r--r--nuttx/configs/README.txt2
-rwxr-xr-xnuttx/configs/stm3210e-eval/RIDE/defconfig4
-rwxr-xr-xnuttx/configs/stm3210e-eval/nsh/defconfig4
-rwxr-xr-xnuttx/configs/stm3210e-eval/ostest/defconfig4
-rwxr-xr-xnuttx/configs/stm3210e-eval/usbserial/defconfig4
-rwxr-xr-xnuttx/sched/work_thread.c36
7 files changed, 41 insertions, 15 deletions
diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html
index 1ce105c8f..93c629fe5 100644
--- a/nuttx/Documentation/NuttxPortingGuide.html
+++ b/nuttx/Documentation/NuttxPortingGuide.html
@@ -2148,7 +2148,7 @@ extern void up_ledoff(int led);
</li>
<li>
<code>CONFIG_SCHED_WORKPERIOD</code>: How often the worker thread checks for
- work. Default: 50 MS.
+ work in units of microseconds. Default: 50*1000 (50 MS).
</li>
<li>
<code>CONFIG_SCHED_WORKSTACKSIZE</code>: The stack size allocated for the worker
diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt
index 6ccd83664..17c29286e 100644
--- a/nuttx/configs/README.txt
+++ b/nuttx/configs/README.txt
@@ -256,7 +256,7 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
thread. Default: 50
CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
- work. Default: 50 MS.
+ work in units of microseconds. Default: 50*1000 (50 MS).
CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
diff --git a/nuttx/configs/stm3210e-eval/RIDE/defconfig b/nuttx/configs/stm3210e-eval/RIDE/defconfig
index 7e9a52b64..cc08dc9c0 100755
--- a/nuttx/configs/stm3210e-eval/RIDE/defconfig
+++ b/nuttx/configs/stm3210e-eval/RIDE/defconfig
@@ -307,7 +307,7 @@ CONFIG_HAVE_LIBM=n
# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
# thread. Default: 50
# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
-# work. Default: 50 MS.
+# work in units of microseconds. Default: 50*1000 (50 MS).
# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
# thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
@@ -340,7 +340,7 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_NXFLAT=n
CONFIG_SCHED_WORKQUEUE=n
CONFIG_SCHED_WORKPRIORITY=50
-CONFIG_SCHED_WORKPERIOD=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
CONFIG_SCHED_WORKSTACKSIZE=1024
CONFIG_SIG_SIGWORK=4
diff --git a/nuttx/configs/stm3210e-eval/nsh/defconfig b/nuttx/configs/stm3210e-eval/nsh/defconfig
index 19f682d90..5a41b5b1e 100755
--- a/nuttx/configs/stm3210e-eval/nsh/defconfig
+++ b/nuttx/configs/stm3210e-eval/nsh/defconfig
@@ -317,7 +317,7 @@ CONFIG_HAVE_LIBM=n
# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
# thread. Default: 50
# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
-# work. Default: 50 MS.
+# work in units of microseconds. Default: 50*1000 (50 MS).
# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
# thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
@@ -349,7 +349,7 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_NXFLAT=n
CONFIG_SCHED_WORKQUEUE=y
CONFIG_SCHED_WORKPRIORITY=50
-CONFIG_SCHED_WORKPERIOD=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
CONFIG_SCHED_WORKSTACKSIZE=1024
CONFIG_SIG_SIGWORK=4
diff --git a/nuttx/configs/stm3210e-eval/ostest/defconfig b/nuttx/configs/stm3210e-eval/ostest/defconfig
index 45e416804..0ea76f6cd 100755
--- a/nuttx/configs/stm3210e-eval/ostest/defconfig
+++ b/nuttx/configs/stm3210e-eval/ostest/defconfig
@@ -319,7 +319,7 @@ CONFIG_HAVE_LIBM=n
# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
# thread. Default: 50
# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
-# work. Default: 50 MS.
+# work in units of microseconds. Default: 50*1000 (50 MS).
# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
# thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
@@ -351,7 +351,7 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_NXFLAT=n
CONFIG_SCHED_WORKQUEUE=n
CONFIG_SCHED_WORKPRIORITY=50
-CONFIG_SCHED_WORKPERIOD=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
CONFIG_SCHED_WORKSTACKSIZE=1024
CONFIG_SIG_SIGWORK=4
diff --git a/nuttx/configs/stm3210e-eval/usbserial/defconfig b/nuttx/configs/stm3210e-eval/usbserial/defconfig
index 6d7adf0c0..23910eb2d 100755
--- a/nuttx/configs/stm3210e-eval/usbserial/defconfig
+++ b/nuttx/configs/stm3210e-eval/usbserial/defconfig
@@ -319,7 +319,7 @@ CONFIG_HAVE_LIBM=n
# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
# thread. Default: 50
# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
-# work. Default: 50 MS.
+# work in units of microseconds. Default: 50*1000 (50 MS).
# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
# thread. Default: CONFIG_IDLETHREAD_STACKSIZE.
# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
@@ -352,7 +352,7 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_NXFLAT=n
CONFIG_SCHED_WORKQUEUE=n
CONFIG_SCHED_WORKPRIORITY=50
-CONFIG_SCHED_WORKPERIOD=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
CONFIG_SCHED_WORKSTACKSIZE=1024
CONFIG_SIG_SIGWORK=4
diff --git a/nuttx/sched/work_thread.c b/nuttx/sched/work_thread.c
index d1f415d77..1a772b618 100755
--- a/nuttx/sched/work_thread.c
+++ b/nuttx/sched/work_thread.c
@@ -103,17 +103,24 @@ int work_thread(int argc, char *argv[])
volatile FAR struct work_s *work;
worker_t worker;
FAR void *arg;
+ uint32 elapsed;
+ uint32 remaining;
+ uint32 next;
+ int usec;
irqstate_t flags;
/* Loop forever */
+ usec = CONFIG_SCHED_WORKPERIOD;
+ flags = irqsave();
for (;;)
{
/* Wait awhile to check the work list. We will wait here until either
* the time elapses or until we are awakened by a signal.
*/
- usleep(CONFIG_SCHED_WORKPERIOD);
+ usleep(usec);
+ irqrestore(flags);
/* First, perform garbage collection. This cleans-up memory de-allocations
* that were queued because they could not be freed in that execution
@@ -128,15 +135,19 @@ int work_thread(int argc, char *argv[])
* we process items in the work list.
*/
+ next = CONFIG_SCHED_WORKPERIOD / USEC_PER_TICK;
flags = irqsave();
work = (FAR struct work_s *)g_work.head;
while (work)
{
/* Is this work ready? It is ready if there is no delay or if
- * the delay has elapsed.
+ * the delay has elapsed. qtime is the time that the work was added
+ * to the work queue. It will always be greater than or equal to
+ * zero. Therefore a delay of zero will always execute immediately.
*/
- if (work->delay == 0 || g_system_timer - work->qtime > work->delay)
+ elapsed = g_system_timer - work->qtime;
+ if (elapsed >= work->delay)
{
/* Remove the ready-to-execute work from the list */
@@ -166,12 +177,27 @@ int work_thread(int argc, char *argv[])
}
else
{
- /* This one is not ready, try the next in the list. */
+ /* This one is not ready.. will it be ready before the next
+ * scheduled wakeup interval?
+ */
+
+ remaining = elapsed - work->delay;
+ if (remaining < next)
+ {
+ /* Yes.. Then schedule to wake up when the work is ready */
+
+ next = remaining;
+ }
+
+ /* Then try the next in the list. */
work = (FAR struct work_s *)work->dq.flink;
}
}
- irqrestore(flags);
+
+ /* Now calculate the microsecond delay we should wait */
+
+ usec = next * USEC_PER_TICK;
}
return OK; /* To keep some compilers happy */