User mode interrupt processing method, device, equipment and program product

By using interrupt information and stack frame matching mechanisms in user-state interrupt processing, the problems of increased resource overhead and transparency damage in the prior art are solved, and efficient interrupt processing and system stability are achieved.

CN119938246APending Publication Date: 2025-05-06CHINA MOBILE M2M +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411771039.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

When handling user-state interrupts, the prior art leads to an increase in resource overhead such as memory, CPU, and time, and the implicitly creates threads destroys the transparency of operating system services and the singularity of C library design.

Method used

The interrupt information carried by user-state interrupt requests, including interrupt address information, target process and interrupt service programs, enables the operating system to quickly determine the source and processing path of target user-state interrupts. At the same time, the current process and its current stack frame are obtained and matched with the target process. The target stack frame is determined based on the interrupt address information, thereby shortening the context switching time.

Benefits of technology

Effectively shorten the context switching time during interrupt processing, improve the overall performance and resource utilization of the operating system, and ensure system security and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938246A_ABST
    Figure CN119938246A_ABST
Patent Text Reader

Abstract

The invention relates to a user mode interruption processing method and device, equipment and a program product. Through the interrupt information carried by the user mode interrupt request, the operating system can quickly and accurately determine the source and the processing path of the target user mode interrupt in numerous possible interrupt situations. Meanwhile, the context switching time in the interrupt processing process can be effectively shortened by obtaining the current process and the current stack frame thereof, matching the current process and the current stack frame thereof with the target process and determining a mechanism of the target stack frame in combination with the interrupt address information, so that the context switching time in the interrupt processing process can be effectively shortened when the interrupt occurs. The target stack frame can be quickly determined to provide an accurate execution environment recovery basis for subsequent switching between the kernel mode and the user mode and execution of the interrupt service program, and the interrupt processing speed can be increased by switching the kernel mode to the user mode to run the interrupt service program of the user mode. And the overall performance and resource utilization rate of the operating system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of interrupt control, and in particular to a method, device, equipment and program product for processing user mode interrupts. Background Art

[0002] The microkernel design can create a dedicated thread in the driver service and let the main program of the thread call the interrupt service program to handle the interrupt.

[0003] In the related technology, the execution problem of the upper half of the interrupt service program in the user space can be equated to a thread wake-up problem, and then the interrupt can be processed. However, this process amplifies a "function execution problem" into a "thread execution problem", which will lead to an increase in resource overhead such as memory, CPU and time. Summary of the invention

[0004] In view of this, the embodiments of the present disclosure provide a method, apparatus, device and program product for processing user mode interrupts to solve the problems existing in the related art.

[0005] A first aspect of an embodiment of the present disclosure provides a method for processing a user-mode interrupt, the method comprising: in response to a user-mode interrupt request, switching a processing core corresponding to the user-mode interrupt request from user-mode to kernel-mode, wherein the user-mode interrupt request carries interrupt information corresponding to a target user-mode interrupt, the interrupt information comprising interrupt address information, a target process and an interrupt service program; obtaining a current process and a current stack frame corresponding to the current process, and determining a target stack frame based on the interrupt address information and address information corresponding to the current stack frame when the current process matches the target process; switching the processing core from kernel-mode to user-mode based on the target stack frame, and driving the processing core to run the user-mode interrupt service program to process the target user-mode interrupt.

[0006] A second aspect of an embodiment of the present disclosure provides a user-mode interrupt processing device, which is applied to the user-mode interrupt processing method of the first aspect, and the device includes: a response module, which is used to respond to a user-mode interrupt request and switch the processing core corresponding to the user-mode interrupt request from the user mode to the kernel mode, wherein the user-mode interrupt request carries interrupt information corresponding to the target user-mode interrupt, and the interrupt information includes interrupt address information, target process and interrupt service program; a determination module, which is used to obtain the current process and the current stack frame corresponding to the current process, and when the current process matches the target process, determine the target stack frame based on the interrupt address information and the address information corresponding to the current stack frame; and an operation module, which is used to switch the processing core from the kernel mode to the user mode based on the target stack frame, and drive the processing core to run the user-mode interrupt service program to process the target user-mode interrupt.

[0007] According to a third aspect of an embodiment of the present disclosure, a computer device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above-mentioned method for processing user-mode interrupts.

[0008] According to a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of the method for processing user-mode interrupts are implemented.

[0009] Based on the fifth aspect of the present disclosure, a computer program product is provided, and when the computer program / instructions are executed by a processor, the steps of the above-mentioned method for processing user-mode interrupts are implemented.

[0010] At least one of the above technical solutions adopted in the embodiments of the present disclosure can achieve the following beneficial effects: the interrupt information carried by the user-mode interrupt request, including the interrupt address information, the target process and the interrupt service program, can enable the operating system to quickly and accurately determine the source and processing path of the target user-mode interrupt in many possible interrupt situations. At the same time, by obtaining the current process and its current stack frame, matching them with the target process, and then combining the mechanism of determining the target stack frame with the interrupt address information, the context switching time in the interrupt processing process can be effectively shortened. In this way, when an interrupt occurs, the target stack frame can be quickly determined to provide an accurate basis for the recovery of the execution environment for the subsequent kernel-mode and user-mode switching and the execution of the interrupt service program.

[0011] And by switching from kernel state back to user state to run the user state interrupt service program, the operating system can effectively isolate kernel key resources and user state processes, ensuring that user state processes will not damage kernel resources due to erroneous operations or malicious behavior, thereby ensuring the security of the system. At the same time, switching back to user state allows these interrupt-related processes to be performed in a suitable environment, thereby reducing the burden on kernel state and helping to maintain the stability of the system. In summary, the embodiment of the present disclosure running the interrupt service program in user state can make full use of the resources allocated to the process, reduce kernel state resource occupancy and context switching overhead, speed up interrupt processing, and thus improve the overall performance and resource utilization of the operating system. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The above and other purposes, features and advantages of the present disclosure will become more apparent by describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0013] Figure 1A flowchart of a method for processing an upper user-mode interrupt service program in the prior art provided by an exemplary embodiment of the present disclosure;

[0014] Figure 2 A flowchart of a method for processing a user mode interrupt provided by an exemplary embodiment of the present disclosure;

[0015] Figure 3 A schematic diagram of a stack frame structure provided for an exemplary embodiment of the present disclosure;

[0016] Figure 4 A flowchart of another method for processing a user mode interrupt provided by an exemplary embodiment of the present disclosure;

[0017] Figure 5 A flowchart of another method for processing a user mode interrupt provided by an exemplary embodiment of the present disclosure;

[0018] Figure 6 A schematic diagram of the structure of a user mode interrupt processing device provided by an exemplary embodiment of the present disclosure;

[0019] Figure 7 A schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present disclosure;

[0020] Figure 8 A schematic diagram of the structure of a computer system provided for an exemplary embodiment of the present disclosure;

