Embedded real-time operating system interrupt statistics method, device, equipment and medium
By obtaining interrupt type numbers in real-time operating systems and recording the time-consuming of interrupt services and delayed services, the problem of inaccurate interrupt statistics in the existing technology is solved, efficient and accurate interrupt information statistics between different operating systems are achieved, and the accuracy of system performance evaluation is improved.
Patent Information
- Application Number
- CN202510443270.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2045-04-10
AI Technical Summary
Existing interrupt statistics methods are difficult to accurately count interrupt time in real-time operating systems, especially on processors that support interrupt nesting functions such as the cortex-M series, which leads to errors in performance evaluation and cannot meet the high-precision requirements of satellite navigation systems.
By obtaining the interrupt type number, calling the corresponding interrupt service program and recording the response time, counting the time spent at the end of the target interrupt program, and executing the delayed service program after exiting the interrupt program, comprehensively determining the total interrupt time spent to achieve accurate interrupt information statistics.
Without destroying the interrupt processing process, accurate statistics of interrupt information is achieved, the implementation process is simplified, the resource occupies less, and has strong portability.
Smart Images

Figure CN119960949B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an interrupt statistics method, device, equipment and medium for an embedded real-time operating system. Background Art
[0002] With the rapid development of satellite navigation technology, satellite navigation has become the most important means of navigation and positioning today. As a result, satellite navigation system software has increasingly stringent requirements for real-time performance, stability, and reliability. Therefore, satellite navigation system performance testing has become necessary. Its purpose is to test the functionality or overall operation of the satellite navigation software and then evaluate whether its performance meets user requirements. In computer systems, interrupt statistics are a very important performance tuning tool. By analyzing interrupt statistics, we can gain a deep understanding of the system's operating status, identify possible performance issues, and take effective optimization measures. This plays an irreplaceable role in improving the overall performance and stability of satellite navigation systems. Existing interrupt statistics methods rely on counting the start and end counts of interrupt service routines.
[0003] During the implementation of the present invention, we recognized that the prior art suffers from at least the following technical issues: Currently, interrupt handling in real-time operating systems is generally divided into two parts: an interrupt service routine and a delayed service routine. The delayed service routine allows other interrupts to occur and be processed. Some processors, such as the Cortex-M series, support nested interrupts, which means interrupt statistics cannot simply be calculated by starting and ending the interrupt service routine. Therefore, existing statistical methods cannot accurately calculate interrupt duration, resulting in errors in evaluating system performance. Given the high-precision requirements of current satellite navigation systems, these methods are difficult to meet practical application requirements. Summary of the Invention
[0004] The embodiment of the present invention provides an embedded real-time operating system interrupt statistics method, device, computer equipment and storage medium to improve the accuracy of interrupt time statistics.
[0005] In order to solve the above technical problems, the embodiment of the present application provides an embedded real-time operating system interrupt statistics method, comprising:
[0006] When an interrupt is detected, the interrupt type number is obtained;
[0007] Calling the interrupt service routine corresponding to the interrupt type number as the target interrupt routine, and recording the response time of the target interrupt routine as the first time consumption;
[0008] When detecting that the target interrupt program ends, counting the time consumed by the target interrupt program as a second time consumed;
[0009] Exit the target interrupt program, start executing the delay service program, and count the time consumed by the delay service program as the third time consumption;
[0010] The interruption duration is determined based on the first duration, the second duration, and the third duration.
[0011] Optionally, calling the interrupt service routine corresponding to the interrupt type number as the target interrupt routine, and recording the response time of the target interrupt routine as the first time consumption includes:
[0012] According to the interrupt type number, obtaining an entry address of an interrupt service program corresponding to the interrupt type number from a preset interrupt vector table as a target entry address;
[0013] Enter the target entry address to start the target interrupt program, and record the time at this time as the first time T1;
[0014] When detecting that the target interrupt program responds successfully, recording the time at this time as the second time T2;
[0015] The first duration is determined according to the first time T1 and the second time T2.
[0016] Optionally, exiting the target interrupt program, starting to execute the delayed service program, and counting the time consumed by the delayed service program as the third time consumed includes:
[0017] When the instruction to start executing the delayed service program is issued, the time at this time is recorded as the third moment T3;
[0018] When it is detected that the delayed service program responds successfully, the time at this moment is recorded as the fourth time T4;
[0019] Determining the startup time of the delayed service program according to the third time T3 and the fourth time T4;
[0020] After the delayed service program ends, the time at this time is recorded as the fifth time T5;
[0021] Determining the execution time of the delayed service program according to the fourth time T4 and the fifth time T5;
[0022] The third time duration is determined based on the startup time duration and the execution time duration.
[0023] Optionally, calling the interrupt service program corresponding to the interrupt type number as the target interrupt program also includes: updating the interrupt service processing incomplete flag and the delayed service processing incomplete flag, setting the interrupt service processing incomplete flag, and clearing the interrupt delay incomplete flag.
[0024] Optionally, the interrupt service program corresponding to the interrupt type number includes a first interrupt service function, a second interrupt service function, a delayed interrupt service processing function, and a thread function, and the first interrupt service function has a higher priority than the second interrupt service function;
[0025] The step of counting the time consumed by the target interrupt program as the second time consumed upon detecting that the target interrupt program ends includes:
[0026] If the interrupt service program is the delayed interrupt service processing function, then executing the step of exiting the target interrupt program, starting to execute the delayed service program, and counting the time consumed by the delayed service program as a third time-consuming step;
[0027] If the interrupt service routine is the second interrupt service function, the total interrupt time statistics are updated to be the total interrupt time of the previous interrupt plus the current interrupt processing time;
[0028] If the interrupt service program is a thread, an interrupt processing incomplete flag is added, and an interrupt delay incomplete flag is cleared.
[0029] Optionally, after the step of determining the interrupt duration based on the first duration, the second duration, and the third duration, the method for counting interrupts of an embedded real-time operating system further includes:
[0030] For the embedded interrupt, the number of interrupts and the interruption duration corresponding to each interruption are obtained, and the total duration is determined based on the interruption duration corresponding to each interruption.
[0031] Optionally, after the step of determining the interrupt duration based on the first duration, the second duration, and the third duration, the method for counting interrupts of an embedded real-time operating system further includes:
[0032] Obtain the number of interrupts and the interrupt information when each interrupt occurs, wherein the interrupt information includes the interrupt type number, the interrupt service routine, the first time consumption, the second time consumption and the third time consumption;
[0033] Statistical analysis is performed based on the number of interruptions and interruption information when each interruption occurs to determine whether there is an abnormal interruption.
[0034] In order to solve the above technical problems, the embodiment of the present application further provides an embedded real-time operating system interrupt statistics device, comprising:
[0035] A first acquisition module is used to obtain an interrupt type number when an interrupt is detected;
[0036] Start a timing module, which is used to call the interrupt service program corresponding to the interrupt type number as the target interrupt program, and record the response time of the target interrupt program as the first time consumption;
[0037] an interrupt timing module, configured to count the time consumed by the target interrupt program as a second time consumed when detecting that the target interrupt program has ended;
[0038] A delay timing module is used to exit the target interrupt program, start executing the delay service program, and count the time consumed by the delay service program as the third time consumption;
[0039] A time consumption determination module is used to determine the interruption time consumption based on the first time consumption, the second time consumption and the third time consumption.
[0040] Optionally, the start timing module includes:
[0041] An entry acquisition unit, configured to acquire, according to the interrupt type number, an entry address of an interrupt service routine corresponding to the interrupt type number from a preset interrupt vector table as a target entry address;
[0042] A first time recording unit, configured to enter the target entry address to start the target interrupt program, and record the time at this time as a first time T1;
[0043] A second time recording unit, configured to record the time when it is detected that the target interrupt program responds successfully as a second time T2;
[0044] The first time consumption calculation unit is configured to determine the first time consumption according to the first time T1 and the second time T2.
[0045] In order to solve the above technical problems, an embodiment of the present application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the computer program, the steps of the above-mentioned embedded real-time operating system interrupt statistics method are implemented.
[0046] In order to solve the above technical problems, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the above-mentioned embedded real-time operating system interrupt statistics method.
[0047] The embodiment of the present invention provides an embedded real-time operating system interrupt statistics method, device, computer equipment and storage medium. When an interrupt is detected, the interrupt type number is obtained; the interrupt service program corresponding to the interrupt type number is called as the target interrupt program, and the response time of the target interrupt program is recorded as the first time; when the target interrupt program is detected to have ended, the time taken by the target interrupt program is counted as the second time; the target interrupt program is exited, the delayed service program is started to execute, and the time taken by the delayed service program is counted as the third time; and the interrupt time is determined based on the first time, the second time and the third time. The method achieves the purpose of accurately counting interrupt information without destroying the interrupt processing process and with little impact on the original system. Not only can the interrupt information be accurately counted, but the implementation is simple, the resource usage is low, and the portability between different real-time operating systems is strong. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0049] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0050] Figure 2 It is a flowchart of an embodiment of the method for counting interrupts of an embedded real-time operating system of the present application;
[0051] Figure 3 It is a structural diagram of an embodiment of an interrupt statistics device for an embedded real-time operating system according to the present application;
[0052] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of the application are for the purpose of describing specific embodiments only and are not intended to limit this application. The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of this application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0054] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0055] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0056] See also Figure 1 ,like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. Network 104 is a medium for providing communication links between terminal devices 101, 102, 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0057] Users can use terminal devices 101 , 102 , 103 to interact with server 105 via network 104 to receive or send messages, etc.
[0058] The terminal devices 101, 102, and 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptop computers, desktop computers, etc.
[0059] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0060] It should be noted that the embedded real-time operating system interrupt statistics method provided in the embodiment of the present application is executed by a server, and accordingly, the embedded real-time operating system interrupt statistics device is set in the server.
[0061] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only illustrative. According to the implementation requirements, there can be any number of terminal devices, networks and servers. The terminal devices 101, 102, 103 in the embodiment of the present application can specifically correspond to application systems in actual production.
[0062] See also Figure 2 , Figure 2 An embodiment of the present invention provides an embedded real-time operating system interrupt statistics method, which is applied in Figure 1 The server in the example is used as an example, and the details are as follows:
[0063] S201: When an interruption is detected, an interruption type number is obtained.
[0064] Specifically, after the external device sends an interrupt request signal to the CPU, the CPU checks whether there is an interrupt request after each instruction is executed and processes it according to the priority. Then the interrupt controller receives the interrupt signal and obtains the interrupt type number corresponding to the interrupt signal from the interrupt status register.
[0065] The interrupt controller is a key component in computer systems. Its primary function is to manage and schedule various interrupt requests within the system. It receives requests from multiple interrupt sources and prioritizes them for the CPU, ensuring they can be processed efficiently. The interrupt controller also features interrupt masking, which can block unresponsive interrupts, and priority arbitration, which determines the order in which interrupts are processed based on their priority. In multi-core processor systems, the interrupt controller is also responsible for dispatching interrupts to specific CPU cores.
[0066] In microprocessor systems, particularly in the early x86 architecture, the 8259 interrupt controller is widely used to handle interrupt requests (IRQs). The 8259 uses priority control and interrupt masking to ensure the system can effectively respond to external hardware events and maintain efficient processor operation. The interrupt controller continuously monitors interrupt request signals generated by various devices, converts them into interrupt vectors, and sorts the interrupt requests according to a set priority. The interrupt controller then dispatches the interrupt requests to the appropriate processor or device so that the processor can respond and process the interrupt request promptly. Upon receiving the interrupt request, the processor determines the source of the interrupt request based on the interrupt vector and performs the appropriate processing. Upon completion of the processing, the processor sends an interrupt completion signal through the interrupt controller to notify the interrupt controller that the interrupt request has been processed.
[0067] Interrupt controllers also play a crucial role in program design, improving program efficiency and responsiveness. By effectively utilizing interrupt control, program execution can be decoupled from external events, enabling multitasking and real-time performance. Interrupt controllers are also widely used in various computer and embedded systems to manage and process interrupt requests from external devices such as keyboards, mice, hard drives, and network adapters. In embedded systems, interrupt controllers can process interrupt signals from various sensors, enabling real-time monitoring and control of the physical environment.
[0068] S202: calling an interrupt service program corresponding to the interrupt type number as a target interrupt program, and recording a response time of the target interrupt program as a first time.
[0069] An interrupt service routine (ISR) is a piece of code in an operating system that responds to hardware interrupts. When a hardware device requires the CPU's attention, it sends an interrupt signal. Upon receiving this signal, the CPU suspends its current task and executes the ISR to handle the interrupt.
[0070] In this embodiment, the execution process of the interrupt service program includes the following:
[0071] Protect breakpoints: After responding to an interrupt, the CPU needs to protect the breakpoint information of the currently executing program, usually by saving the contents of general registers on the stack.
[0072] Search the interrupt vector table: The CPU determines the location of the corresponding interrupt service routine by querying the interrupt vector table based on the interrupt type.
[0073] Execute interrupt service routine: CPU jumps to the entry address of the interrupt service routine and starts executing the interrupt service routine.
[0074] Restoring the scene: After the interrupt service program is executed, the CPU will restore the previously protected breakpoint information (that is, pop the register contents that were previously pushed onto the stack and restore them).
[0075] Interrupt return: The CPU returns to the interrupted program and continues execution as if the interrupt had never occurred.
[0076] In a specific optional implementation, in step S202, the interrupt service routine corresponding to the interrupt type number is called as the target interrupt routine, and the response time of the target interrupt routine is recorded as the first time, which includes:
[0077] According to the interrupt type number, obtain the entry address of the interrupt service program corresponding to the interrupt type number from the preset interrupt vector table as the target entry address;
[0078] Enter the target entry address to start the target interrupt program, and record the time at this time as the first time T1;
[0079] When it is detected that the target interrupt program responds successfully, the time at this time is recorded as the second time T2;
[0080] A first elapsed time is determined according to the first time T1 and the second time T2.
[0081] In this embodiment, the interrupt response process includes:
[0082] An interrupt request signal is generated, and the external device sends an interrupt request signal to the CPU.
[0083] Interrupt request check: After each instruction is executed, the CPU checks whether there is an interrupt request and processes it according to the priority.
[0084] Pause the current task. When the CPU responds to an interrupt, it will pause the execution of the current task and save the status of the current task.
[0085] Save the current state. The CPU saves the state of the current task to the memory or stack so that it can be restored to the state before the interrupt after the interrupt processing is completed.
[0086] Jump to the interrupt handler. The CPU finds the entry address of the corresponding interrupt handler in the interrupt vector table according to the type of interrupt request, and jumps to the address to start executing the interrupt handler.
[0087] Execute the interrupt handler, which is responsible for processing interrupt requests, including responding to external devices, data processing and other operations.
[0088] S203: When it is detected that the target interruption program ends, the time consumed by the target interruption program is counted as a second time consumption.
[0089] Preferably, calling the interrupt service program corresponding to the interrupt type number as the target interrupt program further includes: updating the interrupt service processing incomplete flag and the delay service processing incomplete flag, setting the interrupt service processing incomplete flag, and clearing the interrupt delay incomplete flag.
[0090] In a specific optional implementation manner, the interrupt service program corresponding to the interrupt type number includes a first interrupt service function, a second interrupt service function, a delayed interrupt service processing function, and a thread function, and the first interrupt service function has a higher priority than the second interrupt service function;
[0091] After detecting that the target interrupt program has ended, the target interrupt program time consumption is counted as the second time consumption, including:
[0092] If the interrupt service routine is a delayed interrupt service processing function, then exit the target interrupt routine, start executing the delayed service routine, and count the time consumed by the delayed service routine as the third time-consuming step;
[0093] If the interrupt service routine is the second interrupt service function, the total interrupt time statistics are updated to be the total interrupt time of the previous interrupt plus the current interrupt processing time;
[0094] If the interrupt service routine is a thread, the interrupt processing unfinished flag is increased and the interrupt delay unfinished flag is cleared.
[0095] In a specific example, if the interrupt service routine is a delayed interrupt service processing function, the process enters step S204. If the interrupt service routine is a low-priority interrupt service routine, the total interrupt time statistics are updated to be the total interrupt time of the last interrupt plus the current interrupt processing time (i.e., isr_total = isr_total(last) + isr_cycle). If the interrupt service routine is a thread, the interrupt processing unfinished flag is increased (i.e., irq_not_leave = 1), and the interrupt delay unfinished flag is cleared (i.e., dsr_call = 0).
[0096] At the end of the interrupt service program, a counter is used to time the end of the interrupt service program and calculate the interrupt service processing time. Specifically, the time irq_end when the interrupt service program ends is recorded. The mid-segment service processing time is equal to the end time of the interrupt service program processing minus the start time of the interrupt service response (i.e. irq_cycle = irq_end – irq_start). Then the interrupt service program is exited and the interrupt delay service program is started.
[0097] S204: Exit the target interrupt program, start executing the delayed service program, and count the time consumed by the delayed service program as the third time consumption.
[0098] Interrupt service latency (ISR) refers to the time between the occurrence of a hardware interrupt and the execution of the first instruction of the interrupt handler (ISR). This time includes the process from the system receiving the interrupt signal to the operating system responding and switching to the interrupt service routine. Specifically, interrupt latency can be divided into the following stages:
[0099] Task is running: The CPU is executing a task.
[0100] Interrupt arrival: The interrupt signal arrives and the CPU needs to stop the current task.
[0101] Determine the interruption type: The system identifies the interruption type and decides the action to take.
[0102] Context switch: Save the context of the current task and prepare to switch to the ISR.
[0103] Execute interrupt service routine: ISR starts running.
[0104] Interrupt latency is a key indicator of system real-time performance. Optimizing interrupt latency is crucial for improving system responsiveness and resource utilization. In real-time systems, fast interrupt response times and low latency are prerequisites for ensuring timely responses to external events. Optimizing interrupt latency is typically achieved by reducing interrupt processing overhead and optimizing interrupt response mechanisms.
[0105] In a specific optional implementation, in step S204, the target interrupt program is exited, the delayed service program is started, and the time consumed by the delayed service program is counted as the third time consumption, which includes:
[0106] When the instruction to start executing the delayed service program is issued, the time at this time is recorded as the third moment T3;
[0107] When it is detected that the delayed service program responds successfully, the time at this time is recorded as the fourth time T4;
[0108] Determine the startup time of the delayed service program according to the third time T3 and the fourth time T4;
[0109] After the delayed service program ends, the time at this time is recorded as the fifth time T5;
[0110] Determine the execution time of the delayed service program according to the fourth time T4 and the fifth time T5;
[0111] A third time duration is determined based on the startup time duration and the execution time duration.
[0112] In this embodiment, the accuracy of the interruption time is ensured by counting the time overhead of the delay service program.
[0113] In a specific example, a delayed service processing flag is increased at the start of the delayed service program, and a counter is used to time the interrupt delay service at the start of the delayed service processing program, and the interrupt delay service time is specifically implemented as follows: after entering the interrupt delay service program, the start time dsr_start of the interrupt delay service program is recorded, and the interrupt delay service time is the interrupt delay service start time minus the interrupt service end time (i.e., dsr_latency = dsr_start–irq_end), and the interrupt delay incomplete flag is set (i.e., dsr_call = 1).
[0114] At the end of the delayed service program processing, an interrupt processing completion judgment is added; at the end of the interrupt delay service, a counter is used to time the interrupt service processing, the interrupt service processing unfinished flag is cleared, the interrupt delay service processing time is counted, and the total time consumed by the interrupt type is counted. The specific implementation is that if the interrupt processing unfinished flag exits directly without any statistics, otherwise the interrupt delay service end time dsr_end is recorded. The interrupt delay service processing time is the interrupt delay service end time minus the interrupt delay service start time (ie dsr_cycle = dsr_end – dsr_start). At this point, all interrupt processing is completed, and the interrupt processing time is isr_latency + isr_cycle + dsr_latency + dsr_cycle. The total interrupt processing time is the last interrupt processing time plus the current interrupt processing time (ie isr_total = isr_total(last) + isr_latency + isr_cycle+ dsr_latency + dsr_cycle).
[0115] S205: Determine the interruption duration based on the first duration, the second duration, and the third duration.
[0116] Specifically, the interruption duration is determined by accumulating the first duration, the second duration, and the third duration.
[0117] In a specific optional implementation, after step S205, that is, after the step of determining the interruption duration based on the first duration, the second duration, and the third duration, the method for counting interruptions of an embedded real-time operating system further includes:
[0118] For the embedded interrupt, the number of interrupts and the interruption duration corresponding to each interruption are obtained, and the total duration is determined based on the interruption duration corresponding to each interruption.
[0119] In a specific optional implementation, after step S205, that is, after the step of determining the interruption duration based on the first duration, the second duration, and the third duration, the method for counting interruptions of an embedded real-time operating system further includes:
[0120] Obtain the number of interrupts and the interrupt information of each interrupt, including the interrupt type number, interrupt service routine, first time consumption, second time consumption and third time consumption;
[0121] Perform statistical analysis based on the number of interruptions and the interruption information when each interruption occurs to determine whether there is an abnormal interruption.
[0122] Specifically, by checking the real-time operating system interrupt statistics. These statistics include the type of interrupt, the number of occurrences, interrupt services, delayed services, the processing time of each interrupt service, the processing time of each delayed service, and the total processing time of each interrupt type. By analyzing these statistics, we can understand the system's interrupt pattern and identify possible performance bottlenecks, thereby optimizing the system. If we find that interrupts of a specific hardware device occur frequently, we may need to check whether there is a problem with the device driver or whether there is a hardware failure. Or if we find that a large number of delayed service processes are frequently generated, we may need to optimize the code of this task and reduce unnecessary task scheduling.
[0123] In this embodiment, when an interrupt is detected, the interrupt type number is obtained; the interrupt service routine corresponding to the interrupt type number is called as the target interrupt routine, and the time taken for the target interrupt routine to respond is recorded as the first time; when the target interrupt routine is detected to have ended, the time taken for the target interrupt routine is calculated as the second time; the target interrupt routine is exited, the delayed service routine is started, and the time taken for the delayed service routine is calculated as the third time; and the interrupt time is determined based on the first, second, and third time. This method achieves the goal of accurately counting interrupt information without disrupting the interrupt processing flow and with little impact on the original system. It not only accurately counts interrupt information, but is also simple to implement, consumes few resources, and is highly portable between different real-time operating systems.
[0124] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0125] Figure 3 The principle block diagram of the embedded real-time operating system interrupt statistics device is shown in one-to-one correspondence with the embedded real-time operating system interrupt statistics method in the above embodiment. Figure 3 As shown, the embedded real-time operating system interrupt statistics device includes a first acquisition module 31, a start timing module 32, an interrupt timing module 33, a delay timing module 34 and a time-consuming determination module 35. The functional modules are described in detail as follows:
[0126] A first acquisition module 31 is used to obtain an interrupt type number when an interrupt is detected;
[0127] The timing module 32 is started to call the interrupt service program corresponding to the interrupt type number as the target interrupt program, and record the response time of the target interrupt program as the first time;
[0128] An interrupt timing module 33 is configured to count the time consumed by the target interrupt program as a second time consumed when detecting that the target interrupt program has ended;
[0129] The delay timing module 34 is used to exit the target interrupt program, start executing the delay service program, and count the time consumed by the delay service program as the third time consumption;
[0130] The time consumption determining module 35 is configured to determine the interruption time consumption based on the first time consumption, the second time consumption and the third time consumption.
[0131] Optionally, the start timing module 32 includes:
[0132] An entry acquisition unit is used to obtain, according to the interrupt type number, an entry address of an interrupt service program corresponding to the interrupt type number from a preset interrupt vector table as a target entry address;
[0133] A first moment recording unit, configured to enter a target entry address to start a target interrupt program, and record the moment as a first moment T1;
[0134] A second time recording unit, configured to record the time when it is detected that the target interrupt program responds successfully as a second time T2;
[0135] The first time consumption calculation unit is configured to determine a first time consumption according to the first time T1 and the second time T2.
[0136] The specific limitations of the embedded real-time operating system interrupt statistics device can be found in the limitations of the embedded real-time operating system interrupt statistics method described above and will not be further elaborated here. Each module in the aforementioned embedded real-time operating system interrupt statistics device can be implemented in whole or in part through software, hardware, or a combination thereof. Each of these modules can be embedded in or independent of a processor in a computer device in hardware form, or can be stored in a computer device memory in software form, so that the processor can call and execute the corresponding operations of each of these modules.
[0137] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0138] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 4 with components connected to the memory 41, the processor 42, and the network interface 43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0139] The computer device may be a desktop computer, notebook computer, PDA, cloud server, etc. The computer device may interact with the user via a keyboard, mouse, remote control, touchpad, or voice control device.
[0140] The memory 41 includes at least one type of readable storage medium, including flash memory, a hard disk, a multimedia card, card-type memory (e.g., SD or D-interface display memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic storage, a magnetic disk, an optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as the hard disk or internal memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash memory card, etc. Of course, the memory 41 may also include both the internal storage unit and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as the program code of the interrupt statistics method of the embedded real-time operating system. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0141] In some embodiments, the processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to execute program code stored in the memory 41 or process data, such as executing program code for an interrupt statistics method in an embedded real-time operating system.
[0142] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0143] The present application also provides another embodiment, namely, providing a computer-readable storage medium, which stores an interface display program, and the interface display program can be executed by at least one processor to enable the at least one processor to perform the steps of the above-mentioned embedded real-time operating system interrupt statistics method.
[0144] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of this application, or the part that contributes to the existing technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of this application.
[0145] Obviously, the embodiments described above are only some of the embodiments of the present application, rather than all of the embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions described in the aforementioned specific embodiments, or to make equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the present application specification and the accompanying drawings, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present application.
Claims
1. A method for counting interrupts in an embedded real-time operating system, characterized in that: include: When an interrupt is detected, the interrupt type number is obtained; Calling the interrupt service routine corresponding to the interrupt type number as the target interrupt routine, and recording the response time of the target interrupt routine as the first time consumption; When detecting that the target interrupt program ends, counting the time consumed by the target interrupt program as a second time consumed; Exit the target interrupt program, start executing the delay service program, and count the time consumed by the delay service program as the third time consumption; Determining an interruption duration based on the first duration, the second duration, and the third duration; The calling of the interrupt service routine corresponding to the interrupt type number as the target interrupt routine further includes: updating the interrupt service processing unfinished flag and the delayed service processing unfinished flag, setting the interrupt service processing unfinished flag, and clearing the interrupt delay unfinished flag; The interrupt service program corresponding to the interrupt type number includes a first interrupt service function, a second interrupt service function, a delayed interrupt service processing function, and a thread function, and the first interrupt service function has a higher priority than the second interrupt service function; The step of counting the time consumed by the target interrupt program as the second time consumed upon detecting that the target interrupt program ends includes: If the interrupt service program is the delayed interrupt service processing function, then executing the step of exiting the target interrupt program, starting to execute the delayed service program, and counting the time consumed by the delayed service program as a third time-consuming step; If the interrupt service routine is the second interrupt service function, the total interrupt time statistics are updated to be the total interrupt time of the previous interrupt plus the current interrupt processing time; If the interrupt service program is a thread, an interrupt processing incomplete flag is added, and an interrupt delay incomplete flag is cleared.
2. The method for counting interrupts of an embedded real-time operating system according to claim 1, wherein: The calling of the interrupt service routine corresponding to the interrupt type number as the target interrupt routine, and recording the response time of the target interrupt routine as the first time consumption includes: According to the interrupt type number, obtaining an entry address of an interrupt service program corresponding to the interrupt type number from a preset interrupt vector table as a target entry address; Enter the target entry address to start the target interrupt program, and record the time at this time as the first time T1; When detecting that the target interrupt program responds successfully, recording the time at this time as the second time T2; The first duration is determined according to the first time T1 and the second time T2.
3. The method for counting interrupts of an embedded real-time operating system according to claim 1, wherein: The step of exiting the target interrupt program, starting to execute the delayed service program, and counting the time consumed by the delayed service program as the third time consumed includes: When the instruction to start executing the delayed service program is issued, the time at this time is recorded as the third moment T3; When it is detected that the delayed service program responds successfully, the time at this moment is recorded as the fourth time T4; Determining the startup time of the delayed service program according to the third time T3 and the fourth time T4; After the delayed service program ends, the time at this time is recorded as the fifth time T5; Determining the execution time of the delayed service program according to the fourth time T4 and the fifth time T5; The third time duration is determined based on the startup time duration and the execution time duration.
4. The method for counting interrupts of an embedded real-time operating system according to any one of claims 1 to 3, wherein: After the step of determining the interruption duration based on the first duration, the second duration, and the third duration, the method for counting interruptions of an embedded real-time operating system further includes: For the embedded interrupt, the number of interrupts and the interruption duration corresponding to each interruption are obtained, and the total duration is determined based on the interruption duration corresponding to each interruption.
5. The method for counting interrupts of an embedded real-time operating system according to any one of claims 1 to 3, wherein: After the step of determining the interruption duration based on the first duration, the second duration, and the third duration, the method for counting interruptions of an embedded real-time operating system further includes: Obtain the number of interrupts and the interrupt information when each interrupt occurs, wherein the interrupt information includes the interrupt type number, the interrupt service routine, the first time consumption, the second time consumption and the third time consumption; Statistical analysis is performed based on the number of interruptions and interruption information when each interruption occurs to determine whether there is an abnormal interruption.
6. An embedded real-time operating system interrupt statistics device, characterized in that: The method for counting interrupts of an embedded real-time operating system according to any one of claims 1 to 5 is executed, wherein the device comprises: A first acquisition module is used to obtain an interrupt type number when an interrupt is detected; Start a timing module, which is used to call the interrupt service program corresponding to the interrupt type number as the target interrupt program, and record the response time of the target interrupt program as the first time consumption; an interrupt timing module, configured to count the time consumed by the target interrupt program as a second time consumed when detecting that the target interrupt program has ended; A delay timing module is used to exit the target interrupt program, start executing the delay service program, and count the time consumed by the delay service program as the third time consumption; The time consumption determining module is used to determine the interruption time consumption based on the first time consumption, the second time consumption and the third time consumption.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method for counting interruptions of an embedded real-time operating system according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for counting interruptions of an embedded real-time operating system according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method and system for measuring interruption duration of embedded system at high precision and medium
CN114489801A
Network card receiving soft interrupt delay monitoring method and device under Linux system
CN118368222A