Method for improving real-time performance of OpenEuler + Apoll under RISC-V architecture
By adapting to Preempt_RT patch and optimizing the CyberRT communication framework, the problem that the Linux kernel cannot obtain real-time under the RISC-V architecture is solved, the real-time performance of the OpenEuler+Apollo system is improved, and the real-time requirements of intelligent driving scenarios are met.
Patent Information
- Application Number
- CN202411100606.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-11-29
AI Technical Summary
The Linux kernel under the RISC-V architecture cannot obtain real-time performance and is difficult to meet the requirements of real-time performance in intelligent driving scenarios, especially in vehicle-road-cloud collaboration scenarios.
By loading and adapting Preempt_RT patches to the Linux kernel under the RISC-V architecture, and enabling the CyberRT communication framework in the OpenEuler operating system, we optimize task scheduling policies and thread priorities to achieve real-time performance testing.
It improves the real-time performance of the OpenEuler+Apollo system under the RISC-V architecture, meets real-time performance testing indicators, and ensures the stable operation of the system in intelligent driving scenarios.
Smart Images

Figure CN119045964A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of processor core optimization, and in particular to a method for improving the real-time performance of OpenEuler+Apollo under a RISC-V architecture. Background Art
[0002] With the development of technology, driverless technology is becoming more and more mature. To ensure that driverless cars can run stably, a high real-time system is essential. Now, the Linux kernel can be modified through the Preempt_RT patch to make it real-time, but only in the X86 architecture and ARM64 architecture, the Linux kernel can obtain the characteristics of the real-time kernel by loading the PREEMPT_RT patch. This patch is not applicable to the Linux kernel under the RISC-V architecture.
[0003] At present, embedded hardware under the RISC-V architecture can only provide non-real-time kernels using the Linux kernel. In intelligent driving scenarios, it is difficult to meet the real-time requirements of the system, especially for vehicle-road-cloud collaboration scenarios, which have high requirements for the real-time performance of the vehicle side. The task scheduling delay of the non-real-time kernel used by OpenEuler has uncertainty, and there is room for optimization in real-time. Summary of the invention
[0004] The present invention provides a method for improving the real-time performance of OpenEuler+Apollo under the Riscv architecture. The present invention provides the following technical solutions:
[0005] A method for improving the real-time performance of OpenEuler+Apollo under RISC-V architecture, the method comprising:
[0006] Step 1. Build the OpenEulerRiscv operating system based on the RISC-V architecture, load the Apollo platform in the OpenEulerRiscv operating system, and enable the CyberRT communication framework in the Apollo platform;
[0007] Step 2. Obtain and load the Preempt_RT patch corresponding to the Linux kernel version in the OpenEulerRiscv operating system, adapt and compile the Preempt_RT patch based on the Linux kernel under the RISC-V architecture, and inject the Preempt_RT patch into the Linux kernel, changing the Linux kernel to the Preempt_RT kernel adapted to the RISC-V architecture;
[0008] Step 3: Run the OpenEulerRiscv operating system based on the Preempt_RT kernel, monitor and optimize the tasks in the CyberRT communication framework in real time, refer to the running status of the tasks in the Preempt_RT kernel, use the corresponding general interface on the Preempt_RT kernel to create threads and customize the priority and scheduling strategy;
[0009] Step 4: Introduce a real-time performance test set tool for testing real-time performance into the OpenEulerRiscv operating system, and test the real-time performance of the system by running the real-time performance test set tool. If the real-time test indicators are met, it is confirmed that the kernel obtains the required real-time performance.
[0010] Furthermore, the adaptation and compilation of the Preempt_RT patch in step 2 further includes the following steps:
[0011] Step 21, load the Preempt_RT patch into the Linux kernel based on the RISC-V architecture, and obtain the upgraded Preempt_RT patch P2 after adaptation and compilation;
[0012] Step 22: Adapt and debug the upgraded Preempt_RT patch P2 according to the RISC-V architecture to obtain the patch package P3;
[0013] Step 23. Obtain a tool chain that matches the RISC-V architecture and install it into the Linux kernel. Modify the Linux environment variables to the RISC-V architecture, complete the settings of the Linux kernel cross-compilation environment, ensure that the compilation environment supports the RISC-V architecture, and load the compilation patch package P3.
[0014] Step 24: Introduce a configuration tool for modifying the Linux kernel configuration file, and run the configuration tool to enable the Fully Preemptible Kernel option in the Linux kernel configuration file, complete the configuration of patch package P3, and optimize the scheduler according to the configuration of patch package P3, and change the Linux kernel to the final Preempt_RT kernel.
[0015] Furthermore, the compilation and adaptation of the Preempt_RT patch involves:
[0016] Non-preemptive mechanism for some locks: By changing the configuration files of some locks and testing the adaptability of the locks to the RISC-V architecture, the non-preemptive state of some locks in memory is modified;
[0017] Priority inheritance: Implement priority inheritance by testing and improving the interaction method of mutexes compiled to adapt to the RISC-V architecture;
[0018] Printk threading: By adding one or more dedicated threads in the Linux kernel and redirecting the printk function, the result of the printk function is forwarded to the dedicated thread to achieve printk threading;
[0019] lazy_preempt function: introduce the TIF_NEED_RESCHED_LAZY flag and lazy_preempt_count variable to the RISC-V architecture and update the scheduler of the RISC-V architecture to ensure that the lazy_preempt function can be applied to SCHED_OTHER class processes, completing the addition of the lazy_preempt function;
[0020] Interrupt threading: adapt and compile the interrupt controller to the RISC-V architecture, and test whether the interrupt controller supports interrupt generation and routing;
[0021] Furthermore, the optimization of the tasks in the CyberRT communication framework in step 3 further includes the following steps:
[0022] Step 31: Run the OpenerEulerRiscv operating system and monitor the running status of tasks in the CyberRT communication framework in real time;
[0023] Step 32: Based on the task running status obtained after monitoring the CyberRT communication framework, referring to the urgency and priority of the CRoutine work and the orchestration task in the CyberRT communication framework, the priority and core of the task in the CyberRT communication framework are determined through corresponding strategies.
[0024] Furthermore, the CyberRT communication framework provides a Scheduler Classic strategy and a Scheduler Choreography strategy, and the priority of tasks and the determination of cores in the CyberRT communication framework are based on the Scheduler Classic strategy or the Scheduler Choreography strategy.
[0025] In the present invention, by adapting and modifying the Preempt_RT patch, it is ensured that the Preempt_RT patch can adapt to the Linux kernel in the OpenEulerRiscv operating system under the RISC-V architecture, and complete the adaptation to meet the requirements of the real-time kernel, so as to improve the real-time characteristics of the OpenEuler+Apollo architecture. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is the overall structural diagram of the present invention;
[0027] Figure 2 It is a schematic diagram of the Linux kernel in the present invention;
[0028] Figure 3 It is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0029] The embodiments of the present invention are described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0030] In the description of the embodiments of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms, "connection" and "installation" should be understood in a broad sense. For example, "connection" can be a detachable connection or a non-detachable connection; it can be a direct connection or an indirect connection through an intermediate medium. In addition, "connection" can be a direct connection or an indirect connection through an intermediate medium. Among them, "fixed" means that they are connected to each other and the relative position relationship after connection remains unchanged. The directional terms mentioned in the embodiments of the present invention, such as "inside", "outside", "top", "bottom", etc., are only reference to the directions of the accompanying drawings. Therefore, the directional terms used are for better and clearer explanation and understanding of the embodiments of the present invention, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the embodiments of the present invention.
[0031] In the embodiments of the present invention, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.
[0032] In the embodiments of the present invention, "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0033] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present invention. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0034] Example:
[0035] A method for improving the real-time performance of OpenEuler+Apollo under the RISC-V architecture provided by the present invention mainly includes:
[0036] Figure 1 Shows the overall structure of the system. Figure 2 shows the overall structure of the Linux kernel, Figure 3 The system building steps are shown.
[0037] Step 1: Build the OpenEulerRiscv operating system based on the RISC-V architecture, where the RISC-V architecture is mounted on the visionfive2 board, and the OpenEulerRiscv operating system is loaded into the visionfive2 through external memory. The OpenEulerRiscv operating system is an OpenEuler operating system adapted to the RISC-V architecture, and the Apollo platform is loaded into the OpenEulerRiscv operating system. The Apollo platform is an open platform that supports the autonomous driving technology of smart cars. And enable the CyberRT communication framework in the Apollo platform;
[0038] Step 2. Obtain and load the Preempt_RT patch corresponding to the Linux kernel version in the OpenEulerRiscv operating system, adapt and compile the Preempt_RT patch based on the Linux kernel under the RISC-V architecture, and inject the Preempt_RT patch into the Linux kernel, changing the Linux kernel to the Preempt_RT kernel adapted to the RISC-V architecture;
[0039] Step 3: Based on the operation of the OpenEulerRiscv operating system that has completed the kernel upgrade, monitor the tasks in the CyberRT communication framework in real time and optimize them. At the same time, refer to the running status of the tasks in the Preempt_RT kernel, create threads on the corresponding general interface of the Preempt_RT kernel and customize the priority and scheduling strategy;
[0040] Step 4: Introduce a real-time performance test set tool for testing real-time performance into the OpenEulerRiscv operating system, and test the real-time performance of the system by running the real-time performance test set tool. If the real-time test indicators are met, it is confirmed that the kernel obtains the required real-time performance.
[0041] Advantageously, adaptive compilation of the Preempt_RT patch based on the RISC-V architecture mainly includes:
[0042] Load the Preempt_RT patch into the Linux kernel based on the RISC-V architecture, compile and adapt to obtain the upgraded Preempt_RT patch, set up the cross-compilation environment, where the cross-compilation environment selects the tool chain that matches the RISC-V architecture and modifies the environment variables to the RISC-V architecture, then introduces the configuration tool and runs the kernel configuration menu. The kernel configuration menu tool run here can use make menuconfig. By using the make menuconfig configuration modification tool, open the Fully Preemptible The Kernel option completes the final configuration of the kernel real-time performance. Then, by compiling the Preempt_RT patch into the Linux kernel and changing the Linux kernel to the Preempt_RT kernel, the compile- ed Preempt_RT kernel is tested for compatibility under the RISC-V architecture and the running status of the Preempt_RT kernel is checked. The functions compiled into the Linux kernel here mainly include the non-preemptive mechanism of some locks, priority inheritance, Printk threading, adding lazy_preempt function and interrupt threading. Among them, the non-preemptive mechanism of some locks mainly refers to the rtmutex, spinlock and other locks that are often in a non-preemptive state when running. Therefore, the configuration files of these locks are modified. After the modification, the adaptability test under the RISC-V architecture is carried out to further improve the real-time performance of the Linux kernel under the RISC-V architecture. Priority inheritance is achieved by adding a specially designed real-time mutex to the RISC-V architecture to ensure RISC-V The low-priority tasks under the C-V architecture inherit the priority of the high-priority tasks to complete the tasks. Furthermore, for the tasks in the CyberRT communication framework, priority inheritance can ensure that the low-priority tasks holding the same mutex as the tasks in the CyberRT communication framework can temporarily inherit the priority of the tasks in the CyberRT communication framework to complete the tasks, and release the mutex to the tasks in the CyberRT communication framework, which can effectively improve the real-time performance of the CyberRT communication framework; Printk threading is to add one or more dedicated threads in the Linux kernel and redirect the Printk function to ensure that the result value of the Printk function will be forwarded to the dedicated thread, which will not affect the threads of the Linux kernel and can also ensure the real-time performance of the Linux kernel. For the RISC-V architecture, further adaptation is required to ensure that the RISC-V architecture can well complete the increase of threads and can well redirect the Printk function, so as to realize the threading of the Printk function based on the RISC-V architecture;The lazy_preempt function, by introducing the TIF_NEED_RESCHED_LAZY flag and lazy_preempt_count variable and applying them to the SCHED_OTHER class process, controls the preemption mechanism of the SCHED_OTHER class process and improves the real-time performance of the Linux kernel. If the lazy_preempt function is to be added based on the RISC-V architecture, the TIF_NEED_RESCHED_LAZY flag and lazy_preempt_count variable need to be adapted and the scheduler of the RISC-V architecture needs to be optimized and adapted to ensure that the method can be fully implemented; interrupt threading, interrupt threading is implemented by dividing the interrupt function and updating the interrupt descriptor. The implementation of the interrupt threading function based on the RISC-V architecture needs to consider whether request_threaded_irq is adapted to the RISC-V architecture and needs to make corresponding adaptive compilation to ensure that the interrupt threading can be fully used; and after completing the addition and modification of the above functions, the overall scheduler needs to be modified to ensure that the Preempt_RT patch based on RISC-V can be better adapted and play a role. ;
[0043] After completing the Preempt_RT patch upgrade of the Linux kernel, it is necessary to consider the real-time performance of the tasks in the CyberRT communication framework.
[0044] Advantageously, after the upgrade is completed, it is necessary to monitor the operation status in the CyberRT communication framework in real time and modify the priority and optimize the scheduling model. The operation status refers to the urgency and priority of the CRoutine work and the orchestration task. According to the above situation, the priority and core allocation are completed to ensure the most reasonable utilization of CPU resources in the scenario. At the same time, the real-time performance of each task and CRoutine work is guaranteed.
[0045] Advantageously, based on the above monitoring of the real-time tasks of the CyberRT communication framework, the real-time performance of the CyberRT communication framework and the Preempt_RT kernel can be effectively improved by selecting two scheduling strategies, SchedulerClassic and Scheduler Choreography;
[0046] Scheduler Classic: This strategy can be selected for tasks in the CyberRT communication framework that do not require strict periodic execution or do not have particularly high real-time requirements. This strategy is usually used for background services or non-critical computing tasks. These tasks can run when the system is idle, or be scheduled for execution after meeting certain conditions, ensuring that non-critical computing tasks in the CyberRT communication framework do not occupy too many threads.
[0047] Scheduler Choreography: When the CyberRT communication framework has high real-time requirements, it will give priority to this strategy, which emphasizes the periodicity and real-time nature of task execution. This strategy is suitable for key tasks in autonomous driving systems, such as sensor data processing and control algorithm execution, which need to be completed within a fixed time interval to ensure the safety and stable operation of the vehicle.
[0048] Advantageously, after the CyberRT communication framework completes the selection of the task scheduling strategy, the system will create threads based on the CyberRT communication framework's tasks and the Preempt_RT kernel tasks through the Preempt_RT kernel common interface, and set the thread priority and scheduling strategy to ensure that the tasks in the CyberRT communication framework can be processed by the technology, thereby improving the overall real-time performance.
[0049] Advantageously, after the system is debugged, the real-time performance needs to be tested. The test tool is the real-time performance test set rt-test (cyclictest and hackbench), which tests the real-time performance of the system. The test results show that the maximum scheduling delay of the real-time thread can be controlled within 100us. Hackbench is a program that simulates the load.
[0050] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention; the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A method for improving the real-time performance of OpenEuler+Apollo under RISC-V architecture, characterized in that: The method comprises: Step 1. Build the OpenEulerRiscv operating system based on the RISC-V architecture, load the Apollo platform in the OpenEulerRiscv operating system, and enable the CyberRT communication framework in the Apollo platform; Step 2. Obtain and load the Preempt_RT patch corresponding to the Linux kernel version in the OpenEulerRiscv operating system, adapt and compile the Preempt_RT patch based on the Linux kernel under the RISC-V architecture, and inject the Preempt_RT patch into the Linux kernel, changing the Linux kernel to the Preempt_RT kernel adapted to the RISC-V architecture; Step 3: Run the OpenEulerRiscv operating system based on the Preempt_RT kernel, monitor and optimize the tasks in the CyberRT communication framework in real time, refer to the running status of the tasks in the Preempt_RT kernel, use the corresponding general interface on the Preempt_RT kernel to create threads and customize the priority and scheduling strategy; Step 4: Introduce a real-time performance test set tool for testing real-time performance into the OpenEulerRiscv operating system, and test the real-time performance of the system by running the real-time performance test set tool. If the real-time test indicators are met, it is confirmed that the kernel obtains the required real-time performance.
2. The method for improving the real-time performance of OpenEuler+Apollo under the RISC-V architecture according to claim 1, characterized in that: The adaptation and compilation of the Preempt_RT patch in step 2 further includes the following steps: Step 21, load the Preempt_RT patch into the Linux kernel based on the RISC-V architecture, and obtain the upgraded Preempt_RT patch P2 after adaptation and compilation; Step 22: Adapt and debug the upgraded Preempt_RT patch P2 according to the RISC-V architecture to obtain the patch package P3; Step 23. Obtain a tool chain that matches the RISC-V architecture and install it into the Linux kernel. Modify the Linux environment variables to the RISC-V architecture, complete the settings of the Linux kernel cross-compilation environment, ensure that the compilation environment supports the RISC-V architecture, and load the compilation patch package P3. Step 24: Introduce a configuration tool for modifying the Linux kernel configuration file, and run the configuration tool to enable the Fully Preemptible Kernel option in the Linux kernel configuration file, complete the configuration of patch package P3, and optimize the scheduler according to the configuration of patch package P3, and change the Linux kernel to the final Preempt_RT kernel.
3. The method for improving the real-time performance of OpenEuler+Apollo under the RISC-V architecture according to claim 2 is characterized in that: Compilation and adaptation of the Preempt_RT patch involves: Non-preemptive mechanism for some locks: By changing the configuration files of some locks and testing the adaptability of the locks to the RISC-V architecture, the non-preemptive state of some locks in memory is modified; Priority inheritance: Implement priority inheritance by testing and improving the interaction method of mutexes compiled to adapt to the RISC-V architecture; Printk threading: By adding one or more dedicated threads in the Linux kernel and redirecting the printk function, the result of the printk function is forwarded to the dedicated thread to achieve printk threading; lazy_preempt function: introduce the TIF_NEED_RESCHED_LAZY flag and lazy_preempt_count variable to the RISC-V architecture and update the scheduler of the RISC-V architecture to ensure that the lazy_preempt function can be applied to SCHED_OTHER class processes, completing the addition of the lazy_preempt function; Interrupt threading: Adapt the interrupt controller to the RISC-V architecture and test whether the interrupt controller supports interrupt generation and routing.
4. The method for improving the real-time performance of OpenEuler+Apollo under the RISC-V architecture according to claim 1, characterized in that: The optimization of the tasks in the CyberRT communication framework in step 3 further includes the following steps: Step 31: Run the OpenerEulerRiscv operating system and monitor the running status of tasks in the CyberRT communication framework in real time; Step 32: Based on the task running status obtained after monitoring the CyberRT communication framework, referring to the urgency and priority of the CRoutine work and the orchestration task in the CyberRT communication framework, the priority and core of the task in the CyberRT communication framework are determined through corresponding strategies.
5. The method for improving the real-time performance of OpenEuler+Apollo under the RISC-V architecture according to claim 4 is characterized in that: The CyberRT communication framework provides the Scheduler Classic strategy and the Scheduler Choreography strategy, and the priority of tasks and the determination of cores in the CyberRT communication framework are based on the Scheduler Classic strategy or the Scheduler Choreography strategy.
Citation Information
Cited By
PreemptRT-based system optimization method and device and medium
CN119225943A
Multi-system real-time system performance evaluation method based on rk3568
CN119847892A
