how can vxworks task yield the CPU to lower priority tasks for minimumal amount of time?
Is there a method that lets a task give up the CPU for less than 1ms?
The only method that I know of to let other lower priority tasks run is taskDelay(n), where n>=1.
I have always assumed that taskDelay(0) let's all other tasks of equal or greater priority run.
taskDelay(1) lets all lower priority pending tasks run for up to 1ms.
A higher priority task will always run, if it is ready, and if you haven't called taskLock()
or intLock()
etc, so you dont need to taskDelay()
to let higher priority tasks run.
taskDelay(0)
will place the current task at the back of the ready queue for that priority level. If it is the only task at that priority, it will be immediately rescheduled regardless of the presence of lower priority tasks
taskDelay(n>0)
will place the current task at the back of the ready queue, for that priority, and it will not be rescheduled for n
ticks. This will allow any ready tasks of lower priority to run.
The parameter to taskDelay()
is ticks, not ms. The length of this can be determined based on the system clk rate (which you set by sysClkRateSet()
, and read by sysClkRateGet()
). 1 tick might equal 1ms, but only if the system clk rate is 1000. Which it probably wont be. The default rate is 60, which gives a 16ms tick, but this is normally overridden either statically in the kernel config, or dynamically by calling sysClkRateSet()
NOTE: This system clock is not the same as the CPU freq.
There are certain events in VxWorks that force the scheduler to run, for instance, each semGive(), each system clock tick, and taskDelay(). The argument for taskDelay() is ticks of the system clock. sysClkRateGet() will return the rate of your system clock.
For example if sysClkRateGet() returns 10, then each clock tick is 100 ms. So if you call taskDelay(1), then that will tell your task to sleep until the next system tick. However this doesn't guarantee a 100 ms sleep, but instead a sleep of up to 100 ms or as little as 0 ms if the next clock tick is imminent. If you call taskDelay(2), then your task will sleep until the next clock tick (some time between 0 and 100 ms) plus the following clock tick (guaranteed to be 100 ms) - resulting in a total delay of between 100 ms and 200 ms.
Timing in VxWorks has alot of consideration and I hope this helps explain some of the details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With