All Topics  
Real-time operating system

 

   Email Print
   Bookmark   Link






 

Real-time operating system



 
 
A Real-Time Operating System (RTOS) is a multitasking
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
 operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 intended for real-time
Real-time computing

In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
 applications. Such applications include embedded system
Embedded system

An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints....
s (programmable thermostats, household appliance controllers), industrial robot
Robot

A robot is a virtual or mechanical artificial agent. In practice, it is usually an Electromechanics which, by its appearance or movements, conveys a sense that it has Intention or Agency of its own....
s, spacecraft, industrial control (see SCADA
SCADA

SCADA stands for Supervisory Control And Data Acquisition. It generally refers to an industrial control system: a computer system monitoring and controlling a process....
), and scientific research equipment.

A RTOS facilitates the creation of a real-time system, but does not guarantee the final result will be real-time; this requires correct development of the software.






Discussion
Ask a question about 'Real-time operating system'
Start a new discussion about 'Real-time operating system'
Answer questions from other users
Full Discussion Forum



Encyclopedia


A Real-Time Operating System (RTOS) is a multitasking
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
 operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 intended for real-time
Real-time computing

In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
 applications. Such applications include embedded system
Embedded system

An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints....
s (programmable thermostats, household appliance controllers), industrial robot
Robot

A robot is a virtual or mechanical artificial agent. In practice, it is usually an Electromechanics which, by its appearance or movements, conveys a sense that it has Intention or Agency of its own....
s, spacecraft, industrial control (see SCADA
SCADA

SCADA stands for Supervisory Control And Data Acquisition. It generally refers to an industrial control system: a computer system monitoring and controlling a process....
), and scientific research equipment.

A RTOS facilitates the creation of a real-time system, but does not guarantee the final result will be real-time; this requires correct development of the software. An RTOS does not necessarily have high throughput
Throughput

In communication networks, such as Ethernet or packet radio, throughput is the average rate of successful message delivery over a communication channel....
; rather, an RTOS provides facilities which, if used properly, guarantee deadlines can be met generally (soft real-time
Real-time computing

In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
) or deterministically (hard real-time
Real-time computing

In computer science, real-time computing is the study of Computer hardware and computer software systems that are subject to a "real-time constraint"?i.e., operational deadlines from event to system response....
). An RTOS will typically use specialized scheduling algorithms in order to provide the real-time developer with the tools necessary to produce deterministic behavior in the final system. An RTOS is valued more for how quickly and/or predictably it can respond to a particular event than for the amount of work it can perform over a given period of time. Key factors in an RTOS are therefore a minimal interrupt latency
Interrupt latency

In real-time operating systems, interrupt latency is the time between the generation of an interrupt by a device and the servicing of the device which generated the interrupt....
 and a minimal thread switching latency
Thread switching latency

The thread switching latency is the time needed by the operating system to switch the Central processing unit to another thread . In some operating systems running on some hardware, switching between threads belonging to the same process is much faster than switching to a thread from different process ....
.

An early example of a large-scale real-time operating system was Transaction Processing Facility
Transaction Processing Facility

TPF is an International Business Machines real-time operating system for IBM mainframe descended from the IBM System/360 family, including zSeries and ZSeries....
 developed by American Airlines
American Airlines

American Airlines, Inc. is a major carrier of the United States. It is the world's largest airlines in passenger miles transported and passenger fleet size; second largest, behind FedEx Express, in aircraft operated; and second behind Air France-KLM in operating revenues....
 and IBM for the Sabre Airline Reservations System.

Design philosophies


Two basic designs exist:

  • Event-driven (priority scheduling) designs switch tasks only when an event of higher priority needs service, called pre-emptive priority.
  • Time-sharing designs switch tasks on a clock interrupt, and on events, called round robin
    Round-robin scheduling

    Round-robin is one of the simplest scheduling algorithms for Computer process in an operating system, which assigns Preemption_#Time_slice to each process in equal portions and in order, handling all processes without priority....
    .


Time-sharing designs switch tasks more often than is strictly needed, but give smoother, more deterministic multitasking
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
, giving the illusion that a process or user has sole use of a machine.

Early CPU design
CPU design

CPU design is the design engineering task of creating a central processing unit , a component of computer hardware. It is a subfield of electronics engineering and computer engineering....
s needed many cycles to switch tasks, during which the CPU could do nothing useful. So early OSes tried to minimize wasting CPU time by maximally avoiding unnecessary task-switches.

More recent CPUs take far less time to switch from one task to another; the extreme case is barrel processor
Barrel processor

