Time synchronization method and device and electronic equipment

By obtaining the timestamps in the hardware transmission queue and determining the deviation parameters, and adjusting the client time, the problem of difficult to balance cost and accuracy during time synchronization between the client and the server is solved, and high-precision time synchronization is achieved.

CN120238228APending Publication Date: 2025-07-01TP-LINK INT CHENGDU CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510420048.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

In the time synchronization process between the client and the server, it is difficult to balance the cost and synchronization effect. In the prior art, the timestamp accuracy of software processing data is insufficient, and adding integrated circuits such as FPGAs increases costs.

Method used

By sending a time synchronization request to the hardware transmission queue, obtaining the transmission timestamp and feedback timestamp, determining the deviation parameters, and adjusting the client time according to the deviation parameters to achieve time synchronization with the server.

Benefits of technology

The accuracy of time synchronization is improved, and the problem of poor synchronization effect of software processing data is avoided. At the same time, the problem of adding integrated circuits increases costs is avoided, and the technical problem of difficult to balance costs and synchronization effects is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120238228A_ABST
    Figure CN120238228A_ABST
Patent Text Reader

Abstract

The invention discloses a time synchronization method, a time synchronization device and electronic equipment. The method comprises the steps that a time synchronization request is sent to a hardware transmission queue, and the hardware transmission queue is a transmission queue between a processor and network interface equipment in a client side; determining a transmission timestamp corresponding to the hardware transmission queue; a synchronization response result sent by the server is received, and the synchronization response result carries a feedback timestamp; determining a deviation parameter according to the transmission timestamp and the feedback timestamp; and according to the deviation parameter, adjusting the time corresponding to the client to obtain synchronization time, so that the time of the client and the server is synchronized. According to the time synchronization method and device, the technical problem that the cost and the synchronization effect are difficult to balance when time synchronization is carried out between the client and the server in the related technology is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of time synchronization, and in particular, to a time synchronization method, apparatus, and electronic device. Background Art

[0002] In the related art, when synchronizing time between a client and a server, the software is used to process the timestamp of the data to calculate the synchronization time, which can only meet the accuracy of milliseconds, and the synchronization effect is not good. If an integrated circuit, such as an FPGA, is added, and the FPGA is used to process the timestamp of the message, there will be a problem of increasing the cost of setting up the FPGA. Therefore, when synchronizing time between a client and a server, there is a technical problem of being difficult to balance the cost and the synchronization effect.

[0003] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention

[0004] Embodiments of the present invention provide a time synchronization method, apparatus, and electronic device, so as to at least solve the technical problem that it is difficult to balance the cost and the synchronization effect when synchronizing time between a client and a server in the related art.

[0005] According to one aspect of the embodiments of the present invention, a time synchronization method is provided, including: sending a time synchronization request to a hardware transmission queue, where the time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target sending address, and the hardware transmission queue is a transmission queue between a processor and a network interface device in a client; obtaining a transmission timestamp corresponding to the hardware transmission queue; receiving a synchronization response result sent by the server, where the synchronization response result carries a feedback timestamp; determining a deviation parameter according to the transmission timestamp and the feedback timestamp; and adjusting the time corresponding to the client according to the deviation parameter to obtain a synchronization time, so that the time of the client is synchronized with the time of the server.

[0006] Optionally, the determining a deviation parameter according to the transmission timestamp and the feedback timestamp includes: in a case where the transmission timestamp is a first timestamp and the feedback timestamp is a second timestamp, determining the deviation parameter according to a first difference between the first timestamp and the second timestamp, where the first timestamp is a timestamp when the time synchronization request is sent from the hardware transmission queue, and the second timestamp is a timestamp when the server receives the time synchronization request.

[0007] Optionally, determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: when the transmission timestamp is a third timestamp and the feedback timestamp is a fourth timestamp, determining the deviation parameter according to a second difference between the third timestamp and the fourth timestamp, where the third timestamp is the timestamp when the synchronization response result enters the hardware transmission queue, and the fourth timestamp is the timestamp when the server sends the synchronization response result.

[0008] Optionally, determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: when the transmission timestamp includes a first timestamp and a third timestamp, and the feedback timestamp includes a second timestamp and a fourth timestamp, determining a first difference between the first timestamp and the second timestamp, and determining a second difference between the third timestamp and the fourth timestamp; and determining the deviation parameter according to the first difference and the second difference.

[0009] Optionally, after obtaining the transmission timestamp corresponding to the hardware transmission queue, the method further includes: determining a process timestamp for receiving the synchronization response result, where the process timestamp is a timestamp obtained through a predetermined software process; determining a processing delay according to the process timestamp and the transmission timestamp; and determining a calibration time for the predetermined software process according to the processing delay.

[0010] Optionally, determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: when there are multiple time synchronization requests, determining the transmission timestamps and feedback timestamps respectively corresponding to the multiple time synchronization requests; and determining the deviation parameter according to the transmission timestamps and feedback timestamps respectively corresponding to the multiple time synchronization requests.

