Clock synchronization method, system, device and medium

By deploying clock synchronization drivers and HVC interfaces in virtual machines and host machines, high-precision time data can be directly obtained to synchronize the virtual machine system clock, solving the clock drift problem in the virtualization environment and achieving high-precision, low-overhead clock synchronization.

CN121501090APending Publication Date: 2026-02-10SHANDONG CHAOYUE DATA CONTROL ELECTRONICS CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202511842079.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-08
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

In virtualized computing environments, there is a continuous deviation between the virtual machine clock and the real physical time, which causes clock drift. Existing network synchronization methods are not accurate, not stable, and have high resource consumption in virtualized environments.

Method used

By deploying a clock synchronization driver in the virtual machine and an HVC interface in the host machine, a direct time transfer path is established. The hardware virtualization calling mechanism of the ARM architecture is used to directly obtain high-precision time data to synchronize the virtual machine system clock.

Benefits of technology

It achieves high-precision synchronization between the virtual machine clock and the host machine clock, with the synchronization error stabilized within 10 microseconds, avoiding network latency and resource consumption, and suppressing the accumulation of clock drift.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121501090A_ABST
    Figure CN121501090A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a clock synchronization method, system and device and a medium. The clock synchronization method is applied to a virtualization system based on an ARM architecture, the virtualization system comprises a host machine and a virtual machine, and the method comprises the following steps: deploying a clock synchronization drive in the virtual machine; deploying an HVC interface in a host machine; and acquiring current time data from the host machine based on the clock synchronization drive and the HVC interface, and synchronizing the current time data to a system clock of the virtual machine. Through the scheme of the invention, the problems of delay and error caused by network transmission and software processing are solved, and the precision and efficiency of clock synchronization of the virtual machine in a virtualization environment can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a clock synchronization method, system, device and medium. BACKGROUND

[0002] In a virtualized computing environment, the clock accuracy of a virtual machine is the key to guaranteeing system reliability and business collaboration. Since a virtual machine does not directly access a physical hardware clock, its clock operation relies on the scheduling and simulation of the host layer, and thus is subject to interference from various factors such as host load, interrupt processing delay, virtual CPU scheduling, and resource competition. This interference causes a persistent deviation between the internal clock of the virtual machine and the real physical time, i.e. clock drift. If the virtual machine only relies on the virtual hardware clock provided by the virtualization layer at startup to obtain an initial time, and then runs independently thereafter, the deviation will continue to accumulate over time. In actual applications, different virtual machines on the same host machine may thus produce significant and unstable clock differences, with a deviation of up to seconds or even higher, seriously affecting applications that require precise time collaboration, such as distributed transactions, log timestamps, and timing tasks.

[0003] To address this problem, existing technologies usually introduce an external Network Time Protocol (NTP) server to calibrate the clock of the host machine and the virtual machine. However, in a virtualization architecture, this method has inherent limitations. The transmission of network time synchronization packets needs to traverse a complex path such as the virtual network interface and the host network protocol stack, introducing a large amount of additional context switching and processing delay. More critically, the steps of capturing and processing network packet timestamps in a virtualized environment are mostly implemented in software, and the obtained timestamps have limited precision (i.e. "soft timestamps"). These factors make the traditional network synchronization method less accurate and less stable in a virtualized environment, and also incur additional resource overhead due to the need to calculate and compensate for network link delays.

[0004] Therefore, there is an urgent need for a clock synchronization method that can efficiently and accurately synchronize the clock between the host machine and the virtual machine. SUMMARY

[0005] In view of the above, the present application provides a clock synchronization method, system, computer device and computer readable medium, which solves the problem of delay and error introduced by network transmission and software processing, and can improve the accuracy and efficiency of virtual machine clock synchronization in a virtualized environment.

[0006] Based on the above purpose, one aspect of an embodiment of the present application provides a clock synchronization method applied to a virtualization system based on ARM architecture, the virtualization system including a host machine and a virtual machine, and the clock synchronization method specifically includes the following steps: deploying a clock synchronization driver in the virtual machine; deploying an HVC interface in the host machine; synchronizing current time data from the host machine to a system clock of the virtual machine based on the clock synchronization driver and the HVC interface.

[0007] In some embodiments, the clock synchronization method further comprises: creating a device node in a kernel of the virtual machine through the clock synchronization driver, and deploying a time acquisition interface corresponding to the device node.

[0008] In some embodiments, the synchronizing current time data from the host machine based on the clock synchronization driver and the HVC interface comprises: in response to the device node receiving an access request of a clock synchronization service in the virtual machine, calling the clock synchronization driver to initiate an HVC request to the HVC interface through the time acquisition interface; in response to the HVC interface receiving the HVC request, acquiring the current time data from the host machine and returning the current time data to the clock synchronization driver.

