Interrupt processing method and apparatus, and electronic device

By replacing ordinary running entities with interrupt running entities in the operating system, the problem of user-mode interrupt processing delay is solved and real-time and efficient interrupt processing is achieved.

WO2024193308A1PCT designated stage expired Publication Date: 2024-09-26HUAWEI TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/079197
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-21
Filing Date
2024-02-29
Publication Date
2024-09-26

AI Technical Summary

Technical Problem

In the operating system, how to ensure the real-time nature of interrupt processing, especially when running in user mode, to avoid delays caused by interrupt processing threads due to operations such as preemption or core cutting.

Method used

By replacing ordinary running entities with interrupt running entities, the context switching of interrupt processing is reduced, preemption or core cutting operations during interrupt processing are avoided, and the interrupt processing strategy is dynamically adjusted according to the interrupt priority and load size.

Benefits of technology

It improves the interrupt response speed, ensures the real-time nature of interrupt processing, avoids low-priority interrupts from interrupting high-priority interrupt processing, and improves the overall performance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024079197_26092024_PF_FP
    Figure CN2024079197_26092024_PF_FP
Patent Text Reader

Abstract

Embodiments of the present application provide an interrupt processing method and apparatus, and an electronic device. The method comprises: when a first interrupt request is triggered, determining a target CPU responding to the first interrupt request; determining a first target interrupt running entity on the target CPU; scheduling a target thread from a user mode to a kernel mode; replacing a running entity of the target thread with the first target interrupt running entity; and scheduling the target thread containing the first target interrupt running entity to the user mode, and running the first target interrupt running entity by using the target CPU. According to the technical method, a common running entity is replaced with an interrupt running entity, and due to less content comprised in the interrupt running entity, an interrupt response speed can be increased; in addition, the electronic device can sense the running of an interrupt by means of the interrupt running entity, so that operations such as preemption or core switching for an interrupt processing thread caused by the interrupt or scheduling during interrupt running can be avoided, thereby ensuring the real-time performance of the interrupt.
Need to check novelty before this filing date? Find Prior Art

Description

Interrupt processing method, device and electronic device

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on March 21, 2023, with application number 202310304586.X and invention name “Method, device and electronic device for interrupt processing”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] Embodiments of the present application relate to the field of operating systems, and more specifically, to a method, apparatus, and electronic device for interrupt processing. Background Art

[0003] In operating systems such as Linux, an increasing number of them are placing interrupts in user mode for security, maintainability, and business flexibility reasons. User-mode interrupts are becoming a future trend. For example, driver operation relies on interrupt processing, so user-mode drivers also need to handle interrupts in user mode. The real-time nature of user-mode interrupt processing directly impacts driver performance.

[0004] How to ensure the real-time performance of interrupt processing has become a technical problem that needs to be solved.

[0005] Summary of the Invention

[0006] The embodiments of the present application provide a method, apparatus, and electronic device for interrupt processing. This technical solution can replace an ordinary running entity with an interrupt running entity. Since the interrupt running entity includes less content, the speed of interrupt response can be improved, and the electronic device can perceive the operation of the interrupt based on the interrupt running entity, thereby avoiding operations such as preemption or core switching of the interrupt processing thread due to interruption or scheduling during the interrupt operation, thereby ensuring the real-time nature of the interrupt.

[0007] In a first aspect, a method for interrupt processing is provided, which is applied to an electronic device, and the method includes: when a first interrupt request is triggered, the electronic device determines a target central processing unit CPU that responds to the first interrupt request; the electronic device determines a first target interrupt running entity on the target CPU; the electronic device schedules a target thread from user mode to kernel mode; the electronic device replaces the running entity of the target thread with the first target interrupt running entity; the electronic device schedules a target thread containing the first target interrupt running entity to the user mode, and uses the target CPU to run the first target interrupt running entity.

[0008] It is understandable that the electronic device may include multiple CPUs, and the target CPU may be one of the multiple CPUs. The first interrupt request may be configured to be respondable to multiple CPUs.

[0009] The target thread may be a thread currently running in user mode.

[0010] In an embodiment of the present application, the electronic device can determine the target CPU that responds to the first interrupt request when the interrupt request is triggered; and determine the first target interrupt running entity on the target CPU, and then preempt the target thread running in the user state to enter the kernel state; and use the first target interrupt running entity to replace the running entity in the target thread, and then schedule the target thread to the user state, and run the first target interrupt running entity on the target CPU.

[0011] In this way, during the interrupt processing process, the interrupt execution entity replaces the normal execution entity. Since the interrupt execution entity contains less content, the interrupt response speed can be improved. Furthermore, the electronic device can perceive the execution of the interrupt based on the interrupt execution entity, thereby avoiding the interrupt handling thread preemption or core switching caused by the interrupt or scheduling during the interrupt execution, thereby ensuring the real-time performance of the interrupt.

[0012] In combination with the first aspect, in an implementation of the first aspect, the electronic device determines the first target interrupt running entity on the target CPU, including: determining the first target interrupt running entity on the target CPU according to the priority of the first interrupt request.

[0013] In the embodiments of the present application, different interrupt requests may have different priorities. The electronic device may determine the interrupt execution entity on the target CPU based on the priority of the interrupt request. The priority of the interrupt execution entity corresponds to the priority of the interrupt request. This ensures that interrupt requests of different priorities correspond to different target interrupt execution entities, preventing the current interrupt from being interrupted by other interrupts of equal or lower priority, thereby ensuring the real-time nature of interrupt processing.

[0014] In other examples, the electronic device may also determine the first target interrupt running entity on the target CPU by other means, which is not limited in the embodiments of the present application.

[0015] In combination with the first aspect, in an implementation of the first aspect, the method also includes: the electronic device creates an interrupt running entity resource pool for the target CPU, the interrupt running entity resource pool includes multiple interrupt running entities, and the multiple interrupt running entities have different priorities; the electronic device determines the first target interrupt running entity on the target CPU according to the priority of the first interrupt request, including: the electronic device determines the first target interrupt running entity from the interrupt running entity resource pool according to the priority of the first interrupt request.

[0016] In an embodiment of the present application, the electronic device can create an interrupt running entity resource pool for each CPU, and the interrupt running entity resource pool can include multiple interrupt running entities with different priorities, so that the electronic device can determine the corresponding interrupt running entity from the interrupt running entity resource pool according to the priority of the interrupt request.

[0017] In this way, each interrupt request has its corresponding priority interrupt running entity, which can prevent the current interrupt from being interrupted by other interrupts of equal or lower priority during the running period, thereby ensuring the real-time performance of interrupt processing.

[0018] In combination with the first aspect, in an implementation of the first aspect, before the electronic device uses the first target interrupt running entity to replace the running entity of the target thread, the method further includes: the electronic device saving the running entity of the target thread.

[0019] In an embodiment of the present application, the electronic device can save the running entity of the target thread without saving the scheduling entity of the target thread, thereby making the interrupt processing faster and enabling the target thread to quickly return to user state after the interrupt is processed.

[0020] In combination with the first aspect, in an implementation of the first aspect, during the process of the target CPU running the first target interrupt running entity, the method also includes: when the second interrupt request is triggered, the electronic device determines that the CPU responding to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request; the electronic device determines the second target interrupt running entity on the target CPU according to the priority of the second interrupt request, and the priority of the second target interrupt running entity is greater than the priority of the first target interrupt running entity; the electronic device schedules the target thread from the user state to the kernel state; the electronic device uses the second target interrupt running entity to replace the first target interrupt running entity in the target thread; the electronic device schedules the target thread containing the second target interrupt running entity to the user state, and uses the target CPU to run the second target interrupt running entity.

[0021] In an embodiment of the present application, during the process of the target CPU running the first target interrupt running entity, the electronic device triggers a second interrupt request with a higher priority, and the response CPU of the second interrupt request is also the above-mentioned target CPU; at this time, the electronic device can determine the second target interrupt running entity on the target CPU according to the priority of the second interrupt request, and schedule the target thread from user state to kernel state, and use the second target interrupt running entity to replace the first target interrupt running entity in the target thread; then, the electronic device schedules the target thread containing the second target interrupt running entity to user state, and uses the target CPU to run the second target interrupt running entity.

[0022] This technical solution can use a high-priority interrupt running entity to preempt a low-priority interrupt running entity, thereby ensuring that the high-priority interrupt can be processed first.

[0023] In other examples, while the target CPU is executing the first target interrupt execution entity, if the electronic device receives another interrupt request with a priority lower than or equal to the first interrupt request, the electronic device can continue to process the other interrupt after processing the first interrupt request. This can prevent other interrupts of equal or lower priority from interrupting the current interrupt.

