Virtual machine memory sharing method and system and computer equipment

The write message is parsed with the virtual machine monitor and the bus device to obtain the interrupt number and passed it between the virtual machine, which solves the problems of cumbersome communication and low processing efficiency in the virtual machine memory sharing technology, and realizes efficient memory sharing and interrupt notification.

CN119179551APending Publication Date: 2024-12-24ECARX (HUBEI) TECHCO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411299631.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

The existing virtual machine memory sharing technology has problems such as cumbersome communication process and low processing efficiency, especially when multiple virtual machines collaborate to complete the same task.

Method used

Through the bus devices corresponding to the virtual machine monitor and the virtual machine, the write message is parsed and the interrupt number is obtained and sent to other bus devices to realize interrupt notification and improve the efficiency of memory sharing and message notification.

Benefits of technology

It realizes memory sharing and interrupt notification between virtual machines, improving resource usage efficiency and memory sharing processing speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119179551A_ABST
    Figure CN119179551A_ABST
Patent Text Reader

Abstract

The invention relates to the field of virtual machines, and discloses a virtual machine memory sharing method and system and computer equipment, the method is applied to bus equipment corresponding to a virtual machine in a virtual machine monitor, and the method comprises the following steps: under the condition of receiving a write-in message sent by the corresponding virtual machine, analyzing the write-in message to obtain an interrupt number; the interrupt number is sent to other bus devices, so that the other bus devices determine corresponding interrupt notifications based on the interrupt number, and the interrupt notifications are sent to the corresponding virtual machines for response; wherein the write-in message is a message that a virtual machine corresponding to the bus equipment writes in data based on a shared data address; the shared data address of the virtual machine corresponds to the target physical memory space. By means of the technical scheme, memory sharing and interrupt notification between the virtual machines are achieved, and the resource use efficiency and the memory sharing processing speed are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of virtual machines, and in particular to a virtual machine shared memory method, system and computer equipment. Background Art

[0002] With the continuous development of virtual machine technology, in order to solve the limitation of virtual machine memory space, memory sharing technology has been proposed as a method to solve memory availability, which can effectively eliminate redundant memory. Therefore, the demand for memory data sharing and message notification between virtual machines is real, especially in the deployment environment of virtual machines, when multiple virtual machines work together to complete the same task. However, the current memory sharing technology has the problems of cumbersome communication process and low processing efficiency.

[0003] In view of this, the present invention is proposed. Summary of the invention

[0004] In order to solve the above technical problems, the present invention provides a virtual machine shared memory method, system and computer device, which realize memory sharing and interrupt notification between virtual machines, improve resource utilization efficiency and memory sharing processing speed.

[0005] An embodiment of the present invention provides a virtual machine shared memory method, which is applied to a bus device corresponding to the virtual machine in a virtual machine monitor, and the method includes:

[0006] When receiving a write message sent by the corresponding virtual machine, parsing the write message to obtain an interrupt number;

[0007] Sending the interrupt number to each other bus device, so that the other bus device determines a corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine for response;

[0008] The write message is a message that the virtual machine corresponding to the bus device writes data based on a shared data address; the shared data address of the virtual machine corresponds to the target physical memory space.

[0009] An embodiment of the present invention provides a virtual machine shared memory method for a virtual machine, the method comprising:

[0010] In response to determining that the data to be written is written into the shared data address of the virtual machine, determining an interrupt number based on the data to be written;

[0011] Generate a write message according to the interrupt number, and send the write message to a corresponding bus device in the virtual machine monitor, so that the bus device parses the write message when receiving the write message sent by the corresponding virtual machine, obtains the interrupt number, and sends the interrupt number to each other bus device;

[0012] The shared data address of the virtual machine corresponds to the target physical memory space.

[0013] An embodiment of the present invention provides a virtual machine shared memory system, the system comprising: at least two virtual machines, a virtual machine monitor and a target physical memory space; the virtual machine monitor comprises a bus device corresponding to each virtual machine, each of the bus devices is connected to each other, and the virtual machine is connected to the corresponding bus device; the target physical memory space corresponds to the shared data address of each virtual machine;

[0014] The virtual machine is used to determine an interrupt number based on the data to be written in response to determining that the data to be written is written in the shared data address of the virtual machine; generate a write message according to the interrupt number, and send the write message to the corresponding bus device in the virtual machine monitor;

