CN116225820A - Method, device, electronic equipment and storage medium for monitoring interrupt state - Google Patents

Method, device, electronic equipment and storage medium for monitoring interrupt state Download PDF

Info

Publication number
CN116225820A
CN116225820A CN202211104756.1A CN202211104756A CN116225820A CN 116225820 A CN116225820 A CN 116225820A CN 202211104756 A CN202211104756 A CN 202211104756A CN 116225820 A CN116225820 A CN 116225820A
Authority
CN
China
Prior art keywords
interrupt
target
function
monitoring
state
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211104756.1A
Other languages
Chinese (zh)
Inventor
黄自江
郭天泽
邹操
杨伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guoke Chushi Chongqing Software Co ltd
Original Assignee
Guoke Chushi Chongqing Software Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guoke Chushi Chongqing Software Co ltd filed Critical Guoke Chushi Chongqing Software Co ltd
Priority to CN202211104756.1A priority Critical patent/CN116225820A/en
Publication of CN116225820A publication Critical patent/CN116225820A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3024Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a central processing unit [CPU]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The disclosure relates to a method, a device, an electronic device and a storage medium for monitoring an interrupt state, wherein the method comprises the following steps: interrupt monitoring is carried out on the CPU; in response to the CPU being monitored to enter an interrupt state, obtaining an interrupt identifier and an interrupt type of an interrupt source which causes the interrupt state; calling a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, wherein the target interrupt hook function is used for ending calling when the CPU exits from the interrupt state; and determining the interrupt operation time length corresponding to the interrupt identifier according to the call information of the target interrupt hook function. The interrupt running time is used for indicating the running time of the interrupt triggered by each interrupt identifier in the kernel mode, so that finer-granularity interrupt state information can be conveniently provided for a user, and convenience is provided for a system developer to self-test the interrupt running time and adjust an interrupt processing function according to the self-test interrupt running time.

Description