[0024] In combination with the first aspect, in an implementation of the first aspect, before the electronic device uses the second target interrupt running entity to replace the first target interrupt running entity in the target thread, the method further includes: the electronic device saving the first target interrupt running entity.

[0025] In an embodiment of the present application, before the electronic device uses the second target interrupt running entity to replace the first target interrupt running entity in the target thread, the electronic device can save the first target interrupt running entity without saving the scheduling entity, so that it can quickly return to the user state when the first target interrupt running entity is subsequently run.

[0026] In combination with the first aspect, in an implementation of the first aspect, after the second target interrupt running entity is completed, the method also includes: the electronic device schedules the target thread to the kernel state; the electronic device uses the first target interrupt running entity to replace the second target interrupt running entity; the electronic device schedules the target thread containing the first target interrupt running entity to the user state, and uses the target CPU to continue running the first target interrupt running entity.

[0027] In the embodiment of the present application, after the second target interrupt execution entity with a high priority finishes execution, the electronic device can continue to execute the first target interrupt execution entity, thereby facilitating the timely processing of the high priority interrupt.

[0028] In combination with the first aspect, in an implementation of the first aspect, after the first target interrupt running entity is completed, the method also includes: the electronic device schedules the target thread to the kernel state; the electronic device uses the running entity to replace the first target interrupt running entity; the electronic device schedules the target thread containing the running entity to the user state, and uses the target CPU to continue running the running entity.

[0029] In an embodiment of the present application, after the first target interrupt running entity has completed execution, the electronic device can schedule the target thread to the kernel state, replace the first target interrupt running entity with its original running entity, and return the target thread to the user state to execute, so that the target thread continues to execute its original task.

[0030] In combination with the first aspect, in an implementation of the first aspect, the electronic device includes multiple CPUs, and the electronic device determines the target CPU that responds to the first interrupt request, including: the electronic device determines the target CPU that responds to the first interrupt request based on the interrupt load size of the multiple CPUs, wherein the first interrupt request is configured to be able to be responded to by the target CPU.

[0031] In the embodiment of the present application, the electronic device may include multiple CPUs, and the first interrupt request may also be configured to be responded to by multiple CPUs. In this case, the electronic device may determine the target CPU to respond to based on the interrupt load size of the multiple CPUs.

[0032] In combination with the first aspect, in an implementation of the first aspect, the electronic device determines the target CPU that responds to the first interrupt request based on the interrupt load size of the CPU, including: the electronic device uses the CPU with a smaller interrupt load as the target CPU that responds to the first interrupt request.

[0033] In the embodiment of the present application, the electronic device may use a CPU with a smaller interrupt load as the target CPU for responding to an interrupt request, thereby facilitating ensuring that the interrupt can be processed in a timely manner.

[0034] In combination with the first aspect, in an implementation of the first aspect, the electronic device determines the target CPU that responds to the first interrupt request, including: the electronic device receives indication information sent by the CPU, the indication information is used to indicate that the CPU cannot handle the interrupt; the electronic device determines the target CPU from CPUs other than the CPU that sends the indication information that can respond to the first interrupt request.

[0035] In an embodiment of the present application, when the overall CPU load is high, the CPU can proactively send an indication to the electronic device, indicating that it cannot handle a new interrupt. In this case, the electronic device can determine the target CPU that responds to the first interrupt request from other CPUs. This helps ensure that the interrupt can be handled in a timely manner.

[0036] In combination with the first aspect, in an implementation of the first aspect, the first target interrupt execution entity includes at least information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the first interrupt request, and a status register.

[0037] In the embodiment of the present application, the first target interrupt running entity includes less content than a common running entity, which can improve the speed of responding to the first interrupt request.

[0038] In combination with the first aspect, in an implementation of the first aspect, the second target interrupt execution entity includes at least information related to the interrupt execution, which is used to indicate the address space, and includes a general register and a status register containing the interrupt number corresponding to the second interrupt request.

[0039] In the embodiment of the present application, the second target interrupt running entity includes less content than the common running entity, which can improve the speed of responding to the second interrupt request.

[0040] In a second aspect, an electronic device is provided, comprising: one or more processors; one or more memories; the one or more memories storing one or more programs, which, when executed by the one or more processors, enable the interrupt handling method described in the first aspect and any possible implementation thereof to be executed.

[0041] According to a third aspect, a device for interrupt processing is provided, comprising: a processing module for: determining a target central processing unit (CPU) that responds to a first interrupt request when a first interrupt request is triggered; determining a first target interrupt running entity on the target CPU according to the priority of the first interrupt request; scheduling a target thread from user state to kernel state; replacing the running entity of the target thread with the first target interrupt running entity; scheduling a target thread containing the first target interrupt running entity to the user state, and using the target CPU to run the first target interrupt running entity.

[0042] In combination with the third aspect, in an implementation manner of the third aspect, the processing module is specifically used to: determine a first target interrupt running entity on the target CPU according to the priority of the first interrupt request.

[0043] In combination with the third aspect, in an implementation of the third aspect, the processing module is also used to: create an interrupt running entity resource pool for the target CPU, the interrupt running entity resource pool including multiple interrupt running entities, and the multiple interrupt running entities have different priorities; the processing module is specifically used to: determine the first target interrupt running entity from the interrupt running entity resource pool according to the priority of the first interrupt request.

[0044] In combination with the third aspect, in an implementation of the third aspect, before the processing module uses the first target interrupt running entity to replace the running entity of the target thread, the processing module is further used to: save the running entity of the target thread.

[0045] In combination with the third aspect, in an implementation of the third aspect, in the process of the target CPU running the first target interrupt running entity, the processing module is also used to: when a second interrupt request is triggered, determine that the CPU responding to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request; determine the second target interrupt running entity on the target CPU according to the priority of the second interrupt request, and the priority of the second target interrupt running entity is greater than the priority of the first target interrupt running entity; schedule the target thread from the user state to the kernel state; use the second target interrupt running entity to replace the first target interrupt running entity in the target thread; schedule the target thread containing the second target interrupt running entity to the user state, and use the target CPU to run the second target interrupt running entity.

[0046] In combination with the third aspect, in an implementation of the third aspect, before the processing module uses the second target interrupt running entity to replace the first target interrupt running entity in the target thread, the processing module is also used to: save the first target interrupt running entity.

[0047] In combination with the third aspect, in an implementation of the third aspect, after the second target interrupt running entity is completed, the processing module is also used to: schedule the target thread to the kernel state; replace the second target interrupt running entity with the first target interrupt running entity; schedule the target thread containing the first target interrupt running entity to the user state, and use the target CPU to continue running the first target interrupt running entity.

[0048] In combination with the third aspect, in an implementation of the third aspect, after the first target interrupt running entity is completed, the processing module is also used to: schedule the target thread to the kernel state; use the running entity to replace the first target interrupt running entity; schedule the target thread containing the running entity to the user state, and use the target CPU to continue running the running entity.

[0049] In combination with the third aspect, in an implementation of the third aspect, the device includes multiple CPUs, and the processing module is specifically used to: determine the target CPU that responds to the first interrupt request based on the interrupt load size of the multiple CPUs, wherein the first interrupt request is configured to be able to be responded to by the target CPU.

[0050] In combination with the third aspect, in an implementation manner of the third aspect, the processing module is specifically configured to: use the CPU with a smaller interrupt load as a target CPU for responding to the first interrupt request.

[0051] In combination with the third aspect, in an implementation of the third aspect, the receiving module is also used to: receive indication information sent by the CPU, the indication information being used to indicate that the CPU cannot handle the interrupt; the processing module is specifically used to: determine the target CPU from CPUs other than the CPU that sends the indication information that can respond to the first interrupt request.

[0052] In combination with the third aspect, in an implementation of the third aspect, the first target interrupt execution entity includes at least information related to the interrupt execution, including a general register and a status register indicating an address space and an interrupt number corresponding to the first interrupt request.

[0053] In combination with the third aspect, in an implementation of the third aspect, the second target interrupt execution entity includes at least information related to the interrupt execution, including a general register and a status register for indicating an address space and an interrupt number corresponding to the second interrupt request.

[0054] In a fourth aspect, a chip is provided, which includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the interrupt processing method described in the first aspect and any possible implementation thereof is executed.

[0055] In a fifth aspect, a readable storage medium is provided, wherein the readable storage medium stores instructions. When the instructions are executed on a device, the interrupt handling method described in the first aspect and any possible implementation thereof is executed.

