vxWorks如何处理两个优先级相同的任务?
我们的 vxWorks 嵌入式系统中有两个任务(T1 和 T2),它们具有相同的优先级 (110)。
如果两个任务都准备好运行,常规 vxWorks 调度程序如何处理这个问题?
哪个任务先执行?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,第一个生成的那个将被执行,除非它放弃 CPU,否则另一个将永远不会运行。
您可以显式启用循环,然后它们将进行时间片。
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.
VxWorks 有 256 个优先级(0 最高,255 最低)。 在任何给定时间,最高优先级的任务都在 CPU 上运行。 每个优先级概念上都有一个队列,多个任务在其中排队等待执行。
我们有 3 个具有相同优先级的任务 A、B、C。假设 A 正在执行。
当A阻塞(taskDelay,SemTake,msgQReceive)时,B将开始执行。
当A解除阻塞时,它被放在队列的末尾。 我们现在有 B、C、A。
当 B 阻塞时,C 接管等...
如果启用了循环调度(时间切片),则应用相同的概念,但当其时间片结束时,任务将被放置在队列的末尾。
请注意,被更高优先级任务抢占的任务不会影响队列的顺序。 如果 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.
首先运行的任务是由 VxWorks 调度程序任务实现的首先生成的任务。 VxWorks 默认使用基于优先级的调度。 因此,在您的情况下,由于 T1 和 T2 具有相同的优先级,因此无论哪一个先获得 CPU 都将继续无限期地运行,直到它被明确阻止(使用 taskSuspend 或 taskDelay) ,此时另一个 READY 任务将执行,直到被阻塞,依此类推。 这应该由信号量或互斥体(mutices?)来控制。
基于优先级的调度的主要问题正是由这个问题说明的。 我们如何确定让这些任务运行多长时间? 它们具有相同的优先级这一事实使事情变得复杂。 另一个问题是,具有高优先级(较低的数字意味着较高的优先级)的 VxWorks 任务可能会抢占您的应用程序,您必须在代码中为此做好准备。 这些问题可以通过使用循环调度来解决。 循环调度带来的其他问题及其解决方案均在此处。
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.