An apparatus and method for improving virtual device performance
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- KYLIN CORP
- Filing Date
- 2022-08-19
- Publication Date
- 2026-06-23
AI Technical Summary
In existing technologies, QEMU's image update timer takes too long to process large amounts of desktop images, resulting in reduced virtual device response speed and timer malfunction, thus affecting the performance and stability of the virtual device.
An image update module is introduced in QEMU to handle the comparison and copying of desktop images in a separate thread, replacing the image update timer. The main thread only needs to send signals, while the image update module performs the actual operations in parallel.
It improves the response speed of virtual devices and the accuracy of timers, enhances the overall performance and stability of virtual devices, and maintains QEMU compatibility.
Smart Images

Figure CN115357340B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of virtualization technology, and more specifically, to an apparatus and method for improving the performance of virtual devices. Background Technology
[0002] Currently, virtualization technology has become very popular and widely used, and the technology is quite mature, with performance approaching that of physical machines. However, there is still significant room for improvement in device virtualization, and the functionality and performance of some virtual devices still lag considerably behind physical devices. Currently, the Chinese invention patent "A Method and Device for Optimizing Virtual Machine Performance" (patent number: CN111240797A) mainly relies on the NUMA binding relationship of physical machines for optimization, essentially optimizing the virtual machine's operating environment and resource configuration. It fails to delve into the internal implementation of the virtual machine and does not optimize the implementation principles of each virtual device, thus limiting its potential for improvement. The Chinese invention patent "A Method, System, Device, and Storage Medium for Optimizing Multicast Performance in Virtual Machines" (patent number: CN113259142B) focuses only on the multicast portion of the virtual network, failing to optimize other types of virtual machine devices. Its method lacks universality and cannot be applied to the optimization of other virtual devices, let alone improve the overall performance of all virtual devices. The Chinese invention patent "A method for optimizing network performance of KVM" (patent number: CN106789337B) focuses only on optimizing the virtual network part and is deeply tied to Intel VT-d technology. It lacks universality and cannot be applied to other virtual devices.
[0003] Currently, in existing technologies, to improve the performance of virtual devices, it is first necessary to analyze QEMU, the implementer of virtual devices. QEMU is mainly based on a single thread, and its main thread is responsible for cyclically processing various virtual device events and timer events. The core logic can be found in the appendix of the specification. Figure 4 Obviously, with such a design, when the processing timer event takes too long, it will cause the device event to not be processed in a timely manner, thereby affecting the response speed of the virtual device and ultimately leading to a decrease in performance.
[0004] Within QEMU's UI module (responsible for implementing the virtual machine's user interface), there exists a relatively time-consuming timer: the image update timer. It is primarily responsible for periodically updating the desktop image output by the virtual graphics card to the virtual displays such as the SPICE server and VNC server. To describe the function and impact of this timer in more detail, we need to analyze it in conjunction with the virtual machine's image data stream; refer to the appendix of the manual. Figure 3 .
[0005] The typical process of generating, transmitting, and finally displaying a virtual machine's desktop image to the user can be divided into the following steps:
[0006] 1. Applications within the virtual machine (including window managers, user applications, etc.) send image rendering requests to the virtual graphics card driver;
[0007] 2. The virtual graphics card driver integrates rendering requests and forwards them to the virtual graphics card (created by QEMU);
[0008] 3. The virtual graphics card processes each rendering request and generates the final desktop image;
[0009] 4. The QEMU UI module pre-creates an image update timer and uses the timer to periodically forward the desktop image output by the virtual graphics card to virtual displays such as SPICE and VNC servers.
[0010] 5. The SPICE and VNC servers transmit the desktop image to the SPICE and VNC clients respectively via the SPICE and VNC protocols;
[0011] 6. SPICE and VNC clients receive the desktop image and display it to the user.
[0012] Currently, with the increasing resolution of popular monitors, the data volume of the aforementioned desktop images is also growing larger. In step 4, the image update timer needs to continuously compare and copy these large amounts of desktop images. As is well known, large-scale memory comparisons and copies are very time-consuming. Tests have shown that on a Kunpeng server, when the virtual machine resolution is set to 1024×768, the image update timer can take more than 1 millisecond.
[0013] Please refer to the attached instruction manual. Figure 3 Here, we analyze the logic of the QEMU main thread again, and we can see that whenever the image timer starts working, it will cause the following problem (taking an image update timer that takes 1 millisecond as an example):
[0014] 1. This causes device events that have already occurred to be delayed by at least 1 millisecond in processing, which greatly reduces the response speed of each virtual device and causes performance problems.
[0015] 2. This causes other timers that have already timed out to be delayed by at least 1 millisecond, which has two effects: for timers with timeouts of less than 1 millisecond, their timing function is essentially disabled; for timers with timeouts of more than 1 millisecond, their accuracy is greatly reduced. Since the timer module is a core foundational module of QEMU, many critical functions are closely related to it. Therefore, an anomaly in the timer module will inevitably affect the normal operation of related QEMU functions, causing stability and reliability issues. Summary of the Invention
[0016] To overcome the aforementioned deficiencies of the prior art, embodiments of the present invention provide an apparatus and method for improving the performance of virtual devices. This method introduces a new image update module into QEMU to replace the image update timer for comparing and copying desktop images. The image update module operates in a new, independent thread, running in parallel with the main thread, and the two maintain state synchronization through image update signals.
[0017] like Figure 1-4 As shown, to achieve the above objectives, the present invention provides the following technical solution: an apparatus for improving the performance of virtual devices, comprising:
[0018] The virtual machine unit includes a virtual machine, which consists of a built-in application and a virtual graphics card driver. The virtual graphics card driver accepts image rendering requests sent by the application at its input end.
[0019] The host unit includes a host machine, which consists of a built-in virtual graphics card, a UI module, and a virtual display. The virtual graphics card handles image rendering requests integrated by the virtual graphics card driver, and the UI module includes an image update timer.
[0020] The host unit also includes an image update module, which is connected to the virtual display and transmits the desktop image processed by the virtual graphics card to the virtual display.
[0021] The user end consists of a SPICE client and a VNC client, and connects to a virtual monitor to receive the processed desktop image.
[0022] In a preferred embodiment, the applications within the virtual machine include a window manager and user applications.
[0023] In a preferred embodiment, the virtual display is a SPICE server or a VNC server.
[0024] In a preferred embodiment, the image update module periodically forwards the desktop image output by the virtual graphics card to the SPICE and VNC server virtual display.
[0025] In a preferred embodiment, the image update module specifically includes comparing the current output image of the virtual graphics card with the previous frame pixel by pixel and calculating the difference region. The image update module also specifically includes updating the pixel data of the difference region in the output image to the SPICE and VNC servers.
[0026] In a preferred embodiment, the SPICE server and VNC server have built-in SPICE and VNC protocols respectively. The SPICE server communicates with the SPICE client via the SPICE protocol, and the VNC server communicates with the VNC client via the VNC protocol.
[0027] A method for improving the performance of virtual devices includes the following steps:
[0028] S1. The main thread initializes the image update module by creating and initializing it.
[0029] S2, The main thread handles the key events of the virtual device and the rendering requests of the virtual graphics card that have occurred;
[0030] S3. The main thread processes the timeout events of the image update timer and other timers, and then proceeds to step S2.
[0031] In a preferred embodiment, the main thread in step S3 processes the timeout event of the image update timer and sends an image update signal to the image update module.
[0032] In a preferred embodiment, the image update module processes the image update signal as follows:
[0033] (1) The image update module waits for and receives the image update signal;
[0034] (2) The image update module compares the current desktop image output by the virtual graphics card with the previous frame by pixels and calculates the difference area.
[0035] (3) The image update module updates the pixel data of the difference area in the output image to the SPICE and VNC servers, and then proceeds to step (1).
[0036] The key improvements and innovations of this invention are as follows:
[0037] This invention adds an image update module to receive image update signals from the image update timer, reads desktop images from the virtual graphics card for difference comparison, and then updates the differences to each virtual display. At the same time, it also optimizes the image update timer. By introducing a dedicated image update module, after the image update timer times out, it is only necessary to send a simple signal to the image update module, which reduces the load and improves the execution efficiency of the QEMU main thread, thus achieving performance optimization.
[0038] Based on the above-mentioned innovative technical points, the present invention has the following technical effects and advantages:
[0039] 1. Improved the timeliness of device event handling in QEMU, thereby increasing the response speed of various virtual devices and ultimately improving their performance. For example, for virtual graphics cards, this translates to faster execution of rendering commands, smoother visuals, and higher frame rates; for virtual keyboards and mice, it results in more timely key presses and cursor movement, reduced input latency, and a smoother user experience.
[0040] 2. Improved the accuracy of the timer module in QEMU, which in turn improved the stability of other timer-related functional modules in QEMU, and ultimately improved the overall stability and reliability of the virtual machine.
[0041] 3. The critical internal logic of QEMU was not compromised, maintaining good software compatibility; Attached Figure Description
[0042] Figure 1 This is a flowchart illustrating the QEMU main thread and image update module of the present invention.
[0043] Figure 2 This is a schematic diagram of the image data stream of the virtual machine of the present invention.
[0044] Figure 3 This is a flowchart illustrating the main thread of QEMU in this invention.
[0045] Figure 4 This is a flowchart illustrating the traditional QEMU main thread. Detailed Implementation
[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0047] like Figure 1-4As shown, an apparatus for improving the performance of virtual devices includes:
[0048] The virtual machine unit includes a virtual machine, which consists of a built-in application and a virtual graphics card driver. The virtual graphics card driver accepts image rendering requests sent by the application at its input end.
[0049] The host unit includes a host machine, which consists of a built-in virtual graphics card, a UI module, and a virtual display. The virtual graphics card handles image rendering requests integrated by the virtual graphics card driver, and the UI module includes an image update timer.
[0050] The host unit also includes an image update module, which is connected to the virtual display and transmits the desktop image processed by the virtual graphics card to the virtual display.
[0051] The user end consists of a SPICE client and a VNC client, and connects to a virtual monitor to receive the processed desktop image.
[0052] Furthermore, the applications within the virtual machine include a window manager and user applications. The virtual displays are a SPICE server and a VNC server. The image update module periodically forwards the desktop image output by the virtual graphics card to the SPICE and VNC server virtual displays. Specifically, the image update module compares the current output image of the virtual graphics card with the previous frame pixel by pixel, calculates the difference areas, and updates the pixel data of the difference areas in the output image to the SPICE and VNC servers. The SPICE server and VNC server have the SPICE protocol and VNC protocol built-in, respectively. The SPICE server communicates with the SPICE client via the SPICE protocol, and the VNC server communicates with the VNC client via the VNC protocol.
[0053] A method for improving the performance of virtual devices includes the following steps:
[0054] S1. The main thread initializes the image update module by creating and initializing it.
[0055] S2, the main thread handles rendering requests for virtual devices that have already occurred. There are many types of virtual devices, including but not limited to virtual disks, virtual mice, virtual monitors, virtual graphics cards, virtual network cards, etc.
[0056] S3. The main thread processes the timeout events of the image update timer and other timers, and then proceeds to step S2.
[0057] Furthermore, in step S3, the main thread processes the timeout event of the image update timer and sends an image update signal to the image update module.
[0058] Furthermore, the steps for the image update module to process the image update signal are as follows:
[0059] (1) The image update module waits for and receives the image update signal;
[0060] (2) The image update module compares the current desktop image output by the virtual graphics card with the previous frame by pixels and calculates the difference area.
[0061] (3) The image update module updates the pixel data of the difference area in the output image to the SPICE and VNC servers, and then proceeds to step (1).
[0062] This invention introduces a new image update module into QEMU to replace the image update timer for comparing and copying desktop images. The image update module resides in a new, independent thread, running in parallel with the main thread, and the two maintain state synchronization through an image update signal. With this design, when the main thread handles an image update timer timeout event, it no longer needs to perform time-consuming image comparison and copying operations; instead, it simply sends an image update signal to the image update module. Upon receiving the signal, the image update module then begins the image comparison and copying process in place of the image update timer.
[0063] For detailed procedures, please refer to the instruction manual. Figure 1 This method is divided into two parts: the "original main thread" and the "new image update module," which are described separately.
[0064] (I) The original main thread part, the steps are as follows:
[0065] 1. The main thread performs initialization. This includes creating and initializing the image update module;
[0066] 2. The main thread handles device events that have occurred, such as virtual keyboard key presses and virtual graphics card rendering requests;
[0067] 3. The main thread handles the timer event, and then proceeds to step 2. The processing is explained in two scenarios:
[0068] (1) Handling the timeout event of the image update timer: that is, sending the image update signal to the image update module, without having to perform time-consuming image comparison and copying.
[0069] (2) Handle timeout events of other timers;
[0070] (II) The steps for adding an image update module are as follows:
[0071] 1. The image update module waits for and receives the image update signal;
[0072] 2. The image update module compares the current desktop image output by the virtual graphics card with the previous frame pixel by pixel and calculates the difference area;
[0073] 3. The image update module updates the pixel data of the difference areas in the output image to SPICE, VNC server, etc., and then proceeds to step 1.
[0074] After completing the above steps, the workload of the image update timer can be transferred to the image update module, thereby greatly reducing the time consumption of the image update timer, improving the timeliness of device event processing, thereby improving the response speed of the virtual device, and ultimately improving its overall performance.
[0075] At the same time, this method can also improve the accuracy of QEMU timers, thereby improving the stability of other timer-related functional modules in QEMU, and ultimately improving the overall stability and reliability of the virtual machine.
[0076] In summary, the purpose of this invention is to solve the time consumption problem of image update timers in QEMU by providing a new device and method, thereby improving the performance of virtual devices and the accuracy of timer modules, and enhancing the overall stability and reliability of virtual machines.
[0077] Finally, the following points should be noted: First, in the description of this application, it should be noted that, unless otherwise specified and limited, the terms "installation", "connection", and "linkage" should be interpreted broadly, and can be mechanical or electrical connections, or internal connections between two components, or direct connections. "Up", "down", "left", "right", etc. are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may change.
[0078] Secondly: The accompanying drawings of the embodiments disclosed in this invention only involve the structures involved in the embodiments disclosed in this invention. Other structures can refer to the general design. In the absence of conflict, the same embodiment and different embodiments of this invention can be combined with each other.
[0079] In conclusion, the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An apparatus for improving virtual device performance, the apparatus comprising: include: The virtual machine unit includes a virtual machine, which consists of a built-in application and a virtual graphics card driver. The virtual graphics card driver accepts image rendering requests sent by the application at its input end. The host unit includes a host machine, which consists of a built-in virtual graphics card, a UI module, and a virtual display. The virtual graphics card handles image rendering requests integrated by the virtual graphics card driver, and the UI module includes an image update timer. The host unit also includes an image update module, which is connected to the virtual display and transmits the desktop image processed by the virtual graphics card to the virtual display. The user end consists of a SPICE client and a VNC client, and connects to a virtual monitor to receive the processed desktop image; The main thread processes the timeout event of the image update timer and sends an image update signal to the image update module. The image update module waits for and receives the image update signal and performs desktop image comparison and copying in place of the image update timer. The image update module operates in a new independent thread and runs in parallel with the main thread.
2. The apparatus of claim 1, wherein: The applications within the virtual machine include a window manager and user applications.
3. The apparatus of claim 2, wherein: The virtual display is a SPICE server and a VNC server.
4. The apparatus of claim 3, wherein: The image update module periodically forwards the desktop image output by the virtual graphics card to the SPICE and VNC server virtual display.
5. The apparatus of claim 4, wherein: The image update module specifically includes comparing the current output image of the virtual graphics card with the previous frame pixel by pixel, calculating the difference area, and updating the pixel data of the difference area in the output image to the SPICE and VNC servers.
6. The apparatus of claim 5, wherein: The SPICE server and VNC server have built-in SPICE and VNC protocols respectively. The SPICE server communicates with the SPICE client through the SPICE protocol, and the VNC server communicates with the VNC client through the VNC protocol.
7. A method of improving performance of a virtual appliance, the method comprising: Includes the following steps: S1. The main thread initializes, creates and initializes the image update module, which runs in a new independent thread in parallel with the main thread. S2, The main thread handles the key events of the virtual device and the rendering requests of the virtual graphics card that have occurred; S3. The main thread processes the timeout event of the image update timer and the timeout events of other timers. The main thread processes the timeout event of the image update timer and sends an image update signal to the image update module. After completion, it proceeds to step S2. S4. The image update module waits for and receives the image update signal and performs desktop image comparison and copying in place of the image update timer.
8. The method of claim 7, wherein: In step S3, the main thread processes the timeout event of the image update timer and sends an image update signal to the image update module.
9. The method of claim 8, wherein: The steps for the image update module to process the image update signal are as follows: (1) The image update module waits for and receives the image update signal; (2) The image update module compares the current desktop image output by the virtual graphics card with the previous frame by pixels and calculates the difference area; (3) The image update module updates the pixel data of the difference region in the output image to the SPICE, VNC server, and then enters step (1).