实时操作系统如何工作? [英] How do Real Time Operating Systems work?

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

问题描述

我的意思是实时操作系统如何以及为什么能够在不错过最后期限的情况下完成任务?还是这只是一个神话(他们不错过最后期限)?它们与任何常规操作系统有何不同?是什么阻止了常规操作系统成为RTOS?

I mean how and why are realtime OSes able to meet deadlines without ever missing them? Or is this just a myth (that they do not miss deadlines)? How are they different from any regular OS and what prevents a regular OS from being an RTOS?

推荐答案

会议截止日期是您编写的应用程序的功能. RTOS只是提供了可以帮助您在截止日期之前完成的功能.您还可以在大型主循环中使用裸机"(不带RTOS)进行编程,并按时完成任务.

Meeting deadlines is a function of the application you write. The RTOS simply provides facilities that help you with meeting deadlines. You could also program on "bare metal" (w/o a RTOS) in a big main loop and meet you deadlines.

还请记住,与更通用的OS不同,RTOS的运行任务和进程集非常有限.

Also keep in mind that unlike a more general purpose OS, an RTOS has a very limited set of tasks and processes running.

RTOS提供的一些功能:

Some of the facilities an RTOS provide:

  • 基于优先级的计划程序
  • 系统时钟中断例程
  • 确定性行为

基于优先级的计划程序

大多数RTOS对于单个任务/过程都具有32到256个可能的优先级.调度程序将以最高优先级运行任务.当正在运行的任务放弃CPU时,将运行下一个优先级最高的任务,依此类推...

Most RTOS have between 32 and 256 possible priorities for individual tasks/processes. The scheduler will run the task with the highest priority. When a running task gives up the CPU, the next highest priority task runs, and so on...

系统中优先级最高的任务将拥有CPU,直到:

The highest priority task in the system will have the CPU until:

  • 运行完成(即自愿放弃CPU)
  • 已准备好较高优先级的任务,在这种情况下,原始任务会被新的(较高优先级)任务抢占.

作为开发人员,分配任务优先级是您的工作,以便您能按时完成任务.

As a developer, it is your job to assign the task priorities such that your deadlines will be met.

系统时钟中断例程

RTOS通常会提供某种系统时钟(从500 uS到100ms的任何地方),使您可以执行对时间敏感的操作. 如果您的系统时钟为1毫秒,并且需要每50毫秒执行一次任务,那么通常会有一个API允许您说在50毫秒内,唤醒我".届时,任务将一直处于休眠状态,直到RTOS将其唤醒.

The RTOS will typically provide some sort of system clock (anywhere from 500 uS to 100ms) that allows you to perform time-sensitive operations. If you have a 1ms system clock, and you need to do a task every 50ms, there is usually an API that allows you to say "In 50ms, wake me up". At that point, the task would be sleeping until the RTOS wakes it up.

请注意,仅被唤醒并不能确保您那时能准确运行.这取决于优先级.如果当前正在运行优先级更高的任务,则可能会延迟您的工作.

Note that just being woken up does not insure you will run exactly at that time. It depends on the priority. If a task with a higher priority is currently running, you could be delayed.

确定性行为

RTOS竭尽所能,以确保您有10个任务或100个任务,都不再需要切换上下文,确定下一个优先级最高的任务是什么,等等.

The RTOS goes to great length to ensure that whether you have 10 tasks, or 100 tasks, it does not take any longer to switch context, determine what the next highest priority task is, etc...

通常,RTOS操作会尝试为O(1).

In general, the RTOS operation tries to be O(1).

中断处理是RTOS中确定性行为的主要方面之一.当发出中断信号时,RTOS会立即切换到正确的中断服务程序,并立即处理中断(无论当前正在执行的任何任务的优先级如何).

One of the prime areas for deterministic behavior in an RTOS is the interrupt handling. When an interrupt line is signaled, the RTOS immediately switches to the correct Interrupt Service Routine and handles the interrupt without delay (regardless of the priority of any task currently running).

请注意,大多数特定于硬件的ISR将由开发人员在项目上编写. RTOS可能已经为串行端口,系统时钟,也许是网络硬件提供了ISR,但是任何专门的东西(起搏器信号,执行器等)都不属于RTOS.

Note that most hardware-specific ISRs would be written by the developers on the project. The RTOS might already provide ISRs for serial ports, system clock, maybe networking hardware but anything specialized (pacemaker signals, actuators, etc...) would not be part of the RTOS.

这是一个概括,与其他所有内容一样,RTOS实现种类繁多.某些RTOS的处理方式有所不同,但上面的描述应适用于现有RTOS的很大一部分.

This is a gross generalization and as with everything else, there is a large variety of RTOS implementations. Some RTOS do things differently, but the description above should be applicable to a large portion of existing RTOSes.

这篇关于实时操作系统如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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