Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can a vxworks task let all other lesser priority tasks run for a single multitasking cycle?

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.

like image 784
Doug Null Avatar asked Sep 01 '25 01:09

Doug Null


2 Answers

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.

like image 149
mjs Avatar answered Sep 04 '25 17:09

mjs


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.

like image 42
gjcamann Avatar answered Sep 04 '25 15:09

gjcamann