Method, system and medium for high-precision measurement of interruption duration of embedded system
By specifying interrupt exception handling functions in the embedded system, building a trap program environment and obtaining interrupt timestamps, the operation inconvenience of intrusive measurement methods in the existing technology is solved, and a non-invasive solution for high-precision interrupt duration measurement and performance analysis is realized, which improves debugging efficiency.
Patent Information
- Application Number
- CN202210127665.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-11
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2042-02-11
AI Technical Summary
The existing interrupt delay measurement method is invasive performance analysis, which requires modification of the program function flow, which is inconvenient to operate.
A non-invasive performance analysis method is adopted to specify interrupt exception handling functions, and use hardware resources to measure the interrupt duration without modifying the program function flow, including building a trap program environment, saving on-site register groups, calling interrupt vector processing macro functions, obtaining in-out interrupt timestamps and counting data.
It realizes high-precision interrupt time measurement, improves debugging efficiency, and can quickly locate performance bottlenecks and improves system performance.
Smart Images

Figure CN114489801B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, system and medium for measuring the interruption duration of an embedded system with high precision. Background Art
[0002] Interrupts are a crucial concept in computer systems, and modern computers, without exception, employ interrupt mechanisms. During program execution, a specific situation (or "event") can cause the CPU to halt the current program and switch to executing the event handler (commonly known as an interrupt handler or interrupt service routine). After the interrupt service routine completes, the CPU returns to the breakpoint and resumes execution of the original program. This process is called an interrupt.
[0003] Interrupt latency (interrupt duration) is one of the most important performance indicators of a real-time operating system. It usually refers to the time from when an external device issues an interrupt request to when the operating system's interrupt service routine executes the first instruction. Accurate measurement of interrupt latency is of great significance for quantitatively analyzing the real-time performance of a real-time operating system.
[0004] There are two ways to measure interrupt delay: the first is the PWM interrupt pin test method (oscilloscope test method), such as Figure 1 As shown in the following example, the oscilloscope test method: First, use oscilloscope channel 1 to output a fixed frequency square wave to a test GPIO (PIN1), then connect oscilloscope channel 2 to another test GPIO (PIN2). The program sets PIN1 to interrupt rising edge (or falling edge) trigger mode, and PIN2 is initially low. When it reaches the interrupt processing entry, it is set to high. The time difference between the PIN1 input trigger signal and the PIN2 pin output high level is measured on the oscilloscope to obtain the interrupt response time. The second method is the timer method, as shown in the following example: Figure 2 As shown, the timer test method uses two internal timers for measurement. Essentially, two counters are enabled: one incrementing and the other decrementing. When the decrementing counter reaches 0, an interrupt is generated. These two timers are temporarily defined as timer1 and timer2. At a specific point in time, timer1 is set to count down for 2 seconds, and the value of timer2, cnt1, is recorded. After the 2-second countdown, an interrupt is triggered. The hardware is then processing the interrupt. After the actual interrupt handler is executed, the timer2 count, cnt2, is recorded at the beginning of the interrupt handler. The resulting interrupt response time is: cnt2 - cnt1 - 2 seconds. Of course, this 2-second countdown can be adjusted based on specific circumstances.
[0005] However, both of the above-mentioned two measurement methods are invasive performance analysis methods. When used, they need to modify the program function flow, which is inconvenient to operate. Summary of the Invention
[0006] The present invention provides a method, system and medium for measuring the interruption duration of an embedded system with high precision, aiming to solve the problems existing in the above-mentioned background technology.
[0007] In order to achieve the above technical objectives, the present invention mainly adopts the following technical solutions:
[0008] A method for measuring the duration of an embedded system interruption with high precision, comprising the following steps:
[0009] S1 specifies the interrupt exception handling function as the service function of the specific exception vector number in the interrupt exception vector table, so that the exception vector number corresponds to the interrupt exception type;
[0010] S2 When an interrupt exception occurs, the system enters the kernel state, builds the trap program environment, saves the on-site register group, and then jumps to the system's general exception entry function;
[0011] The S3 general exception entry function reads the on-site register group information and determines the type of exception through the exception type value. If it is other exceptions, the corresponding other exception handling function is called. If it is an interrupt entry exception, the interrupt entry function is called.
[0012] S4 calls the interrupt processing entry function in the interrupt entry function, calls the specific interrupt processing function in the interrupt processing entry function, calls the archIntHandle() function in the specific interrupt processing function, calls the interrupt service routine function in the archIntHandle() function, and finally calls the interrupt vector processing macro function in the interrupt service routine function;
[0013] S5, at the entry of the interrupt vector processing macro function, first executes the interrupt duration measurement startup macro function to obtain the interrupt input timestamp, then calls the interrupt processing function to obtain the interrupt output timestamp and calculate the data, and finally, at the exit of the interrupt vector processing macro function, executes the interrupt duration measurement end timing and data statistics macro function to interrupt the cleanup process;
[0014] After S6 interrupt processing is completed, it returns to the system state.
[0015] Furthermore, in the interrupt service routine function, the steps of calling the interrupt vector processing macro function include:
[0016] The interrupt service routine function inputs the parameter through the interrupt vector number, first queries the system interrupt vector table structure to obtain pidesc, and then obtains the interrupt processing function list, and then calls the interrupt vector processing macro function to execute the specific interrupt processing function.
[0017] Preferably, the interruption duration measurement startup macro function is empty in the initial state; the interruption duration measurement end timing and data statistics function macro function is empty in the initial state.
[0018] The present invention further includes a bspTickHighResolution function, which is used to correct the precise time from the most recent tick to the current time.
[0019] The present invention also provides a system for high-precision measurement of the duration of an embedded system interruption, which applies a method for high-precision measurement of the duration of an embedded system interruption, including:
[0020] A first acquisition module is used to acquire an exception vector table when an interrupt exception occurs;
[0021] The first control module is used to control the system to jump to the general exception entry function of the system when an interrupt exception occurs;
[0022] Reading module, used to read the abnormal type value;
[0023] The judgment module judges the type of abnormality by reading the abnormality type value read by the reading module;
[0024] A second control module is used to control the system to search for the other exception handling function or interrupt entry function according to the exception type and execute the other exception handling function or interrupt entry function;
[0025] The measurement module is used to measure the time difference between the interruption input timestamp and the interruption output timestamp to measure the interruption duration.
[0026] Furthermore, the measurement module is named InterVectorMeasure.ko, and is loaded and run through the moduleregInterVectorMeasure.ko command when measuring the interruption duration.
[0027] Furthermore, when the InterVectorMeasure.ko module is loaded, the system executes the module_init function, executes its module_init function, and first executes the __isHighResolutionValid() function to determine whether the system high-precision clock interface is valid; if the high-precision clock interface does not exist, the execution is exited; if it exists, the installation interrupt timing operation set function __interVectorMeasureFuncsInstall() and the registration callback function API_InterVectorMeasureHook() are executed, as well as the initialization kernel proc file function function procFsKernelInterMeasureInit().
[0028] The present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for high-precision measurement of the interruption duration of an embedded system are implemented.
[0029] In addition, the present invention also provides an electronic device, comprising:
[0030] Memory for storing computer programs;
[0031] The processor is configured to implement the steps of the above-mentioned method for measuring the interruption duration of an embedded system with high precision when executing the computer program.
[0032] Compared with the existing technology, the present invention has the following beneficial effects: the present invention provides a method for high-precision measurement of interruption duration in embedded systems, which is a non-invasive performance analysis method. It can fully utilize hardware resources without modifying the program function flow, improve debugging efficiency, and provide an effective tool for quickly locating performance bottlenecks and effectively improving system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 This is a working diagram of an oscilloscope testing method in the prior art;
[0034] Figure 2 This is a schematic diagram of the working of the timer test method in the prior art;
[0035] Figure 3 is a flow chart of the measurement method of the present invention;
[0036] Figure 4 This is the statistical effect of the interruption duration measurement of the present invention. DETAILED DESCRIPTION
[0037] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0038] like Figure 3 A method for measuring the interruption duration of an embedded system with high precision is shown, comprising the following steps:
[0039] S1 specifies the interrupt exception handling function as the service function of the specific exception vector number in the interrupt exception vector table, so that the exception vector number corresponds to the interrupt exception type;
[0040] In this application, first, the interrupt exception handling function bspIntHandle() is specified in the system as the service function of the interrupt exception vector number 0, and the vector number 0 corresponds to the interrupt exception type;
[0041] S2 When an interrupt exception occurs, the system enters the kernel state, builds the trap program environment, saves the on-site register group, and then jumps to the system's general exception entry function archExceptionHandle();
[0042] Among them, the startup.S exception vector table is as follows:
[0043] Program Listing 1 startup.S exception vector table
[0044]
[0045]
[0046] When an exception occurs, the program jumps to the start of the startup.S exception vector table (see Listing 1) and executes different handlers based on the exception type (TLB flush / cash error / general exception / cash interrupt / system restart). Interrupts are general exceptions, so when an interrupt exception occurs, the program jumps to the handler code segment (see Listing 2) using the MIPS_EXCEPTION_HANDLE address. The general exception entry function archExceptionEntry (see Listing 3) is executed, and then the general exception entry function archExceptionHandle (see Listing 4) is executed.
[0047] Program Listing 2 General exception entry jump
[0048]
[0049] Listing 3 General exception entry
[0050]
[0051] Listing 4 General exception entry processing function
[0052]
[0053]
[0054] The S3 general exception entry function reads the field register group information and determines the type of exception by the exception type value. If it is other exceptions, the corresponding other exception handling function is called. If it is an interrupt entry exception, the specified interrupt entry function bspIntHandle() is called, as shown in Listing 4.
[0055] S4 is in the interrupt entry function and finally calls the interrupt vector processing macro function;
[0056] Among them, this step includes:
[0057] In the interrupt entry function bspIntHandle() (see program list 5), call the interrupt handling entry function ls2kIntDispach() (see program list 6);
[0058] In the interrupt processing entry function ls2kIntDispach() (see program list 6), call the specific interrupt processing function
[0059] ls2kIrqDispatch() function (see Listing 7);
[0060] In the specific interrupt handling function ls2kIrqDispatch() function (see program list 7), call the archIntHandle() function;
[0061] In the archIntHandle() function, call the interrupt service routine function API_InterVectorIsr() (see Listing 9);
[0062] In the interrupt service routine function API_InterVectorIsr() (see Listing 9), the interrupt vector processing macro function INTER_VECTOR_SVC() (see Listing 10) is called.
[0063] Among them, in the interrupt service routine function, the steps of calling the interrupt vector processing macro function are as follows:
[0064] The interrupt service routine function API_InterVectorIsr() (see Listing 9) uses the interrupt vector number ulVector as the input parameter, first executes LW_IVEC_GET_IDESC(ulVector) to query the system interrupt vector table structure to obtain pidesc, and then obtains the interrupt processing function list piaction=(PLW_CLASS_INTACT)pidesc->IDESC_plineAction, and then calls the interrupt vector processing macro function INTER_VECTOR_SVC() to execute the specific interrupt processing function.
[0065] Listing 5 Interrupt Entry
[0066]
[0067]
[0068] Program Listing 6 Interrupt processing entry
[0069]
[0070] Program Listing 7 Specific interrupt processing
[0071]
[0072]
[0073] Listing 8 Architecture layer interrupt handling function
[0074]
[0075]
[0076]
[0077] Listing 9 Vector interrupt service
[0078]
[0079]
[0080]
[0081] Program Listing 10 Interrupt Service Macro Function
[0082]
[0083]
[0084] S5, at the entry of the interrupt vector processing macro function, first executes the interrupt duration measurement start macro function INTER_VECTOR_MEASURE_ENTER to obtain the interrupt entry timestamp, then calls the interrupt processing function INTER_VECTOR_SVC_HANDLE() to obtain the interrupt output timestamp and count the data, and finally, at the exit of the interrupt vector processing macro function, executes the interrupt duration measurement end timing and data statistics macro function INTER_VECTOR_MEASURE_EXIT() to interrupt the cleanup process;
[0085] After S6 interrupt processing is completed, it returns to the system state.
[0086] The macro function for starting interrupt duration measurement is initially empty, while the macro function for ending interrupt duration measurement and performing data statistics is initially empty. See Listings 10 and 11.
[0087] Listing 11 Interrupt measurement callback
[0088]
[0089]
[0090] The present invention further includes a bspTickHighResolution function, which is used to correct the precise time from the most recent tick to the current time.
[0091] Typically, the system tick clock has an accuracy of only 10ms or 1ms, which is insufficient for applications requiring high-precision timing. Therefore, to achieve high-precision timing, the system provides the bspTickHighResolution function, which reads the current count value of the hardware timer to adjust the time from the most recent tick to the current precise time. Specifically, at the driver level, the bspTickHighResolution() call reads the hardware device's HPET timer register, achieving a clock accuracy of nanoseconds (see Listing 12).
[0092] Listing 12
[0093]
[0094]
[0095] The present invention also provides a system for high-precision measurement of the interruption duration of an embedded system, comprising:
[0096] A first acquisition module is used to acquire an exception vector table when an interrupt exception occurs;
[0097] The first control module is used to control the system to jump to the general exception entry function of the system when an interrupt exception occurs;
[0098] Reading module, used to read the abnormal type value;
[0099] The judgment module judges the type of abnormality by reading the abnormality type value read by the reading module;
[0100] A second control module is used to control the system to search for other exception handling functions or interrupt entry functions according to the exception type and execute the other exception handling functions or interrupt entry functions;
[0101] The measurement module is used to measure the time difference between the interruption input timestamp and the interruption output timestamp to measure the interruption duration.
[0102] The measurement module is named InterVectorMeasure.ko. When measuring the interruption duration, it is loaded and run through the moduleregInterVectorMeasure.ko command.
[0103] When the InterVectorMeasure.ko module is loaded, the system will execute its module_init function, and first execute the __isHighResolutionValid() function to determine whether the system high-precision clock interface is valid; if the high-precision clock interface does not exist, the execution will be exited; if it exists, the installation of the interrupt timing operation set function __interVectorMeasureFuncsInstall() [initializes the variables used by the interrupt measurement timing module] and the registration callback function API_InterVectorMeasureHook() and the execution of the initialization kernel proc file function function procFsKernelInterMeasureInit() are executed, see Listing 13.
[0104] Listing 13
[0105]
[0106]
[0107] The API_InterVectorMeasureHook() function installs the interrupt vector measurement callback functions __curTimeStampGet() and __deltaTimeStampGet into the system kernel. Whenever an interrupt exception occurs in the system, the interrupt vector processing macro function INTER_VECTOR_SVC() is entered. __curTimeStampGet() is first called to obtain the interrupt input timestamp. After executing the specific interrupt processing function, __deltaTimeStampGet() is called to obtain the interrupt output timestamp and record the maximum interrupt time. Both functions call the bspTickHighResolution function to obtain the current precise time, as shown in Listing 14.
[0108] Listing 14
[0109]
[0110]
[0111]
[0112]
[0113] The present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for high-precision measurement of the interruption duration of an embedded system are implemented.
[0114] The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program codes.
[0115] In addition, the present invention also provides an electronic device, comprising:
[0116] Memory for storing computer programs;
[0117] The processor is configured to implement the steps of the above-mentioned method for measuring the interruption duration of an embedded system with high precision when executing the computer program.
[0118] The electronic device may also include various network interfaces, power supplies and other components.
[0119] When the user calls the cat / proc / kernel / interMeasure command in the system shell command terminal, __procFsKernelInterMeasureRead() will be executed to view the time statistics of all interrupts in the system. See the program flow for details.
[0120] Program Listing 15, the statistical effect of interruption duration measurement is as follows Figure 4 shown.
[0121] Listing 15
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
[0131] It should also be noted that, in this specification, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus comprising the element.
Claims
1. A method for measuring the interruption duration of an embedded system with high precision, characterized in that: The following steps are involved: S1 specifies the interrupt exception handling function as the service function of the specific exception vector number in the interrupt exception vector table, so that the specific exception vector number corresponds to the interrupt exception type; S2 When an interrupt exception occurs, the system enters the kernel state, builds the trap program environment, saves the on-site register group, and then jumps to the system's general exception entry function; The S3 general exception entry function reads the on-site register group information and determines the type of exception through the exception type value. If it is other exceptions, the corresponding other exception handling function is called. If it is an interrupt entry exception, the interrupt entry function is called. S4 calls the interrupt processing entry function in the interrupt entry function, calls the specific interrupt processing function in the interrupt processing entry function, calls the archIntHandle() function in the specific interrupt processing function, calls the interrupt service routine function in the archIntHandle() function, and in the interrupt service routine function, inputs the parameter through the interrupt vector number, first queries the system interrupt vector table structure to obtain pidesc, and then obtains the interrupt processing function list, then calls the interrupt vector processing macro function, executes the specific interrupt processing function, and finally calls the interrupt vector processing macro function; S5, at the entry of the interrupt vector processing macro function, first executes the interrupt duration measurement startup macro function to obtain the interrupt input timestamp, then calls the interrupt processing function to obtain the interrupt output timestamp and calculate the data, and finally, at the exit of the interrupt vector processing macro function, executes the interrupt duration measurement end timing and data statistics macro function to interrupt the cleanup process; After S6 interrupt processing is completed, return to the system state.
2. The method for high-precision measurement of interruption duration of an embedded system according to claim 1, characterized in that: The interruption duration measurement startup macro function is empty in the initial state; the interruption duration measurement end timing and data statistics function macro function is empty in the initial state.
3. The method for measuring the interruption duration of an embedded system with high precision according to claim 1, wherein: The bspTickHighResolution function is also included, and the bspTickHighResolution function is used to correct the most recent tick to the current precise time.
4. A system for high-precision measurement of the interruption duration of an embedded system, characterized in that: A method for high-precision measurement of an embedded system interruption duration according to any one of claims 1 to 3 is applied, comprising: A first acquisition module is used to acquire an exception vector table when an interrupt exception occurs; The first control module is used to control the system to jump to the general exception entry function of the system when an interrupt exception occurs; Reading module, used to read the abnormal type value; The judgment module judges the type of abnormality by reading the abnormality type value read by the reading module; A second control module is used to control the system to search for a target interrupt processing function according to the exception type and execute the target interrupt processing function; The measurement module is used to measure the time difference between the interruption input timestamp and the interruption output timestamp to measure the interruption duration.
5. The system for high-precision measurement of interruption duration of embedded systems according to claim 4, characterized in that: The measurement module is named InterVectorMeasure.ko and is loaded and run through the moduleregInterVectorMeasure.ko command when measuring the interruption duration.
6. The system for high-precision measurement of interruption duration of an embedded system according to claim 5, characterized in that: When the InterVectorMeasure.ko module is loaded, the system executes the module_init function, executes its module_init function, and first executes the __isHighResolutionValid() function to determine whether the system high-precision clock interface is valid; if the high-precision clock interface does not exist, the execution is exited; if it exists, the installation interrupt timing operation set function __interVectorMeasureFuncsInstall() and the registration callback function API_InterVectorMeasureHook() are executed, as well as the initialization kernel proc file function function procFsKernelInterMeasureInit().
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the method for high-precision measurement of the interruption duration of an embedded system as claimed in any one of claims 1 to 3.
8. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the method for high-precision measurement of interruption duration of an embedded system as claimed in any one of claims 1 to 3 when executing the computer program.
Citation Information
Patent Citations
Method for measuring task CPU occupancy rate in multitasking operation system
CN101145125A
Processing method and device for access exception of processor, storage medium and computing equipment
CN113535451A