[0011] According to one aspect of the embodiments of the present invention, there is provided a time synchronization device, including: a sending module, configured to send a time synchronization request to a hardware transmission queue, where the time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target sending address, and the hardware transmission queue is a transmission queue between a processor and a network interface device in a client; a first determining module, configured to obtain a transmission timestamp corresponding to the hardware transmission queue; a receiving module, configured to receive a synchronization response result sent by the server, where the synchronization response result carries a feedback timestamp; a second determining module, configured to determine a deviation parameter according to the transmission timestamp and the feedback timestamp; and an adjustment module, configured to adjust the time corresponding to the client according to the deviation parameter to obtain a synchronization time, so that the time of the client is synchronized with the time of the server.

[0012] According to one aspect of an embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium includes a stored executable program. When the executable program runs, it controls the device where the computer-readable storage medium is located to execute the method described in any one of the above.

[0013] According to one aspect of an embodiment of the present invention, an electronic device is provided, including: a memory storing an executable program; a processor for running the program. When the program runs, it executes the method described in any one of the above.

[0014] According to one aspect of an embodiment of the present invention, a computer program product is provided, including a computer program. When the computer program is executed by a processor, it implements the steps of the method described in any one of the above.

[0015] In an embodiment of the present invention, a time synchronization request is sent to the hardware transmission queue. The time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to the server corresponding to the target sending address. The hardware transmission queue is the transmission queue between the processor and the network interface device in the client; a transmission timestamp corresponding to the hardware transmission queue is determined; a synchronization response result sent by the server is received. The synchronization response result carries a feedback timestamp; a deviation parameter is determined based on the transmission timestamp and the feedback timestamp; the time corresponding to the client is adjusted based on the deviation parameter to obtain a synchronized time, so that the time of the client is synchronized with the server. That is, by determining the hardware transmission queue between two ordinary hardware devices and determining the timestamp corresponding to the data processed by the hardware transmission queue for time synchronization, the hardware transmission queue can use the hardware time source to provide accurate timestamps at the microsecond or nanosecond level. That is, it does not determine the timestamp of software processing data, avoiding the problem of poor timestamp synchronization effect of software processing data, nor does it determine the timestamp of integrated circuit processing data, avoiding the problem of increasing costs due to adding integrated circuits. Furthermore, it solves the technical problem in the related art that it is difficult to balance costs and synchronization effects when performing time synchronization between a client and a server. Description of the Drawings

[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings:

[0017] Figure 1 is a schematic diagram of the time synchronization method according to an embodiment of the present invention;

[0018] Figure 2 is a schematic diagram of a deviation parameter calculation method according to the related art;

[0019] Figure 3 It is a schematic diagram of a client configuring a programmable logic device according to related technologies;

[0020] Figure 4 It is a schematic diagram of a deviation parameter calculation method provided by an alternative embodiment of the present invention;

[0021] Figure 5 It is a structural block diagram of a time synchronization device according to an embodiment of the present invention. Detailed implementation manners

[0022] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such used data can be interchanged under appropriate circumstances so that the embodiments of the present invention described here can be implemented in an order different from those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those clearly listed steps or units, but may include other steps or units not clearly listed or inherent to these process, method, product or device.

[0024] First, some nouns or terms that appear in the process of describing the embodiments of the present application are applicable to the following explanations:

[0025] NIC: Network Interface Card, often also referred to as a "network card". It is a hardware device in a computer for connecting to a network, responsible for sending the computer's data packets to the network and receiving data packets from the network. In modern computer systems, the function of the NIC is often integrated into the motherboard and exists in the form of a chip. This form of NIC is usually referred to as an "onboard network card" or an "integrated network interface card".

[0026] NTP: Network Time Protocol, a protocol for synchronizing clocks in a distributed network environment. It allows the exchange of time information between clients and servers in a network, thereby adjusting the local clocks of the clients to achieve consistency with the server clocks.

[0027] FPGA: Field-Programmable Gate Array, which is an integrated circuit (IC) design that can be programmed by the user through software after manufacturing to implement specific digital logic functions.

[0028] According to an embodiment of the present invention, an embodiment of a time synchronization method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0029] Figure 1 is a schematic diagram of a time synchronization method according to an embodiment of the present invention, such as Figure 1 As shown, the method comprises the following steps:

[0030] Step S102, sending a time synchronization request to a hardware transmission queue, wherein the time synchronization request carries a target transmission address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target transmission address, and the hardware transmission queue is a transmission queue between a processor in a client and a network interface device;

[0031] In step S102 provided in the present application, a time synchronization request is sent to the hardware transmission queue.

[0032] Among them, the client is involved. The client refers to a device or software application that initiates a service request, which usually corresponds to the concept of a server. In the scenario of time synchronization, the client refers to those devices that need to synchronize time with the time server, such as personal computers, servers, mobile devices, IoT devices, etc.