A barrel processor is a Central processing unit that switches between Thread of execution on every Instruction cycle. This CPU design technique is also known as "interleaved" or "fine-grained" temporal multithreading....
s that switch from one task to the next in zero cycles. Newer RTOSes almost invariably implement time-sharing scheduling with priority driven pre-emptive scheduling.

Scheduling

In typical designs, a task has three states: 1) running, 2) ready, 3) blocked. Most tasks are blocked, most of the time. Only one task per CPU is running. In simpler systems, the ready list is usually short, two or three tasks at most.

The real key is designing the scheduler. Usually the data structure of the ready list in the scheduler is designed to minimize the worst-case length of time spent in the scheduler's critical section, during which preemption is inhibited, and, in some cases, all interrupts are disabled. But, the choice of data structure depends also on the maximum number of tasks that can be on the ready list.

If there are never more than a few tasks on the ready list, then a simple unsorted bidirectional linked list of ready tasks is likely optimal. If the ready list usually contains only a few tasks but occasionally contains more, then the list should be sorted by priority, so that finding the highest priority task to run does not require iterating through the entire list. Inserting a task then requires walking the ready list until reaching either the end of the list, or a task of lower priority than that of the task being inserted. Care must be taken not to inhibit preemption during this entire search; the otherwise-long critical section should probably be divided into small pieces, so that if, during the insertion of a low priority task, an interrupt occurs that makes a high priority task ready, that high priority task can be inserted and run immediately (before the low priority task is inserted).

The critical response time, sometimes called the flyback time, is the time it takes to queue a new ready task and restore the state of the highest priority task. In a well-designed RTOS, readying a new task will take 3-20 instructions per ready queue entry, and restoration of the highest-priority ready task will take 5-30 instructions. On a 20MHz 68000
Motorola 68000

The Motorola 68000 is a 16/32-bit Complex instruction set computer microprocessor core designed and marketed by Freescale Semiconductor ....
 processor, task switch times run about 20 microseconds with two tasks ready. 100 MHz ARM
ARM architecture

The ARM architecture is a 32-bit RISC central processing unit architecture developed by ARM Limited that is widely used in embedded system designs....
 CPUs switch in a few microseconds.

In more advanced real-time systems, real-time tasks share computing resources with many non-real-time tasks, and the ready list can be arbitrarily long. In such systems, a scheduler ready list implemented as a linked list would be inadequate.

Algorithms

Some commonly used RTOS scheduling algorithms are:
  • Cooperative scheduling
    • Round-robin scheduling
      Round-robin scheduling

      Round-robin is one of the simplest scheduling algorithms for Computer process in an operating system, which assigns Preemption_#Time_slice to each process in equal portions and in order, handling all processes without priority....
  • Preemptive scheduling
    Preemption (computing)

    Preemption in computing is the act of temporarily interrupting a task being carried out by a computer, without requiring its cooperation, and with the intention of resuming the task at a later time....
    • Fixed priority pre-emptive scheduling
      Fixed priority pre-emptive scheduling

      Fixed priority pre-emptive scheduling is a scheduling system commonly used in real-time systems. With fixed priority pre-emptive scheduling, the scheduler ensures that at any given time, the processor executes the highest priority task of all those tasks that are currently ready to execute....
      , an implementation of preemptive time slicing
      Preemption (computing)

      Preemption in computing is the act of temporarily interrupting a task being carried out by a computer, without requiring its cooperation, and with the intention of resuming the task at a later time....
    • Critical section preemptive scheduling
    • Static time scheduling
  • Earliest Deadline First
    Earliest deadline first scheduling

    Earliest Deadline First or is a dynamic scheduling algorithm used in real-time operating systems. It places processes in a priority queue. Whenever a scheduling event occurs the queue will be searched for the process closest to its deadline....
     approach
  • Advanced scheduling using the stochastic and MTG


Intertask communication and resource sharing

Multitasking systems must manage sharing data and hardware resources among multiple tasks. It is usually "unsafe" for two tasks to access the same specific data or hardware resource simultaneously. ("Unsafe" means the results are inconsistent or unpredictable, particularly when one task is in the midst of changing a data collection. The view by another task is best done either before any change begins, or after changes are completely finished.) There are three common approaches to resolve this problem:
  • Temporarily masking/disabling interrupt
    Interrupt

    In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
    s
  • Binary semaphore
    Semaphore (programming)

    In computer science, a semaphore is a protected variable or abstract data type which constitutes the classic method for restricting access to shared resources such as shared memory in a multiprogramming environment....
    s
  • Message passing
    Message passing

    Message passing in computer science, is a form of communication used in parallel computing, object-oriented programming, and interprocess communication....