[0015] The bus device is used to parse the write message sent by the corresponding virtual machine to obtain an interrupt number when receiving the write message; send the interrupt number to each other bus device, so that the other bus device determines the corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine for response.

[0016] An embodiment of the present invention provides a computer device, the computer device comprising:

[0017] Processor and memory;

[0018] The processor is used to execute the steps of the virtual machine shared memory method described in any embodiment by calling the program or instruction stored in the memory.

[0019] The embodiments of the present invention have the following technical effects:

[0020] The bus device corresponding to the virtual machine in the virtual machine monitor parses the write message when receiving the write message sent by the corresponding virtual machine to obtain the interrupt number, so as to determine the relevant information of the shared memory through the virtual machine monitor, and send the interrupt number to each other bus device, so that the other bus devices determine the corresponding interrupt notification based on the interrupt number, and send the interrupt notification to the corresponding virtual machine for response, so as to facilitate message notification when sharing memory, realize memory sharing and interrupt notification between virtual machines, and improve resource utilization efficiency and memory sharing processing speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0022] Figure 1 is a flow chart of a virtual machine shared memory method provided by an embodiment of the present invention;

[0023] Figure 2 is a flow chart of another virtual machine shared memory method provided by an embodiment of the present invention;

[0024] Figure 3 It is a structural diagram of a virtual machine shared memory system provided by an embodiment of the present invention;

[0025] Figure 4 It is a structural schematic diagram of another virtual machine shared memory system provided by an embodiment of the present invention;

[0026] Figure 5 It is a schematic diagram of message transmission of a virtual machine shared memory system provided by an embodiment of the present invention;

[0027] Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.

[0029] The virtual machine shared memory method provided by the embodiment of the present invention is mainly applicable to the case where virtual machines share memory through a virtual machine monitor and perform message notification when sharing memory. The virtual machine shared memory method provided by the embodiment of the present invention can be executed by a computer device.

[0030] Figure 1 is a flow chart of a virtual machine shared memory method provided by an embodiment of the present invention. Figure 1 The virtual machine shared memory method is applied to a bus device corresponding to a virtual machine in a virtual machine monitor, and specifically includes:

[0031] S110. When receiving a write message sent by a corresponding virtual machine, parse the write message to obtain an interrupt number.

[0032] Among them, the virtual machine monitor (hypervisor) can be used to establish and execute the software, firmware or hardware of the virtual machine. The bus device is a PCI (Peripheral Component Interconnect, a standard that defines a local bus) device simulated for the virtual machine, which is used for sharing memory between the virtual machine and the physical memory. The write message is a message that the virtual machine corresponding to the bus device writes data based on the shared data address, which can be information related to the written data. The shared data address of the virtual machine corresponds to the target physical memory space. It can be understood that when data is written to the target physical memory space, that is, the shared memory, via the shared data address of a virtual machine, other virtual machines sharing the target physical memory space can see the data update in the shared memory. The interrupt number is a number used to describe the memory that has changed in the target physical memory space, for example: it can indicate the memory location, data type, etc. The target physical memory space can be a part of the memory space reserved when the virtual machine monitor is started, which cannot be used by the virtual machine monitor, nor can it be used as ordinary memory for the virtual machine.

[0033] Specifically, if the user writes data to the target physical memory space through the shared data address through the virtual machine, a write message will be sent to the bus device corresponding to the virtual machine, so as to generate and send an interrupt notification related to the shared memory through the virtual machine monitor. When the bus device receives the write message sent by the corresponding virtual machine, it can be determined that the corresponding virtual machine has written data to the shared target physical memory space, parse the write message, and obtain the interrupt number in the write message, so as to generate an interrupt notification later.

[0034] S120: Send the interrupt number to each other bus device, so that the other bus device determines the corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine for response.

[0035] The other bus devices are bus devices corresponding to virtual machines that share the target physical memory space with the virtual machine corresponding to the current bus device. The interrupt notification may be a notification of an interrupt mechanism (Message Signaled Interrupts-Extended, MSI-X), which is used to trigger a virtual machine interrupt.

[0036] Specifically, the bus device sends the parsed interrupt number to each other bus device, so that when the other bus device receives the interrupt number, it determines the corresponding interrupt notification according to the interrupt number, and sends the interrupt notification to the virtual machine corresponding to the other bus device, so that the other bus devices that receive the interrupt notification respond to the interrupt notification to complete the sharing of the target physical memory space.