[0033] Among them, the server is involved. The server is a device that interacts with the client. In the time synchronization scenario, the server can be a server that provides time information. It receives the client's time synchronization request, processes the request and returns a synchronization response result containing the server's time information.

[0034] Among them, the time synchronization request is a network request initiated by the client to request the server to provide time information so that the client can correct its own clock (time). For example, when the network protocol is the NTP protocol, the time synchronization request is encapsulated in a specific format, which can include the client's identification information and the local timestamp when the request is sent.

[0035] Among them, a hardware transmission queue is involved. In a network device, a hardware transmission queue is a transmission queue located between a processor (e.g., a CPU) and a network interface device (e.g., a NIC). Packets in the queue are sent onto the network according to a certain order and policy. The hardware transmission queue can directly manage the sending of packets at the hardware level, reducing the latency and uncertainty of software scheduling and improving the sending efficiency and accuracy of packets.

[0036] Among them, a target sending address is involved. The target sending address is the destination of the time synchronization request, that is, the network address (such as an IP address) of the NTP server. When the client sends a time synchronization request, it will use the server's address as the target address so that the hardware transmission queue can correctly send the request to the specified server.

[0037] This step describes an improved time synchronization method, in which the client sends a time synchronization request to the hardware transmission queue instead of the traditional software sending mechanism. The request contains the target sending address, that is, the server's address, so that the hardware transmission queue can directly send the request to the specified server without software-level intervention. The hardware transmission queue in this method specifically refers to the transmission queue between the processor and the network interface device in the client, which can more accurately record the sending time of packets and improve the accuracy of time synchronization.

[0038] That is, the hardware transmission queue is used to improve the accuracy and efficiency of time synchronization. The traditional software sending mechanism may cause inaccuracies in timestamps due to software-level delays and jitters such as CPU task scheduling and interrupt handling, and usually has a millisecond-level accuracy. While the hardware transmission queue can directly capture the sending time of packets at the hardware level, usually with a nanosecond-level accuracy, thus reducing the uncertainty in the time synchronization process.

[0039] Step S104, determine the transmission timestamp corresponding to the hardware transmission queue;

[0040] In step S104 provided in this application, the transmission timestamp corresponding to the hardware transmission queue is determined.

[0041] Among them, a transmission timestamp is involved. The transmission timestamp refers to the sending or receiving time when a packet is recorded in the hardware transmission queue, which can be adaptively set according to the actual application and scenario. The specific timestamp will be described later and will not be elaborated here. Compared with the software timestamp, the hardware transmission timestamp usually has higher accuracy because it can use the hardware clock signal to directly record the transmission moment of the packet.

[0042] This step describes the mechanism of using the hardware transmission queue to accurately record the time of packets during the time synchronization process.

[0043] Step S106: Receive the synchronization response result sent by the server. The synchronization response result carries a feedback timestamp.

[0044] In step S106 provided by this application, the synchronization response result sent by the server is received.

[0045] Among them, the synchronization response result is involved. When the server receives the time synchronization request from the client, it will generate a synchronization response message and send it to the client. This response result contains the server's time information, which is used to help the client adjust its own time.

[0046] Among them, the feedback timestamp is involved. The feedback timestamp represents the exact time when the response message leaves the server or the time when the request arrives at the server. The specific time setting can be adaptively set according to the actual application and scenario, that is, the specific timestamp will be described later and will not be elaborated here.

[0047] Receiving the synchronization response result with the feedback timestamp, because the feedback timestamp provides the accurate time when the server generates the response message, thus helping the client calculate the time deviation and round-trip delay.

[0048] Step S108: Determine the deviation parameter based on the transmission timestamp and the feedback timestamp.

[0049] In step S108 provided by this application, the deviation parameter is determined.

[0050] Among them, the deviation parameter is involved. The deviation parameter usually refers to the time offset and the round-trip delay (RTD). The time offset represents the time difference between the client clock and the server clock, while the round-trip delay represents the total transmission time from the client sending the request to the server and receiving the response. By calculating these deviation parameters through algorithms, the client can adjust its own time accordingly to achieve accurate time synchronization with the server.

[0051] Using the transmission timestamp and the feedback timestamp to determine the deviation parameter can significantly improve the accuracy of time synchronization compared to the timestamps obtained by traditional software. Since the hardware timestamp has nanosecond-level accuracy, the calculation of the deviation parameter will be more accurate, which reduces the time synchronization error caused by factors such as software scheduling delay and interrupt handling, and helps to achieve higher-precision time synchronization.

[0052] Step S110: Adjust the time corresponding to the client according to the deviation parameter to obtain the synchronization time, so that the time of the client is synchronized with that of the server.

[0053] In step S110 provided by this application, the synchronization time is obtained.

[0054] Among them, the time corresponding to the client is involved. The time corresponding to the client can refer to the clock time inside the client system, that is, the local system time on the client device.

[0055] Among them, the synchronization time is involved. The synchronization time refers to the target time to which the client should be adjusted to make it as consistent as possible with the server time. By calculating the deviation parameter and adjusting the local time accordingly, the client can achieve high-precision time synchronization with the server.

