什么是做接近实时任务的最佳方式在非实时操作系统/内核? [英] What are the best ways to do close to real-time tasks on a non real-time OS/kernel?

查看:243
本文介绍了什么是做接近实时任务的最佳方式在非实时操作系统/内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GNU / Linux的机器,如果一个人想要做实时(亚毫秒级的时间关键)任务,你几乎总是要经过修补的内核暴露的冗长,复杂,问题易发的过程足够的支持​​ [1] [2]

On a GNU/Linux machine, if one wants to do "real-time"(sub millisecond time critical) tasks, you almost invariably have to go through the lengthy, complex, and problem prone process of patching the kernel to expose adequate support[1] [2].

的最大问题是,许多系统,其中实时任务是最有用的不具备基本的硬件要求,甚至允许这些补丁的工作,即,高分辨率计时器外设。或者如果他们这样做,这是特定于硬件,因此这样需要被具体地在上的情况下的补丁逐个实现。这是真实的,即使在CPU /指令时钟速率比足够快多,得到所需要的时间粒度,然后一些

The biggest problem is, many systems where real-time tasking is most useful do not have the fundamental hardware requirements to even allow these patches to work, namely a high resolution timer peripheral. Or if they do, it is specific to the hardware, so as such needs to be specifically implemented in the patch on a case by case basis. This is true even if the CPU/instruction clock rate is more than fast enough to give the required time granularity and then some.

所以,我的问题是,什么是一些最好的第二名的方式/技巧来获得尽可能接近上述实时目标是什么?事情可以做简单的应用程序的源$ C ​​$ C,没有底层硬件或过多的内核黑客成竹在胸。

So, my question is, what are some of the best second place ways/tricks to get as close as possible to the above real-time goal? Things that one can simply do in the applications source code, without intimate knowledge of underlying hardware or too much "kernel hacking".

升降过程中的优先​​级,为启动关键任务的额外的线程,并使用了nanosleep的变种(C语言)()是最好看的答案/技巧我想出了这么远。我希望能找到更多。

Elevating process priority, starting an extra thread for "critical" tasks, and (in C) using variants of nanosleep() are the best looking answers/tricks I have come up with so far. I hope to find more.

推荐答案

sched_setscheduler(2)和朋友允许你使用两种不同的软实时调度,SCHED_FIFO SCHED_RR。这些调度下运行的过程比常规的进程优先级越高。所以只要你只有几个论题流程,并控制它们之间的优先事项,其实你可以得到pretty血统的实时响应。

The sched_setscheduler(2) and friends allow you to use two different soft real-time schedulers, SCHED_FIFO SCHED_RR. Processes running under these schedulers are prioritised higher than regular processes. So as long as you only have a few of theses processes, and control the priorities between them, you can actually get pretty descent real-time responses.

作为评论的要求,这里是SCHED_FIFO和SCHED_RR的区别是:

As requested in a comment, here is the difference between SCHED_FIFO and SCHED_RR:

随着实时的调度,有多达100个不同的优先级(POSIX只需要32种不同的级别,因此应该使用的 sched_get_priority_min(2)和的 sched_get_priority_max(2)获得的实际数量。该调度由preempting进程和线程的优先级低都工作,不同的是它们处理任务,并具有相同的优先级。

With the "real-time" schedulers, there are up to 100 different priorities (POSIX only requires 32 distinct levels, so one should use sched_get_priority_min(2) and sched_get_priority_max(2) to get the actual number. The schedulers both work by preempting processes and threads with lower priority, the difference is in how they handle tasks with the same priority.

SCHED_FIFO,是先出调度(因此得名)第一。这意味着,首先撞击运行队列的任务​​,允许运行,直到它完成,自愿放弃其空间运行队列,或者是由一个高优先级任务pempted $ P $。

SCHED_FIFO, is a first in first out scheduler (hence the name). This means that the the task that hits the run queue first, is allowed to run until it is done, voluntarily gives up its space on the run queue, or is preempted by a higher priority task.

SCHED_RR,是循环赛调度。这意味着,具有相同优先级的任务只允许在一定时间内量子运行。如果在这个时间段用完的任务的任务仍在运行是pempted $ P $,并在运行队列中的下一个任务(具有相同的优先级)被允许最多的时间段运行。与SCHED_FIFO,高优先级的任务preempt优先级较低的人,怎么过,当时这是一个高优先级任务pempted $ P $允许再次运行任务,那么它只能为一次运行留下的是量子。请参阅 sched_rr_get_interval(2)反对者占多数,部分如何设置时间为量子任务。

SCHED_RR, is a round robin scheduler. This means that tasks with the same priority are only allowed to run for a certain time quantum. If the task is still running when this time quantum runs out the task is preempted, and the next task in the run queue (with same priority) is allowed to run for up to its time quantum. As with SCHED_FIFO, higher priority tasks preempt lower priority ones, how ever, when a task which was preempted by a higher priority task is allowed to run again, then it's only allowed to run for the time left in its quantum. See the Noes-section in sched_rr_get_interval(2) for how to set the time quantum for a task.

这篇关于什么是做接近实时任务的最佳方式在非实时操作系统/内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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