Test method for measuring real-time performance of Linux system
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a testing method for measuring real-time performance of a Linux system.
Background
The Linux system is taken as outstanding figure of an open source system, and the application scene is very wide. The origin of the Linux system is a user interactive system, and the real-time performance of the Linux system is not considered, but as the open-source Linux system is more and more popular, the Linux system obtains a kernel patch with optimized real-time performance, so that the kernel of the Linux system can become a real-time system kernel, and the Linux system improves the real-time performance of the Linux kernel by patching the Linux kernel so as to meet the real-time performance requirements of most scenes. The real-time performance of the operating system is a comparatively abstract concept, and can be understood as that the specified work is completed within the specified time, and can be called as the real-time performance of the operating system reaching a certain level, which is easy to be affected by hardware resources, software and the like, and the real-time performance of the Linux system is measured and needs to be embodied through data by a test tool.
The CYCLICTEST tool is a relatively authoritative tool for measuring the real-time performance of the Linux system at present, the kernel interrupt delay and the kernel scheduling delay are obtained by simulating the scheduling of the Linux system in a user mode and a method of subtracting a time stamp, so that the real-time performance of the Linux system is reflected, but the CYCLICTEST tool is also a tool which is centralized by a real-time test tool of Linux, is used for measuring a relatively less simulation process of the real-time performance, the reflected real-time performance data is relatively simple, and CYCLICTEST only carries out simulation and data output in the user mode, so that slight additional time expenditure is unavoidable.
In addition, ftrace is taken as a built-in module of a Linux system kernel, the real-time performance of the system can track related detectable points in the running process of the system through a Ftrace tool, and the aim of quantifying the real-time performance is achieved by focusing on a function calling process related to the real-time performance, but Ftrace is supported by Linux authorities and is essentially a Linux kernel tracking mechanism module, the real-time performance is detected as one of functions, the data acquired through Ftrace is often not intuitive, the operation is complex, the integration level is not high, and the quantized real-time performance data can be acquired only by further processing the data.
Disclosure of Invention
Aiming at the defects and problems that existing tools for measuring the real-time performance of the Linux system, such as CYCLICTEST tools and Ftrace tools, have relatively fewer simulation processes for measuring the real-time performance, reflected real-time performance data are simpler, additional time cost exists, the acquired data are not visual enough, the operation is complex, the integration level is not enough, and further quantization processing is needed to be carried out on the data, the invention provides a test method for measuring the real-time performance of the Linux system.
The invention solves the technical problems by adopting a scheme that the testing method for measuring the real-time performance of the Linux system comprises the following steps:
Firstly, a special kernel module and a testing tool are constructed, namely a source code is imported into a Linux system for compiling, and a Linux kernel module and an executable file are generated through compiling, wherein the executable file is the testing tool;
Inserting the kernel module into the Linux kernel, and according to the work content of the self-defined kernel module, realizing the collection of kernel information and storing the collection information in the kernel module;
step three, determining and classifying test index items, namely distinguishing the test index items according to granularity, so that fine-granularity test points test through a kernel module to obtain data, and testing coarse-granularity test points in a user mode in a Linux system;
Step four, executing user mode test, wherein a user runs the executable file compiled in the step one, performs user mode test point simulation, simulates a coarse-granularity simulation program, marks time stamps before and after a simulation process, and performs time period statistics to obtain test point data;
Testing the kernel module, namely triggering the event in the running of the kernel through the set TRACE EVENT in the kernel, realizing statistics of system parameters, subtracting time stamps of different event statistics to obtain the delay of a tested demand point, and reacting to a user state after obtaining delay data of the demand point in the kernel;
And step six, the kernel module combines the coarse-granularity simulation process and combines the kernel data collected from the steps to calculate and arrange, so as to output the real-time data of the Linux system which is concerned by the user.
As a preferable technical scheme of the invention, in the second step, the kernel module is inserted into the Linux kernel by using an insmod command.
As a preferable technical scheme of the invention, the test index item in the third step comprises 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.
As a preferred technical solution of the present invention, the criterion for distinguishing the test index items in the third step is whether the packaging of the demand point can be achieved.
As a preferable technical scheme of the invention, the kernel module in the fifth step adopts tracer technology, interacts with the kernel module through the input of a user, sets and calls corresponding functions, acquires the kernel module test data required by the user, and feeds back the test data to the user through a proc file system.
As a preferable technical scheme of the invention, the proc file system is a communication window of kernel mode and user mode in the Linux system, and a user observes real-time test data through the proc file system.
As a preferable technical scheme of the invention, the process of calculating and sorting the data in the step six is to process a large amount of time data acquired by cyclic test, the minimum value, the maximum value and the accumulation sum of the data item are updated each time the time data are acquired in each cycle, the accumulation sum is used for outputting an average value finally, and the real-time quantized data of the Linux system concerned by the user is output finally.
Compared with the prior art, the method for measuring the real-time performance of the Linux system has the advantages that the special kernel module is constructed, the real-time performance simulation test can be carried out in the kernel state, so that the time loss is reduced, the accuracy of a test result is improved, the Linux kernel state and the user state are combined, the test index items in the existing real-time test tool are enriched, the test environment is more specific, and the time of the test process concerned by the user is acquired before and after the simulation environment, so that the real-time performance test of the Linux system is more comprehensive and accurate.
Drawings
FIG. 1 is a schematic overall flow chart of the present invention;
FIG. 2 is a schematic diagram of a compiling process according to the present invention;
FIG. 3 is a schematic diagram of a testing workflow of the present invention.
Detailed Description
The invention will be further described with reference to the drawings and examples.
Referring to fig. 1-3, the invention provides a testing method for measuring real-time performance of a Linux system, which combines a measuring method of kernel mode and user mode testing data of the Linux system, provides richer testing points, simulates a more specific environment, and acquires time before and after the environment is simulated to acquire time of a testing process concerned by a user, so that real-time performance of the Linux system is reflected better.
Embodiment one:
The test method for measuring the real-time performance of the Linux system provided by the invention comprises the following steps,
Firstly, a special kernel module and a testing tool are constructed, namely a source code is imported into a Linux system with a Linux5.10rt kernel to be compiled, the Linux system comprises a user mode and a kernel mode, a Linux kernel module and an executable file are generated after compiling, the kernel module belongs to the kernel mode, the executable file belongs to the user mode, the kernel module is used for detecting a detectable point in the kernel to obtain related calling information, and the executable file is the testing tool through proc file system and user mode interaction, namely the executable file in the user mode is not only communicated with the kernel module to obtain data, but also performs simulation tests with larger granularity to enrich test data;
The method comprises the steps that a Linux kernel module is inserted into a Linux kernel, the Linux kernel module is divided into a module which is statically compiled into the kernel and a module which is dynamically loaded by an insmod command, the ko file is essentially an ELF file, compared with a common ELF file, a section of structure is added, the ko module is used for recording some information of the ko module, the information is used when the kernel is loaded into the Linux kernel, the kernel module which is dynamically inserted is inserted into the Linux kernel by using the insmod command, the corresponding kernel module is inserted into the kernel when certain functions are needed by the Linux kernel, the kernel module starts to work according to the working content of the self-defined kernel module after the Linux kernel module is inserted into the kernel, in the method, kernel information is collected on the basis of the Linux kernel operation, for example, a time stamp is added to a calling place of two functions of interrupt and on interrupt in the kernel module, the corresponding interrupt processing time can be obtained by subtracting the time, the obtained information is the time delay of each required point in the kernel, and the obtained information is stored in the collection module;
Step three, determining and classifying test index items: distinguishing test index items according to granularity, wherein the test index items comprise 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, distinguishing the test index items according to granularity, and judging whether a system realizes packaging of the demand point or not, wherein a fine-granularity test point tests through a kernel module to obtain data, a coarse-granularity test point tests in a user state in a Linux system, namely the interrupt response delay and the context switching delay pass through the test in the kernel module, and the other index items are placed in the user state to test, so that each abstract behavior is abstracted through various basic behaviors of a refined operation system, such as interrupt processing time, context switching time and the like, and a simulation test is performed on each abstracted behavior to obtain corresponding time values, and the time values can well reflect the real-time of the operation system;
And step four, executing user mode test, namely, when the user mode test is carried out, the user runs the executable file compiled in the step one, and the executable file is used for bearing the input of the user so as to modify other adjustable data such as test cycle times and the like. The method comprises the steps of executing different test schemes of file simulation, obtaining data concerned by a user, carrying out user state test point simulation, running a coarse-grained simulation program of user state simulation, stamping time stamps before and after the simulation process of the corresponding index item in the step three, carrying out time period statistics, and adopting a memory lock and a real-time scheduling strategy to avoid the influence of preemption as much as possible so as to obtain the data of the test point;
And fifthly, testing the kernel module, namely testing the interrupt response delay and the context switching delay in the kernel module, wherein the kernel module triggers the set event in the kernel operation by means of tracer technology through the set TRACE EVENT in the kernel, so as to realize statistics of system parameters such as time, and the time stamps of different event statistics are subtracted to obtain the delay of a tested demand point, the delay data of the demand point is obtained in the kernel, and then is reacted to a user state through a proc file system, so that user interaction is facilitated, namely interaction is performed with the kernel module through input of a user, a corresponding function is set and called, kernel module test data required by the user is obtained, the proc file system is fed back to the user, a custom directory under the proc file system is defined in the kernel module, and is used for interaction of the user, the proc file system is a communication window of the kernel state and the user state in the Linux system, is a virtual file system, is very suitable for observing kernel information in the Linux system, the kernel information is used as a communication channel of the kernel state and the user state, and the proc file system is created dynamically.
In the method, a part of files are defined for user input, the input content can be copied from a user state to a kernel state through a system interface and used for observing real-time test data, wherein the data are copied from the kernel state, a tracepoint mechanism is adopted by a kernel module, tracepoint is reserved at some fixed positions in the kernel, the insertable codes are mainly data with corresponding time stamps and are stored, the stored time stamp data are subtracted by the kernel module to obtain a time delay time value of a test requirement point, the time delay value is reflected to the user state through a proc file system from the kernel state, and the interface of the proc file system is called by the user state code.
Step six, the kernel module combines the coarse-grained simulation process and the kernel data collected from the steps, performs calculation and arrangement, namely processes a large amount of time data obtained through cyclic test, updates the minimum value, the maximum value and the accumulation sum of the data item every time the time data are obtained in a cyclic way, performs subtraction of the time stamp, and the accumulation sum is used for outputting an average value finally to output Linux system real-time quantized data concerned by a user. The method for measuring the real-time performance of the Linux system provided by the invention adopts a certain relatively short process of operating the operating system to summarize the abstract description of the real-time performance of the system, and then judges the real-time performance of the system by using the abstract description and the test data, combines the advantage of acquiring the Linux data from the kernel mode, simultaneously gives consideration to the convenience of a user mode test tool, enriches the method for testing the real-time performance of the Linux, and ensures that the real-time performance test of the Linux system is more comprehensive and accurate.
The foregoing description of the preferred embodiments of the invention is not intended to limit the invention to the particular embodiments disclosed, but on the contrary, the intention is to cover all modifications, equivalents, and alternatives falling within the spirit and scope of the invention.