Linux real-time enhancement method based on domestic real-time kernel
By introducing the kernel adaptation layer and the real-time core designed in parallel, the problem of insufficient real-time performance of traditional Linux kernels in hard real-time applications is solved, and efficient interaction and resource management between the real-time kernel and the Linux kernel is realized, ensuring the stability and real-time performance of the system.
Patent Information
- Application Number
- CN202411901613.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
AI Technical Summary
The traditional Linux kernel lacks real-time performance in hard real-time applications, and existing solutions such as real-time Linux patches or foreign real-time frameworks have compatibility issues, high code coupling and security risks.
By introducing the kernel adaptation layer, the real-time kernel is designed in parallel with the Linux kernel. The real-time kernel presets the Linux kernel to the lowest priority, and the critical path is implanted with the real-time kernel hook function, and the same timer queue is used for event management, and an independent memory pool is allocated to the real-time kernel through the memory interface vmalloc.
It realizes efficient interaction and resource management between the real-time kernel and the Linux kernel, reduces the degree of code coupling, ensures the stability and real-time performance of the system, and meets the needs of hard real-time applications.
Smart Images

Figure CN119829245A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded real-time operating systems, and specifically to a Linux real-time enhancement method based on a domestic real-time kernel. The method improves the real-time performance of the Linux kernel by integrating a domestic real-time kernel. The method is suitable for application scenarios that require high reliability and low-latency response, such as industrial control, automation, automotive electronics, and aerospace. Background Art
[0002] With the development of science and technology, embedded systems play an increasingly important role in many industries. For these systems, the demand for real-time performance is growing. Although the traditional Linux kernel is popular for its open source and rich driver support, its non-preemptive scheduling mechanism and real-time performance limit its use in hard real-time applications.
[0003] To solve these problems, commonly used solutions include: applying real-time Linux patches (such as PREEMPT_RT) to improve the real-time performance of the system, which is a soft real-time patch and may introduce compatibility issues between drivers and software; or using existing foreign real-time frameworks and systems to enhance real-time performance, but this usually leads to high code coupling and difficulties in maintenance and expansion, which brings potential security risks, especially under the current international situation.
[0004] In contrast, domestically developed real-time operating systems have higher real-time performance and security, but their ecosystems are relatively small, which is not conducive to long-term development. Therefore, it is particularly important to combine the two to form a hybrid kernel environment, which can not only make up for the shortcomings of Linux real-time performance, but also promote the ecological construction of domestic operating systems. However, the main challenge facing such a combination is how to effectively achieve efficient interaction between the two kernels, effective management of resources and reduce the coupling between codes, while ensuring the stability and real-time performance of the overall system. Summary of the invention
[0005] The purpose of the technical solution of the present invention is to provide an effective method to enhance the real-time capability of the system by integrating an efficient domestic real-time kernel without changing the original characteristics of Linux. The method is committed to reducing system complexity, optimizing resource utilization, ensuring stable operation of the system, and meeting strict real-time requirements.
[0006] The technical solution of the present invention provides a Linux real-time enhancement method based on a domestic real-time kernel, comprising the following steps:
[0007] The real-time kernel uses the interface of the kernel adaptation layer to access the Linux kernel, and references the header files of the Linux kernel and the external interface provided by the kernel state, so that the real-time kernel and the Linux kernel are designed in parallel in the embedded real-time operating system;
[0008] The kernel adaptation layer creates corresponding wrappers to encapsulate the header files or external interfaces that reference the Linux kernel;
[0009] The Linux kernel is preset as the lowest priority within the real-time kernel;
[0010] In the critical path of the embedded real-time operating system, a hook function is implanted in the real-time core to intercept the request. If the hook function determines that the intercepted request is a real-time task request, it is directly intercepted to the real-time core for processing. Otherwise, it is processed by the Linux kernel.
[0011] The memory interface vmalloc of the Linux kernel is used to allocate an independent memory pool for the real-time core, and is allocated to the real-time core during the real-time core initialization phase.
[0012] Preferably, the Linux kernel and the real-time core use the same timer queue for event management.
[0013] Preferably, the header file includes Linux kernel data structure, function prototypes and other necessary information.
[0014] Preferably, the external interface provides an access point to Linux kernel services.
[0015] Preferably, the wrapper handles internal conversions, parameter checking, and error handling.
[0016] Preferably, the Linux kernel is responsible for initializing the serial port and the clock module, and the real-time core interacts by calling the encapsulation interface through the kernel adaptation layer.
[0017] Preferably, the real-time core includes a real-time library and a real-time system call, and the Linux kernel includes a non-real-time library and a non-real-time system call;
[0018] Introduce the task_struct pointer of the Linux kernel into the task control block of the real-time task in the real-time library, so that the switch_to interface of the Linux kernel is used when switching between real-time tasks and non-real-time tasks;
[0019] When the idle task switches to the real-time task, the task_struct pointer of the idle task is updated;
[0020] Before switching tasks, prepare by switching floating point and SIMD register states, thread local storage (TLS), context ID registers, and user access permissions.
[0021] Record memory context information during task switching;
[0022] Save general purpose registers according to register status.
[0023] The technical solution of the present invention proposes a Linux real-time enhancement method based on a domestic real-time kernel. By introducing a kernel adaptation layer and designing an encapsulation mechanism of the kernel adaptation layer, it is ensured that the code space between the real-time kernel and the Linux kernel is effectively isolated, the code coupling degree is reduced, and the kernel and the Linux kernel can coexist harmoniously in the same environment without interfering with each other. The real-time task can call a non-real-time system call and inherit the existing functions and services of Linux, thereby giving full play to the advantages of the Linux ecosystem. Through flexible and diverse resource allocation and sharing strategies, the effective management of hardware and memory resources is ensured, and the problems of resource contention and performance degradation are reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A schematic diagram of a system architecture provided by an embodiment of the present invention;
[0025] Figure 2 A flow chart of initialization of a real-time kernel provided by an embodiment of the present invention;
[0026] Figure 3 A schematic diagram of a real-time scheduling algorithm provided by an embodiment of the present invention;
[0027] Figure 4 A schematic diagram of deploying real-time tasks using an embodiment of the present invention;
[0028] Figure 5 This is a schematic diagram of test results before the modification using the embodiment of the present invention;
[0029] Figure 6 This is a schematic diagram of test results after modification using an embodiment of the present invention. DETAILED DESCRIPTION
[0030] The present invention will be further described below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms fall within the scope limited by the appended claims of the application equally.
[0031] The embodiment of the present invention provides a Linux real-time enhancement method based on a domestic real-time kernel, which relates to a dual-core coexistence architecture, in which the real-time kernel is responsible for processing high-priority tasks, and the Linux kernel runs as an idle task. The real-time library provides the necessary interfaces to support user-mode application development, allowing the creation and management of real-time tasks and the execution of real-time-specific operations.
[0032] The above system architecture is as follows Figure 1 As shown in the figure. In this architecture, the Linux kernel and the domestic real-time kernel (hereinafter referred to as the "real-time kernel") exist in parallel in the same system environment, jointly providing services for applications. This design not only retains the advantages of Linux's rich ecosystem and support for a wide range of hardware drivers, but also significantly improves the system's response speed and reliability by introducing high-performance real-time processing capabilities.
[0033] Hard real-time has strict requirements on the deadline of task response, emphasizing that tasks must complete the specified task within the specified time. In order to meet this requirement, the real-time kernel treats the Linux kernel as an idle task to run, which means that the Linux kernel will take over the CPU resources only when there is no higher priority task to be executed. Inside the real-time kernel, the idle task is given the lowest priority to ensure that at any time, the real-time task can be scheduled immediately once it is ready, thus ensuring the low latency characteristics of the system.
[0034] The system scheduling is mainly driven by interrupts and system scheduling. In order to ensure that real-time tasks can be processed in a timely manner, hook functions of the real-time kernel are implanted on the critical path. The function of these hook functions is to intercept requests at appropriate times. First, it is determined whether a real-time task is involved. If so, the real-time kernel directly takes over the processing; if not, it is handed over to the Linux kernel for processing according to the normal process. This method effectively guarantees the priority of real-time tasks, while also avoiding the modification of the original scheduling logic of the Linux kernel, maintaining the stability and compatibility of the system.
[0035] In order to maintain the consistency of the internal timing of the entire system, the real-time core and the Linux kernel use the same timer queue for management. Whenever a new timer is registered or a timed event is processed, the relevant code segment will be processed by the hook function to ensure that all timing activities are carried out under a unified framework. This not only simplifies the complexity of timing management, but also avoids clock drift and event loss.
[0036] We have adopted a flexible and efficient approach to the allocation of hardware resources and memory. On the one hand, hardware devices can be managed by the real-time kernel or the Linux kernel according to different requirements. On the other hand, memory resources are also reasonably divided into two parts: one part is dedicated to the real-time kernel, and the other part is for the Linux kernel. The corresponding drivers can also be divided into two types: real-time and non-real-time. In this way, the resource conflict between the two can be effectively reduced and resource utilization can be improved.
[0037] In order to ensure that the real-time kernel and the Linux kernel can be compiled smoothly in the same environment and coexist harmoniously in a system, the compatibility and isolation issues between the two must be resolved. Due to the significant differences in the design intentions, functional characteristics, and code structure of the two kernels, directly combining them together will lead to code complexity, increase development and maintenance costs, and reduce system stability and scalability.
[0038] To this end, we introduced a specially designed Kernel Adaptation Layer (KAL). This adaptation layer plays a vital role as a bridge between the real-time kernel and the Linux kernel. It not only effectively isolates the code space of the two kernels to prevent mutual contamination, but also provides a set of simplified interfaces for the real-time kernel to enable it to safely access the functions and services of the Linux kernel.
[0039] Specifically, the kernel adaptation layer allows the real-time kernel to reference the header files of the Linux kernel and the external interfaces provided by the kernel state. These header files contain Linux kernel data structures, function prototypes, and other necessary information, while the external interfaces provide access points to Linux kernel services. In this way, the real-time kernel can take advantage of its rich driver support and other resources without changing the original Linux code.
[0040] To further improve the isolation effect and enhance flexibility, the adaptation layer encapsulates the referenced content. This means that for each data structure or interface referenced from the Linux kernel, the adaptation layer will create a corresponding wrapper. These wrappers are responsible for handling internal conversions, parameter checking, and error handling to ensure the safety and efficiency of the interaction between the real-time kernel and the Linux kernel. For example, when the real-time kernel initializes the memory pool, it does not directly call the Linux vmalloc() function, but operates through the vmalloc_rt() interface encapsulated by the adaptation layer. Similarly, for other types of requests, such as configuring the clock and obtaining the task status, the adaptation layer will also provide corresponding wrappers to ensure real-time and correctness. In addition, for some complex interface calls, the adaptation layer will also build temporary objects to bridge the real-time kernel and the Linux kernel. For example, when processing task scheduling, the adaptation layer will create a shadow task to record the task information in the Linux kernel and map it to the task model of the real-time kernel.
[0041] Through the above measures, the kernel adaptation layer can reduce the coupling degree between the real-time kernel and the Linux kernel and reduce the direct dependence between the two, so that each kernel can develop independently without being affected by the other, greatly improving the maintainability and scalability of the system.
[0042] Another key issue that the dual-core system needs to solve is how to deal with the allocation and sharing of system resources. To this end, we have adopted a flexible allocation and sharing strategy. The first is the allocation of memory resources. In order to enhance the portability of the code and simplify memory management, we use the existing memory interface vmalloc of the Linux kernel to allocate an independent memory pool for the real-time core, and allocate it to the real-time core during the real-time core initialization phase. The real-time core does not need to care about the physical memory layout and mapping, and also avoids memory conflicts with the Linux kernel. On the other hand, efficient data exchange can be achieved between real-time tasks and non-real-time tasks through shared memory. The real-time core continues to use the existing memory management mechanism to operate this pre-allocated memory, ensuring that the two memory management systems can coexist harmoniously without the need for additional porting work.
[0043] Secondly, for other hardware resources, appropriate sharing strategies can be selected as needed. For example, Linux is responsible for the initialization of the serial port and clock module, and the real-time kernel interacts by calling the encapsulation interface (such as printk or timer configuration) through the adaptation layer; low real-time devices such as graphics engines inherit the existing Linux drivers to give full play to its ecological advantages; network devices can choose to inherit the Linux network card driver or develop independent real-time drivers to support hard real-time applications; sensors and control devices can directly access hardware registers to achieve high-precision real-time drivers.
[0044] This flexible allocation and sharing mechanism can not only give full play to the ecological advantages of Linux, but also ensure timely response of real-time tasks and reduce resource contention and performance degradation.
[0045] During the Linux initialization phase, a special initialization program is registered through the device_initcall interface to load the real-time kernel. At this point, the Linux kernel's subsystem initialization has been completed, and the real kernel can safely call Linux's vmalloc function to allocate the required memory resources for itself and activate the hook functions previously implanted in key locations such as interrupt processing, system calls, and timing processing. This process ensures that the real-time kernel can be seamlessly integrated into the existing Linux environment while maintaining its independence and real-time responsiveness.
[0046] The initialization process of the real-time kernel is as follows Figure 2 As shown in the figure. First, the system memory is initialized based on the pre-allocated memory pool, and core objects such as semaphores, mutexes, and message queues are allocated. Subsequently, the real-time kernel scheduler is initialized, the current Linux task is regarded as an idle task, and its memory context is recorded. The task_struct pointer of the Linux task is introduced in the task control block to maintain the association between the two. Next, a key task (such as kernel_job) for handling kernel events is created, the clock and interrupt modules are initialized, and the necessary hook functions are implanted in the Linux kernel. When all preparations are completed, the real-time kernel scheduler is started, and the Linux kernel is run as an idle task with the lowest priority, thereby achieving a smooth switch from Linux to the real-time kernel. When all real-time tasks are completed or processor resources are released, the system will switch back to the Linux task again. When an external interrupt or system call occurs, the handler in the hook function makes a judgment again to decide whether the system should switch to a real-time task or a non-real-time task. Through this mechanism, it can be ensured that tasks in both modes can run normally.
[0047] In a dual-core environment, task switching becomes complex and diverse. The key issue is how to efficiently handle context switching between different types of tasks. Specifically, task switching mainly involves switching between real-time tasks, switching between non-real-time tasks, and switching between real-time tasks and non-real-time tasks. To cope with this complexity, we introduced the Linux kernel's task switching logic into the real-time kernel's task switching mechanism to ensure smooth switching between the two types of tasks. Specific methods include:
[0048] (1) Introducing Linux task structure pointer: Introducing Linux task_struct pointer in the task control block (TCB) of the real-time task makes it possible to use Linux switch_to interface when switching between real-time tasks and Linux tasks, thus achieving seamless switching.
[0049] (2) Accurately record the current task: When switching between the real-time task and the idle task, the system needs to record the correct current task. Since the task currently running in Linux is uncertain when switching from the idle task to the real-time task, the task_struct pointer of the idle task must be updated every time the idle task is left to accurately record the current task of Linux. This ensures that when the real-time task switches back to the idle task, Linux can recover to the correct task.
[0050] (3) Saving memory context: During the task switching process, the system will record the memory context information so that it can be restored to the correct memory address space later to ensure the consistency of the execution environment after the task switch.
[0051] (4) Preparation before task switching: As needed, the system will complete a series of preparations before task switching, such as switching the floating-point and SIMD register states, thread local storage (TLS), context ID registers, and user access permissions, to ensure that the task can run correctly after switching.
[0052] (5) Optimize the preservation of CPU general registers: Considering that task switching is usually triggered by interrupts or system calls, and these events have saved some register states, only some general registers need to be saved during the actual task switching. For example, on the aarch64 platform, only callee-saved registers (registers that must be saved and restored by the callee when a function is called, as agreed by the architecture) need to be saved. In this way, the time required for task switching is reduced and the system response speed is improved.
[0053] In order to meet the hard real-time requirements, the real-time kernel uses a priority-based preemptive scheduling algorithm and combines time slice rotation and first-in-first-out strategy to schedule tasks of the same priority, such as Figure 3As shown. The task priority range is 0-255, where 255 is the highest priority and 0 is the lowest priority. The Linux kernel is regarded as the lowest priority idle task to ensure that real-time tasks can respond in time. The scheduling algorithm schedules tasks according to their priority, and tasks with higher priorities are given priority to CPU resources. If a higher priority task is ready, the kernel will immediately save the context of the current task and switch to the high-priority task for execution. In addition, the time slice rotation strategy ensures that tasks of the same priority can use processor resources fairly. Each task releases the processor after running a time slice, and the task is placed at the end of the same priority task queue according to its priority, waiting for the next scheduling. This scheduling mechanism can effectively meet the needs of most hard real-time applications and ensure the stability and efficiency of the system.
[0054] The kernel's scheduling is mainly driven by external interrupts and system calls, which is the key to ensuring that the operating system can respond to various events in a timely manner. In order to achieve comprehensive control of the entire system by the real-time kernel, the real-time kernel's hook function must be added during the interrupt processing and system call process. The role of the hook function is to intercept requests on the critical path, determine whether it involves real-time tasks, and ensure that they are processed first.
[0055] When an interrupt occurs, since the real-time task has a higher priority, the interrupt processing function of the real-time kernel will be executed first, and the interrupt processing of Linux may be delayed. Specifically:
[0056] (1) Real-time task priority: When an external interrupt occurs, if the real-time task is currently running or is about to be scheduled, the real-time interrupt processing function will be executed immediately. At this time, the Linux interrupt processing function will be postponed, and the related interrupt events will be temporarily stored in the waiting queue. Only when the schedule returns to the Linux task again, these postponed interrupt events will be processed. This design ensures that the real-time task can quickly obtain CPU resources when needed, avoiding delays.
[0057] (2) Switching from Linux tasks: On the contrary, if the Linux task is currently running and an interrupt event occurs that causes the real-time task to be awakened, the Linux task as an idle task will be immediately switched out. The real-time kernel takes over the CPU resources and starts executing the high-priority real-time task, thus ensuring that the real-time task can always respond in time and meet the strict time requirements.
[0058] To avoid clock confusion caused by different interrupt processing orders, the real-time kernel and Linux use the same timer queue for unified management. This strategy simplifies the timer management logic and ensures the consistency and accuracy of the system clock. Whenever Linux adds a new timer, the timer will also be added to the timer queue maintained by the real-time kernel. The Linux system clock is usually periodic, and when an interrupt occurs, the timer will be reset immediately. Even though Linux's timing processing may be delayed due to the existence of real-time tasks, the system clock itself will not become inaccurate.
[0059] Through the above mechanism, we not only ensure that real-time tasks can respond in a timely manner, but also maintain the accuracy of the system clock, so that the system can remain stable and efficient even in high-load scenarios.
[0060] The real-time kernel provides a set of POSIX-compatible interfaces for user-mode applications. These interfaces execute functions within the real-time kernel through system calls. This design can simplify the development process and ensure the portability of applications. User-mode programs can create and manage real-time tasks through POSIX interfaces, and handle synchronization and mutual exclusion events between tasks. In this way, developers can write efficient and reliable real-time applications without understanding the underlying details.
[0061] During the system call process, the real-time kernel implants a special handler to determine whether the current system call number is for real-time or non-real-time operation. Based on this judgment, the real-time kernel will choose to call the corresponding kernel processing function to ensure that different types of system calls can be handled correctly. This mechanism ensures a clear division between real-time tasks and non-real-time tasks, and ensures that real-time system calls can be executed in a timely manner.
[0062] In order to give full play to the ecological advantages of Linux, real-time tasks are allowed to call non-real-time system calls in certain scenarios. To this end, when a user-mode program creates a real-time task, the real-time kernel will simultaneously create a corresponding "shadow task" in the Linux kernel. The two tasks share the same task_struct pointer to record task context information. This means that at any given moment, only one real task entity is actually running in the system, thus avoiding resource conflicts and inconsistent states.
[0063] Specifically, when a real-time system call is executed, the shadow task in the Linux kernel will be suspended, and the corresponding real-time task will be awakened and obtain CPU resources. Conversely, when a non-real-time system call needs to be executed, the real-time task will be suspended, and the shadow task will be activated to continue to execute operations in the Linux environment. This mechanism ensures that both real-time and non-real-time system calls can be executed in the correct environment. It should be noted that the execution of non-real-time system calls by real-time tasks is only applicable to occasions with low real-time requirements. Therefore, this situation should be fully considered when designing user programs to avoid using non-real-time system calls at inappropriate times.
[0064] Combining the real-time runtime and the non-real-time runtime can give full play to the advantages of the Linux ecosystem. By cleverly combining real-time tasks and non-real-time tasks, it can not only meet the needs of high-real-time applications, but also retain Linux's extensive driver support and other functional features.
[0065] This solution is used to perform real-time enhancement on Linux 4.19 based on the domestic Ruihua embedded real-time operating system on the Feiteng 2000aarch64 platform. Figure 4 This shows how to deploy real-time tasks in a Linux system. The test program creates a real-time task, obtains real-time task information by calling a real-time system call, and uses a non-real-time system call printf to print the current running real-time task information. Figure 4 In the figure, we can see that two real-time system tasks, sweeper_job and thread_job, which process system events, and a real-time task rt-test created by a user program are running. At the same time, other Linux tasks running in the system can also be seen through the Linux ps command. This shows that the two kernels can coexist harmoniously in a unified environment, and the real-time kernel can inherit the existing Linux resources.
[0066] To evaluate the improvement in real-time performance, we used the cyclictest benchmark program to test the original version and the real-time performance-enhanced version. Cyclictest is a tool specifically designed to test the performance of real-time systems, which can measure the maximum and average delays of the system.
[0067] The test results before transformation are as follows Figure 5 Without real-time enhancement, the average response time of the task is 5 microseconds, and the maximum response time reaches 16 microseconds.
[0068] The test results after transformation are as follows Figure 6As shown in the figure, the average response time of the task is significantly reduced to 1 microsecond and the maximum response time is shortened to 6 microseconds after the real-time kernel is enhanced. Compared with the system before the transformation, the real-time performance has been significantly improved.
[0069] These test results fully demonstrate the effectiveness of the real-time enhancement solution, which is particularly important for application scenarios that require high reliability and low latency. It also reflects the compatibility of the real-time kernel with the Linux ecosystem, ensuring that the system can be applied in a variety of application scenarios.
[0070] Beneficial effects of the embodiments of the present invention: By integrating the domestic real-time kernel, the real-time response capability of the Linux system is significantly enhanced. Especially in the application scenarios of high reliability and low latency response, this enhancement can ensure that the system operates efficiently under strict time constraints. This solution not only improves the real-time performance, but also retains the rich driver support and good ecology of Linux. By introducing the kernel adaptation layer (KAL), the kernel and the Linux kernel can coexist harmoniously in the same environment without interfering with each other. Real-time tasks can call non-real-time system calls and inherit the existing functions and services of Linux, so as to give full play to the advantages of the Linux ecology. The encapsulation mechanism of the kernel adaptation layer can ensure that the code space between the real-time kernel and the Linux kernel is effectively isolated and the code coupling is reduced. The development process is simplified and the maintainability and scalability of the system are improved. This patent proposes flexible and diverse resource allocation and sharing strategies to ensure the effective management of hardware and memory resources and reduce the problems of resource contention and performance degradation. In addition, the real-time scheduling algorithm based on priority preemption combined with time slice rotation and first-in-first-out strategy ensures the timely response and fair scheduling of real-time tasks and improves the overall performance of the system.
[0071] In summary, this patent provides an effective solution that significantly improves the real-time performance of the Linux system by integrating a domestic real-time kernel while retaining its rich ecosystem advantages.
[0072] The key technical points of the embodiments of the present invention are as follows:
[0073] 1) Efficient collaboration: How to achieve efficient collaboration between the domestic real-time kernel and the Linux kernel, ensuring both real-time performance and taking into account the Linux ecosystem is the key to the present invention. By introducing a kernel adaptation layer, it is ensured that the two kernels can coexist harmoniously in the same environment and can work together effectively.
[0074] 2) Task switching mechanism: A well-designed task switching mechanism is the key to ensuring the real-time performance of the system. The mechanism needs to ensure that real-time tasks can quickly obtain CPU resources when needed, while not affecting the normal operation of non-real-time tasks. Specific measures include implanting hook functions on the critical path, giving priority to real-time task requests, and smoothly switching between real-time and non-real-time tasks.
[0075] 3) Scheduling algorithm: In order to meet strict time constraints, a priority-based preemptive real-time scheduling algorithm is adopted, and time slice rotation and first-in-first-out strategy are combined to schedule tasks of the same priority. This not only ensures the timely response of real-time tasks, but also achieves fair scheduling between tasks, improving the overall efficiency of the system.
[0076] 4) Compatibility with existing resources: Ensure that the real-time kernel can fully utilize existing Linux resources and services, such as drivers, file systems, and network protocol stacks. Through the POSIX standard interface, user-mode programs can create and manage real-time tasks and call non-real-time system calls, giving full play to the ecological advantages of Linux.
[0077] The technical points to be protected in this application include but are not limited to the following:
[0078] 1) Design of kernel adaptation layer: As a bridge between the real-time kernel and the Linux kernel, the kernel adaptation layer is responsible for isolating the code space, encapsulating interfaces, and providing efficient and reliable access methods. It ensures efficient interaction between the two kernels, reduces code coupling, and improves the maintainability and scalability of the system.
[0079] 2) Specific implementation of task scheduling and context switching: A real-time scheduling algorithm based on priority preemption combined with time slice rotation and first-in-first-out strategy ensures timely response of real-time tasks and reflects the fairness of task scheduling. Specific steps such as preparation before task switching, saving memory context information, and optimizing CPU general register switching are defined in detail to ensure stable and efficient context switching of different types of tasks.
[0080] 3) Resource sharing strategy: A set of flexible resource allocation and sharing strategies is proposed to ensure the effective management of hardware and memory resources. According to the real-time requirements of different devices, the hardware resources managed by the real-time kernel or Linux kernel are flexibly allocated, reducing the problems of resource contention and performance degradation.
[0081] 4) Timer management solution: To avoid clock confusion caused by different interrupt processing orders, the real-time kernel and Linux use the same timer queue for unified management. This simplifies the timer management logic and ensures the consistency and accuracy of the system clock.
Claims
1. A Linux real-time enhancement method based on a domestic real-time kernel, characterized in that: The following steps are involved: The real-time kernel uses the interface of the kernel adaptation layer to access the Linux kernel, and references the header files of the Linux kernel and the external interface provided by the kernel state, so that the real-time kernel and the Linux kernel are designed in parallel in the embedded real-time operating system; The kernel adaptation layer creates corresponding wrappers to encapsulate the header files or external interfaces that reference the Linux kernel; The Linux kernel is preset as the lowest priority within the real-time kernel; In the critical path of the embedded real-time operating system, a hook function is implanted in the real-time core to intercept the request. If the hook function determines that the intercepted request is a real-time task request, it is directly intercepted to the real-time core for processing. Otherwise, it is processed by the Linux kernel. The memory interface vmalloc of the Linux kernel is used to allocate an independent memory pool for the real-time core, and is allocated to the real-time core during the real-time core initialization phase.
2. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The Linux kernel and the real-time core use the same timer queue for event management.
3. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The header file includes Linux kernel data structure, function prototypes and other necessary information.
4. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The external interface provides an access point to Linux kernel services.
5. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The wrapper handles internal conversions, parameter checking, and error handling.
6. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The Linux kernel is responsible for initializing the serial port and the clock module, and the real-time core interacts by calling the encapsulation interface through the kernel adaptation layer.
7. A Linux real-time enhancement method based on a domestic real-time kernel as claimed in claim 1, characterized in that: The real-time core includes a real-time library and a real-time system call, and the Linux kernel includes a non-real-time library and a non-real-time system call; Introduce the task_struct pointer of the Linux kernel into the task control block of the real-time task in the real-time library, so that when switching between the real-time task and the non-real-time task, the switch_to interface of the Linux kernel is used; when the idle task switches to the real-time task, the task_struct pointer of the idle task is updated; Before switching tasks, prepare by switching floating point and SIMD register states, thread local storage (TLS), context ID registers, and user access permissions. Record memory context information during task switching; Save general purpose registers according to register status.
Citation Information
Cited By
Dispensing equipment data management method and device and electronic equipment
CN120909783A
Method for ensuring hard real-time in Linux user mode based on multi-core CPU
CN121187791A
Method for guaranteeing hard real-time in linux user mode based on multi-core cpu
CN121187791B