[0056] Through the above steps, a time synchronization request is sent to the hardware transmission queue. Among them, the time synchronization request carries the target sending address, so that the hardware transmission queue sends the time synchronization request to the server corresponding to the target sending address; determine the transmission timestamp corresponding to the hardware transmission queue; receive the synchronization response result sent by the server. Among them, the synchronization response result carries the feedback timestamp; determine the deviation parameter based on the transmission timestamp and the feedback timestamp; adjust the time corresponding to the client according to the deviation parameter to obtain the synchronization time, so that the time of the client is synchronized with that of the server. That is, by determining the hardware transmission queue between two ordinary hardware devices and determining the timestamp corresponding to the data processed by the hardware transmission queue for time synchronization, the hardware transmission queue can use the hardware time source to provide accurate timestamps at the microsecond or nanosecond level. That is, it does not determine the timestamp of software processing data, avoiding the problem of poor timestamp synchronization effect of software processing data, nor does it determine the timestamp of integrated circuit processing data, avoiding the problem of increasing costs due to adding integrated circuits. Furthermore, it solves the technical problem in the related art that it is difficult to balance costs and synchronization effects when performing time synchronization between the client and the server.

[0057] It should be noted that in a scenario of the synchronization method between the client and the server, multiple timestamps can be obtained, including the timestamp t1' when the client determines that the time synchronization request is sent from the hardware transmission queue, the moment t2 when the server determines that the time synchronization request arrives at the server, the timestamp t3 when the server determines that the synchronization response result leaves the server, and the timestamp t4' when the client determines that the synchronization response result enters the hardware transmission queue when receiving the synchronization response result. To determine the deviation parameter through the above t1', t2, or t3, t4', or t1', t2, t3, t4', and then achieve synchronization between the client and the server, which will be introduced below.

[0058] As an alternative embodiment, a deviation parameter is determined based on a transmission timestamp and a feedback timestamp, including: in the case where the transmission timestamp is a first timestamp and the feedback timestamp is a second timestamp, determining the deviation parameter based on a first difference between the first timestamp and the second timestamp, where the first timestamp is the timestamp when the time synchronization request is sent from the hardware transmission queue, and the second timestamp is the timestamp when the server receives the time synchronization request.

[0059] In the same scenario as above, the deviation parameter is determined through the above t1' and t2, thereby achieving synchronization between the client and the server.

[0060] In this embodiment, the process of determining the deviation parameter is described.

[0061] Among them, the first timestamp is involved, which is equivalent to the above t1'. The first timestamp is the timestamp when the time synchronization request is sent from the hardware transmission queue in the time synchronization process. This timestamp is the exact time when the time synchronization request packet is actually sent out as recorded in the hardware transmission queue, and it can provide accuracy at the nanosecond level and is not affected by CPU scheduling delays.

[0062] Specifically, there is a dedicated hardware buffer inside the network interface device for processing packets to be sent. When the time synchronization request is actually taken out of the queue by the network interface device and sent onto the network, the hardware records this time point (i.e., the moment when the request leaves the network interface device). This timestamp is very close to the time when the request is physically sent to start transmission, so it can provide a more accurate time.

[0063] Among them, the second timestamp is involved, which is equivalent to the above t2. When the server receives the time synchronization request from the client, it will feedback a timestamp in the response message, indicating the exact time point when the server receives the request. This timestamp is generated by the server and returned to the client in the response message for calculating the deviation parameter of time synchronization.

[0064] Among them, the first difference is involved. The first difference refers to the time difference between the above first timestamp and the second timestamp. This difference is the basis for calculating the time offset and round-trip delay, and it can help the client understand the propagation time of the request message in the network.

[0065] The client calculates the deviation parameter using the first difference between the request issuance time recorded by the hardware transmission queue (i.e., the first timestamp) and the received time feedback by the server (i.e., the second timestamp). In this way, the time offset between the client and the server, as well as the propagation delay of the request message in the network, can be estimated more accurately, thus achieving more precise time synchronization. The calculation of the first difference takes into account the propagation time of the message in the network, which helps to reduce the impact of network delay on the accuracy of time synchronization. Even when the network condition fluctuates, the hardware timestamp can provide a stable time reference to ensure the accuracy of time synchronization. By directly using the hardware transmission timestamp and the server feedback timestamp to determine the deviation parameter, the software processing burden of the client device is reduced, and the overall system efficiency is improved.

[0066] As an optional embodiment, determining the deviation parameter based on the transmission timestamp and the feedback timestamp includes: in the case where the transmission timestamp is the third timestamp and the feedback timestamp is the fourth timestamp, determining the deviation parameter based on the second difference between the third timestamp and the fourth timestamp, where the third timestamp is the timestamp when the synchronization response result enters the hardware transmission queue, and the fourth timestamp is the timestamp when the server sends the synchronization response result.