[0021] Fig. 9 A schematic diagram of a computer program product provided for an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0022] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0023] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0024] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0025] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0026] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0027] At present, with the development of operating systems and the increase in user demand, new functional modules are constantly added to the kernel of the operating system, making the kernel increasingly large. The large kernel will not only cause the operating system startup process to take a long time, but may also cause the operating system to run less effectively. At the same time, security vulnerabilities may occur due to the excessive amount of code in the kernel, thereby increasing the difficulty of security maintenance.

[0028] In view of the above problems, a microkernel design scheme has been proposed in the prior art. The main design idea is to transfer some functional modules originally implemented in the kernel space, such as the file system and device driver, to the user space for implementation. This can streamline the microkernel functions, reduce its code volume, and thus reduce the failure rate of the microkernel. At the same time, when the user space crashes, it will not affect the operation of the kernel, so that the risk is controlled outside the kernel.

[0029] In practical applications, an interrupt is a mechanism in the operating system that allows external devices, such as hard disks, network cards, keyboards, etc., or internal events, such as timer expiration and division errors, to send interrupt requests to the central processing unit (CPU) to notify the CPU that there are events that need to be processed. Specifically, an interrupt is like an "emergency call" that allows the CPU to suspend the currently executing task and handle more urgent or more important things. Among them, the CPU is the core component of the computer system, mainly responsible for executing instructions in computer programs and processing data.

[0030] In the related art, each interrupt has a unique interrupt number, so that after the interrupt occurs, the CPU can obtain the interrupt information corresponding to the interrupt according to the interrupt number, for example, the corresponding interrupt service program can be obtained according to the interrupt number, and then the interrupt is processed by executing the interrupt service program. The above process can be performed in the kernel. It should be understood that the interrupt service program is usually divided into an upper half and a lower half. The task of the upper half is to do urgent matters as quickly as possible, while those non-urgent and time-consuming matters will be placed in the lower half.

[0031] For the upper interrupt service routine, under the microkernel architecture concept, the interrupt service routine belongs to the scope of the device driver. Therefore, the execution of the interrupt can be transferred to the user space for processing, so that frequent changes to the kernel can be avoided, thereby maintaining the stability of the kernel. What can be done directly through function calls in the kernel originally requires at least two steps to complete under the microkernel architecture concept, including:

[0032] Step 1: Switch from kernel space to user space;

[0033] Step 2: Execute the interrupt service routine in user space.

[0034] In practical applications, the specific implementation of step 1 essentially depends on the specific design of step 2. Therefore, in the existing microkernel design, a dedicated thread solution can be adopted. This solution is mainly for the interrupt registered by the driver service process. By creating a dedicated thread in the driver service, the main program of the thread can call the interrupt service program corresponding to the upper half of the interrupt service program. And during the operation of the driver service, when no interrupt registered by it occurs, the dedicated thread is in a blocked state; when the interrupt registered by it occurs, the kernel will wake up the dedicated thread and call the interrupt service program through the thread for execution. After the interrupt service program is executed, the dedicated thread enters the blocked state again, waiting for the next interrupt to occur.

[0035] Figure 1 The flowchart of a method for processing an upper user-mode interrupt service program in the prior art is provided as a flowchart of an exemplary embodiment of the present disclosure. Figure 1 As shown, in the thread solution in the prior art, the execution logic of the interrupt service program can be divided into two parts, one of which is executed in the user space and the other is executed in the kernel space, which specifically includes the following steps:

[0036] Step 1: Perform space switching in response to a user-mode interrupt request and save the current process.

[0037] In some embodiments, when hardware devices, such as a keyboard, mouse, and network card, complete data transmission or require specified services, they can send user-mode interrupt requests to the CPU. These user-mode interrupt requests will cause the CPU to pause the currently executing events and instead process the interrupt events corresponding to the user-mode interrupt requests.

[0038] In actual applications, since the interrupt service program is usually located in the space corresponding to the processing core, it will trigger the switching of the processing core from user state to kernel state, that is, from user space to kernel space. Among them, user state is an operating mode of the processor, in which the application runs at a lower privilege level; user space is an area of ​​memory space, where user programs run and store data; kernel state is an operating mode of the processor, which has the highest privilege level. In this mode, the operating system kernel can execute all instructions, including privileged instructions, which can directly operate the key resources of the system. Kernel space is an area of ​​memory space, where the operating system kernel runs and stores data. Based on this, when an interrupt occurs, the operating system will automatically save some key information and control the processing core to switch to kernel state, where the key information can be the information included in the program counter and the processor status register.

[0039] Step 2: Identify the interrupt number corresponding to the user-mode interrupt, and determine the target process and target thread.

[0040] In some embodiments, different operating systems may use different methods to determine the interrupt number corresponding to the user-mode interrupt. Specifically, taking Linux as an example, in early Linux systems, the "int0x80" instruction can be used to trigger a system call, which can be regarded as a software interrupt. The interrupt number corresponding to this instruction is 128 (0x80 converted to decimal). Based on this, after obtaining the interrupt message, the corresponding interrupt number can be determined, and then the target process and target thread corresponding to the interrupt number can be determined.

[0041] Step 3: Perform space switching in response to the space return instruction.

[0042] In some embodiments, the interrupt handler can be caused to return to user space by setting a space return instruction.

[0043] Step 4: drive the target thread to run the interrupt service program.

[0044] In some embodiments, the target process may be called in user space to run an interrupt service routine.

[0045] Step 5: Feedback the operation results.

[0046] In some embodiments, after the target thread is called in the user space to run the interrupt service program, the running result can be fed back to the kernel space, and since the kernel space restarts the current process, the current process is switched to the user space to execute.

[0047] It can be seen that the first part can be processed in the kernel space corresponding to the kernel. At the same time, when receiving a user-mode interrupt request, the current process can be saved, and the interrupt number corresponding to the user-mode interrupt request can be obtained, and based on the interrupt number, it can be determined which thread of which process should handle the interrupt; the second part can be processed in the user space. After the kernel determines the target thread to execute the interrupt, the interrupt service program corresponding to the upper half interrupt service program is called through the target thread, and then the interrupt service program is processed using the target thread. In the prior art, there are mainly the following two problems:

[0048] Question 1: The existing technology can equate the execution problem of the interrupt service program in the user space to a thread wake-up problem, that is, equating "the occurrence of an interrupt" to "the establishment of a thread wake-up condition." It can be seen that the existing technology is actually a magnified solution to the problem, because the interrupt service program is essentially just a special function, and its execution does not require a specific thread context. This is because the execution of the interrupt service program is triggered by a hardware interrupt, rather than actively called by a thread. Therefore, if a "function execution problem" is magnified into a "thread execution problem", this will inevitably lead to an increase in resource overhead such as memory and CPU time.