Method, device, electronic equipment and storage medium for monitoring interrupt state
Technical Field
The present disclosure relates to the field of operation and maintenance monitoring of operating systems, and in particular, to a method, an apparatus, an electronic device, and a storage medium for monitoring an interrupt status.
Background
The real-time operating system is an operating system which can receive and process external events or data quickly enough, and the processing result can control the production process or make a quick response to the processing system within a specified time and control all real-time tasks to run in a coordinated and consistent manner. For example, an embedded hard real-time operating system RT (real time) -Linux system is used as a real-time operating system, and has been widely used in the fields of industrial automation control, aerospace, instrument measurement and control, movie trick image processing, communication equipment, and the like.
The operating system is provided with an interrupt mechanism, and the kernel utilization efficiency is improved through the interrupt mechanism. The Central Processing Unit (CPU) comprises two states, namely a user state and a kernel state, wherein the kernel state runs an operating system program and operates hardware; the user mode runs the user program, and the interrupt mechanism is a mechanism for triggering the user mode to switch to the kernel mode.
In the related art, the monitoring statistics of interrupts of an operating system are based on an operation and maintenance tool or a performance monitoring tool, and the current operation and maintenance tool or the performance monitoring tool are all used for monitoring and counting interrupts of the utilization rate of a CPU occupied by hard interrupts or soft interrupts of an electronic device (such as a computer or a server).
Disclosure of Invention
The embodiment of the disclosure provides a method, a device, electronic equipment and a storage medium for monitoring interrupt states.
According to a first aspect of embodiments of the present disclosure, a method of monitoring an interrupt condition is provided. The method comprises the following steps: interrupt monitoring is carried out on the CPU; in response to the CPU being monitored to enter an interrupt state, obtaining an interrupt identifier and an interrupt type of an interrupt source which causes the interrupt state; calling a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, wherein the target interrupt hook function is used for ending calling when the CPU exits from the interrupt state; and determining the interrupt operation time length corresponding to the interrupt identifier according to the call information of the target interrupt hook function.
In some embodiments, the call information includes: a start call time and an end call time. Determining the interrupt operation duration corresponding to the interrupt identifier according to the call information of the target interrupt hook function, including: and calculating a difference value between the ending calling time and the starting calling time of the target interrupt hook function, wherein the difference value is used as an interrupt running time corresponding to the interrupt identifier.
In some embodiments, the interrupt types include: hardware interrupt type, software interrupt type and timer interrupt type; the interrupt hook function in the kernel interface function library is associated with an interrupt type identifier. The calling the target interrupt hook function corresponding to the interrupt type from the predefined kernel interface function library comprises the following steps: screening a matched interrupt type identifier matched with the interrupt type from the kernel interface function library; determining an interrupt hook function corresponding to the matched interrupt type identifier as the target interrupt hook function; the target interrupt hook function is called.
In some embodiments, the above method further comprises: monitoring the function execution state of the operating system after entering the interrupt state, wherein the function execution state comprises a state of executing a target interrupt processing function, and the target interrupt processing function is an interrupt processing function corresponding to the interrupt identifier; and determining the function operation time length and the function operation times of the target interrupt processing function according to the function execution state.
In some embodiments, the above method further comprises: storing the interrupt identifier and the corresponding interrupt running time to a kernel memory cache area; accumulating interrupt operation time lengths of a plurality of interrupt states stored in the kernel memory buffer area to obtain accumulated interrupt operation time lengths; and counting the target interrupt operation time length meeting the preset condition in the interrupt states, and at least one of interrupt identification or interrupt processing function corresponding to the target interrupt operation time length.
In some embodiments, the above method further comprises: receiving a monitoring object selection instruction, wherein the monitoring object selection instruction comprises one or more of a first selection instruction and a second selection instruction, the first selection instruction is an instruction for monitoring a first target interrupt state, and the first target interrupt state is an interrupt state corresponding to a preset interrupt identifier or a preset interrupt type; the second selection instruction is an instruction for monitoring a second target interrupt state in which the interrupt operation duration exceeds a set threshold value; in response to the first selection instruction, calling a target interrupt hook function corresponding to the interrupt type of the first target interrupt state from a predefined kernel interface function library; responding to the second selection instruction, and determining a second target interrupt state corresponding to the target interrupt operation duration of which the interrupt operation duration exceeds the set threshold; and obtaining the interrupt identification, the user state stack information, the kernel state stack information and the running time stamp of the second target interrupt state.
In some embodiments, the above method further comprises: receiving a monitoring control instruction, wherein the monitoring control instruction comprises: monitoring a start instruction and a stop instruction; wherein, the interrupt monitoring for the CPU includes: and in the monitoring period corresponding to the monitoring start instruction and the monitoring stop instruction, carrying out interrupt monitoring on the CPU.
In some embodiments, the monitoring control instructions further include: monitoring result output instructions carrying: screening conditions for the target output object, wherein the screening conditions are used for limiting at least one of interrupt identification, interrupt type or interrupt operation duration of the target output object; the method further comprises the following steps: and acquiring an interrupt state monitoring result aiming at the target output object from the kernel memory buffer area according to the screening condition.
According to a second aspect of embodiments of the present disclosure, an apparatus for monitoring an interrupt condition is provided. The device comprises: the system comprises an interrupt monitoring module, an information acquisition module, a calling module and an interrupt operation duration determining module. The interrupt monitoring module is used for monitoring the interrupt of the CPU. The information acquisition module is used for responding to the detection that the CPU enters an interrupt state and acquiring an interrupt identifier and an interrupt type of an interrupt source which causes the interrupt state. The calling module is used for calling a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, and the target interrupt hook function is used for ending calling when the CPU exits from the interrupt state. The interrupt operation duration determining module is used for determining the interrupt operation duration corresponding to the interrupt identifier according to the calling information of the target interrupt hook function.
According to a third aspect of embodiments of the present disclosure, there is provided an electronic device, comprising: a processor; a memory for storing the processor-executable instructions; the processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the method for monitoring interrupt status provided in the first aspect of the present disclosure.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the method of monitoring interrupt status provided by the first aspect of the present disclosure.
The technical scheme provided by the embodiment of the disclosure can comprise the following beneficial effects:
the target interrupt hook function triggers the call when entering the interrupt state and finishes the call when the CPU exits the interrupt state, and the interrupt operation time length corresponding to the interrupt identifier can be determined according to the call information of the target interrupt hook function, so that the interrupt operation time length of the interrupt state corresponding to each interrupt source under each type can be counted, the interrupt operation time length is used for indicating the operation time length of the interrupt triggered by each interrupt identifier in the kernel state, the user can conveniently provide interrupt state information with finer granularity, and the system developer can self-test the interrupt operation time length and accordingly adjust the interrupt processing function.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure.
FIG. 1 is a system architecture diagram illustrating a method of monitoring interrupt status according to an exemplary embodiment.
FIG. 2 is a flowchart illustrating a method of monitoring interrupt status according to an exemplary embodiment.
Fig. 3 is a detailed implementation flowchart of step S230, shown according to an exemplary embodiment.
Fig. 4 is a schematic diagram illustrating an implementation procedure of step S240 according to an exemplary embodiment.
FIG. 5 is a flowchart illustrating a method of monitoring interrupt status according to another exemplary embodiment.
Fig. 6 is a flowchart illustrating a method of monitoring interrupt status according to yet another exemplary embodiment.
FIG. 7 is a schematic diagram illustrating an implementation of a method of monitoring interrupt status, according to an example embodiment.
FIG. 8 is a block diagram illustrating an apparatus for monitoring interrupt status according to an exemplary embodiment.
Fig. 9 is a block diagram of an electronic device, according to an example embodiment.
Detailed Description
Exemplary embodiments will be described in detail below with reference to the accompanying drawings.
It should be noted that the related embodiments and the drawings are only for the purpose of describing exemplary embodiments provided by the present disclosure, and not all embodiments of the present disclosure, nor should the present disclosure be construed to be limited by the related exemplary embodiments.
It should be noted that the terms "first," "second," and the like, as used in this disclosure, are used merely to distinguish between different steps, devices, or modules, and the like. Relational terms are used not to indicate any particular technical meaning nor sequence or interdependence between them.
It should be noted that the modifications of the terms "one", "a plurality", "at least one" as used in this disclosure are intended to be illustrative rather than limiting. Unless the context clearly indicates otherwise, it should be understood as "one or more".
It should be noted that the term "and/or" is used in this disclosure to describe an association between associated objects, and generally indicates that there are at least three associations. For example, a and/or B may at least represent: a exists independently, A and B exist simultaneously, and B exists independently.
It should be noted that the various steps recited in the method embodiments of the present disclosure may be performed in a different order and/or performed in parallel. The scope of the present disclosure is not limited by the order of description of the steps in the related embodiments unless specifically stated.
It should be noted that, all actions for acquiring signals, information or data in the present disclosure are performed under the condition of conforming to the corresponding data protection rule policy of the country of the location and obtaining the authorization given by the owner of the corresponding device.
Description of technical terms
Operating system (operating system): is a set of interrelated system software programs that hosts and controls the operation, scheduling and running of hardware resources, software resources, and provides common services to organize user interactions.
Central Processing Unit (CPU): the electronic device is an operation core and a control core of the electronic device, and is a final execution unit for information processing and program running. The central processing unit comprises an arithmetic logic unit, a register unit, a control unit and the like, and has the functions of processing instructions, executing operations, controlling time, processing data and the like.
Interrupt source: the cause of the interrupt, or the source from which the interrupt request signal can be sent, is collectively referred to as the interrupt source. Interrupt sources may include, but are not limited to: external interface devices request interrupts (belonging to the hardware interrupt type), fault forced interrupts (belonging to the hardware interrupt type), real-time clock request interrupts (belonging to the timer interrupt type), program voluntary interrupts (belonging to the software interrupt type), and the like.
Wherein an interrupt event is one way of interrupting the source. In some scenarios, after an interrupt event occurs, the interrupt state may not be entered (e.g., by masking), i.e., not responded to. For example, some maskable interrupt events enter the CPU via an INTR (identification of a pin) signal line, and for maskable interrupt events generated by external hardware devices, the CPU may or may not be taken into account (enter interrupt state), since such interrupts do not cause the operating system to crash.
In other scenarios, after an interrupt event occurs, the CPU must enter an interrupt state and cannot be masked, i.e., must respond to the interrupt event, the CPU does not continue to execute the previous user mode process, but transitions to a kernel mode, where an interrupt handler (which may also be described as an interrupt handling function) is executed by the operating system. For example, some interrupt events such as power down, memory read-write errors, bus parity errors, etc., may enter the CPU through the NMI (identification of another pin) signal line.
Hardware interrupts and software interrupts are two types of interrupts, and in addition to the two types of hardware interrupts and software interrupts, the type of timer interrupts is involved in the embodiments of the present disclosure.
Software interrupt (software irq): software may trigger any VIC interrupt by writing the appropriate Vector Interrupt Controller (VIC) and status register (CSR). Software may trigger interrupts that are connected to any hardware interrupt source, as well as interrupts that are not connected to hardware, including software emulating hardware interrupt implementations.
Hardware interrupt (hardware irq): executing upon occurrence of an associated hardware interrupt event, the programs in the hardware interrupt Organization Block (OB) may be responded to and executed quickly (e.g., immediately stopping certain critical devices).
Timer interrupt: refers to the type of interrupt triggered at the end of the timer countdown.
Interrupt handler/function: in response to an interrupt, the kernel executes a corresponding function, referred to as an interrupt handling function, or interrupt handling function.
FIG. 1 is a system architecture diagram illustrating a method of monitoring interrupt status according to an exemplary embodiment.
Referring to fig. 1, a system architecture 100 suitable for a method for monitoring interrupt status provided in an embodiment of the present disclosure includes: a CPU 101, an operating system (operating system) 102, an external interface device 103, and an application 104.
The CPU 101 has two states: user mode and kernel mode, in which programs of the operating system 102 (which may be described as operating system programs) operate in hardware. A program (which may be described as an application program) of the application 104 is run in a user state.
The kernel mode is capable of running privileged instructions and the user mode is capable of running non-privileged instructions.
Privileged instructions may only be used by operating system 102 and applications 104 may not be used, such as: an enable input/output (I/O) memory clear instruction, a modify program status word instruction, a set clock instruction, an enable/disable terminal instruction, a shutdown instruction, etc. all belong to the privileged instructions.
Non-privileged instructions are instructions that application 104 is able to use. Such as control transfer instructions, arithmetic instructions, fetch instructions, etc., belong to non-privileged instructions.
Applications running in the user state cannot directly access kernel data structures and programs in the operating system. Privilege levels may be represented by a privilege ring: r0 (R represents a privilege Ring, the numbers represent the level numbers, and the meanings of R1, R2 and R3 are the same later), R1, R2 and R3, R0 corresponds to the kernel mode, and R3 corresponds to the user mode; different levels can run different instruction sets. Typically, some hardware drivers, system kernel modules, have an R0 privilege level, and programs running at the R0 privilege level have direct address level access to all hardware.
When an application is executed in the system, most of the time, some non-privileged instructions are executed in the user state; the switch to kernel mode occurs when the operating system is required to help complete a job (e.g., operating hardware) that some applications have no authority or capability to complete.
When the interrupt source triggers an interrupt, the CPU is caused to switch from the user mode to the kernel mode. For example, referring to FIG. 1, in some embodiments, when a hardware interrupt or a software interrupt triggers an interrupt from these types of interrupt sources, the CPU will save the context of the currently executing application program into a stack, go to kernel state, and execute the interrupt handler (or be described as an interrupt handling function) by the operating system.
The system architecture 100 may be an architecture that an electronic device has a CPU 101 and an operating system 102, has an external interface device 103 connected thereto, and has an application 104 installed.
Operating systems include, but are not limited to, windows, linux, mac and the like, including, for example, various real-time operating systems: industrial control system, information inquiry system, multimedia system, embedded system, etc., can be specifically: windows, vxWorks, linux, muClinux, muC/OS-II, eCos, freeRTOS, bed OS, RTX, QNX, nuttX, city river weir operating System (djyos), alios thins, RT-Thread, sylixOS, etc.
The real-time operation system is that the system can respond to the external request in time, finish the processing of the external request in a specified time and control all real-time tasks to run in a coordinated and consistent way.
The external interface device includes: input devices such as a mouse, keyboard, scanner, voice input system, digital camera system, handwriting revenue system, etc.); output devices such as a display screen, a printer, a plotter, a floppy disk memory, a hard disk memory, an external storage device, and the like; multimedia devices such as optical disk drives, sound cards, speakers, video cards, cameras, etc.; network devices such as network cards, hubs, routers, modems, gateways, switches, and the like.
The method for monitoring interrupt status provided by the embodiments of the present disclosure may be performed by the electronic device having the system architecture 100 described above.
Exemplary method
The current interrupt monitoring has thicker fine granularity, and cannot meet the more refined interrupt monitoring requirement of users.
FIG. 2 is a flowchart illustrating a method of monitoring interrupt status according to an exemplary embodiment. Referring to fig. 2, a method for monitoring interrupt status according to an embodiment of the present disclosure includes the following steps: s210, S220, S230 and S240. The method may be performed by an electronic device, which may be a terminal device or a server. The electronic device may be a computer device, including: notebook computers, desktop computers, tablet computers, etc., may also be smart cars, smart phones, smart watches, etc., and may also be service clusters or service nodes. In an electronic device, there may be one or more CPUs.
In step S210, the CPU is subjected to interrupt monitoring.
An interrupt is a description of an operating state in which a processor is located. In some embodiments, it may be determined whether each CPU is in an interrupt state by monitoring the state in which the corresponding monitored CPU is in.
The trigger source of the interrupt is described as an interrupt source, one embodiment of which is an interrupt event or interrupt request signal. For example, hardware interrupt events include maskable interrupt events and non-maskable interrupt events, the hardware interrupt events including: rising and falling edge events of the built-in digital input and High Speed Counter (HSC) events. When a hardware interrupt event occurs, the hardware interrupt is triggered, and the normal loop program is interrupted to execute the interrupt processing function of the hardware interrupt preferentially. The user may define hardware interrupt events in advance in the attributes of the hardware configuration, one hardware interrupt event allowing only one corresponding hardware interrupt, and one hardware interrupt may be allocated to a plurality of hardware interrupt events.
The interrupt sources also include software interrupt request instructions/signals, timer interrupt request signals, and the like.
For example, interrupt event X 1 To mask interrupt event X 1 After occurrence, by monitoring the state of each CPU, determining whether the corresponding monitored CPU is directed at the interrupt event X 1 An interrupt response is performed.
For example, in an exemplary embodiment, CPU status is monitored and interrupt event X is received at the CPU 1 Corresponding interrupt request signal INTx 1 If the CPU is monitored to be switched from the user mode to the kernel mode, starting to run the kernel program or operating hardware, and regarding the CPU to enter an interrupt state.
As an example, interrupt event X 1 The method comprises the following steps: when the network card receives the data packet from the network, the kernel data packet needs to be informed that the data packet arrives, and the network card needs to send an interrupt request signal INTRx to the CPU 1 At this time, the interrupt request signal INTRx 1 Sent to interrupt controller via bus, if CPU is to interrupt event X 1 Without masking, the interrupt controller will interrupt the request signal INTRx 1 To pins of the CPU (which, if masked, would be masked by the interrupt controller, would not be transmitted to pins of the CPU), based on the interrupt request signal INTRx 1 The CPU will switch to kernel mode, at this time it can be determined whether the CPU enters the interrupt state according to the monitored CPU state. After entering the interrupt state, the CPU calls the interrupt event X 1 And the corresponding interrupt processing program performs interrupt processing.
In an exemplary embodiment, CPU status is monitored and interrupt event X is received at the CPU 2 Corresponding interrupt request signal NMIx (e.g. as a non-maskable hardware interrupt) 2 If it is monitored that the CPU is switched from the user mode to the kernel mode, the CPU is regarded as entering the interrupt state.
In an exemplary embodiment, CPU status is monitored while the CPU is executing current application X 3 Is read into the Vector Interrupt Controller (VIC) or the status register (CSR) (the interrupt instruction is executed by the application X 3 Writing into the VIC or CSR, belonging to the type of software interrupt), if the CPU is monitored to be switched from the user state to the kernel state, the CPU is considered to enter the interrupt state.
In an exemplary embodiment, the electronic device is required to perform timing detection and control of the controlled hardware, and therefore a clock circuit (programmable) is used to control the time interval, and in the case of timing, the CPU issues a command to start the operation of the clock circuit, and once a specified time is reached, the clock circuit issues an interrupt request signal X to the CPU 4 The CPU responds to the interrupt request signal X 4 The CPU is switched from the user state to the kernel state, and whether the CPU enters the interrupt state can be determined through monitoring the CPU state. In the interrupt state, the CPU completes the detection and control of the controlled hardware And (5) manufacturing work.
In step S220, in response to detecting that the CPU enters an interrupt state, an interrupt identifier and an interrupt type of an interrupt source that causes the interrupt state are acquired.
The interrupt state refers to a state in which the CPU stops executing a user process being processed due to the triggering of the interrupt source, the user state is switched to the kernel state, and the operating system executes an interrupt processing function to perform interrupt processing.
In some embodiments, entering the interrupt state is represented as: after the interrupt source occurs, the CPU stops executing the state corresponding to the user process. For example, if it is monitored that the CPU stops executing the user process currently being processed, it is considered that the CPU is monitored to enter an interrupt state.
In other embodiments, entering the interrupt state is represented as: after the interrupt source occurs, the CPU stops executing the user process, and the operating system starts executing the initial state of the interrupt handling function, in which case the interrupt running duration is equal to the running duration of the interrupt handling function. For example, if it is monitored that the CPU has saved information about the interrupted user process and the operating system begins executing the interrupt handling function, it is considered that the CPU is monitored to enter an interrupt state.
The interrupt identifier is an identity that facilitates the operating system to distinguish between different interrupt sources. For example, when an external interface device (for short, a peripheral device) performs an I/O operation, an interrupt request signal is randomly generated, and a specific identifier is in the interrupt request signal, so that a computer can determine which device makes an interrupt request, and the identifier of the signal is called an interrupt identifier and may also be described as an interrupt number.
Interrupt type refers to the type to which the interrupt source that originated the interrupt belongs, including but not limited to: the hardware interrupt type, the software interrupt type, the timer interrupt type and the like can be specifically referred to the description in the previous technical term.
In step S230, a target interrupt hook function corresponding to the interrupt type is called from a predefined kernel interface function library, and the target interrupt hook function is used to end the call when the CPU exits the interrupt state.
In some embodiments, the interrupt hook functions predefined in the kernel interface function library are kernel interface functions that are adapted to different interrupt types. The kernel interface function may be regarded as an interface service for performing kernel operations, kernel monitoring, etc. by a user process (e.g., an application program), for example, the user process may access a corresponding kernel interface function by initiating a system call, perform kernel operations or kernel monitoring based on the kernel interface function, etc.
An interrupt Hook Function is a custom Hook Function (Hook Function) created to track interrupt status. A hook function is a program that processes system messages, hangs it into the operating system through system calls, and captures at system level event messages that will occur to processes in the operating system.
In some embodiments, the process of creating an interrupt hook function is as follows: creating a data structure in the memory, configuring definition information serving as an interrupt hook function for the data structure, namely, creating the interrupt hook function after the data structure is configured, and adding the data structure after the data structure is configured into an existing kernel interface function library.
The definition information of the interrupt hook function includes call information, and the call information of the interrupt hook function includes: the calling occasion limits the calling occasion to the interrupt hook function when the interrupt source triggers the CPU to enter the interrupt state, and the calling is ended when the CPU exits the interrupt state. Each interrupt source triggers and enters an interrupt state, then a target interrupt hook function is started to be called, and based on the setting of the interrupt hook function, the interrupt operation duration of the interrupt state corresponding to each interrupt source can be accurately represented according to the calling process of the interrupt hook function, so that the fine granularity monitoring of the interrupt state is realized. In addition, as can be seen from the foregoing description about the user state and the kernel state in the system architecture 100, if the privilege level of a program is not at the R0 level (for example, the privilege levels of R1, R2, R3, etc.), no privilege is given to how the hardware changes, and in the related art, since the interrupt hook function provided by the embodiments of the present disclosure is not provided, only the percentage of the CPU occupied by the hard interrupt and the soft interrupt can be counted, and what the specific interrupt source corresponding to each interrupt is, what the specific information about each interrupt state is, for example, how long the interrupt runs, how long the interrupt processing function runs, and so on. In contrast, the embodiment of the disclosure enables an application program to access hardware information which cannot be accessed in a user state and fine granularity information of an interrupt, such as information of an interrupt running duration in a kernel state of a CPU, by setting an interrupt hook function and calling a corresponding type of target interrupt hook function when entering an interrupt state.
In step S240, an interrupt operation duration corresponding to the interrupt identifier is determined according to the call information of the target interrupt hook function.
Since the call information includes: the interrupt source is called under the condition that the CPU is triggered to enter an interrupt state, and the call is ended when the CPU exits the interrupt state, so that the interrupt operation time length corresponding to the interrupt identifier can be calculated according to the call information.
When the system is running, an interrupt occurs, and the running time of an interrupt processing function written by a system developer needs to be fixed within a certain time range, if the running time exceeds the certain time range, the running condition of the system can be influenced. The interrupt operation time length corresponding to the interrupt identifier is determined according to the call information of the target interrupt hook function, so that finer-granularity interrupt state information is conveniently provided for a user, and convenience is provided for system developers to self-test the interrupt operation time length and adjust the interrupt processing function according to the interrupt operation time length.
Each time an interrupt is entered and exited, there is an interrupt state and a corresponding interrupt source, and an interrupt state corresponds to a call to a target interrupt hook function, then the interrupt operation duration calculated according to the target interrupt hook function is associated with the interrupt identifier corresponding to the interrupt state.
In summary, in the method including steps S210 to S240, since the target interrupt hook function triggers the call when entering the interrupt state and ends the call when the CPU exits the interrupt state, the interrupt operation duration corresponding to the interrupt identifier can be determined according to the call information of the target interrupt hook function, so that the interrupt operation duration of the interrupt state corresponding to each interrupt source in each type can be counted, and the interrupt operation duration is used for indicating the operation duration of the interrupt triggered by each interrupt identifier in the kernel state, so that the interrupt operation duration is convenient for providing the user with interrupt state information with finer granularity, and convenience is provided for the system developer to self-test the interrupt operation duration and adjust the interrupt processing function according to the self-test interrupt operation duration.
Fig. 3 is a detailed implementation flowchart of step S230, shown according to an exemplary embodiment.
In some embodiments, the interrupt types include: hardware interrupt type, software interrupt type and timer interrupt type; the interrupt hook function in the kernel interface function library is associated with an interrupt type identifier.
Referring to fig. 3, in the step S230, a target interrupt hook function corresponding to the interrupt type is called from a predefined kernel interface function library, and the method includes the steps of: s310, S320 and S330.
In step S310, a matching interrupt type identifier that matches the interrupt type is screened from the kernel interface function library.
In step S320, the interrupt hook function corresponding to the matching interrupt type identifier is determined as the target interrupt hook function.
In step S330, the above-described target interrupt hook function is called.
For example, by executing the steps S310 to S330, the target interrupt hook function adapted to the hardware interrupt type is obtained as follows: trace_irq_handler functions, the trace_irq_handler functions include: hard interrupt hook entry function irq_handler_entry and hard interrupt hook exit function irq_handler_exit; the target interrupt hook function adapted to the software interrupt type is: trace_softirq function, trace_softirq function including soft interrupt hook entry function softirq_entry and soft interrupt hook exit function softirq_exit; the target interrupt hook function adapted to the timer interrupt type is: trace_timer_expire function, trace_timer_expire function includes: timer interrupt hook entry function timer_expire_entry and timer interrupt hook exit function timer_expire_exit.
The above-mentioned target interrupt hook function (e.g., definition information of the target interrupt hook function) defines instructions to be executed during the called period, specifically, the hook entry function and the hook exit function of each interrupt type define instructions to be executed by the interrupt hook function at the stage of starting and ending the call, including, for example, recording call information: the hook enters a function to record a time stamp when the call is started as an initial call time, and records an interrupt identifier corresponding to the call at the same time; the hook exit function records the time stamp at the end of the call as the end call time.
In the embodiment including steps S310 to S330, when defining each interrupt hook function in advance, different interrupt hook functions adapted to each interrupt type are associated in advance, so that what interrupt types corresponding to the interrupt can be identified in the process that each interrupt hook function is called by the system, and further, it is convenient to trace call information corresponding to different interrupt identifiers under each interrupt type.
In some embodiments, there is a common portion of the execution logic of each interrupt hook function, and specific data structures may have differences according to the write requirements. For example, both the hook entry function and the hook exit function of the hardware interrupt type and the software interrupt type require statistics of interrupt identifications and the number of interrupts corresponding to the same interrupt identifications. The hard interrupt hook exit function irq_handler_exit records an interrupt identifier and the corresponding interrupt times respectively, for example, a data structure adopted for recording the interrupt identifier is as follows: result.irq= (=means assignment operation, and the same will not be described later), irq_num, and the data structure used for recording the number of interrupts is: result.count (representing the statistics of the number of hard breaks) +=1.
The soft interrupt hook exit function softirq_exit takes an interrupt identifier as a variable of an interrupt frequency statistical function, and adopts a data structure as follows: result. Softirq_cnt [ nr_sirq ] + =1, wherein result. Softirq_cnt represents a soft break count function; nr_sirq represents the interrupt identification as a variable of the soft interrupt count function. In the above data structure, the meaning of + =1 is explained by the result.count+ =1, and the result.count+ =1 represents the accumulation of the result.count, and the value is calculated by: result.count (this) =result.count (last) +1. The same interrupt identifier is accumulated once every time the call occurs, so as to obtain the interrupt number corresponding to a certain interrupt identifier.
Similarly, the result. Softirq_cnt [ nr_sirq ] +=1 specific calculation procedure is:
result.softirq_cnt [ nr_sirq ] (this time) =result.softirq_cnt [ nr_sirq ] (last time) +1. Each time a call with the same interrupt identification occurs, the count is incremented once.
Based on the description of the above embodiments, the expression forms of the data structures of the interrupt hook functions under the same execution logic may have differences, so that it is able to identify what interrupt types correspond to the interrupts during the process that each interrupt hook function is called by the system by associating different interrupt hook functions adapted for different interrupt types, and further convenient to track call information corresponding to different interrupt identifiers under each interrupt type.
Fig. 4 is a schematic diagram illustrating an implementation procedure of step S240 according to an exemplary embodiment. FIG. 7 is a schematic diagram illustrating an implementation of a method of monitoring interrupt status, according to an example embodiment.
In some embodiments, the call information includes: a start call time and an end call time. In the step S240, determining, according to the call information of the target interrupt hook function, an interrupt operation duration corresponding to the interrupt identifier, including: and calculating a difference value between the ending calling time and the starting calling time of the target interrupt hook function, wherein the difference value is used as an interrupt running time corresponding to the interrupt identifier.
Referring to fig. 4 and 7, for example, during the running of an application program by a CPU, the CPU enters an interrupt due to an interrupt source, at which time the application program interrupts execution, the CPU calls a target interrupt hook function adapted to different interrupt types according to the difference of the hardware interrupt type, the software interrupt type and the timer interrupt type; when the CPU exits from the interrupt, the target interrupt hook function finishes calling, and the time stamps recorded by the entry (entry) function and the exit (exit) function in each target interrupt hook function are respectively the starting calling time and the ending calling time.
In some embodiments, the instructions in the target interrupt hook function may further include: the instruction for calculating the interrupt running time according to the call information is executed by, for example, hooking the exit function, and the specific calculation mode may be: and making a difference between the recorded ending calling time and the recorded starting calling time to obtain the interrupt running duration.
As an example, for a hardware interrupt type, call trace_irq_handler function, when an interrupt is entered, hard interrupt hook entry function irq_handler_entry records the current timestamp t 1 As a start call time cpu_irq_enter_time;
When the interrupt is exited, the hard interrupt hook exit function irq_handler_exit records the current timestamp t 2 As the end call time cpu_irq_exit_time, reference is made to the broken line in fig. 4.
The data structure of the hard interrupt hook exit function irq_handler_exit for calculating the interrupt running time of the current interrupt is, for example: result_irq_run_time (representing the interrupt running duration of the current interrupt of the hardware interrupt type) =current_time (cpu_irq_exit_time in this case) -cpu_irq_enter_time, i.e., t 2 -t 1 This difference is taken as the interrupt running duration of the current interrupt.
As an example, for a software interrupt type, call trace_softrq function, when an interrupt is entered, softinterrupt hook entry function softrq_entry records the current timestamp t 1 As a starting call time cpu_softiq_enter_time [ nr_sirq ]];
When the interrupt is exited, the soft interrupt hook exit function softrq_exit records the current timestamp t 2 As end call time cpu_softrq_exit_time [ nr_sirq]Reference is made to the dashed line in fig. 4.
The data structure of the soft interrupt hook exit function softirq_exit for calculating the interrupt running time of the current interrupt is as follows: result. Softirq run time [ nr sirq](interrupt run-time of current interrupt representing software interrupt type) =current_time (cpu_softrq_exit_time [ nr_sirq at this time) ])-cpu_softirq_enter_time[nr_sirq]I.e. t 2 -t 1 This difference is taken as the interrupt running duration of the current interrupt.
As an example, for the timer interrupt type, a trace_timer_expire function is called, and when an interrupt is entered, a timer interrupt hook entry function timer_expire_entry records the current timestamp t 1 As the starting call time cpu_timer_enter_time, an interrupt identifier corresponding to the interrupt source may also be recorded: a timer; when the interrupt is exited, the timer interrupt hook exit function timer_expire_exit records the current timestamp t 2 As the end call time cpu_timer_exit_time, reference is made to the broken line in fig. 4.
The data structure of the timer interrupt hook exit function timer_expire_exit for calculating the interrupt running time of the current interrupt is, for example: result. Timer_run_time (the duration of the interrupt running representing the current interrupt of the timer interrupt type) =current_time (in this case cpu_timer_exit_time) -cpu_timer_enter_time, i.e. t 2 -t 1 This difference is taken as the interrupt running duration of the current interrupt.
FIG. 5 is a flowchart illustrating a method of monitoring interrupt status according to another exemplary embodiment.
In other embodiments of the present disclosure, referring to fig. 5, the method includes the following steps in addition to the steps S210 to S240: s510 and S520.
In step S510, the function execution state of the operating system after entering the interrupt state is monitored, where the function execution state includes a state in which a target interrupt handling function is executed, and the target interrupt handling function is an interrupt handling function corresponding to the interrupt identifier.
In step S520, a function operation duration and a function operation number of the target interrupt handling function are determined according to the function execution state.
For example, in some embodiments, this step S510 is implemented based on the targeted interrupt hook function described above, or steps S510 and S520 are implemented. For example, the above instruction defined by the definition information of the interrupt hook function includes, in addition to: besides the call information and the calculation of the interrupt running time according to the call information, the method also comprises the following instructions: and monitoring the function execution state of the operating system after entering the interrupt state. Or further comprising the following: monitoring the function execution state of the operating system after entering the interrupt state; and determining the function operation time length and the function operation times of the target interrupt processing function according to the function execution state. For example, as shown in fig. 7, for simplicity of illustration, only the function operation duration and the function operation number obtained after the execution of the above steps S510 and S520 by the hard interrupt hook exit function irq_handler_exit are illustrated, and the function operation duration corresponding to the software interrupt type is not illustrated.
After entering the interrupt state, the CPU is in a kernel state, and in response to different interrupt sources, the operating system searches the address of a target interrupt processing function corresponding to the interrupt identifier from a register of the CPU, and calls the corresponding target interrupt processing function according to the address. The target interrupt hook function can determine the function running duration of the target interrupt processing function by monitoring the function execution state of the operating system, for example, when the operating system is monitored to start calling the target interrupt processing function, starting timing until the operating system executes the target interrupt processing function to finish, and ending timing, wherein the total timing duration of the time period is used as the function running duration of the target interrupt processing function in the current interrupt state. The number of function runs is determined based on the number of times the operating system calls the target interrupt handling function (which may be understood as the cumulative number of calls for the same target interrupt handling function).
In the embodiment, besides the interrupt operation time length corresponding to the interrupt identifier, the function operation time length and the function operation times of the target interrupt processing function can be monitored, so that richer interrupt state information is provided for a user, and a system developer can intuitively adjust the interrupt processing function according to the function operation time length.
Fig. 6 is a flowchart illustrating a method of monitoring interrupt status according to yet another exemplary embodiment.
In still other embodiments of the present disclosure, the method of monitoring the interrupt status includes the following steps in addition to the steps S210 to S240 described above or the steps S210 to S240, S510 and S520 described above: s610, S620, and S630, referring to fig. 6, only steps S610 to S630 are illustrated in fig. 6 for simplicity of illustration.
In step S610, the interrupt identifier and the corresponding interrupt running duration are stored in the kernel memory buffer.
For example, referring to fig. 7, the interrupt identifier result.irq of the hardware interrupt type and the corresponding hard interrupt running duration result.irq_run_time are stored in the kernel memory buffer 701; storing an interrupt identifier nr_sirq of the software interrupt type and a corresponding soft interrupt running duration result. Softirq_run_time [ nr_sirq ] into a kernel memory cache area 701; the interrupt identifier timer of the timer interrupt type and the corresponding timer interrupt running duration result. Timer_run_time are stored in the kernel memory buffer 701.
In step S620, the interrupt operation durations of the interrupt states stored in the kernel memory buffer area are accumulated, so as to obtain an accumulated interrupt operation duration.
In some embodiments, referring to fig. 7, for the hardware interrupt type, the accumulated interrupt running duration of the current CPU is counted, and the corresponding data structure is: result_total_run_time (accumulated interrupt running duration representing an interrupt of hardware interrupt type) +=current_time (end call time of interrupt: cpu_irq_exit_time) -cpu_irq_enter_time.
That is, result_total_run_time (accumulated interrupt operation duration of the current interrupt in the case of the hardware interrupt type) =result_irq_total_run_time (accumulated interrupt operation duration of the last interrupt in the case of the hardware interrupt type) +current_time (end call time of the current interrupt: cpu_irq_exit_time) -cpu_irq_enter_time.
In some embodiments, referring to fig. 7, for the software interrupt type, the accumulated interrupt running duration of the current CPU is counted, and the corresponding data structure is: result. Software_total_run_time [ nr_sirq ] (representing the cumulative interrupt running duration of an interrupt of the software interrupt type) +=current_time (end call time of interrupt: cpu_software_exit_time [ nr_sirq ]) -cpu_software_entry_time [ nr_sirq ].
That is, result. Softrq_total_run_time [ nr_sirq ] (accumulated interrupt operation duration of the current interrupt in the software interrupt type) =result. Softrq_total_run_time [ nr_sirq ] (accumulated interrupt operation duration of the last interrupt in the software interrupt type) +current_time (end call time of the current interrupt: cpu_softrq_exit_time [ nr_sirq ]) -cpu_softrq_enter_time [ nr_sirq ].
In some embodiments, referring to fig. 7, for the timer interrupt type, the accumulated interrupt running duration of the current CPU is counted, and the corresponding data structure is: result. Timer_total_run_time (the accumulated interrupt running duration representing the interrupts of the timer interrupt type) +=current_time (the end call time of the interrupt: cpu_timer_exit_time) -cpu_timer_enter_time.
Namely, result. Timer_total_run_time (accumulated interrupt operation duration of the current interrupt in the timer interrupt type) =result. Timer_total_run_time (accumulated interrupt operation duration of the last interrupt in the timer interrupt type) +current_time (end call time of the current interrupt: cpu_timer_exit_time) -cpu_timer_enter_time.
In step S630, the target interrupt operation duration satisfying the preset condition in the plurality of interrupt states and at least one of the interrupt identifier or the interrupt processing function corresponding to the target interrupt operation duration are counted.
In some embodiments, the preset conditions include one or more of the following for a hardware interrupt type, a software interrupt type, or a timer interrupt type:
counting the maximum interrupt operation time length in the interrupt states, and at least one of interrupt identification and interrupt processing function corresponding to the maximum interrupt operation time length;
Counting a second target interrupt state in which the interrupt running time length exceeds a set threshold value in the interrupt states, and at least one of an interrupt identifier and an interrupt processing function corresponding to the second target interrupt state;
and counting the target accumulated interrupt operation time length of which the accumulated interrupt operation time length corresponding to the adjacent interrupt states exceeds a set threshold value, and at least one of interrupt identification and interrupt processing function corresponding to the target accumulated interrupt operation time length.
For example, referring to fig. 7, for the hardware interrupt type, in the case where multiple interrupts occur, the maximum hard interrupt running duration result_max_irq.time and the corresponding interrupt identifier result_max_irq.irq within the multiple interrupt states are counted, where only the interrupt identifier is illustrated, and actually, the interrupt processing function corresponding to the maximum hard interrupt running duration may also be counted.
Referring to fig. 7, for the software interrupt type, under the condition that multiple interrupts occur, the maximum soft interrupt running duration and the corresponding interrupt identifier in multiple interrupt states are counted: result.max_sirq.time [ nr_sirq ], wherein the parameter nr_sirq inside the middle bracket represents the interrupt identifier corresponding to the function result.max_sirq.time [ ] of the maximum soft interrupt running duration.
Referring to fig. 7, for the timer interrupt type, in the case of multiple interrupts, the maximum timer interrupt running duration result.max_timer.time and the corresponding interrupt processing function (which is the callback function of the timer) result.max_timer_function in multiple interrupt states are counted.
In some embodiments, in embodiments including steps S210-S240, S510, and S520, the method may further include the steps of: storing the function operation time length and the function operation times of the target interrupt processing function into a kernel memory buffer area; according to the function operation time length and the function operation times, counting the target interrupt operation time length meeting the preset conditions in the interrupt states and at least one of interrupt identification or interrupt processing function corresponding to the target interrupt operation time length.
For example, in this embodiment, the preset conditions include one or more of the following conditions: the function operation time exceeds the set threshold value and the function operation times exceeds the set times.
On the basis of the above embodiments, referring to fig. 7, the execution body corresponding to each step may be a kernel monitoring module 700, where the kernel monitoring module 700 is configured to implement each step S210 to S240, S510 to S520, S610 to S630, etc., and in some embodiments, starting, stopping, and outputting results of the kernel monitoring module 700 are controlled by instructions sent by a user through a user mode control program.
For example, a user may send a monitoring control command through an application program (e.g., described as a user mode control program) to control the kernel monitoring module 700 to perform monitoring tasks according to instructions such as start (activate), stop (deactivate), result output (or described as report).
In these embodiments, the above method further comprises the steps of: s710a, S710b and S710c.
In step S710a, a monitoring control instruction is received, where the monitoring control instruction includes: and monitoring a starting instruction.
In step S710b, a monitoring control command is received, where the detecting control command includes: a stop instruction is monitored.
Wherein, the interrupt monitoring for the CPU includes: and in the monitoring period corresponding to the monitoring start instruction and the monitoring stop instruction, carrying out interrupt monitoring on the CPU. The steps S710a and S710b may be performed in two different periods or may be performed in the same period, for example, the user may input the time of monitoring start and the time of stopping in one control; or respectively inputting a monitoring start command and a monitoring stop command at the starting time and the time of the control period.
In step S710c, a monitoring control command is received, where the detecting control command includes: and outputting an instruction by the monitoring result.
The monitoring result output instruction carries: screening conditions for the target output object, wherein the screening conditions are used for limiting at least one of interrupt identification, interrupt type or interrupt operation duration of the target output object; the method further comprises the following steps: according to the screening condition, the interrupt status monitoring result for the target output object is obtained from the kernel memory buffer 701.
For example, the screening condition defines outputting a monitoring result of one or more interrupt states corresponding to the interrupt identifier, a monitoring result of one or more interrupt types, and a monitoring result of one or more interrupt states with interrupt operation time exceeding a set threshold.
In the embodiment, through interaction between the user mode control program and the kernel monitoring module, the kernel monitoring module executes the instructions controlled by the user in each step, and personalized customization can be realized according to the requirements of different users such as monitoring time periods, monitoring objects, monitoring conditions and the like.
In some embodiments, in embodiments that include the steps S710 a-S710 c described above or do not include the steps S710 a-S710 c described above, the method further includes step S720, and includes at least one of steps S731, S732.
In step S720, a monitoring object selection instruction is received, where the monitoring object selection instruction includes one or more of a first selection instruction and a second selection instruction; the first selection instruction is an instruction for monitoring a first target interrupt state, and the first target interrupt state is an interrupt state corresponding to a preset interrupt identifier or a preset interrupt type; the second selection instruction is an instruction for monitoring a second target interrupt state in which the interrupt operation duration exceeds a set threshold. For example, referring to FIG. 7, the kernel monitor module 700 receives a detection object selection instruction from a user mode control program.
In step S731, in response to the first selection instruction, a target interrupt hook function corresponding to the interrupt type of the first target interrupt state is called from a predefined kernel interface function library. In this step S731 is a specific embodiment of the foregoing step S230, where the preset interrupt type is a hardware interrupt type, and the target interrupt hook function corresponding to the hardware interrupt type is called from the predefined kernel interface function library, that is, the trace_irq_handler function described above, where the target interrupt hook function trace_irq_handler includes a hard interrupt hook entry function irq_handler_entry and a hard interrupt hook exit function irq_handler_exit, which are shown in fig. 7.
In step S732, a second target interrupt state corresponding to a target interrupt operation duration in which the interrupt operation duration exceeds the set threshold is determined in response to the second selection instruction; and obtaining the interrupt identification, the user state stack information, the kernel state stack information and the running time stamp of the second target interrupt state. For example, referring to fig. 7, the soft interrupt hook exit function softiq_exit in the trace_softiq function calculates that the interrupt running duration of a certain interrupt corresponding to the software interrupt type exceeds the set threshold, takes the interrupt running duration of the interrupt as a target interrupt running duration, and takes the corresponding interrupt state as a second target interrupt state, and obtains the interrupt identifier, the user state stack information, the kernel state stack information and the running timestamp of the second target interrupt state.
The scheme corresponding to step S732 may be a refined embodiment of the foregoing step S630.
In an embodiment, when the interrupt running duration exceeds a set threshold value, or the function running duration exceeds another set threshold value, the interrupt identifier, the user state stack information, the kernel state stack information and the running timestamp corresponding to the instant when the target interrupt state corresponds to the case are acquired, for example, the set threshold value is 10ms (millisecond), the interrupt running duration is 16ms, and under the condition that the minimum timing unit of the timer is 0.1ms, the actual time corresponding to the case that the running timestamp of the interrupt running duration of the interrupt state just exceeding 10ms is 10.1ms is recorded. For example, the running time stamp corresponding to the initial call time is 18 (hours): 23 (part): 10 (milliseconds), the recorded running timestamp of the second target interrupt state is 18 (hours): 23 (part): 20.1 (milliseconds).
By recording the running time stamp, an operation and maintenance person or a software developer can conveniently acquire the actual record corresponding to the overtime processing of the interrupt processing function, and the service running program (application program, user program and the like) and the corresponding interrupt processing function can be conveniently optimized and adjusted.
In the embodiment including S720, S731, and S732, the user is supported to set the interrupt of interest, so that the kernel mode only focuses on the interrupt state of interest of the user to monitor and obtain the corresponding interrupt state information; in some embodiments, a user is supported to set a threshold, and delay and frequency events exceeding the set threshold are output according to the set threshold of the user, for example, by the method provided by the embodiment of the disclosure, an interrupt processing function with a function running time exceeding the set threshold, or an interrupt identifier or an interrupt processing function with the function running time exceeding the set threshold can be obtained, so that software research and development personnel can conveniently perform optimization adjustment on the interrupt processing function.
Exemplary apparatus
FIG. 8 is a block diagram illustrating an apparatus for monitoring interrupt status according to an exemplary embodiment. The apparatus 800 for monitoring an interrupt status provided in an embodiment of the present disclosure includes: the kernel monitoring module comprises: the interrupt monitoring module 810, the information acquisition module 820, the calling module 830, and the interrupt runtime determination module 840 are described with reference to fig. 8. Part of the functions of the kernel monitor module of this embodiment may be shown with reference to the kernel monitor module 700 in fig. 7.
The interrupt monitoring module 810 is configured to monitor interrupts of the CPU.
The information obtaining module 820 is configured to obtain, in response to detecting that the CPU enters an interrupt state, an interrupt identifier and an interrupt type of an interrupt source that causes the interrupt state.
The calling module 830 is configured to call a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, where the target interrupt hook function is configured to end the call when the CPU exits the interrupt state.
The interrupt operation duration determining module 840 is configured to determine, according to the call information of the target interrupt hook function, an interrupt operation duration corresponding to the interrupt identifier.
In some embodiments, the interrupt types include: hardware interrupt type, software interrupt type and timer interrupt type; the interrupt hook function in the kernel interface function library is associated with an interrupt type identifier.
The calling module 830 includes: the system comprises a screening module, a target interrupt hook function determining module and a hook function calling module.
The screening module is used for: screening the matched interrupt type identification matched with the interrupt type from the kernel interface function library.
The target interrupt hook function determination module is used for: and determining an interrupt hook function corresponding to the matched interrupt type identifier as the target interrupt hook function.
The hook function call module is used for: the target interrupt hook function is called.
The call information includes: a start call time and an end call time. In some embodiments, determining, according to the call information of the target interrupt hook function, an interrupt running duration corresponding to the interrupt identifier includes: and calculating a difference value between the ending calling time and the starting calling time of the target interrupt hook function, wherein the difference value is used as an interrupt running time corresponding to the interrupt identifier.
In some embodiments, the apparatus further comprises: the device comprises a storage module, a calculation module and a statistics module.
The storage module is used for: and storing the interrupt identifier and the corresponding interrupt running time to a kernel memory cache area.
The calculation module is used for: accumulating the interrupt operation time lengths of a plurality of interrupt states stored in the kernel memory buffer area to obtain accumulated interrupt operation time lengths.
The statistics module is used for: and counting the target interrupt operation time length meeting the preset condition in the interrupt states, and at least one of interrupt identification or interrupt processing function corresponding to the target interrupt operation time length.
In some embodiments, the preset conditions include one or more of the following for a hardware interrupt type, a software interrupt type, or a timer interrupt type:
counting the maximum interrupt operation time length in the interrupt states, and at least one of interrupt identification and interrupt processing function corresponding to the maximum interrupt operation time length;
counting a second target interrupt state in which the interrupt running time length exceeds a set threshold value in the interrupt states, and at least one of an interrupt identifier and an interrupt processing function corresponding to the second target interrupt state;
and counting the target accumulated interrupt operation time length of which the accumulated interrupt operation time length corresponding to the adjacent interrupt states exceeds a set threshold value, and at least one of interrupt identification and interrupt processing function corresponding to the target accumulated interrupt operation time length.
In other embodiments, the targeted interrupt hook function described above is configured to: monitoring the function execution state of the operating system after entering the interrupt state, wherein the function execution state comprises a state of executing a target interrupt processing function, and the target interrupt processing function is an interrupt processing function corresponding to the interrupt identifier; and determining the function operation time length and the function operation times of the target interrupt processing function according to the function execution state. In this embodiment, the above-mentioned storage module is further configured to: storing the function operation time length and the function operation times of the target interrupt processing function into a kernel memory buffer area; the statistics module is further configured to: according to the function operation time length and the function operation times, counting the target interrupt operation time length meeting the preset conditions in the interrupt states and at least one of interrupt identification or interrupt processing function corresponding to the target interrupt operation time length.
For example, in this embodiment, the preset conditions include one or more of the following conditions: the function operation time exceeds the set threshold value and the function operation times exceeds the set times.
In some embodiments, the apparatus further comprises: the control instruction receiving module is used for receiving a monitoring control instruction, and the monitoring control instruction comprises: monitoring a start instruction and monitoring a stop instruction. The above-mentioned interrupt monitoring for the CPU includes: and in the monitoring period corresponding to the monitoring start instruction and the monitoring stop instruction, carrying out interrupt monitoring on the CPU.
In some embodiments, the monitoring control instructions further include: and outputting an instruction by the monitoring result. The monitoring result output instruction carries: screening conditions for the target output object, wherein the screening conditions are used for limiting at least one of interrupt identification, interrupt type or interrupt operation duration of the target output object; the device further comprises: and the monitoring result acquisition module is used for acquiring an interrupt state monitoring result aiming at the target output object from the kernel memory buffer area according to the screening condition.
In some embodiments, the apparatus further comprises: and selecting an instruction receiving module. The selection instruction receiving module is used for receiving a monitoring object selection instruction, wherein the monitoring object selection instruction comprises one or more of a first selection instruction and a second selection instruction; the first selection instruction is an instruction for monitoring a first target interrupt state, and the first target interrupt state is an interrupt state corresponding to a preset interrupt identifier or a preset interrupt type; the second selection instruction is an instruction for monitoring a second target interrupt state in which the interrupt operation duration exceeds a set threshold.
The calling module 830 is configured to call, in response to the first selection instruction, a target interrupt hook function corresponding to an interrupt type of the first target interrupt state from a predefined kernel interface function library.
The statistics module is used for responding to the second selection instruction and determining a second target interrupt state corresponding to the target interrupt operation duration of which the interrupt operation duration exceeds the set threshold; and obtaining the interrupt identification, the user state stack information, the kernel state stack information and the running time stamp of the second target interrupt state.
For further details of this embodiment reference is made to the detailed description of the method embodiments described above.
Exemplary electronic device
Fig. 9 is a block diagram of an electronic device, according to an example embodiment.
Referring to fig. 9, the electronic device 900 provided in the present embodiment may be a vehicle controller, an in-vehicle terminal, an in-vehicle computer, or other types of electronic devices.
Referring to fig. 9, an electronic device 900 includes at least one processor 910 and memory 920. Processor 910 may execute instructions stored in memory 920. The processor 910 is communicatively coupled to the memory 920 via a data bus. In addition to memory 920, processor 910 may also be communicatively coupled to input devices 930, output devices 940, and communication devices 950 via a data bus.
The processor 910 may be any conventional processor, such as a commercially available CPU. The processor may also include, for example, an image processor (Graphic Process Unit, GPU), a field programmable gate array (Field Programmable Gate Array, FPGA), a System On Chip (SOC), an application specific integrated Chip (Application Specific Integrated Circuit, ASIC), or a combination thereof.
The memory 920 may be implemented by any type of volatile or nonvolatile memory device or combination thereof, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disk.
In the embodiment of the present disclosure, the memory 920 stores executable instructions, and the processor 910 may read the executable instructions from the memory 920 and execute the instructions to implement all or part of the steps of the method for monitoring interrupt status in any of the above exemplary embodiments.
Exemplary computer-readable storage Medium
In addition to the methods and apparatus described above, exemplary embodiments of the present disclosure may also be a computer program product or a computer readable storage medium storing the computer program product. The computer program product comprises computer program instructions executable by a processor to perform all or part of the steps described in any of the methods of the exemplary embodiments described above.
The computer program product may write program code for performing the operations of embodiments of the present application in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages, as well as scripting languages (e.g., python). The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server.
The computer readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may include, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the readable storage medium include: a Static Random Access Memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic or optical disk, or any suitable combination of the foregoing having one or more electrical conductors.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure. This application is intended to cover any adaptations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A method of monitoring interrupt conditions, comprising:
interrupt monitoring is carried out on the CPU;
in response to monitoring that the CPU enters an interrupt state, acquiring an interrupt identifier and an interrupt type of an interrupt source which causes the interrupt state;
calling a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, wherein the target interrupt hook function is used for ending calling when the CPU exits from the interrupt state;
And determining the interrupt operation time length corresponding to the interrupt identifier according to the call information of the target interrupt hook function.
2. The method of claim 1, wherein the call information comprises: starting and ending the call time;
determining the interrupt operation duration corresponding to the interrupt identifier according to the call information of the target interrupt hook function, wherein the method comprises the following steps:
and calculating a difference value between the ending calling time and the starting calling time of the target interrupt hook function, wherein the difference value is used as an interrupt running time corresponding to the interrupt identifier.
3. The method of claim 1, wherein the interrupt type comprises: hardware interrupt type, software interrupt type and timer interrupt type; the interrupt hook function in the kernel interface function library is associated with an interrupt type identifier;
the calling the target interrupt hook function corresponding to the interrupt type from the predefined kernel interface function library comprises the following steps:
screening a matched interrupt type identifier matched with the interrupt type from the kernel interface function library;
determining an interrupt hook function corresponding to the matched interrupt type identifier as the target interrupt hook function;
And calling the target interrupt hook function.
4. The method as recited in claim 1, further comprising:
monitoring a function execution state of an operating system after entering an interrupt state, wherein the function execution state comprises a state of executing a target interrupt processing function, and the target interrupt processing function is an interrupt processing function corresponding to the interrupt identifier;
and determining the function operation time length and the function operation times of the target interrupt processing function according to the function execution state.
5. The method as recited in claim 1, further comprising:
storing the interrupt identifier and the corresponding interrupt running time to a kernel memory cache area;
accumulating interrupt operation time lengths of a plurality of interrupt states stored in the kernel memory buffer area to obtain accumulated interrupt operation time lengths;
and counting target interrupt operation time length meeting preset conditions in the interrupt states, and at least one of interrupt identification or interrupt processing function corresponding to the target interrupt operation time length.
6. The method as recited in claim 1, further comprising:
receiving a monitoring object selection instruction, wherein the monitoring object selection instruction comprises one or more of a first selection instruction and a second selection instruction, the first selection instruction is an instruction for monitoring a first target interrupt state, and the first target interrupt state is an interrupt state corresponding to a preset interrupt identifier or a preset interrupt type; the second selection instruction is an instruction for monitoring a second target interrupt state in which the interrupt operation duration exceeds a set threshold value;
In response to the first selection instruction, calling a target interrupt hook function corresponding to an interrupt type of the first target interrupt state from a predefined kernel interface function library;
responding to the second selection instruction, and determining a second target interrupt state corresponding to the target interrupt operation duration of which the interrupt operation duration exceeds the set threshold; and obtaining the interrupt identification, the user state stack information, the kernel state stack information and the running time stamp of the second target interrupt state.
7. The method according to any one of claims 1-6, further comprising:
receiving a monitoring control instruction, wherein the monitoring control instruction comprises: monitoring a start instruction and a stop instruction;
wherein, the interrupt monitoring for the CPU comprises:
and in a monitoring period corresponding to the monitoring start instruction and the monitoring stop instruction, carrying out interrupt monitoring on the CPU.
8. An apparatus for monitoring interrupt conditions, comprising:
the interrupt monitoring module is used for monitoring the interrupt of the CPU;
the information acquisition module is used for responding to the condition that the CPU enters an interrupt state and acquiring an interrupt identifier and an interrupt type of an interrupt source which causes the interrupt state;
The calling module is used for calling a target interrupt hook function corresponding to the interrupt type from a predefined kernel interface function library, and the target interrupt hook function is used for ending calling when the CPU exits from the interrupt state;
and the interrupt operation duration determining module is used for determining the interrupt operation duration corresponding to the interrupt identifier according to the calling information of the target interrupt hook function.
9. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
the processor being configured to read the executable instructions from the memory and execute the executable instructions to implement the method of monitoring interrupt status of any of claims 1-7.
10. A computer readable storage medium having stored thereon computer program instructions, which when executed by a processor, implement the method of monitoring interrupt status of any of claims 1-7.
CN202211104756.1A 2022-09-09 2022-09-09 Method, device, electronic equipment and storage medium for monitoring interrupt state Pending CN116225820A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211104756.1A CN116225820A (en) 2022-09-09 2022-09-09 Method, device, electronic equipment and storage medium for monitoring interrupt state

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211104756.1A CN116225820A (en) 2022-09-09 2022-09-09 Method, device, electronic equipment and storage medium for monitoring interrupt state