[0067] In the same scenario as above, the deviation parameter is determined through the above t3 and t4’, thereby achieving synchronization between the client and the server.

[0068] In this embodiment, another process for determining the deviation parameter is described.

[0069] Among them, the third timestamp is involved, which is equivalent to the above t3. The third timestamp refers to the time point when the synchronization response result enters the client hardware transmission queue. Different from the transmission timestamp of the previous request message, this is a timestamp record during the reception process of the response message, and it is also provided by the hardware timestamp function, with nanosecond-level accuracy.

[0070] Among them, the fourth timestamp is involved, which is equivalent to the above t4’. The fourth timestamp refers to the timestamp included in the synchronization response message generated and sent by the server after receiving the client's time synchronization request, indicating the exact time point when the server sends the synchronization response result.

[0071] Among them, the second difference is involved. The second difference is the interval between the reception time of the synchronization response result recorded by the client hardware transmission queue (i.e., the third timestamp) and the time when the server sends the response (i.e., the fourth timestamp). This difference is the direct data for calculating the time offset between the client and the server.

[0072] When the client receives the synchronization response result from the server, the hardware transmission queue automatically records a timestamp (i.e., the third timestamp), indicating the exact moment when the response message enters the queue. At the same time, the server carries a feedback timestamp (i.e., the fourth timestamp) in the response message, indicating the moment when the response message is generated and sent on the server side. Based on these two hardware-recorded timestamps, the client can calculate the second difference, that is, the total time for the response message to travel from the server to enter the client's hardware transmission queue. By analyzing this difference, the client can calculate the deviation parameters more accurately, including time offset and round-trip delay, so as to achieve high-precision time synchronization with the server. The use of hardware timestamps, especially the timestamps recorded when receiving response messages, can improve the client's adaptability to network delay changes, making the time synchronization algorithm more robust and maintaining a high synchronization accuracy even in poor network conditions.

[0073] As an alternative embodiment, based on the transmission timestamp and the feedback timestamp, the deviation parameters are determined, including: when the transmission timestamp includes the first timestamp and the third timestamp, and the feedback timestamp includes the second timestamp and the fourth timestamp, determining the first difference between the first timestamp and the second timestamp, and determining the second difference between the third timestamp and the fourth timestamp; based on the first difference and the second difference, determining the deviation parameters.

[0074] In the same scenario as above, the deviation parameters are determined through the above t1’, t2, t3, t4’, and then the synchronization between the client and the server is achieved.

[0075] In this embodiment, another method for determining the deviation parameters is described.

[0076] The process of using four key timestamps to determine the deviation parameters is as follows. First, the client records the first timestamp for sending the request and the third timestamp for receiving the response message, while the server records the second timestamp for receiving the request and the fourth timestamp for sending the response. Then, by calculating the first difference between the first timestamp and the second timestamp (i.e., the propagation time from the client sending the request to the server receiving the request), and the second difference between the third timestamp and the fourth timestamp (i.e., the propagation time from the server sending the response to the client receiving the response), the deviation parameters between the client and the server can be further determined. By accurately measuring these two differences through the four time points recorded by the hardware timestamp, the propagation time of the message in the network can be calculated more accurately, the deviation parameters can be calculated more accurately, and the synchronization error can be reduced, thus achieving high-precision synchronization between the client clock and the server clock.

[0077] As an alternative embodiment, after obtaining the transmission timestamp corresponding to the hardware transmission queue, the method further includes: determining the process timestamp of the process that receives the synchronization response result, where the process timestamp is a timestamp obtained through a predetermined software process; determining the processing delay based on the process timestamp and the transmission timestamp; and determining the calibration time for the predetermined software process based on the processing delay.

[0078] In this embodiment, the process of determining the calibration time is described.

[0079] Among them, the process timestamp is involved. The process timestamp refers to the current timestamp recorded by the software process when the response of the server is received and processed by the predetermined software process of the client, usually obtained in the operating system or application program, and reflects the time point when the software receives the response message.

[0080] Among them, the processing delay is involved. The processing delay refers to the time difference between the moment when the transmission timestamp of the response result is received by the hardware transmission queue and the moment when the predetermined software process receives and records the process timestamp.

[0081] Among them, the calibration time is involved. The calibration time is calculated based on the processing delay and is related to the predetermined software process. It is used to compensate for the software processing delay and align the client clock with the server clock more accurately.

[0082] This step describes the process of determining the processing delay and further calculating the calibration time by using the process timestamp and the transmission timestamp after obtaining the transmission timestamp. First, the client records the transmission timestamp when the hardware transmission queue receives the response, and then processes the response through the predetermined software process and records the current process timestamp. Next, by calculating the difference between the process timestamp and the transmission timestamp, that is, the processing delay, the additional time consumption caused by processing the response message inside the software can be evaluated. Finally, based on the processing delay, the algorithm will determine a calibration time to compensate for the impact of the software processing delay and ensure the synchronization accuracy of the client and the server time. By calculating the processing delay, the time consumption of processing the response inside the software can be compensated, the impact of the software processing delay on the time synchronization accuracy can be reduced, and the accuracy of time synchronization can be improved.

