WO2024098783A1 - Time correction method and apparatus - Google Patents

Time correction method and apparatus Download PDF

Info

Publication number
WO2024098783A1
WO2024098783A1 PCT/CN2023/103446 CN2023103446W WO2024098783A1 WO 2024098783 A1 WO2024098783 A1 WO 2024098783A1 CN 2023103446 W CN2023103446 W CN 2023103446W WO 2024098783 A1 WO2024098783 A1 WO 2024098783A1
Authority
WO
WIPO (PCT)
Prior art keywords
clock module
time
slave clock
slave
master clock
Prior art date
Application number
PCT/CN2023/103446
Other languages
French (fr)
Chinese (zh)
Inventor
赵思蓉
任慰
代雷
曾维林
李宗鸿
谢国琪
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2024098783A1 publication Critical patent/WO2024098783A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements

Definitions

  • the present application relates to the field of communications, and in particular to a time correction method and device.
  • each virtual machine performs its own functional tasks without interfering with each other, thus ensuring that the failure of a virtual machine will not affect the normal operation of other virtual machines.
  • frequent real-time data transmission is required between virtual machines to perform specific complex functional operations.
  • the brake system (virtual machine 1) needs to obtain data such as vehicle distance based on the radar system (virtual machine 2) to determine whether to brake at the moment.
  • the real-time communication function between virtual machines needs to ensure low latency and high reliability of the message transmission process.
  • ADAS advanced driver assistance system
  • the time error between virtual machines is not allowed to be less than microseconds. Therefore, it is necessary to perform time synchronization operations between the host and the virtual machine to reduce the time deviation between the two to the microsecond level to meet the needs of real-time communication between multiple virtual machines.
  • the existing time synchronization methods have low accuracy.
  • the present application provides a time correction method and device for solving the problem of low accuracy of existing time synchronization methods.
  • a time correction method is provided, which is applied to a slave clock module of a computing device, wherein the computing device further includes a master clock module, and the method includes:
  • the master clock module and the slave clock module When the master clock module and the slave clock module send time messages to each other at least twice, the master clock module and the slave clock module respectively send and receive multiple timestamps of the time messages; the master clock module and the slave clock module send and receive time messages through a first channel; the first channel is realized by mapping between the Unex domain socket file installed in the master clock module and the virtual serial port installed in the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module; according to the multiple timestamps, the time error of the slave clock module relative to the master clock module is determined; and the system time of the slave clock module is corrected according to the time error.
  • the slave clock module and the master clock module send and receive time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps. Then the slave clock module determines the time error of the slave clock module relative to the master clock module based on the multiple timestamps, and then corrects the system time of the slave clock module according to the time error.
  • the first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization, which does not rely on network communication and does not require protocol processing.
  • obtaining multiple timestamps includes:
  • the first time message carries a first timestamp representing the moment when the master clock module sends the first time message; record a second timestamp representing the moment when the master clock module receives the first time message; in response to the first time message, send a second time message to the master clock module, and record a third timestamp representing the moment when the slave clock module sends the second time message; receive a third time message sent by the master clock module to the slave clock module in response to the second time message, the third time message includes a fourth timestamp representing the time when the master clock module receives the second time message.
  • a response mechanism for the time message is designed so that the slave clock module can obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
  • the master clock module is a clock module of a master operating system
  • the slave clock module is a clock module in a slave operating system
  • the master operating system is an operating system of a computing device
  • the slave operating system is an operating system of a virtual machine running on the computing device.
  • the virtio serial field and the Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file with the virtio serial field and the Unex field added; wherein, one virtual serial port corresponds to one Unex domain socket file.
  • the VirtIO driver is used to build the first channel.
  • VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It implements data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delays, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
  • correcting the system time of the slave clock module according to the time error includes:
  • the time error is input into a preset computer function to correct the system time of the slave clock module.
  • the system time of the slave clock module is corrected based on the time error by a preset computer function, and the correction efficiency is high.
  • the method further includes:
  • a plurality of time stamps are reacquired to recorrect the system time of the slave clock module.
  • a recalibration mechanism is designed in the event that the system time correction of the slave clock module fails.
  • the system time correction of the slave clock module fails, multiple timestamps can be reacquired to recalibrate the system time of the slave clock module, thereby improving the time correction accuracy.
  • a time correction method is provided, which is applied to a computing device, wherein the computing device includes a master clock module and a slave clock module, and the method is applied to the master clock module, and the method includes:
  • At least two timestamps are sent to the slave clock module through the first channel, and the timestamps are used to correct the system time of the slave clock module that obtains the at least two timestamps;
  • the at least two timestamps include a timestamp representing the moment when the master clock module sends a time message to the slave clock module, and a timestamp representing the moment when the master clock module receives a time message from the slave clock module;
  • the first channel includes a mapping between the Unex domain socket file installed in the master clock module and the virtual serial port installed in the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
  • the slave clock module and the master clock module send and receive time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps.
  • the first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It achieves data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delay, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
  • At least two timestamps are sent to the slave clock module through the first channel, including: sending a first time message to the slave clock module, the first time message carrying a timestamp representing the moment when the master clock module sends the first time message to the slave clock module; receiving a second time message from the slave clock module, the second time message is a time message sent by the slave clock module to the master clock module in response to the first time message; in response to the second time message, sending a third time message to the slave clock module, the third time message including a timestamp representing the moment when the master clock module receives the second time message.
  • a response mechanism for the time message is designed so that the slave clock module can obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
  • the master clock module is a clock module of a master operating system
  • the slave clock module is a clock module in a slave operating system
  • the master operating system is an operating system of a computing device
  • the slave operating system is an operating system of a virtual machine running on the computing device.
  • the startup configuration XML file of the slave clock module is provided with a virtio serial field and an unix field; the virtual serial port is configured by the master clock module according to the startup configuration file with the virtio serial field and the unix field added.
  • the VirtIO driver is used to build the first channel.
  • VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It implements data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delays, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
  • the present application provides a time correction device, which may be a slave clock module or a chip or system on chip in a slave clock module.
  • the time correction device may implement the functions performed by the slave clock module in the first aspect or a possible design of the first aspect, and the functions may be implemented by hardware or by hardware executing corresponding software.
  • the present application provides a time correction device, which may be a main clock module or a chip or system on chip in the main clock module.
  • the time correction device may implement the function performed by the main clock module in the second aspect or the possible design of the second aspect, and the function may be implemented by hardware or by hardware executing corresponding software.
  • the present application provides a time correction device, the time correction device includes a processor, the processor is used to support the time correction device to execute the method of the first aspect or the second aspect. Further, the time correction device may also include a memory, the memory stores computer instructions, and the processor can execute the computer instructions to execute the method of the first aspect or the second aspect.
  • the present application provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed, the method of the first aspect or the second aspect is executed.
  • the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method of the first aspect or the second aspect described above.
  • the present application provides a chip comprising a processor and a transceiver, wherein the processor and the transceiver are used to support a time correction device to execute the method of the first aspect or the second aspect.
  • the present application provides a time correction system, which includes a master clock module and a slave clock module; wherein the master clock module is used to execute the method of the second aspect; and the slave clock module is used to execute the method of the first aspect.
  • the beneficial effects described in the third to ninth aspects of the present application can refer to the analysis of the beneficial effects of the first or second aspect, and will not be repeated here.
  • FIG1 is a schematic diagram of the structure of a time correction system provided in an embodiment of the present application.
  • FIG2 is a schematic diagram of a flow chart of a time correction method provided in an embodiment of the present application.
  • FIG3 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application.
  • FIG4 is a schematic diagram of a flow chart of another time correction method provided in an embodiment of the present application.
  • FIG5 is a schematic diagram of a flow chart of another time correction method provided in an embodiment of the present application.
  • FIG6 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application.
  • FIG7 is a schematic diagram of the structure of a time device provided in an embodiment of the present application.
  • FIG8 is a structural diagram of a time correction device provided in an embodiment of the present application.
  • FIG9 is a structural diagram of another time correction device provided in an embodiment of the present application.
  • FIG. 10 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application.
  • the network architecture and business scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application.
  • a person of ordinary skill in the art can appreciate that with the evolution of the network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
  • Message passing A general term for a type of data time correction method between processes or software components in a computer system. It abstracts and encapsulates the data to be communicated into "messages". The two or more parties involved in the communication can transfer messages between processes or components by calling primitives such as message sending and receiving, thereby completing data communication.
  • Time synchronization The process of providing a unified time scale for distributed systems through certain operations on local clocks.
  • the operating system when the operating system starts, it is necessary to obtain the real-time clock (RTC) time for time initialization, and then calculate the current system time through the frequency count of the clock source (the kernel automatically selects the clock source with the highest precision value).
  • the count values are stored in registers.
  • the host and virtual machine are set to obtain the current system time through the count value of the cntvct_el0 register.
  • the same register cannot be read by multiple virtual machines at the same time, it is interrupted by interruptions during the reading and writing process of obtaining the count value, resulting in a time deviation of several milliseconds between the current time obtained by the virtual machine and the actual time. This is not conducive to ensuring low latency and high reliability of real-time communication for systems with high time accuracy. Therefore, it is necessary to perform time synchronization operations between the host and the virtual machine to reduce the time deviation between the two to the microsecond level to meet the needs of real-time communication between multiple virtual machines.
  • the general time synchronization method relies on the network between the host and the virtual machine for time synchronization, such as precise time protocol (PTP), Chrony time synchronization service, network time protocol (NTP) time synchronization service, etc.
  • PTP precise time protocol
  • NTP network time protocol
  • the above methods are aimed at the scenarios of cloud computing and virtualization platforms in high-performance computing, which are not limited by communication resources and are based on large communication resource consumption to achieve high-precision time synchronization.
  • an embodiment of the present application provides a time correction method.
  • the method provided by the embodiment of the present application is described below in conjunction with the drawings in the specification.
  • the time correction method provided in the embodiment of the present application can be applied to various time correction systems, such as: long term evolution (LTE) system, fifth generation (5G) mobile time correction system, wireless fidelity (WiFi) system, future time correction system, or a system integrating multiple time correction systems, etc., which is not limited in the embodiment of the present application.
  • LTE long term evolution
  • 5G fifth generation
  • WiFi wireless fidelity
  • future time correction system future time correction system
  • NR new radio
  • the time correction method provided in the embodiment of the present application is described below using the time correction system shown in FIG. 1 as an example.
  • FIG1 is a schematic diagram of a computing device provided by an embodiment of the present application.
  • the computing device may include: a master clock module and a slave clock module.
  • the master clock module may be a clock module of a master operating system
  • the slave clock module may be a clock module of a guest operating system.
  • the number of slave clock modules may be multiple, and two are used as an example in FIG1 . Messages can be transmitted bidirectionally between the master clock module and the slave clock module.
  • FIG2 shows a schematic flow chart of a time correction method provided by an embodiment of the present application. As shown in FIG2 , the method may include the following steps:
  • the multiple timestamps include the timestamps of the moments when the master clock module and the slave clock module respectively send and receive time messages when the master clock module and the slave clock module send time messages to each other at least twice.
  • the master clock module sends a time message to the slave clock module once, or the slave clock module sends a time message to the master clock module once, which is recorded as one mutual transmission.
  • the multiple timestamps obtained include at least the timestamp of the master clock module sending a time message (recorded as message A), the timestamp of the slave clock module receiving the message A, the timestamp of another time message (recorded as message B) sent by the slave clock module in response to the message A, and the timestamp of the master clock module receiving the message B. That is to say, at least four timestamps are included.
  • the master clock module can be the main operating system; the slave clock module can be the guest operating system.
  • the master clock module and the slave clock module send and receive time messages through the first channel; the first channel is established before the slave clock module obtains multiple timestamps, which is the preparatory work of the time correction method provided in the embodiment of the present application.
  • the first channel is mapped between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module. The establishment process of the first channel is described below:
  • XML startup configuration extensible markup language
  • the slave clock module determines a time error of the slave clock module relative to the master clock module according to the multiple timestamps.
  • the multiple timestamps can represent the time when the master clock module and the slave clock module send and receive time messages respectively when the master clock module and the slave clock module send time messages to each other at least twice. Furthermore, the time error of the slave clock module relative to the master clock module can be determined based on the multiple timestamps.
  • the interval from sending a certain time message to receiving the time message is recorded as the transmission time
  • the slave clock module can calculate the difference between any transmission time and the average of the transmission time as the time error of the slave clock module relative to the master clock module. It can be understood that the time error of the slave clock module relative to the master clock module is obtained according to the difference between the transmission time of a time message and the average of the transmission time of multiple time messages.
  • the time error when determining the time error, can be calculated according to a time error calculation formula. Taking the calculation of the time error based on the timestamps corresponding to the two times when the master clock module and the slave clock module send time messages to each other as an example, the time error calculation formula can be:
  • Time error (T 2 - T 1 ) - [(T 2 - T 1 ) + (T 4 - T 3 )] / 2
  • T1 represents the timestamp of the time when the time message is sent for the first time
  • T2 represents the timestamp of the time when the time message is received for the second time
  • T3 represents the timestamp of the time when the time message is sent for the second time
  • T4 represents the timestamp of the time when the time message is received for the first time.
  • the time error calculation is performed based on the time error calculation formula. Although a small amount of time is consumed in reading the data each time the timestamp is transmitted in S210, according to the time error calculation formula, the transmission time of a time message (the sum of the net transmission time and the above-mentioned small amount of time) and the average of the transmission time of multiple time messages both include the small amount of time. By subtracting them, they can offset each other, thereby increasing the accuracy of the time error and being able to accurately calculate the time error of the slave clock module relative to the master clock module.
  • the slave clock module corrects the system time of the slave clock module according to the time error.
  • the system time of the slave clock module can be corrected according to the time error.
  • the system time of the slave clock module can be corrected by inputting the time error into a preset computer function.
  • the preset computer function can be selected as adjtime.
  • the slave clock module and the master clock module receive and send time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps. Then the slave clock module determines the time error of the slave clock module relative to the master clock module based on the multiple timestamps, and then corrects the system time of the slave clock module based on the time error.
  • the first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization, which does not rely on network communication and does not require protocol processing.
  • S210 obtaining multiple timestamps from a clock module may include:
  • the master clock module sends a first time message to the slave clock module, and correspondingly, the slave clock module receives the first time message from the master clock module.
  • the first time message carries a first timestamp, and the first timestamp represents the time when the main clock module sends the first time message.
  • the second timestamp represents the time when the main clock module receives the first time message.
  • the slave clock module sends a second time message to the master clock module in response to the first time message, and records a third timestamp. Accordingly, the master clock module receives the second time message.
  • the second time message may not carry content data.
  • the third timestamp represents the time when the second time message is sent from the clock module.
  • S440 The master clock module sends a third time message to the slave clock module in response to the second time message.
  • the slave clock module receives the third time message.
  • the third time message includes a fourth timestamp, and the fourth timestamp represents the time when the master clock module receives the second time message.
  • a response mechanism for designing a time message enables a slave clock module to obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
  • the slave clock module corrects the time of the slave clock module according to the time error, as shown in FIG5 , the method may further:
  • the preset computer function can output a result indicating whether the correction of the system time of the slave clock module is successful, taking the adjtime function as an example. If the correction is successful, TRUE is output; if the correction fails, FALSE is output. In the case where the output result indicates that the correction fails, multiple timestamps can be re-acquired according to the time error calculated in S220 to re-correct the system time of the slave clock module.
  • a re-correction mechanism is designed in the event that the system time correction of the slave clock module fails.
  • the system time correction of the slave clock module fails, multiple timestamps can be re-acquired to re-correct the system time of the slave clock module, thereby improving the time correction accuracy.
  • the time correction method provided in the embodiment of the present application can be applied to computing devices of various architectures, and can be applied to X86 architecture and ARM64 architecture, for example.
  • both the master clock module and the slave clock module are Ubuntu operating systems, and based on the creation steps of the first channel introduced in S210, two unix domain socket files vm1.ctl and vm2.ctl are created on the master clock module; two virtual serial ports vport2p1 and vport2p2 are generated on the slave clock module, and vm1.ctl and vm2.ctl are mapped one-to-one with vport2p1 and vport2p2, respectively.
  • the time error between the master clock module and the slave clock module is calculated to test the correction effect.
  • the time error between the master clock module and the slave clock module is calculated after time correction using the Chrony time synchronization service as a control group. The test results are shown in Table 1.
  • Table 1 shows that on the X86 architecture, the time correction method provided in the embodiment of the present application can reduce the time error between the virtual machine and the host to about 40 microseconds (us), and stabilize it at the microsecond level, while the existing time synchronization technology Chrony time synchronization service can only reduce the time error between the virtual machine and the host to about 2000us (i.e. 2 milliseconds (ms)).
  • the time correction method provided in the embodiment of the present application can reduce the time error between the virtual machine and the host to about 400us, while the Chrony time synchronization service can only reduce it to about 4100us (ie 4ms).
  • the time correction method provided in the embodiment of the present application has high time correction accuracy and can reduce the time error between the slave clock module and the master clock module from the millisecond level to the microsecond level.
  • each node such as the master clock module and the slave clock module, includes a hardware structure and/or software module corresponding to each function in order to realize the above functions.
  • the method of the embodiment of the present application can be implemented in the form of hardware, software, or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
  • the embodiment of the present application can divide the functional modules of the master clock module and the slave clock module according to the above method example.
  • each functional module can be divided according to each function, or two or more functions can be integrated into one processing module.
  • the above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. It can be implemented in practice. There are other ways to divide it.
  • the computing device shown in the present application may adopt the composition structure shown in Figure 7 or include the components shown in Figure 7.
  • Figure 7 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application.
  • the computing device may be a master clock module or a chip or system on chip in the master clock module.
  • the computing device may be a slave clock module or a chip or system on chip in the slave clock module.
  • the computing device may include a processor 701, a communication line 702, and a memory 704.
  • the processor 701 and the memory 704 may be connected via the communication line 702.
  • the processor 701 may include one or more CPUs, such as CPU0 and CPU1 in FIG7 .
  • the computing device includes multiple processors.
  • the processor 701 in FIG. 7 it may also include a processor 707 .
  • the processor 701 may be a central processing unit (CPU), a general-purpose processor, a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof.
  • the processor 701 may also be other devices with processing functions, such as circuits, devices, or software modules.
  • the communication line 702 is used to transmit information between the various components included in the computing device.
  • the computing device may also include a memory 704.
  • the memory 704 is used to store instructions, wherein the instructions may be computer programs.
  • the memory 704 can be a read-only memory (ROM) or other types of static storage devices that can store static information and/or instructions, or a random access memory (RAM) or other types of dynamic storage devices that can store information and/or instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage, magnetic disk storage media or other magnetic storage devices, and the optical disc storage includes a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, or a Blu-ray disc, etc.
  • ROM read-only memory
  • RAM random access memory
  • EEPROM electrically erasable programmable read-only memory
  • CD-ROM compact disc read-only memory
  • CD-ROM compact disc read-only memory
  • magnetic disk storage media or other magnetic storage devices and the optical disc storage includes a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, or a Blu-ray disc, etc.
  • the memory 704 can exist independently of the processor 701, or can be integrated with the processor 701.
  • the memory 704 can be used to store instructions or program codes or some data, etc.
  • the memory 704 can be located in the computing device or outside the computing device, without limitation.
  • the computing device may be a desktop computer, a portable computer, a network server, a mobile phone, a tablet computer, a wireless terminal, an embedded device, a chip system, or a device having a similar structure as shown in FIG7.
  • the composition structure shown in FIG7 does not constitute a limitation on the time correction device.
  • the computing device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
  • FIG8 shows a structural diagram of a time correction device, which is applied to a slave clock module.
  • Each module in the device shown in FIG8 has the function of implementing the corresponding steps in FIG2 and can achieve its corresponding technical effects.
  • the corresponding beneficial effects of the steps executed by each module can be referred to the description of the corresponding steps in FIG2, and will not be repeated here.
  • the functions can be implemented by hardware or by hardware executing corresponding software.
  • the hardware or software includes one or more modules corresponding to the above functions.
  • the time correction device includes:
  • the transceiver module 810 is used to obtain multiple timestamps.
  • the multiple timestamps include timestamps of the moments when the master clock module and the slave clock module send and receive time messages respectively when the master clock module and the slave clock module send and receive time messages to each other at least twice.
  • the master clock module and the slave clock module send and receive time messages through a first channel.
  • the first channel is implemented by mapping between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
  • the processing module 820 is used to determine the time error of the slave clock module relative to the master clock module according to the multiple timestamps.
  • the processing module 820 is further configured to correct the system time of the slave clock module according to the time error.
  • the transceiver module 810 is specifically configured to:
  • a first time message is received, where the first time message carries a first timestamp, and the first timestamp represents a time when the master clock module sends the first time message.
  • a second timestamp is recorded, where the second timestamp represents the time when the master clock module receives the first time message.
  • a second time message is sent to the master clock module, and a third time stamp is recorded, wherein the third time stamp represents the time when the slave clock module sends the second time message.
  • a third time message is received, where the third time message is sent by the master clock module to the slave clock module in response to the second time message, and the third time message includes a fourth timestamp, where the fourth timestamp indicates the time when the master clock module receives the second time message.
  • the master clock module is a clock module of a master operating system
  • the slave clock module is a guest operating system
  • a virtio serial field and an unexchange field are set in a boot configuration extensible markup language file of a slave clock module.
  • the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration XML file with the virtio serial field and the Unex field added. Among them, one virtual serial port corresponds to one Unex domain socket file.
  • processing module 820 is specifically configured to:
  • the time error is input into a preset computer function to correct the system time of the slave clock module.
  • processing module 820 is further configured to:
  • the slave clock module After the slave clock module corrects the time of the slave clock module according to the time error, and the result output by the preset computer function indicates that the system time correction of the slave clock module fails, multiple time stamps are reacquired to recorrect the system time of the slave clock module.
  • FIG9 shows a structural diagram of a time correction device, which is applied to a main clock module.
  • Each module in the device shown in FIG9 has the function of implementing the corresponding steps in FIG2 and can achieve its corresponding technical effects.
  • the corresponding beneficial effects of the steps executed by each module can be referred to the description of the corresponding steps in FIG2, and will not be repeated here.
  • the functions can be implemented by hardware or by hardware executing corresponding software.
  • the hardware or software includes one or more modules corresponding to the above functions.
  • the time correction device includes:
  • the sending module 910 is used to send at least two time messages to the slave clock module through the first channel.
  • the time message includes a timestamp of the time when the master clock module sends the time message; the first channel is realized by mapping the Unex domain socket file installed by the master clock module with the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
  • the apparatus further includes a receiving module 920;
  • a sending module 910 is used to send a first time message to the slave clock module, where the first time message carries a first timestamp, and the first timestamp indicates the time when the master clock module sends the first time message;
  • a receiving module 920 configured to receive a second time message from a slave clock module
  • the sending module 910 is used to send a third time message to the slave clock module in response to the second time message, where the third time message includes a fourth timestamp, and the fourth timestamp indicates the time when the master clock module receives the second time message.
  • the master clock module is a clock module of a master operating system; the slave clock module is a clock module of a guest operating system.
  • a virtio serial field and a Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file with the virtio serial field and the Unex field added; wherein, one virtual serial port corresponds to one Unex domain socket file.
  • FIG10 is a structural diagram of a time correction system provided in an embodiment of the present application.
  • the time correction system is a time correction system corresponding to a time correction scenario.
  • the time correction system may include:
  • a master clock module 110 and a slave clock module 120 are connected to A master clock module 110 and a slave clock module 120 .
  • the master clock module 110 is used to send at least two time messages to the slave clock module 120 through the first channel.
  • the time message includes a timestamp of the time when the master clock module 110 sends the time message.
  • the first channel is realized by mapping between the Unex domain socket file installed by the master clock module 110 and the virtual serial port installed by the slave clock module 120.
  • the virtual serial port is obtained by the master clock module 110 starting the VirtIO driver in the slave clock module 120.
  • the slave clock module 120 is configured to receive at least two time messages and record the timestamp of the moment when the at least two time messages are received, and to send at least one time message to the master clock module 110 in response to the first time message of the at least two time messages, and record the timestamp of the moment when the at least one time message is sent.
  • the slave clock module 120 is further used to determine the time error of the slave clock module 120 relative to the master clock module 110 according to the received timestamp and the recorded timestamp.
  • the slave clock module 120 is further used to correct the system time of the slave clock module 120 according to the time error.
  • the embodiment of the present application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be completed by a computer program to instruct the relevant hardware, and the program can be stored in the above computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments.
  • the computer-readable storage medium can be a terminal device of any of the above embodiments, such as: an internal storage unit including a data sending end and/or a data receiving end, such as a hard disk or memory of the terminal device.
  • the above computer-readable storage medium can also be an external storage device of the above terminal device, such as a plug-in hard disk equipped on the above terminal device, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, a flash card (flash card), etc. Further, the above computer-readable storage medium can also include both the internal storage unit of the above terminal device and an external storage device.
  • the above computer-readable storage medium is used to store the above computer program and other programs and data required by the above terminal device.
  • the above computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.
  • the present application also provides a computer instruction. All or part of the process in the above method embodiment can be completed by computer instructions to instruct related hardware (such as computers, processors, network devices, and terminals, etc.).
  • the program can be stored in the above computer-readable storage medium.
  • the embodiment of the present application also provides a chip system.
  • the chip system can be composed of a chip, or can include a chip and other discrete devices, without limitation.
  • the chip system includes a processor and a transceiver, and all or part of the processes in the above method embodiment can be completed by the chip system, such as the chip system can be used to implement the functions performed by the master clock module in the above method embodiment, or to implement the functions performed by the slave clock module in the above method embodiment.
  • the above-mentioned chip system also includes a memory, which is used to store program instructions and/or data.
  • the processor executes the program instructions stored in the memory so that the chip system performs the functions performed by the main clock module in the above-mentioned method embodiment or performs the functions performed by the slave clock module in the above-mentioned method embodiment.
  • the processor may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application.
  • the general-purpose processor may be a microprocessor or any conventional processor, etc.
  • the steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
  • the memory may be a non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), etc., or a volatile memory (volatile memory), such as a random-access memory (RAM).
  • the memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
  • the memory in the embodiments of the present application may also be a circuit or any other device that can realize a storage function, for storing instructions and/or data.
  • At least one (item) refers to one or more
  • multiple refers to two or more
  • at least two (items) refers to two or three and more than three
  • and/or is used to describe the association relationship of the associated objects, indicating that there can be three relationships.
  • a and/or B can represent: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural.
  • the character “/” generally indicates that the associated objects before and after are in an "or” relationship.
  • At least one of the following (items) refers to any combination of these items, including any combination of single items (items) or plural items (items).
  • at least one of a, b or c can represent: a, b, c, "a and b", “a and c", “b and c", or "a and b and c", where a, b, c can be single or multiple.
  • "B corresponding to A" means that B is associated with A.
  • B can be determined based on A.
  • determining B based on A does not mean determining B based only on A, but B can also be determined based on A and/or other information.
  • connection mentioned in the examples refers to various connection modes such as direct connection or indirect connection to achieve communication between devices, and the embodiments of the present application do not impose any limitation on this.
  • the "transmission” (transmit/transmission) appearing in the embodiments of the present application refers to bidirectional transmission, including sending and/or receiving actions.
  • the "transmission” in the embodiments of the present application includes the sending of data, the receiving of data, or the sending of data and the receiving of data.
  • the data transmission here includes uplink and/or downlink data transmission.
  • Data may include channels and/or signals, uplink data transmission is uplink channel and/or uplink signal transmission, and downlink data transmission is downlink channel and/or downlink signal transmission.
  • the "network” and “system” appearing in the embodiments of the present application express the same concept, and the time correction system is a communication network.
  • the disclosed devices and methods can be implemented in other ways.
  • the device embodiments described above are only schematic.
  • the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
  • Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
  • each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
  • the above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium.
  • the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device, such as: a single-chip microcomputer, a chip, etc., or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application.
  • the aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, disks, or optical disks.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Electric Clocks (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)