[0056] In a sixth aspect, a program product is provided, comprising a program code, which, when executed on a device, enables the interrupt handling method as described in the first aspect and any possible implementation thereof to be executed. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] FIG1 is a schematic diagram of a user-mode interrupt processing flow.

[0058] FIG2 is a schematic diagram of a system architecture to which the present application may be applied.

[0059] FIG3 is a flowchart of an interrupt processing provided in an embodiment of the present application.

[0060] FIG4 is a schematic diagram of an interrupt preemption provided in an embodiment of the present application.

[0061] FIG5 is a schematic flowchart of an interrupt handling method provided in an embodiment of the present application.

[0062] FIG6 is a schematic flowchart of an interrupt handling method provided in an embodiment of the present application.

[0063] FIG7 is a schematic block diagram of an electronic device provided in an embodiment of the present application.

[0064] FIG8 is a schematic block diagram of an interrupt processing apparatus provided in an embodiment of the present application. DETAILED DESCRIPTION

[0065] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings.

[0066] Before introducing the technical solution of the present application, a brief introduction is first given to some professional terms involved in the embodiments of the present application.

[0067] User space: Code runs at a lower privilege level, can only see some system resources, and cannot directly access kernel space and hardware devices. When a process runs in user space, it is said to be in user state (or simply user state).

[0068] Kernel space: Code runs at a higher privilege level, has full visibility into all system resources, and has full access to hardware devices. For example, when a task (process) executes a system call and falls into kernel code execution, the process is said to be in kernel running state (or simply kernel state).

[0069] Central Processing Unit (CPU): The computing and control core of a computer, and the execution unit for programs.

[0070] Interrupt: An interrupt is a process in which the CPU is interrupted by internal or external events during its operation, pausing the execution of the current program and switching to executing a specific program. After the processing is completed, the program returns to the original program to continue execution.

[0071] Interrupt number: This is a hardware code assigned to each interrupt source to facilitate system identification and processing of interrupts. For example, each type of interrupt can be associated with an interrupt number. For example, the interrupt of a mouse can be associated with IRQ4.

[0072] Interrupt priority: The order in which the CPU responds to interrupts.

[0073] Interrupt Request (IRQ): When a peripheral device needs to send an interrupt signal, it modifies the level of the interrupt pin connected to the Generic Interrupt Controller (GIC) or (Advanced) Programmable Interrupt Controller (A)PIC). The GIC or (A)PIC recognizes the change in level on the interrupt signal line and notifies the CPU, which then stops the current execution flow and jumps to the interrupt handler. Interrupt signals sent by a general device to the GIC or (A)PIC, and by the GIC to the CPU, are considered interrupt requests (IRQs) by the software side. In this application, IRQ stands for Interrupt Request.

[0074] Context: A static description of a thread at a specific moment in its execution. Thread / process execution is a dynamic process. If a thread / process is paused, the context is the state of all CPUs associated with that thread / process at that moment. Context generally consists of two aspects: one is the thread state, grouping, priority, affinity, etc. related to scheduling, which are used by the operating system to schedule the context; the other is the general registers, system registers, stack, etc. related to execution. The thread context in this application can include both the scheduling entity and the execution entity.

[0075] Context switch: When a user-mode program is running, if a system call, exception, or interrupt occurs and needs to be handled by kernel mode, the system will fall back to kernel mode. Kernel mode will save the current user-mode context (including the scheduling and execution parts) and restore the original kernel mode context. This process is called context switching.

[0076] Scheduling context (sched-context): This is the portion of the thread / process context that stores scheduling information, including the thread's running state, thread priority, thread grouping, and thread affinity. For a typical thread, the scheduler can perform operations such as preemption, scheduling, and core switching based on the information in the sched-context. When waking up a user-mode thread, the scheduler compares the priorities within the sched-context within the thread context and selects the thread with the highest priority for processing.

[0077] A run-context is the portion of the thread / process context that stores execution information. Threads are divided into a scheduling entity and a run-context. Together, these two entities ensure the proper operation of the thread / process. Once a thread enters the kernel, the run-context can be replaced, altering the thread's execution flow. A run-context contains complete run-context information (including information indicating the address space, general registers, and status registers). A run-context is lighter than a thread, resulting in better performance.

[0078] Interrupt run-context: A more streamlined run-context. Compared to a run-context, an interrupt run-context has less context information (only the information required for interrupt execution, including information indicating the address space, some general registers, status registers, etc.). It is an extremely simplified run-context and has better performance when context switching is performed through the run-context.

[0079] Scheduler: The operating system's program that performs scheduling tasks. The scheduler determines which threads / processes can run, allowing multiple programs to effectively share system resources simultaneously. A normally running thread may be preempted by the scheduler to run another thread. In this application, the scheduler can detect the priority and affinity of cooperative interrupts by interrupting the running entity, thereby modifying the scheduling policy for the thread currently running the interrupting running entity.

[0080] Scheduling affinity: A scheduling-related attribute that indicates the tendency of a process to run on a specific CPU for as long as possible without being migrated to other CPUs.

[0081] Interrupt affinity: The tendency of global interrupts to be handled by those CPUs in a multi-core scenario.

[0082] Thread: The basic unit that the operating system can schedule and execute.

[0083] Figure 1 is a schematic diagram of the user-mode interrupt handling process. As shown in Figure 1, interrupts typically originate from the hardware GIC or (A)PIC. Taking the GIC as an example, upon receiving a device IRQ, the GIC sends the IRQ to the CPU. Upon receiving the IRQ, the CPU generates an interrupt exception, causing the CPU to jump to the kernel interrupt handling function for execution. Upon receiving the interrupt initiation message, the kernel uses the scheduler to wake up the user-mode thread corresponding to the interrupt request number. It then switches the thread-level context (primarily including scheduling information, execution information, address space, status registers, general registers, etc.) and returns to user mode. The user-mode interrupt thread then runs. While the interrupt thread is running, the scheduler may preempt or switch the core, causing the interrupt thread to be blocked or preempted. Alternatively, other interrupts may interrupt the running user-mode interrupt thread again. The interrupt thread can only continue processing the interrupt after completing its new task. After the interrupt is handled, a system call can be used to return the interrupt thread to kernel mode, saving the thread's context (including the scheduling entity and execution entity). The scheduler then reblocks the thread, placing it in a blocked state, completing the interrupt handling process.

[0084] From the above interrupt processing process, it can be seen that from the start of the interrupt to the execution of the interrupt thread in user mode, it will be affected by factors such as the scheduler and the thread context. The speed at which the thread returns from kernel mode to user mode determines the user mode interrupt response speed. In addition, during the execution of the user mode interrupt thread, it may be affected by the scheduler, causing the interrupt thread to be blocked or preempted, or other interrupts may interrupt the user mode interrupt thread again, making it impossible to guarantee the real-time performance of the interrupt.

[0085] In view of this, the present application provides a method, device and electronic device for interrupt processing. This technical solution can improve the speed of interrupt response through streamlined context; and the scheduling module of the electronic device can sense the interrupt, thereby avoiding operations such as preempting or cutting the core of the interrupt processing thread during interrupt processing; in addition, by multi-layer grading of interrupts, the current user-mode interrupt thread can be avoided from being interrupted by other interrupts during operation, thereby ensuring the real-time nature of the interrupt.

[0086] The following will introduce the technical solution of the interrupt processing method in this application in conjunction with Figures 2 to 6.

[0087] FIG2 is a schematic diagram of a system architecture of an electronic device to which the present application may be applied. As shown in FIG2 , the interrupt handling method may be applied to an electronic device 100 , which may include at least a user space 110 , a kernel space 120 , and an interrupt controller 130 .

[0088] The interrupt controller 130 may be configured to send an interrupt request from a peripheral device to the CPU. For example, the interrupt controller 130 may be a GIC or an (A)PIC.

[0089] The kernel space 120 may include an interrupt initialization module 121 , an interrupt distribution module 122 , a scheduling module 123 and an interrupt execution entity processing module 124 .

[0090] The interrupt initialization module 121 may be used to initialize interrupts, configure interrupt groups and priorities, and create interrupt execution entities. For example, the interrupt initialization module 121 may establish an interrupt execution entity resource pool for each CPU, and the interrupt execution entity resource pool may include multiple interrupt execution entities of different priorities.

[0091] It should be understood that the embodiment of the present application does not limit the number of interruption running entities included in the interruption running entity resource pool.

[0092] It should be understood that different interruption running entities in the interruption running entity resource pool have different priorities.