[0083] As an alternative embodiment, determining the deviation parameter based on the transmission timestamp and the feedback timestamp includes: in the case where the time synchronization request is a plurality of time synchronization requests, determining the transmission timestamp and the feedback timestamp respectively corresponding to the plurality of time synchronization requests; and determining the deviation parameter based on the transmission timestamp and the feedback timestamp respectively corresponding to the plurality of time synchronization requests.

[0084] In this embodiment, the process of determining the deviation parameter in the case where the time synchronization request is a plurality of time synchronization requests is described.

[0085] In the case where the client needs to perform multiple time synchronization requests with the server, the processing of multiple requests and responses is involved. First, the client sends multiple time synchronization requests, and each request will be recorded with a transmission timestamp by the hardware. Subsequently, each response message received from the server contains a feedback timestamp, which is used to indicate the specific time when the server receives the request and the specific time when the response is sent. The client will collect the transmission timestamp and feedback timestamp corresponding to each time synchronization request, and then use these timestamps to calculate the deviation parameters for each request respectively, including time offset and round-trip delay. By analyzing the deviation parameters of multiple requests, the accuracy and stability of time synchronization can be further improved, such as identifying and filtering abnormal time synchronization results and selecting the optimal time source for synchronization.

[0086] That is, by sending multiple time synchronization requests, multiple deviation parameter samples can be obtained, which helps to reduce the influence of accidental errors and improve the accuracy of time synchronization through methods such as statistical analysis or weighted average. Multiple requests can provide redundant data. Even if a single request is abnormal or a data packet is lost, the client can still perform time synchronization based on the deviation parameters of other requests, improving the robustness of the algorithm in a complex network environment. In addition, network latency may fluctuate over time. By regularly sending multiple time synchronization requests, the change of network latency can be monitored in real time, and the deviation parameters can be adjusted accordingly to ensure the consistency and accuracy of time synchronization.

[0087] Based on the above embodiments and optional embodiments, an optional implementation manner is provided, which is specifically described below.

[0088] In the related art, the most typical time synchronization method of NTP is the client / server method. Figure 2 It is a schematic diagram of a deviation parameter calculation method according to the related art. As Figure 2 shown, the client first sends an NTP request message to the server, which contains the timestamp t1 when the message leaves the client; the NTP request message arrives at the NTP server, and the time of the NTP server at this time is t2. When the server receives the message, after processing by the NTP server, an NTP response message is sent at time t3. The response message carries the timestamp t1 when the message leaves the NTP client, the timestamp t2 when it arrives at the NTP server, and the timestamp t3 when it leaves the NTP server; when the client receives the response message, it records the timestamp t4 when the message returns.

[0089] The client calculates the round-trip delay delay of the NTP packet from the client to the server and the time difference offset between the client and the server using the above four timestamp parameters. The NTP client adjusts its clock according to the calculated offset to achieve clock synchronization with the NTP server.

[0090] However, the NTP protocol runs on the CPU, and the timestamps obtained for the protocol are acquired at the time when the protocol packets are encapsulated by software. Due to the existence of mechanisms such as CPU task scheduling, there are delays and jitters between the time when the protocol packet is timestamped and the time when it is actually sent out from the device. Due to the delay, there will be a deviation in the time synchronized by the client. The jitter will cause a large error in the time accuracy synchronized by the client.

[0091] In addition, the currently highest-precision solution in the industry is to add programmable logic devices (FPGAs) at the device in / out ports, program to identify NTP packets, and re-edit the timestamps inside the packets to improve the precision. Figure 3 It is a schematic diagram of a client configuring a programmable logic device according to related technologies, as Figure 3 shown, but the cost of adding programmable logic devices is relatively high. This method greatly increases the hardware cost of the product. The NTP server side may not be very sensitive to cost and is willing to increase the cost for high precision. However, the client is generally a low-cost device and is thus cost-sensitive.

[0092] In view of this, an optional embodiment of the present invention provides a time synchronization method, which can obtain a high-precision standard time through the NTP protocol, enabling the terminal to keep the time unified with the entire network devices in scenarios such as network management, billing, and collaborative processing, with an accuracy within dozens of milliseconds. The present invention belongs to the technical category of the communication field. This invention is applied to network and terminal devices, and it can improve the precision of NTP clock alignment to within dozens of nanoseconds while saving costs.

[0093] This method uses the CPU hardware queue timestamp at the client to replace the timestamp for editing the packet by the FPGA, thereby removing the programmable device at the client and reducing the hardware cost. Figure 4 It is a schematic diagram of the deviation parameter calculation method provided by an optional embodiment of the present invention, as Figure 4 shown, and the following is an introduction to it:

[0094] Step 1: The client sends an NTP request packet to the server, and the timestamp t1 when the packet leaves the client included in it can be filled with any value or not carried;