[0049] Question 2: The operating system corresponding to the solution of the prior art will provide an interrupt service program registration application programming interface (Application Programming Interface, API) in the C library, which is used to implement the registration of the interrupt service program for the user. Among them, the C library is a set of pre-written functions and data types, which provide many basic functions to support the development of C language programs.

[0050] In actual applications, the API only requires the user to input the interrupt number and the address information corresponding to the interrupt service program to work. In the prior art, in the process of creating proprietary threads through API encapsulation, users can use the API like using ordinary functions without having to deeply understand the complex details of thread creation. However, since the implementation of proprietary threads is relatively complex, and if the operating system and C library are implemented by users themselves to implement operating system-related functions or functions similar to the C library, the system's security mechanism may be damaged due to errors or malicious operations, and may also cause a large number of duplicate codes with uneven quality. Therefore, the operating system and C library should not be implemented by users themselves.

[0051] The above method of working by inputting the interrupt number and the address information corresponding to the interrupt service program by the user is a method of implicitly creating threads. The inventor believes that the method of implicitly creating threads in the C library API is inappropriate. The main reasons are as follows;

[0052] From the user's perspective, after inputting the interrupt number and the address information corresponding to the interrupt service program, the operating system should be able to directly execute the interrupt service program. However, in the actual operation process, the operating system will first create the target thread corresponding to the interrupt, and then call the target thread to execute the interrupt service program. The above process of creating the target thread is implicit to the user, therefore, it destroys the transparency principle of the operating system service, that is, this method cannot meet the user's expectations. At the same time, under the POSIX (Portable Operating System Interface) specification, there will be some inheritance relationships between all threads of a process, such as the inheritance of signal mask words. Therefore, if the user wants to use this inheritance setting, the existence of this implicit thread will increase the difficulty of the user's control of the thread organization structure. Based on this, the inventor believes that implicit thread creation destroys the transparency principle of the operating system service, and at the same time, destroys the single principle of the C library design, thereby burying hidden problems for users, causing unpredictable impacts on the logic of the user program, and increasing the difficulty of user problem analysis and debugging.

[0053] In practical applications, the question of "why the use of dedicated threads to execute interrupt service programs will increase the complexity of the problem" is mainly attributed to the characteristics of the interrupt service program itself. Since the core appeal of the interrupt service program lies in the purity of the task objectives and the efficiency of execution, it is essentially a function-oriented function module and has strict non-blocking requirements. At the same time, from the perspective of program operation logic, when the interrupt service program is executed in user mode, since its operation only relies on a single stack structure to achieve basic functional operation (from the perspective of the underlying operating mechanism of the C language), it does not require an additional thread resource to support it. Therefore, it is unnecessary to use dedicated threads to execute interrupt service programs. Instead, it will introduce unnecessary resource overhead and scheduling complexity, causing the problem to be magnified.

[0054] In order to further explain the above situation, the embodiment of the present disclosure raises another related question: "In user-mode programming, what kind of requirements must create threads?" The answer to this question is: any function that has the possibility of blocking must be executed in an independent thread. This is mainly because once a function falls into a blocking state, its subsequent execution will rely entirely on the operating system's wake-up mechanism, and in the design architecture of modern operating systems, threads constitute the basic unit for the operating system to implement wake-up operations. Based on this, in a microkernel architecture, users often construct the upper half of the interrupt service program as a thread solution that follows standard specifications and has explicit definitions, so as to ensure that when dealing with possible function blocking situations, the operating system thread scheduling mechanism can be used to achieve an efficient, reliable program execution process that is compatible with the overall system architecture.

[0055] In view of the above problems, the embodiments of the present disclosure provide a method, device, equipment and program product for processing user-mode interrupts. For the upper half interrupt service program, the interrupt information carried by the user-mode interrupt request, including the interrupt address information, the target process and the interrupt service program, can be used to enable the operating system to quickly and accurately determine the source and processing path of the target user-mode interrupt in many possible interrupt situations. At the same time, by obtaining the current process and its current stack frame, matching them with the target process, and then combining the interrupt address information to determine the mechanism of the target stack frame, the context switching time in the interrupt processing process can be effectively shortened. In this way, when an interrupt occurs, the target stack frame can be quickly determined to provide an accurate execution environment recovery basis for the subsequent kernel state and user state switching and interrupt service program execution. In addition, by switching from the kernel state back to the user state to run the user state interrupt service program, the operating system can effectively isolate kernel key resources and user-mode processes, ensuring that the user-mode process will not damage the kernel resources due to erroneous operations or malicious behaviors, thereby ensuring the security of the system. At the same time, switching back to the user state allows these interrupt-related processes to be performed in a suitable environment, thereby reducing the burden on the kernel state and helping to maintain the stability of the system. In summary, the embodiments of the present disclosure can fully utilize the resources allocated to the process by running the interrupt service program in user mode, reduce kernel mode resource usage and context switching overhead, speed up interrupt processing, and thus improve the overall performance and resource utilization of the operating system.

[0056] Figure 2 The flowchart of a method for processing a user-mode interrupt is provided by an exemplary embodiment of the present disclosure. Figure 2 As shown, specifically including:

[0057] Step 1: Perform space switching in response to a user-mode interrupt request and save the current process.

[0058] Step 2: Identify the interrupt number corresponding to the user-mode interrupt and construct a target stack frame.

[0059] Step 3: Perform space switching in response to the space return instruction.

[0060] Step 4, calling the target stack frame driver processing core to run the interrupt service program.

[0061] Step 5: Feedback the operation results.

[0062] Specifically, the kernel's processing of user-mode interrupts includes steps 2 to 5. In step 5, the instruction int_return can be set so that the interrupt service program returns to the kernel space after execution. Int_return represents interrupt return, which is an internal function of a C library designed in the embodiment of the present disclosure. Based on this, the kernel code can call the interrupt service program through the above method, such as Figure 2 As shown, step 3 can be regarded as the beginning of the call, and step 5 can be regarded as the end of the call. In this process, the interrupt service program does not belong to any thread during execution. In this way, the interrupt service program can be called using kernel code without creating a thread, and then the interrupt service program can be executed.

[0063] The following will introduce the implementation process of the above ideas in the order from user state to kernel state, as follows:

[0064] For user-mode interrupt registration sub-process.

[0065] In some embodiments, the declaration of the user-mode interrupt registration API isr_register provided by the C library is shown in Table 1:

[0066] Table 1 Declaration of API isr_register

[0067]

[0068] Among them, interrupt_id indicates the interrupt number corresponding to the user-mode interrupt; isr_entry indicates the entry address of the interrupt service program; isr_arg indicates the parameter address of the interrupt service program, and if there is none, it can be set to NULL. Among them, isr_register indicates a function used to register the interrupt service program. Its main function is to allow the process to register the user-mode interrupt it wants to handle. If the process registers a certain interrupt number, it is called the target process of the user-mode interrupt. It should be understood that registering a user-mode interrupt is a process-wide transaction and has nothing to do with threads.