[0009] In some embodiments, the synchronizing the current time data to the system clock of the virtual machine comprises: in response to the clock synchronization driver receiving the current time data, returning the current time data to the device node; in response to the device node receiving the current time data, returning the current time data as an access result of the clock synchronization service to the clock synchronization service; in response to the clock synchronization service receiving the access result, synchronizing the system clock of the virtual machine to be consistent with the access result.

[0010] In some embodiments, the deploying the clock synchronization driver in the virtual machine comprises: acquiring a header file of a kernel of the virtual machine; integrating source code of the clock synchronization driver with the kernel header file to compile a target script; determining a kernel module file based on the target script, and loading the kernel module file to the kernel of the virtual machine to deploy the clock synchronization driver.

[0011] In some embodiments, the deploying the HVC interface in the host machine comprises: deploying the HVC interface in a kernel of the host machine for the clock synchronization driver to access.

[0012] In some embodiments, the obtaining the current time data from the host machine comprises: capturing a time snapshot of a system clock of the host machine, and obtaining the current time data from the time snapshot.

[0013] In another aspect of the embodiments of the present application, a clock synchronization system is also provided, comprising: a first deployment unit configured to deploy a clock synchronization driver in a virtual machine; a second deployment unit configured to deploy an HVC interface in a host machine; a clock synchronization unit configured to obtain current time data from the host machine based on the clock synchronization driver and the HVC interface, and synchronize the current time data to a system clock of the virtual machine.

[0014] In yet another aspect of the embodiments of the present application, a computer device is also provided, comprising at least one processor, and a memory storing a computer program capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the above method.

[0015] In still another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which stores a computer program capable of being executed by a processor to implement the steps of the above method.

[0016] The present application has at least the following beneficial technical effects: through the cooperation of the clock synchronization driver deployed in the virtual machine and the special HVC interface deployed in the host machine, and by using the hardware virtualization calling mechanism of the ARM architecture, the virtual machine can directly and atomically obtain a high-precision system time snapshot of the host machine. Not only is the estimation and compensation of the network link delay completely avoided, but also the obtained high-precision time data is directly used to calibrate the system clock of the virtual machine, effectively suppressing the accumulation of clock drift, thereby realizing stable and microsecond-level high-precision synchronization between the virtual machine clock and the host machine clock. The present application builds a direct time transfer path between the host machine and the virtual machine that does not depend on external networks, and fundamentally solves the problems of low precision, high delay and large resource consumption caused by protocol stack processing, context switching and soft timestamps in the traditional network synchronization method. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other embodiments can also be obtained from these drawings without creative labor.

[0018] Figure 1 a block diagram of an embodiment of the clock synchronization method provided by the present application; Figure 2 a principle schematic diagram of an embodiment of the clock synchronization method provided by the present application; Figure 3 a code schematic diagram of an embodiment of the clock synchronization driver provided by the present application; Figure 4 a schematic diagram of an embodiment of the clock synchronization system provided by the present application; Figure 5 a structure schematic diagram of an embodiment of the computer device provided by the present application; Figure 6 a structure schematic diagram of an embodiment of the computer readable storage medium provided by the present application. DETAILED DESCRIPTION

[0019] In order to make the objectives, technical solutions and advantages of the present application clearer, further detailed description will be made to the embodiments of the present application with reference to the accompanying drawings.

[0020] It should be noted that all the expressions of "first" and "second" in the embodiments of the present application are used to distinguish two same-named different entities or different parameters, and it can be seen that "first" and "second" are only used for the convenience of description, and should not be understood as the limitation of the embodiments of the present application, and the subsequent embodiments will not be described one by one.

[0021] The present application provides a high-precision clock synchronization method suitable for a virtualization system based on ARM architecture. The virtualization system includes a host and a virtual machine running thereon. The core of the clock synchronization method is to establish a direct time transfer path independent of external network protocol stack by respectively deploying a dedicated interactive interface and a driver in the host and the virtual machine kernel level, so as to realize high-precision synchronization of the virtual machine system clock and the host system clock.

[0022] Based on the above purpose, the first aspect of the embodiments of the present application proposes a clock synchronization method, which is applied to a virtualization system based on ARM architecture, and the virtualization system includes a host and a virtual machine. As shown in the figure, Figure 1 The clock synchronization method specifically includes the following steps: Step S100, deploying a clock synchronization driver in the virtual machine; Step S200, deploying an HVC interface in the host; Step S300, acquiring current time data from the host based on the clock synchronization driver and the HVC interface, and synchronizing the current time data to the system clock of the virtual machine.