[0095] Step 2: The client records the timestamp t1' (same as the above first timestamp) when the message is sent from the CPU hardware queue (same as the above hardware transmission queue).

[0096] Step 3: The NTP request message arrives at the NTP server, and the time at the NTP server at this time is t2 (same as the above second timestamp).

[0097] When the server receives this message, after processing by the NTP server, it sends an NTP response message at time t3. The response message carries the timestamp t1 when the message leaves the NTP client (it can also not carry it), the timestamp t2 when it arrives at the NTP server, and the timestamp t3 when it leaves the NTP server (same as the above fourth timestamp).

[0098] Step 4: When the client receives the response message, it records the timestamp t4' (same as the above third timestamp) when the message enters the CPU hardware queue, rather than the timestamp when the software obtains the message or the timestamp when the FPGA edits the message.

[0099] The client can calculate two key parameters using the above four timestamp parameters:

[0100] The round-trip delay delay of the NTP message from the client to the server.

[0101] Delay = (t4' - t1') - (t3 - t2);

[0102] The time difference offset between the client and the server.

[0103] offset = ((t2 - t1') + (t4' - t3)) / 2;

[0104] The NTP client adjusts its clock according to the calculated offset to achieve clock synchronization with the NTP server. That is, it uses the timestamp of the CPU hardware queue to replace the timestamp marked by the FPGA and optimizes the software algorithm to optimize the source of timestamp acquisition. Thus, the effect of achieving high-precision NTP can be achieved with less (FPGA) on the device.

[0105] It should be noted that in the above steps, the server side can also adopt similar technologies to improve the accuracy of timestamps. This technology usually involves using a hardware-assisted timestamp mechanism to reduce the delay and uncertainty brought by software processing. Using a hardware queue or other hardware mechanisms on the server side to record more accurate timestamps is an effective way to improve the accuracy of NTP time synchronization, especially in scenarios that require sub-millisecond or nanosecond accuracy.

[0106] Similar to the client-side solution, the server can also use the hardware queue of its CPU to record more accurate packet arrival and transmission times. This typically involves configuring the network interface card (NIC) to automatically record hardware timestamps when packets arrive or leave, and then embedding this timestamp information into the NTP packets.

[0107] For NIC timestamps, modern NICs usually have a timestamp engine that can provide high-precision timestamps. The server can configure the NIC to automatically add hardware timestamps when receiving or sending NTP packets, thereby improving the accuracy of time measurement.

[0108] The server may integrate a dedicated real-time clock (RTC) or a high-precision clock chip, which can provide a more stable and accurate time reference. Combining with the hardware queue or NIC timestamps, the server can generate very accurate timestamp information.

[0109] It should also be noted that the hardware optimization solution on the server side is not limited to the hardware queue timestamp, but can adopt more complex and professional hardware support according to the specific hardware configuration and application scenario of the server. Implementing hardware optimization on the server side can further improve the overall performance of NTP time synchronization, especially in scenarios where a large number of concurrent NTP requests are processed and a stable time service needs to be provided. That is, the server side can also record more accurate timestamps by using the hardware queue timestamp or other hardware mechanisms to improve the accuracy and stability of NTP time synchronization. This kind of hardware optimization is one of the key steps to achieve high-precision time synchronization. Especially for NTP servers, their authority and stability as time sources are crucial.

[0110] Through the above optional implementation manners, at least the following beneficial effects can be achieved:

[0111] The optional implementation manner of the present application improves the accuracy of the timestamp, from the ms-level accuracy obtained by software to the ns-level accuracy using hardware timestamps. Since the timestamp accuracy is improved to the ns level, the results calculated by the algorithm and the final time synchronization results are also improved to the ns level.

[0112] Figure 5 It is a structural block diagram of a time synchronization device according to an embodiment of the present invention, as Figure 5 shown. According to another aspect of the present invention, a time synchronization device is provided, including: a sending module 502, a first determination module 504, a receiving module 506, a second determination module 508, and an adjustment module 510, wherein,

[0113] A sending module 502 is configured to send a time synchronization request to a hardware transmission queue. The time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target sending address. The hardware transmission queue is a transmission queue between a processor and a network interface device in a client. A first determination module 504 is connected to the sending module 502 and is configured to obtain a transmission timestamp corresponding to the hardware transmission queue. A receiving module 506 is connected to the first determination module 504 and is configured to receive a synchronization response result sent by the server. The synchronization response result carries a feedback timestamp. A second determination module 508 is connected to the receiving module 506 and is configured to determine a deviation parameter based on the transmission timestamp and the feedback timestamp. An adjustment module 510 is connected to the second determination module 508 and is configured to adjust the time corresponding to the client according to the deviation parameter to obtain a synchronized time, so that the time of the client is synchronized with the time of the server.

[0114] The above modules correspond one by one to steps S102 to S110. The examples and application scenarios implemented by multiple modules and corresponding steps are the same, but are not limited to the content disclosed in the above embodiments.

