COMPUTER DEVICE, EXCEPTION PROCESSING METHOD, AND INTERRUPT PROCESSING METHOD - Patent application

By using a redirection device to switch directly from VM to host user mode for exception and interrupt handling, the method addresses performance overhead in virtualization systems, improving I/O efficiency.

JP7538950B2Active Publication Date: 2024-08-22HUAWEI TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
JP2023512217
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2020-08-19
Filing Date
2021-06-02
Publication Date
2024-08-22
Estimated Expiration
2041-06-02

AI Technical Summary

Technical Problem

Existing virtualization systems in computing devices experience significant overhead due to frequent switching between virtual machine (VM) and host modes during exception and interrupt handling, affecting I/O performance.

Method used

Implementing a redirection device to directly switch from the virtualization privilege level of a VM to the user mode of the host, reducing the need for multiple mode switches and executing exception or interrupt handling functions in user mode.

Benefits of technology

This approach significantly reduces switching overhead and improves computing device performance by minimizing the need for multiple mode transitions, enhancing I/O operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007538950000006
    Figure 0007538950000006
  • Figure 0007538950000014
    Figure 0007538950000014
  • Figure 0007538950000003
    Figure 0007538950000003
Patent Text Reader

Abstract

A computer device is disclosed. In a virtualized I / O procedure, a redirection unit in the processor is used to implement a privilege level switch in a synchronous processing procedure to switch directly from the virtualized privilege level of the VM to the user mode of the host, and perform corresponding exception handling. In an asynchronous processing procedure, an interrupt request may be asynchronously forwarded by using a virtual event notification unit and an interrupt controller in the processor without passing through the kernel mode of the host. In both the synchronous and asynchronous processing procedures of the device, the overhead generated during the switch is reduced, improving the performance of the computer device.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0002] The present application relates to the field of computer technology, and in particular to computer devices, methods of exception handling, and methods of interrupt handling. [Background technology]

[0003] In virtualization systems, virtual device simulation solutions are mainly used to implement input / output (I / O) virtualization. Based on the mode of processing virtual I / O, virtual device simulation solutions can be classified into synchronous processing and asynchronous processing.

[0004] In a synchronous processing procedure, an exception instruction is triggered when a virtual machine (VM) performs an operation related to a virtual I / O device (e.g., a read or write operation to a serial port memory, or an access operation to another virtual I / O device). The VM sends the exception instruction to a virtual machine monitor (VMM) in a kernel mode of the host, and the VMM transfers the exception processing to the host in a user mode for processing the exception in the user mode of the host. After the exception is processed, the processing result is transferred from the host in the user mode to the VMM, and then from the VMM to the VM. In this procedure, the overhead of switching between the VM and the VMM is generated twice, and the overhead of switching between the host kernel mode and the host user mode is generated twice.

[0005] In the asynchronous processing procedure, an interrupt request is triggered when the VM performs a read or write operation on the memory of the disk or on the memory of the network adapter. The interrupt request needs to notify a quick emulator (Qemu) thread on the remote processor in an asynchronous manner to complete the processing of the interrupt request. The remote processor is another processor different from the local processor that supports the execution of the VM. On the local processor, the VM triggers an exception instruction, which then sends the exception instruction to the VMM in the host kernel mode. The VMM then identifies the instruction as a user mode exception instruction, which then forwards the exception instruction from the host kernel mode to the host user mode, a system call is triggered from the host user mode to enter the host kernel mode, an interrupt request is triggered in the host kernel mode, and the interrupt request is forwarded to the remote processor. The Qemu thread on the remote processor needs to wake up the scheduler in the kernel mode. In this procedure, in order to access a physical device such as a disk, the kernel mode needs to be switched to the user mode and then back to the kernel mode by using a system call. It can be seen that in asynchronous processing procedures, switching between the user mode and the kernel mode also needs to be performed frequently.

[0006] In both synchronous and asynchronous processing procedures, overhead is generated multiple times during switching and I / O performance is affected. Summary of the Invention [Means for solving the problem]

[0007] The embodiments of the present application provide a computer device, an exception handling method, and an interrupt handling method to reduce the overhead generated during switching and improve the performance of the computer device. The present application further provides corresponding apparatuses, computer-readable storage media, computer program products, etc.

[0008] A first aspect of the present application provides a computer device, the computer device including a hardware layer, a host executing on the hardware layer, the hardware layer including a first processor, a virtual machine (VM) executing on the first processor, the first processor including a redirection device. The first processor is configured to retrieve an exception instruction triggered by the VM. The redirection device is configured to switch from a virtualization privilege level of the VM to a user mode of the host. The first processor is further configured to execute an exception handling function corresponding to the exception instruction in the user mode of the host.

[0009] In the first aspect, exceptions triggered by the VM are handled in a synchronous manner.

[0010] It should be noted that the processor in this embodiment of the present application may be a processor core, and one processor core supports the execution of one VM in one time period. Multiple VMs may use the same processing core in a time division multiplexed manner.

[0011] In a first aspect, the computing device may be a terminal device such as a mobile phone, a tablet computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a handheld computer, or a netbook, or the computing device may be a server. The hardware layer may include hardware devices such as a processor, a memory, and a communication interface. The VM and the host are simulated by software and run in the hardware layer. The redirection device included in the first processor may be implemented by using a hardware circuit. When the VM performs an input / output (I / O) operation, an exception instruction may be triggered. When the VM needs to access a virtual I / O device, the I / O operation may be the triggered operation. The virtual I / O device generally includes a front-end driver and a back-end device. The front-end driver runs on the VM, and the program of the back-end device runs on the host. When an operation performed by the VM needs to access a back-end device by using a front-end driver, an exception instruction is triggered and the back-end device is accessed by using the exception instruction. A virtual I / O device is one type of back-end device. An access to a virtual I / O device may be a read of data from the memory of the virtual I / O device or a write of data to the memory of the virtual I / O device. A virtual I / O device is an I / O device that may be used by a virtual machine. A virtual I / O device may be a fully virtualized I / O device simulated by using software. A virtual I / O device may also be mapped to a physical I / O device in a mapping manner. When a virtual I / O device is accessed, a physical I / O device is ultimately accessed.

[0012] When the first VM performs an operation that exceeds the permission of the first VM, the exception instruction may be that an exception occurs. The first processor may detect the exception code by calling a computer instruction stored in a memory and executing a corresponding detection logic. This step may also be that the first processor detects the exception code by executing a hardware detection logic, and then obtains the exception instruction. After obtaining the exception instruction, the first processor may write the cause and type of the exception, the memory accessed by the first VM, and the return address to a hardware register for subsequent exception processing.

[0013] The virtualization privilege level of a VM represents a privilege level in a virtualization mode, i.e., an operating mode of a VM, and may also be called a virtualization mode. The virtualization privilege level includes a virtualized user mode and a virtualized kernel mode. Switching (direct switching) from the virtualization privilege level of a VM to the user mode of a host may include a procedure of moving information about the virtualization privilege level of the VM from a register used to store the privilege level, and then writing information about the user mode of the host to a register, which may be a system register. In this application, the privilege level and virtualization may be represented by using one bit each. For example, 0 indicates user mode, 1 indicates kernel mode, 0 indicates non-virtualization, and 1 indicates virtualization. The privilege level is in the first bit, and whether to virtualize is in the second bit. For example, 00 indicates non-virtualized user mode, sometimes called host user mode, 10 indicates non-virtualized kernel mode, sometimes called host kernel mode, 01 indicates virtualized user mode, sometimes called VM user mode, and 11 indicates virtualized kernel mode, sometimes called VM kernel mode.

[0014] A user mode host refers to a host that operates in a user mode. The user mode of a host refers to the operating mode of the host. The operating modes of the host include a user mode and a kernel mode.

[0015] The redirection device being configured to switch from the virtualization privilege level of the VM to the user mode of the host may be understood as the redirection device being configured to switch the operation mode of the first processor. Specifically, the redirection device is configured to switch the operation mode of the first processor from the virtualization mode to the user mode (the user mode of the host) in the non-virtualization mode. The operation mode of the processor may be understood as the operation state of the processor, and the operation state of the processor may be represented by the value of a bit in the aforementioned system register.

[0016] The exception handling function may be included in a thread of a virtual central processing unit (vCPU) executing in a user mode of the host. The first processor may execute an exception handling function corresponding to the exception instruction in the user mode of the host. The exception instruction may be associated with an exception handling function based on the exception type. Different exception types may correspond to different exception handling functions. For example, an exception handling function corresponding to a write operation performed by the VM on a serial port is different from an exception handling function corresponding to a write operation performed by the VM on a graphics card, or all exception instructions may correspond to the same exception handling function, and different data are called to handle the different exception instructions when the exception handling function is executed. For example, if the exception instruction is triggered by an I / O operation performed by the VM, the corresponding I / O operation is completed by executing the exception handling function, e.g., reading data in a memory of the I / O device or writing data to the memory of the I / O device. If the exception instruction is triggered by another operation (e.g., a page fault) performed by the VM, the first processor executes the exception handling function to handle the page fault. In other words, the redirection device is configured to switch from the virtualization mode to the non-virtualization mode, so that an interrupt or exception in the user mode can be redirected to the user space of the host for processing, i.e., the host in the user mode executes an exception or interrupt processing function.

[0017] It can be seen from the first aspect that the computer device can directly switch the exception instruction from the virtualization privilege level of the VM to the user mode of the host by using the redirection device, and execute the exception handling function in the user mode of the host.Compared with the conventional technology in which the virtualization privilege level of the VM needs to be first switched to the kernel mode of the host, and then the kernel mode of the host needs to be switched to the user mode of the host, the computer device can reduce the switching overhead and improve the performance of the computer device.

[0018] In one possible implementation of the first aspect, the redirection device is further configured to write an entry address of the exception handling function to the first register. The first processor is specifically configured to read the entry address of the exception handling function from the first register, call the exception handling function based on the entry address, and execute the exception handling function corresponding to the exception instruction in the user mode of the host.

[0019] In this possible embodiment, the redirection device may write an entry address of an exception handling function (sometimes called a trap handler) to the first register. In this manner, the first processor subsequently reads the entry address from the first register, calls the exception handling function based on the entry address, and executes the exception handling function in the user mode of the host. The "redirection" in the redirection device may include switching privilege levels and writing the entry address of the exception handling function to the first register. In this possible embodiment, the redirection device writes the entry address to the first register, which may allow the first processor to quickly execute the exception handling function.

[0020] In one possible implementation of the first aspect, the exception handling function is included in a virtual processor thread executing in a user mode of the host, and an execution environment assigned to the virtual processor thread includes a main thread execution environment, a VM execution environment, and a shadow execution environment, the execution environment assigned to the virtual processor thread is a resource required to execute the virtual processor thread, and the shadow execution environment has a user mode memory space independent from the main thread execution environment and the VM execution environment. The shadow execution environment is used to execute the exception handling function, and the exception handling function is used to handle the exception that triggers the exception instruction. The first processor is configured to switch from a VM context to a user mode shadow execution environment context, and the user mode memory space of the shadow execution environment is used to store the VM context that is moved during the context switch.

[0021] In this application, executing an exception handling function includes a context switching procedure and handling of the exception in the user mode of the host.

[0022] In this possible embodiment, before a virtual processor thread executes, the virtual processor thread applies to the host for resources, and the host allocates the virtual processor thread with the resources it needs for execution. The resources may be referred to as an execution environment. In this application, the "execution environment" includes two aspects: a software execution environment and a hardware execution environment. The software execution environment includes information in a stack and thread context information that are used when a virtual processor thread executes in a different execution environment. The hardware aspect includes hardware resources that are used when a thread executes, including memory resources or processing resources. The main thread execution environment, the VM execution environment, and the shadow execution environment all have independent memory spaces. The main thread execution environment includes an execution environment of a main thread in user mode and an execution environment of a main thread in kernel mode. The execution environment of a main thread in kernel mode is used to store the context of the VM and the host. The shadow execution environment includes a user mode shadow execution environment and a kernel mode shadow execution environment. The user mode shadow execution environment is the user mode memory space of the shadow execution environment. The user mode memory space represents a memory address space corresponding to the user mode shadow execution environment, and the user mode memory space is used to store the context of the VM that is moved from the register during a context switch. Since the shadow execution environment has an independent user mode memory space, the user mode memory space can store the context of the VM, and by using the main thread execution environment, there is no need to first switch from the virtualization privilege level of the VM to the kernel mode of the host, and then switch from the kernel mode to the user mode. In this way, the switching overhead can be further reduced, and the performance of the computer device is improved.

[0023] In one possible implementation of the first aspect, the first processor is further configured to: if an interrupt or exception that needs to be handled in kernel mode of the host is generated when the exception handling function is executed, switch from the user mode shadow execution environment context to the kernel mode shadow execution environment context, handle the interrupt or exception that needs to be handled in the kernel mode of the host, in the kernel mode of the host, and switch from the kernel mode shadow execution environment context back to the user mode shadow execution environment context to continue execution of the exception handling function.

[0024] In this possible embodiment, the shadow execution environment further includes a kernel mode shadow execution environment, i.e., a kernel mode user space. When the context of the user mode shadow execution environment is switched to the context of the kernel mode shadow execution environment, the kernel mode user space is used to store the context of the user mode shadow execution environment and the switched from registers. This possible embodiment may ensure that when an exception handling function is executed, an interrupt or exception that needs to be executed in kernel mode is handled, improving the compatibility of the computer system.

[0025] A second aspect of the present application provides a computer system. The computer system is based on the computer system provided in the first aspect, and further includes a second processor and an interrupt controller. For the procedure before the exception handling function is executed in the first aspect, please refer to the contents of the first aspect. The difference is that the first processor does not execute the exception handling function, but sends an access request to the interrupt controller, and the access request indicates access to a user mode address mapping space in the interrupt controller. Then, the interrupt controller sends an interrupt request to the second processor, and the second processor executes the exception handling function based on the interrupt request.

[0026] According to the second aspect, the redirection to the host user mode is performed by using a redirection device in the synchronous processing solution of the first aspect, and then the asynchronous processing procedure is performed by accessing a user mode address mapping space in the interrupt controller. According to the second aspect, the switch from the privilege level of the VM to the host user mode is performed by using a redirection device. Thus, the switching overhead of the asynchronous processing is reduced, and the performance of the computing device is improved.

[0027] A third aspect of the present application provides a computer device, the computer device including a hardware layer, a host running on the hardware layer, the hardware layer including a first processor, a second processor, and an interrupt controller, a virtual machine, the first VM, running on the first processor, the first processor including a virtual event notification device, the first processor configured to obtain a first interrupt request triggered by the first VM, the first interrupt request being used to request the interrupt handling function to be executed, the virtual event notification device configured to send interrupt information directly to the interrupt controller in response to the first interrupt request, the interrupt controller configured to determine an identifier of the second processor based on the interrupt information, and send a second interrupt request to the second processor based on the identifier of the second processor, the second processor configured to execute the interrupt handling function in response to the received second interrupt request.

[0028] In a third aspect, the interrupt triggered by the first VM is processed in an asynchronous processing manner. The asynchronous processing refers to a cross-processor processing procedure, i.e., the first VM running on the first processor executes the interrupt, and the interrupt processing procedure can be completed by using the second processor.

[0029] In a third aspect, the virtual event notification device may be implemented by using a hardware circuit. When the first VM performs an I / O operation, the first interrupt request may be triggered, and when the first VM needs to access a virtual I / O device, the I / O operation may be a triggered operation. The interrupt information indicates a virtual event occurring in the first VM. According to the computer device that processes interrupts in an asynchronous manner and is provided in the third aspect, the virtual event notification device may process the interrupt event without being trapped in the kernel mode of the host. Therefore, the privilege level switching overhead is reduced, and the performance of the computer device is improved.

[0030] In a possible implementation of the third aspect, the first interrupt request includes a virtual event interrupt request number VEI ID, where the VEI ID identifies a virtual event that triggers the first interrupt request. The first processor is further configured to obtain a VM ID of the first VM. The interrupt information includes the VEI ID and the VM ID of the first VM. The interrupt controller is specifically configured to determine an identifier of a corresponding second processor, a VEI physical number, and a privilege level of a host that processes the first interrupt request based on the VEI ID and the VM ID of the first VM, where the VEI physical number identifies a virtual event in the host, and to send a second interrupt request to the second processor based on the identifier of the second processor, where the second interrupt request includes information indicating the privilege level of the host. The second processor is specifically configured to obtain the VEI physical number, and execute an interrupt processing function corresponding to the VEI physical number in response to the received second interrupt request based on a processing scheme corresponding to the privilege level of the host.

[0031] In this possible embodiment, the VEI ID identifies a virtual event occurring in a virtual machine, and the VEI physical number indicates an identifier of the virtual event in the host. There is a mapping relationship between the VEI ID and the VEI physical number. The VEI ID and the VEI physical number that are mapped to each other indicate the same virtual event (e.g., a disk read / write event or a network adapter read / write event). The VEI ID may be represented by a value from 0 to 63, for example. Each value identifies a different virtual event. One I / O device may have multiple different virtual events. For example, a disk read event may be represented by a value 1, a disk write event may be represented by a value 2, a disk control event may be represented by a value 3, a network adapter read event may be represented by a value 4, a network adapter write event may be represented by a value 5, and so on. The same virtual event in each virtual machine may use the same VEI ID. The VEI physical number may be globally unique, and virtual events of the same VEI ID occurring on different virtual machines may correspond to different VEI physical numbers. For example, the VEI physical number corresponding to the value range of the VEI ID of VM1 may be 0 to 63, the VEI physical number corresponding to the value range of the VEI ID of VM2 may be 64 to 127, and the rest may be inferred by analogy. In this way, the second processor may determine the virtual machine where the virtual event occurs based on the range of different VEI physical numbers, and then determine the virtual event occurring on the VM based on the specific value of the VEI physical number. For example, the VEI ID is 5 indicates a disk read event, and when the VEI physical number is 5, it indicates that the disk read event occurred on VM1. When the VEI physical number is 69, it indicates that the disk read event occurred on VM2. The correspondence between the virtual event and the VEI ID, and the correspondence between the VEI physical number and the virtual machine may be set based on requirements. This is not limited in the present application.

[0032] In the present application, since the same virtual event in each virtual machine may use the same VEI ID, in order to distinguish between virtual machines where a virtual event occurs, the first processor may obtain a VM ID, and the VM ID may be read by the first processor from a register for storing a virtual machine identifier. Then, the virtual event notification device sends the VEI ID and the VM ID to an interrupt controller, and the interrupt controller may search for the identifier of the second processor, the VEI physical number, and the corresponding host privilege level based on the VEI ID and the VM ID. The interrupt controller may hold a mapping table whose input is (VEI ID)+(VM ID) and whose output is (CPU ID)+(VEI physical number)+(host privilege level). The interrupt controller may directly determine the corresponding (CPU ID)+(VEI physical number)+(host privilege level) based on the mapping table. The interrupt controller may determine the second processor to subsequently perform asynchronous interrupt processing based on the CPU ID, and may determine whether to subsequently use a user mode processing method or a kernel mode processing method based on the host privilege level. The second processor may read the VEI physical number from the register storing the VEI physical number, and determine an interrupt handling function corresponding to the VEI physical number by using the VEI physical number, and then execute the interrupt handling function based on a user mode processing procedure or a kernel mode processing procedure. In the computer device, the mapping relationship between the VEI physical number and the interrupt handling function may be held by using a memory, and the second processor may read the corresponding interrupt handling function from the memory based on the VEI physical number. In this possible embodiment, a virtual event occurring on a virtual machine may be quickly determined by using the VEI ID and the VM ID, and then the virtual event notification device and the interrupt controller may process the interrupt event without being trapped into the kernel mode of the host. Therefore, the privilege level switching overhead is reduced, and the performance of the computer device is improved.

[0033] In a possible implementation of the third aspect, the first interrupt request includes a virtual event interrupt request number VEI ID, the VEI ID identifies a virtual event that causes the first VM to trigger the first interrupt request, and the interrupt information includes the VEI ID. The interrupt controller is specifically configured to determine an identifier of a corresponding second processor and a privilege level of a host that processes the first interrupt request based on the VEI ID, and to send a second interrupt request to the second processor based on the identifier of the second processor, the second interrupt request including information indicating the privilege level of the host. The second processor is specifically configured to obtain the VEI ID, and execute an interrupt processing function corresponding to the VEI ID in response to the received second interrupt request based on a processing scheme corresponding to the privilege level of the host.

[0034] In this possible embodiment, the VEI ID may be globally unique, and different VMs use different VEI IDs for the same virtual event. In this way, the VM ID does not need to be used, the VEI physical number does not need to be translated, and subsequent interrupt processing can be performed once the corresponding identifier of the second processor and the privilege level of the host are determined based on the VEI ID. The second processor may obtain the VEI ID from a register that stores the VEI ID. In this possible embodiment, the virtual event occurring on the virtual machine may be quickly determined by using the VEI ID, and then the virtual event notification device and the interrupt controller may process the interrupt event without being trapped into the kernel mode of the host. Thus, the privilege level switching overhead is reduced, and the performance of the computer device is improved.

[0035] In a possible implementation of the third aspect, the privilege level of the host is a user mode, and the interrupt controller may further set information about the shadow thread. The second processor further includes a hardware assisted switching device. The hardware assisted switching device is configured to switch from a first thread to a shadow thread, the first thread being a thread executed by the second processor before switching, the shadow thread being a thread executing in the host in the user mode, and the shadow thread being used to execute an interrupt handling function. The second processor is specifically configured to execute an interrupt handling function in the user mode of the host.

[0036] In this possible implementation, the first thread may also be referred to as an interrupt thread, or the first thread may switch information about the interrupt thread to information about the shadow thread, the interrupt thread being the thread being executed by the second processor before the switch. The second processor is further configured to switch to an entry address of an interrupt handling function of the shadow thread and execute the interrupt handling function in the user mode of the host, where the interrupt handling function responds to the second interrupt request.

[0037] In this possible embodiment, the hardware assisted switching device may be implemented by using a hardware circuit. The thread switching may include switching information regarding the threads, and the information regarding the first thread includes the memory address space, page table start address, data structure information, processing privilege level, etc. of the first thread. The shadow thread is a thread running in the host in user mode and configured to execute an interrupt processing function. The information regarding the shadow thread includes the memory address space, page table start address, data structure information, processing privilege level, etc. of the shadow thread. The shadow thread may be understood as a shadow of the first thread. After the first thread running by the second processor is interrupted, the second processor executes the shadow thread to perform interrupt processing. In this possible embodiment, the information regarding the first thread and the information regarding the shadow thread may be quickly switched by using the hardware assisted switching device without being trapped into the kernel mode of the host, so that the interrupt may be directly processed in the user mode of the host. Thus, the switching overhead is further reduced and the performance of the computer device is improved.

[0038] In a possible implementation of the third aspect, the second processor further includes a redirection device, and the second processor is further configured to determine whether the first thread is at a virtualization privilege level of the second VM before executing the interrupt handling function in the user mode of the host, and the second VM executes on the second processor. The redirection device is configured to switch the virtualization privilege level of the second VM to the user mode of the host if the interrupt thread is at the virtualization privilege level of the second VM.

[0039] In this possible embodiment, the redirection device in the second processor may be implemented by using a hardware circuit. For the function of the redirection device, please refer to the function of the redirection device in the first aspect. In this possible embodiment, the virtualization privilege level of the second VM can be directly switched to the user mode of the host by using the redirection device in the second processor. Therefore, the switching overhead in the asynchronous processing procedure is further reduced, and the performance of the computer device is further improved.

[0040] In a possible implementation of the third aspect, the redirection device is further configured to write an entry address of the interrupt handling function to the first register. The second processor is specifically configured to read the entry address of the interrupt handling function from the first register, call the interrupt handling function based on the entry address, and execute the interrupt handling function in a user mode of the host.

[0041] The procedure may be readily implemented by using the corresponding content of the first aspect, and the details will not be described again here.

[0042] In a possible implementation of the third aspect, the second processor is specifically configured to switch from the context of the second VM to the context of the shadow thread, process an interrupt in the user mode of the host, and switch from the context of the shadow thread back to the context of the second VM after processing the interrupt. The redirection device is further configured to switch from the user mode of the host back to the virtualization privilege level of the second VM. The second processor is further configured to continue execution of the second VM.

[0043] In this possible implementation, executing the interrupt handling function includes a procedure of context switching and a procedure of handling the interrupt. In this solution, the redirection device directly switches from the user mode of the host to the virtualization privilege level of the second VM, so that the interrupted second VM can be started quickly.

[0044] In a possible implementation of the third aspect, the second processor is further configured to switch from the context of the first thread to a context of the shadow thread, handle an interrupt in the user mode of the host, and after handling the interrupt, switch from the context of the shadow thread to a context of the first thread and continue executing the first thread.

[0045] In this possible implementation, if the virtual machine is not running on the second processor, the second processor may directly switch between the context of the first thread and the context of the shadow thread, then service the interrupt, and then switch back to the context of the first thread. In this manner, the first thread may be started quickly, allowing the first thread to continue executing.

[0046] In a possible implementation of the third aspect, the privilege level of the host is a kernel mode, and the second processor is in the kernel mode of the host and is configured to receive a second interrupt request sent by the interrupt controller, switch to an entry address of an interrupt handling function of the kernel mode of the host, the interrupt handling function responds to the second interrupt request, and execute the kernel mode interrupt handling function in the kernel mode of the host.

[0047] In this possible embodiment, if the privilege level of the host is kernel mode, the interrupt controller may directly send the kernel mode interrupt to the second processor, and the second processor performs the kernel mode processing procedure to complete the corresponding operation. If the second VM runs on the second processor before the second processor switches to the entry address of the interrupt handling function of the kernel mode of the host, the second processor first switches from the virtualization privilege level of the second VM to the kernel mode of the host. If the virtual machine is not running on the second processor and the host is in user mode, the second processor first switches from the user mode of the host to the kernel mode of the host. If the host is in kernel mode, the second processor directly switches to the entry address of the interrupt handling function and then executes the interrupt handling function.

[0048] A fourth aspect of the present application provides a computer device, the computer device including a first processor, a second processor, and an interrupt controller, a host executing on the computer device, and the second processor further including a hardware assisted switching device. The first processor may send an interrupt request to the interrupt controller by accessing a user mode address mapping space or a kernel mode address mapping space in the interrupt controller. The interrupt controller sets information about a shadow thread. The interrupt controller sends the interrupt request to the second processor. The hardware assisted switching device is configured to switch from the first thread to a shadow thread, the first thread being a thread executed by the second processor before the switch, the shadow thread being a thread executing in the host in a user mode and including an interrupt handling function, the interrupt handling function corresponding to the second interrupt request. The second processor is specifically configured to execute the interrupt handling function in the user mode of the host.

[0049] In this possible embodiment, the hardware assisted switching device may be implemented by using a hardware circuit. The thread switching may include information about the thread switching. The information about the first thread includes the memory address space, page table start address, data structure information, and processing privilege level of the first thread. The shadow thread is a thread running in the host in user mode and is used to execute an interrupt processing function. The information about the shadow thread includes the memory address space, page table start address, data structure information, processing privilege level, etc. of the shadow thread. The first thread is a thread running by the second processor. The shadow thread may be understood as a shadow of the first thread. After the thread running by the second processor is interrupted, the second processor runs the shadow thread to perform interrupt processing. In this possible embodiment, the information about the first thread and the information about the shadow thread may be quickly switched by using the hardware assisted switching device without being trapped into the kernel mode of the host, so that the interrupt can be directly processed in the user mode of the host. Thus, the switching overhead is further reduced and the performance of the computer device is improved.

[0050] In a possible implementation of the fourth aspect, the second processor further includes a redirection device, and the second processor is further configured to determine whether the first thread is in a virtualization privilege level of a second VM before executing the interrupt handling function in a user mode of the host, and the second VM executes on the second processor. If the first thread is in a virtualization privilege level of the second VM, the redirection device is configured to switch the virtualization privilege level of the VM to a user mode of the host.

[0051] In this possible embodiment, the redirection device in the second processor may be implemented by using a hardware circuit. For the function of the redirection device, please refer to the function of the redirection device in the first aspect. In this possible embodiment, the virtualization privilege level of the second VM can be directly switched to the user mode of the host by using the redirection device in the second processor. Therefore, the switching overhead in the asynchronous processing procedure is further reduced, and the performance of the computer device is further improved.

[0052] In a possible implementation of the fourth aspect, the redirection device is further configured to write an entry address of the interrupt handling function to the first register. The second processor is specifically configured to read the entry address of the interrupt handling function from the first register, call the interrupt handling function based on the entry address, and execute the interrupt handling function in a user mode of the host.

[0053] The procedure may be readily implemented by using the corresponding content of the first aspect, and the details will not be described again here.

[0054] In a possible implementation of the fourth aspect, the second processor is specifically configured to switch from a context of the second VM to a context of the shadow thread, process an interrupt in a user mode of the host, and switch from the context of the shadow thread back to the context of the second VM after processing the interrupt. The redirection device is further configured to switch from the user mode of the host back to a virtualization privilege level of the second VM. The second processor is further configured to continue execution of the second VM.

[0055] In this possible implementation, executing the interrupt handling function includes a procedure of context switching and a procedure of handling the interrupt. In this solution, the redirection device directly switches from the user mode of the host to the virtualization privilege level of the second VM, so that the interrupted second VM can be started quickly.

[0056] In a possible implementation of the fourth aspect, the second processor is further configured to switch from the context of the first thread to a context of the shadow thread, handle an interrupt in a user mode of the host, and after handling the interrupt, switch from the context of the shadow thread to a context of the first thread and continue executing the first thread.

[0057] In this possible implementation, if the virtual machine is not running on the second processor, the second processor may directly switch between the context of the first thread and the context of the shadow thread, then service the interrupt, and then switch back to the context of the first thread. In this manner, the first thread may be started quickly, allowing the first thread to continue executing.

[0058] In a possible implementation of the fourth aspect, the privilege level of the host is a kernel mode, and the second processor is in the kernel mode of the host and is configured to receive a second interrupt request sent by the interrupt controller, switch to an entry address of an interrupt handling function of the kernel mode of the host, the interrupt handling function responding to the second interrupt request, and execute the kernel mode interrupt handling function in the kernel mode of the host.

[0059] In this possible embodiment, if the privilege level of the host is kernel mode, the interrupt controller may directly send the kernel mode interrupt to the second processor, and the second processor performs the kernel mode processing procedure to complete the corresponding operation. If the second VM runs on the second processor before the second processor switches to the entry address of the interrupt handling function of the kernel mode of the host, the second processor first switches from the virtualization privilege level of the second VM to the kernel mode of the host. If the virtual machine is not running on the second processor and the host is in user mode, the second processor first switches from the user mode of the host to the kernel mode of the host. If the host is in kernel mode, the second processor directly switches to the entry address of the interrupt handling function and then executes the interrupt handling function.

[0060] A fifth aspect of the present application provides an exception handling method, the method being applied to a computing device, a host, and a virtual machine VM running on the computing device, the method including obtaining an exception instruction triggered by the VM, switching from a virtualization privilege level of the VM to a user mode of the host, and executing an exception handling function corresponding to the exception instruction in the user mode of the host.

[0061] In a possible implementation of the fifth aspect, the method further includes writing an entry address of the exception handling function to a first register. The first processor is specifically configured to read the entry address of the exception handling function from the first register, call the exception handling function based on the entry address, and execute the exception handling function corresponding to the exception instruction in a user mode of the host.

[0062] In a possible implementation of the fifth aspect, the exception instruction is triggered by the VM performing an input / output I / O operation.

[0063] In a possible implementation of the fifth aspect, the method further includes switching from the context of the VM to a context of a user mode shadow execution environment and handling the exception in the user mode of the host, wherein the exception handling function is included within a virtual processor thread executing in the user mode of the host, and an execution environment assigned to the virtual processor thread includes a main thread execution environment, a VM execution environment, and a shadow execution environment, wherein the execution environment assigned to the virtual processor thread is resources necessary to execute the virtual processor thread, and the shadow execution environment has a user mode memory space independent from the main thread execution environment and the VM execution environment, and the shadow execution environment is used to execute the exception handling function, and the exception handling function is used to handle the exception that triggers the exception instruction.

[0064] For the exception handling method provided in the fifth aspect and any possible implementations, please refer to the relevant description of the first aspect and any possible implementations of the first aspect, and the details will not be described again here.

[0065] A sixth aspect of the present application provides an interrupt processing method, the method being applied to a computing device, a host, and a first VM executed on the computing device, the method including: obtaining a first interrupt request triggered by the first VM, the first interrupt request being used to request execution of an interrupt handling function; determining interrupt information in response to the first interrupt request; generating a second interrupt request based on the interrupt information, the second interrupt request being used to request execution of the interrupt handling function; and executing the interrupt handling function in response to the second interrupt request, the second interrupt request being obtained by using the first interrupt request.

[0066] In a possible implementation example of the sixth aspect, the first interrupt request includes a virtual event interrupt request number VEI ID, the VEI ID identifying a virtual event that triggers the first interrupt request, and the method further includes obtaining a VM ID of the first VM, where the interrupt information includes the VEI ID and VM ID of the first VM, and determining a VEI physical number and privilege level of a host that processes the first interrupt request based on the VEI ID and VM ID of the first VM, where the VEI physical number identifies a virtual event within the host, and the aforementioned step of executing an interrupt handling function in response to a second interrupt request includes obtaining a VEI physical number and executing the interrupt handling function corresponding to the VEI physical number in response to the received second interrupt request based on a processing scheme corresponding to the privilege level of the host.

[0067] In a possible implementation of the sixth aspect, the first interrupt request includes a virtual event interrupt request number VEI ID, the VEI ID identifies a virtual event that triggers the first interrupt request, and the interrupt information includes the VEI ID, and the method further includes determining a privilege level of a host that processes the first interrupt request based on the VEI ID, and the aforementioned step of executing an interrupt handling function in response to a second interrupt request includes obtaining a VEI ID and executing the interrupt handling function corresponding to the VEI ID in response to the received second interrupt request based on a processing scheme corresponding to the privilege level of the host.

[0068] In a possible implementation of the sixth aspect, the privilege level of the host is user mode, and the aforementioned step of executing an interrupt handling function in response to a second interrupt request includes switching from a first thread to a shadow thread, where the first thread is a thread executing in the host before switching, and the shadow thread is a thread executing in the host in user mode, where the shadow thread is used to execute the interrupt handling function, and executing the interrupt handling function in the user mode of the host.

[0069] In a possible implementation of the sixth aspect, the method further includes determining whether the first thread is at a virtualization privilege level of a second VM, the second VM executing on the computing device, before executing the interrupt handling function in a user mode of the host, and if the interrupt thread is at the virtualization privilege level of the second VM, switching the virtualization privilege level of the second VM to the user mode of the host.

[0070] In a possible implementation of the sixth aspect, the method further includes writing an entry address of the interrupt handling function to a first register, reading the entry address of the interrupt handling function from the first register, calling the interrupt handling function based on the entry address, and executing the interrupt handling function in a user mode of the host.

[0071] In a possible implementation of the sixth aspect, the aforementioned step of executing an interrupt handling function in the user mode of the host includes switching from the context of the second VM to a shadow thread context and handling the interrupt in the user mode of the host, switching from the shadow thread context to the context of the second VM after the interrupt has been handled, switching from the user mode of the host back to the virtualization privilege level of the second VM, and continuing execution of the second VM.

[0072] In a possible implementation of the sixth aspect, the method further includes switching from a context of the first thread to a context of a shadow thread to handle an interrupt in a user mode of the host, and after the interrupt is handled, switching from the context of the shadow thread to a context of the first thread, and continuing execution of the first thread.

[0073] In a possible implementation of the sixth aspect, the privilege level of the host is a kernel mode, and the aforementioned step of executing an interrupt handling function corresponding to the VEI ID in response to a received second interrupt request based on a processing scheme corresponding to the privilege level of the host includes switching to an entry address of the interrupt handling function of the kernel mode of the host, where the interrupt handling function corresponds to the second interrupt request, and executing the kernel mode interrupt handling function in the kernel mode of the host.

[0074] For the exception handling method provided in the sixth aspect and any possible implementations, please refer to the relevant description of the third aspect and any possible implementations of the third aspect. The details will not be described again here.

[0075] A seventh aspect of the present application provides a computer device. The computer device has a function of performing the method in the fifth aspect or any one of the possible implementations of the fifth aspect. The function may be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the aforementioned functions, such as a receiving unit and a processing unit.

[0076] An eighth aspect of the present application provides a computer device. The computer device has a function for implementing the method in the sixth aspect or any one of the possible implementations of the sixth aspect. The function may be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the aforementioned functions, such as a receiving unit and a processing unit.

[0077] A ninth aspect of the present application provides a computer-readable storage medium storing one or more computer-executable instructions which, when executed by a processor, cause the processor to perform a method according to the fifth aspect or any one of the possible implementations of the fifth aspect.

[0078] A tenth aspect of the present application provides a computer-readable storage medium storing one or more computer-executable instructions which, when executed by a processor, cause the processor to perform a method according to the sixth aspect or any one of the possible implementations of the sixth aspect.

[0079] An eleventh aspect of the present application provides a computer program product storing one or more computer-executable instructions which, when executed by a processor, cause the processor to perform a method according to the fifth aspect or any one of the possible implementations of the fifth aspect.

[0080] A twelfth aspect of the present application provides a computer program product storing one or more computer-executable instructions which, when executed by a processor, cause the processor to perform a method according to the sixth aspect or any one of the possible implementations of the sixth aspect.

[0081] A thirteenth aspect of the present application provides a chip system, the chip system including at least one processor, the at least one processor configured to support an inter-process communication device when performing the functions of the fifth aspect or any one of the possible implementations of the fifth aspect. In one possible design, the chip system further includes a memory. The memory is configured to store program instructions and data required for the message manager. The chip system may include a chip, or may include a chip and another discrete component.

[0082] A fourteenth aspect of the present application provides a chip system, the chip system including at least one processor, the at least one processor configured to support an inter-process communication device when performing the functions of the sixth aspect or any one of the possible implementations of the sixth aspect. In one possible design, the chip system further includes a memory. The memory is configured to store program instructions and data required for the scheduling device. The chip system may include a chip, or may include a chip and another discrete component.

[0083] In the embodiment of the present application, the privilege level switching in the synchronous processing procedure is implemented by using a redirection device, and the interrupt request may be forwarded asynchronously by using a virtual event notification device and an interrupt controller without passing through the kernel mode of the host. In both the synchronous processing procedure and the asynchronous processing procedure, the switching overhead is reduced, and the performance of the computer device is improved. [Brief description of the drawings]

[0084] [Figure 1] 1 is a schematic diagram of the structure of a computing device according to an embodiment of the present application. [Diagram 2] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Diagram 3]1 is a schematic diagram of an embodiment of an exception handling method according to an embodiment of the present application; [Figure 4] 1 is a schematic diagram of a processor structure according to an embodiment of the present application; [Diagram 5] 2 is a schematic diagram of a structure of a thread of a virtual processor according to one embodiment of the present application; [Figure 6] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Figure 7A] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Figure 7B] FIG. 2 is a schematic diagram of an interrupt state change according to an embodiment of the present application; [Figure 8] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Figure 9] FIG. 2 is a schematic diagram of a shadow thread structure according to an embodiment of the present application. [Figure 10A] 2 is a schematic diagram of an embodiment of an interrupt processing method according to an embodiment of the present application; [Figure 10B] 2 is a schematic diagram of an embodiment of an interrupt processing method according to an embodiment of the present application; [Figure 11] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Figure 12] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. [Figure 13] FIG. 2 is another schematic diagram of the structure of a computing device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0085] Hereinafter, the embodiments of the present application will be described with reference to the accompanying drawings. It is clear that the described embodiments are only a part, not all, of the embodiments of the present application. Those skilled in the art will understand that the technical solutions provided in the embodiments of the present application can also be applied to similar technical problems as technology evolves and new scenarios emerge.

[0086] In the specification, claims, and accompanying drawings of this application, terms such as "first," "second," and the like are intended to distinguish between similar objects, but do not necessarily indicate a particular order or sequence. It is to be understood that such designated data are interchangeable in appropriate circumstances, whereby the embodiments described herein may be performed in other orders than those shown or described herein. In addition, "include," "have," and any other variations are intended to cover non-exclusive inclusion. For example, a procedure, method, system, product, or device that includes a list of steps or units is not necessarily limited to the steps or units expressly listed, and may include other steps or units that are not expressly listed or that are inherent to such procedure, method, product, or device.

[0087] The embodiments of the present application provide a computer device, an exception handling method, and an interrupt handling method to reduce the overhead generated during switching and improve the performance of the computer device. The present application further provides corresponding apparatuses, computer-readable storage media, computer program products, etc. Details are described separately below.

[0088] Virtualization means that hardware resources (e.g., processor or memory space, and network resources) of the hardware layer of a computing device are virtualized, and the virtualized resources are shared by multiple virtual computers. A virtual computer is a general term for running a virtualized environment by using software in all types of virtualization devices, and the concept of a virtual computer includes a virtual machine or a container.

[0089] As shown in Fig. 1, the computer device 100 includes a hardware layer 112, a host layer 109, and a virtualization layer. The virtualization layer includes virtual machines 101 and 102. There may be more or less virtual machines. Here, only two virtual machines are used as an example. The hardware layer 112 includes a processor system 114, a memory 113, a communication interface 115, and an interrupt controller 116.

[0090] A virtual machine (VM) is one or more virtual computers simulated on a computing device by using virtualization software. A virtual machine runs in a completely isolated environment and behaves like a real computer. A guest operating system (guest OS) (105 and 106 in FIG. 1) may be installed on the virtual machine (101 and 102 in FIG. 1), and one or more applications (103 and 104 in FIG. 1) run on the guest operating system. The virtual machine may also access network resources. Applications running on the virtual machine behave as if the applications were running on a real computer.

[0091] When a VM is running, a virtual machine privilege level is involved, which includes a virtual machine user mode and a virtual machine kernel mode. The virtual machine kernel mode and user mode are separated by considering the VM as a real computer.

[0092] Before the concepts of user mode and kernel mode are introduced, the following first introduces user space and kernel space.

[0093] In some existing computer systems, the entire virtual address space is divided and two virtual address spaces are obtained as kernel space (kernel mode virtual address space) and user space (user mode virtual address space) through the division. As an example, 48-bit effective virtual addresses in a 64-bit architecture are used. In this case, the user space is (00000000, 00000000)-(0000FFFF, FFFFFFFF) and the kernel space is (FFFF0000, 00000000)-(FFFFFFFF, FFFFFFFF). The kernel space and the user space have corresponding registers, which store the independent page table base addresses of the corresponding spaces. The kernel space may also be called kernel mode memory space and the user space may also be called user mode memory space. A process or thread running in the user space may also be called a user mode process or thread and a process or thread running in the kernel space is called a kernel mode process or thread.

[0094] A virtual processor (e.g., 107 and 108 in FIG. 1) is a physical processing unit, e.g., a virtual central processing unit (vCPU), provided to a virtual computer for use in a shared or sliced ​​manner in virtualization technology. A virtual computer may be served by one or more virtual processors. When there are multiple virtual processors, one virtual processor is usually a primary virtual processor, and the others are secondary virtual processors. Other virtual hardware resources, such as virtual memory, included in a virtual machine are not shown in FIG. 1. It should be understood that a virtual machine corresponds to an independent computer. Therefore, the operations performed by a virtual machine may also be considered as the virtual processor performing the operations. The virtual processor is virtualized by using virtualization software. The execution of a virtual processor is actually performed as follows, that is, a host processor or physical core reads and executes a software program. For example, a physical core reads a software program and executes the software program in a specific mode of hardware-assisted virtualization of the physical core (e.g., non-root of x86) to implement the virtual processor. Multiple virtual processors of a virtual machine may be placed on different physical cores.

[0095] Virtual processor trap in and trap out, that is, the virtualization system includes two modes: host mode and guest mode. The host mode may also be referred to as the host privilege level, e.g., the host user mode or the host kernel mode. The guest mode may also be referred to as the VM privilege level, e.g., the VM user mode or the VM kernel mode. When the virtual processor enters the guest mode, this procedure is called trap in (virtual), and when the virtual processor leaves the guest mode, this procedure is called trap out (virtual). After the virtual processor traps out, the physical processor temporarily stops executing the code of the virtual processor. Therefore, in this case, the virtual processor may be understood to be not running. When the virtual processor executing on the physical processor traps in, the physical processor may be considered to be in the guest mode, and the code of the virtual processor is executed. When the virtual processor executing on the physical processor traps out to the host mode, the physical processor may be considered to be in the host mode, and execute host-related code, such as a virtual machine monitor.

[0096] The host layer 109 is used as a management layer to manage and allocate hardware resources, present a virtual hardware platform for the virtual machines, schedule and isolate the virtual machines, etc. In some implementations, the host layer 109 includes a host operating system 111 and a virtual monitor, such as a virtual machine monitor (VMM) 110. The virtual monitor 110 may be deployed inside the host operating system 111 or outside the host operating system 111. In other virtualization architectures, the virtual monitor may be called a hypervisor or another type of virtual monitor. In some other implementations, for example, in the Xen virtualization architecture, the host layer 109 may further include one privileged virtual machine. The virtual hardware platform provides various hardware resources, such as virtual processors, virtual memory, virtual disks, and virtual network interface cards, to the virtual computers that run on the virtual hardware platform. The virtual computers run on the virtual hardware platform provided by the host layer for the virtual computers. The host layer 109 may also be called a virtualization platform, and the host layer may be called a host for short. The host privilege levels include a user mode and a kernel mode.

[0097] The hardware layer 112 is a hardware platform on which the virtualization environment runs. The hardware layer may include multiple types of hardware. As shown in FIG. 1, the hardware layer may include a processor system 114 and a memory 113, and may further include a communication interface 115, such as a network interface card (NIC), an interrupt controller 116, an input / output (I / O) device, etc. The processor system 114 may include one or more processors, such as processor 1 and processor 2 shown in FIG. 1. Each processor may include multiple physical cores, and the processor may further include multiple registers, such as general-purpose registers and floating-point registers.

[0098] The processor system 114 may also be referred to as a physical processor. A physical core represents the smallest processing unit in a processor, and each processor may have the same or different number of cores. A processor with one core is referred to as a single-core processor, and a processor with multiple physical cores is referred to as a multi-core processor. Multi-core processors may be classified as homogeneous and heterogeneous multi-core processors based on whether the core architectures are the same or not. A virtual processor may be bound to a physical core. In other words, a virtual processor always executes on a particular physical core and cannot be scheduled for execution on another physical core. In this case, the virtual processor is core bound. If the virtual processor can be scheduled for execution on different physical cores based on requirements, the virtual processor is not core bound.

[0099] The interrupt controller 116 is disposed between the processor and the hardware that triggers the interrupt request, and is mainly configured to collect the interrupt requests generated by the hardware and send the interrupt requests to the processor based on a specific priority or another rule. The interrupt controller is, for example, an advanced programmable interrupt controller (APIC).

[0100] An interruption indicates that execution of the current program's instructions is suspended and an interrupt service routine is executed.

[0101] An interrupt service routine (ISR), sometimes called an interrupt handling function, is a program used to handle interrupt requests. When a processor receives an interrupt request, it suspends execution of the current program and executes the interrupt service routine that corresponds to the interrupt request.

[0102] An interrupt request is an event generated by hardware. The hardware sends the event to the processor. When the processor receives the event, it interrupts the execution of the current program and executes a routine corresponding to the event. An interrupt request generated by hardware may be triggered by hardware or software. An interrupt request may be simply called an interrupt. Some hardware in a computer (such as a network adapter, an audio adapter, a mouse, a hard disk, etc.) may complete certain operations without the intervention of the processor. However, the hardware still needs to use an interrupt controller to enable the processor to perform some specific operation for the hardware. An interrupt number is an identifier of an interrupt request and is represented by an IRQ ID in this application.

[0103] The hardware layer 112 may further include a memory management unit (MMU). The MMU is computer hardware configured to process memory access requests. The functions of the MMU include virtual to physical address translation (i.e., virtual memory management), memory protection, and control of the central processing unit cache. The MMU typically uses an associative cache of translation lookaside buffers (TLBs) to translate virtual page numbers to physical page numbers.

[0104] The storage space (address space) provided by memory 113 is assigned to the virtual machines and the host for use. A host physical address (HPA) is the physical address space that may be used by the local host (host). A host virtual address (HVA) is the virtual address space that may be used by the local host (host). A guest physical address (GPA) is the physical address space that may be used by the guest operating system of the virtual machine. A guest virtual address (GVA) is the virtual address space that may be used by the guest operating system of the virtual machine.

[0105] The computing device 100 may be a physical device, such as a server or a terminal device. The terminal device may be a handheld device with wireless connectivity or another processing device connected to a wireless modem. For example, the terminal device may be a mobile phone, a personal computer (PC), a tablet computer, a personal digital assistant (PDA), a mobile Internet device (MID), a wearable device, and an e-book reader, or may be a portable, pocket-sized, handheld, computer-embedded, or vehicle-mounted mobile device.

[0106] When a VM in the computer device 100 performs some operations (e.g., read / write operations to memory of a serial port, read / write operations to memory of a disk, read / write operations to memory of a network adapter, and operations to page faults), an exception or interrupt is triggered (an exception is usually described as a synchronous exception, and an interrupt is usually described as an asynchronous exception). The hardware layer, or the kernel of the host, handles the exception or interrupt. In the present embodiment of the present application, the exception may be handled in a synchronous manner, and the interrupt may be handled in an asynchronous manner. Synchronous processing refers to processing on the same processor, and asynchronous processing refers to cross-processor processing. In a virtual I / O scenario, the virtual I / O processing may be classified into synchronous processing and asynchronous processing. When the I / O device used to run the VM is a device such as a serial port, a graphic card, a character, or a USB, the synchronous processing method is generally used. When the I / O device used to run the VM is a device such as a disk or a network adapter, the asynchronous processing method is generally used.

[0107] A first processor and a second processor are used in the following embodiments of the present application. It should be noted that the first processor and the second processor may alternatively be two different cores within the same multi-core processor.

[0108] The synchronous processing procedure and the asynchronous processing procedure will be described below.

[0109] 1. Synchronization As shown in FIG. 2, a computing device includes a first processor, a host, and a first VM executing on the computing device. Specifically, the first VM executes on the first processor. The first VM triggers an exception instruction when performing some operations. When the VM performs an input / output (I / O) operation, the exception instruction may be triggered. When the VM needs to access a virtual I / O device, the I / O operation may be the triggered operation. A virtual I / O device generally includes a front-end driver and a back-end device. The front-end driver executes on the VM, and a program of the back-end device executes on the host. When an operation performed by the VM needs to access a back-end device by using the front-end driver, the exception instruction is triggered, and the back-end device is accessed by using the exception instruction. A virtual I / O device is one type of back-end device. The access to the virtual I / O device may be reading data from or writing data to the memory of the virtual I / O device, or may be another control operation on the virtual I / O device. The virtual I / O device is an I / O device that can be used by a virtual machine. The virtual I / O device may be a fully virtualized I / O device simulated by using software. The virtual I / O device may also be mapped to a physical I / O device in a mapping manner. When the virtual I / O device is accessed, the physical I / O device is eventually accessed. If the first processor receives an exception instruction and the first processor determines that the exception instruction needs to be handled in the host user mode, the first processor switches from the virtualization privilege level of the first VM to the host user mode and executes an exception handling function in the host user mode. For example, the virtual I / O device includes a serial port, a graphics card, a character, or a USB.A serial port, a graphic card, a character, or a USB has a respective address range. The first processor may determine a virtual I / O device to perform a current I / O operation based on the address range. In the present application, operations related to a virtual I / O device are performed synchronously. When a virtual I / O device is a virtual I / O device simulated by using software, for example, a virtual serial port of a linux system, the virtual I / O device simulated by using software may not correspond to a physical I / O device. A virtual I / O device in a virtual machine may be associated with a physical I / O device. For example, a virtual mouse is associated with a physical mouse. When a virtual I / O device is associated with a physical I / O device, the first processor executes a thread in a user mode to trap into kernel mode by using a system call, and then calls the driver of the physical I / O device to operate the physical I / O device.

[0110] There may be multiple types of exception instructions triggered by the first VM, such as an invalid instruction exception, a page fault exception, a memory access exception, an address alignment exception, and an exception caused by accessing a virtual I / O device. Based on the type of the exception instruction, the first processor may determine that the exception instruction needs to be processed in the user mode of the host or the kernel mode of the host. The above-mentioned redirection operation may be performed for the exception instruction that needs to be processed in the user mode of the host.

[0111] The first processor may include a first redirection device. The first redirection device may perform a procedure of switching from a virtualization privilege level of the first VM to a privilege level of a user mode of the host, and writing an entry address of an exception handling function to a first register. In this way, the first processor may read the entry address of the exception handling function from the first register, call the exception handling function based on the entry address, and execute the exception handling function corresponding to the exception instruction in the user mode of the host. The function of the first redirection device may be implemented by using a hardware circuit.

[0112] The host in user mode may include a thread of a virtual central processing unit (vCPU), and the thread may include a shadow execution environment. The first processor may execute an exception handling function within the shadow execution environment.

[0113] With reference to FIG. 3, the following describes a procedure for implementing the aforementioned exception handling method for synchronous processing by using a first processor, a first redirection device, and a shadow execution environment.

[0114] 201: A first processor gets an exceptional instruction triggered by a first VM.

[0115] The procedure of step 201 may be that when the first VM performs an operation that exceeds the permission of the first VM, an exception occurs, and the first processor may detect the exception code through hardware logic and further obtain the exception instruction.

[0116] After getting the exception instruction, the first processor may write the cause and type of the exception, the memory accessed by the first VM, and the return address to hardware registers for subsequent exception handling.

[0117] Optionally, 202: the first processor determines that the exceptional instruction needs to be handled in a user mode of the host.

[0118] The first processor may determine, based on the address range of the virtual I / O device corresponding to the exception instruction, that the exception instruction needs to be handled in a user mode of the host.

[0119] If the exception instruction needs to be processed in the kernel mode of the host, the first redirection device switches from the virtualization privilege level of the first VM to the kernel mode of the host, and then switches to an entry of the exception handling function in the kernel mode of the host for processing.

[0120] Step 202 is an optional step, i.e., step 202 may not be performed. If step 202 is not performed, step 203 may be performed directly.

[0121] 203: The first redirection device switches from the virtualization privilege level of the first VM to the user mode of the host.

[0122] The virtualization privilege level of a VM represents a privilege level in a virtualization mode, i.e., an operating mode of the VM. The virtualization privilege level includes a virtualization user mode and a virtualization kernel mode. Switching (direct switching) from the virtualization privilege level of a VM to the user mode of a host may include a procedure of moving information about the virtualization privilege level of the VM from a register used to store the privilege level, and then writing information about the user mode of the host to a register, which may be a system register. In this application, the privilege level and virtualization may be represented by using one bit each. For example, 0 indicates user mode, 1 indicates kernel mode, 0 indicates non-virtualization, and 1 indicates virtualization. The privilege level is in the first bit, and whether to virtualize is in the second bit. For example, 00 indicates a non-virtualized user mode, which may also be referred to as the host's user mode, 10 indicates a non-virtualized kernel mode, which may also be referred to as the host's kernel mode, 01 indicates a virtualized user mode, which may also be referred to as the VM's user mode, and 11 indicates a virtualized kernel mode, which may also be referred to as the VM's kernel mode. Of course, the foregoing are merely a few examples. The set of privilege levels and virtualization, as well as other possible representations, are not limited by this application.

[0123] 204: The first redirection unit writes the entry address of the exception handling function to a first register.

[0124] 205: The first processor switches, in the shadow execution environment, from a context of the first VM to a context of the user mode shadow execution environment and performs exception handling.

[0125] The shadow execution environment is a carrier for exception handling functions in user mode, which are sometimes called service routines for handling exception interrupts.

[0126] The exception handling function is included in a virtual processor thread that executes in a user mode of the host, and the execution environment assigned to the virtual processor thread includes a main thread execution environment, a VM execution environment, and a shadow execution environment, the execution environment assigned to the virtual processor thread is a resource required to execute the virtual processor thread, and the shadow execution environment has a user mode memory space independent from the main thread execution environment and the VM execution environment, the shadow execution environment is used to execute the exception handling function, and the exception handling function is used to handle the exception that triggers the exception instruction.

[0127] Optionally, 206: in the procedure for handling exceptions, determine whether an interrupt or exception that needs to be handled in the kernel has been generated, and if an interrupt or exception that needs to be handled in the kernel has been generated, perform 207, and if an interrupt or exception that needs to be handled in the kernel has not been generated, perform 209.

[0128] 207: When an interrupt or exception that needs to be handled in the kernel is generated, the context of the user mode shadow execution environment is switched to the context of the kernel mode shadow execution environment, and the interrupt or exception is handled in kernel mode.

[0129] 208: After an interrupt or exception is handled by the kernel, the context of the kernel-mode shadow execution environment needs to be switched to the context of the user-mode shadow execution environment.

[0130] 209: Continue handling the exception.

[0131] 210: After the interrupt or exception is handled, the context of the user mode shadow execution environment is switched to the context of the first VM.

[0132] 211: The first redirection device switches from the user mode of the host back to the virtualization privilege level of the first VM.

[0133] In the switching procedure, information about the host's user mode is moved from the privilege register, and information about the first VM's virtualization privilege level originally stored in the privilege register or in the memory corresponding to the register is written to the privilege register.

[0134] 212: The first redirection device switches execution procedure to the interrupted instruction in the first VM, and the first VM continues executing the interrupted instruction.

[0135] The above describes a synchronization process. In the synchronization process, as shown in Fig. 4, the first redirect device may include a privilege level selection module and a privilege level redirect module. The privilege level redirect module may further include an update module and a restore module.

[0136] The privilege level selection module may be configured to determine whether an exceptional instruction triggered during execution of the first VM needs to be redirected to a user mode of the host for handling.

[0137] If the exception instruction needs to be redirected to the user mode of the host, the privilege level selection module notifies the privilege level redirection module to perform the redirection operation. For the redirection procedure, please refer to the description of step 204.

[0138] The update module is (1) Record switching information, the switching information including information about a virtualization privilege level of a first VM before the switching and information about a user mode of a host after the switching; (2) updating state control information, i.e. updating the state register for relevant information of the user mode exception handling function, the relevant information including but not limited to the entry address of the exception handling function, the cause of the exception, the memory address or instruction of the exception, etc; (3) switching privilege levels, i.e., switching the virtualization privilege level of the first VM to the host's user mode and switching to the entry address of an exception handling function in the host's user mode; It is configured as follows.

[0139] The restoration module is configured to switch from the host's user mode back to the first VM's virtualization privilege level based on the recorded information regarding the first VM's virtualization privilege level, and to switch to the instruction interrupted by the first VM based on the return address, thereby causing the first VM to continue executing the instruction.

[0140] The shadow execution environment includes a user mode shadow execution environment and a kernel mode shadow execution environment. Specifically, the shadow execution environment has an independent storage space that may store context information in both user mode and kernel mode. The storage space may be a stack, the storage space in user mode may be a stack in user mode, and the storage space in kernel mode may be a stack in kernel mode.

[0141] The shadow execution environment is located within the execution environment of a virtual processor's thread. See Figure 5 for the task structure of a virtual processor's thread.

[0142] As shown in FIG. 5, the tasks of a thread of a virtual processor may include a task for simulating a virtual processor, a task for running a VM, and a task for exception / interrupt handling.

[0143] A vCPU user mode main thread execution environment and a vCPU kernel mode main thread execution environment are used in the task of simulating a virtual processor. The vCPU user mode main thread execution environment includes a first storage device and a second storage device. The first storage device is configured to store a user mode context or a kernel mode context, and the second storage device is configured to store a host context or a VM context.

[0144] A VM execution environment is used in the task of running a VM, and a VM execution environment is used to run a VM.

[0145] A shadow execution environment is used in the task of interrupt processing, the shadow execution environment includes a user mode shadow execution environment and a kernel mode shadow execution environment, the user mode shadow execution environment includes a first switching device, and the kernel mode shadow execution environment includes a second switching device.

[0146] The first switching device is configured to switch from the context of the VM to the user mode context of the host, as described above in steps 205 and 210. The first switching device stores the execution state of the VM and restores the execution state of the user mode of the shadow execution environment. The information about the execution state includes, but is not limited to, information in registers, such as general-purpose registers, floating-point registers, and system registers.

[0147] The second switching device is configured to switch from the host user mode context to the host kernel mode context as described above in steps 207 and 208. The second switching device is configured to store the host user mode context, restore the kernel mode context, enter the kernel mode, and handle an interrupt or exception that occurs during the shadow execution environment user mode and needs to be handled in the kernel mode. After the interrupt or exception is handled in the kernel mode, the device restores the user mode context and switches back to the user mode shadow execution environment to continue execution of the exception instruction. The kernel mode shadow execution environment context and the kernel mode context of the virtual processor's thread do not conflict with or affect each other.

[0148] The device for storing user mode and kernel mode contexts, the device for storing host and VM contexts, the device for switching between a VM context and a user mode shadow execution environment, and the device for switching between user mode and kernel mode contexts may be general-purpose registers, floating-point registers, or system registers, etc.

[0149] In this application, "execution environment" includes two aspects: a software execution environment and a hardware execution environment. The software execution environment includes information in a stack and thread context information that are used when a thread of a virtual processor executes in a different execution environment. The hardware aspect includes hardware resources, including memory resources or processing resources, that are used when a thread executes.

[0150] According to the computer system provided in this embodiment of the present application, an exception occurring during the execution of a VM is redirected to the user mode of a host for processing in a synchronous manner. Therefore, the overhead of switching between the kernel mode of a host and the user mode of a host is not required, and the performance of the computer system is improved.

[0151] 2. Asynchronous Processing Asynchronous processing refers to a cross-processor processing procedure. A first VM running on a first processor needs to access a back-end device of the first VM and perform an operation that triggers an interrupt request. The interrupt request needs to be processed by using a second processor. Therefore, the asynchronous processing procedure may be divided into an interrupt request send end procedure and an interrupt request receive end procedure. The send end procedure may not include the host kernel or may include the host kernel. The receive end procedure may not include the host kernel or may include the host kernel. There are four possible asynchronous processing methods:

[0152] Asynchronous processing method 1: The sending completion procedure does not involve the host kernel, and the receiving completion procedure does not involve the host kernel either.

[0153] As shown in Figure 6, the computer system includes a first processor, a second processor, an interrupt controller, and a physical I / O device. A host runs on the computer device, and a first virtual machine VM runs on the first processor. The computer system further includes a virtual event interrupt component. The virtual event interrupt component may include a virtual event notification device and a virtual event interrupt device. The circuit structure of the virtual event notification device is disposed in the first processor, and the circuit structure of the virtual event interrupt device is disposed in the interrupt controller.

[0154] The first processor is configured to receive a first interrupt request triggered by the first VM, the first interrupt request being used to request execution of an interrupt handling function. The virtual event notification device is configured to send interrupt information directly to an interrupt controller in response to the first interrupt request. The interrupt controller is configured to determine an identifier of the second processor based on the interrupt information, and send a second interrupt request to the second processor based on the identifier of the second processor. The second processor is configured to execute the interrupt handling function in response to the received second interrupt request.

[0155] The structure of the virtual event interrupt component can be understood with reference to Figure 7A. As shown in Figure 7A, the virtual event interrupt component includes a virtual event generating module, a virtual event monitoring module, a virtual event interrupt mapping table, a virtual event interrupt query module, and a virtual event interrupt information setting module. The virtual event generating module and the virtual event monitoring module are disposed in a first processor, and the virtual event interrupt mapping table, the virtual event interrupt query module, and the virtual event interrupt information setting module are disposed in an interrupt controller.

[0156] The virtual event generation module may include a VEI-REG register that may be directly accessed by the first VM. In this way, when the first VM accesses the virtual event generation module, the VM may write a virtual event interrupt request number (VEI ID) to the VEI-REG register. The manner in which the first VM accesses the virtual event generation module includes, but is not limited to, reading and writing dedicated registers, executing dedicated instructions, executing existing instructions to trigger dedicated hardware logic, etc.

[0157] The VEI ID identifies a virtual event that causes the first VM to trigger a first interrupt request. In general, the type of interrupt triggered by the VM may further include a local interrupt, an external interrupt, a clock interrupt, etc. If the VEI ID indicates that the interrupt request is an interrupt triggered by a virtual event, the virtual event generating module notifies the virtual event monitoring module to start operating. The virtual event monitoring module queries the number of the first VM, i.e., a virtual machine identifier (VM ID). The virtual event monitoring module may obtain the VM ID from a register for storing the virtual machine identifier. When the first VM runs on the first processor, the VM ID is written to the register for storing the virtual machine identifier. The register for storing the virtual machine identifier may be a control status register (CSR). The interrupt information includes the VEI ID and the VM ID.

[0158] The virtual event monitoring module sends the VEI ID and a virtual machine identifier (VM ID) of the first VM to the virtual event interruption query module.

[0159] In this embodiment of the present application, a VEI-REG register that can be directly accessed by the VM is newly added to prevent the first VM from trapping out to the host. The VM can write a VEI ID to the VEI-REG register, so that the first processor can read the VEI ID by using the VEI-REG register, and then the first processor reads the VM ID from the CSR register and further performs the subsequent interrupt processing asynchronously by using the interrupt controller and the second processor. After the first VM writes the VEI ID to the VEI-REG register, the first VM does not need to terminate and can continue to run, since the subsequent interrupt procedure is performed asynchronously.

[0160] The virtual event interrupt mapping table holds a VEI ID, a VM ID, a processor ID (CPU ID), and a VEI physical number, and further holds a mapping relationship between the VEI ID and a host privilege level (whether the interrupt request should be processed in user mode or kernel mode) corresponding to an interrupt request corresponding to the VM ID. The VEI ID indicates a virtual event interrupt of a virtual machine, and the VEI physical number is used by a processor to identify the virtual event interrupt. The VEI ID ranges from 0 to 63, and the VEI physical number ranges from 0 to 2047. In the present embodiment of the present application, the VEI ID identifies a virtual event occurring in a virtual machine, and the VEI physical number indicates an identifier of a virtual event in a host. There is a mapping relationship between the VEI ID and the VEI physical number. The VEI ID and the VEI physical number mapped to each other indicate the same virtual event (e.g., a disk read / write event, or a network adapter read / write event). The VEI ID may be represented by a value from 0 to 63, for example. Each value identifies a different virtual event. One I / O device may have multiple different virtual events. For example, a disk read event may be represented by a value of 1, a disk write event may be represented by a value of 2, a disk control event may be represented by a value of 3, a network adapter read event may be represented by a value of 4, a network adapter write event may be represented by a value of 5, etc. The same virtual event in each virtual machine may use the same VEI ID. The VEI physical number may be globally unique, and virtual events of the same VEI ID occurring on different virtual machines may correspond to different VEI physical numbers. For example, the VEI physical number corresponding to the range of values ​​of the VEI ID of VM1 may be 0 to 63, the VEI physical number corresponding to the range of values ​​of the VEI ID of VM2 may be 64 to 127, and the rest may be inferred by analogy.In this way, the second processor may determine the virtual machine on which the virtual event occurs based on the range of different VEI physical numbers, and then determine the virtual event occurring on the VM based on the specific value of the VEI physical number. For example, the VEI ID is 5 indicates a disk read event, and when the VEI physical number is 5, it indicates that the disk read event occurs on VM1. When the VEI physical number is 69, it indicates that the disk read event occurs on VM2. The correspondence between the virtual event and the VEI ID, and the correspondence between the VEI physical number and the virtual machine may be set based on requirements. This is not limited in the present application.

[0161] The virtual event interrupt mapping table further holds information of the interrupt handling function corresponding to the virtual event interrupt (sometimes called service routine information), including, but not limited to, the memory address space of the service routine, data structure information, processing privilege level, etc.

[0162] The virtual event interruption inquiry module checks whether the VEI ID is registered or exists by searching the virtual event interruption mapping table. If the VEI ID is registered or exists, the virtual event interruption inquiry module transfers the VEI ID and the VM ID to the virtual event interruption information setting module. If the VEI ID is not registered or does not exist, the interruption request is ignored or an exception is thrown.

[0163] The virtual event interrupt information setting module queries the virtual event interrupt mapping table based on the VEI ID and the VM ID, and determines the CPU ID of the second processor corresponding to the current interrupt request, the VEI physical number, and the corresponding host privilege level.

[0164] In the present application, since the same virtual event in each virtual machine may use the same VEI ID, in order to distinguish between virtual machines where a virtual event occurs, the first processor may obtain a VM ID, and the VM ID may be read by the first processor from a register for storing a virtual machine identifier. Then, the virtual event notification device sends the VEI ID and the VM ID to an interrupt controller, and the interrupt controller may search for the identifier of the second processor, the VEI physical number, and the corresponding host privilege level based on the VEI ID and the VM ID. The interrupt controller may hold a mapping table whose input is (VEI ID)+(VM ID) and whose output is (CPU ID)+(VEI physical number)+(host privilege level). The interrupt controller may directly determine the corresponding (CPU ID)+(VEI physical number)+(host privilege level) based on the mapping table. The interrupt controller may determine the second processor to subsequently perform asynchronous interrupt processing based on the CPU ID, and may determine whether to subsequently use a user mode processing method or a kernel mode processing method based on the host privilege level. The second processor may read the VEI physical number from the register storing the VEI physical number, and then perform the corresponding processing based on a user mode processing procedure or a kernel mode processing procedure.

[0165] The VM ID and the VEI physical number are used in the above-mentioned manner. If the VEI ID is globally unique, different VMs use different VEI IDs for the same virtual event. In this way, the VM ID does not need to be used, the VEI physical number does not need to be translated, and subsequent interrupt processing can be performed once the corresponding second processor identifier and host privilege level are determined based on the VEI ID. In this embodiment, the interrupt information includes the VEI ID, and the VM ID is no longer needed.

[0166] If the interrupt request needs to be processed in the user mode of the host, the virtual event interrupt information setting module sets information about an interrupt processing thread in the user mode in the second processor. If the interrupt request needs to be processed in the kernel mode of the host, the virtual event interrupt information setting module notifies the second processor to process the kernel interrupt.

[0167] In this embodiment of the present application, the interrupt request needs to be processed in the user mode of the host. Therefore, after the virtual event interrupt information setting module sets information about the interrupt processing thread in the user mode, the virtual event interrupt information setting module notifies the second processor to process the interrupt request in the user mode.

[0168] The second processor performs a corresponding interrupt process after receiving an interrupt request in the user mode.

[0169] In this embodiment of the present application, the interrupt controller further holds a state machine indicating the virtual event interrupt VEI by using two registers. Each VEI ID corresponds to a state machine. The state machine of different stages of processing an interrupt shown in Figure 7B has four states: inactive state, pending state, active state, and (active + pending) state. The active state may also be understood as a processing state, and the (active + pending) state indicates that the current interrupt is still being processed and a new interrupt is coming.

[0170] One of the two registers (e.g., register 1) is configured to store a value indicating whether the state machine is in an active state, and the other register (e.g., register 2) is configured to store a value indicating whether the state machine is in a pending state. It will also be appreciated that the four states are represented by using two bits. For example, a first bit may indicate whether the state machine is in a pending state, with 1 indicating that the state machine is in a pending state. A second bit may indicate whether the state machine is in an active state, with 0 indicating that the state machine is in an inactive state, and 1 indicating that the state machine is in an active state. In this manner, the inactive state may be represented by 00, the pending state may be represented by 10, the active state may be represented by 01, and the (active+pending) state may be represented by 11.

[0171] When the interrupt controller does not get the first interrupt request, the state values ​​in register 1 and register 2 are both 0, ie, the state value for the inactive state is 00.

[0172] S1: If the interrupt controller gets interrupt request 1, the interrupt controller needs to switch to pending state and set the state value in register 1 to 1.

[0173] Thus, the state value of register 1 is 1 and the state value of register 2 is 0, i.e., the state value of the pending state is 10.

[0174] S2: The interrupt controller must start processing interrupt request 1 and switch to the active state. In this case, the status value in register 1 is cleared, i.e. restored to 0, and the status value in register 2 is set to 1.

[0175] Thus, the state value in register 1 is 0 and the state value in register 2 is 1, i.e., the state value for the active state is 01.

[0176] S3: When the interrupt controller processes interrupt request 1, if it receives another interrupt request 2, the interrupt controller should switch to the (active + pending) state and set the state value in register 1 to 1.

[0177] Thus, the status value in register 1 is 1 and the status value in register 2 is 1, i.e., the status value of the pending state is 11.

[0178] S4: After processing interrupt request 1, if the interrupt controller needs to switch to the inactive state, the status value in register 1 and the status value in register 2 need to be cleared.

[0179] The state values ​​in register 1 and register 2 are both 0, i.e., the state value for the inactive state is 00.

[0180] S5: When the interrupt controller changes from the (active+pending) state to the pending state, the state value in register 2 needs to be cleared.

[0181] Thus, the status value in register 1 is 1 and the status value in register 2 is 0, i.e., a status value of 10 for the pending state is returned.

[0182] In this application, in the interrupt controller, one state machine is maintained by using two registers, so that the interrupt controller can continuously obtain the state of handling an interrupt, which helps to quickly enter into the processing of the next interrupt after the processing of one interrupt is completed.

[0183] As shown in Figure 6, the second processor includes a hardware assisted switching device and a second redirection device. The structure of the hardware assisted switching device can be understood with reference to Figure 8. As shown in Figure 8, when processing a user mode interrupt, the hardware assisted switching device can support thread switching without trapping to the kernel. The hardware assisted switching device includes a processor state determination module, a thread switching module, and a kernel notification module.

[0184] The processor state determination module is configured to determine whether a current state of the processor supports immediate response to an interrupt in a user mode. Based on the current state of the processor, the processor determines to execute a shadow thread in a user mode to respond to the interrupt in a thread switching manner or a kernel notification manner.

[0185] The thread switching module includes information about a shadow thread, information about a first thread, and a thread-related cache data refresh module. The shadow thread is a thread running in the host in a user mode and configured to execute an interrupt processing function. Before the second processor switches the information about the thread, the first thread is a thread executed by the second processor, and the information about the shadow thread may be logically updated by using software or hardware running on another processor. When the thread information is switched, the information about the first thread is stored in the first thread information module. When the user mode interrupt processing is completed, the related information about the first thread is restored from the first thread information module. If the cache data refresh module does not support the identification of process or virtual machine information, after the thread information switching is completed, the cache information related to the thread needs to be refreshed by using the cache data refresh module. If the cache data refresh module supports the identification of process or virtual machine information, the cache data refresh module may not be triggered to perform execution.

[0186] Schemes including, but not limited to, generating an existing or newly added interrupt or exception when the second processor is currently in a state where the second processor cannot respond to a user mode interrupt in time, when the second processor is handling a kernel mode interrupt or exception, when the processor is idle, etc., are used to notify the kernel to wake up the shadow thread for execution.

[0187] When the second processor determines that the first thread is at the virtualization privilege level, the second redirection device completes updating state control information associated with the shadow thread and then switches the virtualization privilege level to the user mode of the host.

[0188] In the above description, "handling an interrupt request in a user mode" may refer to the second processor responding to a user mode interrupt and executing a shadow thread in a user mode to handle the user mode interrupt. As shown in FIG. 9, the shadow thread includes an original thread and a coroutine that implements a dual-layer switching mechanism.

[0189] Once created, the original thread may block sleep and be woken up by the kernel to perform the functional functions of a user mode interrupt service routine.

[0190] The double-layer switching mechanism includes a hardware-assisted switching device and a first thread and a shadow thread context switching module. When the processor can respond to a user mode interrupt, information required for the coroutine execution (including, but not limited to, memory address space, data structures, etc.) can be switched by using the hardware-assisted switching device, and a context switch between the first thread and the shadow thread can be implemented by using the first thread and the shadow thread context switching module. The coroutine of the shadow thread responds to the user mode interrupt and further calls a function of the user mode interrupt service routine to process the user mode interrupt.

[0191] The above describes the asynchronous processing procedure from the viewpoint of hardware functions. The following describes the procedure of the interrupt processing method with reference to Figures 10A and 10B.

[0192] 301: A first processor obtains a first interrupt request that is triggered when a first VM performs an operation related to a virtual I / O device.

[0193] The procedure of step 301 may be that an interrupt occurs when the first VM performs an operation that exceeds the permission of the first VM, and the first processor may detect the interrupt code by using hardware logic and may further obtain the first interrupt request.

[0194] The first interrupt request including the VEI ID may be the first VM writing the VEI ID to a register for storing the VEI ID and the first processor reading the VEI ID from the register for storing the VEI ID.

[0195] 302: The first processor obtains a VM ID of the first VM.

[0196] The first processor may obtain the VM ID from a register for storing virtual machine identifiers, and when the first VM executes on the first processor, the VM ID is written to the register for storing virtual machine identifiers.

[0197] 303: The first processor sends the VEI ID and the VM ID of the first VM to the interrupt controller.

[0198] 304: The interrupt controller queries a corresponding processor identifier and a corresponding VEI physical number based on the VEI ID and VM ID of the first VM, and determines a privilege level that belongs to the host and corresponds to the first interrupt request.

[0199] The referral procedure can be understood with reference to Table 1.

[0200] [Table 1]

[0201] It can be seen from Table 1 that the corresponding CPU ID, VEI physical number, and privilege level of the host can be queried by using the VEI ID, VM ID, and mapping relationship in Table 1.

[0202] If a corresponding processor identifier and VEI physical number are found, step 305 is performed. If not, an exception is reported or the interrupt request is ignored.

[0203] 305: If the first interrupt request needs to be processed in the user mode of the host, information about the shadow thread is set.

[0204] The information about the shadow thread includes the memory address space occupied by the shadow thread, information about the thread data structure, the entry address of the interrupt handling function, and the like.

[0205] 306: If the first interrupt request needs to be processed in a kernel mode of the host, the interrupt controller notifies the second processor to process the first interrupt request in the kernel mode.

[0206] The second interrupt request is a user mode virtual event interrupt.

[0207] 307: The interrupt controller sends a second interrupt request to the second processor. In response, the second processor receives the second interrupt request sent by the interrupt controller.

[0208] The second interrupt request includes information indicating the privilege level of the host.

[0209] 308: The second processor determines whether a current state of the second processor supports the corresponding user mode interrupt, and if the current state of the second processor supports the corresponding user mode interrupt, step 309 is performed; or if the current state of the second processor does not support the corresponding user mode interrupt, step 310 is performed.

[0210] 309: If the second processor currently supports user mode interrupts, the second processor switches information about the first thread to information about the shadow thread.

[0211] The first thread refers to the thread currently being executed by the second processor, and the information about the shadow thread is the information set by the interrupt controller in step 305 .

[0212] 310: If the second processor does not currently support user mode interrupts, the second processor triggers an exception or interrupt to notify the kernel to handle the virtual event interrupt.

[0213] The second processor, in kernel mode, identifies the cause of the exception or interrupt trigger, and then schedules and wakes up the virtual I / O processing thread. The virtual I / O processing thread processes the virtual event interrupt. After processing the virtual event interrupt, the virtual I / O processing thread is blocked and waits for the next virtual event processing notification.

[0214] If the second processor is currently in an idle state, the second processor cannot respond to user mode interrupts.

[0215] 311: If the second processor supports user mode interrupts, the second processor determines whether the first thread is at a virtualization privilege level, and if the first thread is at a virtualization privilege level, step 312 is performed, or if the first thread is not at a virtualization privilege level, step 315 is performed.

[0216] 312: The second processor switches from the virtualization privilege level to the user mode of the host.

[0217] Step 311 may be performed by the second redirection device of FIG.

[0218] 313: The second processor switches to the entry address of the interrupt handling function of the shadow thread to execute the interrupt handling function corresponding to the VEI physical number.

[0219] In the computer device, the mapping relationship between the VEI physical number and the interrupt handling function may be maintained by using a memory, and the second processor may read the corresponding interrupt handling function from the memory based on the VEI physical number.

[0220] If the first thread is at a virtualization privilege level, the context of a second VM executing on a second processor is stored and the context of the shadow thread is restored.

[0221] The second processor may execute a thread in user mode to trap into kernel mode by using a system call and then call a driver for the physical I / O device to operate the physical I / O device.

[0222] 314: After the second processor completes execution of the second interrupt request, it restores the context of the second VM, switches back to the pre-interrupt virtualization privilege level, executes the second VM, and switches to the interrupted instruction address of the second VM to continue execution of the interrupted instruction.

[0223] 315: If the first thread is not at the virtualization privilege level, in response to the user mode interrupt, switch to an entry address of the interrupt handling function of the shadow thread to execute the interrupt handling function corresponding to the VEI physical number.

[0224] If the first thread is not at a virtualization privilege level, the hardware assisted switching apparatus of FIG. 6 responds directly to the user mode interrupt and switches to the entry address of the shadow thread's interrupt handling function to execute the second interrupt request.

[0225] If the first thread is not at the virtualization privilege level, the context of the first thread is stored and the context of the shadow thread is restored.

[0226] 316: If the interrupted thread is not at the virtualization privilege level, restore the context of the first thread and switch to the first thread to continue execution of the interrupted instruction.

[0227] In the asynchronous processing method 1, a VEI ID, a VM ID, and a VEI physical number are used. If the VEI ID is globally unique, the interrupt processing procedure of Figures 10A and 10B may be simplified, and the corresponding procedure described in the embodiment corresponding to Figures 10A and 10B may be implemented only by using the VEI ID to determine the identifier of the corresponding second processor and the privilege level of the corresponding host.

[0228] According to the computer system provided in this embodiment of the present application, an exception or interrupt occurring during the execution of the first VM is transferred to the user mode of the host for processing by using an interrupt controller and a second processor in an asynchronous processing manner.Therefore, the overhead of switching between the kernel mode of the host and the user mode of the host is not required, and the performance of the computer system is improved.

[0229] Asynchronous processing method 2: The sending completion procedure does not include the host kernel, and the receiving completion procedure passes through the host kernel.

[0230] In the asynchronous processing method 2, the procedure at the end of transmission is the same as that of the asynchronous processing method 1 described above, and is implemented by setting a virtual event interrupt component in the first processor and the interrupt controller.

[0231] The difference is that the interrupt controller sends the kernel's second interrupt request to the second processor.

[0232] As shown in FIG. 11, after receiving the second interrupt request of the kernel, the second processor switches to the entry address of the interrupt handling function of the kernel.

[0233] Before switching to the entry address of the interrupt handling function in the host's kernel mode, if the second VM is running on the second processor, the virtualization privilege level of the second VM is switched to the host's kernel mode; if the virtual machine is not running on the second processor and the host is in user mode, the host is first switched from the host's user mode to the host's kernel mode; if the host is in kernel mode, the host switches directly to the entry address of the interrupt handling function.

[0234] The kernel processes an interrupt request and, by using a scheduler, wakes up a kernel-mode thread or a user-mode thread within the virtual I / O processing thread to process a second interrupt request.

[0235] When the scheduler wakes up a user-mode thread, the procedure may be that the second processor executes the user-mode thread, trapping into kernel mode through a system call, and then calling the driver of the physical I / O device to operate the physical I / O device.

[0236] When the scheduler wakes up a kernel-mode thread, a procedure may execute the kernel-mode thread to call the driver of the physical I / O device to operate the physical I / O device.

[0237] Compared with the asynchronous virtual I / O processing framework of the aforementioned asynchronous processing method 1, in this embodiment of the present application, hardware-assisted switching logic and shadow thread technology are not required, and the design and implementation of the asynchronous virtual I / O processing framework is simplified.

[0238] Asynchronous processing method 3: A synchronous method is used for the sending completion procedure, and the receiving completion procedure does not involve the host kernel.

[0239] In the asynchronous processing method 3, the procedure at the sending end implements an asynchronous virtual I / O request notification framework based on the first redirection device and the shadow execution environment in the synchronous virtual I / O processing framework.

[0240] In the asynchronous processing method 3, as shown in FIG. 12, the interrupt controller includes a user mode mapping address space. The first VM may generate a user mode exception instruction by using the solution described in the synchronous method described above, enter a user mode shadow execution environment, and send an interrupt request to the second processor by accessing the user mode mapping address space in the interrupt controller. The interrupt request may be a user mode interrupt or a kernel mode interrupt. Then, the interrupt controller controls the interrupt request to execute the procedure of the reception end in the asynchronous processing method 1. For this part of the content, please refer to the corresponding content of the reception end in the asynchronous processing method 1 for understanding, and the details will not be described again here.

[0241] In this embodiment of the present application, the overhead of sending an interrupt is reduced to the overhead of a context switching procedure, the overhead of an unrelated trap-out procedure of the virtual machine is not required, and the virtual event interrupt component of the asynchronous processing method 1 is not required, reducing the complexity of the hardware design and implementation.

[0242] Asynchronous processing method 4: The sending completion procedure passes through the host kernel, and the receiving completion procedure does not include the host kernel.

[0243] In the asynchronous processing method 4, as shown in FIG. 13, the virtual machine may not be used in the send-end procedure, and the interrupt controller may include a kernel mapping address space and a user mode mapping address space. The first processor may execute a kernel mode thread to access the kernel mapping address space in the interrupt controller and trigger the first interrupt request, and the first processor may execute a user mode thread to access the user mode mapping address space in the interrupt controller and trigger the first interrupt request. That is, the first processor may send the first interrupt request to the interrupt controller by using the user mode thread or the kernel mode thread. The interrupt controller is configured to set information about the shadow thread and send the second interrupt request to the second processor. The second processor switches from the first thread to a shadow thread, the first thread being a thread executed by the second processor before switching, the shadow thread being a thread executing in the host in a user mode and including an interrupt handling function, the interrupt handling function responding to the second interrupt request. The second processor is specifically configured to execute the interrupt handling function in the user mode of the host. For the processing procedure of the second processor, please refer to the reception end procedure of the above-mentioned asynchronous processing method 1. The details will not be described again here.

[0244] According to the solution provided in this embodiment of the present application, in an asynchronous processing manner, an interrupt triggered by a user mode thread or a kernel mode thread is transferred to the host user mode for processing by using an interrupt controller and a second processor. Therefore, the overhead of switching between the host kernel mode and the host user mode is not required, and the performance of the computer system is improved.

[0245] In another embodiment of the present application, a computer-readable storage medium is further provided. The computer-readable storage medium stores computer-executable instructions. When a processor of the device executes the computer-executable instructions, the device performs the exception handling method of FIGS. 2 to 5.

[0246] In another embodiment of the present application, a computer-readable storage medium is further provided. The computer-readable storage medium stores computer-executable instructions. When a processor of the device executes the computer-executable instructions, the device performs the interrupt processing method of FIG. 6 to FIG. 13.

[0247] In another embodiment of the present application, a computer program product is further provided. The computer program product includes computer-executable instructions, and the computer-executable instructions are stored in a computer-readable storage medium. When a processor of the device executes the computer-executable instructions, the device performs the exception handling method of Figures 2 to 5.

[0248] In another embodiment of the present application, a computer program product is further provided. The computer program product includes computer-executable instructions, which are stored in a computer-readable storage medium. When a processor of the device executes the computer-executable instructions, the device performs the interrupt processing method of FIG. 6 to FIG. 13.

[0249] In another embodiment of the present application, a chip system is further provided. The chip system includes a processor, the processor configured to implement the exception handling method of Figures 2-5. In one possible design, the chip system further includes a memory. The memory is configured to store program instructions and data required for exception handling. The chip system may include the chip, or may include the chip and another discrete component.

[0250] In another embodiment of the present application, a chip system is further provided. The chip system includes a processor, and the processor is configured to perform the interrupt processing method of FIG. 6-FIG. 13. In one possible design, the chip system further includes a memory. The memory is configured to store program instructions and data for interrupt processing. The chip system may include the chip, or may include the chip and another discrete component.

[0251] Those skilled in the art may recognize that in combination with the examples described in the embodiments disclosed herein, the units and algorithm steps may be implemented by electronic hardware or by a combination of computer software and electronic hardware. Whether a function is implemented by hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but the implementation should not be considered to go beyond the scope of the embodiments of the present application.

[0252] For the sake of simplicity, the detailed operation processes of the above-mentioned systems, devices and units may be clearly understood by those skilled in the art, and the details will not be described again here, and the detailed operation processes of the above-mentioned systems, devices and units may be clearly understood by those skilled in the art, and the details will not be described again here.

[0253] In some embodiments provided in the embodiments of the present application, it is understood that the disclosed system, device and method may be implemented in other ways. For example, the described device embodiment is merely an example. For example, the division into units is merely a logical division of functions, and may be other divisions in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not implemented. Furthermore, the shown or described mutual couplings, or direct couplings or communication connections, may be implemented by using some interfaces. Indirect couplings or communication connections between devices or units may be implemented in electronic, mechanical, or other forms.

[0254] The units described as separate parts may or may not be physically separated, and the components shown as units may or may not be physical units, in other words, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected based on the actual requirements to achieve the objectives of the solutions of the embodiments.

[0255] In addition, the functional sites of the embodiments of the present application may be integrated into one processing site, each site may exist physically alone, or two or more sites may be integrated into one site.

[0256] When a function is implemented in the form of a software functional unit and sold or used as an independent product, the function may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the embodiments of the present application may be essentially implemented in the form of a software product, or the part that contributes to the prior art, or all or part of the technical solution. The computer software product is stored in a storage medium and includes some instructions for instructing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method described in the embodiments of the present application. The aforementioned storage medium includes any medium that can store program code, such as a USB flash drive, a removable hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. [Explanation of symbols]

[0257] 100 Computer Devices 101 Virtual Machines (VMs) 102 VM 103 Applications 104 Applications 105 Guest Operating System (OS) 106 Guest OS 107 Virtual Processors 108 Virtual Processors 109 Host Layer 110 Virtual Machine Monitor 111 Host Operating System 112 Hardware Layer 113 Memory 114 Processor System 115 Communication Interface 116 Interrupt Controller

Claims

1. A computing device, the computing device comprising a hardware layer, a host executing on the hardware layer, the hardware layer comprising a first processor, a virtual machine VM executing on the first processor, the first processor comprising a redirection device; the first processor is configured to catch an exceptional instruction triggered by the VM; The redirect device, configured to switch from a virtualization privilege level of the VM to a user mode of the host; The first processor executes an exception handling function corresponding to the exception instruction in the user mode of the host. The method further comprises: A computing device, wherein the exception instruction is triggered by an input / output I / O operation performed by the VM.

2. A computing device, the computing device comprising a hardware layer, a host executing on the hardware layer, the hardware layer comprising a first processor, a virtual machine VM executing on the first processor, the first processor comprising a redirection device, the first processor is configured to catch an exceptional instruction triggered by the VM; The redirect device, configured to switch from a virtualization privilege level of the VM to a user mode of the host; The first processor executes an exception handling function corresponding to the exception instruction in the user mode of the host. The method further comprises: the exception handling function is provided within a thread of a virtual processor executing in the user mode of the host, an execution environment assigned to the thread of the virtual processor comprises a main thread execution environment, an execution environment of the VM, and a shadow execution environment, the shadow execution environment having a user mode memory space independent of the main thread execution environment and the execution environment of the VM, the shadow execution environment is used to execute the exception handling function, and the exception handling function is used to handle an exception that triggers the exceptional instruction; A computing device, wherein the first processor is specifically configured to switch from the context of the VM to the context of a user-mode shadow execution environment, and the user-mode memory space of the shadow execution environment is used to store the context of the VM that is moved during a context switch.

3. the redirection unit is further configured to write an entry address of the exception handling function to a first register; The first processor is specifically configured to read the entry address of the exception handling function from the first register, call the exception handling function based on the entry address, and execute the exception handling function corresponding to the exception instruction in the user mode of the host.

3. A device as claimed in claim 1 or 2.

4. A computing device, the computing device comprising a hardware layer, a host executing on the hardware layer, the hardware layer comprising a first processor, a second processor, and an interrupt controller, a first virtual machine VM executing on the first processor, the first processor comprising a virtual event notification device, The first processor is configured to receive a first interrupt request triggered by the first VM, the first interrupt request being used to request to execute an interrupt handling function; the virtual event notification device is configured to send interrupt information to the interrupt controller in response to the first interrupt request; the interrupt controller is configured to determine an identifier of the second processor based on the interrupt information, and to send a second interrupt request to the second processor based on the identifier of the second processor, the second interrupt request being used to request the second processor to execute the interrupt handling function; the second processor is configured to execute the interrupt handling function in response to receiving the second interrupt request; the first interrupt request comprises a virtual event interrupt request number (VEI ID), the VEI ID identifying a virtual event that triggers the first interrupt request; the first processor is further configured to obtain a VM ID of the first VM; the interrupt information comprises the VEI ID and the VM ID of the first VM; The interrupt controller is specifically configured to determine, based on the VEI ID and the VM ID of the first VM, an identifier of the corresponding second processor, a VEI physical number, and a privilege level of the host that processes the first interrupt request, the VEI physical number identifying the virtual event in the host, and to send a second interrupt request to the second processor based on the identifier of the second processor, the second interrupt request comprising information indicative of the privilege level of the host; The second processor is specifically configured to obtain the VEI physical number, and execute an interrupt processing function corresponding to the VEI physical number in response to the received second interrupt request based on a processing method corresponding to the privilege level of the host. Computer device.

5. A computing device comprising a hardware layer, a host executing on the hardware layer, the hardware layer comprising a first processor, a second processor, and an interrupt controller, a first virtual machine executing on the first processor, the first processor comprising a virtual event notification device, The first processor is configured to receive a first interrupt request triggered by the first VM, the first interrupt request being used to request to execute an interrupt handling function; the virtual event notification device is configured to send interrupt information to the interrupt controller in response to the first interrupt request; the interrupt controller is configured to determine an identifier of the second processor based on the interrupt information, and to send a second interrupt request to the second processor based on the identifier of the second processor, the second interrupt request being used to request the second processor to execute the interrupt handling function; the second processor is configured to execute the interrupt handling function in response to receiving the second interrupt request; the first interrupt request comprises a virtual event interrupt request number (VEI ID), the VEI ID identifying a virtual event that triggers the first interrupt request; The interrupt information comprises the VEI ID, The interrupt controller is specifically configured to: determine, based on the VEI ID, an identifier of the corresponding second processor and a privilege level of the host that processes the first interrupt request; and send a second interrupt request to the second processor based on the identifier of the second processor, the second interrupt request comprising information indicative of the privilege level of the host; The second processor is specifically configured to obtain the VEI ID, and execute an interrupt processing function corresponding to the VEI ID in response to the received second interrupt request based on a processing scheme corresponding to the privilege level of the host. Computer device.

6. the privilege level of the host is a user mode, and the second processor further comprises a hardware assisted switching device; The hardware assisted switching device, switching from a first thread to a shadow thread, the first thread being a thread executed by the second processor before switching, the shadow thread being a thread executing within the host in the user mode, the shadow thread being used to execute the interrupt handling function; the second processor is specifically configured to execute the interrupt handling function in the user mode of the host; A computing device according to claim 4 or 5.

7. the second processor further comprises a redirection device; the second processor is further configured to determine whether the first thread is at a virtualization privilege level of a second VM before executing the interrupt handling function in the user mode of the host, the second VM executing on the second processor; the redirection device is configured to switch the virtualization privilege level of the second VM to the user mode of the host if an interrupt thread is in the virtualization privilege level of the second VM.

7. The computing device of claim 6.

8. The redirection unit is further configured to write an entry address of the interrupt handling function to a first register; The second processor is specifically configured to read the entry address of the interrupt handling function from the first register, call the interrupt handling function based on the entry address, and execute the interrupt handling function in the user mode of the host.

8. The computing device of claim 7.

9. the privilege level of the host is kernel mode, The second processor: receiving the second interrupt request in the kernel mode of the host and sent by the interrupt controller; switching to an entry address of an interrupt handling function of the kernel mode of the host, the interrupt handling function responding to the second interrupt request; Executing the interrupt handling function of the kernel mode in the kernel mode of the host. It is configured as follows: A computing device according to claim 4 or 5.

10. 1. An exception handling method, the method being applied to a computing device, a host, and a virtual machine VM running on the computing device, the method comprising: obtaining an exception instruction triggered by the VM; switching from a virtualization privilege level of the VM to a user mode of the host; executing an exception handling function corresponding to the exception instruction in the user mode of the host; Including, A method of handling exceptions, wherein the exception instruction is triggered by an input / output I / O operation performed by the VM.

11. A method for handling an exception, the method being applied to a computer device, a host, and a virtual machine VM running on the computer device, the method comprising: obtaining an exception instruction triggered by the VM; switching from a virtualization privilege level of the VM to a user mode of the host; executing an exception handling function corresponding to the exception instruction in the user mode of the host; Including, the step of executing an exception handling function corresponding to the exception instruction in the user mode of the host, switching from a context of the VM to a context of a shadow execution environment of the user mode to handle an exception in the user mode of the host, wherein the exception handling function is provided within a thread of a virtual processor executing in the user mode of the host, an execution environment assigned to the thread of the virtual processor comprises a main thread execution environment, an execution environment of the VM, and the shadow execution environment, the shadow execution environment having a user mode memory space independent from the main thread execution environment and the execution environment of the VM, the shadow execution environment is used to execute the exception handling function, and the exception handling function is used to handle the exception that triggers the exceptional instruction. Exception handling methods, including:

12. The method further comprising: The method further includes the step of writing an entry address of the exception handling function to a first register; the step of executing an exception handling function corresponding to the exception instruction in the user mode of the host, reading the entry address of the exception handling function from the first register, calling the exception handling function based on the entry address, and executing the exception handling function corresponding to the exception instruction in the user mode of the host; 12. The method of claim 10 or 11, comprising:

13. 1. An interrupt processing method, the method being applied to a computing device, a host, and a first virtual machine VM executing on the computing device, the method comprising: obtaining a first interrupt request triggered by the first VM, the first interrupt request being used to request execution of an interrupt handling function; determining interrupt information in response to the first interrupt request; generating a second interrupt request based on the interrupt information, the second interrupt request being used to request execution of the interrupt handling function; executing the interrupt handling function in response to the second interrupt request; Including, the first interrupt request comprises a virtual event interrupt request number (VEI ID), the VEI ID identifying a virtual event that triggers the first interrupt request, the method further comprising: obtaining a VM ID of the first VM, wherein the interrupt information comprises the VEI ID and the VM ID of the first VM; determining a corresponding VEI physical number and privilege level of the host that processes the first interrupt request based on the VEI ID and the VM ID of the first VM, the VEI physical number identifying the virtual event in the host; the step of executing the interrupt handling function in response to the second interrupt request comprises: acquiring the VEI physical number, and executing an interrupt processing function corresponding to the VEI physical number in response to the second interrupt request based on a processing method corresponding to the privilege level of the host; 13. An interrupt handling method comprising:

14. A method for handling interrupts, the method being applied to a computer device, a host, and a first virtual machine VM executing on the computer device, the method comprising: obtaining a first interrupt request triggered by the first VM, the first interrupt request being used to request execution of an interrupt handling function; determining interrupt information in response to the first interrupt request; generating a second interrupt request based on the interrupt information, the second interrupt request being used to request execution of the interrupt handling function; executing the interrupt handling function in response to the second interrupt request; Including, the first interrupt request comprises a virtual event interrupt request number VEI ID, the VEI ID identifying a virtual event that triggers the first interrupt request, the interrupt information comprises the VEI ID, and the method further comprises: determining a privilege level of the host for processing the first interrupt request based on the VEI ID; the step of executing the interrupt handling function in response to the second interrupt request comprises: acquiring the VEI ID, and executing an interrupt processing function corresponding to the VEI ID in response to the second interrupt request based on a processing method corresponding to the privilege level of the host; 13. A method for handling an interrupt, comprising:

15. the privilege level of the host is a user mode, and the step of executing the interrupt handling function in response to the second interrupt request comprises: switching from a first thread to a shadow thread, the first thread being a thread executed by the host before switching, the shadow thread being a thread executing within the host in the user mode, the shadow thread being used to execute the interrupt handling function; executing the interrupt handling function in the user mode of the host; 15. The method of claim 13 or 14, comprising:

16. the privilege level of the host is a kernel mode, and the step of executing the interrupt processing function corresponding to the VEI ID in response to the received second interrupt request based on a processing method corresponding to the privilege level of the host, switching to an entry address of an interrupt processing function of the kernel mode of the host, the interrupt processing function corresponding to the second interrupt request; executing, in the kernel mode of the host, the interrupt handling function of the kernel mode; 15. The method of claim 13 or 14, comprising:

Citation Information

Patent Citations

  • Interrupt request processing method, device, and virtualization device

    CN109144679A

  • Big data platform process management method based on process virtualization and computer device

    CN109284169A

  • TLB exception handling method and device, electronic equipment and storage medium

    CN110990180A

  • Providing multiple virtual device controllers by redirecting interrupt from physical device controller

    JP2010157232A

  • Providing multiple virtual device controllers by redirecting an interrupt from a physical device controller

    US20100169883A1