[0023] In some embodiments, the following describes the deployment of the clock synchronization driver in the virtual machine. The clock synchronization driver is a kernel module running in the kernel space of the virtual machine.

[0024] In some embodiments, step S100 includes: obtaining a header file of the kernel of the virtual machine; integrating the source code of the clock synchronization driver with the kernel header file to compile a target script; determining a kernel module file based on the target script, and loading the kernel module file to the kernel of the virtual machine to deploy the clock synchronization driver.

[0025] The source code of the clock synchronization driver is adapted and integrated with the obtained kernel header file of the virtual machine, and a Makefile (a configuration file) script for guiding the compilation process is compiled. Figure 3 For example, in a virtual machine based on the Galaxy Kirin operating system, a header file of the virtual machine kernel is obtained, which is the basis for compiling the clock synchronization driver and can ensure the compatibility of the driver with the virtual machine kernel. For a virtual machine whose kernel source code is not open (such as Galaxy Kirin 020 GFB virtual machine), the kernel header file and the corresponding Makefile can be obtained from its preset path (such as / usr / src / linux-headers-5.4.18-87.76). The source code of the clock synchronization driver is integrated with the above-mentioned kernel header file, and a target script (i.e. Makefile) is compiled according to the integrated file. The target script needs to specify the driver module name, the source file on which the driver depends, the kernel path, and other key information as the entry for subsequent compilation. Based on the compiled target script, a kernel module file (such as ptp_kvm.ko) is generated, which is the executable form of the clock synchronization driver. The generated kernel module file is loaded into the kernel of the virtual machine, which completes the deployment of the clock synchronization driver, and the deployment method does not have compatibility problems.

[0026] In some embodiments, the following describes the deployment of the HVC interface in the host machine. The HVC interface, i.e. Hypervisor Call interface, is an access interface specially deployed for the clock synchronization driver in the kernel of the host machine. Its core function is to receive the HVC request (such as SMCCC_PTP_KVM_FUNC_ID request) initiated by the clock synchronization driver of the virtual machine, and return the time data of the host machine to the clock synchronization driver based on the request.

[0027] In some embodiments, step S200 includes: deploying the HVC interface in the kernel of the host machine for the clock synchronization driver to access.

[0028] The host kernel is modified to register a dedicated HVC interface in its KVM (Kernel-based Virtual Machine, an open-source system virtualization module) virtualization module. This HVC interface is configured to respond to and handle specific function requests from the virtual machine. The HVC interface provides a channel for the clock synchronization driver within the virtual machine to access the host machine's high-precision time. The deployment of the HVC interface is achieved by modifying the host kernel. The host kernel is modified to register and implement the HVC interface in the KVM virtualization layer, enabling the interface to receive HVC requests initiated by the virtual machine's clock synchronization driver, obtain host machine time data, and return it, ensuring that the clock synchronization driver can normally access the interface to complete time data exchange.

[0029] In some implementations, the clock synchronization method further includes: creating a device node in the kernel of a virtual machine through a clock synchronization driver, and deploying a time acquisition interface corresponding to the device node.

[0030] In some implementations, the device node is a virtual PTP (Precision Time Protocol) device node, such as / dev / ptp_kvm, simulated by the clock synchronization driver in the virtual machine kernel. Its function is to act as an access object for the clock synchronization service (such as chrony) within the virtual machine, receiving time acquisition requests initiated by the clock synchronization service. The time acquisition interface (such as the gettime64 interface) is an interface bound to the device node. Its function is to translate the access requests from the clock synchronization service into calls to the clock synchronization driver, triggering the clock synchronization driver to initiate an HVC request to the host HVC interface. This device node and its time acquisition interface present a standard clock source device to the virtual machine user-space applications.

[0031] The usage logic of the device node and time acquisition interface is as follows: when the clock synchronization service in the virtual machine needs to calibrate the system clock, it will send an access request to the device node. After receiving the request, the device node will trigger the time acquisition interface to call the clock synchronization driver, and the clock synchronization driver will send an HVC request to the host HVC interface to obtain time data.

[0032] In some implementations, step S300 includes: in response to a device node receiving an access request for a clock synchronization service in a virtual machine, initiating an HVC request to the HVC interface via a time acquisition interface by calling the clock synchronization driver; in response to the HVC interface receiving the HVC request, obtaining current time data from the host machine and returning the current time data to the clock synchronization driver; in response to the clock synchronization driver receiving the current time data, returning the current time data to the device node; in response to the device node receiving the current time data, returning the current time data as the access result of the clock synchronization service to the clock synchronization service; in response to the clock synchronization service receiving the access result, synchronizing the virtual machine's system clock to be consistent with the access result. A time snapshot of the host machine's system clock is captured, and the current time data is obtained from the time snapshot.