[0093] The interrupt distribution module 122 can determine the corresponding interrupt execution entity according to the interrupt number, interrupt priority and CPU.

[0094] Exemplarily, the electronic device 100 may include CPU1 and CPU2, each CPU having an interrupt execution entity resource pool. For example, the interrupt execution entity resource pool of CPU1 may include a high-priority interrupt execution entity A1, a medium-priority interrupt execution entity B1, and a low-priority interrupt execution entity C1; the interrupt execution entity resource pool of CPU2 may include a high-priority interrupt execution entity A2, a medium-priority interrupt execution entity B2, and a low-priority interrupt execution entity B2.

[0095] By establishing an interrupt running entity resource pool for each CPU, the interrupt distribution module 122 can determine the corresponding interrupt running entity based on the interrupt number, interrupt priority and CPU, which can ensure the unity of the interrupt response CPU and the running CPU, and associate the interrupt running entity with the interrupt priority and interrupt affinity, avoiding the phenomenon that the interrupt distribution module 122 runs on CPU1 and the interrupt processing module 111 runs on CPU2, which is conducive to realizing exclusive and exclusive operations such as interrupts.

[0096] It should be understood that the interrupt distribution module 122 running on CPU 1 can be understood as the interrupt being responded to by CPU 1. The interrupt processing module 111 running on CPU 2 can be understood as the interrupt being processed by CPU 2.

[0097] In the embodiment of the present application, the interrupt execution entity contains less context information than the execution entity, and only needs to contain information related to the interrupt execution, such as the address space, some general registers (for storing the interrupt number) and the status register. It should be understood that because some general registers in the context of the interrupt execution entity can be used to store the interrupt number, there is no need to store other information, so the thread containing the interrupt execution entity can return to the user state more quickly.

[0098] The scheduling module 123 can identify that the interrupt thread is running an interrupt running entity, so that it can sense the interrupt during scheduling behaviors such as wake-up, core switching, and preemption, avoid scheduling operations such as core switching and preemption during the operation of the interrupt running entity, and avoid being interrupted by other interrupts, thereby ensuring the real-time nature of interrupt processing. For example, the scheduling module 123 can be a scheduler. When the scheduler determines that the running entity is an interrupt running entity based on the running entity of the thread, it can determine that the thread is processing an interrupt, so that the scheduler's behavior and strategy can be adjusted accordingly. For example, the priority of the thread can be temporarily increased, and scheduling can be stopped, etc., to ensure the real-time nature of interrupt processing.

[0099] The interrupted running entity processing module 124 can be used to preempt, save and restore the interrupted running entity, replace the interrupted running entity with a normal running entity in the thread, and use a specific thread or the preempted thread to quickly return to the user state.

[0100] The user space 110 may include an interrupt processing module 111. The interrupt processing module 111 may process a user-mode interrupt after determining a corresponding interrupt number according to an interrupt execution entity.

[0101] FIG3 is a flow chart of an interrupt processing provided by an embodiment of the present application. As shown in FIG3 , thread 250 runs normally in user mode. When CPU 210 receives an interrupt request from the interrupt controller, it sends an interrupt start signal to the kernel, and the hardware preempts the thread 250 running in user mode and enters kernel mode. The running entity 211 of the thread 250 is saved in the kernel. The running entity 211 may include information for indicating the address space, general registers, and status registers. Then, the kernel determines the corresponding interrupt running entity 231 based on the interrupt priority, and uses the interrupt running entity 231 to replace the running entity 211 in thread 250 to form a new context for thread 250. The running context contained in the interrupt running entity 231 includes the address space, general registers for storing the interrupt number, and status registers. Then, the scheduler 240 that can sense the interrupt can schedule the thread 250 to the user mode, so that the thread 250 can handle the interrupt as an interrupt processing thread.

[0102] It is understandable that when processing an interrupt, the kernel uses the interrupt execution entity 231 to preempt the execution entity 211 of thread 250 and reuse the scheduling entity of thread 250. Therefore, when thread 250 is scheduled from user mode to kernel mode, the kernel only needs to save the execution entity of thread 250 and does not need to save its scheduling entity, thereby making interrupt processing faster.

[0103] Since the scheduler 240 is able to sense interrupts, scheduling operations such as core switching and preemption of the thread 250 can be avoided during interrupt processing, thereby ensuring the real-time nature of interrupt processing.

[0104] It can be understood that the preempted thread 250 can be understood as the thread 250 that is executing other tasks before the interrupt begins; when the interrupt begins, the system uses the thread 250 to handle the interrupt. At this time, the task being executed by the thread 250 will be suspended. After the thread 250 handles the interrupt, it can continue to execute the original task.

[0105] Alternatively, the preempted thread 250 may also be understood as a thread created by the system that can be used to process interrupts.

[0106] In other examples, after the system starts, the system can also create a thread in user mode in advance, and use the thread to handle the interrupt after the interrupt starts, thereby avoiding preempting the thread that is executing other tasks to handle the interrupt.

[0107] It should be understood that when the created thread processes an interrupt, the interrupt running entity can also be used to preempt its running entity and reuse its original scheduling entity, so that the thread can quickly return to the user state.

[0108] In one embodiment of the present application, when the system handles an interrupt, the execution entity of the preempted thread can be replaced with an interrupt execution entity that includes a partial execution context. This reduces the execution context of the preempted thread, allowing it to return to user mode more quickly to handle the interrupt. Furthermore, because the scheduler is interrupt-aware, scheduling operations such as core switching and preemption can be avoided during interrupt processing, ensuring real-time interrupt processing.

[0109] Furthermore, in an embodiment of the present application, each CPU can be configured with multiple interrupt running entities of different priorities. When processing an interrupt, the electronic device can select the corresponding interrupt running entity according to the interrupt priority, so that the current interrupt running period can be prevented from being interrupted by other interrupts of the same priority or lower priority, thereby ensuring the real-time nature of interrupt processing.

[0110] In some cases, while one interrupt is being processed, another interrupt may need to be processed. Due to the different priorities of interrupts, the high-priority interrupt needs to be processed by the system first. The following will introduce this technical solution in conjunction with Figure 4.

[0111] Figure 4 is a schematic diagram of an interrupt preemption provided by an embodiment of the present application, wherein (a) to (b) in Figure 4 illustrate the process of a high-priority interrupt preempting a low-priority interrupt.

[0112] It is understandable that the preemption here can be understood as system priority processing.

[0113] Referring to (a) in FIG. 4 , the electronic device may include CPU1 and CPU2. CPU1 may be used to respond to IRQ1, and CPU2 may be used to respond to IRQ2. The kernel may determine the corresponding interrupt execution entity based on the interrupt number corresponding to the IRQ, the CPU that responds to the IRQ, and the interrupt priority. The determined interrupt execution entity is then used to replace the execution entity of the preempted thread. The scheduler may then schedule the interrupt handling thread including the interrupt execution entity to user mode to handle the interrupt.

[0114] For example, the kernel can determine the low-priority interrupt running entity 1 on CPU1 based on the interrupt number, interrupt priority and responding CPU1 corresponding to IRQ1, and then the scheduler can schedule the interrupt processing thread including the interrupt running entity 1 to the user state to handle the interrupt corresponding to IRQ1; the kernel can determine the medium-priority interrupt running entity 2 on CPU2 based on the interrupt number, interrupt priority and responding CPU2 corresponding to IRQ2, and then the scheduler can schedule the interrupt processing thread including the interrupt running entity 2 to the user state to handle the interrupt corresponding to IRQ2.

[0115] It should be understood that the priority of IRQ can be pre-configured by the system. Exemplarily, the interrupt initialization module in the kernel can divide the IRQ priority, etc. For example, for CPU1, the interrupt initialization module can configure three running entities running on CPU1: a high-priority interrupt running entity, a medium-priority interrupt running entity, and a low-priority interrupt running entity; for CPU2, the interrupt initialization module can configure three running entities running on CPU2: a high-priority interrupt running entity, a medium-priority interrupt running entity, and a low-priority interrupt running entity. In other examples, the number of interrupt running entities running on the CPU configured by the interrupt initialization module can also be other numbers, such as four or more, and different interrupt running entities have different priorities.

[0116] It should be understood that which CPUs respond to IRQs can be pre-defined by the system. In some cases, a single IRQ can be responded to by multiple CPUs. For example, IRQ1 can be responded to by both CPU1 and CPU2, but ultimately only by one of them. When an IRQ is responded to by CPU1, the kernel can determine the interrupt execution entity running on CPU1 based on the interrupt number corresponding to the IRQ, the CPU1 that responded to the IRQ, and the interrupt priority, thereby ensuring that the CPU that responds to the IRQ and the CPU that executes it are consistent.