[0069] In some embodiments, the implementation points of isr_register mainly include the following two aspects:

[0070] Aspect 1: passing the interrupt service program information to be registered to the kernel. After receiving the interrupt service program information, the kernel will create and maintain a linear table of information corresponding to the interrupt service program indexed by the interrupt number;

[0071] Second, the kernel allocates stack space. Specifically, because the interrupt service program does not belong to any thread during execution, the stack of any thread cannot be used during the entire interrupt processing. At this time, the kernel area stack and the user state stack can be allocated to the interrupt service program. At this time, the kernel only needs to ensure that each process has a corresponding kernel stack and user stack for each CPU processing core, because for any CPU, only one user state interrupt can be processed at the same time.

[0072] For example, assuming that the operating system has 4 CPU processing cores, the kernel implementation part of isr_register can allocate 4 kernel stacks and user stacks for the current process, one for each of the 4 CPU processing cores. The size of the kernel stack can be 8K, and the size of the user stack can be 8K to 8M. The operating system can configure the process according to the situation.

[0073] In some embodiments, an internal interface int_return may be defined in the C library to implement the return process of the kernel to the user mode call. The specific declaration table is shown in Table 2:

[0074] Table 2C library internal interface int_return declaration table

[0075]

[0076] Among them, attribute represents a keyword, noreturn represents an attribute description, int_return represents a function name, and void represents a parameter list.

[0077] In some embodiments, implementation details for int_return include:

[0078] Point 1: This function does not require parameters. Its function is only to trap into the kernel through the operating system call and then perform task scheduling in the kernel. The operating system call number used can be determined by the operating system as needed.

[0079] Point 2: This function never returns and has a noreturn attribute, where the noreturn attribute is a compilation instruction that tells the compiler that the marked function will not return control flow to its caller.

[0080] Point 3: This function is not open to user program developers and is an internal interface function of the C library.

[0081] For the user-mode interrupt processing sub-process.

[0082] In practical applications, the processing of user-mode interrupts always starts from the kernel. In modern CPU architectures, when a user-mode interrupt occurs, the CPU processing core has corresponding mode switching rules, allowing the CPU processing core to enter a mode with operating system permissions to handle the user-mode interrupt. For example, the armv7 architecture has a corresponding interrupt mode, and the armv8 architecture has an el hierarchical division. Therefore, at the software design level, after a user-mode interrupt occurs, regardless of whether the current CPU processing core is in kernel-mode execution or user-mode execution, the CPU processing core will enter kernel-mode and first perform on-site protection of the execution flow of the user-mode interrupt.

[0083] Specifically, "scene protection" and "scene recovery" are the core contents of user-state interrupt processing and thread scheduling. The basic principle is to save a stack frame on the kernel stack corresponding to the execution flow. The scene information of the user-state interrupt and the blocked thread scene information are both saved by this stack frame. Correspondingly, the scene recovery of user-state interrupts and the scene recovery of thread scheduling also rely on stack frames to restore the state of the CPU processing core.

[0084] Figure 3 A schematic diagram of a stack frame structure provided by an exemplary embodiment of the present disclosure. Figure 3 As shown, we can see that the stack frame is basically composed of three parts: general registers, special registers and CPU status registers, as shown in Table 3:

[0085] Table 3 Register comparison table

[0086]

[0087] Specifically, R0 represents the identifier corresponding to the first general register, R1 represents the identifier corresponding to the first general register, R2 represents the identifier corresponding to the first general register, SP represents the stack pointer register, PC represents the program counter, and LR represents the subroutine return register.

[0088] As shown in Table 3, by modifying the key information in the stack frame, the running state of the CPU processing core can be changed. Based on this, a target stack frame can be constructed by modifying the key information in the current stack frame, and the specific parameters are shown in Table 4.

[0089] Table 4 Parameter table corresponding to the target stack frame

[0090] R0 Parameter address of interrupt service routine SP The user stack address where the interrupt service routine is executed PC The entry address of the interrupt service routine LR Entry address of user mode int_return CPU Status Register Status bit flags are set to user mode Other Registers Any

[0091] In actual applications, when the target stack frame is restored to the CPU processing core, first, the CPU processing core will switch to the user state, and because the value of PC is the entry address of the interrupt service program, the CPU processing core will start to execute the interrupt service program, and because the LR register is the entry address of int_return, the int_return function will be executed after the interrupt service program is executed. This function directly enters the kernel through the operating system call, and then the kernel will select the highest priority thread that has entered the ready state from the scheduling queue for switching. It should be understood that the program return address is the entry address of int_return in the user state.

[0092] Figure 4 FIG. 1 is a flow chart of another method for processing a user mode interrupt provided by an exemplary embodiment of the present disclosure. Figure 4 As shown, specifically including:

[0093] S401 , in response to a user-mode interrupt request, switching a processing core corresponding to the user-mode interrupt request from a user-mode to a kernel-mode, and acquiring interrupt information corresponding to the user-mode interrupt request.

[0094] In some embodiments, it is assumed that the CPU processing core corresponding to the user-mode interruption is numbered 0 and is running the current thread a corresponding to the current process A. At this time, when the user-mode interruption occurs, the processing core numbered 0 will enter the kernel mode from the user mode, and at the same time, the kernel will save the scene information of thread a on the kernel stack of thread a. This step is implemented by assembly code.

[0095] S402, determine the interrupt number and target process corresponding to the user mode interrupt, and judge whether the target process is the current process. If so, only switch the thread; if not, switch the process first and then switch the thread. This process can be implemented by mixing assembly and C language.

[0096] In some embodiments, the kernel can obtain the interrupt number that occurs, and determine whether the current process A is its target process based on the interrupt number. If it is, there is no need to switch the process, and only the thread needs to be switched from the current thread to the target thread. If the current process is not the target process of the user-mode interrupt, the kernel can first switch the current process to the target process, and then switch the current thread to the target thread. This process can be implemented in a mixture of assembly and C languages. It should be understood that in actual applications, thread switching and kernel stack switching are closely related operations. Therefore, when the operating system switches threads, in order to ensure that each thread can correctly restore the execution environment, the kernel stack is usually switched at the same time.

[0097] S403, constructing a scheduling stack frame for the current thread a, so that when a core is idle, the current process A that is stopped due to a user mode interrupt can be processed in time.

[0098] In some embodiments, the kernel can construct a scheduling stack frame for the current thread a, and then use the scheduling stack frame to put the current thread a into the queue to be scheduled of the kernel scheduling module. At this time, if there are other idle CPU processing cores, the idle CPU processing cores can be used to execute the current thread a. Among them, the function of the constructed scheduling stack frame is to ensure that the execution state of thread a after being executed is the execution state when it is interrupted by a user-mode interrupt. Based on this, the idle CPU processing core can be used to continue to execute the corresponding task according to the execution state when it is interrupted by a user-mode interrupt, thereby ensuring that the execution of the current thread a is not affected. This process can be implemented in a mixed way of assembly and C language. The specific design of the scheduling stack frame for the current thread a is shown in Table 5.