Abstract

The present application relates to the field of communications, and discloses a time correction method and apparatus. The time correction method is applied to a computing device, the computing device comprises a master clock module and a slave clock module, and the method is applied to the slave clock module. The method comprises: when the master clock module and the slave clock module send time messages to each other at least twice, acquiring a plurality of timestamps of the master clock module and the slave clock module respectively transmitting and receiving the time messages, the master clock module and the slave clock module transmitting and receiving the time messages by means of a first channel, the first channel being realized by means of mapping between an Unix domain socket file installed in the master clock module and a virtual serial port installed in the slave clock module, and the virtual serial port being obtained by starting a VirtIO driver in the slave clock module by the master clock module; determining a time error of the slave clock module with respect to the master clock module according to the plurality of timestamps; and correcting the system time of the slave clock module according to the time error. The time correction precision of the slave clock module is improved.

Description

时间校正方法及装置Time correction method and device
本申请要求于2022年11月11日提交国家知识产权局、申请号为202211414938.9、申请名称为“时间校正方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on November 11, 2022, with application number 202211414938.9 and application name “Time Correction Method and Device”, all contents of which are incorporated by reference in this application.
技术领域Technical Field
本申请涉及通信领域,尤其涉及时间校正方法及装置。The present application relates to the field of communications, and in particular to a time correction method and device.
背景技术Background technique
在以虚拟化技术支持的嵌入式系统里,各个虚拟机执行着各自的功能任务,相互之间互不干涉,从而能够确保某个虚拟机出现故障的时候不会影响其他虚拟机的正常运行。但虚拟机之间需要进行频繁的实时数据传输来进行特定的复杂功能操作。例如,在汽车中,刹车系统(虚拟机1)需要根据雷达系统(虚拟机2)获取到车距等数据来判断当前是否刹车。In an embedded system supported by virtualization technology, each virtual machine performs its own functional tasks without interfering with each other, thus ensuring that the failure of a virtual machine will not affect the normal operation of other virtual machines. However, frequent real-time data transmission is required between virtual machines to perform specific complex functional operations. For example, in a car, the brake system (virtual machine 1) needs to obtain data such as vehicle distance based on the radar system (virtual machine 2) to determine whether to brake at the moment.
虚拟机之间的实时通信功能需要保证消息传输过程的低时延性及高可靠性。部分时间精度要求高的应用场景中,例如先进驾驶辅助系统(advanced driver assistance system,ADAS)应用场景,要求虚拟机之间的时间误差是不允许低于微秒级别的。因此,需要对主机与虚拟机之间进行时间同步操作,将两者之间的时间偏差降低到微秒级别,以满足多虚拟机之间实时通信的需求。然而,现有的时间同步方法精度较低。The real-time communication function between virtual machines needs to ensure low latency and high reliability of the message transmission process. In some application scenarios with high time accuracy requirements, such as advanced driver assistance system (ADAS) application scenarios, the time error between virtual machines is not allowed to be less than microseconds. Therefore, it is necessary to perform time synchronization operations between the host and the virtual machine to reduce the time deviation between the two to the microsecond level to meet the needs of real-time communication between multiple virtual machines. However, the existing time synchronization methods have low accuracy.
发明内容Summary of the invention
本申请提供一种时间校正方法及装置,用于解决现有的时间同步方法精度较低的问题。The present application provides a time correction method and device for solving the problem of low accuracy of existing time synchronization methods.
为达到上述目的,本申请采用如下技术方案:In order to achieve the above objectives, this application adopts the following technical solutions:
第一方面,提供了一种时间校正方法,应用于计算设备的从时钟模块,该计算设备还包括主时钟模块,该方法包括:In a first aspect, a time correction method is provided, which is applied to a slave clock module of a computing device, wherein the computing device further includes a master clock module, and the method includes:
获取主时钟模块和从时钟模块至少两次互相发送时间消息时,主时钟模块和从时钟模块分别收发时间消息的多个时间戳;主时钟模块与从时钟模块通过第一通道收发时间消息;第一通道通过主时钟模块安装的尤内克斯域套接字文件与从时钟模块安装的虚拟串口之间的映射实现,虚拟串口由主时钟模块在从时钟模块中启动VirtIO驱动得到;根据多个时间戳,确定从时钟模块相对主时钟模块的时间误差;根据时间误差校正从时钟模块的系统时间。When the master clock module and the slave clock module send time messages to each other at least twice, the master clock module and the slave clock module respectively send and receive multiple timestamps of the time messages; the master clock module and the slave clock module send and receive time messages through a first channel; the first channel is realized by mapping between the Unex domain socket file installed in the master clock module and the virtual serial port installed in the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module; according to the multiple timestamps, the time error of the slave clock module relative to the master clock module is determined; and the system time of the slave clock module is corrected according to the time error.
第一方面中,从时钟模块与主时钟模块通过由尤内克斯域套接字文件与虚拟串口之间的映射构成的第一通道收发时间消息,进而使从时钟模块获取到多个时间戳。然后从时钟模块根据多个时间戳确定从时钟模块相对主时钟模块的时间误差,再根据时间误差校正从时钟模块的系统时间。采用VirtIO驱动构建第一通道,而VirtIO是一种基于I/O虚拟化的共享物理内存通信方式,不依赖网络通信,无需进行协议处理,通过文件映射实现数据复制的作用,减少了从时钟模块与主时钟模块收发时间消息的负载消耗以及网络延迟带来的影响,进而实现资源层面轻量化的时间校正,能够满足资源受限的虚拟化平台的时间校正要求。并且将从时钟模块与主时钟模块之间的时间误差从毫秒级别降低到微秒级别。In the first aspect, the slave clock module and the master clock module send and receive time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps. Then the slave clock module determines the time error of the slave clock module relative to the master clock module based on the multiple timestamps, and then corrects the system time of the slave clock module according to the time error. The first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization, which does not rely on network communication and does not require protocol processing. It realizes the role of data replication through file mapping, reduces the load consumption of the slave clock module and the master clock module sending and receiving time messages and the impact of network delay, and then realizes lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms. And the time error between the slave clock module and the master clock module is reduced from milliseconds to microseconds.
在一种可能的实现中,获取多个时间戳包括:In one possible implementation, obtaining multiple timestamps includes:
接收第一时间消息,第一时间消息携带表征主时钟模块发送第一时间消息的时刻的第一时间戳;记录表征主时钟模块接收第一时间消息的时刻的第二时间戳;响应于第一时间消息,向主时钟模块发送第二时间消息,并记录表征从时钟模块发送第二时间消息的时刻的第三时间戳;接收主时钟模块响应于第二时间消息向从时钟模块发送的第三时间消息,第三时间消息包括表征主时钟模块接收第二时间消息的时间的第四时间戳。Receive a first time message, the first time message carries a first timestamp representing the moment when the master clock module sends the first time message; record a second timestamp representing the moment when the master clock module receives the first time message; in response to the first time message, send a second time message to the master clock module, and record a third timestamp representing the moment when the slave clock module sends the second time message; receive a third time message sent by the master clock module to the slave clock module in response to the second time message, the third time message includes a fourth timestamp representing the time when the master clock module receives the second time message.
在该实现中,通过设计时间消息的应答机制使得从时钟模块能够获取到多个时间戳,获取到的多个时间戳准确性较高。 In this implementation, a response mechanism for the time message is designed so that the slave clock module can obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
在一种可能的实现中,主时钟模块为主操作系统的时钟模块,从时钟模块为从操作系统中的时钟模块,其中,主操作系统是计算设备的操作系统,从操作系统是运行于计算设备的虚拟机的操作系统。In a possible implementation, the master clock module is a clock module of a master operating system, and the slave clock module is a clock module in a slave operating system, wherein the master operating system is an operating system of a computing device, and the slave operating system is an operating system of a virtual machine running on the computing device.
在一种可能的实现中,从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;虚拟串口由主时钟模块根据添加了virtio serial字段和尤内克斯字段的启动配置可扩展标记语言文件,在从时钟模块中启动VirtIO驱动得到;其中,一个虚拟串口对应一个尤内克斯域套接字文件。In a possible implementation, the virtio serial field and the Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file with the virtio serial field and the Unex field added; wherein, one virtual serial port corresponds to one Unex domain socket file.
在该实现中,采用VirtIO驱动构建第一通道,而VirtIO是一种基于I/O虚拟化的共享物理内存通信方式,不依赖网络通信,无需进行协议处理,通过文件映射实现数据复制的作用,减少了从时钟模块与主时钟模块收发时间消息的负载消耗以及网络延迟带来的影响,进而实现资源层面轻量化的时间校正,能够满足资源受限的虚拟化平台的时间校正要求。In this implementation, the VirtIO driver is used to build the first channel. VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It implements data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delays, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
在一种可能的实现中,根据时间误差校正从时钟模块的系统时间,包括:In a possible implementation, correcting the system time of the slave clock module according to the time error includes:
将时间误差输入预设计算机函数以校正从时钟模块的系统时间。The time error is input into a preset computer function to correct the system time of the slave clock module.
在该实现中,通过预设计算机函数基于时间误差校正从时钟模块的系统时间,校正效率较高。In this implementation, the system time of the slave clock module is corrected based on the time error by a preset computer function, and the correction efficiency is high.
在一种可能的实现中,在从时钟模块根据时间误差校正从时钟模块的时间之后,方法还包括:In a possible implementation, after the slave clock module corrects the time of the slave clock module according to the time error, the method further includes:
在预设计算机函数输出的结果表征从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间。In the case where the result of the preset computer function output indicates that the system time correction of the slave clock module fails, a plurality of time stamps are reacquired to recorrect the system time of the slave clock module.
在该实现中,设计了一种从时钟模块的系统时间校正失败情况下的再校正机制,能够在从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间,进而提升时间校正精度。In this implementation, a recalibration mechanism is designed in the event that the system time correction of the slave clock module fails. When the system time correction of the slave clock module fails, multiple timestamps can be reacquired to recalibrate the system time of the slave clock module, thereby improving the time correction accuracy.
第二方面,提供了一种时间校正方法,应用于计算设备,计算设备包括主时钟模块和从时钟模块,方法应用于主时钟模块,方法包括:In a second aspect, a time correction method is provided, which is applied to a computing device, wherein the computing device includes a master clock module and a slave clock module, and the method is applied to the master clock module, and the method includes:
通过第一通道向从时钟模块发送至少两个时间戳,时间戳用于校正获取到至少两个时间戳的从时钟模块的系统时间;至少两个时间戳包括表征主时钟模块向从时钟模块发送时间消息的时刻的时间戳,以及包括表征主时钟模块从从时钟模块接收到时间消息的时刻的时间戳;第一通道包括主时钟模块安装的尤内克斯域套接字文件与从时钟模块安装的虚拟串口之间的映射,虚拟串口由主时钟模块在从时钟模块中启动VirtIO驱动得到。At least two timestamps are sent to the slave clock module through the first channel, and the timestamps are used to correct the system time of the slave clock module that obtains the at least two timestamps; the at least two timestamps include a timestamp representing the moment when the master clock module sends a time message to the slave clock module, and a timestamp representing the moment when the master clock module receives a time message from the slave clock module; the first channel includes a mapping between the Unex domain socket file installed in the master clock module and the virtual serial port installed in the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
第二方面中,从时钟模块与主时钟模块通过由尤内克斯域套接字文件与虚拟串口之间的映射构成的第一通道收发时间消息,进而使从时钟模块获取到多个时间戳。采用VirtIO驱动构建第一通道,而VirtIO是一种基于I/O虚拟化的共享物理内存通信方式,不依赖网络通信,无需进行协议处理,通过文件映射实现数据复制的作用,减少了从时钟模块与主时钟模块收发时间消息的负载消耗以及网络延迟带来的影响,进而实现资源层面轻量化的时间校正,能够满足资源受限的虚拟化平台的时间校正要求。In the second aspect, the slave clock module and the master clock module send and receive time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps. The first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It achieves data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delay, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
在一种可能的实现中,通过第一通道向从时钟模块发送至少两个时间戳,包括:向从时钟模块发送第一时间消息,第一时间消息携带表征主时钟模块向从时钟模块发送第一时间消息的时刻的时间戳;接收来自从时钟模块的第二时间消息,第二时间消息是从时钟模块响应于第一时间消息向主时钟模块发送的时间消息;响应于第二时间消息,向从时钟模块发送第三时间消息,第三时间消息包括表征主时钟模块接收第二时间消息的时刻的时间戳。In one possible implementation, at least two timestamps are sent to the slave clock module through the first channel, including: sending a first time message to the slave clock module, the first time message carrying a timestamp representing the moment when the master clock module sends the first time message to the slave clock module; receiving a second time message from the slave clock module, the second time message is a time message sent by the slave clock module to the master clock module in response to the first time message; in response to the second time message, sending a third time message to the slave clock module, the third time message including a timestamp representing the moment when the master clock module receives the second time message.
在该实现中,通过设计时间消息的应答机制使得从时钟模块能够获取到多个时间戳,获取到的多个时间戳准确性较高。In this implementation, a response mechanism for the time message is designed so that the slave clock module can obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
在一种可能的实现中,主时钟模块为主操作系统的时钟模块,从时钟模块为从操作系统中的时钟模块,其中,主操作系统是计算设备的操作系统,从操作系统是运行于计算设备的虚拟机的操作系统。In a possible implementation, the master clock module is a clock module of a master operating system, and the slave clock module is a clock module in a slave operating system, wherein the master operating system is an operating system of a computing device, and the slave operating system is an operating system of a virtual machine running on the computing device.
在一种可能的实现中,从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;虚拟串口由主时钟模块根据添加了virtio serial字段和尤内克斯字段的启动 配置可扩展标记语言文件,在从时钟模块中启动VirtIO驱动得到;其中,一个虚拟串口对应一个尤内克斯域套接字文件。In a possible implementation, the startup configuration XML file of the slave clock module is provided with a virtio serial field and an unix field; the virtual serial port is configured by the master clock module according to the startup configuration file with the virtio serial field and the unix field added. Configure the Extensible Markup Language file and start the VirtIO driver in the slave clock module to obtain it; among them, one virtual serial port corresponds to one Unex domain socket file.
在该实现中,采用VirtIO驱动构建第一通道,而VirtIO是一种基于I/O虚拟化的共享物理内存通信方式,不依赖网络通信,无需进行协议处理,通过文件映射实现数据复制的作用,减少了从时钟模块与主时钟模块收发时间消息的负载消耗以及网络延迟带来的影响,进而实现资源层面轻量化的时间校正,能够满足资源受限的虚拟化平台的时间校正要求。In this implementation, the VirtIO driver is used to build the first channel. VirtIO is a shared physical memory communication method based on I/O virtualization. It does not rely on network communication and does not require protocol processing. It implements data replication through file mapping, reduces the load consumption of sending and receiving time messages between the slave clock module and the master clock module, and the impact of network delays, thereby achieving lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms.
第三方面,本申请提供一种时间校正装置,该时间校正装置可以为从时钟模块或者从时钟模块中的芯片或者片上系统。该时间校正装置可以实现上述第一方面或者第一方面可能的设计中从时钟模块所执行的功能,所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。In a third aspect, the present application provides a time correction device, which may be a slave clock module or a chip or system on chip in a slave clock module. The time correction device may implement the functions performed by the slave clock module in the first aspect or a possible design of the first aspect, and the functions may be implemented by hardware or by hardware executing corresponding software.
第四方面,本申请提供一种时间校正装置,该时间校正装置可以为主时钟模块或者主时钟模块中的芯片或者片上系统。该时间校正装置可以实现上述第二方面或者第二方面可能的设计中主时钟模块所执行的功能,所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。In a fourth aspect, the present application provides a time correction device, which may be a main clock module or a chip or system on chip in the main clock module. The time correction device may implement the function performed by the main clock module in the second aspect or the possible design of the second aspect, and the function may be implemented by hardware or by hardware executing corresponding software.
第五方面,本申请提供一种时间校正装置,时间校正装置包括处理器,处理器用于支持时间校正装置执行第一方面或第二方面的方法。进一步的,该时间校正装置还可以包括存储器,该存储器存储有计算机指令,当处理器可以运行该计算机指令执行第一方面或者第二方面的方法。In a fifth aspect, the present application provides a time correction device, the time correction device includes a processor, the processor is used to support the time correction device to execute the method of the first aspect or the second aspect. Further, the time correction device may also include a memory, the memory stores computer instructions, and the processor can execute the computer instructions to execute the method of the first aspect or the second aspect.
第六方面,本申请提供一种计算机可读存储介质,计算机可读存储介质存储计算机指令,当计算机指令运行时,第一方面或第二方面的方法被执行。In a sixth aspect, the present application provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed, the method of the first aspect or the second aspect is executed.
第七方面,本申请提供一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机可以执行上述第一方面或第二方面的方法。In a seventh aspect, the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method of the first aspect or the second aspect described above.
第八方面,本申请提供一种芯片,该芯片包括处理器和收发器,处理器和收发器用于支持时间校正装置执行第一方面或第二方面的方法。In an eighth aspect, the present application provides a chip comprising a processor and a transceiver, wherein the processor and the transceiver are used to support a time correction device to execute the method of the first aspect or the second aspect.
第九方面,本申请提供一种时间校正系统,该时间校正系统包括主时钟模块和从时钟模块;其中,主时钟模块,用于执行第二方面的方法;从时钟模块,用于执行第一方面的方法。In a ninth aspect, the present application provides a time correction system, which includes a master clock module and a slave clock module; wherein the master clock module is used to execute the method of the second aspect; and the slave clock module is used to execute the method of the first aspect.
其中,本申请中第三方面至第九方面描述的有益效果,可以对应参考第一方面或第二方面的有益效果分析,此处不再赘述。Among them, the beneficial effects described in the third to ninth aspects of the present application can refer to the analysis of the beneficial effects of the first or second aspect, and will not be repeated here.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本申请实施例提供的一种时间校正系统的结构示意图;FIG1 is a schematic diagram of the structure of a time correction system provided in an embodiment of the present application;
图2为本申请实施例提供的一种时间校正方法的流程示意图;FIG2 is a schematic diagram of a flow chart of a time correction method provided in an embodiment of the present application;
图3为本申请实施例提供的另一种时间校正系统的结构示意图;FIG3 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application;
图4为本申请实施例提供的另一种时间校正方法的流程示意图;FIG4 is a schematic diagram of a flow chart of another time correction method provided in an embodiment of the present application;
图5为本申请实施例提供的另一种时间校正方法的流程示意图;FIG5 is a schematic diagram of a flow chart of another time correction method provided in an embodiment of the present application;
图6为本申请实施例提供的另一种时间校正系统的结构示意图;FIG6 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application;
图7为本申请实施例提供的一种时间设备的结构示意图;FIG7 is a schematic diagram of the structure of a time device provided in an embodiment of the present application;
图8为本申请实施例提供的一种时间校正装置的结构图;FIG8 is a structural diagram of a time correction device provided in an embodiment of the present application;
图9为本申请实施例提供的另一种时间校正装置的结构图;FIG9 is a structural diagram of another time correction device provided in an embodiment of the present application;
图10为本申请实施例提供的另一种时间校正系统的结构示意图。FIG. 10 is a schematic diagram of the structure of another time correction system provided in an embodiment of the present application.
具体实施方式Detailed ways
本申请实施例描述的网络架构以及业务场景是为了更加清楚的说明本申请实施例的技术方案,并不构成对于本申请实施例提供的技术方案的限定,本领域普通技术人员可知,随着网络架构的演变和新业务场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。The network architecture and business scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. A person of ordinary skill in the art can appreciate that with the evolution of the network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
在介绍本申请实施例之前,对本申请实施例涉及的一些名词进行解释。Before introducing the embodiments of the present application, some terms involved in the embodiments of the present application are explained.
消息传递:计算机系统中,进程间或软件组件间的一类数据时间校正方法的统称。它将待通信的数据抽象并封装为“消息”,参与通信的双方或多方通过调用消息发送、接收等原语实现消息在进程或组件之间的传递,从而完成数据通信。Message passing: A general term for a type of data time correction method between processes or software components in a computer system. It abstracts and encapsulates the data to be communicated into "messages". The two or more parties involved in the communication can transfer messages between processes or components by calling primitives such as message sending and receiving, thereby completing data communication.
时间同步:通过对本地时钟的某些操作,达到为分布式系统提供一个统一时间标度的过程。 Time synchronization: The process of providing a unified time scale for distributed systems through certain operations on local clocks.
对于部署于同一物理机上的虚拟机,在操作系统启动的时候,先是需要获取实时时钟(real time clock,RTC)时间进行时间初始化,然后通过时钟源(内核自动选择精确值最高的时钟源)的频率计数来计算当前的系统时间,计数值都是存放在寄存器中,比如ARM处理器(advanced risc machines,ARM)64架构下,主机和虚拟机都设定的通过cntvct_el0寄存器的计数值来获取当前的系统时间。因为同一寄存器不可同时被多台虚拟机读取,在获取到计数值的读写过程中被中断等情况打断,导致虚拟机获取的当前时间与实际时间存在几毫秒的时间偏差,这对于时间精度高的系统不利于保证实时通信的低时延性及高可靠性。因此,需要对主机与虚拟机之间进行时间同步操作,将两者之间的时间偏差降低到微秒级别,满足多虚拟机之间实时通信的需求。For virtual machines deployed on the same physical machine, when the operating system starts, it is necessary to obtain the real-time clock (RTC) time for time initialization, and then calculate the current system time through the frequency count of the clock source (the kernel automatically selects the clock source with the highest precision value). The count values are stored in registers. For example, under the ARM processor (advanced RISC machines, ARM) 64 architecture, the host and virtual machine are set to obtain the current system time through the count value of the cntvct_el0 register. Because the same register cannot be read by multiple virtual machines at the same time, it is interrupted by interruptions during the reading and writing process of obtaining the count value, resulting in a time deviation of several milliseconds between the current time obtained by the virtual machine and the actual time. This is not conducive to ensuring low latency and high reliability of real-time communication for systems with high time accuracy. Therefore, it is necessary to perform time synchronization operations between the host and the virtual machine to reduce the time deviation between the two to the microsecond level to meet the needs of real-time communication between multiple virtual machines.
一般的时间同步方法依赖于主机与虚拟机之间互通的网络进行时间同步,比如精确时间协议(precise time protocol,PTP)、Chrony时间同步服务、网络时间协议(NTP)时间同步服务等。上述几种方法针对的场景是云计算及高性能计算中的虚拟化平台,不会受到通信资源的限制,基于较大的通信资源消耗以实现高精度的时间同步。The general time synchronization method relies on the network between the host and the virtual machine for time synchronization, such as precise time protocol (PTP), Chrony time synchronization service, network time protocol (NTP) time synchronization service, etc. The above methods are aimed at the scenarios of cloud computing and virtualization platforms in high-performance computing, which are not limited by communication resources and are based on large communication resource consumption to achieve high-precision time synchronization.
而对于一些资源受限的虚拟化平台,无法支持较大的通信资源消耗,例如嵌入式系统。如果采用上述几种时间同步方法进行资源受限的虚拟化平台的时间同步,则只能将资源受限的虚拟化平台之间的误差控制在毫秒级别,达不到微秒级别,时间同步精度较低。However, for some resource-constrained virtualization platforms, such as embedded systems, it is impossible to support large communication resource consumption. If the above time synchronization methods are used to synchronize the time of resource-constrained virtualization platforms, the error between resource-constrained virtualization platforms can only be controlled at the millisecond level, not at the microsecond level, and the time synchronization accuracy is low.
为了解决上述技术问题,本申请实施例提供一种时间校正方法,下面结合说明书附图,对本申请实施例提供的方法进行描述。In order to solve the above technical problems, an embodiment of the present application provides a time correction method. The method provided by the embodiment of the present application is described below in conjunction with the drawings in the specification.
本申请实施例提供的时间校正方法可以应用于各种时间校正系统,例如:长期演进(long term evolution,LTE)系统、第五代(5th generation,5G)移动时间校正系统、无线保真(wireless fidelity,WiFi)系统、未来的时间校正系统、或者多种时间校正系统融合的系统等,本申请实施例不做限定。其中,5G还可以称为新无线(new radio,NR)。The time correction method provided in the embodiment of the present application can be applied to various time correction systems, such as: long term evolution (LTE) system, fifth generation (5G) mobile time correction system, wireless fidelity (WiFi) system, future time correction system, or a system integrating multiple time correction systems, etc., which is not limited in the embodiment of the present application. Among them, 5G can also be called new radio (NR).
下面以图1所示时间校正系统为例,对本申请实施例提供的时间校正方法进行描述。The time correction method provided in the embodiment of the present application is described below using the time correction system shown in FIG. 1 as an example.
图1是本申请实施例提供的一种计算设备的示意图,如图1所示,该计算设备可以包括:主时钟模块和从时钟模块。该主时钟模块可以为主操作系统的时钟模块,从时钟模块可以为客操作系统的时钟模块。从时钟模块的数量可以是多个,图1中以两个为示例。主时钟模块与从时钟模块之间能够双向传输消息。FIG1 is a schematic diagram of a computing device provided by an embodiment of the present application. As shown in FIG1 , the computing device may include: a master clock module and a slave clock module. The master clock module may be a clock module of a master operating system, and the slave clock module may be a clock module of a guest operating system. The number of slave clock modules may be multiple, and two are used as an example in FIG1 . Messages can be transmitted bidirectionally between the master clock module and the slave clock module.
图2示出了本申请实施例提供的时间校正方法的流程示意图。如图2所示,该方法可以包括以下步骤:FIG2 shows a schematic flow chart of a time correction method provided by an embodiment of the present application. As shown in FIG2 , the method may include the following steps:
S210,从时钟模块获取多个时间戳。S210, obtaining multiple timestamps from a clock module.
其中,多个时间戳包括主时钟模块和从时钟模块至少两次互相发送时间消息时,主时钟模块和从时钟模块分别收发时间消息的时刻的时间戳。主时钟模块向从时钟模块发送一次时间消息,或者,从时钟模块向主时钟模块发送一次时间消息,记为一次互相发送。获取的多个时间戳至少包括主时钟模块发送一个时间消息(记为消息A)的时间戳、从时钟模块接收该消息A的时间戳、从时钟模块响应于该消息A,发送的另一个时间消息(记为消息B)的时间戳、以及主时钟模块接收该消息B的时间戳。也就是说,至少包括四个时间戳。Among them, the multiple timestamps include the timestamps of the moments when the master clock module and the slave clock module respectively send and receive time messages when the master clock module and the slave clock module send time messages to each other at least twice. The master clock module sends a time message to the slave clock module once, or the slave clock module sends a time message to the master clock module once, which is recorded as one mutual transmission. The multiple timestamps obtained include at least the timestamp of the master clock module sending a time message (recorded as message A), the timestamp of the slave clock module receiving the message A, the timestamp of another time message (recorded as message B) sent by the slave clock module in response to the message A, and the timestamp of the master clock module receiving the message B. That is to say, at least four timestamps are included.
主时钟模块可以为主操作系统;从时钟模块可以为客操作系统。主时钟模块与从时钟模块通过第一通道收发时间消息;该第一通道在从时钟模块获取多个时间戳之前建立完成,是本申请实施例提供的时间校正方法的准备工作。第一通道通过主时钟模块安装的尤内克斯域套接字文件与从时钟模块安装的虚拟串口之间的映射。下面对第一通道的建立过程进行说明:The master clock module can be the main operating system; the slave clock module can be the guest operating system. The master clock module and the slave clock module send and receive time messages through the first channel; the first channel is established before the slave clock module obtains multiple timestamps, which is the preparatory work of the time correction method provided in the embodiment of the present application. The first channel is mapped between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module. The establishment process of the first channel is described below:
在主时钟模块安装尤内克斯unix域套接字文件。以及在主时钟模块中修改从时钟模块对应的启动配置可扩展标记语言(extensible markup language,XML)文件,具体的,如图3所示,在启动配置XML文件中的controller属性对应字段添加virtio serial字段、以及在启动配置XML文件中的channel属性对应字段添加unix字段。然后,主时钟模块根据添加了virtio serial字段和unix字段的启动配置XML文件在从时钟模块中启动VirtIO驱动而以从时钟模块中安装虚拟串口。再将从时钟模块的虚拟串口与主时钟模块的unix域套接字文件进行一一映射,使得一个虚拟串口对应一个尤内克斯域套接字文件,最终得到第一通道。通过第一通道,可以实现主时钟 模块与从时钟模块之间的通信。Install the Unex Unix domain socket file in the master clock module. And modify the startup configuration extensible markup language (XML) file corresponding to the slave clock module in the master clock module. Specifically, as shown in Figure 3, add the virtio serial field to the field corresponding to the controller attribute in the startup configuration XML file, and add the unix field to the field corresponding to the channel attribute in the startup configuration XML file. Then, the master clock module starts the VirtIO driver in the slave clock module according to the startup configuration XML file with the virtio serial field and the unix field added to install the virtual serial port in the slave clock module. Then, map the virtual serial port of the slave clock module to the unix domain socket file of the master clock module one by one, so that one virtual serial port corresponds to one Unex domain socket file, and finally obtain the first channel. Through the first channel, the master clock can be realized. Communication between the module and the slave clock module.
S220,从时钟模块根据多个时间戳,确定从时钟模块相对主时钟模块的时间误差。S220: The slave clock module determines a time error of the slave clock module relative to the master clock module according to the multiple timestamps.
其中,多个时间戳能够表征主时钟模块和从时钟模块至少两次互相发送时间消息时,主时钟模块和从时钟模块分别收发时间消息的时间。进而,根据多个时间戳,能够确定从时钟模块相对主时钟模块的时间误差。The multiple timestamps can represent the time when the master clock module and the slave clock module send and receive time messages respectively when the master clock module and the slave clock module send time messages to each other at least twice. Furthermore, the time error of the slave clock module relative to the master clock module can be determined based on the multiple timestamps.
可选的,记从发送某一时间消息到接收该时间消息的间隔为传输时间,从时钟模块可以通过计算任一次传输时间与传输时间的均值的差值作为从时钟模块相对主时钟模块的时间误差。可以理解为,根据一条时间消息的传输时间和多条时间消息传输时间的均值的差值,来得到从时钟模块相对主时钟模块的时间误差。Optionally, the interval from sending a certain time message to receiving the time message is recorded as the transmission time, and the slave clock module can calculate the difference between any transmission time and the average of the transmission time as the time error of the slave clock module relative to the master clock module. It can be understood that the time error of the slave clock module relative to the master clock module is obtained according to the difference between the transmission time of a time message and the average of the transmission time of multiple time messages.
示例性的,在确定时间误差时,可以根据时间误差计算公式计算时间误差。以主时钟模块和从时钟模块两次互相发送时间消息时对应的时间戳计算时间误差为例,该时间误差计算公式可以是:Exemplarily, when determining the time error, the time error can be calculated according to a time error calculation formula. Taking the calculation of the time error based on the timestamps corresponding to the two times when the master clock module and the slave clock module send time messages to each other as an example, the time error calculation formula can be:
时间误差=(T2-T1)-[(T2-T1)+(T4-T3)]/2Time error = (T 2 - T 1 ) - [(T 2 - T 1 ) + (T 4 - T 3 )] / 2
其中,T1表示第一次发送时间消息的时刻的时间戳,T2表示第二次接收时间消息的时刻的时间戳,T3表示第二次发送时间消息的时刻的时间戳,T4表示第一次接收时间消息的时刻的时间戳。Among them, T1 represents the timestamp of the time when the time message is sent for the first time, T2 represents the timestamp of the time when the time message is received for the second time, T3 represents the timestamp of the time when the time message is sent for the second time, and T4 represents the timestamp of the time when the time message is received for the first time.
基于该时间误差计算公式进行时间误差计算,虽然S210中每次传递时间戳的时候,数据的读取消耗了微小时间,但根据时间误差计算公式,一条时间消息的传输时间(净传输时间和上述微小时间的和)和多条时间消息传输时间的均值都包含了该微小时间,通过相减,可以相互抵消掉,增加了时间误差的准确性,能够准确计算出从时钟模块相对主时钟模块的时间误差。The time error calculation is performed based on the time error calculation formula. Although a small amount of time is consumed in reading the data each time the timestamp is transmitted in S210, according to the time error calculation formula, the transmission time of a time message (the sum of the net transmission time and the above-mentioned small amount of time) and the average of the transmission time of multiple time messages both include the small amount of time. By subtracting them, they can offset each other, thereby increasing the accuracy of the time error and being able to accurately calculate the time error of the slave clock module relative to the master clock module.
S230,从时钟模块根据时间误差校正从时钟模块的系统时间。S230: The slave clock module corrects the system time of the slave clock module according to the time error.
其中,在确定出从时钟模块相对主时钟模块的时间误差后,即可根据该时间误差校正从时钟模块的系统时间。After the time error of the slave clock module relative to the master clock module is determined, the system time of the slave clock module can be corrected according to the time error.
进一步地,可以通过将时间误差输入预设计算机函数以校正从时钟模块的系统时间。示例性的,预设计算机函数可以选用为adjtime。Furthermore, the system time of the slave clock module can be corrected by inputting the time error into a preset computer function. Exemplarily, the preset computer function can be selected as adjtime.
本申请实施例中,从时钟模块与主时钟模块通过由尤内克斯域套接字文件与虚拟串口之间的映射构成的第一通道收发时间消息,进而使从时钟模块获取到多个时间戳。然后从时钟模块根据多个时间戳确定从时钟模块相对主时钟模块的时间误差,再根据时间误差校正从时钟模块的系统时间。采用VirtIO驱动构建第一通道,而VirtIO是一种基于I/O虚拟化的共享物理内存通信方式,不依赖网络通信,无需进行协议处理,通过文件映射实现数据复制的作用,减少了从时钟模块与主时钟模块收发时间消息的负载消耗以及网络延迟带来的影响,进而实现资源层面轻量化的时间校正,能够满足资源受限的虚拟化平台的时间校正要求。并且将从时钟模块与主时钟模块之间的时间误差从毫秒级别降低到微秒级别。In an embodiment of the present application, the slave clock module and the master clock module receive and send time messages through the first channel composed of the mapping between the Unex domain socket file and the virtual serial port, so that the slave clock module obtains multiple timestamps. Then the slave clock module determines the time error of the slave clock module relative to the master clock module based on the multiple timestamps, and then corrects the system time of the slave clock module based on the time error. The first channel is constructed using the VirtIO driver, and VirtIO is a shared physical memory communication method based on I/O virtualization, which does not rely on network communication and does not require protocol processing. It realizes the role of data replication through file mapping, reduces the load consumption of the slave clock module and the master clock module sending and receiving time messages and the impact of network delay, and then realizes lightweight time correction at the resource level, which can meet the time correction requirements of resource-constrained virtualization platforms. And the time error between the slave clock module and the master clock module is reduced from milliseconds to microseconds.
在一种实施例中,如图4所示,S210,从时钟模块获取多个时间戳,可以包括:In one embodiment, as shown in FIG. 4 , S210, obtaining multiple timestamps from a clock module may include:
S410,主时钟模块向从时钟模块发送第一时间消息,相应的,从时钟模块接收来自主时钟模块的第一时间消息。S410, the master clock module sends a first time message to the slave clock module, and correspondingly, the slave clock module receives the first time message from the master clock module.
其中,第一时间消息携带第一时间戳,第一时间戳表征主时钟模块发送第一时间消息的时刻。The first time message carries a first timestamp, and the first timestamp represents the time when the main clock module sends the first time message.
S420,从时钟模块记录第二时间戳。S420, recording a second timestamp from the clock module.
其中,第二时间戳表征主时钟模块接收第一时间消息的时刻。The second timestamp represents the time when the main clock module receives the first time message.
S430,从时钟模块响应于第一时间消息,向主时钟模块发送第二时间消息,并记录第三时间戳。相应的,主时钟模块接收第二时间消息。第二时间消息可以不携带内容数据。S430, the slave clock module sends a second time message to the master clock module in response to the first time message, and records a third timestamp. Accordingly, the master clock module receives the second time message. The second time message may not carry content data.
其中,第三时间戳表征从时钟模块发送第二时间消息的时刻。The third timestamp represents the time when the second time message is sent from the clock module.
S440,主时钟模块响应于第二时间消息,向从时钟模块发送第三时间消息。相应的,从时钟模块接收第三时间消息。S440: The master clock module sends a third time message to the slave clock module in response to the second time message. Correspondingly, the slave clock module receives the third time message.
其中,第三时间消息包括第四时间戳,第四时间戳表征主时钟模块接收第二时间消息的时间。 The third time message includes a fourth timestamp, and the fourth timestamp represents the time when the master clock module receives the second time message.
本申请实施例中,通过设计时间消息的应答机制使得从时钟模块能够获取到多个时间戳,获取到的多个时间戳准确性较高。In the embodiment of the present application, a response mechanism for designing a time message enables a slave clock module to obtain multiple timestamps, and the multiple timestamps obtained have high accuracy.
在一种实施例中,在S230:从时钟模块根据时间误差校正从时钟模块的时间之后,如图5所示,该方法还可以:In one embodiment, after S230: the slave clock module corrects the time of the slave clock module according to the time error, as shown in FIG5 , the method may further:
S510,在预设计算机函数输出的结果表征从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间。S510 , when the result output by the preset computer function indicates that the system time correction of the slave clock module fails, reacquire a plurality of time stamps to recorrect the system time of the slave clock module.
其中,预设计算机函数能够输出表征从时钟模块的系统时间校正是否成功的结果,以adjtime函数为例。如果校正成功,则输出TRUE;如果校正失败,则输出FALSE。在输出的结果表征校正失败的情况下,可以根据S220计算出的时间误差重新获取多个时间戳,以重新校正所述从时钟模块的系统时间。The preset computer function can output a result indicating whether the correction of the system time of the slave clock module is successful, taking the adjtime function as an example. If the correction is successful, TRUE is output; if the correction fails, FALSE is output. In the case where the output result indicates that the correction fails, multiple timestamps can be re-acquired according to the time error calculated in S220 to re-correct the system time of the slave clock module.
本申请实施例中,设计了一种从时钟模块的系统时间校正失败情况下的再校正机制,能够在从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间,进而提升时间校正精度。In an embodiment of the present application, a re-correction mechanism is designed in the event that the system time correction of the slave clock module fails. When the system time correction of the slave clock module fails, multiple timestamps can be re-acquired to re-correct the system time of the slave clock module, thereby improving the time correction accuracy.
本申请实施例提供的时间校正方法可以应用于多种架构的计算设备中,示例性的,可以应用于X86架构和ARM64架构。如图6所示,在X86架构或者ARM64架构的计算设备中,主时钟模块和从时钟模块均为Ubuntu操作系统,基于S210介绍的第一通道的创建步骤,在主时钟模块上,创建了vm1.ctl和vm2.ctl两个unix域套接字文件;在从时钟模块上,生成了vport2p1和vport2p2两个虚拟串口,vm1.ctl和vm2.ctl分别与vport2p1和vport2p2一一映射。The time correction method provided in the embodiment of the present application can be applied to computing devices of various architectures, and can be applied to X86 architecture and ARM64 architecture, for example. As shown in FIG6 , in a computing device of X86 architecture or ARM64 architecture, both the master clock module and the slave clock module are Ubuntu operating systems, and based on the creation steps of the first channel introduced in S210, two unix domain socket files vm1.ctl and vm2.ctl are created on the master clock module; two virtual serial ports vport2p1 and vport2p2 are generated on the slave clock module, and vm1.ctl and vm2.ctl are mapped one-to-one with vport2p1 and vport2p2, respectively.
基于上述实施例,在X86架构或者ARM64架构的计算设备执行本申请实施例提供的时间校正方法后,计算主时钟模块与从时钟模块之间的时间误差,以测试校正效果。并同时采用Chrony时间同步服务进行时间校正后计算主时钟模块与从时钟模块之间的时间误差,作为对照组。测试结果如表1所示。Based on the above embodiment, after the computing device of the X86 architecture or the ARM64 architecture executes the time correction method provided in the embodiment of the present application, the time error between the master clock module and the slave clock module is calculated to test the correction effect. At the same time, the time error between the master clock module and the slave clock module is calculated after time correction using the Chrony time synchronization service as a control group. The test results are shown in Table 1.
表1
Table 1
表1表明,在X86架构上,本申请实施例提供的时间校正方法可以将虚拟机与主机之间时间误差降低到40微秒us左右,并且稳定在微秒级别,而现有的时间同步技术Chrony时间同步服务,只能将虚拟机与主机之间的时间误差降低到2000us(即2毫秒ms)左右。Table 1 shows that on the X86 architecture, the time correction method provided in the embodiment of the present application can reduce the time error between the virtual machine and the host to about 40 microseconds (us), and stabilize it at the microsecond level, while the existing time synchronization technology Chrony time synchronization service can only reduce the time error between the virtual machine and the host to about 2000us (i.e. 2 milliseconds (ms)).
在ARM64架构上,本申请实施例提供的时间校正方法可以将虚拟机与主机之间的时间误差降低到400us左右,而Chrony时间同步服务只能降低到4100us(即4ms)左右。On the ARM64 architecture, the time correction method provided in the embodiment of the present application can reduce the time error between the virtual machine and the host to about 400us, while the Chrony time synchronization service can only reduce it to about 4100us (ie 4ms).
经过上述测试可以看出,本申请实施例提供的时间校正方法的时间校正精度较高,可以将从时钟模块与主时钟模块之间的时间误差从毫秒级别降低到微秒级别。It can be seen from the above tests that the time correction method provided in the embodiment of the present application has high time correction accuracy and can reduce the time error between the slave clock module and the master clock module from the millisecond level to the microsecond level.
上述主要从各个节点之间交互的角度对本申请实施例提供的方案进行了介绍。可以理解的是,各个节点,例如主时钟模块和从时钟模块为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的算法步骤,本申请实施例的方法能够以硬件、软件、或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用使用不同方法来实现所描述的功能,但这种实现不应认为超出本申请的范围。The above mainly introduces the scheme provided by the embodiment of the present application from the perspective of interaction between each node. It is understandable that each node, such as the master clock module and the slave clock module, includes a hardware structure and/or software module corresponding to each function in order to realize the above functions. Those skilled in the art should easily realize that, in combination with the algorithm steps of each example described in the embodiment disclosed herein, the method of the embodiment of the present application can be implemented in the form of hardware, software, or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
本申请实施例可以根据上述方法示例对主时钟模块和从时钟模块进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以 有另外的划分方式。The embodiment of the present application can divide the functional modules of the master clock module and the slave clock module according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. It can be implemented in practice. There are other ways to divide it.
在具体实现时,本申请所示计算设备可采用图7所示的组成结构或者包括图7所示的部件。图7为本申请实施例提供的一种计算设备的结构示意图,当该计算设备具有本申请实施例所述的主时钟模块的功能时,该计算设备可以为主时钟模块或主时钟模块中的芯片或片上系统。当计算设备具有本申请实施例所述的从时钟模块的功能时,计算设备可以为从时钟模块或者从时钟模块中的芯片或片上系统。In specific implementation, the computing device shown in the present application may adopt the composition structure shown in Figure 7 or include the components shown in Figure 7. Figure 7 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. When the computing device has the function of the master clock module described in the embodiment of the present application, the computing device may be a master clock module or a chip or system on chip in the master clock module. When the computing device has the function of the slave clock module described in the embodiment of the present application, the computing device may be a slave clock module or a chip or system on chip in the slave clock module.
如图7所示,该计算设备可以包括处理器701,通信线路702,以及存储器704。其中,处理器701,以及存储器704之间可以通过通信线路702连接。在一种示例中,处理器701可以包括一个或多个CPU,例如图7中的CPU0和CPU1。As shown in FIG7 , the computing device may include a processor 701, a communication line 702, and a memory 704. The processor 701 and the memory 704 may be connected via the communication line 702. In an example, the processor 701 may include one or more CPUs, such as CPU0 and CPU1 in FIG7 .
作为一种可选的实现方式,计算设备包括多个处理器,例如,除图7中的处理器701之外,还可以包括处理器707。As an optional implementation, the computing device includes multiple processors. For example, in addition to the processor 701 in FIG. 7 , it may also include a processor 707 .
其中,处理器701可以是中央处理器(central processing unit,CPU)、通用处理器网络处理器(network processor,NP)、数字信号处理器(digital signal processing,DSP)、微处理器、微控制器、可编程逻辑器件(programmable logic device,PLD)或它们的任意组合。处理器701还可以是其它具有处理功能的装置,如电路、器件或软件模块等。The processor 701 may be a central processing unit (CPU), a general-purpose processor, a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof. The processor 701 may also be other devices with processing functions, such as circuits, devices, or software modules.
通信线路702,用于在计算设备所包括的各部件之间传送信息。The communication line 702 is used to transmit information between the various components included in the computing device.
进一步的,该计算设备还可以包括存储器704。存储器704,用于存储指令。其中,指令可以是计算机程序。Furthermore, the computing device may also include a memory 704. The memory 704 is used to store instructions, wherein the instructions may be computer programs.
其中,存储器704可以是只读存储器(read_only memory,ROM)或可存储静态信息和/或指令的其他类型的静态存储设备,也可以是随机存取存储器(random access memory,RAM)或者可存储信息和/或指令的其他类型的动态存储设备,还可以是电可擦可编程只读存储器(electrically erasable programmable read_only memory,EEPROM)、只读光盘(compact disc read_only memory,CD_ROM)或其他光盘存储、光碟存储、磁盘存储介质或其他磁存储设备,光碟存储包括压缩光碟、激光碟、光碟、数字通用光碟、或蓝光光碟等。Among them, the memory 704 can be a read-only memory (ROM) or other types of static storage devices that can store static information and/or instructions, or a random access memory (RAM) or other types of dynamic storage devices that can store information and/or instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage, magnetic disk storage media or other magnetic storage devices, and the optical disc storage includes a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, or a Blu-ray disc, etc.
需要说明的是,存储器704可以独立于处理器701存在,也可以和处理器701集成在一起。存储器704可以用于存储指令或者程序代码或者一些数据等。存储器704可以位于计算设备内,也可以位于计算设备外,不予限制。处理器701执行存储器704中存储的指令时,可以实现本申请实施例提供的方法。It should be noted that the memory 704 can exist independently of the processor 701, or can be integrated with the processor 701. The memory 704 can be used to store instructions or program codes or some data, etc. The memory 704 can be located in the computing device or outside the computing device, without limitation. When the processor 701 executes the instructions stored in the memory 704, the method provided in the embodiment of the present application can be implemented.
需要说明的是,计算设备可以是台式机、便携式电脑、网络服务器、移动手机、平板电脑、无线终端、嵌入式设备、芯片系统或有图7中类似结构的设备。此外,图7中示出的组成结构并不构成对该时间校正装置的限定,除图7所示部件之外,该计算设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。It should be noted that the computing device may be a desktop computer, a portable computer, a network server, a mobile phone, a tablet computer, a wireless terminal, an embedded device, a chip system, or a device having a similar structure as shown in FIG7. In addition, the composition structure shown in FIG7 does not constitute a limitation on the time correction device. In addition to the components shown in FIG7, the computing device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
图8示出了一种时间校正装置的结构图,该时间校正装置应用于从时钟模块。图8所示装置中各模块具有实现图2中对应步骤的功能,并能达到其相应技术效果。各模块执行步骤相应的有益效果可以参考图2对应步骤的说明,不再赘述。所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。所述硬件或软件包括一个或多个上述功能相应的模块。如:该时间校正装置包括:FIG8 shows a structural diagram of a time correction device, which is applied to a slave clock module. Each module in the device shown in FIG8 has the function of implementing the corresponding steps in FIG2 and can achieve its corresponding technical effects. The corresponding beneficial effects of the steps executed by each module can be referred to the description of the corresponding steps in FIG2, and will not be repeated here. The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. For example, the time correction device includes:
收发模块810,用于获取多个时间戳。The transceiver module 810 is used to obtain multiple timestamps.
多个时间戳包括主时钟模块和从时钟模块至少两次互相发送时间消息时,主时钟模块和从时钟模块分别收发时间消息的时刻的时间戳。主时钟模块与从时钟模块通过第一通道收发时间消息。第一通道通过主时钟模块安装的尤内克斯域套接字文件与从时钟模块安装的虚拟串口之间的映射实现,虚拟串口由主时钟模块在从时钟模块中启动VirtIO驱动得到。The multiple timestamps include timestamps of the moments when the master clock module and the slave clock module send and receive time messages respectively when the master clock module and the slave clock module send and receive time messages to each other at least twice. The master clock module and the slave clock module send and receive time messages through a first channel. The first channel is implemented by mapping between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
处理模块820,用于根据多个时间戳,确定从时钟模块相对主时钟模块的时间误差。The processing module 820 is used to determine the time error of the slave clock module relative to the master clock module according to the multiple timestamps.
处理模块820,还用于根据时间误差校正从时钟模块的系统时间。The processing module 820 is further configured to correct the system time of the slave clock module according to the time error.
在一种实施例中,收发模块810,具体用于:In one embodiment, the transceiver module 810 is specifically configured to:
接收第一时间消息,第一时间消息携带第一时间戳,第一时间戳表征主时钟模块发送第一时间消息的时刻。 A first time message is received, where the first time message carries a first timestamp, and the first timestamp represents a time when the master clock module sends the first time message.
记录第二时间戳,第二时间戳表征主时钟模块接收第一时间消息的时刻。A second timestamp is recorded, where the second timestamp represents the time when the master clock module receives the first time message.
响应于第一时间消息,向主时钟模块发送第二时间消息,并记录第三时间戳,第三时间戳表征从时钟模块发送第二时间消息的时刻。In response to the first time message, a second time message is sent to the master clock module, and a third time stamp is recorded, wherein the third time stamp represents the time when the slave clock module sends the second time message.
接收第三时间消息,第三时间消息是主时钟模块响应于第二时间消息向从时钟模块发送的时间消息,第三时间消息包括第四时间戳,第四时间戳表征主时钟模块接收第二时间消息的时间。A third time message is received, where the third time message is sent by the master clock module to the slave clock module in response to the second time message, and the third time message includes a fourth timestamp, where the fourth timestamp indicates the time when the master clock module receives the second time message.
在一种实施例中,主时钟模块为主操作系统的时钟模块。从时钟模块为客操作系统。In one embodiment, the master clock module is a clock module of a master operating system, and the slave clock module is a guest operating system.
在一种实施例中,从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段。In one embodiment, a virtio serial field and an unexchange field are set in a boot configuration extensible markup language file of a slave clock module.
虚拟串口由主时钟模块根据添加了virtio serial字段和尤内克斯字段的启动配置可扩展标记语言文件,在从时钟模块中启动VirtIO驱动得到。其中,一个虚拟串口对应一个尤内克斯域套接字文件。The virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration XML file with the virtio serial field and the Unex field added. Among them, one virtual serial port corresponds to one Unex domain socket file.
在一种实施例中,处理模块820,具体用于:In one embodiment, the processing module 820 is specifically configured to:
将时间误差输入预设计算机函数以校正从时钟模块的系统时间。The time error is input into a preset computer function to correct the system time of the slave clock module.
在一种实施例中,处理模块820还用于:In one embodiment, the processing module 820 is further configured to:
在从时钟模块根据时间误差校正从时钟模块的时间之后,且预设计算机函数输出的结果表征从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间。After the slave clock module corrects the time of the slave clock module according to the time error, and the result output by the preset computer function indicates that the system time correction of the slave clock module fails, multiple time stamps are reacquired to recorrect the system time of the slave clock module.
图9示出了一种时间校正装置的结构图,该时间校正装置应用于主时钟模块。图9所示装置中各模块具有实现图2中对应步骤的功能,并能达到其相应技术效果。各模块执行步骤相应的有益效果可以参考图2对应步骤的说明,不再赘述。所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。所述硬件或软件包括一个或多个上述功能相应的模块。如:该时间校正装置包括:FIG9 shows a structural diagram of a time correction device, which is applied to a main clock module. Each module in the device shown in FIG9 has the function of implementing the corresponding steps in FIG2 and can achieve its corresponding technical effects. The corresponding beneficial effects of the steps executed by each module can be referred to the description of the corresponding steps in FIG2, and will not be repeated here. The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. For example, the time correction device includes:
发送模块910,用于通过第一通道收发向从时钟模块发送至少两次时间消息。The sending module 910 is used to send at least two time messages to the slave clock module through the first channel.
时间消息包括主时钟模块发送时间消息的时刻的时间戳;第一通道通过主时钟模块安装的尤内克斯域套接字文件与从时钟模块安装的虚拟串口之间的映射实现,虚拟串口由主时钟模块在从时钟模块中启动VirtIO驱动得到。The time message includes a timestamp of the time when the master clock module sends the time message; the first channel is realized by mapping the Unex domain socket file installed by the master clock module with the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
在一种实施例中,装置还包括接收模块920;In one embodiment, the apparatus further includes a receiving module 920;
发送模块910,用于向从时钟模块发送第一时间消息,第一时间消息携带第一时间戳,第一时间戳表征主时钟模块发送第一时间消息的时刻;A sending module 910 is used to send a first time message to the slave clock module, where the first time message carries a first timestamp, and the first timestamp indicates the time when the master clock module sends the first time message;
接收模块920,用于接收来自从时钟模块的第二时间消息;A receiving module 920, configured to receive a second time message from a slave clock module;
发送模块910,用于响应于第二时间消息,向从时钟模块发送第三时间消息,第三时间消息包括第四时间戳,第四时间戳表征主时钟模块接收第二时间消息的时间。The sending module 910 is used to send a third time message to the slave clock module in response to the second time message, where the third time message includes a fourth timestamp, and the fourth timestamp indicates the time when the master clock module receives the second time message.
在一种实施例中,主时钟模块为主操作系统的时钟模块;从时钟模块为客操作系统。In one embodiment, the master clock module is a clock module of a master operating system; the slave clock module is a clock module of a guest operating system.
在一种实施例中,从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;虚拟串口由主时钟模块根据添加了virtio serial字段和尤内克斯字段的启动配置可扩展标记语言文件,在从时钟模块中启动VirtIO驱动得到;其中,一个虚拟串口对应一个尤内克斯域套接字文件。In one embodiment, a virtio serial field and a Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file with the virtio serial field and the Unex field added; wherein, one virtual serial port corresponds to one Unex domain socket file.
图10为本申请实施例提供的一种时间校正系统的结构图,该时间校正系统为时间校正场景相应的时间校正系统,如图10所示,该时间校正系统可以包括:FIG10 is a structural diagram of a time correction system provided in an embodiment of the present application. The time correction system is a time correction system corresponding to a time correction scenario. As shown in FIG10 , the time correction system may include:
主时钟模块110和从时钟模块120。A master clock module 110 and a slave clock module 120 .
主时钟模块110,用于通过第一通道收发向从时钟模块120发送至少两次时间消息。The master clock module 110 is used to send at least two time messages to the slave clock module 120 through the first channel.
时间消息包括主时钟模块110发送时间消息的时刻的时间戳。第一通道通过主时钟模块110安装的尤内克斯域套接字文件与从时钟模块120安装的虚拟串口之间的映射实现,虚拟串口由主时钟模块110在从时钟模块120中启动VirtIO驱动得到。The time message includes a timestamp of the time when the master clock module 110 sends the time message. The first channel is realized by mapping between the Unex domain socket file installed by the master clock module 110 and the virtual serial port installed by the slave clock module 120. The virtual serial port is obtained by the master clock module 110 starting the VirtIO driver in the slave clock module 120.
从时钟模块120,用于接收至少两次时间消息,并记录接收至少两次时间消息的时刻的时间戳。以及响应于至少两次时间消息中的第一次时间消息,向主时钟模块110发送至少一次时间消息,并记录发送至少一次时间消息的时刻的时间戳。 The slave clock module 120 is configured to receive at least two time messages and record the timestamp of the moment when the at least two time messages are received, and to send at least one time message to the master clock module 110 in response to the first time message of the at least two time messages, and record the timestamp of the moment when the at least one time message is sent.
从时钟模块120,还用于根据接收到的时间戳和记录到的时间戳,确定从时钟模块120相对主时钟模块110的时间误差。The slave clock module 120 is further used to determine the time error of the slave clock module 120 relative to the master clock module 110 according to the received timestamp and the recorded timestamp.
从时钟模块120,还用于根据时间误差校正从时钟模块120的系统时间。The slave clock module 120 is further used to correct the system time of the slave clock module 120 according to the time error.
本申请实施例还提供了一种计算机可读存储介质。上述方法实施例中的全部或者部分流程可以由计算机程序来指令相关的硬件完成,该程序可存储于上述计算机可读存储介质中,该程序在执行时,可包括如上述各方法实施例的流程。计算机可读存储介质可以是前述任一实施例的终端装置,如:包括数据发送端和/或数据接收端的内部存储单元,例如终端装置的硬盘或内存。上述计算机可读存储介质也可以是上述终端装置的外部存储设备,例如上述终端装置上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。进一步地,上述计算机可读存储介质还可以既包括上述终端装置的内部存储单元也包括外部存储设备。上述计算机可读存储介质用于存储上述计算机程序以及上述终端装置所需的其他程序和数据。上述计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。The embodiment of the present application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be completed by a computer program to instruct the relevant hardware, and the program can be stored in the above computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. The computer-readable storage medium can be a terminal device of any of the above embodiments, such as: an internal storage unit including a data sending end and/or a data receiving end, such as a hard disk or memory of the terminal device. The above computer-readable storage medium can also be an external storage device of the above terminal device, such as a plug-in hard disk equipped on the above terminal device, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, a flash card (flash card), etc. Further, the above computer-readable storage medium can also include both the internal storage unit of the above terminal device and an external storage device. The above computer-readable storage medium is used to store the above computer program and other programs and data required by the above terminal device. The above computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.
本申请实施例还提供了一种计算机指令。上述方法实施例中的全部或者部分流程可以由计算机指令来指令相关的硬件(如计算机、处理器、网络设备、和终端等)完成。该程序可被存储于上述计算机可读存储介质中。The present application also provides a computer instruction. All or part of the process in the above method embodiment can be completed by computer instructions to instruct related hardware (such as computers, processors, network devices, and terminals, etc.). The program can be stored in the above computer-readable storage medium.
本申请实施例还提供了一种芯片系统。该芯片系统可以由芯片构成,也可以包含芯片和其他分立器件,不予限制。该芯片系统包括处理器以及收发器,上述方法实施例中的全部或者部分流程可以由该芯片系统完成,如该芯片系统可以用于实现上述方法实施例中主时钟模块所执行的功能,或者,实现上述方法实施例中从时钟模块所执行的功能。The embodiment of the present application also provides a chip system. The chip system can be composed of a chip, or can include a chip and other discrete devices, without limitation. The chip system includes a processor and a transceiver, and all or part of the processes in the above method embodiment can be completed by the chip system, such as the chip system can be used to implement the functions performed by the master clock module in the above method embodiment, or to implement the functions performed by the slave clock module in the above method embodiment.
在一种可能的设计中,上述芯片系统还包括存储器,所述存储器,用于保存程序指令和/或数据,当该芯片系统运行时,该处理器执行该存储器存储的该程序指令,以使该芯片系统执行上述方法实施例中主时钟模块所执行的功能或者执行上述方法实施例中从时钟模块所执行的功能。In one possible design, the above-mentioned chip system also includes a memory, which is used to store program instructions and/or data. When the chip system is running, the processor executes the program instructions stored in the memory so that the chip system performs the functions performed by the main clock module in the above-mentioned method embodiment or performs the functions performed by the slave clock module in the above-mentioned method embodiment.
在本申请实施例中,处理器可以是通用处理器、数字信号处理器、专用集成电路、现场可编程门阵列或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件,可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。In the embodiments of the present application, the processor may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
在本申请实施例中,存储器可以是非易失性存储器,比如硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD)等,还可以是易失性存储器(volatile memory),例如随机存取存储器(random-access memory,RAM)。存储器是能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。本申请实施例中的存储器还可以是电路或者其它任意能够实现存储功能的装置,用于存储指令和/或数据。In the embodiments of the present application, the memory may be a non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), etc., or a volatile memory (volatile memory), such as a random-access memory (RAM). The memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory in the embodiments of the present application may also be a circuit or any other device that can realize a storage function, for storing instructions and/or data.
需要说明的是,本申请的说明书、权利要求书及附图中的术语“第一”和“第二”等是用于区别不同对象,而不是用于描述特定顺序。此外,术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "first" and "second" in the specification, claims and drawings of the present application are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
应当理解,在本申请实施例中,“至少一个(项)”是指一个或者多个,“多个”是指两个或两个以上,“至少两个(项)”是指两个或三个及三个以上,“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系,例如,“A和/或B”可以表示:只存在A,只存在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b或c中的至少一项(个),可以表示:a,b,c,“a和b”,“a和c”,“b和c”,或“a和b和c”,其中a,b,c可以是单个,也可以是多个。应理解,在本申请实施例中,“与A对应的B”表示B与A相关联。例如,可以根据A可以确定B。还应理解,根据A确定B并不意味着仅仅根据A确定B,还可以根据A和/或其它信息确定B。此外,本申请实 施例中出现的“连接”是指直接连接或者间接连接等各种连接方式,以实现设备间的通信,本申请实施例对此不做任何限定。It should be understood that in the embodiments of the present application, "at least one (item)" refers to one or more, "multiple" refers to two or more, "at least two (items)" refers to two or three and more than three, and "and/or" is used to describe the association relationship of the associated objects, indicating that there can be three relationships. For example, "A and/or B" can represent: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character "/" generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following (items)" or similar expressions refers to any combination of these items, including any combination of single items (items) or plural items (items). For example, at least one of a, b or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple. It should be understood that in the embodiments of the present application, "B corresponding to A" means that B is associated with A. For example, B can be determined based on A. It should also be understood that determining B based on A does not mean determining B based only on A, but B can also be determined based on A and/or other information. The “connection” mentioned in the examples refers to various connection modes such as direct connection or indirect connection to achieve communication between devices, and the embodiments of the present application do not impose any limitation on this.
本申请实施例中出现的“传输”(transmit/transmission)如无特别说明,是指双向传输,包含发送和/或接收的动作。具体地,本申请实施例中的“传输”包含数据的发送,数据的接收,或者数据的发送和数据的接收。或者说,这里的数据传输包括上行和/或下行数据传输。数据可以包括信道和/或信号,上行数据传输即上行信道和/或上行信号传输,下行数据传输即下行信道和/或下行信号传输。本申请实施例中出现的“网络”与“系统”表达的是同一概念,时间校正系统即为通信网络。Unless otherwise specified, the "transmission" (transmit/transmission) appearing in the embodiments of the present application refers to bidirectional transmission, including sending and/or receiving actions. Specifically, the "transmission" in the embodiments of the present application includes the sending of data, the receiving of data, or the sending of data and the receiving of data. In other words, the data transmission here includes uplink and/or downlink data transmission. Data may include channels and/or signals, uplink data transmission is uplink channel and/or uplink signal transmission, and downlink data transmission is downlink channel and/or downlink signal transmission. The "network" and "system" appearing in the embodiments of the present application express the same concept, and the time correction system is a communication network.
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或也可以不是物理上分开的,作为单元显示的部件可以是一个物理单元或多个物理单元,即可以位于一个地方,或者也可以分布到多个不同地方。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该软件产品存储在一个存储介质中,包括若干指令用以使得一个设备,如:可以是单片机,芯片等,或处理器(processor)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device, such as: a single-chip microcomputer, a chip, etc., or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, disks, or optical disks.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。 The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims (23)

  1. 一种时间校正方法,其特征在于,应用于计算设备的从时钟模块,所述计算设备还包括主时钟模块,所述方法包括:A time correction method, characterized in that it is applied to a slave clock module of a computing device, wherein the computing device also includes a master clock module, and the method comprises:
    获取多个时间戳,所述多个时间戳包括所述主时钟模块和所述从时钟模块至少两次互相发送时间消息时,所述主时钟模块和所述从时钟模块分别收发所述时间消息的时刻的时间戳;所述主时钟模块与所述从时钟模块通过第一通道收发时间消息;所述第一通道通过所述主时钟模块安装的尤内克斯域套接字文件与所述从时钟模块安装的虚拟串口之间的映射实现,所述虚拟串口由所述主时钟模块在所述从时钟模块中启动VirtIO驱动得到;Acquire multiple timestamps, the multiple timestamps including timestamps of the moments when the master clock module and the slave clock module respectively send and receive the time messages when the master clock module and the slave clock module send and receive the time messages to each other at least twice; the master clock module and the slave clock module send and receive time messages through a first channel; the first channel is realized by mapping between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module;
    根据所述多个时间戳,确定所述从时钟模块相对所述主时钟模块的时间误差;Determining a time error of the slave clock module relative to the master clock module according to the multiple timestamps;
    根据所述时间误差校正所述从时钟模块的系统时间。The system time of the slave clock module is corrected according to the time error.
  2. 根据权利要求1所述的时间校正方法,其特征在于,所述获取多个时间戳包括:The time correction method according to claim 1, wherein obtaining multiple timestamps comprises:
    接收第一时间消息,第一时间消息携带第一时间戳,所述第一时间戳表征所述主时钟模块发送所述第一时间消息的时刻;receiving a first time message, the first time message carrying a first timestamp, the first timestamp representing the time when the master clock module sends the first time message;
    记录第二时间戳,所述第二时间戳表征所述主时钟模块接收所述第一时间消息的时刻;Recording a second timestamp, where the second timestamp represents the time when the master clock module receives the first time message;
    响应于所述第一时间消息,向所述主时钟模块发送第二时间消息,并记录第三时间戳,所述第三时间戳表征所述从时钟模块发送第二时间消息的时刻;In response to the first time message, send a second time message to the master clock module, and record a third timestamp, wherein the third timestamp indicates the time when the slave clock module sends the second time message;
    接收第三时间消息,所述第三时间消息是主时钟模块响应于所述第二时间消息向从时钟模块发送的时间消息,所述第三时间消息包括第四时间戳,所述第四时间戳表征所述主时钟模块接收所述第二时间消息的时刻。A third time message is received, where the third time message is sent by the master clock module to the slave clock module in response to the second time message, and the third time message includes a fourth timestamp, where the fourth timestamp indicates the moment when the master clock module receives the second time message.
  3. 根据权利要求1或2所述的时间校正方法,其特征在于,所述主时钟模块为主操作系统的时钟模块,所述从时钟模块为从操作系统中的时钟模块,其中,所述主操作系统是所述计算设备的操作系统,所述从操作系统是运行于所述计算设备的虚拟机的操作系统。The time correction method according to claim 1 or 2 is characterized in that the master clock module is a clock module of a master operating system, and the slave clock module is a clock module in a slave operating system, wherein the master operating system is the operating system of the computing device, and the slave operating system is the operating system of a virtual machine running on the computing device.
  4. 根据权利要求1-3任一项所述的时间校正方法,其特征在于,所述从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;则所述虚拟串口由所述主时钟模块根据添加了所述virtio serial字段和所述尤内克斯字段的所述启动配置可扩展标记语言文件,在所述从时钟模块中启动VirtIO驱动得到;其中,一个所述虚拟串口对应一个所述尤内克斯域套接字文件。The time correction method according to any one of claims 1-3 is characterized in that a virtio serial field and a Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file to which the virtio serial field and the Unex field are added; wherein one virtual serial port corresponds to one Unex domain socket file.
  5. 根据权利要求1-4任一项所述的时间校正方法,其特征在于,所述根据所述时间误差校正所述从时钟模块的系统时间,包括:The time correction method according to any one of claims 1 to 4, characterized in that the step of correcting the system time of the slave clock module according to the time error comprises:
    将所述时间误差输入预设计算机函数以校正所述从时钟模块的系统时间。The time error is input into a preset computer function to correct the system time of the slave clock module.
  6. 根据权利要求5所述的时间校正方法,其特征在于,在所述根据所述时间误差校正所述从时钟模块的时间之后,所述方法还包括:The time correction method according to claim 5, characterized in that after correcting the time of the slave clock module according to the time error, the method further comprises:
    在所述预设计算机函数输出的结果指示所述从时钟模块的系统时间校正失败的情况下,重新获取多个时间戳,以重新校正所述从时钟模块的系统时间。When the result output by the preset computer function indicates that the system time correction of the slave clock module fails, a plurality of time stamps are reacquired to recorrect the system time of the slave clock module.
  7. 一种时间校正方法,其特征在于,应用于计算设备的主时钟模块,所述计算设备还包括从时钟模块,所述方法包括:A time correction method, characterized in that it is applied to a master clock module of a computing device, wherein the computing device also includes a slave clock module, and the method comprises:
    通过第一通道向所述从时钟模块发送至少两个时间戳,所述时间戳用于校正获取到所述至少两个时间戳的所述从时钟模块的系统时间;所述至少两个时间戳包括表征所述主时钟模块向所述从时钟模块发送时间消息的时刻的时间戳,以及包括表征所述主时钟模块从所述从时钟模块接收到时间消息的时刻的时间戳;所述第一通道通过所述主时钟模块安装的尤内克斯域套接字文件与所述从时钟模块安装的虚拟串口之间的映射实现,所述虚拟串口由所述主时钟模块在所述从时钟模块中启动VirtIO驱动得到。At least two timestamps are sent to the slave clock module through a first channel, and the timestamps are used to correct the system time of the slave clock module that obtains the at least two timestamps; the at least two timestamps include a timestamp representing the moment when the master clock module sends a time message to the slave clock module, and a timestamp representing the moment when the master clock module receives a time message from the slave clock module; the first channel is realized by mapping between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
  8. 根据权利要求7所述的时间校正方法,其特征在于,所述通过第一通道向所述从时钟模块发送至少两个时间戳,包括:The time correction method according to claim 7, characterized in that the sending of at least two timestamps to the slave clock module through the first channel comprises:
    向所述从时钟模块发送第一时间消息,所述第一时间消息携带表征所述主时钟模块向所述从时钟模块发送所述第一时间消息的时刻的时间戳;Sending a first time message to the slave clock module, where the first time message carries a timestamp indicating the time when the master clock module sends the first time message to the slave clock module;
    接收来自所述从时钟模块的第二时间消息,所述第二时间消息是所述从时钟模块响应于所述 第一时间消息向所述主时钟模块发送的时间消息;Receive a second time message from the slave clock module, wherein the second time message is a time message received by the slave clock module in response to the A time message sent by a first time message to the master clock module;
    响应于所述第二时间消息,向所述从时钟模块发送第三时间消息,所述第三时间消息包括表征所述主时钟模块接收所述第二时间消息的时刻的时间戳。In response to the second time message, a third time message is sent to the slave clock module, the third time message including a timestamp indicating a time when the master clock module receives the second time message.
  9. 根据权利要求7或8所述的时间校正方法,其特征在于,所述主时钟模块为主操作系统的时钟模块,所述从时钟模块为从操作系统中的时钟模块,其中,所述主操作系统是所述计算设备的操作系统,所述从操作系统是运行于所述计算设备的虚拟机的操作系统。The time correction method according to claim 7 or 8 is characterized in that the master clock module is a clock module of a master operating system, and the slave clock module is a clock module in a slave operating system, wherein the master operating system is the operating system of the computing device, and the slave operating system is the operating system of a virtual machine running on the computing device.
  10. 根据权利要求7-9任一项所述的时间校正方法,其特征在于,所述从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;所述虚拟串口由所述主时钟模块根据添加了所述virtio serial字段和所述尤内克斯字段的所述启动配置可扩展标记语言文件,在所述从时钟模块中启动VirtIO驱动得到;其中,一个所述虚拟串口对应一个所述尤内克斯域套接字文件。The time correction method according to any one of claims 7 to 9 is characterized in that a virtio serial field and a Unex field are set in the startup configuration extensible markup language file of the slave clock module; the virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file to which the virtio serial field and the Unex field are added; wherein one virtual serial port corresponds to one Unex domain socket file.
  11. 一种时间校正装置,其特征在于,应用于计算设备的从时钟模块,所述计算设备还包括主时钟模块,所述装置包括:A time correction device, characterized in that it is applied to a slave clock module of a computing device, the computing device also includes a master clock module, and the device includes:
    收发模块,用于获取多个时间戳,所述多个时间戳包括所述主时钟模块和所述从时钟模块至少两次互相发送时间消息时,所述主时钟模块和所述从时钟模块分别收发所述时间消息的时刻的时间戳;所述主时钟模块与所述从时钟模块通过第一通道收发时间消息;所述第一通道通过所述主时钟模块安装的尤内克斯域套接字文件与所述从时钟模块安装的虚拟串口之间的映射实现,所述虚拟串口由所述主时钟模块在从时钟模块中启动VirtIO驱动得到;A transceiver module, used for obtaining a plurality of timestamps, wherein the plurality of timestamps include timestamps of the moments when the master clock module and the slave clock module respectively send and receive the time messages when the master clock module and the slave clock module send and receive the time messages to each other at least twice; the master clock module and the slave clock module send and receive time messages through a first channel; the first channel is realized by mapping between a Unex domain socket file installed by the master clock module and a virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting a VirtIO driver in the slave clock module;
    处理模块,用于根据所述多个时间戳,确定所述从时钟模块相对所述主时钟模块的时间误差;A processing module, configured to determine a time error of the slave clock module relative to the master clock module according to the multiple timestamps;
    所述处理模块,还用于根据所述时间误差校正所述从时钟模块的系统时间。The processing module is further used to correct the system time of the slave clock module according to the time error.
  12. 根据权利要求11所述的时间校正装置,其特征在于,所述收发模块,具体用于:The time correction device according to claim 11, characterized in that the transceiver module is specifically used to:
    接收第一时间消息,第一时间消息携带第一时间戳,所述第一时间戳表征所述主时钟模块发送所述第一时间消息的时刻;receiving a first time message, the first time message carrying a first timestamp, the first timestamp representing the time when the master clock module sends the first time message;
    记录第二时间戳,所述第二时间戳表征所述主时钟模块接收所述第一时间消息的时刻;Recording a second timestamp, where the second timestamp represents the time when the master clock module receives the first time message;
    响应于所述第一时间消息,向所述主时钟模块发送第二时间消息,并记录第三时间戳,所述第三时间戳表征所述从时钟模块发送第二时间消息的时刻;In response to the first time message, send a second time message to the master clock module, and record a third timestamp, wherein the third timestamp indicates the time when the slave clock module sends the second time message;
    接收第三时间消息,所述第三时间消息是主时钟模块响应于所述第二时间消息向从时钟模块发送的时间消息,所述第三时间消息包括第四时间戳,所述第四时间戳表征所述主时钟模块接收所述第二时间消息的时刻。A third time message is received, where the third time message is sent by the master clock module to the slave clock module in response to the second time message, and the third time message includes a fourth timestamp, where the fourth timestamp indicates the time when the master clock module receives the second time message.
  13. 根据权利要求11或12所述的时间校正装置,其特征在于,所述主时钟模块为主操作系统的时钟模块,所述从时钟模块为从操作系统中的时钟模块,其中,所述主操作系统是所述计算设备的操作系统,所述从操作系统是运行于所述计算设备的虚拟机的操作系统。The time correction device according to claim 11 or 12 is characterized in that the master clock module is a clock module of a master operating system, and the slave clock module is a clock module in a slave operating system, wherein the master operating system is the operating system of the computing device, and the slave operating system is the operating system of a virtual machine running on the computing device.
  14. 根据权利要求11-13任一项所述的时间校正装置,其特征在于,所述从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;The time correction device according to any one of claims 11 to 13, characterized in that a virtio serial field and a unexus field are set in the startup configuration extensible markup language file of the slave clock module;
    则所述虚拟串口由所述主时钟模块根据添加了所述virtio serial字段和所述尤内克斯字段的所述启动配置可扩展标记语言文件,在所述从时钟模块中启动VirtIO驱动得到;其中,一个所述虚拟串口对应一个所述尤内克斯域套接字文件。The virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file to which the virtio serial field and the Unex field are added; wherein, one virtual serial port corresponds to one Unex domain socket file.
  15. 根据权利要求11-14任一项所述的时间校正装置,其特征在于,所述处理模块,具体用于:The time correction device according to any one of claims 11 to 14, characterized in that the processing module is specifically used to:
    将所述时间误差输入预设计算机函数以校正所述从时钟模块的系统时间。The time error is input into a preset computer function to correct the system time of the slave clock module.
  16. 根据权利要求15所述的时间校正装置,其特征在于,所述处理模块还用于:The time correction device according to claim 15, characterized in that the processing module is further used for:
    在所述从时钟模块根据所述时间误差校正所述从时钟模块的时间之后,且所述预设计算机函数输出的结果表征所述从时钟模块的系统时间校正失败的情况下,重新校正所述从时钟模块的时间。After the slave clock module corrects the time of the slave clock module according to the time error, and the result output by the preset computer function indicates that the system time correction of the slave clock module fails, the time of the slave clock module is re-corrected.
  17. 一种时间校正装置,其特征在于,应用于计算设备的主时钟模块,所述计算设备还包括从时钟模块,所述装置包括: A time correction device, characterized in that it is applied to a master clock module of a computing device, the computing device also includes a slave clock module, and the device includes:
    发送模块,用于通过第一通道向所述从时钟模块发送至少两个时间戳,所述时间戳用于校正获取到所述至少两个时间戳的所述从时钟模块的系统时间;所述至少两个时间戳包括表征所述主时钟模块向所述从时钟模块发送时间消息的时刻的时间戳,以及包括表征所述主时钟模块从所述从时钟模块接收到时间消息的时刻的时间戳;所述第一通道包括所述主时钟模块安装的尤内克斯域套接字文件与所述从时钟模块安装的虚拟串口之间的映射,所述虚拟串口由所述主时钟模块在所述从时钟模块中启动VirtIO驱动得到。A sending module is used to send at least two timestamps to the slave clock module through a first channel, and the timestamps are used to correct the system time of the slave clock module that obtains the at least two timestamps; the at least two timestamps include a timestamp representing the moment when the master clock module sends a time message to the slave clock module, and a timestamp representing the moment when the master clock module receives a time message from the slave clock module; the first channel includes a mapping between a Unex domain socket file installed by the master clock module and a virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module.
  18. 根据权利要求17所述的时间校正装置,其特征在于,所述装置还包括接收模块;The time correction device according to claim 17, characterized in that the device further comprises a receiving module;
    所述发送模块,用于向所述从时钟模块发送第一时间消息,所述第一时间消息携带表征所述主时钟模块向所述从时钟模块发送所述第一时间消息的时刻的时间戳;The sending module is used to send a first time message to the slave clock module, where the first time message carries a timestamp representing the moment when the master clock module sends the first time message to the slave clock module;
    所述接收模块,用于接收来自所述从时钟模块的第二时间消息,所述第二时间消息是所述从时钟模块响应于所述第一时间消息向所述主时钟模块发送的时间消息;The receiving module is used to receive a second time message from the slave clock module, where the second time message is a time message sent by the slave clock module to the master clock module in response to the first time message;
    所述发送模块,用于响应于所述第二时间消息,向所述从时钟模块发送第三时间消息,所述第三时间消息包括表征所述主时钟模块接收所述第二时间消息的时刻的时间戳。The sending module is used to send a third time message to the slave clock module in response to the second time message, and the third time message includes a timestamp representing the moment when the master clock module receives the second time message.
  19. 根据权利要求17或18所述的时间校正装置,其特征在于,所述主时钟模块为主操作系统的时钟模块;所述从时钟模块为客操作系统的时钟模块。The time correction device according to claim 17 or 18 is characterized in that the master clock module is a clock module of a master operating system; and the slave clock module is a clock module of a guest operating system.
  20. 根据权利要求17-19任一项所述的时间校正装置,其特征在于,所述从时钟模块的启动配置可扩展标记语言文件中设置有virtio serial字段和尤内克斯字段;The time correction device according to any one of claims 17 to 19, characterized in that a virtio serial field and a unexus field are set in the startup configuration extensible markup language file of the slave clock module;
    所述虚拟串口由所述主时钟模块根据添加了所述virtio serial字段和所述尤内克斯字段的所述启动配置可扩展标记语言文件,在所述从时钟模块中启动VirtIO驱动得到;其中,一个所述虚拟串口对应一个所述尤内克斯域套接字文件。The virtual serial port is obtained by the master clock module by starting the VirtIO driver in the slave clock module according to the startup configuration extensible markup language file to which the virtio serial field and the Unex field are added; wherein, one virtual serial port corresponds to one Unex domain socket file.
  21. 一种时间校正装置,其特征在于,所述时间校正装置包括处理器,所述处理器用于支持所述时间校正装置执行如权利要求1-10任一项所述的方法。A time correction device, characterized in that the time correction device comprises a processor, and the processor is used to support the time correction device to execute the method as described in any one of claims 1-10.
  22. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储计算机指令,当所述计算机指令运行时,执行如权利要求1-10任一项所述的方法。A computer-readable storage medium, characterized in that the computer-readable storage medium stores computer instructions, and when the computer instructions are executed, the method according to any one of claims 1 to 10 is executed.
  23. 一种时间校正系统,其特征在于,所述时间校正系统包括:主时钟模块和从时钟模块;A time correction system, characterized in that the time correction system comprises: a master clock module and a slave clock module;
    所述主时钟模块,用于通过第一通道收发向所述从时钟模块发送至少两次时间消息;所述时间消息包括所述主时钟模块发送所述时间消息的时刻的时间戳;所述第一通道通过所述主时钟模块安装的尤内克斯域套接字文件与所述从时钟模块安装的虚拟串口之间的映射实现,所述虚拟串口由所述主时钟模块在从时钟模块中启动VirtIO驱动得到;The master clock module is used to send at least two time messages to the slave clock module through the first channel; the time message includes a timestamp of the moment when the master clock module sends the time message; the first channel is realized by mapping between the Unex domain socket file installed by the master clock module and the virtual serial port installed by the slave clock module, and the virtual serial port is obtained by the master clock module starting the VirtIO driver in the slave clock module;
    所述从时钟模块,用于接收所述至少两次时间消息,并记录接收所述至少两次时间消息的时刻的时间戳;以及响应于所述至少两次时间消息中的第一次时间消息,向所述主时钟模块发送至少一次时间消息,并记录发送所述至少一次时间消息的时刻的时间戳;The slave clock module is used to receive the at least two time messages and record the timestamp of the moment when the at least two time messages are received; and in response to the first time message of the at least two time messages, send at least one time message to the master clock module, and record the timestamp of the moment when the at least one time message is sent;
    所述从时钟模块,还用于根据接收到的所述时间戳和记录到的所述时间戳,确定所述从时钟模块相对所述主时钟模块的时间误差;The slave clock module is further used to determine the time error of the slave clock module relative to the master clock module according to the received timestamp and the recorded timestamp;
    所述从时钟模块,还用于根据所述时间误差校正所述从时钟模块的系统时间。 The slave clock module is further used to correct the system time of the slave clock module according to the time error.