[0117] In some cases, while the system is processing the interrupt corresponding to IRQ2, CPU2 receives IRQ3, and the priority of IRQ3 is higher than that of IRQ2. At this time, the system can process IRQ3 first.

[0118] Referring to (b) in Figure 4 , the system continues to run interrupt processing thread 1 on CPU1 to handle the interrupt corresponding to IRQ1. However, since CPU2 receives IRQ3, which has a higher priority, the kernel can determine the high-priority interrupt execution entity running on CPU2 based on the interrupt number corresponding to IRQ3, the CPU2 that responded to IRQ3, and the interrupt priority. At this point, the kernel can replace the medium-priority interrupt execution entity in interrupt processing thread 2 with the high-priority interrupt execution entity, and return interrupt processing thread 2, which contains the high-priority interrupt execution entity, to user mode to handle the interrupt corresponding to IRQ3, completing interrupt preemption.

[0119] It should be understood that after the medium priority interrupt running entity is preempted by the high priority interrupt running entity, the system will suspend processing the interrupt corresponding to IRQ2. When the interrupt corresponding to IRQ3 is processed, it will continue to process the interrupt corresponding to IRQ2, thereby ensuring that the high priority interrupt can be processed first.

[0120] In one embodiment of the present application, the kernel configures interrupt execution entities with different priorities for each CPU, thereby unifying the CPU that responds to and executes IRQs. When the system is processing one IRQ and a CPU receives another higher-priority IRQ, the system can use the higher-priority interrupt execution entity to preempt the lower-priority interrupt execution entity, allowing the higher-priority interrupt to be processed first, thereby ensuring the real-time performance of the higher-priority interrupt.

[0121] FIG5 is a schematic flow chart of a method for interrupt handling provided by an embodiment of the present application. As shown in FIG5 , the method 500 can be applied to an electronic device, and the method 500 can include steps 510 to 560.

[0122] 510. The electronic device creates multiple interrupt execution entities for each CPU.

[0123] In the embodiment of the present application, the electronic device may include multiple CPUs.

[0124] Exemplarily, referring to FIG. 2 , the electronic device may include an interrupt initialization module 121 , which may be configured to create multiple interrupt execution entities for each CPU.

[0125] For example, the interrupt initialization module 121 may create three or more interrupt execution entities for each CPU.

[0126] In other examples, multiple interruption running entities may also be created by other modules in the electronic device, which is not limited in the embodiments of the present application.

[0127] 520. The electronic device configures priorities of multiple interruption running entities.

[0128] Exemplarily, the interrupt initialization module in the electronic device may be used to configure priorities for multiple created interrupt execution entities.

[0129] For example, an electronic device creates three interrupt execution entities for each CPU, namely interrupt execution entity 1, interrupt execution entity 2, and interrupt execution entity 3. The electronic device can then configure the priority of each interrupt execution entity, for example, configuring interrupt execution entity 1 as high priority, interrupt execution entity 2 as medium priority, and interrupt execution entity 3 as low priority.

[0130] In other examples, the electronic device may further create multiple interrupt execution entities and group the multiple interrupt execution entities. The interrupt execution entities in the same group have the same priority.

[0131] In other examples, step 510 and step 520 may be performed simultaneously, or step 510 and step 520 may be the same step.

[0132] 530 , the electronic device selects a target CPU to respond to the interrupt according to load sizes of the multiple CPUs.

[0133] In the embodiment of the present application, the electronic device may include multiple CPUs. For an interrupt, the electronic device may configure the interrupt to be responsive to multiple CPUs. When actually processing the interrupt, the electronic device may select a target CPU to respond to the interrupt based on the load size of the multiple CPUs.

[0134] For example, an electronic device may include CPU1 and CPU2, and interrupt 1 is configured to be responsive to either CPU1 or CPU2. The electronic device may obtain the interrupt loads of CPU1 and CPU2 for processing interrupts. In this case, the electronic device may select a CPU to respond to interrupt 1 based on the interrupt loads of CPU1 and CPU2. For example, the electronic device may select CPU1, which has a smaller interrupt load, as the target CPU to respond to interrupt 1.

[0135] In another example, when the overall CPU load is high, an indication message can be sent to the hardware, indicating that the CPU is currently overloaded and temporarily unable to handle interrupts. In this case, the electronic device can select another CPU to handle the interrupt. For example, if the electronic device receives an indication message sent by CPU 1, it can select CPU 2 to handle the interrupt.

[0136] In other examples, an external device may trigger interrupt 1 and select CPU 1 and CPU 2 according to the interrupt configuration. CPU 1 and CPU 2 may determine whether to respond to interrupt 1 according to their own load conditions.

[0137] It is understood that in the embodiments of the present application, the electronic device creates multiple interrupt execution entities for each CPU and configures priorities for the multiple interrupt execution entities. This ensures that the interrupt execution entity corresponding to the CPU that responds to the interrupt is used to perform interrupt processing in user mode on that CPU. This ensures that the user mode interrupt processing thread runs on the CPU that responds to the interrupt, avoiding redundant preemption, core switching, and other operations.

[0138] 540, electronic equipment adjusts scheduling strategy.

[0139] For example, the electronic device may include a scheduling module, such as a scheduler, which may determine information such as the priority and grouping of interrupts according to the interrupted running entity, so that the scheduler may appropriately adjust the scheduling strategy.

[0140] For example, the scheduling policy may include but is not limited to: not performing redundant operations such as preempting, core switching, etc. on the thread running the interrupt running entity; adjusting the priority of the preempted thread according to the priority of the interrupt running entity, and waking up the interrupt processing thread to handle the interrupt when the interrupt running entity preempts; during the operation of the current interrupt running entity, interrupts of the same priority or lower priority are all waiting to be processed.

[0141] 550, Electronic equipment processing interruption.

[0142] In one possible implementation, when handling an interrupt, the electronic device preempts a normal thread to handle the interrupt. In this case, after the normal thread falls from user mode to kernel mode, the kernel can obtain the interrupt number and interrupt priority through the interrupt hardware register, determine the corresponding interrupt execution entity based on the interrupt number and interrupt priority, and replace the execution entity of the normal thread with the interrupt execution entity. The scheduler then schedules the thread containing the interrupt execution entity back to user mode to handle the interrupt.

[0143] In other examples, the common thread may also be a thread newly created by the electronic device for processing interrupts.

[0144] In another possible implementation, when processing interrupt 1, the electronic device uses interrupt running entity 1 corresponding to interrupt 1 to preempt interrupt running entity 2 in the interrupt processing thread to process the interrupt. In this case, the priority of interrupt running entity 1 is higher than that of interrupt running entity 2. The electronic device schedules the interrupt processing thread from user mode to kernel mode and saves the context information of the interrupt processing thread. It then replaces interrupt running entity 2 with interrupt running entity 1, schedules the interrupt processing thread including interrupt running entity 1 to user mode, and runs the interrupt running entity to process interrupt 1. After interrupt 1 is processed, the electronic device resumes the operation of interrupt running entity 2 to continue processing interrupt 2.

[0145] In this way, the electronic device can use the high-priority interrupt execution entity to preempt the low-priority interrupt execution entity, so that the interrupt corresponding to the high-priority interrupt execution entity can be processed in a timely manner, thereby ensuring the real-time processing of the high-priority interrupt. In addition, during the high-priority interrupt processing, interrupts of equal or lower priority cannot interrupt the current high-priority user-mode interrupt processing thread, thereby ensuring the real-time processing of the current interrupt.

[0146] 560, electronic equipment release interruption.

[0147] After the electronic device completes the interrupt in the user state, it can schedule the interrupt processing thread from the user state to the kernel state, and restore its own running entity to release the interrupt; then it can be scheduled back to the user state to process its own tasks normally.

[0148] It should be understood that the embodiments of the present application do not limit the specific execution order of steps 510 to 560. In some embodiments, some steps in steps 510 to 560 may not be executed or may be replaced by other steps.

[0149] In one embodiment of the present application, the electronic device may include multiple CPUs, and create multiple interrupt running entities for each CPU, and may configure priorities for the multiple interrupt running entities, and the interrupt is configured to be respondable to multiple CPUs. When actually processing the interrupt, the electronic device may first determine the target CPU that responds to the interrupt, and further determine the interrupt running entity running on the target CPU, so that the responding CPU and the running CPU of the interrupt can be unified, avoiding redundant preemption, core switching and other operations. In addition, since the scheduling module of the electronic device can sense the interrupt, it can avoid scheduling operations such as core switching and preemption on the interrupt processing thread during the interrupt processing, thereby ensuring the real-time nature of the interrupt processing. Furthermore, by configuring multiple priority interrupt running entities, it is possible to avoid the current priority user-mode interrupt processing thread from being interrupted by other interrupts of the same priority or lower priority during the current interrupt operation, further ensuring the real-time nature of the current interrupt processing.