[0099] Table 5 Design table of the scheduling stack frame of the current thread a

[0100]

[0101]

[0102] S404, the kernel constructs a target stack frame corresponding to the user mode interrupt, and switches the CPU processing core from the kernel mode to the user mode based on the target stack frame.

[0103] In some embodiments, the kernel can construct a target stack frame corresponding to the user-mode interrupt request, and then restore the target stack frame to the CPU processing core, that is, load the interrupt service program from the target stack frame into the CPU processing core to switch the CPU processing core from kernel mode to user mode. At this time, the address space of the CPU processing core is the address space of the target process. It can be seen that the execution of the interrupt service program is essentially a call to the interrupt service program by the kernel.

[0104] S405, the CPU processing core completes the execution of the interrupt service program in the user space.

[0105] In some embodiments, the CPU processing core can execute the interrupt service program in the user space, and when the interrupt service program is completed, the int_return function will allow the CPU processing core to return to the kernel. At this point, the interrupt service program is completed. After that, the kernel can take out a ready thread with the highest priority from the scheduling queue of the scheduling module and perform thread switching. At this time, the operating system returns to the thread execution flow and continues to run.

[0106] The method for processing user mode interrupts provided in the embodiments of the present disclosure may be executed by a terminal or by a chip applied to the terminal.

[0107] Exemplarily, the above-mentioned terminals may include one or more of mobile phones, tablet computers, wearable devices, vehicle-mounted devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), and wearable devices based on augmented reality (AR) and / or virtual reality (VR) technology, and may also include but not be limited to remote control devices, wearable devices, street lamps, home appliances and other smart terminals, which are not specifically limited in the embodiments of the present disclosure.

[0108] Figure 5 A flowchart of another method for processing a user mode interrupt is provided as an exemplary embodiment of the present disclosure. Figure 5 As shown, specifically including:

[0109] S501, in response to a user state interrupt request, switching the processing core corresponding to the user state interrupt request from user state to kernel state, wherein the user state interrupt request carries interrupt information corresponding to a target user state interrupt, and the interrupt information includes interrupt address information, target process and interrupt service program.

[0110] In actual applications, the interrupt service program is stored in a specific space corresponding to the processing core. When there is a user-mode interrupt request, such as when an external device completes a data transmission, when a hardware abnormality occurs, or when a timer is reached, the processing core needs to suspend the currently executing user program and instead process the target user-mode interrupt corresponding to the user-mode interrupt request.

[0111] Before executing the target user-state interrupt, the processing core is usually in user state, corresponding to user space. In this space, the resources that the program can access are subject to certain restrictions, mainly around the related operations required for the application itself to run. However, the interrupt service program corresponding to the target user-state interrupt belongs to the management scope of the operating system kernel. Therefore, in order to correctly execute the interrupt service program, the processing core must switch from user state to kernel state, and correspondingly from user space to kernel space. This switching process is coordinated by the operating system kernel. Through such a switching mechanism, the operating system can respond to various interrupt events in a timely manner, ensure the stable and efficient operation of the computer system, and ensure good interaction and cooperation between hardware and software.

[0112] In actual applications, the operating system may include an interrupt controller, based on which, when a user-mode interrupt request occurs, the interrupt controller may capture the request and determine the interrupt information corresponding to the user-mode interrupt request according to the line or interrupt type corresponding to the user-mode interrupt request. After determining the interrupt information corresponding to the user-mode interrupt request, the interrupt controller may also store the interrupt information in its internal register, so that when the user-mode interrupt request is subsequently processed, the interrupt information may be obtained by reading the register of the interrupt controller.

[0113] Specifically, the interrupt information may include interrupt address information, which may be an entry address corresponding to an interrupt service program; and an interrupt service program is a piece of computer program code specifically used to handle interrupt events, which may be used to handle user-mode interrupts corresponding to user-mode interrupt requests; the target process may be determined through the interrupt service program, because the interrupt service program is often associated with a specific process, and its execution subject or module to which it belongs may usually point to one or more related processes. Therefore, when a user-mode interrupt occurs, the processor calls the interrupt service program for processing, and by tracing the ownership of the interrupt service program, for example, whether it belongs to a device driver process, an operating system kernel process used to proxy external device interrupts, or a custom interrupt handler associated with a specific user process, the process closely related to the interrupt event may be determined.

[0114] S502, obtaining a current process and a current stack frame corresponding to the current process, and determining a target stack frame based on interrupt address information and address information corresponding to the current stack frame when the current process matches the target process.

[0115] In some embodiments, the operating system usually maintains a process list or uses a specific process scheduling data structure to record all processes in running, ready, blocked, etc. Therefore, the current running process can be obtained through the relevant system call or kernel function provided by the operating system, and the current stack top position can be determined by reading the value of the stack pointer register, and then the specific content of the current stack frame can be obtained according to the structural layout of the stack frame.

[0116] For example, in the Linux system, the getpid() function can obtain the identifier (PID) of the current process. Through this identifier, you can further obtain detailed information about the process in the process-related data structure maintained by the kernel, thereby determining the overall status of the current process, resource usage, and other aspects of its characteristics.

[0117] In actual applications, the corresponding identifiers of the current process and the target process can also be obtained respectively. When the identifier corresponding to the current process and the identifier corresponding to the target process are consistent, it is determined that the current process matches the target process, and then the target stack frame can be determined based on the interrupt address information and the address information corresponding to the current stack frame.

[0118] Specifically, the interrupt address information may include a number of key address data related to the interrupt, such as the entry address of the interrupt service program, the jump address within the interrupt service program, and the program return address, etc. These address information play an important role in processing the interrupt and subsequently determining the relevant execution environment, etc. Based on this, the address information corresponding to the current stack frame can be modified according to the above interrupt address information to obtain the target stack frame.

[0119] For example, as shown in Table 4, the entry address of the interrupt service program corresponding to the current stack frame can be modified to the entry address corresponding to the interrupt service program, and the stack address corresponding to the current stack frame can be modified to the user-state stack address corresponding to the interrupt service program; the program return address corresponding to the current stack frame can be modified to the program return address corresponding to the target user-state interrupt, based on which, the key address data in the current stack frame can be modified to the interrupt address information corresponding to the target user-state interrupt, and the target stack frame of the embodiment of the present disclosure can be obtained. It should be understood that the program return address is the entry address of the user-state int_return in Table 4.

[0120] S503, switching the processing core from kernel mode to user mode based on the target stack frame, and driving the processing core to run a user mode interrupt service program to process the target user mode interrupt.

