什么使内核/操作系统具有实时性? [英] What makes a kernel/OS real-time?

查看:17
本文介绍了什么使内核/操作系统具有实时性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这个文章,但我的问题是笼统的,我在考虑以下几点:

I was reading this article, but my question is on a generic level, I was thinking along the following lines:

  1. 内核是否可以仅仅因为具有实时调度程序而被称为实时内核?或者换句话说,假设我有一个 linux 内核,如果我将默认调度程序从 O(1)CFS 更改为 real time scheduler,它会成为实时操作系统吗?
  2. 它是否需要硬件的任何支持?一般来说,我见过具有 RTOS 的嵌入式设备(例如 VxWorks、QNX),这些设备是否有任何特殊规定/硬件来支持它们?我知道 RTOS 进程的运行时间是确定性的,但是可以使用 longjump/setjump 在确定的时间内获得输出.
  1. Can a kernel be called real time just because it has a real time scheduler? Or in other words, say I have a linux kernel, and if I change the default scheduler from O(1) or CFS to a real time scheduler, will it become an RTOS?
  2. Does it require any support from the hardware? Generally I have seen embedded devices having an RTOS (eg VxWorks, QNX), do these have any special provisions/hw to support them? I know RTOS process's running time is deterministic, but then one can use longjump/setjump to get the output in determined time.

我非常感谢您对此提供的一些意见/见解,如果我有什么不对的地方,请纠正我.

I'd really appreciate some input/insight on it, if I am wrong about something, please correct me.

推荐答案

在做了一些研究之后,与人们交谈(Jamie Hanrahan、Juha Aaltonen @linkedIn Group - 设备驱动专家)当然还有来自 @Jim Garrison 的意见,这就是我可以得出结论:

After doing some research, talking to poeple (Jamie Hanrahan, Juha Aaltonen @linkedIn Group - Device Driver Experts) and ofcourse the input from @Jim Garrison, this what I can conclude:

杰米·汉拉汉的话来说-

什么使内核具有实时性?
实时操作系统的必要条件 -

  • 能够保证外部中断和中断处理程序启动之间的最大延迟.

请注意,最大延迟不需要特别短(例如微秒),您可以拥有一个实时操作系统,保证绝对最大延迟为 137 毫秒.

Note that the maximum latency need not be particularly short (e.g. microseconds), you could have a real time OS that guaranteed an absolute maximum latency of 137 milliseconds.

实时调度程序提供完全可预测的(对开发人员)线程调度行为——接下来运行哪个线程".

A real time scheduler is one that offers completely predictable (to the developer) behavior of thread scheduling - "which thread runs next".

这通常与响应中断的保证最大延迟问题无关(因为中断处理程序不一定像普通线程一样被调度),但通常需要实现实时应用程序.实时操作系统中的调度程序通常实现大量的优先级.而且他们几乎总是实现优先级继承,以避免优先级反转的情况.

This is generally separate from the issue of a guaranteed maximum latency to responding to an interrupt (since interrupt handlers are not necessarily scheduled like ordinary threads) but it is often necessary to implement a real-time application. Schedulers in real-time OSs generally implement a large number of priority levels. And they almost always implement priority inheritance, to avoid priority inversion situations.

既然中断延迟有保证,线程调度的可预测性就很好,那为什么不让每个操作系统都实时呢?

  • 因为适用于通用用途(服务器和/或台式机)的操作系统需要具有通常与实时延迟保证不一致的特性.

  • Because an OS suited for general purpose use (servers and/or desktops) needs to have characteristics that are generally at odds with real-time latency guarantees.

例如,实时调度程序应该具有完全可预测的行为.这意味着,除其他外,开发人员为各种任务分配的任何优先级都应由操作系统单独处理.这可能意味着一些低优先级的任务最终会长时间处于饥饿状态.但是 RT OS 不得不耸耸肩说这就是开发人员想要的".请注意,为了获得正确的行为,RT 系统开发人员必须很多担心诸如任务优先级和 CPU 亲和性之类的事情.

For example, a real-time scheduler should have completely predictable behavior. That means, among other things, that whatever priorities have been assigned to the various tasks by the developer should be left alone by the OS. This might mean that some low-priority tasks end up being starved for long periods of time. But the RT OS has to shrug and say "that's what the dev wanted." Note that to get the correct behavior, the RT system developer has to worry a lot about things like task priorities and CPU affinities.

通用操作系统正好相反.您希望能够将应用程序和服务放在上面,几乎总是由许多不同供应商编写的东西(而不是像大多数 R-T 系统那样是一个紧密集成的系统),并获得良好的性能.也许不是绝对最好的性能,但很好.

A general-purpose OS is just the opposite. You want to be able to just throw apps and services on it, almost always things written by many different vendors (instead of being one tightly integrated system as in most R-T systems), and get good performance. Perhaps not the absolute best possible performance, but good.

请注意,良好的性能"不仅仅以中断延迟来衡量.特别是,您希望 CPU 和其他资源分配通常被描述为公平",而用户或管理员甚至应用程序开发人员都不必担心线程优先级、CPU 关联性和 NUMA 节点等问题.一项工作可能比另一项更重要,但在通用操作系统中,这并不意味着第二项工作根本不应该获得任何资源.

Note that "good performance" is not just measured in interrupt latency. In particular, you want CPU and other resource allocations that are often described as "fair", without the user or admin or even the app developers having to worry much if at all about things like thread priorities and CPU affinities and NUMA nodes. One job might be more important than another, but in a general-purpose OS, that doesn't mean that the second job should get no resources at all.

所以通用操作系统通常会在同等优先级的线程之间实现时间分片,并且它可能会根据它们过去的行为调整线程的优先级(例如,CPU hog 可能会降低其优先级;I/O 绑定线程可能会提高其优先级,因此它可以保持 I/O 设备工作;CPU 不足的线程可能会提高其优先级,因此它可以不时获得一点 CPU 时间).

So the general purpose OS will usually implement time-slicing among threads of equal priority, and it may adjust the priorities of threads according to their past behavior (e.g. a CPU hog might have its priority reduced; an I/O bound thread might have its priority increased, so it can keep the I/O devices working; a CPU-starved thread might have its priority boosted so it can get a little bit of CPU time now and then).

内核可以仅仅因为它有一个实时调度器就被称为实时吗?

  • 不,RT 调度程序是 RT 操作系统的必要组件,但您还需要操作系统其他部分的可预测行为.

是否需要硬件的支持?

  • 一般来说,硬件越简单,其行为的可预测性就越高.因此 PCI-E 的可预测性低于 PCI,而 PCI 的可预测性低于 ISA,等等.有一些特定的 I/O 总线是为(除其他外)设计的,例如易于预测.中断延迟,但如今可以使用商用硬件满足许多 R-T 要求.

这篇关于什么使内核/操作系统具有实时性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