Alex Rivera | Logout

How do real-time operating systems (RTOSes) work?

Asked 2009-02-11T12:11:31.213
26

I mean, how and why are real-time 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?

Edit
Report

3 Answers

33

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" (without a RTOS) in a big main loop and meet you deadlines.

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

Some of the facilities an RTOS provide:

  • Priority-based Scheduler
  • System Clock interrupt routine
  • Deterministic behavior

Priority-based Scheduler

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...

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

  • it runs to completion (i.e., it voluntarily give up the CPU)
  • a higher priority task is made ready, in which case the original task is preempted by the new (higher priority) task.

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

System Clock Interrupt routines

The RTOS will typically provide some sort of system clock (anywhere from 500 µs to 100 ms) that allows you to perform time-sensitive operations.

If you have a 1 ms system clock, and you need to do a task every 50 ms, 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 ensure 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.

Deterministic Behavior

The RTOS goes to great length to ensure that whether you have 10 tasks, or 100 tasks, it does no

answered 2009-02-11T13:37:06.873
0

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.

answered 2009-11-13T03:34:04.500
-1

Basically, you have to code each "task" in the RTOS such that they will terminate in a finite time.

Additionally your kernel would allocate specific amounts of time to each task, in an attempt to guarantee that certain things happened at certain times.

Note that this is not an easy task to do however. Imagine things like virtual function calls, in OO it's very difficult to determine these things. Also an RTOS must be carefully coded with regard to priority, it may require that a high priority task is given the CPU within x milliseconds, which may be difficult to do depending on how your scheduler works.

answered 2009-02-11T12:17:00.903

Your Answer