[0121] In some embodiments, the target stack frame may include key execution context information closely related to the target user state interrupt, which covers core elements such as function call hierarchy, local variable status, and return address. Therefore, based on the target stack frame, a state switching operation is performed to smoothly convert the processing core from kernel state to user state. In this process, the data contained in the target stack frame can be deeply parsed, and the register state of the processing core can be carefully adjusted accordingly, including but not limited to accurately restoring the program counter to a suitable user state execution position, and accurately changing the privilege level identification of the processor, so as to achieve seamless switching from kernel state to user state.

[0122] After successfully switching to user mode, the processing core is driven to run the user mode interrupt service program corresponding to the target user mode interrupt quickly and accurately according to the target stack frame and the target user mode interrupt associated with it. Among them, the user mode interrupt service program is a code sequence specially customized for the target user mode interrupt, which has a clear correspondence with the specific device driver logic, software function module or interrupt handling process inside the user mode process.

[0123] Specifically, when the processing core runs the user-mode interrupt service program, it strictly follows the logical order of program instructions and comprehensively and deeply processes the target user-mode interrupt. For example, when facing a data transmission interruption, it strictly verifies the integrity and accuracy of the data, efficiently converts the data format and properly stores it in a memory area that meets the needs of the user-mode process; for software timing interrupts, it promptly updates the relevant program state variables, and accurately and correctly executes the functional code fragment corresponding to the timing task. Through the above complete and orderly operation process, the target user-mode interrupt can be effectively processed, thereby effectively ensuring that the operating system can ensure the efficient operation of kernel-level resource management and basic processing in complex interrupt situations, and enable the user-mode process to respond accurately and appropriately to the target user-mode interrupt event, maintain the stability and reliability of the overall operation of the operating system, and greatly improve the performance and adaptability of the operating system in interrupt processing.

[0124] It can be seen that the embodiment of the present disclosure can use the interrupt information carried by the user-mode interrupt request, including the interrupt address information, the target process and the interrupt service program, so that the operating system can quickly and accurately determine the source and processing path of the target user-mode interrupt in many possible interrupt situations. At the same time, by obtaining the current process and its current stack frame, matching them with the target process, and then combining the interrupt address information to determine the mechanism of the target stack frame, the context switching time in the interrupt processing process can be effectively shortened. In this way, when an interrupt occurs, the target stack frame can be quickly determined to provide an accurate execution environment recovery basis for the subsequent kernel state and user state switching and interrupt service program execution, and by switching from the kernel state back to the user state to run the user state interrupt service program, the operating system can effectively isolate the kernel key resources and the user state process, ensuring that the user state process will not damage the kernel resources due to erroneous operations or malicious behaviors, thereby ensuring the security of the system. At the same time, switching back to the user state allows these interrupt-related processes to be performed in a suitable environment, thereby reducing the burden on the kernel state and helping to maintain the stability of the system. In summary, the embodiments of the present disclosure can fully utilize the resources allocated to the process by running the interrupt service program in user mode, reduce kernel mode resource usage and context switching overhead, speed up interrupt processing, and thus improve the overall performance and resource utilization of the operating system.

[0125] In some embodiments, the interrupt address information includes an entry address and a program return address corresponding to a user-mode interrupt service program, and the method includes: modifying the address information corresponding to the current stack frame based on the entry address and the program return address corresponding to the user-mode interrupt service program to obtain a target stack frame.

[0126] In practical applications, as shown in Table 3 above, the stack frame is basically composed of three parts: general registers, special registers, and CPU status registers, and each part includes one or more sub-registers, which are conducive to the storage of address information corresponding to the current stack frame. Therefore, when processing the target user-state interrupt, the operating state of the CPU processing core can be changed by modifying the key information in the stack frame. Based on this, the target stack frame corresponding to the target user-state interrupt can be obtained by modifying the key information in the current stack frame.

[0127] For example, as shown in Table 4, the entry address of the interrupt service program corresponding to the current stack frame can be modified to the entry address corresponding to the interrupt service program, and the stack address corresponding to the current stack frame can be modified to the user-mode stack address corresponding to the interrupt service program; the program return address corresponding to the current stack frame can be modified to the program return address corresponding to the target user-mode interrupt. Based on this, the key address data in the current stack frame can be modified to the interrupt address information corresponding to the target user-mode interrupt, thereby obtaining the target stack frame of the embodiment of the present disclosure.

[0128] In some embodiments, after the user-mode interrupt service program is executed using the processing core, the processing core may be controlled to switch from the user mode to the kernel mode based on the program return address in the target stack frame.

[0129] Specifically, an internal interface int_return may be defined in the C library to implement the kernel's return process to the user state call. Specifically, after the target user state interrupt is processed in the user space, the processing core returns from the user state to the user state through the internal interface int_return.

[0130] For example, the int_return interface can be combined with the privilege level control mechanism of the operating system to convert the processing core's permissions from the high privilege level of the kernel state back to the low privilege level of the user state by setting the processor's status bit flag. The specific declaration table of the internal interface int_return is shown in Table 2:

[0131] Table 2C library internal interface int_return declaration table

[0132]

[0133] Among them, attribute represents a keyword, noreturn represents an attribute description, int_return represents a function name, and void represents a parameter list.

[0134] In some embodiments, implementation details for int_return include:

[0135] Point 1: This function does not require any parameters. Its function is only to fall into the kernel through a system call and then perform task scheduling in the kernel. The system call number used can be determined by the operating system as needed.

[0136] Point 2: This function never returns and has a noreturn attribute, where the noreturn attribute is a compilation instruction that tells the compiler that the marked function will not return control flow to its caller.

[0137] Point 3: This function is not open to user program developers and is an internal interface function of the C library.

[0138] In some embodiments, a scheduling stack frame is determined based on process information corresponding to the current process, and processing states corresponding to multiple processing cores in the current central processing unit are obtained; an idle processing core whose processing state is an idle state is determined from the multiple processing cores, and the current process is run in the idle processing core.

[0139] In some embodiments, a scheduling stack frame for the current thread can be constructed, and then the scheduling stack frame can be used to put the current thread into the queue to be scheduled of the kernel scheduling module. At this time, if there are other idle CPU processing cores, the idle CPU processing cores can be used to execute the current thread. Among them, the function of the constructed scheduling stack frame is to ensure that the execution state of the current thread after being executed is the execution state when it is interrupted by an interrupt. Based on this, the idle CPU processing core can be used to continue to execute the corresponding task according to the execution state when it is interrupted by the user state interrupt, thereby ensuring that the execution of the current thread is not affected. This process can be implemented by a mixture of assembly and C language. The specific design of the scheduling stack frame for the current thread is shown in Table 6.

[0140] Table 6 Design table of the scheduling stack frame of the current thread

