I. Overview
A real-time system requires not only that the results are correct, but also that the results must be generated within a specific cutoff period, or even if they are correct. For example, some embedded systems, security-critical systems.
There are two types of real-time computing: hard-time systems and soft real-time systems. Hard real-time systems have the strictest requirements to ensure that critical real-time tasks are completed within the deadlines. Soft real-time systems are less restrictive, just that critical real-time tasks will have the right to take precedence over other tasks, and will retain priority until completed.
Second, system characteristics
Typical features of real-time systems:
1. Single target
2. Small size
CPU, memory is often very small, so the space consumption is very small, usually used in home appliances and consumer equipment.
3. Low volume production cost
Often CPU, memory (or cache), memory management unit, USB are included in the single integrated circuit
4, the specific time requirements
Third, real-time kernel features
The real-time kernel feature is that the simpler the better, the ability to abandon many general-purpose operating systems.
Even virtual memory has to be implemented in a different way from the real-time system:
1) CPU directly generates physical address, the advantage is fast, but requires programmers to specify the physical location of the program
2) Dynamic Relocation Register, the advantage is that the logical address and physical address can be easily converted, the disadvantage is the lack of inter-process memory protection
3) Adopt common Operation operating system method
Iv. realization of real-time operating system
Features required to implement the real-time operating system:
1, priority-based preemptive scheduling algorithm
2. Preemptive kernel
A non-preemptive kernel does not allow a process that runs in kernel mode to be preempted, and the kernel-mode process runs until it exits kernel mode, blocking or voluntarily discarding the control of the CPU. Instead, the preemptive kernel allows tasks in kernel mode to be preempted.
There are many ways to make the kernel a preemption. One is to insert a preemption point in a long-term system call, and at this point it checks whether there is a high priority process that needs to be run, or a context switch. When the high-priority process terminates, the previously interrupted process continues to run.
The other is that after the kernel is preempted, the kernel data is protected from being modified, and the kernel is fine even if it is preempted.
3, the delay of minimizing
There are two latencies that affect the performance of a real-time system:
1) Interrupt delay
2) Scheduling delay
They must be minimized.
One of the key factors that affect interrupt latency is when the data structure of the kernel is being updated, shielding the time of interruption. The real-time operating system requires interrupts to be blocked only for a short time.
The best way to deal with scheduling delays is to preempt the kernel.
4. Network Support (optional)
Five, real-time CPU scheduling
Soft real-time system scheduling does not guarantee that a critical process is scheduled, only the relative non-critical process can get priority. Hard real-time systems have stricter requirements: a task must be processed within the deadline, or it will be as if there is no service at all.
In a hard real-time system, the process has a periodicity, that is, the CPU is requested at a fixed interval (period). Each recurring process has a fixed processing time for CPU processing, a cutoff period, and a cycle. The scheduler either accepts the process, guarantees that it is completed on time, or rejects it.
wherein, 0 <= processing time <= deadline <= request period. The implication is that before the next request cycle is initiated, it must be processed (deadlines), and in this process, there can be multiple CPU processing.
1. monotonic Rate Scheduling
Schedule recurring tasks with a static preemption-first policy.
Processes running in the system are assigned a priority that is opposite to the length of the cycle. The period is short, the priority is high, otherwise it is low. And the process will run for the same duration each time the CPU is obtained. A low priority can be preempted when a high priority initiates a cycle request. However, regardless of high or low, they are guaranteed to be processed before the deadline.
The monotone rate scheduling theory mountain is the ideal algorithm, but the deadline and request period should be considered synthetically, but sometimes the process cannot be dispatched.
2. First deadline priority scheduling algorithm (EDF)
Dynamically assign priorities based on deadlines. The earlier the deadline, the higher the priority, or the lower the limit. In this algorithm, the priority of the process may often be adjusted. For example, the priority of process A is higher than process B, and when it initiates a cycle request, process B is processing, but since the deadline for B is shorter than A, B has a higher priority and B continues to process the remainder.
In theory, the EDF algorithm can make CPU usage 100%, but it is not possible to achieve this value due to the use of inter-process context switching and interrupt processing.
3. Share the schedule by proportion
All applications are divided into several executions, and the scheduler only accepts requests that share less than the current available share.
4. Pthread Dispatch
POSIX (Portable Operating system Interface, Portable Operating System interface) Pthread API.
Operating System Learning notes: real-time systems