PCT/CN2023/103446 2022-11-11 2023-06-28 Time correction method and apparatus WO2024098783A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211414938.9A CN118041477A (en) 2022-11-11 2022-11-11 Time correction method and device
CN202211414938.9 2022-11-11

Publications (1)

Publication Number Publication Date
WO2024098783A1 true WO2024098783A1 (en) 2024-05-16

Family

ID=90990132

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/103446 WO2024098783A1 (en) 2022-11-11 2023-06-28 Time correction method and apparatus

Country Status (2)

Country Link
CN (1) CN118041477A (en)
WO (1) WO2024098783A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105703865A (en) * 2014-11-25 2016-06-22 中兴通讯股份有限公司 Method and device for automatically acquiring unsymmetrical delay of 1588 links
CN106775946A (en) * 2016-12-16 2017-05-31 无锡华云数据技术服务有限公司 A kind of virtual machine Method of Creation Process
US20190097744A1 (en) * 2017-09-28 2019-03-28 Ciena Corporation Pseudowire clock recovery
CN110572230A (en) * 2019-09-10 2019-12-13 北京邮电大学 correction method and device for realizing time synchronization
CN111726189A (en) * 2020-06-15 2020-09-29 哈工大机器人(合肥)国际创新研究院 Dual-core system clock synchronization method and device based on timestamp marking circuit

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105703865A (en) * 2014-11-25 2016-06-22 中兴通讯股份有限公司 Method and device for automatically acquiring unsymmetrical delay of 1588 links
CN106775946A (en) * 2016-12-16 2017-05-31 无锡华云数据技术服务有限公司 A kind of virtual machine Method of Creation Process
US20190097744A1 (en) * 2017-09-28 2019-03-28 Ciena Corporation Pseudowire clock recovery
CN110572230A (en) * 2019-09-10 2019-12-13 北京邮电大学 correction method and device for realizing time synchronization
CN111726189A (en) * 2020-06-15 2020-09-29 哈工大机器人(合肥)国际创新研究院 Dual-core system clock synchronization method and device based on timestamp marking circuit