[0037] Based on the above example, the bus device includes a message sending register and a message receiving register. The message sending register is used to send an interrupt number to other bus devices, and the message receiving register is used to receive an interrupt number sent by other bus devices.

[0038] Optionally, when receiving a write message sent by a corresponding virtual machine, the write message may be parsed to obtain an interrupt number; and the interrupt number may be sent to each other bus device in the following manner:

[0039] When receiving a write message sent by a corresponding virtual machine through a message sending register, parsing the write message to determine the number of each virtual machine and the interrupt number;

[0040] The interrupt number is sent to the message receiving registers of other bus devices corresponding to each virtual machine number through the message sending register.

[0041] The virtual machine number is a number used to distinguish different virtual machines, and each virtual machine has a corresponding bus device in the virtual machine monitor.

[0042] Specifically, when a write message sent by a corresponding virtual machine is received through a message sending register, it can be determined that the corresponding virtual machine has written data into the shared target physical memory space, so it is necessary to parse the write message to determine the interrupt number, and the virtual machine numbers of other virtual machines that share the target physical memory space can also be determined. Further, the parsed interrupt number is sent to the message receiving register of other bus devices corresponding to each virtual machine number through the message sending register. It can be understood that the virtual machine number corresponds to the virtual machine one-to-one, and the virtual machine corresponds to the bus device in the virtual machine monitor one-to-one.

[0043] Based on the above example, the bus device can also receive the interrupt number and process it, which can be:

[0044] In response to receiving an interrupt number through a message receiving register, an interrupt notification corresponding to the interrupt number is determined through an interrupt mapping relationship in the message receiving register, and the interrupt notification is sent to a corresponding virtual machine.

[0045] The interrupt mapping relationship is a pre-established mapping relationship between an interrupt number and an interrupt notification.

[0046] Specifically, a bus device can not only send an interrupt number to other bus devices, but also receive an interrupt number sent by other bus devices. Therefore, if the message receiving register of the bus device receives an interrupt number, the interrupt notification corresponding to the interrupt number can be determined according to the interrupt mapping relationship stored in the message receiving register, and then the interrupt notification is sent to the virtual machine corresponding to the bus device, so that the virtual machine can respond after receiving the interrupt notification.

[0047] Based on the above example, the bus device also includes a shared address register, which is used to construct a mapping relationship between the shared data address of the virtual machine corresponding to the bus device and the address of the target physical memory space. Then, when writing data based on the shared data address in the virtual machine, the corresponding bus device can be used to trigger the data writing and write message generation of the virtual machine in the following manner:

[0048] When the bus device is initialized, a mapping relationship between the shared data address of the virtual machine and the address of the target physical memory space is established through the shared address register, so that when the corresponding virtual machine writes the data to be written based on the shared data address, the data to be written is written to the address of the target physical memory space.

[0049] The data to be written is data written into the target physical memory space through the shared data address of the virtual machine.

[0050] Specifically, when the bus device is initialized, the mapping relationship between the address of the target physical memory space corresponding to the corresponding virtual machine shared data address can be determined and established according to the shared address register. When the data to be written is subsequently written by the virtual machine based on the shared data address, the data to be written can be directly written to the target physical memory space, which can be understood as writing the data to be written to the address of the target physical memory space that has a mapping relationship with the shared data address.

[0051] The present invention has the following technical effects: a bus device corresponding to a virtual machine in a virtual machine monitor parses a write message to obtain an interrupt number when receiving a write message sent by the corresponding virtual machine, so as to determine the relevant information of the shared memory through the virtual machine monitor, and sends the interrupt number to each other bus device, so that the other bus devices determine the corresponding interrupt notification based on the interrupt number, and send the interrupt notification to the corresponding virtual machine for response, so as to facilitate message notification when sharing memory, realize memory sharing and interrupt notification between virtual machines, and improve resource utilization efficiency and memory sharing processing speed.

[0052] Figure 2 FIG. 1 is a flowchart of another virtual machine shared memory method provided by an embodiment of the present invention. Figure 2 The virtual machine shared memory method applies a virtual machine, specifically comprising:

[0053] S210 . In response to determining that data to be written is written into a shared data address of the virtual machine, determine an interrupt number based on the data to be written.