[0150] FIG6 is a schematic flow chart of a method for interrupt handling provided by an embodiment of the present application. As shown in FIG6 , the method 600 can be applied to an electronic device, and the method 600 can include steps 610 to 650.

[0151] 610. When a first interrupt request is triggered, the electronic device determines a target CPU that responds to the first interrupt request.

[0152] Exemplarily, the triggering of the first interrupt request may be understood as the GIC of the electronic device receiving the first interrupt request, or the GIC sending the first interrupt request to the CPU.

[0153] It should be understood that the electronic device may include multiple CPUs. For example, the electronic device includes CPU1 and CPU2, and the electronic device may determine the target CPU that responds to the first interrupt request from CPU1 and CPU2.

[0154] In a possible implementation, the electronic device determines a target CPU that responds to a first interrupt request according to interrupt load sizes of a plurality of CPUs, wherein the first interrupt request is configured to be responsive to the target CPU.

[0155] It should be understood that the electronic device may obtain the interrupt load sizes of multiple CPUs and may determine the target CPU that responds to the first interrupt request according to the interrupt load sizes of the multiple CPUs.

[0156] Exemplarily, the electronic device includes CPU 1 and CPU 2, and the first interrupt request is configured to be responded to by CPU 1 and CPU 2. The electronic device may use the CPU with the smallest interrupt load as the CPU that responds to the first interrupt request.

[0157] In another possible implementation, the electronic device receives indication information sent by the CPU, where the indication information is used to indicate that the CPU cannot handle the interrupt; the electronic device determines a target CPU from CPUs other than the CPU that sends the indication information that can respond to the first interrupt request.

[0158] It should be understood that when the overall load of a CPU 1 is large, the CPU 1 may send an indication message to the hardware of the electronic device that it cannot handle the interrupt. In this case, the electronic device may select a target CPU to respond to the first interrupt request from CPUs other than the CPU 1.

[0159] 620. The electronic device determines a first target interrupt execution entity on the target CPU.

[0160] Exemplarily, the electronic device may create an interrupt execution entity resource pool for each CPU, wherein the interrupt execution entity resource pool may include multiple interrupt execution entities having different priorities. The electronic device may determine the corresponding first target interrupt execution entity according to the priority of the first interrupt request.

[0161] For example, if the priority of the first interrupt request is high, the electronic device may use the high-priority interrupt execution entity on the target CPU as the first target interrupt execution entity.

[0162] In other examples, the electronic device may also determine the first target interrupt running entity on the target CPU by other means, which is not limited in the embodiments of the present application.

[0163] 630 , the electronic device schedules the target thread from the user state to the kernel state.

[0164] The target thread may be a thread running in a user state. At this point, the electronic device may schedule the target thread from the user state to the kernel state.

[0165] In some examples, the electronic device schedules the target thread from user mode to kernel mode and saves the running entity of the target thread.

[0166] It should be understood that the electronic device can reuse the scheduling entity of the target thread. Therefore, when the electronic device schedules the target thread from user mode to kernel mode, it only needs to save its running entity, thereby improving the speed of interrupt processing.

[0167] 640. The electronic device uses the first target interrupt execution entity to replace the execution entity of the target thread.

[0168] It should be understood that after the electronic device replaces the running entity of the target thread with the first target interrupt running entity, the target thread may include the first target interrupt running entity and the scheduling entity.

[0169] 650 , the electronic device schedules the target thread including the first target interrupt execution entity to the user state, and uses the target CPU to execute the first target interrupt execution entity.

[0170] Exemplarily, the electronic device schedules a target thread containing a first target interrupt execution entity to user mode and uses a target CPU to execute the first target interrupt execution entity to process the interrupt. This ensures that the CPU that responds to the first interrupt request and processes the first interrupt request is the same CPU, thereby facilitating exclusive and exclusive interrupt operations.

[0171] In one embodiment of the present application, the electronic device can determine the target CPU that responds to the first interrupt request when the first interrupt request is triggered; and determine the first target interrupt running entity on the target CPU, and then preempt the target thread running in the user state to enter the kernel state; and use the first target interrupt running entity to replace the running entity in the target thread, and then schedule the target thread to the user state, and run the first target interrupt running entity on the target CPU.

[0172] In this way, during the interrupt processing process, the interrupt execution entity replaces the normal execution entity. Since the interrupt execution entity contains less content, the interrupt response speed can be improved. Furthermore, the electronic device can perceive the execution of the interrupt based on the interrupt execution entity, thereby avoiding the interrupt handling thread preemption or core switching caused by the interrupt or scheduling during the interrupt execution, thereby ensuring the real-time performance of the interrupt.

[0173] In some embodiments, the electronic device determines a first target interrupt execution entity on a target CPU, including:

[0174] A first target interrupt execution entity on the target CPU is determined according to the priority of the first interrupt request.

[0175] In the embodiments of the present application, different interrupt requests may have different priorities. The electronic device may determine the interrupt execution entity on the target CPU based on the priority of the interrupt request. The priority of the interrupt execution entity corresponds to the priority of the interrupt request. This ensures that interrupt requests of different priorities correspond to different target interrupt execution entities, preventing the current interrupt from being interrupted by other interrupts of equal or lower priority, thereby ensuring the real-time nature of interrupt processing.

[0176] In some embodiments, the method 600 may further include:

[0177] The electronic device creates an interrupt running entity resource pool for the target CPU, wherein the interrupt running entity resource pool includes multiple interrupt running entities, and the multiple interrupt running entities have different priorities;

[0178] The electronic device determines a first target interrupt execution entity on a target CPU according to a priority of the first interrupt request, including:

[0179] The electronic device determines a first target interrupt execution entity from an interrupt execution entity resource pool according to the priority of the first interrupt request.

[0180] In one embodiment of the present application, the electronic device can create an interrupt running entity resource pool for each CPU, and the interrupt running entity resource pool can include multiple interrupt running entities with different priorities, so that the electronic device can determine the corresponding interrupt running entity from the interrupt running entity resource pool according to the priority of the interrupt request.

[0181] In this way, each interrupt request has its corresponding priority interrupt running entity, which can prevent the current interrupt from being interrupted by other interrupts of equal or lower priority during the running period, thereby ensuring the real-time performance of interrupt processing.

[0182] In some embodiments, before the electronic device uses the first target interrupt execution entity to replace the execution entity of the target thread, the method 600 may further include:

[0183] The electronic device saves the running entity of the target thread.

[0184] In an embodiment of the present application, the electronic device can save the running entity of the target thread without saving the scheduling entity of the target thread, thereby making the interrupt processing faster and enabling the target thread to quickly return to user state after the interrupt is processed.

[0185] In some embodiments, during the process of the target CPU executing the first target interrupt execution entity, the method 600 may further include:

[0186] When the second interrupt request is triggered, the electronic device determines that the CPU that responds to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request;

[0187] The electronic device determines a second target interrupt execution entity on the target CPU according to the priority of the second interrupt request, where the priority of the second target interrupt execution entity is greater than the priority of the first target interrupt execution entity;

[0188] The electronic device schedules the target thread from the user state to the kernel state;

[0189] The electronic device replaces the first target interrupt execution entity in the target thread with the second target interrupt execution entity;

[0190] The electronic device schedules the target thread including the second target interrupt execution entity to the user state, and uses the target CPU to execute the second target interrupt execution entity.

[0191] Exemplarily, referring to FIG. 4 , the first interrupt request may be IRQ2 , and the second interrupt request may be IRQ3 .

[0192] In an embodiment of the present application, during the process of the target CPU running the first target interrupt running entity, the electronic device triggers or receives a second interrupt request with a higher priority, and the response CPU of the second interrupt request is also the above-mentioned target CPU; at this time, the electronic device can determine the second target interrupt running entity on the target CPU according to the priority of the second interrupt request, and schedule the target thread from user state to kernel state, and use the second target interrupt running entity to replace the first target interrupt running entity in the target thread; then, the electronic device schedules the target thread containing the second target interrupt running entity to user state, and uses the target CPU to run the second target interrupt running entity.

