A testing method for measuring the real-time performance of the Linux system
By building kernel modules and testing tools, combining data interaction between kernel and user mode, the shortcomings of existing Linux system real-time testing tools are solved, and more accurate and comprehensive real-time testing is achieved.
Patent Information
- Application Number
- CN202211743406.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-12-30
AI Technical Summary
Existing Linux system real-time testing tools such as Cyclictest and Ftrace have problems such as few simulation processes, simple data reflections, large extra time overhead, complex operation, not intuitive enough data, and insufficient integration.
Build a dedicated kernel module and testing tool, conduct real-time simulation tests in the kernel state through the kernel module, combine the kernel state and user state for data interaction, fine-grained test points are carried out in the kernel module, coarse-grained test points are carried out in the user state, and data is obtained and feedbacked using tracer technology and proc file system, time stamp statistics and calculations are carried out, and real-time data that users care about are output.
It reduces time loss, improves the accuracy of test results, enriches test indicators, and provides more comprehensive real-time testing of Linux systems.
Smart Images

Figure CN116302945B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and particularly relates to a test method for measuring the real-time performance of a Linux system. Background Art
[0002] As a leading open-source system, the Linux system has a very wide range of application scenarios. The origin of the Linux system was a user-interactive system without any consideration of real-time performance. However, as the open-source Linux system became increasingly popular, the Linux system obtained a kernel patch for real-time optimization. As a result, the Linux system kernel can become a real-time system kernel. The Linux system improves its real-time performance by patching the Linux kernel to meet the real-time requirements of most scenarios. The real-time performance of an operating system is a relatively abstract concept, which can be understood as completing the specified work within the specified time. It can be said that the operating system reaches a certain level of real-time performance. It is easily affected by hardware resources, software interactions, etc. To measure the real-time performance of the Linux system, it needs to be reflected through data by test tools.
[0003] The Cyclictest tool is a relatively authoritative tool for measuring the real-time performance of the Linux system currently. It simulates the scheduling of the Linux system in user space and obtains the kernel interrupt latency and kernel scheduling latency by subtracting the time stamps, so as to reflect the real-time performance of the Linux system. However, the Cyclictest tool is only one of the tools in a set of real-time test tools for Linux. The simulation process for measuring real-time performance is relatively less, and the real-time data it reflects is relatively simple. Moreover, Cyclictest only performs simulation and data output in user space, and there will inevitably be a slight additional time overhead.
[0004] In addition, as a built-in module of the Linux system kernel, Ftrace can measure the real-time performance of the system by tracking relevant probe points during the system operation and paying attention to the function call process related to real-time performance, so as to achieve the purpose of quantifying real-time performance. However, although Ftrace is supported by the Linux official, it is essentially a Linux kernel tracing mechanism module. Measuring real-time performance is just one of its functions. Moreover, the data obtained through Ftrace is often not intuitive enough, the operation is relatively complex, and the integration degree is not high. Further data processing is required to obtain quantified real-time data. Summary of the Invention
[0005] In view of the defects and problems existing in the existing tools for measuring the real-time performance of the Linux system, such as the Cyclictest tool and the Ftrace tool, including relatively few simulation processes for measuring real-time performance, relatively simple real-time performance data reflected, additional time overhead, non-intuitive data acquisition, complex operations, low integration, and the need for further quantification of data, the present invention provides a test method for measuring the real-time performance of the Linux system.
[0006] The solution adopted by the present invention to solve its technical problems is as follows: A test method for measuring the real-time performance of the Linux system includes the following steps:
[0007] Step 1, construct a dedicated kernel module and test tool: Import the source code into the Linux system for compilation, and compile to generate a Linux kernel module and an executable file, where the executable file is the test tool;
[0008] Step 2, insert the kernel module into the Linux kernel: Insert the kernel module into the Linux kernel, and collect kernel information according to the defined working content of the kernel module and save the collected information in the kernel module;
[0009] Step 3, determine and classify test metric items: Distinguish the test metric items according to granularity, so that fine-grained test points are tested through the kernel module to obtain data, and coarse-grained test points are tested in the user space of the Linux system;
[0010] Step 4, perform user-space testing: The user runs the executable file compiled in Step 1 above to simulate user-space test points, simulate a coarse-grained simulation program, mark time stamps before and after the simulation process, and perform statistical analysis of time periods to obtain data for the test points;
[0011] Step 5, perform testing in the kernel module: Trigger the above event during kernel operation through the trace event set in the kernel to implement statistical analysis of system parameters, subtract the time stamps counted by different events to obtain the delay of the required test points, and reflect the delay data of the required points obtained in the kernel to the user space;
[0012] Step 6, the kernel module combines the coarse-grained simulation process and combines the kernel data collected from the above steps for calculation and collation, so as to output the real-time performance data of the Linux system that users care about.
[0013] As a preferred technical solution of the present invention, in Step 2, the kernel module is inserted into the Linux kernel by using the insmod command.
[0014] As a preferred technical solution of the present invention, the test index items in step three include interrupt response delay, semaphore operation delay, message queue operation delay, context switching delay, mutex operation delay, timer operation delay, event operation delay, task operation delay, and scheduling operation delay.
[0015] As a preferred technical solution of the present invention, the criterion for differentiating the test index items in step three is whether the encapsulation of the requirement points can be achieved.
[0016] As a preferred technical solution of the present invention, in step five, the kernel module adopts the tracer technology, interacts with the kernel module through the user's input, sets to call the corresponding functions, obtains the kernel module test data required by the user, and feeds it back to the user through the proc file system.
[0017] As a preferred technical solution of the present invention, the proc file system is a communication window between the kernel state and the user state in the Linux system, and the user observes the real-time test data through the proc file system.
[0018] As a preferred technical solution of the present invention, the process of calculating and sorting out the data in step six is to process the time data obtained from a large number of loop tests. Each time the time data is obtained in a loop, the minimum value, maximum value, and cumulative sum of this data item are updated. The cumulative sum is used to output the average value finally, and finally, the real-time quantization data of the Linux system that the user cares about is output.
[0019] Compared with the prior art, the beneficial effects of the present invention are as follows: The test method for measuring the real-time performance of the Linux system proposed by the present invention constructs a dedicated kernel module, which can perform real-time simulation tests in the kernel state, thereby reducing the time loss and improving the accuracy of the test results; and by combining the Linux kernel state and the user state, the test index items in the existing real-time test tools are also enriched, the test environment is more specific, and by obtaining the time before and after the simulation environment to obtain the time of the test process that the user cares about, the real-time test of the Linux system is made more comprehensive and accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of the overall flow of the present invention;
[0021] Figure 2 It is a schematic diagram of the compilation flow of the present invention;
[0022] Figure 3 It is a schematic diagram of the test work flow of the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0023] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0024] Please refer to Figures 1-3 , the present invention provides a test method for measuring the real-time performance of the Linux system. Combining the measurement methods of test data in the kernel state and user state of the Linux system, it provides richer test points, simulates a more specific environment, obtains the time before and after the simulation environment, so as to obtain the time of the test process that users care about, and preferably reflects the real-time performance of the Linux system.
[0025] Embodiment 1:
[0026] The test method for measuring the real-time performance of the Linux system provided by the present invention includes the following steps.
[0027] Step 1, construct a dedicated kernel module and test tool: Import the source code into a Linux system with a Linux 5.10rt kernel for compilation. The Linux system includes the user state and the kernel state. After compilation, a Linux kernel module and an executable file are generated. The kernel module belongs to the kernel state, and the executable file belongs to the user state. Among them, the kernel module is used to detect the detectable points in the kernel to obtain relevant call information, and interact with the user state through the proc file system. And this executable file is a test tool, that is, the executable file in the user state not only communicates with the kernel module to obtain data, but also conducts some simulation tests with a larger granularity to enrich the test data.
[0028] Step 2, insert the kernel module into the Linux kernel: The Linux kernel module is a file in the ko format. It is divided into modules statically compiled into the kernel and modules dynamically loaded with the insmod command. The ko file is essentially still an ELF file. Compared with ordinary ELF files, it has an additional segment structure to record some information of the ko module. These information are used when the kernel loads the module. Insert the kernel module into the Linux kernel by using the insmod command. These dynamically inserted kernel modules have strong flexibility, allowing the Linux kernel to insert the corresponding kernel module into the kernel when it needs certain functions. After the Linux kernel module is inserted into the kernel, the kernel module will start working according to the custom working content of the kernel module. In this method, on the basis of the Linux kernel running, collect kernel information. For example, add timestamps at the places where two function calls of disabling interrupts and enabling interrupts in the kernel module, obtain the corresponding time, and then subtract the time to obtain the interrupt handling time of the corresponding interrupt. The obtained information is the delay time of each required point in the kernel. Finally, save the collected information in the kernel module.
[0029] Step 3, determine the test indicators and classify them: the test indicators are distinguished according to the granularity. The test indicators include interrupt response delay, semaphore operation delay, message queue operation delay, context switch delay, mutex operation delay, timer operation delay, event operation delay, task operation delay and scheduling operation delay. The above test indicators are distinguished according to the granularity. The distinction standard is whether the system has implemented the encapsulation of the demand point. The fine-grained test points are tested through the kernel module to obtain data, and the coarse-grained test points are tested in the user state of the Linux system. That is, the above interrupt response delay and context switch delay are tested in the kernel module, and the above other indicators are placed in the user state for testing. In this way, by refining various basic behaviors of the operating system, such as interrupt processing time, context switch time, etc., and then abstracting the refined behaviors, each abstracted behavior is simulated and tested to obtain the corresponding time values. These time values can well reflect the real-time performance of the operating system;
[0030] Step 4, perform user-mode testing: When performing user-mode testing, the user runs the executable file compiled in the above step 1. The executable file is used to carry the user's input to modify other adjustable data such as the number of test cycles. The executable file simulates different test scenarios, obtains the data that the user is concerned about, simulates the user-mode test points, runs the coarse-grained simulation program of the user-mode simulation, timestamps the simulation process of the corresponding indicator items in the above step 3, performs time period statistics, and uses memory locks and real-time scheduling strategies to avoid the impact of preemption as much as possible to obtain the data of the test points;
[0031] Step 5, testing in the kernel module: Testing in the kernel module, that is, testing the above-mentioned interrupt response delay and context switching delay through the kernel module. The kernel module uses tracer technology to trigger the set event during kernel operation through the trace event that has been set in the kernel, realizes the statistics of system parameters such as time, and subtracts the timestamps of different event statistics to obtain the delay of the tested demand point. After obtaining the demand point delay data in the kernel, it is reflected to the user state through the proc file system to facilitate user interaction, that is, interacting with the kernel module through user input, setting and calling corresponding functions, obtaining the kernel module test data required by the user, and feeding back to the user through the proc file system. The kernel module defines a custom directory under the proc file system for user interaction. The proc file system is a communication window between the kernel state and the user state in the Linux system. It is a virtual file system, which is very suitable for observing kernel information in the Linux system and using it as a communication channel between the kernel state and the user state. The contents in the proc file system are all created dynamically.
[0032] In this method, a part of files are defined for user input, and the input content can be copied from the user mode to the kernel mode through the system interface for use. Similarly, a part of files are used to observe real-time test data, and the data therein is copied from the kernel mode. In addition, the kernel module also adopts the tracepoint mechanism. Tracepoint is a point where insertable code is reserved at some fixed positions in the kernel. The insertable code here mainly counts the data of the corresponding timestamps and saves them. In the kernel module, the saved timestamp data are subtracted to obtain the delay time value of the test requirement point, which is reflected from the kernel mode to the user mode through the proc file system. By calling the interface of the proc file system in the user-mode code, the data in the proc file system can be obtained without using the terminal, enabling communication between the kernel module and the user mode. In the present invention, the system timestamp is obtained as accurately as possible before and after the test process to reduce the interference of the system on the process. In this way, the test method using the kernel can reduce the time overhead caused by kernel mode switching, making the test results more accurate.
[0033] Step 6: The kernel module combines the coarse-grained simulation process and the kernel data collected from the above steps for calculation and sorting, that is, processes the time data obtained from a large number of loop tests. For each loop to obtain time data, the minimum value, maximum value, and cumulative sum of this data item are updated, and the timestamps are subtracted. The cumulative sum is used to finally output the average value, and finally, the quantitative data of the real-time performance of the Linux system concerned by the user is output. The test method for measuring the real-time performance of the Linux system proposed by the present invention adopts a relatively short process of the operating system running, summarizes an abstract description of the real-time performance of the system, and then uses the abstract description and test data to judge the real-time performance of the system. It combines the advantages of obtaining Linux data from the kernel mode and also takes into account the convenience of the user-mode test tools, enriching the Linux real-time performance test method and making the real-time performance test of the Linux system more comprehensive and accurate.
[0034] The above are only the preferred embodiments of the present invention and do not limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A test method for measuring the real-time performance of a Linux system, characterized in that: It includes the following steps: Step 1, constructing a dedicated kernel module and test tool: Import the source code into the Linux system for compilation, which generates a Linux kernel module and an executable file, where the executable file is the test tool; Step 2, inserting the kernel module into the Linux kernel: Insert the kernel module into the Linux kernel, and according to the working content of the custom kernel module, collect kernel information and save the collected information in the kernel module; Step 3, determining and classifying test metric items: Distinguish the test metric items according to the granularity, so that the fine-grained test points are tested through the kernel module to obtain data, and the coarse-grained test points are tested in the user space of the Linux system; Step 4, performing user-space testing: The user runs the executable file compiled in Step 1 above to simulate the user-space test points, simulate the coarse-grained simulation program, mark timestamps before and after the simulation, and perform time period statistics to obtain the data of the test points; Step 5, testing in the kernel module: Through the trace event set in the kernel, trigger the above event during kernel operation to implement the statistics of system parameters, and subtract the timestamps of different event statistics to obtain the latency of the required test points. After obtaining the latency data of the required points in the kernel, it is reflected to the user space; Step 6, the kernel module combines the coarse-grained simulation process and combines the kernel data collected from the above steps for calculation and collation, so as to output the real-time data of the Linux system that users care about.
2. The test method for measuring the real-time performance of a Linux system according to claim 1, wherein: In Step 2, the kernel module is inserted into the Linux kernel by using the insmod command.
3. The test method for measuring the real-time performance of the Linux system according to claim 1, characterized in that: The test metric items in Step 3 include interrupt response latency, semaphore operation latency, message queue operation latency, context switch latency, mutex operation latency, timer operation latency, event operation latency, task operation latency, and scheduling operation latency.
4. The test method for measuring the real-time performance of a Linux system according to claim 1, wherein: The standard for distinguishing the test metric items in Step 3 is whether the encapsulation of the required points can be achieved.
5. The test method for measuring the real-time performance of a Linux system according to claim 1, characterized in that: In Step 5, the kernel module adopts the tracer technology, interacts with the kernel module through the user's input, sets the corresponding function to be called, obtains the test data of the kernel module required by the user, and feeds it back to the user through the proc file system.
6. The test method for measuring the real-time performance of a Linux system according to claim 5, characterized in that: The proc file system is a communication window between the kernel space and the user space in the Linux system. Users observe the real-time test data through the proc file system.
7. The test method for measuring the real-time performance of a Linux system according to claim 1, characterized in that: The process of calculating and collating the data in Step 6 is to process the time data obtained from a large number of loop tests. Each time the time data is obtained in a loop, the minimum value, maximum value, and cumulative sum of this data item are updated. The cumulative sum is used to output the average value finally, and finally output the quantitative real-time data of the Linux system that users care about.
Citation Information
Patent Citations
Performance test method and tool aiming at Linux process scheduling
CN102722434A
Task scheduling method, system and related device of Linux system
CN109343960A