[0054] Specifically, when the data to be written is written in the shared data address of the virtual machine, a response can be made, and the part of the target physical memory space affected by the data to be written can be determined according to the data to be written to obtain an interrupt number.

[0055] S220. Generate a write message based on the interrupt number, and send the write message to the corresponding bus device in the virtual machine monitor, so that when the bus device receives the write message sent by the corresponding virtual machine based on the shared data address, it parses the write message, obtains the interrupt number, and sends the interrupt number to each other bus device.

[0056] Specifically, the interrupt number is generated into the write message, and the virtual machine numbers of other virtual machines that share the target physical memory space with the virtual machine may also be generated into the write message. Then, the write message is sent to the bus device corresponding to the virtual machine in the virtual machine monitor, so that the bus device responds and processes when receiving the write message sent by the corresponding virtual machine, that is, parses the write message, obtains the interrupt number, and sends the interrupt number to each other bus device.

[0057] Based on the above example, the virtual machine includes a shared memory channel, and the shared memory channel includes a sending shared register, a receiving shared register, and a data shared register.

[0058] Among them, the shared memory channel has the functions of memory sharing and message passing. The sending shared register is used to generate a write message according to the virtual machine number and interrupt number of each other virtual machine, and send the write message to the corresponding bus device. The sending shared register is also used to obtain the virtual machine number of each other virtual machine and determine the interrupt number based on the data to be written. The receiving shared register is used to receive and store the interrupt notification, that is, to receive the interrupt notification sent by the corresponding bus device and temporarily store it when there is no response to the interrupt notification. The data shared register is used to receive the data to be written through the shared data address of the virtual machine, and write the data to be written into the target physical memory space. The data shared register is also used to obtain the required data from the target physical memory space.

[0059] Based on the above example, in addition to writing data to the target physical memory space, the virtual machine can also obtain data from the target physical memory space for processing and use to complete the service function, which can be:

[0060] When an interrupt notification is received, the to-be-written data corresponding to the interrupt notification is obtained from the target physical memory space based on the shared data address, and the virtual machine storage data is updated based on the to-be-written data.

[0061] The virtual machine storage data is the data obtained by copying the data in the target physical memory space to the virtual machine.

[0062] Specifically, when an interrupt notification is received, a response can be made to the interrupt notification immediately. The data corresponding to the interrupt notification can be determined from the target physical memory space according to the shared data address, that is, the data to be written corresponding to the interrupt notification is generated, the data to be written is obtained, and the data to be written is updated to the virtual machine storage data. The update process can be to overwrite the previous data or to add and write new data.

[0063] Based on the above example, in addition to responding immediately after receiving the interrupt notification, the virtual machine can also respond when executing the target instruction related to the data in the target physical memory space, which can be:

[0064] In the case of executing the target instruction, determining whether there is an interrupt notification corresponding to the target instruction;

[0065] If so, the target data corresponding to the target instruction is obtained from the target physical memory space according to the interrupt notification and the shared data address.

[0066] The target instruction is an instruction executed by the virtual machine, and part or all of the data required by the target instruction is stored in the target physical memory space. The target data is the data corresponding to the target instruction stored in the target physical memory space.

[0067] Specifically, when the virtual machine executes the target instruction, it needs to obtain data related to the target instruction. Therefore, it is necessary to ensure the accuracy of the data and determine whether there is an interrupt notification corresponding to the target instruction. If so, it is necessary to respond to the interrupt notification first, and obtain the data to be written by other virtual machines from the target physical memory space corresponding to the shared data address based on the interrupt notification to ensure the accuracy of the data. Further, analyze the target instruction and obtain the target data from the data to be written so as to execute the target instruction based on the target data. If not, there is no need to respond to the interrupt notification, and the target data corresponding to the target instruction can be directly obtained from the target physical memory space.

[0068] The present invention has the following technical effects: a virtual machine responds to determining that data to be written is written into a shared data address of the virtual machine, and based on the data to be written, an interrupt number is determined, so that when data is written in a shared memory, an interrupt notification is sent to other virtual machines, and then, a write message is generated according to the interrupt number, and the write message is sent to a corresponding bus device in a virtual machine monitor, so that when the bus device receives the write message sent by the corresponding virtual machine, it parses the write message and obtains the interrupt number, and sends the interrupt number to each other bus device, thereby realizing communication involving interrupts between the virtual machine and the virtual machine monitor, simplifying the memory sharing method, and improving the processing speed and response speed.