[0193] This technical solution can use a high-priority interrupt running entity to preempt a low-priority interrupt running entity, thereby ensuring that the high-priority interrupt can be processed first.

[0194] In other examples, while the target CPU is executing the first target interrupt execution entity, if the electronic device receives another interrupt request with a priority lower than or equal to the first interrupt request, the electronic device may continue to process the other interrupt after processing the first interrupt request. This prevents other interrupts of equal or lower priority from interrupting the current interrupt.

[0195] In some embodiments, before the electronic device replaces the first target interrupt execution entity in the target thread with the second target interrupt execution entity, the method 600 further includes:

[0196] The electronic device saves the first target interrupt execution entity.

[0197] In an embodiment of the present application, before the electronic device uses the second target interrupt running entity to replace the first target interrupt running entity in the target thread, the electronic device can save the first target interrupt running entity without saving the scheduling entity, so that it can quickly return to the user state when the first target interrupt running entity is subsequently run.

[0198] In some embodiments, after the second target interrupt execution entity completes execution, the method 600 may further include:

[0199] The electronic device schedules the target thread to kernel state;

[0200] The electronic device replaces the second target interruption execution entity with the first target interruption execution entity;

[0201] The electronic device schedules the target thread including the first target interrupt execution entity to the user state, and uses the target CPU to continue to execute the first target interrupt execution entity.

[0202] In the embodiment of the present application, after the second target interrupt execution entity with a high priority finishes execution, the electronic device can continue to execute the first target interrupt execution entity, thereby facilitating the timely processing of the high priority interrupt.

[0203] In some embodiments, after the first target interrupt execution entity completes execution, the method 600 may further include: the electronic device scheduling the target thread to a kernel state;

[0204] The electronic device uses the running entity to replace the first target interrupt running entity;

[0205] The electronic device schedules the target thread including the running entity to the user state, and uses the target CPU to continue running the running entity.

[0206] In an embodiment of the present application, after the first target interrupt running entity has completed execution, the electronic device can schedule the target thread to the kernel state, replace the first target interrupt running entity with its original running entity, and return the target thread to the user state to execute, so that the target thread continues to execute its original task.

[0207] In some embodiments, the first target interrupt execution entity includes at least information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the first interrupt request, and a status register.

[0208] In the embodiment of the present application, the first target interrupt running entity includes less content than a common running entity, which can improve the speed of responding to the first interrupt request.

[0209] In some embodiments, the second target interrupt execution entity includes at least information related to the interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the second interrupt request, and a status register.

[0210] In the embodiment of the present application, the second target interrupt running entity includes less content than the common running entity, which can improve the speed of responding to the second interrupt request.

[0211] Figure 7 is a schematic block diagram of an electronic device provided in an embodiment of the present application. As shown in Figure 7, the electronic device 700 may include one or more processors 710; one or more memories 720; the one or more memories 720 store one or more programs, which, when executed by the one or more processors 710, enable the interrupt handling method described in any of the possible implementations above to be executed.

[0212] FIG8 is a schematic block diagram of an interrupt processing apparatus provided by an embodiment of the present application. As shown in FIG8 , the apparatus 800 may include a processing module 810 .

[0213] The processing module 810 may be used to:

[0214] When the first interrupt request is triggered, determining a target CPU that responds to the first interrupt request;

[0215] Determine a first target interrupt execution entity on the target CPU;

[0216] Replace the target thread's execution entity with the first target interrupt execution entity;

[0217] The target thread including the first target interrupt execution entity is scheduled to the user state, and the first target interrupt execution entity is executed using the target CPU.

[0218] Exemplarily, the processing module 810 may be the interrupt distribution module 122 , the scheduling module 123 , the interrupt running entity processing module 124 , the terminal processing module 111 , etc. mentioned above.

[0219] In some embodiments, the processing module 810 is further configured to:

[0220] Creating an interrupt running entity resource pool for the target CPU, wherein the interrupt running entity resource pool includes multiple interrupt running entities, and the multiple interrupt running entities have different priorities;

[0221] The processing module 810 is specifically configured to:

[0222] A first target interrupt execution entity is determined from an interrupt execution entity resource pool according to the priority of the first interrupt request.

[0223] In some embodiments, before the processing module replaces the target thread's execution entity with the first target interrupt execution entity, the processing module 810 is further configured to:

[0224] Save the running entity of the target thread.

[0225] In some embodiments, during the process of the target CPU executing the first target interrupt execution entity,

[0226] The processing module 810 is further configured to:

[0227] When the second interrupt request is triggered, determining that the CPU that responds to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request;

[0228] determining a second target interrupt execution entity on the target CPU according to the priority of the second interrupt request, wherein the priority of the second target interrupt execution entity is greater than that of the first target interrupt execution entity;

[0229] Schedule the target thread from user state to kernel state;

[0230] Replace the first target interrupt execution entity in the target thread with the second target interrupt execution entity;

[0231] The target thread including the second target interrupt execution entity is scheduled to the user state, and the target CPU is used to execute the second target interrupt execution entity.

[0232] In some embodiments, before the processing module 810 replaces the first target interrupt execution entity in the target thread with the second target interrupt execution entity, the processing module 810 is further configured to:

[0233] Save the first target interrupt running entity.

[0234] In some embodiments, after the second target interrupt execution entity completes execution, the processing module 810 is further configured to:

[0235] Schedule the target thread to kernel state;

[0236] Replace the second target interruption execution entity with the first target interruption execution entity;

[0237] The target thread including the first target interrupt execution entity is scheduled to the user state, and the target CPU is used to continue to execute the first target interrupt execution entity.

[0238] In some embodiments, after the first target interrupt execution entity completes execution, the processing module 810 is further configured to:

[0239] Schedule the target thread to kernel state;

[0240] Replace the first target interrupted running entity with the running entity;

[0241] Schedule the target thread containing the running entity to user mode and continue running the running entity using the target CPU.

[0242] In some embodiments, the apparatus 800 may include multiple CPUs, and the processing module 810 is specifically configured to:

[0243] A target CPU that responds to the first interrupt request is determined according to interrupt load sizes of the plurality of CPUs, wherein the first interrupt request is configured to be responsive to the target CPU.

[0244] In some embodiments, the processing module 810 is specifically configured to:

[0245] The CPU with the smaller interrupt load is selected as the target CPU for responding to the first interrupt request.

[0246] In some embodiments, the apparatus 800 may further include a receiving module 820 configured to:

[0247] Receive an indication message sent by the CPU, where the indication message is used to indicate that the CPU cannot handle the interrupt;

[0248] The processing module 810 is specifically configured to:

[0249] A target CPU is determined from CPUs other than the CPU that sent the instruction information and that can respond to the first interrupt request.

[0250] In some embodiments, the first target interrupt execution entity includes at least information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the first interrupt request, and a status register.

[0251] In some embodiments, the second target interrupt execution entity includes at least information related to the interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the second interrupt request, and a status register.

[0252] An embodiment of the present application also provides a chip, which includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the interrupt processing method described in any possible implementation method described above is executed.

[0253] It is understandable that, in order to implement the above functions, the electronic device includes hardware and / or software modules that perform the corresponding functions. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and software. Whether a function is executed in a hardware or software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of this application.

[0254] In this embodiment, the electronic device can be divided into functional modules according to the above-mentioned method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into a single processing module. The above-mentioned integrated modules can be implemented in the form of hardware. It should be noted that the module division in this embodiment is illustrative and is only a logical functional division. In actual implementation, other division methods may be used.

[0255] This embodiment further provides an interrupt processing device, including a module for implementing the interrupt processing method in the above embodiment.

[0256] This embodiment further provides a readable storage medium, which stores instructions. When the instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the interrupt handling method in the above-mentioned embodiment.

[0257] This embodiment further provides a program product. When the program product is run on an electronic device, the electronic device is caused to execute the above-mentioned related steps to implement the interrupt handling method in the above-mentioned embodiment.

[0258] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store execution instructions, and when the device is running, the processor can execute the execution instructions stored in the memory to enable the chip to execute the interrupt processing method in the above-mentioned method embodiments.

[0259] Among them, the interrupt processing device, electronic device, readable storage medium, program product or chip provided in this embodiment are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.

[0260] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0261] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0262] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0263] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0264] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0265] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0266] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A method of interrupt handling, It is characterized in that include: When the first interrupt request is triggered, the electronic device determines a target central processing unit CPU that responds to the first interrupt request; The electronic device determines a first target interrupt running entity on the target CPU; The electronic device schedules the target thread from the user state to the kernel state; The electronic device uses the first target interrupt running entity to replace the running entity of the target thread; The electronic device schedules the target thread including the first target interrupt execution entity to the user state, and uses the target CPU to execute the first target interrupt execution entity.

