This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > Wiki encyclopedia > RTOS


Real-time operating system (RTOS) means that when an external event or data is generated, it can be accepted and processed at a fast enough speed, and its processing result can control the production process or make a quick response to the processing system within a specified time In response, schedule all available resources to complete real-time tasks, and control the operating system for all real-time tasks to run in unison. Providing timely response and high reliability are its main features.


The real-time operating system is an operating system that guarantees the completion of specific functions within a certain time limit. The real-time operating system is divided into hard real-time and soft real-time. Hard real-time requires that the operation must be completed within the specified time, which is guaranteed during the design of the operating system; soft real-time only needs to complete the operation as quickly as possible according to the priority of the task. That's it. The operating system we usually use can become a real-time operating system after certain changes.

For example, an operating system can be designed to ensure that robots on the production line can acquire an object. In a "hard" real-time operating system, if the calculation of making the object reachable cannot be completed within the allowed time, the operating system will end with an error. In the "soft" real-time operating system, the production line can still continue to work, but the output of the product will be slowed down because the product cannot arrive within the allowed time, which causes the robot to temporarily fail to produce. Some real-time operating systems are designed for specific applications, others are universal. Some general-purpose operating systems call themselves real-time operating systems. But to some extent, most general-purpose operating systems, such as Microsoft's Windows NT or IBM's OS/390, have the characteristics of real-time systems. This means that even if an operating system is not strictly a real-time system, they can solve some real-time application problems.

In general, the real-time operating system (RTOS) requires:


Handle process lines that can be prioritized

A sufficient amount of interruption levels

The embedded small operating system that is installed as part of the micro-device often requires a real-time operating system. Some core issues can be considered to meet the needs of real-time operating systems. However, because other components such as device drivers are also often required by special methods, a real-time operating system is usually larger than the core.

Real-time tasks

There must be several real-time tasks in the real-time system. These tasks are usually related to some external devices and can respond to or control the corresponding external devices, so there is a certain degree of urgency. Real-time tasks can be classified from different angles.

Divided according to whether the task shows periodic changes:

a. Periodic real-time tasks

The external device periodically sends an excitation signal to the computer, requiring it to be executed cyclically in accordance with a specified period, so as to periodically control a certain external device.

b. Aperiodic real-time tasks

There is no obvious periodicity of the stimulus signals sent by external equipment, but they must all be linked to a cut-off time. It can be divided into two parts: start deadline (task must start execution before a certain time) and completion deadline (task must complete before a certain time).

Divided according to the deadline requirements:

a. Hard real-time tasks

b. Soft real-time tasks


1) High-precision timing system

Timing accuracy is an important factor affecting real-time performance. In real-time application systems, it is often necessary to accurately determine the operation of a device or perform a task in real time, or to accurately calculate a time function. These depend not only on the clock accuracy provided by some hardware, but also on the high-precision timing functions implemented by the real-time operating system.

2) Multi-level interrupt mechanism

A real-time application system usually needs to process a variety of external information or events, but the urgency of processing depends on the priority. Some must respond immediately, while others can be postponed. Therefore, it is necessary to establish a multi-level interrupt nesting processing mechanism to ensure that real-time events with high urgency are responded to and processed in a timely manner.

3) Real-time scheduling mechanism

The real-time operating system must not only respond to real-time event interrupts in a timely manner, but also schedule and run real-time tasks in a timely manner. However, processor scheduling cannot be carried out at will, because the switching between the two processes can only be performed at the time point of ensuring "safe switching". The real-time scheduling mechanism includes two aspects. One is the scheduling strategy and The algorithm guarantees the priority scheduling of real-time tasks; the second is to establish more "safe handover" time points to ensure timely scheduling of real-time tasks.


Comparison of characteristics of real-time system and time-sharing system

(1) Multipath. The real-time information processing system has multiple channels as the time-sharing system. The system serves multiple end users according to the time-sharing principle; for real-time control systems, the multi-channel nature is mainly manifested in the frequent collection of multi-channel on-site information and the control of multiple objects or multiple actuators.

(2) Independence. The real-time information processing system is as independent as the time-sharing system. When each end user makes a service request to the time-sharing system, they operate independently of each other and do not interfere with each other; and in the real-time control system, information collection and control of objects do not interfere with each other.