[0069] Figure 3 Schematic diagram of a virtual machine shared memory system provided by an embodiment of the present invention. Figure 3 The virtual machine shared memory system specifically includes: at least two virtual machines 310, a virtual machine monitor 320 and a target physical memory space 330; the virtual machine monitor 320 includes a bus device 321 corresponding to each virtual machine 310, each of the bus devices 311 is connected to each other, and the virtual machine 310 is connected to the corresponding bus device 321; the target physical memory space 330 corresponds to the shared data address of each virtual machine 310.

[0070] The virtual machine 310 is used to determine an interrupt number based on the data to be written in response to determining that the data to be written is written in the shared data address of the virtual machine 310; generate a write message according to the interrupt number, and send the write message to the corresponding bus device 321 in the virtual machine monitor 320;

[0071] The bus device 321 is used to parse the write message sent by the corresponding virtual machine 310 to obtain the interrupt number when receiving the write message; send the interrupt number to each other bus device 321, so that the other bus device 321 determines the corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine 310 for response.

[0072] Based on the above example, optionally, the bus device 321 includes a message sending register and a message receiving register. The bus device 321 is also used to parse the write message and determine the number of each virtual machine and the interrupt number when a write message sent by the corresponding virtual machine 310 is received through the message sending register; and send the interrupt number to the message receiving register of other bus devices 321 corresponding to each virtual machine number through the message sending register.

[0073] Based on the above example, optionally, the bus device 321 is also used to respond to receiving the interrupt number through the message receiving register, determine the interrupt notification corresponding to the interrupt number through the interrupt mapping relationship in the message receiving register, and send the interrupt notification to the corresponding virtual machine 310.

[0074] Based on the above example, optionally, the bus device 321 also includes a shared address register, which is used to construct a mapping relationship between the shared data address of the virtual machine 310 corresponding to the bus device 321 and the address of the target physical memory space 330. The bus device 321 is also used to establish a mapping relationship between the shared data address of the corresponding virtual machine 310 and the address of the target physical memory space 330 through the shared address register when the bus device 321 is initialized, so that when the corresponding virtual machine 310 writes the data to be written based on the shared data address, the data to be written is written to the address of the target physical memory space 330.

[0075] Based on the above example, optionally, the virtual machine 310 is also used to determine an interrupt number in response to determining that the data to be written is written in the shared data address of the virtual machine 310, based on the data to be written; generate a write message according to the interrupt number, and send the write message to the corresponding bus device 321 in the virtual machine monitor 320, so that the bus device 321, upon receiving the write message sent by the corresponding virtual machine 310, parses the write message, obtains the interrupt number, and sends the interrupt number to each other bus device 321; wherein the shared data address of the virtual machine 310 corresponds to the target physical memory space 330.

[0076] Based on the above example, optionally, the virtual machine 310 includes a shared memory channel, and the shared memory channel includes a sending shared register, a receiving shared register and a data shared register; wherein the sending shared register is used to generate a write message according to the virtual machine number of each other virtual machine 310 and the interrupt number, and send the write message to the corresponding bus device 321; the receiving shared register is used to receive and store interrupt notifications; and the data shared register is used to receive the data to be written through the shared data address of the virtual machine 310.

[0077] Based on the above example, optionally, the virtual machine 310 is also used to obtain the data to be written corresponding to the interrupt notification from the target physical memory space 330 based on the shared data address when an interrupt notification is received, and update the virtual machine storage data based on the data to be written.

[0078] Based on the above example, optionally, the virtual machine 310 is also used to determine whether there is an interrupt notification corresponding to the target instruction when executing the target instruction; if so, obtaining the target data corresponding to the target instruction from the target physical memory space 330 according to the interrupt notification and the shared data address.

[0079] Figure 4 is a schematic diagram of the structure of another virtual machine shared memory system provided by an embodiment of the present invention, Figure 5 This is a schematic diagram of message transmission of a virtual machine shared memory system provided by an embodiment of the present invention. Taking Type 1 (bare metal) hypervisor (virtual machine monitor) as an example, the reserved memory space (target physical memory space) of the hypervisor is used to implement a memory sharing channel between virtual machines. The memory sharing channel provides two functions: one is memory sharing between virtual machines, and the other is a message channel between virtual machines. See Figure 4 and Figure 5 , virtual machine 1 and virtual machine 2 both include user space, user space includes kernel space, kernel space includes shared memory device (shared memory channel), including configuration parameter space and three registers, virtual machine monitor includes bus device corresponding to each virtual machine, bus device includes configuration parameter space and three registers. It is mainly explained in the following three aspects:

[0080] 1. Hypervisor reserves physical memory for shared memory space (target physical memory space)

[0081] This part of the target physical memory space is reserved during the hypervisor startup. The hypervisor itself cannot use it, nor can it be used as normal memory for virtual machines.

[0082] 2. Simulate a virtual shared memory PCI device (bus device) for each virtual machine

[0083] For the bus devices corresponding to the simulated virtual machines, the hypervisor not only simulates the EP (Endpoint) device configuration space of the PCI protocol specification, but also virtualizes three BAR (Base Address Register) spaces. They are:

[0084] BAR0 (message send register) is used to simulate interrupt related registers; BAR1 (message receive register) is used to simulate the support of MSI-X entry table (interrupt mapping relationship); BAR2 (shared address register) will serve as the final storage medium of the RAM type BAR of the virtual bus device.

[0085] Specifically, the hypervisor simulates the configuration space of a standard PCI EP device for a virtual machine with a shared memory device. This space occupies 256 bytes. The device has a device id and a vendor id and supports MSI-X interrupts.

[0086] BAR0 register simulation: BAR0 register is used to store interrupt information (write message) of submitted interrupt, mainly including VM ID (number of each virtual machine) of target virtual machine and interrupt number. Optionally, hypervisor simulates BAR0 as 32-bit memory type BAR, which implements two sub-registers, one is the register with offset 0x08, which is used to store VM ID, used to indicate which virtual machine to send interrupt notification to later, and the other is the register with offset 0x0C, which is used to store interrupt number.

[0087] BAR1 register simulation: The BAR1 register is used to store the MSI-X interrupt information (interrupt mapping relationship) configured by the virtual machine kernel. Optionally, the hypervisor simulates BAR1 as a 32-bit memory type BAR.

[0088] BAR2 register simulation: Optionally, the hypervisor simulates BAR2 as a 64-bit memory type BAR. The BAR2 (data shared register) storage medium of all virtual machines with shared memory devices uses the same physical memory space reserved by the hypervisor (target physical memory space). Therefore, the extended paging mechanism of the hypervisor needs to map the GPA (Guest Physical Address) of BAR2 of the virtual machine with shared memory devices to the HPA (Host Physical Address) of the reserved physical memory space (target physical memory space).

[0089] 3. The process of using shared memory channels inside the virtual machine

[0090] Before a virtual machine reads or writes BAR2 of a shared memory device, because BAR2 of shared memory devices of different virtual machines are mapped to a physical memory address space (target physical memory space), as long as one virtual machine writes to the BAR2 address space of a shared memory device (data to be written), then another virtual machine can immediately read the data in the address space (target physical memory space) through the BAR2 of the shared memory device seen by this virtual machine.

[0091] The virtual machine kernel usually maps the BAR RAM space of the corresponding bus device to the physical memory with no cache attribute, which is to ensure the consistency of the physical memory of the CPU (Central Processing Unit) and the RAM between each virtual machine. If there is a cache, because the shared memory device is essentially a piece of physical memory, its RAM consistency is guaranteed by the SOC (System-on-a-Chip), so the read and write performance of the RAM space (space for shared data addresses) shared by the BAR2 of the shared memory device can reach the read and write performance of the physical memory (target physical memory space). To this end, a kernel module can be implemented inside the virtual machine. The kernel module provides the user with a device node of / dev / shmemx (shared memory directory). After the user opens the device node, he can call mmap (memory mapping) to implement the mapping of the first-level page table of the RAM GPA address space of the shared memory device BAR2. It can be understood that the data in the cache of the target physical memory space written through the shared data address can be automatically written to the physical memory space at a preset time interval, or when any virtual machine executes an interrupt notification, all or part of the data in the cache (the part corresponding to the interrupt notification) can be passively written to the physical memory space.

