How do Real Time Operating Systems work?

后端 未结 12 794
借酒劲吻你
借酒劲吻你 2021-01-31 04:12

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

相关标签:
12条回答
  • 2021-01-31 04:30

    You might find it helpful to read the source of a typical RTOS. There are several open-source examples out there, and the following yielded links in a little bit of quick searching:

    • FreeRTOS
    • eCos

    A commercial RTOS that is well documented, available in source code form, and easy to work with is µC/OS-II. It has a very permissive license for educational use, and (a mildly out of date version of) its source can be had bound into a book describing its theory of operation using the actual implementation as example code. The book is MicroC OS II: The Real Time Kernel by Jean Labrosse.

    I have used µC/OS-II in several projects over the years, and can recommend it.

    0 讨论(0)
  • 2021-01-31 04:31

    I haven't used an RTOS, but I think this is how they work.

    There's a difference between "hard real time" and "soft real time". You can write real-time applications on a non-RTOS like Windows, but they're 'soft' real-time:

    • As an application, I might have a thread or timer which I ask the O/S to run 10 times per second ... and maybe the O/S will do that, most of the time, but there's no guarantee that it will always be able to ... this lack of guarantee is why it's called 'soft'. The reason why the O/S might not be able to is that a different thread might be keeping the system busy doing something else. As an application, I can boost my thread priority to for example HIGH_PRIORITY_CLASS, but even if I do this the O/S still has no API which I can use to request a guarantee that I'll be run at certain times.

    • A 'hard' real-time O/S does (I imagine) have APIs which let me request guaranteed execution slices. The reason why the RTOS can make such guarantees is that it's willing to abend threads which take more time than expected / than they're allowed.

    0 讨论(0)
  • 2021-01-31 04:35

    It is not that they are able to meet deadlines, it is rather that they have deadlines fixed whereas in a regular OS there is no such deadline.

    In a regular OS the task scheduler is not really strict. That is the processor will execute so many instructions per second, but it may occasionally not do so. For example a task might be pre-empted to allow a higher priority one to execute (and may be for longer time). In RTOS the processor will always execute the same number of tasks.

    Additionally there is usually a time limit for tasks to completed after which a failure is reported. This does not happen in regular OS.

    Obviously there is lot more detail to explain, but the above are two of the important design aspects that are used in RTOS.

    0 讨论(0)
  • 2021-01-31 04:37

    In RTOSes the most critical parameters which should be taken care of are lower latencies and time determinism. Which it pleasantly does by following certain policies and tricks.

    Whereas in GPOSes, along with acceptable latencies the critical parameters is high throughput. you cannot count on GPOS for time determinism.

    RTOSes have tasks which are much lighter than processes/threads in GPOS.

    0 讨论(0)
  • 2021-01-31 04:41

    ... well ...

    A real-time operating system tries to be deterministic and meet deadlines, but it all depends on the way you write your application. You can make a RTOS very non real-time if you don't know how to write "proper" code.

    Even if you know how to write proper code: It's more about trying to be deterministic than being fast.

    When we talk about determinism it's

    1) event determinism

    For each set of inputs the next states and outputs of a system are known

    2) temporal determinism

    … also the response time for each set of outputs is known

    This means that if you have asynchronous events like interrupts your system is strictly speaking not anymore temporal deterministic. (and most systems use interrupts)

    If you really want to be deterministic poll everything.

    ... but maybe it's not necessary to be 100% deterministic

    0 讨论(0)
  • 2021-01-31 04:41

    They actually don't guarantee meeting deadlines; what they do that makes them truly RTOS is to provide the means to recognize and deal with deadline overruns. 'Hard' RT systems generally are those where missing a deadline is disastrous and some kind of shutdown is required, whereas a 'soft' RT system is one where continuing with degraded functionality makes sense. Either way an RTOS permits you to define responses to such overruns. Non RT OS's don't even detect overruns.

    0 讨论(0)
提交回复
热议问题