views:

1843

answers:

3

We have two tasks (T1 and T2) in our vxWorks embedded system that have the same priority (110).
How does the regular vxWorks scheduler deal with this if both tasks are ready to run?
Which task executes first?

+1  A: 

The task that will run first is the task that is spawned first as realized by the VxWorks scheduler task. VxWorks uses priority-based scheduling by default. So in your case, since T1 and T2 have the same priority, whichever one gets the CPU first will continue to run indefinitely until it is explicitly blocked (using taskSuspend or taskDelay), at which time the other READY task will execute until it is blocked, and so on. This ought to be controlled by semaphores or mutexes (mutices?)

The main problem with priority-based scheduling is illuminated by this exact problem. How do we determine how long to let these tasks run? The fact that they have the same priority complicates things. Another concern is that VxWorks tasks that have high priority (lower number means higher priority) can preempt your application which you must be prepared for in your code. These problems can be solved by using round-robin scheduling. The additional problems posed by round-robin scheduling and the solutions are all described here.

unwieldy
A: 

VxWorks has 256 priority levels (0 is highest, 255 is lowest). At any given time, the highest priority task runs on the CPU. Each priority level conceptually has a queue where multiple tasks queue up for execution.

We have 3 tasks at the same priority A, B, C. Assume A is executing.
When A blocks (taskDelay, SemTake, msgQReceive), B will start execution.
When A unblocks, it is put at the end of the queue. We now have B, C, A.
When B blocks, C takes over, etc...

If Round Robin scheduling (Time slicing) is enabled, the same concept applies, but the task gets put at the end of the queue when its time slice is over.

Note that a task being pre-empted by a higher priority task will NOT affect the order of the queue. If A was running and gets pre-empted, it will continue execution when the higher priority task is done. It does not get put at the end of the queue.

Benoit
A: 

By default the one which is spawned first will be executing and unless it gives up the CPU the other will never run.

You can explicitly enable round robin, than they will timeslice.

robert.berger