vxWorks如何处理两个优先级相同的任务?

发布于 2024-07-04 20:06:30 字数 114 浏览 11 评论 0原文

我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浊酒尽余欢 2024-07-11 20:06:30

默认情况下,第一个生成的那个将被执行,除非它放弃 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.

吐个泡泡 2024-07-11 20:06:30

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.

英雄似剑 2024-07-11 20:06:30

首先运行的任务是由 VxWorks 调度程序任务实现的首先生成的任务。 VxWorks 默认使用基于优先级的调度。 因此,在您的情况下,由于 T1 和 T2 具有相同的优先级,因此无论哪一个先获得 CPU 都将继续无限期地运行,直到它被明确阻止(使用 taskSuspendtaskDelay) ,此时另一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文