General-purpose operating systems usually do not allow user programs to mask (disable) interrupts, because the user program could control the CPU for as long as it wished. Modern CPUs make the interrupt disable control bit (or instruction) inaccessible in user mode to allow operating systems to prevent user tasks from doing this. Many embedded systems and RTOSs, however, allow the application itself to run in kernel mode for greater system call
System call

In computing, a system call is the mechanism used by an application program to request service from the kernel based on the Monolithic_kernel or to system servers on operating systems based on the microkernel-structure....
 efficiency and also to permit the application to have greater control of the operating environment without requiring OS intervention.

On single-processor systems, if the application runs in kernel mode and can mask interrupts, often that is the best (lowest overhead) solution to preventing simultaneous access to a shared resource. While interrupts are masked, the current task has exclusive use of the CPU; no other task or interrupt can take control, so the critical section is effectively protected. When the task exits its critical section
Critical section

In concurrent programming a critical section is a piece of code that accesses a shared resource that must not be concurrently accessed by more than one thread of execution....
, it must unmask interrupts; pending interrupts, if any, will then execute. Temporarily masking interrupts should only be done when the longest path through the critical section is shorter than the desired maximum interrupt latency
Interrupt latency

In real-time operating systems, interrupt latency is the time between the generation of an interrupt by a device and the servicing of the device which generated the interrupt....
, or else this method will increase the system's maximum interrupt latency. Typically this method of protection is used only when the critical section is just a few source code lines long and contains no loops. This method is ideal for protecting hardware bitmapped registers when the bits are controlled by different tasks.

When the critical section is longer than a few source code lines or involves lengthy looping, an embedded/real-time programmer must resort to using mechanisms identical or similar to those available on general-purpose operating systems, such as semaphores and OS-supervised interprocess messaging. Such mechanisms involve system calls, and usually invoke the OS's dispatcher code on exit, so they can take many hundreds of CPU instructions to execute, while masking interrupts may take as few as three instructions on some processors. But for longer critical sections, there may be no choice; interrupts cannot be masked for long periods without increasing the system's interrupt latency.

A binary semaphore is either locked or unlocked. When it is locked, a queue of tasks can wait for the semaphore. Typically a task can set a timeout on its wait for a semaphore. Problems with semaphore based designs are well known: priority inversion
Priority inversion

In scheduling , priority inversion is the scenario where a low priority task holds a shared resource that is required by a high priority task. This causes the execution of the high priority task to be blocked until the low priority task has released the resource, effectively "inverting" the relative priorities of the two tasks....
 and deadlock
Deadlock

A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. It is often seen in a paradox like 'the chicken or the egg'....
s.

In priority inversion, a high priority task waits because a low priority task has a semaphore. A typical solution is to have the task that has a semaphore run at (inherit) the priority of the highest waiting task. But this simplistic approach fails when there are multiple levels of waiting (A waits for a binary semaphore locked by B, which waits for a binary semaphore locked by C). Handling multiple levels of inheritance without introducing instability in cycles is not straightforward.

In a deadlock, two or more tasks lock a number of binary semaphores and then wait forever (no timeout) for other binary semaphores, creating a cyclic dependency graph. The simplest deadlock scenario occurs when two tasks lock two semaphores in lockstep, but in the opposite order. Deadlock is usually prevented by careful design, or by having floored semaphores (which pass control of a semaphore to the higher priority task on defined conditions).

The other approach to resource sharing is for tasks to send messages. In this paradigm, the resource is managed directly by only one task; when another task wants to interrogate or manipulate the resource, it sends a message to the managing task. This paradigm suffers from similar problems as binary semaphores: Priority inversion occurs when a task is working on a low-priority message, and ignores a higher-priority message (or a message originating indirectly from a high priority task) in its in-box. Protocol deadlocks occur when two or more tasks wait for each other to send response messages.

Although their real-time behavior is less crisp than semaphore systems, simple message-based systems usually do not have protocol deadlock hazards, and are generally better-behaved than semaphore systems.

Interrupt handlers and the scheduler