Also Published As

Publication number Publication date
CN118041477A (en) 2024-05-14

Similar Documents

Publication Publication Date Title
US11550819B2 (en) Synchronization cache seeding
EP3982261A1 (en) Method and apparatus for processing io
US9081709B2 (en) Virtualizable and forward-compatible hardware-software interface
US20140348182A1 (en) Time synchronization between nodes of a switched interconnect fabric
CN106775946B (en) A kind of virtual machine Method of Creation Process
Stuedi et al. jverbs: Ultra-low latency for data center applications
CN110046050B (en) Device and method for inter-core data transmission
WO2019028682A1 (en) Multi-system shared memory management method and device
TW202311977A (en) Systems and methods for sleep clock edge-based global counter synchronization in a chiplet system
WO2024098783A1 (en) Time correction method and apparatus
US9619415B2 (en) System and method for intelligent platform management interface keyboard controller style interface multiplexing
WO2016188014A1 (en) Data storage method and device
CN116848519A (en) Method and device for generating hardware interface signal and electronic equipment
WO2024016595A1 (en) Rbd-nbd mapping method and apparatus
CN115981892A (en) Log reading method and device, electronic equipment and storage medium
CN116601616A (en) Data processing device, method and related equipment
CN114510325A (en) Task scheduling method, device and system
US20230153156A1 (en) Synchronization of system resources in a multi-socket data processing system
WO2022041936A1 (en) Clock synchronization method and device in distributed system, and system
CN117971135B (en) Storage device access method and device, storage medium and electronic device
WO2024093885A1 (en) Chip system and collective communication method
US11847088B2 (en) Data transmission method and device connecting a FPGA with an ARM processor
CN117873853B (en) Data recording method, device, electronic equipment and medium
WO2024055679A1 (en) Data storage method, apparatus and system, and chip and acceleration device
KR20240095423A (en) System resource synchronization in multi-socket data processing systems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23887479

Country of ref document: EP

Kind code of ref document: A1