[0092] Sending process: Map and determine the BAR0 (send shared register) of the virtual machine to write to the shared memory device, and write the VM ID and interrupt number of the target virtual machine into the registers with offsets of 0x08 and 0x0C respectively. Writing these two registers will cause the VM (Virtual Machine) to fall into the hypervisor and write the message sending register. The hypervisor finds the simulated shared memory device (other bus device) of the target virtual machine based on the VM id information (virtual machine number), and determines the MSI-X interrupt based on the interrupt number and the BAR1 (message receiving register) configuration information (interrupt mapping relationship) of the bus device, and injects the corresponding virtual MSI-X interrupt into the virtual machine (receive shared register). Each bit represents an interrupt number, which can be 32 bits, that is, it supports up to 32 interrupt numbers, and each interrupt number can correspond one-to-one with the information of the MSI-X entry table (interrupt mapping relationship) configured in BAR1.

[0093] Receiving process: The receiving process can refer to the standard MSI-X interrupt processing process inside the virtual machine.

[0094] It is understandable that by sharing the target physical memory space with different virtual machines through the hypervisor, different virtual machines can share this part of physical memory, and realize zero-copy sharing of memory data between virtual machines. When a virtual machine writes data to the shared memory (via the shared data address to the target physical memory space), the other virtual machine can immediately see the update of the shared memory data (data in the target physical memory space), eliminating the CPU resources consumed by the shared copy of data. By adding an additional message mechanism to the shared memory, it is possible to send messages between virtual machines in the form of virtual interrupts. A virtual machine can send a virtual interrupt (interrupt notification) to another virtual machine by writing to the register of the shared memory channel (sending a shared register). The virtual machine that receives the interrupt notification enters the interrupt processing flow and parses the detailed interrupt information. The message delay of the above message mechanism is very small, which is at the same order of magnitude as the virtual machine interrupt delay, that is, a few us, which effectively improves the processing efficiency.

[0095] The present invention has the following technical effects: the virtual machine responds to the determination that the shared data address of the virtual machine writes the data to be written, determines the interrupt number based on the data to be written, generates a write message according to the interrupt number, and sends the write message to the corresponding bus device in the virtual machine monitor; the bus device corresponding to the virtual machine in the virtual machine monitor parses the write message and obtains the interrupt number when receiving the write message sent by the corresponding virtual machine, and sends the interrupt number to each other bus device, so that the other bus devices determine the corresponding interrupt notification based on the interrupt number, and send the interrupt notification to the corresponding virtual machine for response, which is convenient for message notification when sharing memory, realizes memory sharing and interrupt notification between virtual machines, and improves resource utilization efficiency and memory sharing processing speed.

[0096] Figure 6 A schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Figure 6 As shown, computer device 400 includes one or more processors 401 and memory 402 .

[0097] The processor 401 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the computer device 400 to perform desired functions.

[0098] The memory 402 may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 401 may run the program instructions to implement the virtual machine shared memory method of any embodiment of the present invention described above and / or other desired functions. Various contents such as initial external parameters, thresholds, etc. may also be stored in the computer-readable storage medium.

[0099] In one example, the computer device 400 may further include: an input device 403 and an output device 404, which are interconnected via a bus system and / or other forms of connection mechanisms (not shown). The input device 403 may include, for example, a keyboard, a mouse, etc. The output device 404 may output various information to the outside, including early warning information, braking force, etc. The output device 404 may include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, etc.

[0100] Of course, to simplify, Figure 6 Only some of the components related to the present invention in the computer device 400 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application conditions, the computer device 400 may also include any other appropriate components.

[0101] In addition to the above methods and devices, an embodiment of the present invention may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the virtual machine shared memory method provided by any embodiment of the present invention.

[0102] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the embodiments of the present invention, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0103] In addition, an embodiment of the present invention may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, enables the processor to execute the steps of the virtual machine shared memory method provided by any embodiment of the present invention.

[0104] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0105] It should be noted that the terms used in the present invention are only for describing specific embodiments, rather than limiting the scope of the present application. As shown in the present specification, unless the context clearly indicates an exception, the words "one", "a", "a kind of" and / or "the" do not specifically refer to the singular, but may also include the plural. The terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method or device. In the absence of further restrictions, the elements defined by the sentence "include one..." do not exclude the presence of other identical elements in the process, method or device including the elements.

[0106] It should also be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. Unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", etc. should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the technical solutions of the embodiments of the present invention.

Claims