[0141] SP The top position of the stack at the scene where the current thread is interrupted by a user-mode interrupt PC Points to the code for scene recovery (usually assembly code) LR Any CPU Status Register The status bit flag is kernel mode Other Registers Any

[0142] In some embodiments, the interrupt information also includes a target thread, and the method also includes: obtaining the current thread of the current process running, and when the current process matches the target process and the target thread matches the current thread, determining the target stack frame based on the interrupt address information and the address information corresponding to the current stack frame.

[0143] Specifically, the corresponding identifiers of the current process, current thread, target process and target thread can be obtained respectively. When the identifier corresponding to the current process is consistent with the identifier corresponding to the target process, and the identifier corresponding to the current thread is consistent with the identifier corresponding to the target thread, the target stack frame is determined based on the interrupt address information and the address information corresponding to the current stack frame.

[0144] For example, assuming that the identifier corresponding to the current process is X and the identifier corresponding to the current thread is x, based on this, when the identifier corresponding to the target process is X, it is determined that the target process matches the current process, and when the identifier corresponding to the target thread is x, it is determined that the target thread matches the current thread.

[0145] In some embodiments, when the target thread does not match the current thread, the execution right of the processing core is transferred from the current thread of the current process to the target thread, and then the target stack frame is determined based on the interrupt address information and the address information corresponding to the current stack frame.

[0146] Specifically, when the identifier corresponding to the current process and the identifier corresponding to the target process are inconsistent, it is determined that the target thread does not match the current thread. At this time, the execution right of the processing core can be transferred from the current thread running by the current process to the target thread, and then the target stack frame is determined based on the interrupt address information and the address information corresponding to the current stack frame.

[0147] For example, assuming that the identifier corresponding to the current process is X and the identifier corresponding to the target process is Y, at this time, when the identifier corresponding to the target process is different from the identifier corresponding to the target process, it can be determined that the target process does not match the current process. Therefore, the execution right of the processing core can be transferred from the current thread running the current process to the target thread, and then the target stack frame can be determined based on the interrupt address information and the address information corresponding to the current stack frame.

[0148] In the related art, in most operating system designs, there is a global variable pointer in the kernel, which is called current thread, and it always indicates what thread context the current CPU is in. In the scheme designed in the embodiment of the present disclosure, the kernel not only includes the current thread global pointer, but also includes the current process global pointer, which is used to indicate what process context the current CPU is in, because in the design of the embodiment of the present disclosure, when the user mode interrupt is executed, the CPU is not in any thread context, but in a certain process context.

[0149] At the same time, the design of the embodiment of the present disclosure also supports interrupt nesting. First, interrupt nesting refers to the occurrence of an interrupt with a higher priority than the current user state interrupt during the execution of the current upper-half user interrupt. The embodiment of the present disclosure can slightly improve the steps of executing the upper-half user interrupt. When a higher priority interrupt occurs, it is found that the interrupted is an upper-half interrupt service program process. What the embodiment of the present disclosure needs to do is not to put the current execution flow into the scheduling queue, but to perform a logical "push-pop" process to logically push the interrupted low-priority upper-half user interrupt process. When the high-priority upper-half interrupt service program process is executed, the low-priority upper-half interrupt service program process can be logically popped.

[0150] In summary, first of all, the upper half of the interrupt processing proposed in the embodiment of the present disclosure runs in the user state, while the code running in the kernel part is the general logic (constructing the stack frame), and thus different logic will not be run according to different interrupt numbers. Therefore, the method using the embodiment of the present disclosure will not change the kernel due to the addition of interrupt processing or driver development, thereby maintaining the stability of the kernel. At the same time, the embodiment of the present disclosure not only maintains the kernel security brought by the microkernel idea, but also enables the execution of the interrupt service program in the user state, thereby achieving lightweight and thread-free, and maintaining the transparency principle of the operating system service. This not only reduces the system overhead, but also maintains the singleness and elegance of the C library API design, allowing user programming to be free from the various risks brought by implicit threads, and has the characteristics of easy development, easy debugging, and no burden on developers. In terms of performance, the processing timeliness of the prior art depends on the thread scheduling time, while the embodiment of the present disclosure can immediately start processing the user state interrupt when the interrupt occurs. Compared with the prior art, the real-time performance of the embodiment of the present disclosure is better. Specifically, you can refer to the resource demand comparison table 7 of the prior art solution and the embodiment of the present disclosure, which is as follows:

[0151] Table 7 Comparison of resource requirements between the prior art solution and the embodiment of the present disclosure

[0152]

[0153] The above mainly introduces the solution provided by the embodiment of the present disclosure from the perspective of the server. It is understandable that, in order to implement the above functions, the server includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware 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 to exceed the scope of the present disclosure.

[0154] The embodiments of the present disclosure can divide the functional units of the server based on the above method examples. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one management module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiments of the present disclosure is schematic and is only a logical functional division. There may be other division methods in actual implementation.

[0155] In the case of dividing each functional module according to each function, an exemplary embodiment of the present disclosure provides a device for processing a user-mode interrupt, and the device for processing a user-mode interrupt may be a server or a chip applied to a server. Figure 6 The structure diagram of a user mode interrupt processing device provided by an exemplary embodiment of the present disclosure is as follows. Figure 6 As shown, the user mode interrupt processing device 600 includes:

[0156] A response module 601 is used to respond to a user state interrupt request and switch the processing core corresponding to the user state interrupt request from the user state to the kernel state, wherein the user state interrupt request carries interrupt information corresponding to the target user state interrupt, and the interrupt information includes interrupt address information, target process and interrupt service program;

[0157] A determination module 602 is used to obtain a current process and a current stack frame corresponding to the current process, and when the current process matches the target process, determine a target stack frame based on the interrupt address information and the address information corresponding to the current stack frame;

[0158] The running module 603 is used to switch the processing core from kernel mode to user mode based on the target stack frame, and drive the processing core to run the user mode interrupt service program to process the target user mode interrupt.

[0159] In an optional manner, the interrupt address information includes an entry address and a program return address corresponding to the user-state interrupt service program, and the determination module 602 is also used to modify the address information corresponding to the current stack frame based on the entry address and the program return address corresponding to the user-state interrupt service program to obtain the target stack frame.

[0160] In an optional manner, the user-mode interrupt processing device 600 also includes a switching module 604, which is used to control the processing core to switch from user mode to kernel mode based on the program return address in the target stack frame after using the processing core to run the user-mode interrupt service program.

[0161] In an optional manner, the user-mode interrupt processing device 600 also includes a screening module 605, which is used to determine a scheduling stack frame based on process information corresponding to the current process, and obtain processing states corresponding to multiple processing cores in the current central processing unit; determine an idle processing core whose processing state is an idle state from the multiple processing cores, and run the current process in the idle processing core.