Since an interrupt handler blocks the highest priority task from running, and since real time operating systems are designed to keep thread latency to a minimum, interrupt handlers are typically kept as short as possible. The interrupt handler defers all interaction with the hardware as long as possible; typically all that is necessary is to acknowledge or disable the interrupt (so that it won't occur again when the interrupt handler returns). The interrupt handler then queues work to be done at a lower priority level, often by unblocking a driver task (through releasing a semaphore or sending a message). The scheduler often provides the ability to unblock a task from interrupt handler context.

Memory allocation

Memory allocation is even more critical in an RTOS than in other operating systems.

First, speed of allocation is important. A standard memory allocation scheme scans a linked list of indeterminate length to find a suitable free memory block; however, this is unacceptable as memory allocation has to occur in a fixed time in an RTOS.

Second, memory can become fragmented as free regions become separated by regions that are in use. This can cause a program to stall, unable to get memory, even though there is theoretically enough available. Memory allocation algorithms that slowly accumulate fragmentation may work fine for desktop machines—when rebooted every month or so—but are unacceptable for embedded systems that often run for years without rebooting.

The simple fixed-size-blocks algorithm works astonishingly well for simple embedded system
Embedded system

An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints....
s.

Another real strength of fixed size blocks is for DSP systems particularly where one core is performing one section of the pipeline and the next section is being done on another core. In this case, fixed size buffer management with one core filling the buffers and another set of cores returning the buffers is very efficient. A DSP optimized RTOS like Unison Operating System
Unison Operating System

The Unison Operating System is a SoC, multi-core and digital signal processor optimized open source real-time operating system which offers a tiny tiny Linux compatible solution....
 or DSPnano RTOS
DSPnano RTOS

DSPnano is an embedded real-time operating system which is 100% compatible with POSIX and offers a tiny tiny embedded Linux compatible solution. It was first created in 1996 and was one of the first pthread based real-time kernels....
 provides these features.

See memory allocation for more details.

Examples

These are the best known, most widely deployed real-time operating systems. See List of real-time operating systems
List of real-time operating systems

This list of real-time operating systems enumerates real-time operating systems. An RTOS is an operating system in which the maximum time from an input stimulus to an output response can be definitely determined....
 for a comprehensive list. Also, see List of operating systems
List of operating systems

Operating systems can be categorized by technology, ownership, licensing, working state, usage, and by many other characteristics. In practice, many of these groupings may overlap....
 for all types of operating systems.

  • QNX
    QNX

    QNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market. On September 12, 2007, the source of the QNX kernel was released for non-commercial use....
  • RTLinux
    RTLinux

    RTLinux is an extension of Linux to a real-time operating system, which was originally developed by Victor Yodaiken at the New Mexico Institute of Mining and Technology....
  • VxWorks
    VxWorks

    VxWorks is a real-time operating system operating system made and sold by Wind River Systems of Alameda, California, California, USA.VxWorks is designed for use in embedded systems....
  • Windows CE
    Windows CE

    Windows CE is Microsoft's operating system for minimalistic computers and embedded systems. Windows CE is a distinctly different operating system and Kernel , rather than a trimmed-down version of desktop Windows....


See also

  • Adaptive Partition Scheduler
    Adaptive Partition Scheduler

    Adaptive Partition Schedulers are a relatively new type of partition scheduler, pioneered with the most recent version of the QNX operating system....
  • BIOS
    BIOS

    In computing, the Basic Input/Output System , also known as the System BIOS, is a de facto standard defining a firmware interface for IBM PC Compatible computers....
  • DO-178B
    DO-178B

    DO-178B, Software Considerations in Airborne Systems and Equipment Certification is a guidance for software development published by RTCA, Incorporated....
  • Earliest deadline first scheduling
    Earliest deadline first scheduling

    Earliest Deadline First or is a dynamic scheduling algorithm used in real-time operating systems. It places processes in a priority queue. Whenever a scheduling event occurs the queue will be searched for the process closest to its deadline....
  • Least slack time scheduling
    Least slack time scheduling

    Least Slack Time scheduling is a scheduling. It assigns priority based on the slack time of a process. Slack time is the amount of time left after a job if the job was started now....
  • Operating system
    Operating system

    An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
  • POSIX
    POSIX

    POSIX or "Portable Operating System Interface" is the collective name of a family of related standardizations specified by the Institute of Electrical and Electronics Engineers to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, altho...
  • Rate-monotonic scheduling
    Rate-monotonic scheduling

    In computer science, rate-monotonic scheduling is a scheduling algorithm used in real-time operating systems with a static-priority scheduling class....
  • Synchronous programming language
    Synchronous programming language

    A synchronous programming language is a computer computer programming programming language optimized for programming reactive systems, systems that are often interrupted and must respond quickly....