VxWorks调度程序如何执行?

发布于 2024-09-04 20:58:01 字数 198 浏览 17 评论 0原文

想知道如何调用调度程序以便它可以切换任务。即使是抢占式调度或循环调度 - 调度程序也应该参与其中以进行任何类型的任务切换。假设一个低优先级任务有一个无限循环——调度程序什么时候介入并切换到更高优先级的任务?

查询是: 1.谁调用调度器? [在VxWorks中] 2. 如果定期调用它 - 该机制是如何实现的?

提前致谢。

——阿什温

Would like to know how the scheduler gets called so that it can switch tasks. As in even if its preemptive scheduling or round robin scheduling - the scheduler should come in to picture to do any kind of task switching. Supposing a low priority task has an infinite loop - when does the scheduler intervene and switch to a higher priority task?

Query is:
1. Who calls the scheduler? [in VxWorks]
2. If it gets called at regular intervals - how is that mechanism implemented?

Thanks in advance.

--Ashwin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

扛刀软妹 2024-09-11 20:58:01

简单的答案是,vxWorks 通过系统计时器的硬件中断来进行控制,该系统计时器在系统运行时以固定的时间间隔连续发生。

这里有更多细节:

当 vxWorks 启动时,它会将您的硬件配置为每隔中断生成一个计时器 n 毫秒,其中 n 通常为 10,但完全取决于您的硬件。计时器间隔通常由 vxWorks 在启动时在 板支持包 (BSP) 中设置。

每次计时器触发中断时,系统都会开始执行计时器中断处理程序。定时器中断处理程序是vxWorks的一部分,因此现在vxWorks拥有控制权。它所做的第一件事是将 CPU 状态(例如寄存器)保存到 当前运行任务的任务控制块 (TCB)

然后最终 vxWorks 运行调度程序来确定下一个运行的人。为了运行任务,vxWorks 将任务的状态从其 TCB 复制到机器寄存器中,然后任务就可以控制 CPU。

额外信息:

vxWorks 提供挂钩任务切换逻辑,以便您可以在任务被抢占时调用一个函数。

The simple answer is that vxWorks takes control through a hardware interrupt from the system timer that occurs continually at fixed intervals while the system is running.

Here's more detail:

When vxWorks starts, it configures your hardware to generate a timer interrupt every n milliseconds, where n is often 10 but completely depends on your hardware. The timer interval is generally set up by vxWorks in your Board Support Package (BSP) when it starts.

Every time the timer fires an interrupt, the system starts executing the timer interrupt handler. The timer interrupt handler is part of vxWorks, so now vxWorks has control. The first thing it does is save the CPU state (such as registers) into the Task Control Block (TCB) of the currently running task.

Then eventually vxWorks runs the scheduler to determine who runs next. To run a task, vxWorks copies the state of the task from its TCB into the machine registers, and after it does that the task has control of the CPU.

Bonus info:

vxWorks provides hooks into the task switching logic so you can have a function get called whenever your task gets preempted.

马蹄踏│碎落叶 2024-09-11 20:58:01

indiv 提供了一个非常好的答案,但它只是部分准确。
系统的实际工作稍微复杂一些。

调度程序可以作为同步或异步操作的结果来执行。

同步是指由当前正在执行的任务中的代码引起的操作。一个典型的例子就是获取信号量 (semTake)。
如果信号量不可用,当前正在执行的任务将挂起并且不再可以执行。此时,将调用调度程序并确定应执行的下一个任务并将执行上下文切换。

异步操作本质上是指中断。 indiv 很好地描述了定时器中断。然而,许多不同的元素可能会导致执行中断:网络流量、传感器、串行数据等......

还需要记住的是,定时器中断不一定会导致上下文切换!是的,将发生中断,并且延迟任务和时间片计数器将递减。但是,如果时间片未过期,或者没有更高优先级的任务从挂起状态转换为就绪状态,那么调度程序实际上不会被调用,并且您将返回到原始任务,在执行被中断的确切位置。

请注意,调度程序没有自己的上下文;这不是一项任务。它只是在调用它的任何上下文中执行的代码。来自中断上下文(异步)或来自调用任务上下文(同步)。

indiv provides a very good answer, but it is only partially accurate.
The actual working of the system is slightly more complex.

The scheduler can be executed as a result of either synchronous or asynchronous operations.

Synchronous refers to operations that are caused as a result of the code in the currently executing task. A prime example of this would be to take a semaphore (semTake).
If the semaphore is not available, the currently executing task will pend and no longer be available to execute. At this point, the scheduler will be invoked and determine the next task that should execute and will perform a context switch.

Asynchronous operations essentially refer to interrupts. Timer interrupts were very well described by indiv. However, a number of different elements could cause an interrupt to execute: network traffic, sensor, serial data, etc...

It is also good to remember that the timer interrupt does not necessarily cause a context switch! Yes, the interrupt will occur, and delayed task and the time slice counters will be decremented. However, if the time slice is not expired, or no higher priority task transitions from the pended to the ready state, then the scheduler will not actually be invoked, and you will return back to the original task, at the exact point where execution was interrupted.

Note that the scheduler does not have its own context; it is not a task. It is simply code that executes in whatever context it is invoked from. Either from the interrupt context (asynchronous) or from the invoking task context (synchronous).

汐鸠 2024-09-11 20:58:01

除非您有一个主要定制的目标构建,否则调度程序将由计时器中断调用。不过,详细信息是特定于平台的。

Unless you have a majorily-customized target build, the scheduler is invoked by the Timer interrupt. Details are platform-specific, though.

﹎☆浅夏丿初晴 2024-09-11 20:58:01

如果当前任务完成或阻塞,调度程序也会被调用。

The scheduler also gets invoked if current task gets completed or blocks.

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