[0162] In an optional manner, the interrupt information also includes a target thread, and the user-state interrupt processing device 600 also includes a matching module 606, which is used to obtain the current thread running the current process, and when the current process matches the target process and the target thread matches the current thread, determine the target stack frame based on the interrupt address information and the address information corresponding to the current stack frame.

[0163] In an optional manner, the matching module 606 is also used to transfer the execution right of the processing core from the current thread running by the current process to the target thread when the target thread does not match the current thread; and determine the target stack frame based on the interrupt address information and the address information corresponding to the current stack frame.

[0164] An embodiment of the present disclosure also provides an electronic device, comprising: at least one processor; a memory for storing instructions executable by at least one processor; wherein the at least one processor is used to execute instructions to implement the steps of the above method disclosed in the embodiment of the present disclosure.

[0165] Figure 7 The structure diagram of an electronic device provided by an exemplary embodiment of the present disclosure is shown in FIG. Figure 7 As shown, the electronic device 700 includes at least one processor 701 and a memory 702 coupled to the processor 701. The processor 701 can execute corresponding steps in the above method disclosed in the embodiment of the present disclosure.

[0166] The processor 701 may also be referred to as a central processing unit (CPU), which may be an integrated circuit chip having signal processing capabilities. Each step in the method disclosed in the embodiment of the present disclosure may be completed by an integrated logic circuit of hardware in the processor 701 or by instructions in the form of software. The processor 701 may be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present disclosure may be directly embodied as being executed by a hardware decoding processor, or may be executed by a combination of hardware and software modules in a decoding processor. The software module may be located in a memory 702, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, or other mature storage media in the art. The processor 701 reads the information in the memory 702 and completes the steps of the method in combination with its hardware.

[0167] In addition, when various operations / processes based on the present disclosure are implemented by software and / or firmware, they can be transmitted from a storage medium or a network to a computer system with a dedicated hardware structure, for example, Figure 8 The computer system 800 shown installs the programs constituting the software, and when the various programs are installed, the computer system can execute various functions, including the functions described above. Figure 8 A schematic diagram of the structure of a computer system provided by an exemplary embodiment of the present disclosure.

[0168] Computer system 800 is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0169] like Figure 8As shown, the computer system 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the computer system 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0170] A plurality of components in the computer system 800 are connected to the I / O interface 805, including: an input unit 806, an output unit 807, a storage unit 808, and a communication unit 809. The input unit 806 can be any type of device capable of inputting information to the computer system 800, and the input unit 806 can receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 807 can be any type of device capable of presenting information, and can include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 808 can include but is not limited to a disk, an optical disk. The communication unit 809 allows the computer system 800 to exchange information / data with other devices over a network such as the Internet, and can include but is not limited to a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, for example, a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0171] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above. For example, in some embodiments, the above methods disclosed in the embodiments of the present disclosure may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on an electronic device via ROM 802 and / or a communication unit 809. In some embodiments, the computing unit 801 may be configured to perform the above methods disclosed in the embodiments of the present disclosure by any other appropriate means (e.g., by means of firmware).

[0172] The embodiment of the present disclosure also provides a computer-readable storage medium, wherein when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the above method disclosed in the embodiment of the present disclosure.

[0173] The computer-readable storage medium in the disclosed embodiments may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. The computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. More specifically, the computer-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0174] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0175] Fig. 9 Schematic diagram of a computer program product provided by an exemplary embodiment of the present disclosure. Fig. 9 As shown, the computer program product 900 includes a computer program 901, wherein the computer program 901 implements the above method disclosed in the embodiment of the present disclosure when executed by a processor.

[0176] In embodiments of the present disclosure, computer program codes for performing the operations of the present disclosure may be written in one or more programming languages ​​or combinations thereof, including but not limited to object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer.

[0177] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0178] The modules, components or units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the names of the modules, components or units do not, in some cases, limit the modules, components or units themselves.

[0179] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0180] The above descriptions are only some embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, a technical solution formed by replacing the above features with the technical features with similar functions disclosed in the present disclosure (but not limited to).

[0181] Although some specific embodiments of the present disclosure have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present disclosure. It should be understood by those skilled in the art that the above embodiments may be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.

Claims

1. A method for processing a user-mode interrupt, characterized in that: include: In response to a user state interrupt request, switching a processing core corresponding to the user state interrupt request from user state to kernel state, wherein the user state interrupt request carries interrupt information corresponding to a target user state interrupt, the interrupt information including interrupt address information, a target process and an interrupt service program; Acquire a current process and a current stack frame corresponding to the current process, and when the current process matches the target process, determine a target stack frame based on the interrupt address information and address information corresponding to the current stack frame; The processing core is switched from kernel mode to user mode based on the target stack frame, and the processing core is driven to run the user mode interrupt service program to process the target user mode interrupt.

2. The method according to claim 1, characterized in that The interrupt address information includes an entry address and a program return address corresponding to the user-mode interrupt service program, and the method includes: The address information corresponding to the current stack frame is modified based on the entry address corresponding to the user-mode interrupt service program and the program return address to obtain the target stack frame.

3. The method according to claim 1, characterized in that: The method further comprises: After the processing core is used to run the user-mode interrupt service program, the processing core is controlled to switch from the user mode to the kernel mode based on the program return address in the target stack frame.

4. The method according to claim 1, characterized in that The method further comprises: Determine a scheduling stack frame based on process information corresponding to the current process, and obtain processing states corresponding to multiple processing cores in the current central processing unit; An idle processing core whose processing state is an idle state is determined from the plurality of processing cores, and the current process is run in the idle processing core.

5. The method according to claim 1, characterized in that The interrupt information also includes a target thread, and the method further includes: A current thread of a current process is obtained, and when the current process matches the target process and the target thread matches the current thread, a target stack frame is determined based on the interrupt address information and address information corresponding to the current stack frame.

6. The method according to claim 5, characterized in that The method further comprises: If the target thread does not match the current thread, transferring the execution right of the processing core from the current thread of the current process to the target thread; A target stack frame is determined based on the interrupt address information and address information corresponding to the current stack frame.

7. A user-mode interrupt processing device, characterized in that: include: A response module, configured to respond to a user state interrupt request and switch a processing core corresponding to the user state interrupt request from the user state to the kernel state, wherein the user state interrupt request carries interrupt information corresponding to a target user state interrupt, and the interrupt information includes interrupt address information, a target process, and an interrupt service program; A determination module, configured to obtain a current process and a current stack frame corresponding to the current process, and determine a target stack frame based on the interrupt address information and address information corresponding to the current stack frame when the current process matches the target process; The running module is used to switch the processing core from kernel mode to user mode based on the target stack frame, and drive the processing core to run the user mode interrupt service program to process the target user mode interrupt.

8. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product comprising computer program instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Kernel service transfer method and system for accelerating user space execution

    CN120123187A

  • A kernel service transfer method and system for accelerating user space execution

    CN120123187B