实时嵌入式操作系统的线程调度程序

发布于 2024-08-18 03:01:31 字数 649 浏览 2 评论 0原文

我接到的任务是修复一个用 C/C++ 编写的嵌入式操作系统。当前使用的线程调度程序与循环调度非常相似,只是它缺少一个非常重要的功能,能够中断线程然后返回执行,从而创建可靠的执行时间“片段”。

我的问题是,如何中断正在运行的代码,执行另一项任务,然后优雅地返回执行?我相信这种行为需要特定于该架构的汇编器。这是操作系统将在其下运行的芯片: http: //www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPC860

顺便说一句,这是航空电子软件,因此它必须是“确定性”的。除此之外,没有堆使用,所有内存都必须受到限制。

当前的系统是一个“周期性过程”,其中下一个任务必须等待第一个任务完成。这简直太可怕了,如果操作系统的一部分崩溃,比如 ATN 堆栈,那么整个操作系统都会崩溃。 (在这里插入坠毁的飞机……尽管这是 B 类软件,这意味着如果系统坠毁,飞机也不会坠毁。)

I have been given the task to fix an Embedded Operating System which is written in C/C++. The Current thread scheduler being used is very similar to Round Robin Scheduling, except it lacks one very important feature, the ability to interrupt threads and then return executing thus creating a dependable "slice" of execution time.

My Question is, how does one go about interrupting running code, execute another task and then return execution gracefully? I believe this behavior requires assembler specific to the architecture. This is the chip that the OS will be running under: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPC860

On a side note, this is avionics software so it must be "Deterministic". Apart of this is that there is no heap usage, all memory must be bounded.

The current system is a "periodic process" in which the next task must wait for the first to complete. This is simple horrific, if one part of the operating system crashes, lets say the ATN stack, then the entire operating system will be brought to its knees. (Insert crashed airplane here... although this is class B software, which means the airplane will not crash if the system does.)

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

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

发布评论

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

评论(3

挽梦忆笙歌 2024-08-25 03:01:31

免责声明:不要采纳我的建议。寻找专家,如果人们的福祉取决于系统,那么不要将其交给机会/黑客/SO建议!

Plane oops http://xs.to/thumb-AF83_4B54A285.jpg

您应该能够编写一个新程序,该程序以已知的时间间隔通过中断进入,使用保存线程状态现有的调度功能并更改线程上下文。另外,请确保您的锁定原语适用于新的调度,并且不会聚集基于非原子/非指令的 T&S 锁定或任何其他内容。

这个网站提供了有关线程切换的良好信息、国家储蓄等等。最终中断是特定于您的 CPU/硬件的。保存线程状态的方式还取决于系统的约束和您正在使用的线程结构。

现代操作系统第三版包含一些很好的理论内容,但实现取决于现有代码和您所使用的硬件的最佳实践,以及内核中处理中断、信号等的其他代码。

此外,“实时系统设计和分析,作者:Phillip A. Laplante”可能是使现有调度程序适应新要求的良好资源。 另一段有趣的文字

disclaimer: Don't use my advice. Find a specialist, if people's well-being depends on a system then don't leave it to chance/hacks/SO advice!

Plane oops http://xs.to/thumb-AF83_4B54A285.jpg

You should be able to write a new procedure which is entered via an interrupt at a known interval, save thread-state using existing scheduling functions and change thread context. Also,ensure your locking primitives work with the new scheduling and that you don't balls up non-atomic/non-instruction based T&S locking or anything.

This website gives good information about thread switching, state saving and so on. Ultimately interrupts are specific to your CPU/Hardware. The way you save your thread state will also be dependent on the constraints of the system and the thread structure you are using.

Modern Operating Systems 3rd Edition contains some good chunks on the theory, but the implementing depends on existing code and best practice for the hardware you are on, as well as other code in the kernel that handles interrupts, signals and so on.

Also "Real-time systems design and analysis By Phillip A. Laplante" might be a good resource for adapting your existing scheduler to the new requirements. Another interesting bit of text

辞别 2024-08-25 03:01:31

如果这是一个操作系统,真的是一个操作系统,那么它当然是在与硬件对话。它必须进行中断处理才能处理 I/O 设备。

有时定时器中断来自 CPU 本身,但在其他系统架构中,它将来自 IO 控制器或其他一些设备。

一种通用的设计替代方案是仅以较小的量分配 CPU 时间,以便调度程序可以更频繁地重新考虑,但没有人可以从这里判断这是否会使您的特定问题变得更好或更糟。

所以这里真的没有人能够给你详细的处方。

当然,向美国联邦航空局报告您的雇主除外。

If this is an operating system, really an operating system, of course it's talking to the hardware. It must have interrupt handling going in order to deal with I/O devices.

Sometimes the timer interrupt will come from the CPU itself, but in other system architectures it will come from an IO controller or some other device.

A general design alternative is to hand out CPU time only in small quanta so that the scheduler can reconsider more frequently, but no one can tell from here if that is going to make your particular problem better or worse.

So there's really no way anyone is going to be able to give you a detailed prescription here.

Except, of course, to report your employer to the FAA.

橘亓 2024-08-25 03:01:31

如果我正确地阅读了您的问题,我认为您想向调度程序添加线程优先级。循环调度相同优先级的所有线程,但允许较高优先级抢占较低优先级线程。

您必须已经具备用于保存和恢复线程上下文以进行循环时间切片的功能。

If I read your question correctly, I think you want to add thread priorities to your scheduler. Schedule all threads of the same priority round robin, but allow a higher priority to preempt a lower priority thread.

You must already have facilities for saving and restoring a thread's context to to round robin time slicing.

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