[0033] In some implementations, such as Figure 2 As shown, the clock synchronization service is chrony (a flexible and powerful network time protocol implementation). In response to a device node receiving an access request from the user-space clock synchronization service in the virtual machine, the virtual machine kernel calls the time acquisition interface. The implementation of the time acquisition interface further calls the communication functions encapsulated in the clock synchronization driver. These communication functions are configured to conform to the ARM SMCCC specification, initiating an HVC request to the host machine's HVC interface by executing the arm_smccc_hvc instruction. This request is used to request the current time data of the host machine. In response to the host machine's HVC interface receiving the HVC request, the host kernel atomically captures a snapshot of its system clock, obtains a high-precision timestamp (i.e., the current time data) from this snapshot, and returns this timestamp as the return value to the virtual machine's clock synchronization driver through the HVC call mechanism. Subsequently, the clock synchronization driver returns the received current time data to the time acquisition interface, which then fills the data into the corresponding access result of the device node. In this way, the clock synchronization service obtains the result of its initial read operation on the device node, which is a high-precision timestamp obtained directly from the host machine. Finally, in response to receiving the access result containing the high-precision timestamp, the clock synchronization service calibrates the virtual machine's system clock based on this timestamp to keep it consistent with the host machine's time.

[0034] In summary, the clock synchronization method of the present invention establishes a direct time data interaction channel between the host and the virtual machine by deploying a clock synchronization driver on the virtual machine and an HVC interface on the host machine. This eliminates the need to rely on the network protocol stack, effectively reducing the number of context switches. Furthermore, it eliminates the calculation and compensation of link latency in traditional clock synchronization methods, further saving system resource overhead. Thus, it achieves high-precision, low-overhead clock synchronization from the host machine to the virtual machine.

[0035] In some implementations, the clock synchronization method of the present invention can achieve high-precision clock synchronization from the host machine (such as an independent cloud operating system) to the virtual machine (such as the Kylin Virtual Machine), with a synchronization error stable within 10 microseconds, significantly outperforming the traditional NTP clock synchronization method. Furthermore, by deploying the clock synchronization driver as an external driver, the driver integration problem caused by the lack of open kernel source code in some virtual machines (such as the Kylin Virtual Machine) is solved, exhibiting good compatibility and applicability, and suitable for various ARM architecture virtualization systems with high clock precision requirements.

[0036] Based on the same inventive concept, according to another aspect of the present invention, such as Figure 4 As shown, embodiments of the present invention also provide a clock synchronization system, comprising: The first deployment unit 110 is configured to deploy a clock synchronization driver in a virtual machine; The second deployment unit 120 is configured to deploy the HVC interface in the host machine; The clock synchronization unit 130 is configured to obtain current time data from the host machine based on the clock synchronization driver and HVC interface, and synchronize the current time data to the system clock of the virtual machine.

[0037] The clock synchronization system of this invention, through the collaborative operation of a clock synchronization driver deployed on the virtual machine and a dedicated HVC interface deployed on the host machine, utilizes the hardware virtualization calling mechanism of the ARM architecture to enable the virtual machine to directly and atomically obtain a high-precision system time snapshot of the host machine. This not only completely avoids the estimation and compensation of network link latency, but also effectively suppresses the accumulation of clock drift by directly using the obtained high-precision time data to calibrate the virtual machine system clock, thereby achieving stable, microsecond-level high-precision synchronization between the virtual machine clock and the host machine clock. This invention fundamentally solves the problems of low accuracy, high latency, and high resource consumption caused by protocol stack processing, context switching, and soft timestamps in traditional network synchronization methods by constructing a direct time transfer path between the host machine and the virtual machine that does not rely on external networks.

[0038] Based on the same inventive concept, according to another aspect of the present invention, such as Figure 5 As shown, an embodiment of the present invention also provides a computer device 30, which includes a processor 310 and a memory 320. The memory 320 stores a computer program 321 that can be run on the processor. When the processor 310 executes the program, it performs the steps of the method described above.

[0039] Based on the same inventive concept, according to another aspect of the present invention, such as Figure 6As shown, embodiments of the present invention also provide a computer-readable storage medium 40, which stores a computer program 410 that, when executed by a processor, performs the methods described above.

[0040] Finally, it should be noted that those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium for the program can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc. The above computer program embodiments can achieve the same or similar effects as any of the corresponding foregoing method embodiments.