Publications (1)

Publication Number Publication Date
CN116225820A true CN116225820A (en) 2023-06-06

Family

ID=86587996

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211104756.1A Pending CN116225820A (en) 2022-09-09 2022-09-09 Method, device, electronic equipment and storage medium for monitoring interrupt state

Country Status (1)

Country Link
CN (1) CN116225820A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117193991A (en) * 2023-11-08 2023-12-08 广州翼辉信息技术有限公司 Accurate measurement method for real-time operating system interrupt processing time

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117193991A (en) * 2023-11-08 2023-12-08 广州翼辉信息技术有限公司 Accurate measurement method for real-time operating system interrupt processing time
CN117193991B (en) * 2023-11-08 2024-02-23 广州翼辉信息技术有限公司 Accurate measurement method for real-time operating system interrupt processing time

Similar Documents

Publication Publication Date Title
CN107066365B (en) System abnormity monitoring method and device
US5944840A (en) Continuous monitor for interrupt latency in real time systems
CN106681811B (en) Multithreading scheduling method and device based on thread pool
CN109656782A (en) Visual scheduling monitoring method, device and server
CN111625425A (en) Data monitoring method, device and system
CN116225820A (en) Method, device, electronic equipment and storage medium for monitoring interrupt state
EP3489829A1 (en) Semiconductor device and failure detection method of the semiconductor device
US20240126593A1 (en) User-mode interrupt request processing method and apparatus
EP3234764B1 (en) Instrumentation of graphics instructions
CN112306833A (en) Application program crash statistical method and device, computer equipment and storage medium
CN113190427A (en) Caton monitoring method and device, electronic equipment and storage medium
CN111176869B (en) Timeout detection method, device, equipment and storage medium
CN110673976A (en) Anomaly detection method and anomaly detection device for multi-core system and electronic equipment
CN114785714B (en) Message transmission delay detection method, storage medium and equipment
Leyva-del-Foyo et al. Predictable interrupt scheduling with low overhead for real-time kernels
CN112612592A (en) Configurable timed task processing method, device, equipment and storage medium
CN113742113A (en) Embedded system health management method, equipment and storage medium
CN114385387B (en) Access information generation method and device and computer equipment
CN113010336A (en) Application processor crash field debugging method and application processor
CN114647540B (en) Embedded scheduler fault recovery method, embedded system and storage medium
CN115437809A (en) Method and device for counting running time of system call in kernel state and electronic equipment
CN112596818B (en) Application program control method, system and device
CN115687159B (en) Debugging method, debugging device and computer readable storage medium
CN113886123B (en) Watchdog feeding method and device, electronic equipment and storage medium
CN112817811B (en) Method, device, equipment and storage medium for predicting scanning failure rate

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination