Virtual machine switching method, data storage method, device, processor, and storage medium
By setting up a dedicated cache in the processor cache to store virtual machine status data, and directly reading the status data from the cache to improve virtual machine switching efficiency, it solves the time-consuming problem of virtual machine switching and improves system performance.
Patent Information
- Application Number
- PCT/CN2024/074065
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-10
- Filing Date
- 2024-01-25
- Publication Date
- 2024-09-19
AI Technical Summary
The existing virtual machine switching process takes a long time and is inefficient, especially when the virtual machine exits and starts, there are many clock cycles, which affects system performance.
A dedicated cache is set up in the cache of the processor to store the status data of the virtual machine, so that the status data can be read directly from the cache during switching, reducing dependence on memory and improving switching efficiency.
By reducing the number of memory accesses, it significantly improves the speed and efficiency of virtual machine switching, reduces the risk of virtual machine status data being overwritten, and improves system performance.
Smart Images

Figure CN2024074065_19092024_PF_FP_ABST
Abstract
Description
Virtual machine switching and data storage method, device, processor and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 10, 2023, with application number 202310264147.0 and invention name “Virtual machine switching and data storage method, device, processor and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a virtual machine switching and data storage method, device, processor, and storage medium. Background Art
[0003] A virtual machine (VM) refers to a computer system that runs in an isolated environment and has complete hardware system functions simulated by software. In the current virtual machine scheduling, when switching from a virtual machine to the host side (Host), it is necessary to first exit from the current virtual machine (i.e., vmexit) and save the state data of the current virtual machine to the memory. After the operation on the host side is completed, it is necessary to switch back to the exited virtual machine from the host side or switch to another virtual machine. This process requires the host to read the state data of the virtual machine to be run from the host machine's memory to the central processing unit (CPU), and finally run the virtual machine (i.e., vmenter) based on the state data of the virtual machine to be run. The above-mentioned virtual machine scheduling process is a complete virtual machine switching process, which is time-consuming and has low virtual machine switching efficiency.
[0004] Summary of the Invention
[0005] Various aspects of the present application provide a virtual machine switching and data storage method, device, processor, and storage medium to improve virtual machine switching efficiency.
[0006] An embodiment of the present application provides a virtual machine switching method, comprising: in response to a virtual machine scheduling event, obtaining state data of a target virtual machine to be run from a dedicated cache of a processor; the dedicated cache is a partial cache of the processor, used to store the state data of the virtual machine; switching the execution flow of the processor from the host machine of the target virtual machine to the target virtual machine; and running the target virtual machine according to the state data of the target virtual machine.
[0007] An embodiment of the present application also provides a data storage method, in which a processor of a host machine includes: a dedicated cache; the dedicated cache is used to store state data of a virtual machine; the method includes: determining a target virtual machine to be cached from the host machine; obtaining the state data of the target virtual machine from the memory of the host machine; storing the state data of the target virtual machine in the dedicated cache, so as to switch the execution flow of the processor to the target virtual machine using the state data stored in the dedicated cache.
[0008] An embodiment of the present application also provides a computing device, which is deployed with a virtual machine; the computing device includes: a processor, the processor includes: a control unit, an operation unit and a cache; the computing device also includes: a target memory for storing a computer program; the cache includes: a dedicated cache and a shared cache; the dedicated cache is used to store state data of the virtual machine; the shared cache is used to execute other data required by the computer program in addition to the state data of the virtual machine; the control unit is coupled to the operation unit, the cache and the target memory, and is used to execute the computer program and write the other data into the shared cache during the execution of the computer program; and the steps in the above-mentioned virtual machine switching method and / or data storage method are performed in combination with the other data.
[0009] An embodiment of the present application also provides a processor, comprising: a control unit, an operation unit and a cache; the cache comprises: a dedicated cache and a shared cache; when the processor is deployed on an electronic device, the dedicated cache is used to cache the status data of the virtual machine deployed on the electronic device; the shared cache is used to cache other data required by the computer program running on the electronic device in addition to the status data of the virtual machine; the control unit is coupled to the cache and the operation unit, and is used to call and run the computer program stored in the memory of the electronic device on which the processor is deployed, so that the electronic device executes the steps in the above-mentioned virtual machine switching method and / or data storage method.
[0010] An embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned virtual machine switching method and / or data storage method. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar components or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in this application and should not be construed as limiting the scope of this application.
[0012] The accompanying drawings described herein are intended to provide a further understanding of the present application and constitute a part of the present application. The exemplary embodiments of the present application and their descriptions are intended to explain the present application and do not constitute an improper limitation of the present application. The accompanying drawings include the following Figures 1 to 6.
[0013] FIG1 shows a schematic diagram of the structure of a computing device provided in an embodiment of the present application.
[0014] FIG2 shows a schematic diagram of the deployment location of a dedicated cache provided in an embodiment of the present application.
[0015] FIG3 shows a schematic diagram of a virtual machine switching process provided in an embodiment of the present application.
[0016] FIG4 shows a schematic flow chart of a virtual machine switching method provided in an embodiment of the present application.
[0017] FIG5 shows a schematic flow chart of a data storage method provided in an embodiment of the present application.
[0018] FIG6 shows a schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0019] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0020] The inventors of this application have studied the current virtual machine scheduling process and found that in the current virtual machine scheduling process, a complete virtual machine exit (vmexit) and virtual machine startup (vmlaunch) takes approximately 2000 clock cycles, of which the execution time of the virtual machine exit (vmexit) and virtual machine startup (vmlaunch) instructions takes approximately 200-300 clock cycles. The clock cycle refers to the clock cycle of the processor of the virtual machine's host computer.
[0021] In some solutions, to increase the virtual machine switching rate, the operating system applies paravirtualization (PV) technology or input / output (IO) device passthrough technology to reduce the number of virtual machine exits, that is, to reduce the number of vmexit instructions executed. This is mainly because with IO device passthrough technology, the virtual machine can directly access memory to read its status data without the virtual machine exiting. Paravirtualization technology refers to a method by which the virtual machine system cooperates with the host system to virtualize the virtual machine system. In this technology, the virtual machine can use virtualized IO devices to access memory to read data, which can also reduce the number of virtual machine exits.
[0022] However, for paravirtualization technology and IO device direct access technology, the operating system still needs to return to the host side through the virtual machine exit instruction (such as the vmexit instruction) when scheduling the virtual machine. This is mainly because during the operation of the virtual machine, there may be instructions on the host side that need to be executed. Therefore, the virtual machine needs to use clock interrupt technology to interrupt the operation of the virtual machine and switch to the host side to check whether there are instructions that need to be executed. Therefore, paravirtualization technology and IO device direct access technology still have the time overhead of virtual machine exit. The inventors of this application have found that in paravirtualization technology and IO device direct access technology, there is a time overhead of virtual machine exit (vmexit) of about 1,000 times per second.
[0023] The inventors of this application have found that the performance of the virtual machine switching process is closely related to the processor cache. The time overhead of virtual machine switching when the processor cache contains the status data of the relevant virtual machine is about one tenth of the time overhead of virtual machine switching when the processor cache does not contain the status data of the relevant virtual machine.
[0024] Based on this, in some embodiments of the present application, to improve virtual machine switching efficiency, a dedicated cache is provided in the processor's cache for caching virtual machine state data. Based on the dedicated cache, when the processor's execution flow switches from the host machine to the target virtual machine, the target virtual machine's state data can be read from the processor's dedicated cache. Because reading virtual machine state data from the cache is faster than reading virtual machine state data from memory during traditional virtual machine switching, reading state data from the processor's dedicated cache during virtual machine switching helps improve virtual machine switching efficiency.
[0025] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0026] It should be noted that the same reference numerals denote the same objects in the following drawings and embodiments, and therefore, once an object is defined in one drawing or embodiment, it does not need to be further discussed in the subsequent drawings and embodiments.
[0027] FIG1 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. As shown in FIG1 , the computing device includes a processor 10. The processor 10 may include a control unit 101, a cache 102, and an operation unit 103.
[0028] The control unit 101 is the control center of the processor 10 and includes an instruction register (IR), an instruction decoder (ID), and an operation controller (OC). Based on a pre-programmed computer program, the control unit 101 sequentially retrieves instructions from memory and places them in the instruction register (IR). It then decodes the instructions to determine the appropriate operation and, through the operation controller (OC), issues micro-operation control signals to the appropriate components according to a predetermined timing. The control unit 101 controls the operation of the cache 102 and the arithmetic unit 103 through instructions.
[0029] Arithmetic unit 103 is the core of processor 10 and can perform arithmetic and logical operations. Arithmetic unit 103 receives commands from the control unit and performs actions. In other words, all operations performed by arithmetic unit 103 are directed by control signals sent by control unit 101. Arithmetic unit 103 is the execution component of instructions.
[0030] Cache 102 is a temporary data storage unit within processor 10, used to store data awaiting processing or already processed data. Processor 10 accesses cache 102 in a shorter time than accesses to main memory. Using cache 102 reduces the number of main memory accesses required by processor 10, thereby increasing the data processing speed of processor 10.
[0031] In this embodiment, the computing device may further include a target storage 20. The target storage 20 refers to a storage medium on the computing device other than the cache 102. The target storage 20 may include a memory 201 and a non-volatile storage medium 202. The non-volatile storage medium may be a disk, a solid-state drive, or the like.
[0032] In this embodiment, the target storage 20 stores a computer program. For example, the computer program may be stored in the memory 201.
[0033] In this embodiment, the computing device is a host machine of a virtual machine (VM) 30, which can be a server-side device. For example, the computing device can be a single server device or a cloud-based server array. Of course, the computing device can also be a terminal device such as a mobile phone, tablet computer, personal computer, or wearable device.
[0034] In this embodiment, a computing device is deployed with a virtual machine 30. The virtual machine 30 can also be referred to as a guest of the host machine. The VM 30 has an independent processor (e.g., CPU), memory, network, and disk. The CPU corresponding to the virtual machine 30 can also be referred to as a virtual CPU (vCPU). There can be one or more VMs 30 deployed on the computing device. Multiple means two or more. Each VM may have its own logical core, or multiple VMs 30 may share a single logical core.
[0035] For processors such as CPUs, a physical core is a physical resource. A logical core is a logical processing unit created by virtualizing a physical core using hyperthreading technology. A vCPU, a concept introduced during virtualization, typically refers to a CPU logical core divided by the virtual ratio. The virtual ratio refers to the ratio of the number of vCPUs virtualized from one logical core to the number of vCPUs. For example, a virtual ratio of 1:100 means that one logical core is virtualized into 100 vCPUs. When the vCPUs corresponding to multiple VMs share the same logical core, this type of VM is called a shared VM.
[0036] During the operation of a VM, it is often necessary to switch from the currently running VM to the host side. After the host side performs an operation, it switches back to the VM, which is called VM switching. When the processor 10 executes a computer program, it can read the data required to execute the computer program from the memory 201 into the cache 102. Since the data transmission rate of the cache 102 is greater than that of the memory 201, storing the data required by the computer program in the cache 102 helps to improve the data processing efficiency of the processor 10. In an embodiment of the present application, for the application scenario of virtual machine switching, the state data of the virtual machine to be run can be stored in the cache 102 to improve the data processing efficiency of the processor 10.
[0037] Because the storage space in cache 102 is limited and generally much smaller than the storage space in memory 201, data stored in cache 102 frequently needs to be swapped in and out while processor 10 is executing a computer program. Even if cache 102 stores virtual machine state data, it may be overwritten by other data during computer program execution. This means that the virtual machine state data cannot be guaranteed to remain in cache 102. If the virtual machine state data stored in cache 102 is overwritten by other data, the virtual machine state data must be read from memory 201 during virtual machine switching, which still affects virtual machine switching efficiency.
[0038] To reduce the risk of virtual machine state data being overwritten by other data, in this embodiment, a dedicated cache space, namely, dedicated cache 102a, may be provided in cache 102 to store virtual machine state data. Dedicated cache 102a is specifically used to store virtual machine state data, and other data required for executing computer programs is not stored in dedicated cache 102a.
[0039] In this embodiment, dedicated cache 102a uses a storage medium with greater data transmission efficiency than memory 201. For example, if memory 201 is Double Data Rate Synchronous Dynamic Random Access Memory (DDR SDRAM), DDR memory for short, dedicated cache 102 can use Static Random-Access Memory (SRAM). If memory 201 is Phase-Change Memory (PRAM), dedicated cache 102 can use DDR memory, etc.
[0040] Specifically, dedicated cache 102 may be a portion of the cache allocated from the processor 10's intrinsic cache. Specifically, a portion of the processor 10's intrinsic cache is designated as dedicated cache 102, specifically for storing virtual machine state data. Accordingly, the remaining cache in the processor 10's intrinsic cache, excluding dedicated cache 102, is shared cache 102b. Shared cache 102b can store data required by the computer program during its execution, in addition to the virtual machine state data, supporting data swapping.
[0041] Of course, as shown in FIG2 , dedicated cache 102a may also be a newly added cache in processor 10, in addition to the inherent cache of processor 10. The newly added cache serves as a dedicated cache, specifically for storing virtual machine state data. The inherent cache of processor 10 is shared cache 102b, which can store other data required by the computer program during execution, in addition to the virtual machine state data, and supports data swapping.
[0042] In this embodiment, the dedicated cache 102a and the shared cache 102b together constitute the cache 102 of the processor 10. The cache 102 may include multiple levels of cache. For example, the cache 102 may include a Level 1 (L1) cache, a Level 2 (L2) cache, and a Level 3 (L3) cache. Correspondingly, the shared cache 102b may also include an L1 cache, an L2 cache, and an L3 cache. The dedicated cache 102a may also include an L1 cache, an L2 cache, and an L3 cache. Of course, the dedicated cache 102a may also be located at any of the L1, L2, and L3 cache levels. As shown in FIG2 , to improve data transmission efficiency, the dedicated cache 102 may be located at the L1 cache.
[0043] In this embodiment, the storage space size of the dedicated cache 102 is not limited. For example, the storage space of the dedicated cache 102a is a positive integer multiple (such as N times) of the data volume of the state data of a single virtual machine (set to Y kB). Wherein, N≥1 and is an integer. That is, the storage space of the dedicated cache 102a can be N*Y kB. The dedicated cache 102a can be divided into N blocks of cache space according to the data volume of the state data of a single virtual machine. Each cache space is used to store the state data of a virtual machine. In this embodiment, a corresponding identifier, such as idx, can be configured for each cache space. x=0, 1, ..., (N-1). idx can represent the xth block of cache space in the dedicated cache 102a.
[0044] In this embodiment, in order to implement reading and writing of the dedicated cache, a new instruction is added to the processor 10, which instructs the user to manage the dedicated cache. The new instruction can specify which cache space in the dedicated cache 102a is to store data at which memory address. For example, the new instruction can be: "vmcs_cache_addr idx addr". In this instruction, "idx" represents the cache space identified as idx in the dedicated cache. "addr" represents the memory starting address of the data to be stored. Accordingly, the instruction "vmcs_cache_addr idx addr" indicates writing the data in the memory space at the memory address [addr, addr+Y kB] to the cache space identified as idx in the dedicated cache 102a.
[0045] In this embodiment, the control unit 101, cache 102, and computing unit 103 are electrically connected. The processor 10 is electrically connected to the target memory 20. In this embodiment, the control unit 101 can be coupled to the cache 102, computing unit 103, and target memory 20 to execute a computer program stored in the target memory 20. For example, while controlling the computing unit 102 to execute the computer program, the control unit 101 can write the computer program and other data required by the computer program into the shared cache 102b and, in conjunction with the other data in the shared cache 102b, execute a method for storing virtual machine state data.
[0046] The following is an exemplary description of a method for storing virtual machine state data from the perspective of a processor. To accelerate VM switching, processor 10 can determine a target virtual machine to be cached from the computing device based on dedicated cache 102a. The target virtual machine to be cached is the virtual machine whose state data needs to be stored in dedicated cache 102a.
[0047] In this embodiment, the specific implementation method for determining the target virtual machine to be cached is not limited. In some embodiments, the processor 10 may determine the target virtual machine from the virtual machines deployed on the computing device according to the set cache management policy. For example, the processor 10 may select a virtual machine whose switching frequency meets the set cache condition from the virtual machines deployed on the computing device according to the switching frequency of the virtual machines in the computing device, as the target virtual machine to be cached. Among them, the cache condition corresponding to the switching frequency may be implemented as: the switching frequency is greater than or equal to the set frequency threshold. Accordingly, a virtual machine whose switching frequency is greater than or equal to the set frequency threshold may be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached.
[0048] Alternatively, for the switching frequency, the cache condition may be set as follows: the switching frequency is the virtual machine with the highest switching frequency among the virtual machines. Accordingly, the virtual machine with the highest switching frequency may be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached.
[0049] In other embodiments, based on the number of times a virtual machine on a computing device is used within a set time period, a virtual machine whose usage meets a set caching condition can be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached. The caching condition corresponding to the number of usages can be implemented as: the number of usages within the set time period is greater than or equal to a set threshold. Accordingly, a virtual machine whose usage within the set time period is greater than or equal to the set threshold can be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached.
[0050] Of course, in some other embodiments, all virtual machines deployed in the computing device may be used as target virtual machines to be cached; or, any virtual machine in the computing device may be used as a target virtual machine to be cached.
[0051] The implementation method of determining the target virtual machine to be cached shown in the above embodiment is only for illustrative purposes and does not constitute a limitation.
[0052] For the target virtual machine to be cached, the processor 10 may obtain the state data of the target virtual machine from the target memory 20. For example, the processor 10 may obtain the state data of the target virtual machine from the memory 201.
[0053] In various embodiments of the present application, virtual machine state data refers to data required for virtual machine operation, including but not limited to: register state data and the virtual machine's memory page table during virtual machine operation. In some processor architectures, virtual machine state data can be implemented as a virtual machine control structure (VMCS). In other processor architectures, virtual machine state data can be implemented as a processor context, etc.
[0054] Processor 10 can determine the memory address corresponding to the target virtual machine based on the identifier of the target virtual machine. This memory address can be a virtual address of the host machine. The memory address corresponding to the target virtual machine stores the state data of the target virtual machine. Accordingly, processor 10 can read the state data of the target virtual machine from memory 201 based on the memory address corresponding to the target virtual machine.
[0055] In some embodiments, the processor 10 may store the state data of the target virtual machine in the dedicated cache 102a. In this way, when the execution flow of the subsequent processor switches from the host machine to the target virtual machine, the state data of the target virtual machine can be directly read from the dedicated cache 102a, which helps improve the efficiency of virtual machine switching.
[0056] A processor's execution stream is a logically independent region of instructions. Each execution stream is independent, with its own stack, register image, and memory resources—in other words, an independent context. A processor's execution stream may include the instruction sequence currently being executed by the processor and the state of its registers.
[0057] In the embodiment of the present application, when storing the state data of the target virtual machine in the dedicated cache 102 a , the processor 10 may determine the target cache space from the dedicated cache 102 a and write the state data of the target virtual machine into the target cache space.
[0058] In some embodiments, the processor 10 may determine free cache space from the dedicated cache as the target cache space.
[0059] In other embodiments, there may be no free cache space in the dedicated cache. Accordingly, the processor 10 may determine the cache space to be replaced from the dedicated cache 102a according to a predetermined cache replacement algorithm, and use this as the target cache space. Of course, the implementation of using the cache replacement algorithm to determine the cache space to be replaced is also applicable to the case where free cache space is stored in the dedicated cache.
[0060] In the embodiments of the present application, a cache replacement algorithm is used to provide a strategy for determining cache space to be replaced, and the specific implementation of the cache replacement algorithm is not limited. For example, the cache replacement algorithm may include: an optimal replacement (OPT) algorithm, a first-in-first-out (FIFO) algorithm, a least recently used (LRU) algorithm, or a clock replacement (CLOCK) algorithm.
[0061] The optimal replacement algorithm (OPT) is to select a cache space that will never be used in the future or will not be accessed for the longest time, and use this cache space as the target cache space to be replaced.
[0062] The first-in-first-out (FIFO) algorithm arranges the cache spaces in the dedicated cache into a queue according to the order in which data is written, and selects the cache space to which data is written first as the target cache space to be replaced.
[0063] The Least Recently Used (LRU) algorithm selects cache space that has not been used recently. In one embodiment, the Available Access field records the time since the cache space in the dedicated cache was last accessed. When cache replacement is required, the cache space with the largest corresponding time value is selected from the cache space and becomes the least recently used cache space, i.e., the target storage space to be replaced.
[0064] The clock replacement algorithm (CLOCK) links the cache spaces in a dedicated cache into a circular queue using link pointers, adding an access bit field to each cache space. When a cache space is accessed, the corresponding access bit field is also set to 1. In this method, when cache replacement is required, the operating system scans the buffer to find cache spaces with their corresponding access bit fields set to 0. The first cache space found with its access bit field set to 0 is selected as the target cache space to be replaced.
[0065] After determining the target cache space, the processor 10 may write the state data of the target virtual machine into the target cache space.
[0066] Because the dedicated cache is a dedicated cache for virtual machine state data, a processor instruction for managing the dedicated cache can be added to the processor, such as the instruction "vmcs_cache_addr idx addr" shown in the above embodiment. Based on the processor instruction for managing the dedicated cache, after determining the target virtual machine to be cached and the target cache space in the dedicated cache, the processor 10 can write the memory address of the target virtual machine and the identifier of the target cache space into the processor instruction according to the format of the processor instruction for managing the dedicated cache. The processor instruction may include: the memory address where the state data of the target virtual machine is located and the identifier of the target cache space.
[0067] In one embodiment, the processor 10 may execute a processor instruction for managing a dedicated cache, and during execution of the processor instruction, read the target virtual machine's state data from the memory according to the memory address included in the processor instruction. For example, the target virtual machine's state data may be read from the memory space at the memory address [addr, addr+Y kB].
[0068] Exemplarily, during the execution of the processor instructions, the processor 10 may write the target virtual machine's state data into a cache space in the dedicated cache that corresponds to the identifier of the target cache space. For example, the processor 10 may write the target virtual machine's state data into a cache space in the dedicated cache that corresponds to the identifier of the target cache space according to a data structure corresponding to the dedicated cache. The data structure corresponding to the dedicated cache may be a VMCS.
[0069] Since the state data of the target virtual machine is stored in the dedicated cache 102a in the processor 10, when the execution flow of the processor 10 switches from the host machine to the target virtual machine, the state data of the target virtual machine can be read from the dedicated cache 102a, which helps to improve the efficiency of virtual machine switching.
[0070] The following is an illustrative description of the virtual machine switching process provided in the embodiment of the present application. In the embodiment of the present application, the virtual machine switching scenario may include: the execution flow of the processor exits from VM1 and switches to the host machine side where VM1 is located; then, switches back to VM1 from the host machine side. Of course, the virtual machine switching scenario may also include: the execution flow of the processor exits from VM1 and switches to the host machine side where VM1 is located; then, switches from the host machine side to VM2. Whether the execution flow of the processor switches back to VM1 from the host machine side or switches to the new VM2 is specifically determined by the operating system scheduling in the processor 10.
[0071] For example, the processor 10 may determine a target virtual machine to be run according to the load balancing policy. The target virtual machine may be VM1 or VM2.
[0072] The process of switching the processor's execution flow from the host back to the original VM1 or to the new VM2 is the same. In this embodiment of the present application, both the original VM1 and the new VM2 can be defined as target virtual machines. That is, the target virtual machine is the virtual machine to be run on the computing device. The following uses the target virtual machine as an example to illustrate the virtual machine switching process.
[0073] As shown in Figure 3, processor 10 can retrieve the state data of the target virtual machine to be executed from dedicated cache 102a in response to a virtual machine scheduling event. A virtual machine scheduling event is an event that instructs the processor's execution flow to switch from the host machine to the virtual machine. It can be issued by the operating system running on the processor. The target virtual machine to be executed can be determined by the operating system.
[0074] In some embodiments, the processor 10 may determine the target virtual machine to be run based on a set virtual machine scheduling policy. For example, the target virtual machine to be run may be determined based on the task priority of the virtual machine. For example, the virtual machine with the highest task priority may be selected from the virtual machines of the computing device as the target virtual machine to be run. After the target virtual machine is determined, a virtual machine scheduling event may be generated. This virtual machine scheduling event is used to instruct the processor to switch the execution flow from the host machine to the target virtual machine.
[0075] In some embodiments, the processor 10 may obtain the state data of the target virtual machine to be run from the dedicated cache 102a in response to a virtual machine scheduling event. In one embodiment, the processor 10 may switch the execution flow of the processor from the host machine of the target virtual machine to the target virtual machine. For example, the processor 10 may execute a virtual machine entry instruction (such as vmenter) with the target virtual machine as the virtual machine to be entered, thereby switching the execution flow of the processor from the host machine to the target virtual machine. Exemplarily, the processor 10 may run the target virtual machine based on the state data of the target virtual machine.
[0076] In this embodiment, a dedicated cache is provided within the processor's cache for caching virtual machine state data. Based on the dedicated cache, when the processor's execution flow switches from the host machine to the target virtual machine, the target virtual machine's state data can be read from the processor's dedicated cache. Because reading virtual machine state data from the cache is faster than reading virtual machine state data from memory during traditional virtual machine switching, reading state data from the processor's dedicated cache during virtual machine switching helps improve virtual machine switching efficiency.
[0077] On the other hand, a cache dedicated to storing the state data of the virtual machine is set in the processor to prevent the state data of the virtual machine from being overwritten by other data during the execution of the computer program, and to reduce the probability of the processor reading the state data of the virtual machine from the memory.
[0078] In the embodiments of the present application, the execution flow of the processor is not limited to operating on the host machine side. In some embodiments, the execution flow is in a virtual machine state before the host machine side. This virtual machine may be the target virtual machine described above, or it may be another virtual machine. The following example illustrates the process of switching from a virtual machine to a host machine, using the execution flow of the processor in a first virtual machine before switching to the host machine as an example. The first virtual machine may be the target virtual machine to be run, or it may be another virtual machine other than the target virtual machine to be run.
[0079] The processor 10 may, in response to the virtual machine exit event, cause the first virtual machine in the execution flow of the processor to exit the execution flow. For example, the processor 10 may, in response to the virtual machine exit event, execute a virtual machine exit instruction (such as a vmexit instruction) with the first virtual machine as the virtual machine to be exited, thereby causing the first virtual machine to exit the execution flow of the processor.
[0080] The virtual machine exit event may be issued by the operating system running on the processor 10, or by another virtual machine. In some embodiments, the operating system in the processor 10 may issue an interrupt request according to a set interrupt cycle. Accordingly, the virtual machine exit event may be implemented as receiving an interrupt request. In one embodiment, in response to the interrupt request, the first virtual machine in the execution flow of the processor may be exited from the execution flow.
[0081] In other embodiments, if the first virtual machine shares a logical core with other virtual machines, the other virtual machines sharing the logical core with the first virtual machine may issue an inter-core interrupt request to the first virtual machine. Accordingly, the virtual machine exit event may be implemented as receiving an inter-core interrupt request. For example, the processor 10 may exit the first virtual machine from the execution flow of the processor in response to the inter-core interrupt request.
[0082] In one embodiment, the processor 10 may obtain state data of the first virtual machine, wherein the state data of the first virtual machine is state data when the first virtual machine exits the execution flow, and may include: state data of registers when the first virtual machine exits the execution flow and a memory page table corresponding to the first virtual machine.
[0083] Accordingly, the processor 10 can read the status data of the host machine's registers and the memory page table corresponding to the first virtual machine when the first virtual machine exits the processor's execution flow; and use the status data of the host machine's registers and the memory page table corresponding to the first virtual machine at this time as the status data of the first virtual machine.
[0084] For example, the processor 10 may write the state data of the first virtual machine into the dedicated cache 102a. For details on how to write the state data of the first virtual machine into the dedicated cache 102a, please refer to the above-mentioned content on how to write the state data of the target virtual machine into the dedicated cache, which will not be repeated here.
[0085] The processor 10 may switch the execution flow to the host machine of the first virtual machine. Accordingly, the host machine may execute instructions. In this embodiment, the specific content of the instructions executed by the host machine is not limited. In some embodiments, the host machine may detect whether there are instructions to be executed in the host machine process; if so, the host machine process is called to execute the above instructions to be executed. After the host machine executes the above instructions to be executed, the processor 10 may determine the target virtual machine from the computing device according to the virtual machine scheduling policy. Accordingly, if there are no instructions to be executed in the host machine process, the processor 10 may determine the target virtual machine from the computing device according to the virtual machine scheduling policy. For the relevant content of determining the target virtual machine from the computing device according to the virtual machine scheduling policy, please refer to the above relevant content and will not be repeated here.
[0086] In some embodiments, the processor 10 may generate a virtual machine scheduling event that switches the execution flow of the processor to the target virtual machine. Regarding the implementation of the processor 10 switching the execution flow to the target virtual machine in response to the virtual machine scheduling event, please refer to the relevant content of the above embodiment and will not be repeated here.
[0087] The target virtual machine may be the first virtual machine, or may be another virtual machine (defined as a second virtual machine) other than the first virtual machine in the computing device.
[0088] In some embodiments, the target virtual machine is a second virtual machine. Before the state data of the second virtual machine is retrieved from dedicated cache 102a, the state data of the second virtual machine has already been pre-stored in dedicated cache 102a. Accordingly, before responding to the virtual machine scheduling event, the state data of the second virtual machine can also be read from memory and written to dedicated cache 102a. Because the state data of the second virtual machine has already been pre-stored in the dedicated cache before the processor responds to the virtual machine call event, reading the state data of the second virtual machine from the processor's dedicated cache when switching to the second virtual machine helps improve virtual machine switching efficiency.
[0089] Among them, regarding the specific implementation methods of reading the status data of the second virtual machine from the memory and writing the status data of the second virtual machine into the dedicated cache, please refer to the above embodiment, and the relevant content of reading the status data of the target virtual machine from the memory and writing the status data of the target virtual machine into the dedicated cache will not be repeated here.
[0090] In other embodiments, if the processor 10 does not read the state data of the second virtual machine from the dedicated cache 102a, it may read the state data of the second virtual machine from the memory and, based on the state data of the second virtual machine, switch the execution flow of the processor to the second virtual machine. For example, the processor 10 may also write the state data of the second virtual machine to the dedicated cache 102a, so that the state data of the second virtual machine can be read directly from the dedicated cache to perform virtual machine switching.
[0091] In addition to the above system embodiments, the present invention also provides a data storage method and a virtual machine switching method. The data storage method and virtual machine switching method provided in the present invention are exemplarily described below.
[0092] Figure 4 is a flow chart of a data storage method provided by an embodiment of the present application. As shown in Figure 4, the data processing method mainly includes steps 401-403.
[0093] 401. Determine a target virtual machine to be cached from a host machine.
[0094] 402. Obtain the target virtual machine's status data from the host machine's memory.
[0095] 403. Store the state data of the target virtual machine in a dedicated cache of a processor of the host machine, and use the state data stored in the dedicated cache to switch the execution flow of the processor to the target virtual machine.
[0096] The description of the implementation of the dedicated cache can be found in the relevant content of the above computing device embodiment, which will not be repeated here. In this embodiment, the dedicated cache is dedicated to storing state data of the virtual machine.
[0097] In order to accelerate VM switching, a target virtual machine to be cached can be determined from the host machine based on the dedicated cache. The target virtual machine to be cached refers to the virtual machine whose state data needs to be stored in the dedicated cache.
[0098] In this embodiment, the specific implementation method for determining the target virtual machine to be cached is not limited. In some embodiments, the target virtual machine can be determined from the virtual machines deployed by the computing device according to the set cache management policy. For example, based on the switching frequency of the virtual machines in the computing device, a virtual machine whose switching frequency meets the set cache conditions can be selected from the virtual machines deployed by the computing device as the target virtual machine to be cached. Among them, the cache condition corresponding to the switching frequency can be implemented as: the switching frequency is greater than or equal to the set frequency threshold. Accordingly, a virtual machine whose switching frequency is greater than or equal to the set frequency threshold can be selected from the virtual machines deployed by the computing device as the target virtual machine to be cached.
[0099] Alternatively, for the switching frequency, the cache condition may be set as follows: the switching frequency is the virtual machine with the highest switching frequency among the virtual machines. Accordingly, the virtual machine with the highest switching frequency may be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached.
[0100] In other embodiments, based on the number of times a virtual machine on a computing device is used within a set time period, a virtual machine whose usage meets a set caching condition can be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached. The caching condition corresponding to the number of usages can be implemented as: the number of usages within the set time period is greater than or equal to a set threshold number of times. Accordingly, a virtual machine whose usage within the set time period is greater than or equal to the set threshold number of times can be selected from the virtual machines deployed on the computing device as the target virtual machine to be cached.
[0101] Of course, in some other embodiments, all virtual machines deployed in the computing device may be used as target virtual machines to be cached; or, any virtual machine in the computing device may be used as a target virtual machine to be cached.
[0102] The implementation method of determining the target virtual machine to be cached shown in the above embodiment is only for illustrative purposes and does not constitute a limitation.
[0103] For the target virtual machine to be cached, the state data of the target virtual machine may be obtained from the target storage, for example, the state data of the target virtual machine may be obtained from the memory.
[0104] In various embodiments of the present application, virtual machine state data refers to data required for virtual machine operation, including but not limited to register state data and the virtual machine's memory page table during virtual machine operation. In some processor architectures, virtual machine state data may be implemented as a VMCS. In other processor architectures, virtual machine state data may be implemented as a processor context, etc.
[0105] In some embodiments, a memory address corresponding to the target virtual machine can be determined based on the identifier of the target virtual machine. This memory address can be a virtual address of the host machine. The memory address corresponding to the target virtual machine stores the state data of the target virtual machine. Accordingly, the state data of the target virtual machine can be read from the memory based on the memory address corresponding to the target virtual machine.
[0106] For example, the state data of the target virtual machine can be stored in a dedicated cache. In this way, when the execution flow of the subsequent processor switches from the host machine to the target virtual machine, the state data of the target virtual machine can be directly read from the dedicated cache, which helps to improve the efficiency of virtual machine switching.
[0107] In the embodiment of the present application, when the state data of the target virtual machine is stored in the dedicated cache, the target cache space may be determined from the dedicated cache, and the state data of the target virtual machine may be written into the target cache space.
[0108] In some embodiments, free cache space may be determined from a dedicated cache as the target cache space.
[0109] In other embodiments, there may be no free cache space in the dedicated cache. Accordingly, the processor 10 may determine the cache space to be replaced from the dedicated cache based on a predetermined cache replacement algorithm, and use this as the target cache space. Of course, the implementation of using the cache replacement algorithm to determine the cache space to be replaced is also applicable to the case where free cache space is stored in the dedicated cache. For a description of the cache replacement algorithm, please refer to the relevant content of the above embodiment and will not be repeated here.
[0110] After the target cache space is determined, the state data of the target virtual machine may be written into the target cache space.
[0111] Because the dedicated cache is a dedicated cache for virtual machine state data, a processor instruction for managing the dedicated cache can be added to the processor, such as the instruction "vmcs_cache_addr idx addr" shown in the above embodiment. Based on the processor instruction for managing the dedicated cache, after determining the target virtual machine to be cached and the target cache space in the dedicated cache, the memory address of the target virtual machine and the identifier of the target cache space can be written into the processor instruction according to the format of the processor instruction for managing the dedicated cache. The processor instruction may include the memory address of the target virtual machine's state data and the identifier of the target cache space.
[0112] In one embodiment, a processor instruction for managing a dedicated cache may be executed, and during execution of the processor instruction, the state data of the target virtual machine may be read from the memory according to the memory address included in the processor instruction. For example, the state data of the target virtual machine may be read from the memory space at the memory address [addr, addr+Y kB].
[0113] In one embodiment, during execution of the processor instructions, the target virtual machine's state data may be written to a cache space in the dedicated cache that corresponds to the identifier of the target cache space. For example, the target virtual machine's state data may be written to the cache space in the dedicated cache that corresponds to the identifier of the target cache space according to a data structure corresponding to the dedicated cache. The data structure corresponding to the dedicated cache may be a VMCS.
[0114] Since the state data of the target virtual machine is stored in the dedicated cache of the processor, when the execution flow of the processor switches from the host machine to the target virtual machine, the state data of the target virtual machine can be read from the dedicated cache, which helps to improve the efficiency of virtual machine switching.
[0115] The following is an illustrative description of the virtual machine switching process provided in the embodiment of the present application. In the embodiment of the present application, the virtual machine switching scenario may include: the execution flow of the processor exits from VM1 and switches to the host machine side where VM1 is located; thereafter, switching back to VM1 from the host machine side. Of course, the virtual machine switching scenario may also include: the execution flow of the processor exits from VM1 and switches to the host machine side where VM1 is located; thereafter, switching from the host machine side to VM2. Whether the execution flow of the processor switches back to VM1 from the host machine side or switches to the new VM2 is specifically determined by the operating system scheduling in the processor.
[0116] The process of switching the processor's execution flow from the host back to the original VM1 or to the new VM2 is the same. In this embodiment of the present application, both the original VM1 and the new VM2 can be defined as target virtual machines. That is, the target virtual machine is the virtual machine to be run on the computing device. The following uses the target virtual machine as an example to illustrate the virtual machine switching process.
[0117] Figure 5 is a flow chart of a virtual machine switching method provided by an embodiment of the present application. As shown in Figure 5, the virtual machine switching method mainly includes steps 501-503.
[0118] 501. In response to a virtual machine scheduling event, obtain state data of a target virtual machine to be run from a dedicated cache of a processor; the dedicated cache is a partial cache of the processor, used to store state data of the virtual machine.
[0119] 502. Switch the execution flow of the processor from the host machine of the target virtual machine to the target virtual machine.
[0120] 503. Run the target virtual machine according to the state data of the target virtual machine.
[0121] In this embodiment, the processor of the host machine includes a dedicated cache dedicated to storing state data of the virtual machine. The implementation form and location of the dedicated cache can be found in the relevant content of the above computing device embodiment, which will not be repeated here.
[0122] Based on the dedicated cache, in step 501 of this embodiment, the state data of the target virtual machine to be run can be obtained from the dedicated cache in response to a virtual machine scheduling event. A virtual machine scheduling event is an event that instructs the processor's execution flow to switch from the host machine to the virtual machine. It can be issued by the operating system running on the processor. The target virtual machine to be run can be determined by the operating system.
[0123] In some embodiments, the target virtual machine to be run can be determined based on a set virtual machine scheduling policy. Exemplarily, the target virtual machine to be run can be determined based on the task priority of the virtual machine. For example, the virtual machine with the highest task priority can be selected from the virtual machines of the computing device as the target virtual machine to be run. Alternatively, the target virtual machine to be run can be determined based on a load balancing policy. The target virtual machine to be run can be any of the virtual machines for which state data has been stored as shown in FIG. 4 .
[0124] After the target virtual machine is determined, a virtual machine scheduling event may be generated, which is used to instruct the execution flow of the processor to switch from the host machine side to the target virtual machine.
[0125] In one embodiment, in response to a virtual machine scheduling event, state data of the target virtual machine to be run can be obtained from a dedicated cache. In one embodiment, in step 502, the execution flow of the processor can be switched from the host machine of the target virtual machine to the target virtual machine. For example, a virtual machine entry instruction (such as vmenter) with the target virtual machine as the virtual machine to be entered can be executed, thereby switching the execution flow of the processor from the host machine to the target virtual machine. Exemplarily, the target virtual machine can be run based on the state data of the target virtual machine.
[0126] In this embodiment, when the processor's execution flow switches from the host machine to the target virtual machine, the target virtual machine's state data can be read from the processor's dedicated cache. Because reading virtual machine state data from the cache is faster than reading virtual machine state data from memory during traditional virtual machine switching, reading state data from the processor's dedicated cache during virtual machine switching helps improve virtual machine switching efficiency.
[0127] On the other hand, a cache dedicated to storing the state data of the virtual machine is set in the processor to prevent the state data of the virtual machine from being overwritten by other data during the execution of the computer program, and to reduce the probability of the processor reading the state data of the virtual machine from the memory.
[0128] In the embodiments of the present application, the execution flow of the processor is not limited to operating on the host side. In some embodiments, the execution flow is in a virtual machine state before the host side. The virtual machine may be the target virtual machine mentioned above, or it may be another virtual machine. The following takes the execution flow of the processor in the first virtual machine before switching to the host as an example to illustrate the process of switching from the virtual machine to the host. The first virtual machine is the target virtual machine to be run mentioned above; or it is a virtual machine other than the target virtual machine to be run.
[0129] In some embodiments, in response to a virtual machine exit event, a first virtual machine in an execution flow of a processor may be exited from the execution flow. For example, in response to the virtual machine exit event, a virtual machine exit instruction (such as a vmexit instruction) may be executed with the first virtual machine as the virtual machine to be exited, thereby exiting the first virtual machine from the execution flow of the processor.
[0130] The virtual machine exit event may be issued by the operating system running on the processor or by another virtual machine. In some embodiments, the operating system in the processor may issue an interrupt request according to a set interrupt cycle. Accordingly, the virtual machine exit event may be implemented as receiving an interrupt request. For example, in response to the interrupt request, the first virtual machine in the execution flow of the processor may be exited from the execution flow.
[0131] In other embodiments, if a first virtual machine shares a logical core with other virtual machines, the other virtual machines sharing the logical core with the first virtual machine may issue an inter-core interrupt request to the first virtual machine. Accordingly, the virtual machine exit event may be implemented as receiving an inter-core interrupt request. For example, in response to the inter-core interrupt request, the first virtual machine in the execution flow of the processor may be exited from the execution flow.
[0132] In one embodiment, state data of the first virtual machine may be obtained, wherein the state data of the first virtual machine is state data when the first virtual machine exits the execution flow, and may include: state data of registers when the first virtual machine exits the execution flow and a memory page table corresponding to the first virtual machine.
[0133] Accordingly, the status data of the host machine's registers and the memory page table corresponding to the first virtual machine can be read when the first virtual machine exits the processor's execution flow; and the status data of the host machine's registers and the memory page table corresponding to the first virtual machine at this time are used as the status data of the first virtual machine.
[0134] For example, the state data of the first virtual machine can be written into the dedicated cache. For the specific implementation of writing the state data of the first virtual machine into the dedicated cache, please refer to the above-mentioned content of writing the state data of the target virtual machine into the dedicated cache, which will not be repeated here.
[0135] In one embodiment, the execution flow can be switched to the host machine of the first virtual machine. Accordingly, the host machine can execute instructions. In this embodiment, the specific content of the instructions executed by the host machine is not limited. In some embodiments, the host machine can detect whether there are instructions to be executed in the host machine process; if so, the host machine process is called to execute the above instructions to be executed. After the host machine executes the above instructions to be executed, the target virtual machine can be determined from the computing device according to the virtual machine scheduling policy. Accordingly, if there are no instructions to be executed in the host machine process, the target virtual machine can be determined from the computing device according to the virtual machine scheduling policy. Regarding the relevant content of determining the target virtual machine from the computing device according to the virtual machine scheduling policy, please refer to the above-mentioned relevant content, which will not be repeated here.
[0136] For example, a virtual machine scheduling event may be generated to switch the execution flow of the processor to the target virtual machine. For the implementation of switching the execution flow to the target virtual machine in response to the virtual machine scheduling event, please refer to the relevant content of the above embodiment, which will not be repeated here.
[0137] The target virtual machine may be the first virtual machine, or may be another virtual machine (defined as a second virtual machine) other than the first virtual machine in the computing device.
[0138] In some embodiments, the target virtual machine is a second virtual machine. Before the state data of the second virtual machine is obtained from the dedicated cache, the state data of the second virtual machine has already been pre-stored in the dedicated cache. Accordingly, before responding to the virtual machine call event, the state data of the second virtual machine can also be read from the memory and written to the dedicated cache. Because the state data of the second virtual machine has already been pre-stored in the dedicated cache before the processor responds to the virtual machine call event, reading the state data of the second virtual machine from the processor's dedicated cache when switching to the second virtual machine helps improve virtual machine switching efficiency.
[0139] In other embodiments, if the state data of the second virtual machine is not read from the dedicated cache, the state data of the second virtual machine may be read from the memory; and based on the state data of the second virtual machine, the execution flow of the processor may be switched to the second virtual machine. For example, the state data of the second virtual machine may be written to the dedicated cache, so that the state data of the second virtual machine can be read directly from the dedicated cache to perform virtual machine switching.
[0140] Among them, regarding the specific implementation method of reading the status data of the second virtual machine from the memory and writing the status data of the second virtual machine into the dedicated cache, please refer to the embodiment of Figure 4 above, and the relevant content of reading the status data of the target virtual machine from the memory and writing the status data of the target virtual machine into the dedicated cache will not be repeated here.
[0141] It should be noted that the execution entity of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution entity of steps 401 and 402 can be device A; for another example, the execution entity of step 401 can be device A, and the execution entity of step 402 can be device B; and so on.
[0142] In addition, some of the processes described in the above embodiments and the accompanying drawings include multiple operations that appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order in which they appear in this document or may be executed in parallel. The sequence numbers of the operations, such as 401 and 402, are merely used to distinguish between different operations and do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel.
[0143] Accordingly, an embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned data storage method and / or virtual machine switching method.
[0144] Figure 6 is a schematic diagram of the structure of a processor provided in an embodiment of the present application. As shown in Figure 6, the processor may include: a control unit 601, a cache 602, and an arithmetic unit 603. The control unit 601, cache 602, and arithmetic unit 603 are electrically connected. For a description of the control unit, cache, and arithmetic unit, please refer to the relevant content of Figure 1 above and will not be repeated here.
[0145] In this embodiment, the cache 602 includes a dedicated cache 602a and a shared cache 602b. For a description of the implementation form and deployment location of the dedicated cache 602a and the shared cache 602b, please refer to the relevant content of FIG. 1 above, which will not be repeated here.
[0146] 6 , when deployed on an electronic device, the dedicated cache 602a is dedicated to storing state data of the virtual machine deployed on the electronic device. The shared cache is used to store other data required by the computer program running on the electronic device in addition to the state data of the virtual machine.
[0147] In this embodiment, the control unit 601 can be coupled to the cache 602 and the computing unit 603, and is used to call and run the computer program in the memory from the memory of the electronic device deployed with the processor, so that the electronic device executes the above-mentioned data storage method and / or the steps in the virtual machine switching method to achieve virtual machine switching acceleration.
[0148] In an embodiment of the present application, a dedicated cache is provided within the processor's cache for caching virtual machine state data. Based on the dedicated cache, when the processor's execution flow switches from the host machine to the target virtual machine, the target virtual machine's state data can be read from the processor's dedicated cache. Because reading virtual machine state data from the cache is faster than reading virtual machine state data from memory during traditional virtual machine switching, reading state data from the processor's dedicated cache during virtual machine switching helps improve virtual machine switching efficiency.
[0149] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0150] In an embodiment of the present application, the memory is used to store computer programs and can be configured to store various other data to support operations on the device where it is located. The processor can execute the computer program stored in the memory to implement the corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random-access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0151] In the embodiments of the present application, the processor may be any hardware processing device that can execute the logic of the above method. For example, the processor may be a central processing unit (CPU), a graphics processing unit (GPU), or a microcontroller unit (MCU); it may also be a programmable device such as a field programmable gate array (FPGA), a programmable array logic device (PAL), a general array logic device (GAL), a complex programmable logic device (CPLD); or an application specific integrated circuit (ASIC) chip; or an advanced reduced instruction set (RISC) processor (Advanced RISC Machines, ARM) or a system on chip (SoC), etc., but is not limited thereto.
[0152] In an embodiment of the present application, the computing device may further include: a communication component. The communication component is configured to facilitate wired or wireless communication between the device in which it is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as Wireless Fidelity (WiFi), 2G or 3G, 4G, 5G or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component can also be implemented based on Near Field Communication (NFC) technology, Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wide Band (UWB) technology, Bluetooth (BT) technology or other technologies.
[0153] In an embodiment of the present application, the computing device may further include: a display component. The display component may include a liquid crystal display (LCD) and a touch panel (TP). If the display component includes a touch panel, the display component may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0154] In embodiments of the present application, a computing device may further include a power supply assembly. The power supply assembly is configured to provide power to various components of the device in which it resides. The power supply assembly may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply assembly resides.
[0155] In an embodiment of the present application, the computing device may further include: an audio component. The audio component may be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), and when the device where the audio component is located is in an operating mode, such as call mode, recording mode, and voice recognition mode, the microphone is configured to receive external audio signals. The received audio signal may be further stored in a memory or sent via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals. For example, for a device with a language interaction function, voice interaction with the user can be achieved through the audio component.
[0156] It should be noted that the descriptions such as "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence, nor do they limit "first" and "second" to different types.
[0157] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, compact disc read-only memory (Compact Disc Read-Only Memory, CD-ROM), optical storage, etc.) that contain computer-usable program code.
[0158] The present application is described with reference to the flow chart and / or block diagram of the method, device (or system) and computer program product according to the embodiment of the present application. It should be understood that each flow process and / or box in the flow chart and / or block diagram and the combination of the flow process and / or box in the flow chart and / or block diagram can be realized by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processing machine or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for realizing the function specified in one flow chart flow or multiple flows and / or one box or multiple boxes of the block diagram.
[0159] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0160] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0161] In a typical configuration, a computing device includes one or more processors (such as a CPU, etc.), input / output interfaces, network interfaces, and memory.
[0162] Memory may include non-permanent storage in a computer-readable medium, random-access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0163] Computer storage media is readable storage media, also known as readable media. Readable storage media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random-access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0164] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, commodity, or apparatus comprising the aforementioned elements.
[0165] The above contents are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A virtual machine switching method, comprising: In response to a virtual machine scheduling event, obtaining state data of a target virtual machine to be run from a dedicated cache of a processor; The dedicated cache is a partial cache of the processor, and is used to store state data of the virtual machine; Switching the execution flow of the processor from the host machine of the target virtual machine to the target virtual machine; The target virtual machine is run according to the state data of the target virtual machine.
2. The method according to claim 1, wherein: Also includes: In response to a virtual machine exit event, exiting a first virtual machine in an execution flow of the processor from the execution flow of the processor; Obtaining status data of the first virtual machine; The state data of the first virtual machine is state data when the first virtual machine exits the execution flow of the processor; Writing the state data of the first virtual machine into the dedicated cache; Switching the execution flow of the processor to the host machine of the first virtual machine so that the host machine can execute instructions; After the host machine executes the instruction, the target virtual machine is determined according to the virtual machine scheduling policy.
3. The method according to claim 2, wherein: The obtaining of the state data of the first virtual machine includes: Reading state data of the register of the host machine and a memory page table of the first virtual machine when the first virtual machine exits the execution flow of the processor; The state data of the register and the memory page table of the first virtual machine are used as the state data of the first virtual machine.
4. The method according to claim 2, wherein: The step of causing the first virtual machine in the execution flow of the processor to exit the execution flow of the processor includes: A virtual machine exit instruction is executed with the first virtual machine as the virtual machine to be exited, so as to cause the first virtual machine to exit the execution flow of the processor.
5. The method according to any one of claims 1 to 4, wherein: The switching the execution flow of the processor from the host machine of the target virtual machine to the target virtual machine includes: A virtual machine entry instruction is executed with the target virtual machine as the virtual machine to be entered, so as to switch the execution flow of the processor from the host machine to the target virtual machine.
6. The method according to any one of claims 1 to 4, wherein: The target virtual machine is the first virtual machine or a second virtual machine in the host machine; Before responding to the virtual machine scheduling event, the method further includes: Reading state data of the second virtual machine from the memory of the host machine; Determining a target cache space from the dedicated cache; The state data of the second virtual machine is written into the target cache space.
7. The method according to claim 6, wherein: The step of determining a target cache space from the dedicated cache comprises: Determining an idle cache space from the dedicated cache as the target cache space; or, According to a set cache replacement algorithm, a cache space to be replaced is determined from the dedicated cache as the target cache space.
8. The method according to claim 6, wherein: The reading the state data of the second virtual machine from the memory of the host machine includes: Execute a processor instruction for managing a dedicated cache; the processor instruction includes: a memory address where the state data of the second virtual machine is located and an identifier of the target cache space; During the execution of the processor instruction, reading the state data of the second virtual machine from the memory according to the memory address; Writing the state data of the second virtual machine into the target cache space includes: During the execution of the processor instruction, the state data of the second virtual machine is written into a cache space in the dedicated cache corresponding to the identifier of the target cache space according to a data structure corresponding to the dedicated cache.
9. A data storage method, wherein a processor of a host machine comprises: Dedicated cache; The dedicated cache is used to store state data of the virtual machine; The method comprises: Determine a target virtual machine to be cached from the host machine; Obtaining state data of the target virtual machine from the memory of the host machine; The state data of the target virtual machine is stored in the dedicated cache, so as to switch the execution flow of the processor to the target virtual machine by using the state data stored in the dedicated cache.
10. A computing device, wherein a virtual machine is deployed on the computing device; The computing device comprises: processor, The processor includes: a control unit, an operation unit and a cache; the computing device also includes: a target memory for storing a computer program; The cache includes: a dedicated cache and a shared cache; the dedicated cache is used to store the state data of the virtual machine; the shared cache is used to execute other data required by the computer program except the state data of the virtual machine; The control unit is coupled to the computing unit, the cache and the target memory, and is used to execute the computer program and write the other data into the shared cache during the execution of the computer program; and perform the steps in the method of any one of claims 1-9 in combination with the other data.
11. The device according to claim 10, wherein: The dedicated cache belongs to the first-level cache of the processor.
12. A processor, comprising: Control unit, computing unit and cache; The cache includes: a dedicated cache and a shared cache; When the processor is deployed on an electronic device, the dedicated cache is used to cache state data of a virtual machine deployed on the electronic device; the shared cache is used to cache other data required by a computer program running on the electronic device except the state data of the virtual machine; The control unit is coupled to the cache and the computing unit, and is used to call and run a computer program stored in the memory of an electronic device equipped with the processor, so that the electronic device executes the steps of the method according to any one of claims 1 to 9.
13. A computer-readable storage medium storing computer instructions, which, when executed by one or more processors, causes the one or more processors to execute the steps of the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for processing field data of virtual machine
CN104035811A
Embedded network virtualization environment VirtIO (virtual input and output) network virtualization working method
CN104618158A
Virtual machine switching and data storage method and device, processor and storage medium
CN116149796A
Method, apparatus and system for optimizing context switching between virtual machines
US20050132363A1
Context switching method, device, program, recording medium, and central processing unit
US20070022428A1
