Preempt_RT-based application real-time automatic optimization method and system
By analyzing the relationship between application soft resources and processes in the Preempt_RT system, dynamically allocating hardware resources and optimizing process configuration, the real-time jitter problem is solved, the system's real-time performance is improved, and business jitter is reduced.
Patent Information
- Application Number
- CN202510765860.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-06-10
AI Technical Summary
Existing technologies cannot automatically analyze the real-time dependencies of applications in the Preempt_RT system, resulting in difficulty in controlling real-time jitter.
By obtaining the soft resources and processes of the specified application, establishing a process relationship set, dynamically allocating hardware resources and process priorities, and combining memory usage and CPU resources, setting the CPU affinity and NUMA node of the process, hardware resource configuration is optimized.
It enables automatic analysis of application dependencies, improves real-time performance under the Preempt_RT system, reduces business operation jitter, and reduces the engineering investment in improving real-time performance.
Smart Images

Figure CN120276870B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a method and system for automatic optimization of application real-time performance based on Preempt_RT. Background Art
[0002] With the development of robotics and autonomous driving technologies, more and more Linux real-time performance requirements are being raised. Although Linux systems can significantly improve the real-time performance of the operating system through the Preempt_RT soft real-time patch (referred to as the Preempt_RT system), improving the real-time performance of the operating system is only the first step. More importantly, is how to deploy applications in the Preempt_RT system in a reasonable and correct manner.
[0003] Typically, ROS and autonomous driving application scenarios involve numerous application dependencies, requiring consideration of numerous factors during application deployment, such as the relationships between CPU, memory, locks, and semaphores. This requires developing a reasonable configuration method to truly reduce application jitter and keep real-time expectations within an acceptable range. Summary of the Invention
[0004] The technical problem to be solved by the present invention is: Currently, there is no technology or method that can automatically analyze the real-time dependencies of applications, thereby reducing the real-time jitter of applications on the Preempt_RT system.
[0005] In response to the above-mentioned problems in the prior art, a method and system for automatic optimization of application real-time performance based on Preempt_RT is provided, which can automatically analyze the dependencies of specified applications and allocate hardware resources in an optimal manner, thereby improving the real-time performance of applications under the Preempt_RT system and reducing the jitter generated by the business during operation as much as possible.
[0006] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0007] A method for automatically optimizing application real-time performance based on Preempt_RT, comprising the following steps:
[0008] S1) Obtain the soft resources of the specified application, then obtain all processes that use the soft resources of the specified application, and recursively establish a process relationship set with the soft resources as the dependency path;
[0009] S2) Obtaining the hard resources corresponding to each process in the process relationship set, setting the priority of the hard resources and the priority of each process in the process relationship set;
[0010] S3) Dynamically allocates exclusive memory areas to processes in the soft resource and process relationship set based on memory usage in real time, dynamically sets the CPU affinity corresponding to each process in the hard resource and process relationship set based on CPU resource availability in real time, and sets the NUMA node where each process in the process relationship set is located based on the soft resource dependency.
[0011] Furthermore, when recursively establishing a process relationship set with soft resources as dependency paths, the following steps are included:
[0012] S11) adding a designated application and all processes using the designated application's soft resources to a process relationship set, and defining all processes using the designated application's soft resources as dependent processes of the designated application, wherein the dependent processes use the used soft resources as a dependency path;
[0013] S12) traverse the newly added dependent processes in the process relationship set, obtain all soft resources of the current process, then obtain all processes that use the soft resources of the current process as dependent processes of the current process, and add all dependent processes of the current process to the process relationship set;
[0014] S13) Jump to step S12 and execute until there are no new dependent processes.
[0015] Furthermore, the hard resources include interrupt handlers, soft interrupts, and work queues. Setting the priority of the hard resources and the priority of each process in the process relationship set includes the following steps:
[0016] S21) Setting the priority of the specified application to the lowest priority;
[0017] S22) setting the priority of the interrupt handler to a high priority range in the first priority range, setting the priority of the soft interrupt to a medium priority range in the first priority range, and setting the priority of the work queue to a low priority range in the first priority range;
[0018] S23) Setting the priority of each process in the process relationship set to be in a second priority interval, where a lower limit of the second priority interval is higher than the lowest priority, and an upper limit of the second priority interval is lower than a lower limit of the first priority interval.
[0019] Furthermore, setting the priority of each process in the process relationship set to be in the second priority range includes:
[0020] If the current process is not a dependent process of other processes, the priority of the current process is the default value. If the current process is a dependent process of other processes, the priority of the current process is greater than the maximum priority of all processes that depend on the current process and less than the upper limit of the second priority range.
[0021] Furthermore, when dynamically allocating exclusive memory areas to processes in the soft resource and process relationship set based on memory usage in real time, the following steps are included:
[0022] Detect the sum of the maximum memory usage of all soft resources of a specified application, and detect the sum of the peak memory usage of all processes in the process relationship set;
[0023] If the available memory is larger than the sum of the maximum memory usage of all soft resources and the sum of the peak memory usage of all processes, then corresponding exclusive memory areas are provided for the soft resources and processes respectively. The size of the exclusive memory area of the soft resource is the sum of the maximum memory usage of all soft resources, and the size of the exclusive memory area of the process is the sum of the peak memory usage of all processes.
[0024] If the available memory is less than the sum of the maximum memory usage of all soft resources and the sum of the peak memory usage of all processes, and is greater than the sum of the peak memory usage of all processes, corresponding exclusive memory areas are provided for the soft resources and processes respectively. The size of the exclusive memory area of the process is the sum of the peak memory usage of all processes, and the size of the exclusive memory area of the soft resource is the remaining size after deducting the exclusive memory area of the process from the available memory.
[0025] If the available memory is less than the sum of the peak memory usage of all processes, a corresponding exclusive memory area is provided for the process, and after the specified application is placed in the exclusive memory area, each process in the process relationship set is placed in the exclusive memory area in descending order of priority until the exclusive memory area is full or the remaining space in the exclusive memory area is less than the size of a single process.
[0026] Furthermore, dynamically setting the CPU affinity corresponding to each process in the hard resource and process relationship set in real time according to the CPU resource situation includes the following steps:
[0027] Reserve a specified number of CPUs as schedulable CPUs and set the remaining CPUs as unschedulable CPUs;
[0028] Set the different tasks corresponding to all processes in each hard resource and process relationship set to the corresponding unschedulable CPU;
[0029] If the different tasks corresponding to all processes in each hard resource and process relationship set are set to the corresponding unschedulable CPUs, the CPU resources are insufficient. Each hard resource is set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs.
[0030] If each hard resource is set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, the CPU resources are insufficient. All hard resources of the same interrupt are set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs.
[0031] If all hard resources of the same interrupt are set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, the CPU resources are insufficient. In this case, all hard resources corresponding to the process relationship set are set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs.
[0032] If all hard resources corresponding to the process relationship set are set to the corresponding unschedulable CPUs, and then the tasks corresponding to all processes are allocated to the remaining unschedulable CPUs, the CPU resources are insufficient. According to the actual business volume, the tasks and hard resources corresponding to the processes with business volume less than the preset threshold are set to the same unschedulable CPU, and the tasks and hard resources corresponding to the processes with business volume greater than the preset threshold are set to different unschedulable CPUs respectively.
[0033] Furthermore, the soft resources include pipes, message queues, shared memory, semaphores, signals, and sockets. When setting the NUMA nodes where each process in the process relationship set is located based on the dependency relationship of the soft resources, it includes: allocating processes whose soft resources are pipes, shared memory, or sockets to the same NUMA node; for processes whose soft resources are message queues, semaphores, or signals, if they cannot be allocated to the same NUMA node, they are allocated to different NUMA nodes.
[0034] The present invention also proposes a Preempt_RT-based application real-time automated optimization system, including a microprocessor and a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the microprocessor executes the computer program to implement the steps of the Preempt_RT-based application real-time automated optimization method.
[0035] The present invention also proposes a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the Preempt_RT-based application real-time automatic optimization method are implemented.
[0036] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method for automatic optimization of application real-time performance based on Preempt_RT.
[0037] Compared with the prior art, the advantages of the present invention are:
[0038] The present invention uses a specified application as an entry point to obtain all its soft resources, and then uses the soft resources to obtain the set of processes that use these soft resources. Using a process in the process set as a new entry point, all its soft resources and the new dependent processes that use the soft resources are obtained to obtain a process dependency set. Through recursive operations, a set of process relationships based on soft resources is established. This achieves automatic analysis of the dependencies of a specified application.
[0039] The present invention obtains the set of hard resources corresponding to each process relationship set, and sets the priority of the hard resources and the priority of each process relationship set according to preset rules. In combination with the priority of the process relationship set and memory usage, it dynamically allocates exclusive memory areas for soft resources and processes in real time, and flexibly allocates hard resources and the CPU affinity of each process according to the CPU resource situation. At the same time, the NUMA node where the process is located is reasonably set according to the dependency relationship of the soft resources, so as to achieve the purpose of allocating hardware resources in an optimal manner. It can combine the characteristics of the hardware itself to achieve the purpose of improving the real-time performance of the application and reducing the jitter of business operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A brief flowchart of an embodiment of the present invention.
[0041] Figure 2 Detailed flowchart of an embodiment of the present invention.
[0042] Figure 3 A topological diagram of a specified application and process relationship set.
[0043] Figure 4 A topology diagram of a specified application, a set of process relationships, and a set of hard resources.
[0044] Figure 5 A topological diagram of a specified application, a set of process relationships, and a set of hard resources after priority is set.
[0045] Figure 6 A topology diagram of a specified application, a process relationship set, and a set of hard resources after setting CPU affinity and NUMA nodes. DETAILED DESCRIPTION
[0046] The present invention will be further described below in conjunction with the accompanying drawings and specific preferred embodiments, but the scope of protection of the present invention is not limited thereby.
[0047] Example 1
[0048] This embodiment proposes a method for automatically optimizing application real-time performance based on Preempt_RT. Based on the Preempt_RT system, the method automatically identifies the dependencies between an application and other applications or threads, and automatically allocates device resources, thereby minimizing the real-time jitter of services caused by other dependent applications.
[0049] like Figure 1 As shown, the method of this embodiment includes the following steps:
[0050] S1) Obtain the soft resources of the specified application, then obtain all processes that use the soft resources of the specified application, and recursively establish a process relationship set with the soft resources as the dependency path;
[0051] S2) Obtaining the hard resources corresponding to each process in the process relationship set, setting the priority of the hard resources and the priority of each process in the process relationship set;
[0052] S3) Dynamically allocates exclusive memory areas to processes in the soft resource and process relationship set based on memory usage in real time, dynamically sets the CPU affinity corresponding to each process in the hard resource and process relationship set based on CPU resource availability in real time, and sets the NUMA node where each process in the process relationship set is located based on the soft resource dependency.
[0053] The following is combined with Figure 2 , and explain the relevant steps in detail.
[0054] In this embodiment, through step S1, a designated application is used as an analysis entry to obtain all the soft resources of the application to form a software resource set, and the soft resources are used as dependency paths to obtain a set of processes that use these soft resources. Then, all processes in the process set are used as analysis entries in turn to recursively establish a complete process relationship set. Figure 2 As shown, step S1 of this embodiment includes the following steps:
[0055] S101) Download a kernel with the Preempt_RT feature and restart the system. This embodiment uses a domestic FT2000+ / 64-core server as the hardware, and the device is installed with the Kylin Advanced Server Operating System V10 system;
[0056] S102) The user selects a specific application APP and uses the specified application APP as the analysis entry point. The system tool (such as lsof) lists the application's soft resource set SRSet, including pipes, message queues, shared memory, semaphores, signals, sockets, etc.
[0057] S103) Using soft resources as a dependency, obtain the set of processes (APPPSet) that use the soft resources in the set SRSet. Specifically, by checking the usage of these soft resources, it is possible to determine which processes are using these resources. For example, by checking the access rights of shared memory, it is possible to find the process that is accessing the shared memory.
[0058] S104) recursively establishing a process relationship set PSet based on soft resources as dependency paths, including the following steps:
[0059] S11) adding the specified application and all processes in the process set APPPSet to a process relationship set, and making all processes in the process set APPPSet dependent processes of the specified application, with the dependent processes using the used soft resources as dependency paths;
[0060] In this embodiment, a process that uses the soft resources of a specified application or a specified process is called a dependent process. For example, if other processes B / C / D use the soft resources of process A, then other processes B / C / D are dependent processes of process A. When processes B / C / D complete certain operations, process A may continue to execute. In this case, processes B / C / D are factors that affect the real-time performance of process A. The execution of process A depends on processes B / C / D to complete their corresponding operations.
[0061] S12) Traverse the newly added dependent processes in the process relationship set to obtain all soft resources of the current process. Then, by checking the usage of the soft resources, obtain all processes that use the soft resources of the current process. When obtaining all the soft resources of the current process, the soft resources of the process are also obtained through system tools such as lsof.
[0062] After obtaining all dependent processes of the current process, all dependent processes of the current process are added to the process relationship set;
[0063] S13) Jump to step S12 and execute until there are no new dependent processes.
[0064] Through the above steps, this embodiment takes all processes in the process set APPPSet as analysis entries in turn, recursively executes steps S12 and S13 to mine dependent processes, and establishes a complete process relationship set PSet={PSet1,...,PSetN}, where PSetN is a process that meets the requirements during the traversal process, that is, the process has a dependent process that uses its soft resources, and the dependent process obtained through each recursion is dependent on the process where the soft resources used by it are located.
[0065] For example, in the first iteration, the soft resources of the process with PID 1 are obtained, and it is found that its soft resources include shared memory segment A.
[0066] Check the usage of shared memory segment A and find that the process with PID 2 uses the shared memory.
[0067] Therefore, add the process with PID 2 to the process relationship set that already includes the process with PID 1, and we get: {1, 2}. The process with PID 1 depends on the process with PID 2, and the shared memory segment A is the dependency path.
[0068] Then, in the second iteration, the soft resources are obtained for the newly added dependent process in the process relationship set {1, 2}, that is, the process with PID 2.
[0069] Assume that the soft resource with PID 2 includes pipe B. When checking the usage of pipe B, it is found that the process with PID 3 is also using the pipe.
[0070] Therefore, we need to add the process with PID 3 to the process relationship set, and obtain: {1, 2, 3}. At this time, the process with PID 2 depends on the process with PID 3, and the pipe B is the dependency path.
[0071] Subsequent iterations continue to analyze the processes in the newly added process relationship set until no new dependent processes are found.
[0072] S105) Create a topology map for the process relationship set. Specifically, create a topology map by linking the specified application APP with other processes in the process relationship set PSet using the soft resource SRSet as a link, such as Figure 3 As shown, the processes PSet1 to PSet7 depend on each other and on the specified application APP in different soft resources.
[0073] In step S2, this embodiment obtains the hardware resources and device information used by all processes in the process relationship set to obtain a hardware resource set, and sets the priority of the hardware resources to determine the priority of the process using the hardware resources. The following steps are included:
[0074] S201) Obtain the hard resources used by all processes in the process relationship set respectively, and obtain the hard resource set HRSet corresponding to each process. Specifically, by using the lsof command, you can see which devices each process uses, and thus obtain the hard resource information corresponding to these devices, including devices, interrupts, interrupt handlers, soft interrupts, work queues, etc., and add a topological diagram of the hard resource set as shown below: Figure 4 As shown;
[0075] S202) Obtaining hardware device information, including a CPU available list, Numa topology, and memory information;
[0076] S203) Setting the priority of the hard resource and the priority of each process in the process relationship set, including the following steps:
[0077] S21) Setting the priority of the designated application APP to the lowest priority, which in this embodiment is FIFO15;
[0078] S22) Setting the priority of the set of hard resources to be within a first priority interval, wherein the priority of the interrupt handler is within a high priority interval within the first priority interval, the priority of the soft interrupt is within a medium priority interval within the first priority interval, and the priority of the work queue is within a low priority interval within the first priority interval.
[0079] In this embodiment, the first priority interval is FIFO [70-99], the high priority interval is FIFO [90-99], the medium priority interval is FIFO [80-89], and the low priority interval is FIFO [70-79]. Therefore, the detailed priority settings of the hard resources are: interrupt handler is set to [90-99], soft interrupt is set to [80-89], and work queue is set to [70-79].
[0080] S23) Setting the priority of each process in the process relationship set to be within a second priority interval, where the lower limit of the second priority interval is higher than the lowest priority, and the upper limit of the second priority interval is lower than the lower limit of the first priority interval. In this embodiment, the second priority interval is FIFO [20-69]. Setting the priority of each process in the process relationship set to be within the second priority interval includes:
[0081] If the current process is not a dependent process of other processes, that is, the current process is a process in the process set APPPSet that uses the soft resources of the specified application, the priority of the current process is the default value 45. If the current process is a dependent process of other processes, the priority of the current process is greater than the maximum priority of all processes that depend on the current process, and less than the upper limit of the second priority range.
[0082] The topology after increasing the priority is as follows Figure 5 As shown in the figure, based on the priority, when an external event reaches the device, the first program executed is the interrupt handler, followed by the soft interrupt, and then the work queue. After the above three are completed, the data will be transmitted to the specified application through the process relationship set. All processes in the process relationship set execute operations in order from high to low priority. Before the processes in the low-priority process relationship set execute related operations, they need to wait for the processes in the high-priority process relationship set to execute the corresponding operations. Finally, after the related operations of all processes are completed, the operations of the specified application are executed.
[0083] This embodiment detects the memory usage of all software resource sets in step S3, prioritizes exclusive memory access for the client-specified application APP, and also sets the CPU affinity of all processes in the process set based on the hardware NUMA status and memory usage. Specifically, the following steps are included:
[0084] S301) Dynamically allocating exclusive memory areas to processes in the soft resource and process relationship set in real time based on memory usage to set memory for each process, including the following steps:
[0085] Detect the maximum sum of memory usage of all soft resources in the set of soft resources of the specified application, specifically the maximum sum of memory usage of all pipelines, message queues, and shared memories in the set of soft resources SRSet (SumSRMem);
[0086] Detect the sum of the peak memory usage SumPMem of all processes in the process relationship set;
[0087] If the device memory is sufficient, exclusive memory areas are provided for SumPMem and SumSRMem. Specifically, if the available memory is greater than the sum of SumPMem and SumSRMem, corresponding exclusive memory areas are provided for soft resources and processes respectively. The size of the exclusive memory area for soft resources is the sum of the maximum memory usage of all soft resources (SumPMem), and the size of the exclusive memory area for processes is the sum of the peak memory usage of all processes (SumSRMem).
[0088] If the memory is insufficient, SumPMem is given priority. Specifically, if the available memory is less than the sum of SumPMem and SumSRMem, and greater than the sum of the peak memory usage of all processes (SumPMem), corresponding exclusive memory areas are provided for soft resources and processes respectively. The size of the exclusive memory area of the process is the sum of the peak memory usage (SumPMem) of all processes, and the size of the exclusive memory area of the soft resource is the remaining size after deducting the exclusive memory area of the process from the available memory.
[0089] If the memory cannot meet SumPMem, the specified application APP will be given priority, and then the process with higher priority will be considered. Specifically, if the available memory is less than the sum of the peak memory usage of all processes SumPMem, a corresponding exclusive memory area will be provided for the process, and after the specified application APP is placed in the exclusive memory area, each process in the process relationship set will be placed in the exclusive memory area in descending order of priority until the exclusive memory area is full or the remaining space in the exclusive memory area is less than the size of a single process.
[0090] S302) Dynamically setting the CPU affinity corresponding to each process in the hard resource and process relationship set in real time based on the CPU resource situation, and setting the NUMA node where each process in the process relationship set is located based on the soft resource dependency, so as to set the NUMA node and CPU affinity of each process, including the following steps:
[0091] Reserve a specified number of CPUs as schedulable CPUs and set the remaining CPUs as non-schedulable CPUs. Specifically, in this embodiment, 1-4 CPUs are reserved as Linux schedulable CPUs, namely SCPUSet, and the remaining CPUs are set as non-schedulable CPUs, namely ISCPUSet;
[0092] If the number of CPUs is sufficient, set the interrupt handlers, soft interrupts, and work queues of the hard resource set HRSet to different CPUs in ISCPUSet, and set the different tasks corresponding to each process in the process relationship set PSet to different CPUs in ISCPUSet. Specifically, if the number of unschedulable CPUs is greater than the number of CPUs required to set the different tasks corresponding to each hard resource and all processes in the process relationship set to the corresponding unschedulable CPUs, then set each hard resource and each task to the corresponding unschedulable CPU.
[0093] If the number of CPUs is insufficient, the CPU resources of HRSet are guaranteed first. Specifically, if the different tasks corresponding to all processes in each hard resource and process relationship set are set to the corresponding unschedulable CPUs, the CPU resources are insufficient, that is, the number of unschedulable CPUs is less than the number of CPUs required to set the different tasks corresponding to all processes in each hard resource and process relationship set to the corresponding unschedulable CPUs, but greater than the number of CPUs required to set each hard resource to the corresponding unschedulable CPU, and then allocate the tasks corresponding to all processes to the remaining unschedulable CPUs. Set each hard resource to the corresponding unschedulable CPU, and then allocate the tasks corresponding to all processes to the remaining unschedulable CPUs.
[0094] If the CPU resources are still insufficient, you can consider setting the interrupt handler, soft interrupt, and work queue of the same interrupt to the same CPU to ensure that different interrupts are on different CPUs. Specifically, if each hard resource is set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, the CPU resources are insufficient, but greater than the number of CPUs required to set all hard resources of the same interrupt to the corresponding unschedulable CPU, and then assign the tasks corresponding to all processes to the remaining unschedulable CPUs. Set all hard resources of the same interrupt to the corresponding unschedulable CPU, and then assign the tasks corresponding to all processes to the remaining unschedulable CPUs.
[0095] If the CPU resources are still insufficient, the HRSet used by PSet can be considered on the same CPU. Specifically, if all hard resources of the same interrupt are set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, the CPU resources are insufficient, but greater than the number of CPUs required to set all hard resources corresponding to the process relationship set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs. In this case, all hard resources corresponding to the process relationship set are set to the corresponding unschedulable CPU, and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs.
[0096] If the CPU resources are still insufficient, the processes with small business volumes and HRSets can be set to the same CPU based on the actual business volume. Specifically, if all the hard resources corresponding to the process relationship set are set to the corresponding unschedulable CPUs, and then the tasks corresponding to all processes are allocated to the remaining unschedulable CPUs, the CPU resources are insufficient. According to the actual business volume, the tasks and hard resources corresponding to the processes with business volumes less than the preset threshold are all set to the same unschedulable CPU, and the tasks and hard resources corresponding to the processes with business volumes greater than the preset threshold are set to different unschedulable CPUs respectively.
[0097] Allocate processes whose soft resources are pipes, shared memory, or sockets to the same NUMA node. For processes whose soft resources are message queues, semaphores, or signals, if they cannot be allocated to the same NUMA node, allocate them to different NUMA nodes.
[0098] After the above steps, the topology diagram after setting NUMA node and CPU affinity for each process is as follows Figure 6 As shown, flexible allocation of CPU resources and reasonable setting of the NUMA node where the process is located are achieved.
[0099] Example 2
[0100] This embodiment proposes a system for automatic optimization of application real-time performance based on Preempt_RT, including a microprocessor and a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the microprocessor executes the computer program to implement the steps of the method for automatic optimization of application real-time performance based on Preempt_RT described in Example 1.
[0101] This embodiment further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the method for automatic optimization of application real-time performance based on Preempt_RT described in the first embodiment are implemented.
[0102] This embodiment further provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the method for automatic optimization of application real-time performance based on Preempt_RT described in the first embodiment are implemented.
[0103] In summary, the present invention proposes a Preempt_RT-based automated application real-time optimization method and system. Using the Preempt_RT system as the foundational environment, this method enables a Linux system supporting Preempt_RT to, by specifying an application (APP) as the entry point, obtain its soft resource SRSet, including pipelines, and then, using the soft resources, obtain the process set APPPSet that uses these resources. Through recursive operations, a complete process relationship set (PSet) is established using the processes in the APPPSet as new entry points, and a topology diagram of the APP and PSet is generated based on the SRSet. This enables automatic analysis of the dependencies of customer-specified applications. Furthermore, the present invention obtains the hard resource HRSet, including devices, used by processes in the PSet set, as well as hardware device information, and sets the priority of processes using hardware resources according to established rules. The memory usage of the SRSet and PSet is detected, and exclusive memory areas are allocated to them based on the device memory status. Reserving some CPUs as Linux-schedulable CPUs, assigning tasks in HRSet and PSet to unschedulable CPUs, and flexibly allocating them based on CPU resource availability. Furthermore, based on soft resource dependencies, the NUMA nodes where processes in the PSet reside are appropriately assigned. By combining hardware characteristics, this improves application real-time performance and reduces operational jitter, thus eliminating the need for experienced engineers or even software experts to invest in real-time performance improvements and ultimately reducing software R&D costs.
[0104] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiment. All technical solutions based on the concept of the present invention are within the scope of protection of the present invention. It should be noted that for those skilled in the art, various improvements and modifications that do not depart from the principles of the present invention should also be considered within the scope of protection of the present invention.
Claims
1. A method for automatic optimization of application real-time performance based on Preempt_RT, characterized in that: The following steps are involved: S1) obtaining the soft resources of a specified application, including pipes, message queues, shared memory, semaphores, signals, and sockets, then obtaining all processes that use the soft resources of the specified application, and recursively establishing a set of process relationships that use the soft resources as a dependency path; S2) obtaining hard resources used by each process in the process relationship set, the hard resources including interrupt handlers, soft interrupts, and work queues, setting priorities for the hard resources and the priorities for each process in the process relationship set; and executing the hard resources and processes according to the priorities for the hard resources and the priorities for each process in the process relationship set; S3) Dynamically allocate exclusive memory areas to processes in the soft resource and process relationship set based on memory usage in real time, dynamically set the CPU affinity corresponding to each process in the hard resource and process relationship set based on CPU resource availability in real time, and set the NUMA node where each process in the process relationship set is located based on the soft resource dependency, including: allocating processes whose soft resources are pipes, shared memory, or sockets to the same NUMA node; and allocating processes whose soft resources are message queues, semaphores, or signals to different NUMA nodes if they cannot be allocated to the same NUMA node.
2. The method for automatic optimization of application real-time performance based on Preempt_RT according to claim 1, characterized in that: When recursively establishing a set of process relationships with soft resources as dependencies, the following steps are included: S11) Add the specified application and all processes using the specified application's soft resources to a process relationship set. All processes using the specified application's soft resources are defined as dependent processes of the specified application, with the dependent processes using the used soft resources as their dependency path. Processes using the specified application's soft resources or the specified process's soft resources are defined as dependent processes. If other processes B / C / D use process A's soft resources, then these other processes are considered dependent processes of process A. Process A can only continue execution after processes B / C / D complete certain operations. S12) traverse the newly added dependent processes in the process relationship set, obtain all soft resources of the current process, then obtain all processes that use the soft resources of the current process as dependent processes of the current process, and add all dependent processes of the current process to the process relationship set; S13) Jump to step S12 and execute until there are no new dependent processes.
3. The method for automatic optimization of application real-time performance based on Preempt_RT according to claim 2, characterized in that: Setting the priority of hard resources and the priority of each process in the process affinity set involves the following steps: S21) Setting the priority of the specified application to the lowest priority; S22) setting the priority of the interrupt handler to a high priority range in the first priority range, setting the priority of the soft interrupt to a medium priority range in the first priority range, and setting the priority of the work queue to a low priority range in the first priority range; S23) Setting the priority of each process in the process relationship set to be in a second priority interval, where a lower limit of the second priority interval is higher than the lowest priority, and an upper limit of the second priority interval is lower than a lower limit of the first priority interval.
4. The method for automatic optimization of application real-time performance based on Preempt_RT according to claim 3, characterized in that: When setting the priority of each process in the process relationship set to be in the second priority interval, including: If the current process is not a dependent process of other processes, the priority of the current process is the default value. If the current process is a dependent process of other processes, the priority of the current process is greater than the maximum priority of all processes that depend on the current process and less than the upper limit of the second priority range.
5. The method for automatic optimization of application real-time performance based on Preempt_RT according to claim 1, characterized in that: When an exclusive memory area is dynamically allocated to a process in a soft resource and process relationship set based on memory usage in real time, the following steps are included: Detect the sum of the maximum memory usage of all soft resources of a specified application, and detect the sum of the peak memory usage of all processes in the process relationship set; If the available memory is larger than the sum of the maximum memory usage of all soft resources and the sum of the peak memory usage of all processes, then corresponding exclusive memory areas are provided for the soft resources and processes respectively. The size of the exclusive memory area of the soft resource is the sum of the maximum memory usage of all soft resources, and the size of the exclusive memory area of the process is the sum of the peak memory usage of all processes. If the available memory is less than the sum of the maximum memory usage of all soft resources and the sum of the peak memory usage of all processes, and is greater than the sum of the peak memory usage of all processes, corresponding exclusive memory areas are provided for the soft resources and processes respectively. The size of the exclusive memory area of the process is the sum of the peak memory usage of all processes, and the size of the exclusive memory area of the soft resource is the remaining size after deducting the exclusive memory area of the process from the available memory. If the available memory is less than the sum of the peak memory usage of all processes, the specified application is given priority, and then the process with higher priority is considered; a corresponding exclusive memory area is provided for the process, and after the specified application is placed in the exclusive memory area, each process in the process relationship set is placed in the exclusive memory area in descending order of priority until the exclusive memory area is full or the remaining space in the exclusive memory area is less than the size of a single process.
6. The method for automatic optimization of application real-time performance based on Preempt_RT according to claim 1, characterized in that: When dynamically setting the CPU affinity corresponding to each process in the hard resource and process relationship set according to the CPU resource situation in real time, the following steps are included: Reserve a specified number of CPUs as schedulable CPUs and set the remaining CPUs as unschedulable CPUs; If the number of unschedulable CPUs is greater than the number of CPUs required to assign different tasks corresponding to all processes in each set of hard resource and process relationships to the corresponding unschedulable CPUs, then assign different tasks corresponding to all processes in each set of hard resource and process relationships to the corresponding unschedulable CPUs. If the CPU resources are insufficient when all the different tasks corresponding to all the processes in each set of hard resource and process relationships are assigned to the corresponding unschedulable CPUs, that is, the number of unschedulable CPUs is less than the number of CPUs required to assign all the different tasks corresponding to all the processes in each set of hard resource and process relationships to the corresponding unschedulable CPUs, but is greater than the number of CPUs required to assign all the hard resources to the corresponding unschedulable CPUs and then distribute the tasks corresponding to all the processes to the remaining unschedulable CPUs, then each hard resource is assigned to the corresponding unschedulable CPU and then distribute the tasks corresponding to all the processes to the remaining unschedulable CPUs. If each hard resource is assigned to the corresponding unschedulable CPU and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, and the CPU resources are insufficient, but the number of CPUs is greater than the number of CPUs required when all hard resources for the same interrupt are assigned to the same unschedulable CPU and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, then all hard resources for the same interrupt are assigned to the same unschedulable CPU and then the tasks corresponding to all processes are assigned to the remaining unschedulable CPUs. If all hard resources of the same interrupt are set to the same unschedulable CPU and then tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, the CPU resources are insufficient, but the number of CPUs is greater than the number of CPUs required when all hard resources corresponding to the process relationship set are set to the same unschedulable CPU and then tasks corresponding to all processes are assigned to the remaining unschedulable CPUs, then all hard resources corresponding to the process relationship set are set to the same unschedulable CPU and then tasks corresponding to all processes are assigned to the remaining unschedulable CPUs. If all hard resources corresponding to the process relationship set are set to the same unschedulable CPU, and then the tasks corresponding to all processes are allocated to the remaining unschedulable CPUs, the CPU resources are insufficient. According to the actual business volume, the tasks and hard resources corresponding to the processes with business volume less than the preset threshold are set to the same unschedulable CPU, and the tasks and hard resources corresponding to the processes with business volume greater than the preset threshold are set to different unschedulable CPUs.
7. A real-time automatic optimization system for applications based on Preempt_RT, characterized in that: The method comprises a microprocessor and a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the microprocessor executes the computer program to implement the steps of the Preempt_RT-based application real-time automatic optimization method according to any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps of the Preempt_RT-based application real-time automatic optimization method according to any one of claims 1 to 6 are implemented.
9. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the steps of the method for automatic optimization of application real-time performance based on Preempt_RT according to any one of claims 1 to 6.
Citation Information
Patent Citations
Application program processing method and device, electronic equipment and computer readable storage medium
CN109992369A
Linux server multi-application process scheduling method based on shared memory
CN115629827A