2. The method according to claim 1, It is characterized in that The electronic device determines a first target interrupt running entity on the target CPU, including: A first target interrupt execution entity on the target CPU is determined according to the priority of the first interrupt request.

3. The method according to claim 2, It is characterized in that The method further comprises: The electronic device creates an interruption running entity resource pool for the target CPU, wherein the interruption running entity resource pool includes a plurality of interruption running entities, and the plurality of interruption running entities have different priorities; The electronic device determines a first target interrupt running entity on the target CPU according to the priority of the first interrupt request, including: The electronic device determines the first target interrupt execution entity from the interrupt execution entity resource pool according to the priority of the first interrupt request.

4. The method according to any one of claims 1 to 3, It is characterized in that Before the electronic device uses the first target interrupt execution entity to replace the execution entity of the target thread, the method further includes: The electronic device stores the running entity of the target thread.

5. The method according to claim 2 or 3, It is characterized in that During the process in which the target CPU runs the first target interrupt running entity, the method further includes: When a second interrupt request is triggered, the electronic device determines that a CPU that responds to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request; The electronic device determines a second target interrupt running entity on the target CPU according to the priority of the second interrupt request, wherein the priority of the second target interrupt running entity is greater than the priority of the first target interrupt running entity; The electronic device schedules the target thread from the user state to the kernel state; The electronic device uses the second target interrupt execution entity to replace the first target interrupt execution entity in the target thread; The electronic device schedules the target thread including the second target interrupt execution entity to the user state, and uses the target CPU to execute the second target interrupt execution entity.

6. The method according to claim 5, It is characterized in that Before the electronic device uses the second target interrupt execution entity to replace the first target interrupt execution entity in the target thread, the method further includes: The electronic device saves the first target interrupt execution entity.

7. The method according to claim 6, It is characterized in that After the second target interruption running entity completes running, the method further includes: The electronic device schedules the target thread to the kernel state; The electronic device uses the first target interruption running entity to replace the second target interruption running entity; The electronic device schedules the target thread including the first target interrupt execution entity to the user state, and uses the target CPU to continue to execute the first target interrupt execution entity.

8. The method according to any one of claims 1 to 7, It is characterized in that After the first target interruption running entity is finished running, the method further includes: The electronic device schedules the target thread to the kernel state; The electronic device uses the running entity to replace the first target interrupt running entity; The electronic device schedules the target thread including the running entity to the user state, and uses the target CPU to continue running the running entity.

9. The method according to any one of claims 1 to 8, It is characterized in that The electronic device includes a plurality of CPUs, and the electronic device determines a target CPU that responds to the first interrupt request, including: The electronic device determines a target CPU that responds to the first interrupt request according to the interrupt load sizes of the multiple CPUs, wherein the first interrupt request is configured to be responsive to the target CPU.

10. The method according to claim 9, It is characterized in that The electronic device determines a target CPU that responds to the first interrupt request according to the interrupt load size of the CPU, including: The electronic device uses the CPU with a smaller interrupt load as a target CPU for responding to the first interrupt request.

11. The method according to any one of claims 1 to 8, It is characterized in that The electronic device determines a target CPU that responds to the first interrupt request, including: The electronic device receives indication information sent by the CPU, where the indication information is used to indicate that the CPU cannot process an interrupt; The electronic device determines the target CPU from CPUs other than the CPU that sends the instruction information and that can respond to the first interrupt request.

12. The method according to any one of claims 1 to 11, It is characterized in that The first target interrupt execution entity at least includes information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the first interrupt request, and a status register.

13. The method according to any one of claims 5 to 7, It is characterized in that The second target interrupt execution entity at least includes information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the second interrupt request, and a status register.

14. A device for interrupt processing, It is characterized in that include: Processing modules for: When determining that the first interrupt request is triggered, determining a target central processing unit CPU that responds to the first interrupt request; Determine the first target interrupt running entity on the target CPU; Schedule the target thread from user state to kernel state; Using the first target interrupt running entity to replace the running entity of the target thread; The target thread including the first target interrupt execution entity is scheduled to the user state, and the first target interrupt execution entity is executed using the target CPU.

15. The device according to claim 14, It is characterized in that The processing module is specifically used for: A first target interrupt execution entity on the target CPU is determined according to the priority of the first interrupt request.

16. The device according to claim 15, It is characterized in that The processing module is also used for: Creating an interruption running entity resource pool for the target CPU, wherein the interruption running entity resource pool includes a plurality of interruption running entities, and the plurality of interruption running entities have different priorities; The processing module is specifically used for: The first target interrupt execution entity is determined from the interrupt execution entity resource pool according to the priority of the first interrupt request.

17. The device according to any one of claims 14 to 16, It is characterized in that Before the processing module uses the first target interrupt running entity to replace the running entity of the target thread, the processing module is further used to: The running entity of the target thread is saved.

18. The device according to claim 15 or 16, It is characterized in that During the process in which the target CPU runs the first target interrupt execution entity, The processing module is also used for: When a second interrupt request is triggered, determining that a CPU that responds to the second interrupt request is the target CPU, and the priority of the second interrupt request is greater than the priority of the first interrupt request; Determining a second target interrupt running entity on the target CPU according to the priority of the second interrupt request, wherein the priority of the second target interrupt running entity is greater than the priority of the first target interrupt running entity; Scheduling the target thread from the user state to the kernel state; Use the second target interrupt execution entity to replace the first target interrupt execution entity in the target thread; The target thread including the second target interrupt execution entity is scheduled to the user state, and the second target interrupt execution entity is executed using the target CPU.

19. The device according to claim 18, It is characterized in that Before the processing module uses the second target interrupt execution entity to replace the first target interrupt execution entity in the target thread, the processing module is further configured to: The first target interrupt running entity is saved.

20. The device according to claim 19, It is characterized in that After the second target interruption running entity finishes running, the processing module is further used for: Scheduling the target thread to the kernel state; Replace the second target interruption running entity with the first target interruption running entity; The target thread including the first target interrupt execution entity is scheduled to the user state, and the first target interrupt execution entity is continued to be executed using the target CPU.

21. The device according to any one of claims 14 to 20, It is characterized in that After the first target interruption running entity has finished running, the processing module is further used for: Scheduling the target thread to the kernel state; Using the running entity to replace the first target interrupt running entity; The target thread including the running entity is scheduled to the user state, and the running entity is continued to be run using the target CPU.

22. The device according to any one of claims 14 to 21, It is characterized in that The device includes multiple CPUs, and the processing module is specifically used for: A target CPU that responds to the first interrupt request is determined according to the interrupt load sizes of the multiple CPUs, wherein the first interrupt request is configured to be responsive to the target CPU.

23. The device according to claim 22, It is characterized in that The processing module is specifically used for: The CPU with the smaller interrupt load is used as the target CPU for responding to the first interrupt request.

24. The device according to any one of claims 14 to 21, It is characterized in that The device also includes a receiving module, the receiving module is used to: receive indication information sent by the CPU, the indication information is used to indicate that the CPU cannot process an interrupt; The processing module is specifically used for: The target CPU is determined from CPUs other than the CPU that sends the instruction information and that can respond to the first interrupt request.

25. The device according to any one of claims 14 to 24, It is characterized in that The first target interrupt execution entity at least includes information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the first interrupt request, and a status register.

26. The device according to any one of claims 18 to 20, It is characterized in that The second target interrupt execution entity at least includes information related to interrupt execution, which is used to indicate an address space, a general register containing an interrupt number corresponding to the second interrupt request, and a status register.

27. An electronic device, It is characterized in that include: one or more processors; One or more memories; the one or more memories store one or more programs, and when the one or more programs are executed by the one or more processors, the method for interrupt processing as described in any one of claims 1 to 13 is executed.

28. A chip, It is characterized in that The chip includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the interrupt processing method according to any one of claims 1 to 13 is executed.

29. A readable storage medium, It is characterized in that The readable storage medium stores instructions, and when the instructions are executed on a device, the interrupt handling method according to any one of claims 1 to 13 is executed.

Citation Information

Patent Citations

  • Interrupt processing method and device and electronic equipment

    CN118689599A

  • Task handling apparatus and method, and electronic device

    CN105579963A

  • Abnormality repair method and device and storage medium

    CN115495278A

  • Method and device for processing user mode interrupt request

    CN115599505A

  • Interrupt servicing in userspace

    US20210208928A1