Virtual machine clock synchronization method, product, computer equipment and storage medium
By setting up high-precision clock simulation module and virtual device interface in the host kernel, it regularly synchronizes with the high-precision clock source, solving the problem of insufficient clock synchronization accuracy of virtual machine, and improving the stability and user experience of video services.
Patent Information
- Application Number
- CN202411148881.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-20
AI Technical Summary
The insufficient synchronization accuracy of virtual machine clocks leads to black screens for video broadcasts and business lags, affecting the stability and user experience of video services.
在宿主机的内核中设置高精度时钟模拟模块,通过虚拟设备接口供虚拟机访问,并定期与高精度时钟源进行时间同步,确保虚拟机的时间与宿主机时间保持一致,利用硬件时间戳和时钟同步协议调整时钟偏差。
It effectively avoids the video broadcasting black screen and business lag caused by insufficient synchronization accuracy of virtual machine clocks, and improves the stability and user experience of video services.
Smart Images

Figure CN119172572A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of clock synchronization, and in particular to a virtual machine clock synchronization method, product, computer device and storage medium. Background Art
[0002] With the mature deployment of cloud computing in data centers, a large number of services have been migrated to the cloud. However, some services that require extremely high clock accuracy, such as ultra-high-definition 4K video broadcast control, face many challenges in the process of cloud migration. Virtualization technology has deficiencies in clock simulation accuracy, which can easily lead to problems such as black screen during video broadcast and service freezes. These problems seriously affect the stability and user experience of video services. In order to ensure the synchronization, order and stable operation of data transmission, accurate clock and policy configuration have become a security guarantee for video service production. Summary of the invention
[0003] Based on this, a virtual machine clock synchronization method, device, computer equipment and storage medium are provided to solve the problem of insufficient precision of virtual machine clock synchronization in the prior art, which easily leads to black screen of video broadcast and service freeze.
[0004] In one aspect, a virtual machine clock synchronization method is provided, the method comprising:
[0005] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0006] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0007] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0008] In one embodiment, the step of setting a high-precision clock simulation module in the kernel of the host machine, wherein the high-precision clock simulation module sets a virtual device interface for access by the virtual machine comprises:
[0009] Install a network card that supports hardware timestamp function on the host machine;
[0010] Installing and configuring a driver that supports obtaining hardware timestamps in the network card;
[0011] The network card is used as a computing node, a high-precision clock simulation module is set in the network card, a virtual device interface is set in the high-precision clock simulation module, and the high-precision clock simulation module is connected to the virtual machine through the virtual device interface;
[0012] The kernel module of the virtual machine is connected to the high-precision clock simulation module of the host machine through the virtual device interface.
[0013] In one of the embodiments, configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source includes:
[0014] Set up high-precision clock sources including GPS clock or atomic clock;
[0015] Configuring the host machine to periodically synchronize time with the high-precision clock source via a network or time synchronization software;
[0016] When the host machine is synchronized with the high-precision clock source, the system clock of the network card is controlled to synchronize with the high-precision clock source through the hardware timestamp using the precision time protocol service.
[0017] In one embodiment, the controlling the system clock of the network card to use the precision time protocol service to synchronize time with the high-precision clock source through the hardware timestamp includes:
[0018] Implementing hardware timestamps at the driver layer of the network card, and setting the network card to obtain timestamps through hardware acceleration;
[0019] Setting a clock synchronization protocol for calculating a clock deviation between a system clock of the network card and the high-precision clock source;
[0020] The network card and the high-precision clock source exchange and receive messages with timestamps, and determine whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol;
[0021] If the clock deviation exists, the deviation of the system clock of the network card is adjusted according to the clock deviation.
[0022] In one embodiment, the network card and the high-precision clock source interactively send and receive messages with timestamps, and determining whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol includes:
[0023] The high-precision clock source sends a time synchronization message to the network card, and records the timestamp T1 of sending the time synchronization message;
[0024] When the network card receives the time synchronization message, it records the timestamp T2 of receiving the time synchronization message;
[0025] When the network card receives the time synchronization message, it generates a response message and sends it back to the high-precision clock source, and records the timestamp T3 of sending the response message;
[0026] When the high-precision clock source receives the response message, it records the timestamp T4 of receiving the response message;
[0027] The total round-trip delay between the network card and the high-precision clock source is obtained as (T4-T1)-(T3-T2);
[0028] In the clock synchronization protocol, it is assumed that the delays in both directions of sending and receiving messages between the network card and the high-precision clock source are the same, and the one-way delay is obtained by dividing the total round-trip delay by two;
[0029] Obtaining a time deviation ΔT from the network card to the high-precision clock source according to the one-way delay = (T2-T1)-[(T4-T1)-(T3-T2)] / 2;
[0030] When the time deviation ΔT is not zero, determining that there is a clock deviation between the high-precision clock source and the system clock of the network card;
[0031] When ΔT<0, it is determined that the system clock of the network card is earlier than the clock time of the high-precision clock source, and the system clock time of the network card is slowed down by ΔT;
[0032] When ΔT>0, it is determined that the system clock of the network card is later than the clock time of the high-precision clock source, and the system clock time of the network card is adjusted forward by ΔT.
[0033] In one embodiment, the virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine, including:
[0034] The virtual machine is arranged in a client, wherein the client includes a kernel state space and a user state space, wherein a kernel module is arranged in the kernel state space, and a clock device is arranged in the user state space;
[0035] Setting the virtual machine to periodically synchronize time with the high-precision clock simulation module of the host machine;
[0036] In the user state space, when the time synchronization service calls the clock device by setting a hardware clock command, the kernel module calls a hypercall to route to the high-precision clock simulation module of the host machine, requesting to obtain the wall time / counter cycle of the host machine;
[0037] The high-precision clock simulation module super call service responds to the corresponding request and sends the current time data back to the client;
[0038] The current time data is copied to the clock device in the user space in the client.
[0039] In one of the embodiments, the virtual machine clock synchronization method further includes:
[0040] A plurality of virtual machines are connected to a host machine, the plurality of virtual machines form a virtualization cluster, and the host machine constitutes a computing node of the virtualization cluster;
[0041] Setting a scheduler module to collect and monitor the clock deviation of each computing node in the virtualized cluster;
[0042] Using a scheduling algorithm to evaluate clock deviation, the virtual machines corresponding to the computing nodes whose clock deviation exceeds a preset threshold are removed from the virtualization cluster;
[0043] The computing nodes removed from the virtualization cluster are adjusted for clock synchronization until the deviation is reduced to less than the preset threshold, and the virtual machines corresponding to the adjusted computing nodes are re-added to the fault domain of the virtualization cluster. The virtual machines in the fault domain are allowed to perform high availability (HA) and migration operations.
[0044] In another aspect, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0045] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0046] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0047] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0048] In another aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following steps are implemented:
[0049] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0050] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0051] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0052] In another aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0053] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0054] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0055] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0056] The above-mentioned virtual machine clock synchronization method, product, computer equipment and storage medium, by setting a high-precision clock simulation module in the kernel of the host machine, the high-precision clock simulation module sets a virtual device interface for virtual machine access, the high-precision clock simulation module regularly synchronizes time with a high-precision clock source, and the virtual machine regularly obtains current time data from the high-precision clock simulation module through the virtual device interface for time synchronization, so that the time of the virtual machine is consistent with the time of the host machine, avoiding the problem of black screen of video broadcasting and service jamming due to insufficient accuracy of virtual machine clock synchronization, and improving the stability of video services and user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0058] Figure 1 This is an application environment diagram of a virtual machine clock synchronization method in one embodiment of the present application;
[0059] Figure 2A schematic diagram of the structure of the connection between a virtual machine, a host machine and a high-precision clock source for implementing a virtual machine clock synchronization method in one embodiment of the present application;
[0060] Figure 3 A flowchart of a virtual machine clock synchronization method in one embodiment of the present application;
[0061] Figure 4 A flowchart showing steps of setting a high-precision clock simulation module in a kernel of a host machine and setting a virtual device interface for access by a virtual machine in the high-precision clock simulation module in one embodiment of the present application;
[0062] Figure 5 A flowchart of the steps of configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source in one embodiment of the present application;
[0063] Figure 6 A flowchart showing the steps of periodically obtaining the current time data from the high-precision clock simulation module of the host machine through the virtual device interface and copying the current time data of the high-precision clock simulation module to the clock device of the virtual machine in one embodiment of the present application;
[0064] Figure 7 A schematic diagram of a structure in which a scheduler module is set to manage a virtualized cluster in one embodiment of the present application;
[0065] Figure 8 This is a structural block diagram of a virtual machine clock synchronization device in one embodiment of the present application;
[0066] Fig. 9 This is a diagram of the internal structure of a computer device in one embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0068] The virtual machine clock synchronization method provided in this application can be applied to Figure 1 In the application environment shown. The client communicates with the host through the network. The client is a terminal, including a kernel state space and a user state space, wherein the kernel state space is provided with a kernel module, and the user state space is provided with a clock device. The client can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices, and the host can be implemented with an independent server or a server cluster consisting of multiple servers.
[0069] like Figure 2 As shown, Figure 2 The client in the process calls a virtual machine, a high-precision clock simulation module is set in the kernel of the host machine, the high-precision clock simulation module sets a virtual device interface for the virtual machine to access, the client calls the virtual machine, the kernel module calls a hypercall (hypercall) to route to the high-precision clock simulation module of the host machine, the host machine regularly synchronizes time with the high-precision clock source through the network or time synchronization software, and the high-precision clock source includes a GPS clock or an atomic clock.
[0070] In one embodiment, Figure 3 As shown, a virtual machine clock synchronization method is provided, comprising the following steps:
[0071] Step S1, setting a high-precision clock simulation module in the kernel of the host machine, wherein the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0072] Step S2, configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0073] Step S3, the virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0074] Among them, a high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine. The high-precision clock simulation module periodically synchronizes time with the high-precision clock source, and the virtual machine periodically obtains current time data from the high-precision clock simulation module through the virtual device interface for time synchronization, so that the time of the virtual machine is consistent with the time of the host machine, avoiding the problem of black screen of video broadcasting and service jamming due to insufficient accuracy of virtual machine clock synchronization, and improving the stability of video services and user experience.
[0075] like Figure 4 As shown, in this embodiment, the high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for the virtual machine to access, including:
[0076] Step S11, installing a network card supporting hardware timestamp function on the host machine;
[0077] Step S12, installing and configuring a driver that supports obtaining a hardware timestamp in the network card;
[0078] Step S13, using the network card as a computing node, setting a high-precision clock simulation module in the network card, setting a virtual device interface for the high-precision clock simulation module, and connecting the high-precision clock simulation module to the virtual machine through the virtual device interface;
[0079] Step S14, setting the kernel module of the virtual machine to be connected to the high-precision clock simulation module of the host machine through the virtual device interface.
[0080] This embodiment sets a high-precision clock simulation module in the network card, the network card supports timestamps, and the high-precision clock simulation module is connected to the virtual machine. By designing a clock synchronization protocol, using the network card hardware to obtain high-precision timestamps, designing a kernel module to simulate clock devices, and realizing the synchronization of computing nodes with high-precision clocks, high-precision clock synchronization between virtual machines and computing nodes is ensured. This embodiment is suitable for business scenarios with strict requirements on time accuracy, such as video playback control, financial transaction systems, etc.
[0081] Among them, virtual device interface: the virtual machine uses the virtual device interface to access and synchronize the analog clock device provided by the host machine to efficiently obtain high-precision time information.
[0082] like Figure 5 As shown, in this embodiment, configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source includes:
[0083] Step S21, setting a high-precision clock source including a GPS clock or an atomic clock;
[0084] Step S22, configuring the host machine to periodically synchronize time with the high-precision clock source via a network or time synchronization software;
[0085] Step S23, when the host machine is time-synchronized with the high-precision clock source, the system clock of the network card is controlled to use the precision time protocol service to perform time synchronization with the high-precision clock source through the hardware timestamp.
[0086] Among them, simulated clock device driver: load a simulated clock device driver in the host kernel to enable it to simulate a high-precision clock device. The kernel module must not only synchronize with the high-precision clock source through the network, but also calculate the deviation based on the hardware timestamp and adjust the host's own operating system clock deviation. In this way, the virtual machine can accurately lock the system clock later.
[0087] Among them, high-precision clock source synchronization: computing nodes connect to high-precision clock sources (such as GPS clocks, atomic clocks) through the Precision Time Protocol (PTP protocol) service, and synchronize regularly to maintain high-precision clocks.
[0088] In this embodiment, the controlling the system clock of the network card to use the precision time protocol service to synchronize time with the high-precision clock source through the hardware timestamp includes:
[0089] Implementing hardware timestamps at the driver layer of the network card, and setting the network card to obtain timestamps through hardware acceleration;
[0090] Setting a clock synchronization protocol for calculating a clock deviation between a system clock of the network card and the high-precision clock source;
[0091] The network card and the high-precision clock source exchange and receive messages with timestamps, and determine whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol;
[0092] If the clock deviation exists, the deviation of the system clock of the network card is adjusted according to the clock deviation.
[0093] This embodiment calculates the clock deviation between the system clock of the network card and the high-precision clock source through a preset clock synchronization protocol, and adjusts the deviation of the system clock of the network card according to the calculation result.
[0094] In this embodiment, the network card and the high-precision clock source interactively send and receive messages with timestamps, and judging whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol includes:
[0095] The high-precision clock source sends a time synchronization message to the network card, and records the timestamp T1 of sending the time synchronization message;
[0096] When the network card receives the time synchronization message, it records the timestamp T2 of receiving the time synchronization message;
[0097] When the network card receives the time synchronization message, it generates a response message and sends it back to the high-precision clock source, and records the timestamp T3 of sending the response message;
[0098] When the high-precision clock source receives the response message, it records the timestamp T4 of receiving the response message;
[0099] The total round-trip delay between the network card and the high-precision clock source is obtained as (T4-T1)-(T3-T2);
[0100] In the clock synchronization protocol, it is assumed that the delays in both directions of sending and receiving messages between the network card and the high-precision clock source are the same, and the one-way delay is obtained by dividing the total round-trip delay by two;
[0101] Obtaining a time deviation ΔT from the network card to the high-precision clock source according to the one-way delay = (T2-T1)-[(T4-T1)-(T3-T2)] / 2;
[0102] When the time deviation ΔT is not zero, determining that there is a clock deviation between the high-precision clock source and the system clock of the network card;
[0103] When ΔT<0, it is determined that the system clock of the network card is earlier than the clock time of the high-precision clock source, and the system clock time of the network card is slowed down by ΔT;
[0104] When ΔT>0, it is determined that the system clock of the network card is later than the clock time of the high-precision clock source, and the system clock time of the network card is adjusted forward by ΔT.
[0105] The network card is a slave device, the high-precision clock source is a master device, and the slave device adjusts the local time according to the calculated time deviation to synchronize it with the master device. The specific adjustment method can be direct time correction or gradual adjustment to avoid the impact of time jumps on the system.
[0106] like Figure 6 As shown, in this embodiment, the virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine, including:
[0107] Step S31, setting the virtual machine in a client, the client including a kernel state space and a user state space, the kernel state space being provided with a kernel module, and the user state space being provided with a clock device;
[0108] Step S32, setting the virtual machine to periodically synchronize time with the high-precision clock simulation module of the host machine;
[0109] Step S33, in the user state space, when the time synchronization service calls the clock device by setting a hardware clock command, the kernel module calls a hypercall to route to the high-precision clock simulation module of the host machine, requesting to obtain the wall time / counter cycle of the host machine;
[0110] Step S34, the high-precision clock simulation module super call service responds to the corresponding request and sends the current time data back to the client;
[0111] Step S35, in the client, copy the current time data to the clock device in the user state space.
[0112] The hardware clock command is / dev / clock. The method of synchronizing time to the virtual machine is: the synchronized high-precision time is transmitted to the virtual machine through the analog clock device / dev / clock, and the performance overhead of synchronizing the PTP timestamp through the hypercall is very low, ensuring the high precision of the virtual machine time. The hypercall method improves the performance, accuracy and stability of clock synchronization in the virtualization cluster. The dynamic scheduling algorithm optimizes the utilization and response speed of computing resources.
[0113] like Figure 7 As shown, in this embodiment, the virtual machine clock synchronization method also includes:
[0114] A plurality of virtual machines are connected to a host machine, the plurality of virtual machines form a virtualization cluster, and the host machine constitutes a computing node of the virtualization cluster;
[0115] Setting a scheduler module to collect and monitor the clock deviation of each computing node in the virtualized cluster;
[0116] Using a scheduling algorithm to evaluate clock deviation, the virtual machines corresponding to the computing nodes whose clock deviation exceeds a preset threshold are removed from the virtualization cluster;
[0117] The computing nodes removed from the virtualization cluster are adjusted for clock synchronization until the deviation is reduced to less than the preset threshold, and the virtual machines corresponding to the adjusted computing nodes are re-added to the fault domain of the virtualization cluster. The virtual machines in the fault domain are allowed to perform high availability (HA) and migration operations.
[0118] Among them, the fast synchronization mechanism: during virtual machine high availability (HA) and migration operations, the clock can be quickly locked and synchronized. There is no need to interact with PTP multicast messages to synchronize timestamps, which greatly improves efficiency to ensure uninterrupted business and seamless switching.
[0119] Among them, in order to ensure that the virtual machines in the virtualization cluster can have an efficient and stable PTP clock, a scheduler module is set up to maintain the PTP clock deviation of all computing nodes in the virtualization cluster, and a scheduling algorithm is designed to remove nodes with large clock deviations. After the clock deviation is reduced to meet the threshold, it is added back to the fault domain that can be migrated and HA.
[0120] like Figure 3 As shown, in this embodiment, the virtual machine clock synchronization method also includes:
[0121] Step S4: Before the virtual machine and the host machine perform data migration, the virtual machine and the host machine perform clock locking and synchronization, so that the time of the virtual machine and the host machine remains consistent during the data migration process.
[0122] This embodiment can ensure that the time of the virtual machine and the host machine is consistent during the data migration process by locking and synchronizing the clocks before the virtual machine and the host machine perform data migration, thereby avoiding the problem of black screen of video broadcast and service lag caused by insufficient accuracy of virtual machine clock synchronization, and improving the stability of video services and user experience.
[0123] In this embodiment, the virtual machine clock synchronization method further includes:
[0124] After the high-precision clock simulation module of the host machine is synchronized with the high-precision clock source, the time of the high-precision clock simulation module is synchronized to the clock device of the virtual machine within a first time period;
[0125] Monitor the time synchronization between the virtual machine and the host machine, and when the time synchronization of the high-precision clock simulation module to the clock device of the virtual machine is not completed within the first time period, and data migration is required between the virtual machine and the host machine, control the time synchronization of the high-precision clock simulation module to the clock device of the virtual machine before data migration between the virtual machine and the host machine.
[0126] This embodiment enhances the reliability and fault tolerance of the virtualization environment by synchronizing the time of the high-precision clock simulation module to the clock device of the virtual machine within the first time period before the virtual machine and the host machine perform data migration to ensure that its time accuracy does not drift over time.
[0127] In the above-mentioned virtual machine clock synchronization method, a high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine. The high-precision clock simulation module periodically synchronizes time with the high-precision clock source, and the virtual machine periodically obtains current time data from the high-precision clock simulation module through the virtual device interface for time synchronization, so that the time of the virtual machine is consistent with the time of the host machine, avoiding the problem of black screen of video broadcasting and service jamming due to insufficient accuracy of virtual machine clock synchronization, and improving the stability of video services and user experience.
[0128] Compared with the prior art, the technical effects of this application are:
[0129] First, PTP clock synchronization through hyercall has very high performance and stability. Compared with the traditional PTP message interaction method, it needs to receive multicast messages and go through a series of processes such as multiple protocol interactions, calculations, and adjustments. It has poor stability and is not suitable for use in virtualized environments.
[0130] Second, by locking the virtualized cluster, all clocks in the cluster are locked to the external PTP clock in advance. In this way, in cloud computing and virtualization scenarios, the HA and migration of virtual machines are not affected in any way. Compared with the traditional PTP multicast message interaction method, after migration, it is also necessary to update the external switch multicast forwarding table and other protocol interaction processes. The process is time-consuming and PTP locking cannot be performed quickly.
[0131] Third, a virtualization cluster scheduler is designed to maintain the clock deviation of all computing nodes in the cluster. For nodes that do not meet the clock deviation threshold, such as host restart, excessive load pressure, cluster high temperature alarm, network card hardware timestamp failure to work properly, etc., the health status is set to sub-healthy, HA and migration fault domains are removed, and the node clock is rejoined after it meets the requirements, further enhancing the PTP stability of the virtualized cluster virtual machines.
[0132] In one embodiment, Figure 8 As shown, a virtual machine clock synchronization device 10 is provided, comprising: a host machine setting module 1, a host machine time synchronization module 2, and a virtual machine time synchronization module 3.
[0133] The host machine setting module 1 is used to set a high-precision clock simulation module in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine.
[0134] The host machine time synchronization module 2 is used to configure the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source.
[0135] The virtual machine time synchronization module 3 is used for the virtual machine to periodically obtain current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copy the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0136] In this embodiment, the high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for the virtual machine to access, including:
[0137] Install a network card that supports hardware timestamp function on the host machine;
[0138] Installing and configuring a driver that supports obtaining hardware timestamps in the network card;
[0139] The network card is used as a computing node, a high-precision clock simulation module is set in the network card, a virtual device interface is set in the high-precision clock simulation module, and the high-precision clock simulation module is connected to the virtual machine through the virtual device interface;
[0140] The kernel module of the virtual machine is connected to the high-precision clock simulation module of the host machine through the virtual device interface.
[0141] In this embodiment, configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source includes:
[0142] Set up high-precision clock sources including GPS clock or atomic clock;
[0143] Configuring the host machine to periodically synchronize time with the high-precision clock source via a network or time synchronization software;
[0144] When the host machine is synchronized with the high-precision clock source, the system clock of the network card is controlled to synchronize with the high-precision clock source through the hardware timestamp using the precision time protocol service.
[0145] In this embodiment, the controlling the system clock of the network card to use the precision time protocol service to synchronize time with the high-precision clock source through the hardware timestamp includes:
[0146] Implementing hardware timestamps at the driver layer of the network card, and setting the network card to obtain timestamps through hardware acceleration;
[0147] Setting a clock synchronization protocol for calculating a clock deviation between a system clock of the network card and the high-precision clock source;
[0148] The network card and the high-precision clock source exchange and receive messages with timestamps, and determine whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol;
[0149] If the clock deviation exists, the deviation of the system clock of the network card is adjusted according to the clock deviation.
[0150] In this embodiment, the network card and the high-precision clock source interactively send and receive messages with timestamps, and judging whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol includes:
[0151] The high-precision clock source sends a time synchronization message to the network card, and records the timestamp T1 of sending the time synchronization message;
[0152] When the network card receives the time synchronization message, it records the timestamp T2 of receiving the time synchronization message;
[0153] When the network card receives the time synchronization message, it generates a response message and sends it back to the high-precision clock source, and records the timestamp T3 of sending the response message;
[0154] When the high-precision clock source receives the response message, it records the timestamp T4 of receiving the response message;
[0155] The total round-trip delay between the network card and the high-precision clock source is obtained as (T4-T1)-(T3-T2);
[0156] In the clock synchronization protocol, it is assumed that the delays in both directions of sending and receiving messages between the network card and the high-precision clock source are the same, and the one-way delay is obtained by dividing the total round-trip delay by two;
[0157] Obtaining a time deviation ΔT from the network card to the high-precision clock source according to the one-way delay = (T2-T1)-[(T4-T1)-(T3-T2)] / 2;
[0158] When the time deviation ΔT is not zero, determining that there is a clock deviation between the high-precision clock source and the system clock of the network card;
[0159] When ΔT<0, it is determined that the system clock of the network card is earlier than the clock time of the high-precision clock source, and the system clock time of the network card is slowed down by ΔT;
[0160] When ΔT>0, it is determined that the system clock of the network card is later than the clock time of the high-precision clock source, and the system clock time of the network card is adjusted forward by ΔT.
[0161] In this embodiment, the virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine, including:
[0162] The virtual machine is arranged in a client, wherein the client includes a kernel state space and a user state space, wherein a kernel module is arranged in the kernel state space, and a clock device is arranged in the user state space;
[0163] Setting the virtual machine to periodically synchronize time with the high-precision clock simulation module of the host machine;
[0164] In the user state space, when the time synchronization service calls the clock device by setting a hardware clock command, the kernel module calls a hypercall to route to the high-precision clock simulation module of the host machine, requesting to obtain the wall time / counter cycle of the host machine;
[0165] The high-precision clock simulation module super call service responds to the corresponding request and sends the current time data back to the client;
[0166] The current time data is copied to the clock device in the user space in the client.
[0167] In this embodiment, if Figure 8 As shown, the virtual machine clock synchronization device 10 also includes a virtualization cluster management module 4 .
[0168] The virtualization cluster management module 4 is used to: set up a host machine to connect multiple virtual machines, the multiple virtual machines form a virtualization cluster, and the host machine constitutes a computing node of the virtualization cluster; set a scheduler module to collect and monitor the clock deviation of each computing node in the virtualization cluster; use a scheduling algorithm to evaluate the clock deviation, and remove the virtual machines corresponding to the computing nodes whose clock deviation exceeds a preset threshold from the virtualization cluster; adjust the clock synchronization of the computing nodes removed from the virtualization cluster until the deviation is reduced to less than the preset threshold, and then re-add the virtual machines corresponding to the adjusted computing nodes to the fault domain of the virtualization cluster, and the virtual machines in the fault domain are allowed to perform high availability (HA) and migration operations.
[0169] In this embodiment, if Figure 8 As shown, the virtual machine clock synchronization device 10 also includes a data migration management module 5 .
[0170] The data migration management module 5 is used to: before the virtual machine and the host machine perform data migration, the virtual machine and the host machine perform clock locking and synchronization, so that the time of the virtual machine and the host machine remains consistent during the data migration process.
[0171] In this embodiment, the data migration management module 5 is also used to: synchronize the time of the high-precision clock simulation module to the clock device of the virtual machine within a first time period after the high-precision clock simulation module of the host machine is synchronized with the high-precision clock source; monitor the time synchronization between the virtual machine and the host machine, and when the time synchronization of the high-precision clock simulation module to the clock device of the virtual machine is not completed within the first time period, and data migration is required between the virtual machine and the host machine, control the time of the high-precision clock simulation module to be synchronized to the clock device of the virtual machine before data migration is performed between the virtual machine and the host machine.
[0172] In the above-mentioned virtual machine clock synchronization device, a high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine. The high-precision clock simulation module periodically synchronizes time with the high-precision clock source, and the virtual machine periodically obtains the current time data from the high-precision clock simulation module through the virtual device interface for time synchronization, so that the time of the virtual machine is consistent with the time of the host machine, avoiding the problem of black screen of video broadcasting and service jamming due to insufficient accuracy of virtual machine clock synchronization, and improving the stability of video services and user experience.
[0173] For the specific definition of the virtual machine clock synchronization device, please refer to the definition of the virtual machine clock synchronization method above, which will not be repeated here. Each module in the above virtual machine clock synchronization device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0174] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store virtual machine clock synchronization data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a virtual machine clock synchronization method is implemented.
[0175] Those skilled in the art will understand that Fig. 9The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0176] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0177] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0178] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0179] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0180] For specific limitations on the steps implemented when the computer program is executed by the processor, please refer to the limitations on the method for synchronizing the virtual machine clock above, which will not be repeated here.
[0181] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0182] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0183] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0184] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0185] For specific limitations on the steps implemented when the processor executes the computer program, please refer to the limitations on the method for synchronizing the virtual machine clock in the above text, which will not be repeated here.
[0186] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0187] A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine;
[0188] Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source;
[0189] The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
[0190] For specific limitations on the steps implemented when the computer program is executed by the processor, please refer to the limitations on the method for synchronizing the virtual machine clock above, which will not be repeated here.
[0191] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0192] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0193] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A virtual machine clock synchronization method, characterized in that: The virtual machine clock synchronization method comprises: A high-precision clock simulation module is set in the kernel of the host machine, and the high-precision clock simulation module sets a virtual device interface for access by the virtual machine; Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source; The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
2. The virtual machine clock synchronization method according to claim 1, characterized in that: The step of setting a high-precision clock simulation module in the kernel of the host machine, wherein the high-precision clock simulation module sets a virtual device interface for access by the virtual machine comprises: Install a network card that supports hardware timestamp function on the host machine; Installing and configuring a driver that supports obtaining hardware timestamps in the network card; The network card is used as a computing node, a high-precision clock simulation module is set in the network card, a virtual device interface is set in the high-precision clock simulation module, and the high-precision clock simulation module is connected to the virtual machine through the virtual device interface; The kernel module of the virtual machine is connected to the high-precision clock simulation module of the host machine through the virtual device interface.
3. The virtual machine clock synchronization method according to claim 2, characterized in that: Configuring the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source comprises: Set up high-precision clock sources including GPS clock or atomic clock; Configuring the host machine to periodically synchronize time with the high-precision clock source via a network or time synchronization software; When the host machine is synchronized with the high-precision clock source, the system clock of the network card is controlled to synchronize with the high-precision clock source through the hardware timestamp using the precision time protocol service.
4. The virtual machine clock synchronization method according to claim 3, characterized in that: The controlling the system clock of the network card to use the precision time protocol service to synchronize time with the high-precision clock source through the hardware timestamp includes: Implementing hardware timestamps at the driver layer of the network card, and setting the network card to obtain timestamps through hardware acceleration; Setting a clock synchronization protocol for calculating a clock deviation between a system clock of the network card and the high-precision clock source; The network card and the high-precision clock source exchange and receive messages with timestamps, and determine whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol; If the clock deviation exists, the deviation of the system clock of the network card is adjusted according to the clock deviation.
5. The virtual machine clock synchronization method according to claim 4, characterized in that: The network card and the high-precision clock source interactively send and receive messages with timestamps, and judging whether there is a clock deviation between the high-precision clock source and the system clock of the network card through the clock synchronization protocol includes: The high-precision clock source sends a time synchronization message to the network card, and records the timestamp T1 of sending the time synchronization message; When the network card receives the time synchronization message, it records the timestamp T2 of receiving the time synchronization message; When the network card receives the time synchronization message, it generates a response message and sends it back to the high-precision clock source, and records the timestamp T3 of sending the response message; When the high-precision clock source receives the response message, it records the timestamp T4 of receiving the response message; The total round-trip delay between the network card and the high-precision clock source is obtained as (T4-T1)-(T3-T2); In the clock synchronization protocol, it is assumed that the delays in both directions of sending and receiving messages between the network card and the high-precision clock source are the same, and the one-way delay is obtained by dividing the total round-trip delay by two; Obtaining a time deviation ΔT from the network card to the high-precision clock source according to the one-way delay = (T2-T1)-[(T4-T1)-(T3-T2)] / 2; When the time deviation ΔT is not zero, determining that there is a clock deviation between the high-precision clock source and the system clock of the network card; When ΔT<0, it is determined that the system clock of the network card is earlier than the clock time of the high-precision clock source, and the system clock time of the network card is slowed down by ΔT; When ΔT>0, it is determined that the system clock of the network card is later than the clock time of the high-precision clock source, and the system clock time of the network card is adjusted forward by ΔT.
6. The virtual machine clock synchronization method according to claim 1, characterized in that: The virtual machine periodically obtains current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copies the current time data of the high-precision clock simulation module to the clock device of the virtual machine, including: The virtual machine is arranged in a client, wherein the client includes a kernel state space and a user state space, wherein a kernel module is arranged in the kernel state space, and a clock device is arranged in the user state space; Setting the virtual machine to periodically synchronize time with the high-precision clock simulation module of the host machine; In the user state space, when the time synchronization service calls the clock device by setting a hardware clock command, the kernel module calls a hypercall route to the high-precision clock simulation module of the host machine to request to obtain the wall time / counter cycle of the host machine; The high-precision clock simulation module super call service responds to the corresponding request and sends the current time data back to the client; The current time data is copied to the clock device in the user space in the client.
7. The virtual machine clock synchronization method according to claim 1, characterized in that: The virtual machine clock synchronization method also includes: A plurality of virtual machines are connected to a host machine, the plurality of virtual machines form a virtualization cluster, and the host machine constitutes a computing node of the virtualization cluster; Setting a scheduler module to collect and monitor the clock deviation of each computing node in the virtualized cluster; Using a scheduling algorithm to evaluate clock deviation, the virtual machines corresponding to the computing nodes whose clock deviation exceeds a preset threshold are removed from the virtualization cluster; The computing nodes removed from the virtualization cluster are subjected to clock synchronization adjustment until the deviation is reduced to less than the preset threshold, and the virtual machines corresponding to the adjusted computing nodes are re-added to the fault domain of the virtualization cluster, and the virtual machines in the fault domain are allowed to perform high availability and migration operations.
8. A virtual machine clock synchronization device, characterized in that: include: A host machine setting module, used to set a high-precision clock simulation module in the kernel of the host machine, wherein the high-precision clock simulation module sets a virtual device interface for access by the virtual machine; A host machine time synchronization module, used to configure the high-precision clock simulation module of the host machine to periodically synchronize time with a high-precision clock source; A virtual machine time synchronization module is used for the virtual machine to periodically obtain current time data from the high-precision clock simulation module of the host machine through the virtual device interface, and copy the current time data of the high-precision clock simulation module to the clock device of the virtual machine.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