(3) Timeliness. The real-time information system's real-time requirements are similar to the time-sharing system, which is determined by the waiting time acceptable to humans; while the real-time control system's timeliness is based on the start deadline or completion deadline required by the control object. To determine, it is generally in the order of seconds, hundreds of milliseconds to milliseconds, and some are even less than 100 microseconds.

(4) Interactivity. The real-time information processing system is interactive, but the interaction between people and the system here is limited to access to certain special service programs in the system. It does not provide data processing services, resource sharing and other services to end users like a time-sharing system.

(5) Reliability. Time-sharing systems require reliable systems, while real-time systems require highly reliable systems. Because any error can bring huge economic losses and even unpredictable catastrophic consequences. Therefore, in real-time systems, multi-level fault-tolerant measures have been taken to ensure the security of the system and the security of data.

Related concepts

Basic concepts

Code critical section: refers to the inseparable code during processing. Once this part of the code begins to execute, it is not allowed to break into;

Resources: any entity occupied by the task;

Shared resources: resources that can be used by more than one task;

Task: Also called a thread, it is a simple program. Each task is given a certain priority, with its own set of CPU registers and its own stack space. Typically, each task is an infinite loop, and each task is in the following five states: sleep state, ready state, running state, suspended state, and interrupted state;

Task switching: save the current state of the running task (the entire contents of the CPU register) in the task's own stack area, and then reload the current state of the next task to be run from the task's stack into the CPU's register, And start the next task;

Core: responsible for managing various tasks, allocating CPU time for each task, and responsible for communication between tasks. Divided into an inalienable core and an inalienable core;

Scheduling: One of the core responsibilities of the kernel, deciding which task to run in turn. Generally based on priority scheduling method;

Priority issues

Task priority: divided into static priority with unchangeable priority and dynamic priority with changeable priority;

Priority inversion: The priority inversion problem is the most common problem in real-time systems. The allocation of shared resources can cause tasks with low priority to run first and tasks with high priority to run later. The solution is to use the "priority inheritance" algorithm to temporarily change the priority of the task to curb the priority inversion.

Mutually exclusive

Although the shared data area simplifies the exchange of information between tasks, it is necessary to ensure the exclusivity of each task when processing shared shared data. The general methods to make it meet the mutually exclusive conditions are: turn off interrupt, use test and set instruction (TAS), prohibit task switching, use semaphore.

Because the significance of using a real-time operating system is to be able to deal with various emergencies in a timely manner, that is, to handle various interrupts, so the most important and representative performance index parameter for measuring embedded real-time operating systems should undoubtedly be the interrupt response time Too. Interrupt response time is usually defined as:

Interrupt response time = interrupt delay time + time to save CPU state + execution time of the ISR entry function of the core.

Interrupt delay time = MAX (the longest time to turn off the interrupt, the longest instruction time) + the time to start executing the first instruction of the ISR.

Maximum interrupt prohibition time:

When the RTOS is running in nuclear state or executing certain system calls, it will not be interrupted due to the arrival of an external interrupt. Only when the RTOS returns to the user state will it respond to the external interrupt request. The maximum time required for this process is the maximum interrupt prohibit time.

Task switching time:

When a task quits running for some reason, RTOS saves its running site information, inserts the corresponding queue, and re-selects a task to be put into operation according to a certain scheduling algorithm. The time required for this process is called task switching time .

Among the above items, the maximum interrupt prohibition time and task switching time are the two most important technical indicators for evaluating the real-time performance of an RTOS.


  • XC2C64A-7VQG44I


    CPLD CoolRunner -II Family 1.5K Gates 64 Macro Cells 159MHz 0.18um Technology 1.8V 44-Pin VQFP

  • XCV200-6BG352C


    FPGA Virtex Family 236.666K Gates 5292 Cells 333MHz 0.22um Technology 2.5V 352-Pin Metal BGA

  • XCV200-6PQ240C


    FPGA Virtex Family 236.666K Gates 5292 Cells 333MHz 0.22um Technology 2.5V 240-Pin PQFP

  • XC4028XL-3BG256C


    FPGA XC4000X Family 28K Gates 2432 Cells 0.35um Technology 3.3V 256-Pin BGA

  • XC5VFX130T-2FF1738I


    FPGA Virtex-5 FXT Family 65nm Technology 1V 1738-Pin FCBGA

FPGA Tutorial Lattice FPGA
Need Help?


If you have any questions about the product and related issues, Please contact us.