[0115] An embodiment of the present invention may provide an electronic device. The computer device includes a memory and a processor. The memory stores an executable program. The processor is configured to run the program. The processor can call the information and application program stored in the memory through a transmission device to execute the following steps: sending a time synchronization request to a hardware transmission queue. The time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target sending address. The hardware transmission queue is a transmission queue between a processor and a network interface device in a client. Obtaining a transmission timestamp corresponding to the hardware transmission queue. Receiving a synchronization response result sent by the server. The synchronization response result carries a feedback timestamp. Determining a deviation parameter based on the transmission timestamp and the feedback timestamp. Adjusting the time corresponding to the client according to the deviation parameter to obtain a synchronized time, so that the time of the client is synchronized with the time of the server.

[0116] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware of the terminal device through a program. The program can be stored in a non-volatile storage medium. The storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.

[0117] An embodiment of the present invention also provides a computer-readable storage medium. Optionally, in this embodiment, the above computer-readable storage medium may be used to store the program code executed by the time synchronization method provided in the above embodiment.

[0118] An embodiment of the present invention also provides a computer program product, including a computer program, which implements the steps of the time synchronization method in each embodiment of the present application when executed by a processor.

[0119] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0120] In the above embodiments of the present invention, the descriptions of each embodiment have their own emphases. For the parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0121] In the several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of units or modules can be in an electrical or other form.

[0122] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0123] In addition, the functional units in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0124] When 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 computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the related technology, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs that can store program codes.

[0125] The foregoing are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A time synchronization method, characterized in that: include: Sending a time synchronization request to a hardware transmission queue, wherein the time synchronization request carries a target transmission address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target transmission address, and the hardware transmission queue is a transmission queue between a processor in a client and a network interface device; Obtaining a transmission timestamp corresponding to the hardware transmission queue; Receiving a synchronization response result sent by the server, wherein the synchronization response result carries a feedback timestamp; Determining a deviation parameter according to the transmission timestamp and the feedback timestamp; According to the deviation parameter, the time corresponding to the client is adjusted to obtain the synchronization time, so that the time of the client is synchronized with that of the server.

2. The method according to claim 1, characterized in that The determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: When the transmission timestamp is a first timestamp and the feedback timestamp is a second timestamp, a deviation parameter is determined based on a first difference between the first timestamp and the second timestamp, wherein the first timestamp is the timestamp when the time synchronization request is issued from the hardware transmission queue, and the second timestamp is the timestamp when the server receives the time synchronization request.

3. The method according to claim 1, characterized in that The determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: When the transmission timestamp is the third timestamp and the feedback timestamp is the fourth timestamp, the deviation parameter is determined based on the second difference between the third timestamp and the fourth timestamp, wherein the third timestamp is the timestamp when the synchronization response result enters the hardware transmission queue, and the fourth timestamp is the timestamp when the server sends the synchronization response result.

4. The method according to claim 1, characterized in that: The determining the deviation parameter according to the transmission timestamp and the feedback timestamp includes: In a case where the transmission timestamp includes a first timestamp and a third timestamp, and the feedback timestamp includes a second timestamp and a fourth timestamp, determining a first difference between the first timestamp and the second timestamp, and determining a second difference between the third timestamp and the fourth timestamp; The deviation parameter is determined according to the first difference and the second difference.

5. The method according to claim 1, characterized in that After obtaining the transmission timestamp corresponding to the hardware transmission queue, the method further includes: Determine a process timestamp of receiving the synchronization response result, wherein the process timestamp is a timestamp obtained through a predetermined software process; determining a processing delay based on the process timestamp and the transmission timestamp; Based on the processing delay, an alignment time with the predetermined software process is determined.

6. The method according to any one of claims 1 to 5, characterized in that Determining a deviation parameter according to the transmission timestamp and the feedback timestamp includes: In the case where the time synchronization request is a plurality of time synchronization requests, determining transmission timestamps and feedback timestamps respectively corresponding to the plurality of time synchronization requests; The deviation parameter is determined according to the transmission timestamps and feedback timestamps respectively corresponding to the multiple time synchronization requests.

7. A time synchronization device, characterized in that: include: A sending module, used for sending a time synchronization request to a hardware transmission queue, wherein the time synchronization request carries a target sending address, so that the hardware transmission queue sends the time synchronization request to a server corresponding to the target sending address, and the hardware transmission queue is a transmission queue between a processor in a client and a network interface device; A first determining module, configured to obtain a transmission timestamp corresponding to the hardware transmission queue; A receiving module, configured to receive a synchronization response result sent by the server, wherein the synchronization response result carries a feedback timestamp; A second determination module, configured to determine a deviation parameter according to the transmission timestamp and the feedback timestamp; The adjustment module is used to adjust the time corresponding to the client according to the deviation parameter to obtain the synchronization time so as to synchronize the time of the client with that of the server.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 6.

9. An electronic device, characterized in that: include: A memory storing an executable program; A processor, configured to run the program, wherein the program executes the method according to any one of claims 1 to 6 when running.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.