[0041] Those skilled in the art will also understand that the various exemplary logic blocks, modules, circuits, and algorithm steps described in conjunction with the disclosure herein can be implemented as electronic hardware, computer software, or a combination of both. To clearly illustrate this interchangeability between hardware and software, the functionality of various illustrative components, blocks, modules, circuits, and steps has been generally described. Whether this functionality is implemented as software or as hardware depends on the specific application and the design constraints imposed on the system as a whole. Those skilled in the art can implement the functionality in various ways for each specific application, but such implementation decisions should not be construed as departing from the scope of the embodiments disclosed herein.

[0042] The above are exemplary embodiments disclosed in this invention. However, it should be noted that various changes and modifications can be made without departing from the scope of the embodiments of this invention as defined by the claims. The functions, steps, and / or actions of the methods according to the disclosed embodiments described herein do not need to be performed in any particular order. The sequence numbers of the disclosed embodiments of this invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments. Furthermore, although the elements disclosed in the embodiments of this invention may be described or claimed individually, they may be understood as multiple unless explicitly limited to a singular number.

[0043] It should be understood that, as used herein, the singular form “a” is intended to include the plural form as well, unless the context clearly supports an exception. It should also be understood that, as used herein, “and / or” refers to any and all possible combinations of one or more of the associated listed items.

[0044] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples. Within the framework of the invention, technical features of the above embodiments or different embodiments can be combined, and many other variations of different aspects of the invention exist, which are not provided in the details for the sake of brevity. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the invention should be included within the protection scope of the invention.

Claims

1. A clock synchronization method, characterized in that, The clock synchronization method is applied to an ARM-based virtualization system, which includes a host machine and virtual machines, and includes: Deploy a clock synchronization driver in the virtual machine; Deploy the HVC interface in the host machine; Based on the clock synchronization driver and the HVC interface, the current time data is obtained from the host machine and synchronized to the system clock of the virtual machine.

2. The clock synchronization method according to claim 1, characterized in that, Also includes: The clock synchronization driver creates a device node in the kernel of the virtual machine and deploys a time acquisition interface corresponding to the device node.

3. The clock synchronization method according to claim 2, characterized in that, The process of obtaining current time data from the host machine based on the clock synchronization driver and the HVC interface includes: In response to the device node receiving an access request for the clock synchronization service in the virtual machine, the clock synchronization driver is invoked through the time acquisition interface to initiate an HVC request to the HVC interface. In response to the HVC interface receiving the HVC request, the current time data is obtained from the host machine and returned to the clock synchronization driver.

4. The clock synchronization method according to claim 3, characterized in that, The step of synchronizing the current time data to the system clock of the virtual machine includes: In response to the clock synchronization driver receiving the current time data, the current time data is returned to the device node; In response to the device node receiving the current time data, the current time data is returned to the clock synchronization service as the access result of the clock synchronization service; In response to the clock synchronization service receiving the access result, the system clock of the virtual machine is synchronized to be consistent with the access result.

5. The clock synchronization method according to claim 1, characterized in that, Deploying the clock synchronization driver in the virtual machine includes: Obtain the kernel header file of the virtual machine; The source code of the clock synchronization driver is integrated with the kernel header file to obtain the target script; The kernel module file is determined based on the target script, and the kernel module file is loaded into the kernel of the virtual machine to deploy the clock synchronization driver.

6. The clock synchronization method according to claim 1, characterized in that, Deploying the HVC interface in the host machine includes: The HVC interface is deployed in the kernel of the host machine for access by the clock synchronization driver.

7. The clock synchronization method according to claim 3, characterized in that, The step of obtaining the current time data from the host machine includes: Capture a time snapshot of the host machine's system clock, and obtain the current time data from the time snapshot.

8. A clock synchronization system, characterized in that, include: The first deployment unit is configured to deploy a clock synchronization driver in a virtual machine; The second deployment unit is configured to deploy the HVC interface in the host machine; A clock synchronization unit is configured to obtain current time data from the host machine based on the clock synchronization driver and the HVC interface, and synchronize the current time data to the system clock of the virtual machine.

9. A computer device, comprising: At least one processor; as well as A memory storing a computer program executable on the processor, characterized in that the processor executes the program by performing the steps of the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it performs the steps of the method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and circuit arrangement for the realization of the higher path adaptation function in synchronous digital hierarchy equipments

    CN1125369A

  • Apparatus and method for adjusting skew between data and clock

    CN119718003A

  • Apparatuses and methods for adjusting skews between data and clock

    US20250103091A1