What Is a Real-Time Operating System?
Real-time operating system (RTOS) means that when external events or data are generated, they can be accepted and processed at a fast enough speed, and the results of the processing can control the production process or make rapid processing systems within a specified time. Respond, schedule all available resources to complete real-time tasks, and control the operating system where all real-time tasks run in unison. Providing timely response and high reliability are its main features.
- A real-time operating system is an operating system that guarantees that certain functions are completed within a certain time limit. Real-time operating systems are divided into hard real-time and soft real-time. Hard real-time requires that operations must be completed within a 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. Just fine. The operating system we usually use can become a real-time operating system after a certain change.
- 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 to make an object reachable is not 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 makes the robot have a short period of non-production. Some real-time operating systems are designed for specific applications, while others are general purpose. 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
- There must be several real-time tasks in a real-time system. These tasks are usually related to certain external devices and can reflect or control the corresponding external devices, so they have a certain degree of urgency. Real-time tasks can be classified from different perspectives.
- Divided according to whether there is a periodic change in the task execution:
- a. Periodic real-time tasks
- The external device sends a stimulus signal to the computer periodically, requiring it to execute in a cyclic manner in order to periodically control some external device.
- b. Aperiodic real-time tasks
- There is no obvious periodicity of the stimulus signals sent by external equipment, but they must be associated with a deadline. It can be divided into two parts: the start deadline (the task must be executed before a certain time) and the completion deadline (the task must be completed before a certain time).
- Divided according to the deadline requirements:
- a, hard real-time tasks
- b. Soft real-time tasks [2]
- 1) High-precision timing system
- Timing accuracy is an important factor affecting real-time performance. In a real-time application system, it is often necessary to accurately determine to operate a certain device or perform a certain 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 is of different priorities. Some must respond immediately, while others can be postponed. Therefore, multiple levels need to be established
- Comparison of characteristics of real-time systems and time-sharing systems
- (1) Multi-way. Real-time information processing systems are as multiplexed as time-sharing systems. The system serves multiple end users according to the time-sharing principle. For real-time control systems, the multi-path is mainly reflected in the collection of multi-channel field information and 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, the collection of information and control of objects do not interfere with each other.
- (3) Timeliness. The real-time requirements of real-time information systems are similar to those of time-sharing systems, which are determined by the acceptable waiting time of people; while the timeliness of real-time control systems is based on the start or finish deadline required by the control object. To determine, it is usually in the order of seconds, hundreds of milliseconds up to milliseconds, and even some are 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 some specific dedicated service programs in the system. It does not provide data processing services, resource sharing, and other services to end users like time-sharing systems.
- (5) Reliability. Time-sharing systems require systems to be reliable, in contrast, real-time systems require systems to be highly reliable. Because any mistake can bring huge economic losses and even unpredictable catastrophic consequences. Therefore, in real-time systems, multi-level fault tolerance measures are adopted to ensure the security of the system and the security of data. [2]
Real-time operating system basic concepts
- Code critical section: refers to the code that is inseparable during processing. Once this part of the code starts to execute, interrupts are not allowed to be entered;
- Resource: 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 and has 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: hibernation, ready, running, suspended, and interrupted;
- Task switching: save the current status of the running task (the entire contents of the CPU register) in the task's own stack area, and then reload the current status of the next task to be run from the task's stack into the CPU's register, And start the next task;
- Kernel: responsible for managing each task, allocating CPU time for each task, and responsible for communication between tasks. Divided into non-deprivable kernels and deprivable kernels;
- Scheduling: One of the main responsibilities of the kernel, deciding which task to run. Generally based on priority scheduling method;
Real-time operating system priority issues
- Task priority: divided into static priority with unchangeable priority and dynamic priority with changeable priority;
- Priority inversion: Priority inversion is the most common problem in real-time systems. The allocation of shared resources can cause low-priority tasks to run first and higher-priority tasks to run later. The solution is to use the "priority inheritance" algorithm to temporarily change the task priority to curb priority inversion.
Real-time operating system mutex
- Although the shared data area simplifies the exchange of information between tasks, it must ensure that each task is exclusive when dealing with shared shared data. The general methods to make it meet the mutually exclusive conditions are: turn off interrupts, use test and set instructions (TAS), prohibit task switching, and use semaphores.
- Because the significance of using a real-time operating system is to be able to handle various unexpected events in a timely manner, that is, to handle various interrupts, the most important and representative performance indicator parameter for measuring the embedded real-time operating system should undoubtedly be the interrupt response time. Already. 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 kernel.
- Interrupt delay time = MAX (the longest time to turn off the interrupt, the longest instruction time) + the time to start the first instruction of the ISR.
- Maximum interrupt disable time:
- When the RTOS is running in kernel mode or executing certain system calls, it will not interrupt execution due to the arrival of external interrupts. Only when the RTOS returns to user mode will it respond to external interrupt requests. The maximum time required for this process is the maximum interrupt disable time.
- Task switching time:
- When a task is taken out of operation for some reason, the RTOS saves its running field information, inserts it into the corresponding queue, and reselects a task to run according to a certain scheduling algorithm. The time required for this process is called task switching time .
- Among the above items, the maximum interrupt disable time and task switching time are the two most important technical indicators for evaluating the real-time performance of an RTOS.