1. A virtual machine shared memory method, characterized in that: Applied to a bus device corresponding to a virtual machine in a virtual machine monitor, the method comprises: When receiving a write message sent by the corresponding virtual machine, parsing the write message to obtain an interrupt number; Sending the interrupt number to each other bus device, so that the other bus device determines a corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine for response; The write message is a message that the virtual machine corresponding to the bus device writes data based on a shared data address; the shared data address of the virtual machine corresponds to the target physical memory space.

2. The method according to claim 1, characterized in that The bus device includes a message sending register and a message receiving register, and when receiving a write message sent by a corresponding virtual machine, the write message is parsed to obtain an interrupt number; Send the interrupt number to each other bus device, including: When receiving a write message sent by a corresponding virtual machine through the message sending register, parsing the write message to determine the number of each virtual machine and the interrupt number; The interrupt number is sent to the message receiving registers of other bus devices corresponding to each virtual machine number through the message sending register.

3. The method according to claim 2, characterized in that Also includes: In response to receiving the interrupt number through the message receiving register, an interrupt notification corresponding to the interrupt number is determined through the interrupt mapping relationship in the message receiving register, and the interrupt notification is sent to the corresponding virtual machine.

4. The method according to claim 2, characterized in that: The bus device further includes a shared address register, and the shared address register is used to construct a mapping relationship between a shared data address of a virtual machine corresponding to the bus device and an address of a target physical memory space. The method further includes: When the bus device is initialized, a mapping relationship between the shared data address of the corresponding virtual machine and the address of the target physical memory space is established through the shared address register, so that when the corresponding virtual machine writes the data to be written based on the shared data address, the data to be written is written to the address of the target physical memory space.

5. A virtual machine shared memory method, characterized in that: Applicable to virtual machines, including: In response to determining that the data to be written is written into the shared data address of the virtual machine, determining an interrupt number based on the data to be written; Generate a write message according to the interrupt number, and send the write message to a corresponding bus device in the virtual machine monitor, so that the bus device parses the write message when receiving the write message sent by the corresponding virtual machine, obtains the interrupt number, and sends the interrupt number to each other bus device; The shared data address of the virtual machine corresponds to the target physical memory space.

6. The method according to claim 5, characterized in that The virtual machine includes a shared memory channel, and the shared memory channel includes a sending shared register, a receiving shared register, and a data shared register; Among them, the sending shared register is used to generate a write message according to the virtual machine number of each other virtual machine and the interrupt number, and send the write message to the corresponding bus device; the receiving shared register is used to receive and store interrupt notifications; the data shared register is used to receive the data to be written through the shared data address of the virtual machine, and write it into the target physical memory space.

7. The method according to claim 5, characterized in that Also includes: When an interrupt notification is received, the to-be-written data corresponding to the interrupt notification is obtained from the target physical memory space based on the shared data address, and the virtual machine storage data is updated based on the to-be-written data.

8. The method according to claim 5, characterized in that Also includes: In the case of executing a target instruction, determining whether there is an interrupt notification corresponding to the target instruction; If so, the target data corresponding to the target instruction is obtained from the target physical memory space according to the interrupt notification and the shared data address.

9. A virtual machine shared memory system, characterized in that: include: At least two virtual machines, a virtual machine monitor, and a target physical memory space; The virtual machine monitor includes bus devices corresponding to each virtual machine, each of the bus devices is connected to each other, and the virtual machine is connected to the corresponding bus device; the target physical memory space corresponds to the shared data address of each virtual machine; The virtual machine is used to determine an interrupt number based on the data to be written in response to determining that the data to be written is written in the shared data address of the virtual machine; generate a write message according to the interrupt number, and send the write message to the corresponding bus device in the virtual machine monitor; The bus device is used to parse the write message sent by the corresponding virtual machine to obtain the interrupt number when receiving the write message; The interrupt number is sent to each other bus device, so that the other bus device determines a corresponding interrupt notification based on the interrupt number, and sends the interrupt notification to the corresponding virtual machine for response.

10. A computer device, characterized in that: The computer device comprises: Processor and memory; The processor is used to execute the steps of the virtual machine shared memory method according to any one of claims 1 to 4 or claims 5 to 8 by calling the program or instruction stored in the memory.

Citation Information

Cited By

  • Parameter adjusting method, device and system

    CN119902806A

  • Parameter adjustment method, device and system

    CN119902806B