Clock synchronization methods, devices, boards, and computer-readable storage media
By encapsulating timestamps in the service cards and using high-priority IPU channels for time synchronization, the problem of timestamp errors during interaction between the master control card and service cards in distributed devices is solved, enabling accurate clock deviation calculation and system time consistency between the master control card and the NTP server.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MAIPU COMM TECH CO LTD
- Filing Date
- 2023-08-30
- Publication Date
- 2026-05-26
AI Technical Summary
In distributed devices, the large error between the timestamps sent and received by the device due to the interaction between the master control card and the service card through the IPU channel leads to a large clock offset error calculated by the master control card.
By encapsulating device sending and receiving timestamps in NTP request and response messages based on the current system time in the service card, and calculating the network clock deviation in the main control card, time synchronization is performed using high-priority IPU channels, thus avoiding timestamp errors caused by IPU queue congestion and CPU overload.
This ensures accurate network clock deviation calculated by the main control card, avoiding timestamp errors caused by IPU queue congestion and CPU overload, and achieving consistent synchronization of system time between the main control card and the service card.
Smart Images

Figure CN117155504B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network time synchronization technology, and more specifically, to a clock synchronization method, apparatus, board, and computer-readable storage medium. Background Technology
[0002] Currently, NTP (Network Time Protocol) is widely deployed in customer network environments. All network devices within the same network environment, acting as clients, need to periodically synchronize their time with a single NTP server.
[0003] In existing technology, the master control card in a distributed device can generate an NTP request message and encapsulate it with its current time as a sending timestamp. This NTP request message is then sent to a service card in the distributed device, which in turn forwards it to an NTP server. The NTP server fills the NTP request message with its receiving timestamp and the timestamp of its sending response message, generating an NTP response message, which it then sends to the service card. The service card forwards the NTP response message to the master control card. In this case, the master control card can determine the time of receiving the NTP response message as its receiving timestamp, and then calculate the clock offset based on the receiving timestamp and the NTP response message to adjust the master control card's system time.
[0004] However, since the master control card and service card in the distributed device need to exchange information through the IPU (Inter-Process Unit) channel, as the service volume of the distributed device increases, the IPU queue will become congested and the CPU in the service card will be busy. Therefore, there will be a large error between the timestamp sent by the device and the timestamp received by the device, which in turn will lead to a large error in the clock offset calculated by the master control card. Summary of the Invention
[0005] In view of this, the purpose of this application is to provide a clock synchronization method, device, board and computer-readable storage medium to solve the problem in the prior art that there is a large error between the device sending timestamp and the device receiving timestamp, which in turn leads to a large error in the clock offset calculated by the main control card.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows:
[0007] In a first aspect, this application provides a clock synchronization method applied to a service card in a distributed device, the distributed device further including a master control card, the service card being communicatively connected to the master control card and an NTP server respectively, the method comprising:
[0008] Receive the first NTP request message sent by the main control card; wherein, the main control system time of the main control card sending the first NTP request message is consistent with the service system time of the service card;
[0009] Based on the first current business system time, the device sending timestamp is encapsulated in the first NTP request message to obtain the second NTP request message, and the second NTP request message is sent to the NTP server;
[0010] The system receives a second NTP response message sent by the NTP server and encapsulates a device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message; the second NTP response message is obtained by the NTP server encapsulating a server receiving timestamp and a server sending timestamp in the second NTP request message.
[0011] The first NTP response message is sent to the main control card, so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card according to the network clock deviation.
[0012] In an optional implementation, the step of encapsulating a device sending timestamp in the first NTP request message according to the first current business system time to obtain a second NTP request message includes:
[0013] Obtain the pre-stored transmission delay compensation time; the transmission delay compensation time is the hardware transmission delay time of the service card;
[0014] The sum of the first current business system time and the transmission delay compensation time is used as the device transmission timestamp and encapsulated into the first NTP request message to obtain the second NTP request message.
[0015] In an optional implementation, the step of encapsulating a device reception timestamp in the second NTP response message according to the second current business system time to obtain the first NTP response message includes:
[0016] Obtain the pre-stored reception delay compensation time; the reception delay compensation time is the hardware reception delay time of the service card;
[0017] The sum of the second current business system time and the receiving delay compensation time is used as the device receiving timestamp and encapsulated into the second NTP response message to obtain the first NTP response message.
[0018] In an optional implementation, after sending the first NTP response message to the main control card, the method further includes:
[0019] The system receives the network clock deviation sent by the main control card and adjusts the service system time of the service card according to the network clock deviation.
[0020] In an optional implementation, the method further includes:
[0021] A device time request message is sent to the main control card, so that the main control card encapsulates the main control receiving timestamp and the main control sending timestamp in the device time request message, generates a device time response message, and sends the device time response message to the service card; wherein, the device time request message includes the service sending timestamp;
[0022] Determine the service reception timestamp of the device time response message, and calculate the system clock deviation between the service system time and the main control system time based on the service reception timestamp, the service transmission timestamp in the device time response message, the main control reception timestamp, and the main control transmission timestamp.
[0023] If the system clock deviation exceeds a preset deviation threshold, the business system time is adjusted according to the system clock deviation so that the business system time of the business card is consistent with the main control system time of the main control card.
[0024] Secondly, this application provides a clock synchronization method applied to a master control card in a distributed device, wherein the distributed device further includes a service card, the service card being communicatively connected to the master control card and an NTP server respectively, and the method includes:
[0025] When the business system time of the service card is consistent with the main control system time of the main control card, a first NTP request message is sent to the service card, so that the service card encapsulates the device sending timestamp in the first NTP request message according to the first current business system time to obtain a second NTP request message, and sends the second NTP request message to the NTP server, receives the second NTP response message sent by the NTP server, and encapsulates the device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message;
[0026] The system receives the first NTP response message sent by the service card, calculates the network clock deviation between itself and the NTP server based on the first NTP response message, and adjusts the time of the main control system based on the network clock deviation.
[0027] In an optional implementation, calculating the network clock offset with the NTP server based on the first NTP response message includes:
[0028] Based on the device sending timestamp, the server receiving timestamp, the server sending timestamp, and the device receiving timestamp in the first NTP response message, calculate the network clock offset between the device and the NTP server.
[0029] Thirdly, this application provides a clock synchronization device applied to a service card in a distributed device, wherein the distributed device further includes a master control card, and the service card is communicatively connected to the master control card and an NTP server respectively. The device includes:
[0030] The receiving module is configured to receive a first NTP request message sent by the main control card when the service system time of the service card is consistent with the main control system time of the main control card.
[0031] The encapsulation module is used to encapsulate the device sending timestamp in the first NTP request message according to the first current business system time, obtain the second NTP request message, and send the second NTP request message to the NTP server;
[0032] The encapsulation module is further configured to receive a second NTP response message sent by the NTP server, and encapsulate a device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message; the second NTP response message is obtained by the NTP server encapsulating a server receiving timestamp and a server sending timestamp in the second NTP request message;
[0033] The encapsulation module is further configured to send the first NTP response message to the main control card, so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card based on the network clock deviation.
[0034] Fourthly, this application provides a clock synchronization device applied to a master control card in a distributed device. The distributed device further includes a service card, which is communicatively connected to the master control card and an NTP server. The device includes:
[0035] The NTP module is used to send a first NTP request message to the service card when the service system time of the service card is consistent with the main control system time of the main control card. The service card encapsulates a device sending timestamp in the first NTP request message according to the first current service system time to obtain a second NTP request message, and sends the second NTP request message to the NTP server. The service card receives a second NTP response message sent by the NTP server, and encapsulates a device receiving timestamp in the second NTP response message according to the second current service system time to obtain a first NTP response message.
[0036] The calculation module is used to receive the first NTP response message sent by the service card, calculate the network clock deviation between the system and the NTP server based on the first NTP response message, and adjust the time of the main control system based on the network clock deviation.
[0037] Fifthly, this application provides a board including a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the method described in any of the foregoing embodiments.
[0038] In a sixth aspect, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any of the foregoing embodiments.
[0039] The clock synchronization method, apparatus, board, and computer-readable storage medium provided in this application embodiment allow the main control card to send a first NTP request message. When the main control card sends a first NTP request message, the service card's service system time is consistent with the main control card's main control system time. The service card can encapsulate a device sending timestamp in the first NTP request message sent by the main control card according to the first current service system time, thereby obtaining a second NTP request message. The service card then sends the second NTP request message to the NTP server. Afterward, it receives a second NTP response message sent by the NTP server, encapsulates a device receiving timestamp in the second NTP response message according to the second current service system time, thereby obtaining a first NTP response message. After sending the first NTP response message to the main control card, the main control card can directly calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and then adjust the main control system time according to the network clock deviation. Since the system time of the service card and the main control card are consistent, the service card encapsulates the device send timestamp and the device receive timestamp. This avoids the problem of large errors in the device send timestamp and device receive timestamp caused by IPU queue congestion or CPU busyness in the service card, thus ensuring that the network clock deviation calculated by the main control card will not have large errors.
[0040] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0041] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 An example diagram of a clock synchronization method in the prior art is shown;
[0043] Figure 2 A block diagram of a clock synchronization network is shown.
[0044] Figure 3 A block diagram of the board provided in an embodiment of this application is shown;
[0045] Figure 4 This paper illustrates a flowchart of a clock synchronization method for a service card provided in an embodiment of this application.
[0046] Figure 5 This paper illustrates another flowchart of a clock synchronization method for a service card provided in an embodiment of this application.
[0047] Figure 6 This paper illustrates a flowchart of a clock synchronization method for a main control card provided in an embodiment of this application.
[0048] Figure 7 This paper illustrates a functional block diagram of a clock synchronization device applied to a service card, according to an embodiment of this application.
[0049] Figure 8 This illustration shows a functional block diagram of a clock synchronization device applied to a master control card, according to an embodiment of this application.
[0050] Icons: 10-Clock synchronization network; 100-Distributed device; 101-Main control card; 102-Service card; 110-NTP server; 20-Board; 200-Memory; 210-Processor; 220-Communication module; 300-Receiver module; 310-Encapsulation module; 400-Transmitter module; 410-Computing module. Detailed Implementation
[0051] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations.
[0052] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0053] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0054] To facilitate understanding of the solution in this application, the problems existing in the prior art are described in detail below with reference to the illustrations.
[0055] Figure 1 For an example diagram of a clock synchronization method in the prior art, please refer to [link / reference]. Figure 1 Distributed devices need to act as NTP clients to synchronize their clocks with the NTP server. During clock synchronization, the master control card in the distributed device can generate an NTP request message and encapsulate the current time T1 of the master control card as the device's sending timestamp in the NTP request message. Then, the master control card sends the NTP request message to the service card, which forwards the NTP request message to the NTP server.
[0056] When an NTP server receives an NTP request message, it can encapsulate the server's receiving timestamp in the NTP request message based on the system time T2 when it receives the NTP request message, and encapsulate the server's sending timestamp in the NTP request message based on the system time T3 when it sends the message, thereby generating an NTP response message and sending it to the service card.
[0057] After receiving the NTP response message, the service card can forward the time response message to the main control card. The main control card can then determine the time T4 of receiving the NTP response message as the device receiving timestamp, and calculate the clock offset based on the device receiving timestamp and the NTP response message to adjust the system time of the main control card.
[0058] In addition, the master control card will send the adjusted system time T5 to the service card, and the service card can then adjust its system time according to the adjusted system time of the master control card.
[0059] However, since the master control card and service cards in the distributed device need to exchange information through the IPU (Inter-Process Unit) channel, and as the workload of the distributed device increases, it can lead to congestion in the IPU queue and excessive CPU usage on the service cards. Therefore, this process mainly has the following problems:
[0060] 1. There is a large error between the device sending timestamp and the device receiving timestamp recorded by the master control card. That is, the time when the master control card sends the NTP request message is not actually the time when the NTP request message is sent from the distributed device, and the time when the master control card receives the NTP response message is not the time when the distributed device receives the NTP response message. Therefore, the clock offset calculated by the master control card will have a large error.
[0061] 2. The error between the system time adjusted by the service card and the system time adjusted by the main control card is large. That is, although the main control card sends the adjusted system time to the service card, due to the congestion of the IPU channel and the busy CPU in the service card, the actual system time adjusted by the service card is already significantly different from the system time adjusted by the main control card.
[0062] Based on this, embodiments of this application provide a clock synchronization method, apparatus, board, and computer-readable storage medium to solve the above-mentioned problems.
[0063] Figure 2 Please refer to the block diagram of a clock synchronization network 10. Figure 2 The clock synchronization network 10 includes at least one distributed device 100 and an NTP server 110, wherein the distributed device 100 includes a master control card 101 and a service card 102.
[0064] Optionally, the service card 102 is communicatively connected to the main control card 101 and the NTP server 110, respectively.
[0065] In this embodiment, the distributed device 100 may be equipped with multiple service cards, and the service card refers to the service card among the multiple service cards that needs to perform the NTP network clock synchronization task.
[0066] Optionally, the main control card, or MPU (Main Processing Unit), is responsible for the control and management of the system; the service card, or LPU (Line Processing Unit), includes multiple interfaces for processing the reception and transmission of data packets.
[0067] Optionally, Figure 3 This is a block diagram of the board 20 provided in the embodiments of this application. It can be understood that the board 20 can be as described above. Figure 2 The main control card 101 in the middle can also be the one mentioned above. Figure 2 Business card 102 in the middle.
[0068] Please see Figure 3 The board 20 includes a memory 200, a processor 210, and a communication module 220. The memory 200, processor 210, and communication module 220 are electrically connected directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines.
[0069] The memory 200 is used to store programs or data. The memory 200 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0070] The processor 210 is used to read / write data or programs stored in memory and to perform corresponding functions.
[0071] The communication module 220 is used to establish a communication connection between the board 20 and other communication terminals via the network, and to send and receive data via the network.
[0072] It should be understood that, Figure 3 The structure shown is only a schematic diagram of board 20. Board 20 may also include more than Figure 3 The more or fewer components shown, or having the same Figure 3 The different configurations shown. Figure 3 The components shown can be implemented using hardware, software, or a combination thereof.
[0073] The following is based on the above. Figure 2 The service card in the diagram serves as the execution entity. The clock synchronization method provided in this application embodiment will be described executively with reference to the flowchart. Specifically, Figure 4 For a flowchart illustrating a clock synchronization method for a service card provided in this application embodiment, please refer to [link / reference]. Figure 4 The method includes:
[0074] Step S20: Receive the first NTP request message sent by the main control card.
[0075] In this case, the master control card sends the first NTP request message at the same time as the business system time of the business card.
[0076] Optionally, when the master control card sends the first NTP request message, its master control system time is consistent with the service system time of the service card.
[0077] Optionally, the master control card can send the first NTP request message to the service card through the IPU channel.
[0078] Optionally, the main control card can send the first NTP request message to the NTP server every preset time interval to perform clock synchronization.
[0079] Step S21: Based on the first current business system time, encapsulate the device sending timestamp in the first NTP request message to obtain the second NTP request message, and send the second NTP request message to the NTP server.
[0080] Among them, the first current business system time is the business system time when the business card sends the second NTP request message.
[0081] Optionally, the device sends a timestamp that is the time the second NTP request message is sent from the distributed device. It is understood that the second NTP request message is a first NTP request message encapsulated with the device's timestamp.
[0082] Step S22: Receive the second NTP response message sent by the NTP server, and encapsulate the device receiving timestamp in the second NTP response message according to the second current business system time to obtain the first NTP response message.
[0083] The second NTP response message is obtained by the NTP server encapsulating the server's receiving timestamp and the server's sending timestamp in the second NTP request message; the second current business system time is the business system time when the business card receives the second NTP response message.
[0084] Optionally, the server receive timestamp refers to the time when the NTP server receives the second NTP request message; the server send timestamp refers to the time when the NTP server sends the network response message.
[0085] Optionally, the NTP server can receive a second NTP request message and directly encapsulate the server's receiving timestamp and server's sending timestamp in the second NTP request message to generate a second NTP response message, which is then sent to the service card.
[0086] Understandably, the second NTP response message contains the device sending timestamp, the server receiving timestamp, and the server sending timestamp.
[0087] Optionally, the device receive timestamp is the time when the distributed device receives the second NTP response message. Optionally, the service card can encapsulate the device receive timestamp in the second NTP response message to obtain the first NTP response message.
[0088] Understandably, the first NTP response message includes the device sending timestamp, the server receiving timestamp, the server sending timestamp, and the device receiving timestamp.
[0089] Optionally, considering that the device receive timestamp cannot be encapsulated in the NTP standard protocol message, in this embodiment, the content of the second NTP response message can be expanded so that the device receive timestamp is encapsulated at the end of the second NTP response message.
[0090] Step S23: Send the first NTP response message to the main control card so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card according to the network clock deviation.
[0091] Optionally, the network clock skew refers to the deviation between the master control card's master system time and the NTP server's server system time.
[0092] In this embodiment, the main control card can adjust the main control system time according to the calculated network clock deviation, so that the main control system time is synchronized with the server system time of the NTP server.
[0093] The clock synchronization method provided in this application embodiment involves a service card whose service system time is consistent with the main control card's main control system time when the main control card sends a first NTP request message. The service card can encapsulate a device sending timestamp in the first NTP request message sent by the main control card according to the first current service system time to obtain a second NTP request message, and then send the second NTP request message to the NTP server. After receiving the second NTP response message sent by the NTP server, the service card encapsulates a device receiving timestamp in the second NTP response message according to the second current service system time to obtain a first NTP response message. After sending the first NTP response message to the main control card, the main control card can directly calculate the network clock deviation between the main control card and the NTP server according to the first NTP response message, and then adjust the main control system time according to the network clock deviation. Since the system time of the service card and the main control card are consistent, the service card encapsulates the device send timestamp and the device receive timestamp. This avoids the problem of large errors in the device send timestamp and device receive timestamp caused by IPU queue congestion or CPU busyness in the service card, thus ensuring that the network clock deviation calculated by the main control card will not have large errors.
[0094] Optionally, after calculating the network clock deviation between the main control card and the NTP server based on the first NTP response message, the main control card needs to adjust not only the main control system time of the main control card, but also the service system time of the service card, so that the service system time of the service card is synchronized with the adjusted main control system time.
[0095] In one possible implementation, since the system time of the master control card and the service card is consistent before adjustment, the master control card can directly send the calculated network clock deviation to the service card. The service card can then receive the network clock deviation sent by the master control card and adjust the service system time of the service card according to the network clock deviation.
[0096] Optionally, the master control card can send the adjusted master control system time or network clock offset through a high-priority IPU channel.
[0097] Optionally, in order to ensure the stable data synchronization of the high-priority IPU channel and prevent it from being affected by other business factors, the high-priority IPU channel can be used only for time synchronization between the main control card and the service card, that is, only the high-priority IPU channel is used to send data for time synchronization between the main control card and the service card.
[0098] In this embodiment, since the service system time of the service card is consistent with the master control system time of the master control card, the master control card directly sends the network clock deviation to the service card for adjustment. This not only ensures that the master control system time adjusted by the master control card is consistent with the service system time adjusted by the service card, but also ensures that there will be no large error between the master control system time adjusted by the master control card and the service system time adjusted by the service card.
[0099] In one possible implementation, the service card can directly encapsulate the first current service system time as the device sending timestamp into the first NTP request message, and directly encapsulate the second current service system time as the device receiving timestamp into the second NTP response message.
[0100] In another possible implementation, considering that hardware drivers will have a certain message link transmission and reception delay when they are close to the underlying driver message transmission and reception layer, in order to ensure that the device transmission time is more accurate, the message link transmission and reception delay of the service card can be tested in advance to determine the corresponding transmission delay compensation time and reception delay compensation time, so as to perform hardware delay compensation on the first current business system time and the second current business system time when determining the device transmission timestamp and the device reception timestamp.
[0101] Specifically, the service card can achieve the following steps in step S21 above: encapsulating the device sending timestamp in the first NTP request message according to the first current service system time to obtain the second NTP request message:
[0102] Obtain the pre-stored transmission delay compensation time; the transmission delay compensation time is the hardware transmission delay time of the service card; encapsulate the sum of the first current service system time and the transmission delay compensation time as the device transmission timestamp into the first NTP request message to obtain the second NTP request message.
[0103] Optionally, the transmission delay compensation time refers to the response time of the corresponding interface when the service card sends the second NTP request message.
[0104] Understandably, at this time, the device's sending timestamp should be the sum of the first current business system time and the sending delay compensation time.
[0105] Furthermore, the service card can also achieve the following steps in step S22 above: encapsulating the device's received timestamp in the second NTP response message according to the second current service system time to obtain the first NTP response message:
[0106] Obtain the pre-stored receive delay compensation time; the receive delay compensation time is the hardware receive delay time of the service card; encapsulate the sum of the second current service system time and the receive delay compensation time as the device receive timestamp into the second NTP response message to obtain the first NTP response message.
[0107] Optionally, the receive delay compensation time refers to the response time of the corresponding interface of the service card when it receives the second NTP request message.
[0108] Understandably, at this point, the device's received timestamp should be the sum of the second current business system time and the sending delay compensation time.
[0109] Optionally, before synchronizing the clocks between the main control card and the NTP server, it should be ensured that the main control system time of the main control card is consistent with the business system time of the business card.
[0110] Specifically, in Figure 4 On this basis, Figure 5 For another flowchart illustrating the clock synchronization method for service cards provided in this application embodiment, please refer to [link / reference]. Figure 5 The method also includes:
[0111] Step S10: Send a device time request message to the main control card so that the main control card can encapsulate the main control receiving timestamp and the main control sending timestamp in the device time request message, generate a device time response message, and send the device time response message to the service card.
[0112] The device time request message includes the service sending timestamp;
[0113] Optionally, the service card can send a device time request message to the master control card through a high-priority IPU channel.
[0114] In this embodiment, the service card can encapsulate the service sending timestamp in the device time request message, and the master control card can encapsulate the master control receiving timestamp and the master control sending timestamp in the device time request message, thereby generating a device time response message.
[0115] Understandably, the service sending timestamp refers to the service system time when the service card sends the device time request message; the master control receiving timestamp refers to the master control system time when the master control card receives the device time request message; and the master control sending timestamp refers to the master control system time when the master control card sends the device time response message.
[0116] Step S11: Determine the service reception timestamp of the receiving device time response message, and calculate the system clock deviation between the service system time and the master control system time based on the service reception timestamp and the service transmission timestamp, master control reception timestamp, and master control transmission timestamp in the device time response message.
[0117] Optionally, the service reception timestamp refers to the service system time when the service card receives the device time response message.
[0118] In this embodiment, the service card can calculate the system clock deviation between the service system time and the master control system time based on the service reception timestamp and the service transmission timestamp, master control reception timestamp, and master control transmission timestamp in the device time response message. In one possible implementation, the service card can calculate the system clock deviation between the service system time and the master control system time using the following formula:
[0119]
[0120] Where A represents the system clock deviation between the service system time and the master control system time, T1 represents the service transmission timestamp, T2 represents the master control reception timestamp, T3 represents the master control transmission timestamp, and T4 represents the service reception timestamp.
[0121] Optionally, the service card can also calculate the round-trip delay between the master control card and the service card based on the service reception timestamp and the service transmission timestamp, master control reception timestamp, and master control transmission timestamp in the device time response message:
[0122] In one possible implementation, the service card can calculate the round-trip latency between the main control card and the service card using the following formula:
[0123]
[0124] Where B represents the round-trip delay of messages between the master control card and the service card, T1 represents the service sending timestamp, T2 represents the master control receiving timestamp, T3 represents the master control sending timestamp, and T4 represents the service receiving timestamp.
[0125] Step S12: If the system clock deviation exceeds the preset deviation threshold, the business system time is adjusted according to the system clock deviation so that the business system time of the business card is consistent with the main control system time of the main control card.
[0126] Optionally, if the system clock deviation between the master control system time of the master control card and the business system time of the business card is within a preset deviation value, then the master control system time of the master control card and the business system time of the business card can be considered to be consistent.
[0127] In this embodiment, if the system clock deviation exceeds a preset deviation threshold, the service card needs to adjust the service system time according to the system clock deviation so that the service system time of the service card is consistent with the main control system time of the main control card.
[0128] In one possible implementation, the consistency between the master control system time of the master control card and the business system time of the business card can be maintained through different threads, as well as the clock synchronization between the master control system time of the master control card and the server system time of the NTP server in the distributed device.
[0129] However, it should be emphasized that when the master control card sends the first NTP request message, the master control system time of the first NTP request message should be consistent with the business system time of the service card.
[0130] The following is based on the above. Figure 2 The main control card in this application is the execution entity. The clock synchronization method provided in this embodiment, illustrated in conjunction with a flowchart, will be described executively. Specifically, Figure 6 For a flowchart illustrating a clock synchronization method applied to a main control card provided in an embodiment of this application, please refer to [link / reference]. Figure 6 The method includes:
[0131] Step S30: When the business system time of the service card is consistent with the main control system time of the main control card, a first NTP request message is sent to the service card so that the service card can encapsulate the device sending timestamp in the first NTP request message according to the first current business system time to obtain a second NTP request message, and send the second NTP request message to the NTP server, receive the second NTP response message sent by the NTP server, and encapsulate the device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message;
[0132] Step S31: Receive the first NTP response message sent by the service card, calculate the network clock deviation between the system and the NTP server based on the first NTP response message, and adjust the time of the main control system according to the network clock deviation.
[0133] The clock synchronization method provided in this application embodiment ensures that the service card's system time is consistent with the main control card's system time. The service card can encapsulate a device transmission timestamp in a first NTP request message sent by the main control card based on the first current service system time, thereby obtaining a second NTP request message. This second NTP request message is then sent to the NTP server. Subsequently, the service card receives a second NTP response message from the NTP server, encapsulates a device reception timestamp in this second NTP response message based on the second current service system time, thereby obtaining a first NTP response message. This first NTP response message is then sent to the main control card. The main control card can then directly calculate the network clock deviation between itself and the NTP server based on the first NTP response message, and adjust its main control system time accordingly. Since the system times of the service card and the main control card are consistent, encapsulating the device transmission and reception timestamps by the service card avoids large errors in the device transmission and reception timestamps caused by IPU queue congestion or CPU overload in the service card, thus ensuring that the network clock deviation calculated by the main control card will not have significant errors.
[0134] Optionally, the main control card can calculate the network clock offset between itself and the NTP server based on the device sending timestamp, server receiving timestamp, server sending timestamp, and device receiving timestamp in the first NTP response message.
[0135] Alternatively, the main control card can calculate the network clock offset with the NTP server using the following formula:
[0136]
[0137] Wherein, C represents the network clock deviation between the master control system time and the NTP server, T5 represents the device sending timestamp, T6 represents the server receiving timestamp, T7 represents the server sending timestamp, and T8 represents the device receiving timestamp.
[0138] In addition, the main control card can also calculate the round-trip delay between the main control card and the NTP server based on the device's sending timestamp, the server's receiving timestamp, the server's sending timestamp, and the device's receiving timestamp.
[0139] In one possible implementation, the service card can calculate the round-trip latency between the main control card and the NTP server using the following formula:
[0140]
[0141] Among them, D represents the round-trip delay of messages between the main control card and the NTP server, T5 represents the device sending timestamp, T6 represents the server receiving timestamp, T7 represents the server sending timestamp, and T8 represents the device receiving timestamp.
[0142] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a clock synchronization device applied to a service card is given below. Further, please refer to... Figure 7 , Figure 7 This is a functional block diagram of a clock synchronization device applied to a service card, provided as an embodiment of this application. It should be noted that the basic principle and technical effects of the clock synchronization device provided in this embodiment are the same as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. The clock synchronization device includes: a receiving module 300 and an encapsulation module 310.
[0143] The receiving module 300 is used to receive the first NTP request message sent by the master control card; wherein the master control system time of the master control card sending the first NTP request message is consistent with the service system time of the service card.
[0144] Understandably, the receiving module 300 can also be used to perform the above step S20.
[0145] The encapsulation module 310 is used to encapsulate the device sending timestamp in the first NTP request message according to the first current business system time, obtain the second NTP request message, and send the second NTP request message to the NTP server.
[0146] Understandably, the encapsulation module 310 can also be used to perform the above step S21.
[0147] The encapsulation module 310 is also used to receive a second NTP response message sent by the NTP server, and to encapsulate the device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message; the second NTP response message is obtained by the NTP server encapsulating the server receiving timestamp and the server sending timestamp in the second NTP request message.
[0148] Understandably, the encapsulation module 310 can also be used to perform the above step S22.
[0149] The encapsulation module 310 is also used to send the first NTP response message to the main control card, so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card according to the network clock deviation.
[0150] Understandably, the encapsulation module 310 can also be used to perform the above step S23.
[0151] Optionally, the encapsulation module 310 is further configured to obtain a pre-stored transmission delay compensation time; the transmission delay compensation time is the hardware transmission delay time of the service card; and the sum of the first current service system time and the transmission delay compensation time is encapsulated as a device transmission timestamp into the first NTP request message to obtain the second NTP request message.
[0152] Optionally, the encapsulation module 310 is further configured to obtain a pre-stored reception delay compensation time; the reception delay compensation time is the hardware reception delay time of the service card; and the sum of the second current service system time and the reception delay compensation time is encapsulated as a device reception timestamp into the second NTP response message to obtain the first NTP response message.
[0153] Optionally, the encapsulation module 310 is also used to receive the network clock deviation sent by the main control card and adjust the service system time of the service card according to the network clock deviation.
[0154] Optionally, the receiving module 300 is further configured to send a device time request message to the master control card, so that the master control card encapsulates the master control receiving timestamp and the master control sending timestamp in the device time request message, generates a device time response message, and sends the device time response message to the service card; wherein, the device time request message includes a service sending timestamp; the service receiving timestamp of the received device time response message is determined, and the system clock deviation between the service system time and the master control system time is calculated based on the service receiving timestamp and the service sending timestamp, master control receiving timestamp, and master control sending timestamp in the device time response message; if the system clock deviation exceeds a preset deviation threshold, the service system time is adjusted according to the system clock deviation so that the service system time of the service card is consistent with the master control system time of the master control card.
[0155] Optionally, the receiving module 300 can also be used to perform the above steps S10 to S12.
[0156] The clock synchronization device provided in this application embodiment receives a first NTP request message sent by the main control card when the service system time of the service card is consistent with the main control card's main control system time through a receiving module; it encapsulates a device sending timestamp into the first NTP request message according to the first current service system time through an encapsulation module to obtain a second NTP request message, and sends the second NTP request message to the NTP server; it receives a second NTP response message sent by the NTP server, and encapsulates a device receiving timestamp into the second NTP response message according to the second current service system time to obtain a first NTP response message. The second NTP response message is obtained by the NTP server encapsulating the server's receive timestamp and server's send timestamp in the second NTP request message. The first NTP response message is sent to the main control card so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card according to the network clock deviation. This can avoid the problem of large errors in the device send timestamp and device receive timestamp caused by IPU queue congestion or CPU busyness in the service card, thus ensuring that the network clock deviation calculated by the main control card will not have large errors.
[0157] Optionally, Figure 8 For a functional block diagram of a clock synchronization device applied to a main control card provided in an embodiment of this application, please refer to [link / reference]. Figure 8 The clock synchronization device includes a transmitting module 400 and a computing module 410.
[0158] The sending module 400 is used to send a first NTP request message to the service card when the service system time of the service card is consistent with the main control system time of the main control card. The service card encapsulates the device sending timestamp in the first NTP request message according to the first current service system time to obtain a second NTP request message, and sends the second NTP request message to the NTP server. The service card receives a second NTP response message sent by the NTP server, and encapsulates the device receiving timestamp in the second NTP response message according to the second current service system time to obtain a first NTP response message.
[0159] Understandably, the sending module 400 can also be used to perform the above step S30.
[0160] The calculation module 410 is used to receive the first NTP response message sent by the service card, calculate the network clock deviation between the main control system and the NTP server based on the first NTP response message, and adjust the main control system time based on the network clock deviation.
[0161] Understandably, the calculation module 410 can also be used to perform the above step S31.
[0162] Optionally, the calculation module 410 is also used to calculate the network clock deviation between itself and the NTP server based on the device sending timestamp, server receiving timestamp, server sending timestamp, and device receiving timestamp in the first NTP response message.
[0163] The clock synchronization device provided in this application embodiment, through a sending module, sends a first NTP request message to the service card when the service system time of the service card is consistent with the main control system time of the main control card. The service card then encapsulates a device transmission timestamp in the first NTP request message based on the first current service system time to obtain a second NTP request message, and sends the second NTP request message to the NTP server. The service card then receives a second NTP response message from the NTP server and encapsulates a device reception timestamp in the second NTP response message based on the second current service system time to obtain a first NTP response message. A calculation module receives the first NTP response message from the service card, calculates the network clock deviation between the service card and the NTP server based on the first NTP response message, and adjusts the main control system time according to the network clock deviation. This avoids problems such as large errors in the device transmission timestamp and device reception timestamp caused by IPU queue congestion or CPU overload in the service card, thus ensuring that the network clock deviation calculated by the main control card will not have large errors.
[0164] Optionally, the above modules can be stored in the form of software or firmware. Figure 3 The memory shown is either stored in or embedded in the operating system (OS) of the board, and can be used by... Figure 3 The processor executes the commands. Meanwhile, the data and program code required to execute these modules can be stored in memory.
[0165] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, can implement the clock synchronization method provided in this application.
[0166] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0167] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0168] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0169] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A clock synchronization method, characterized in that, A service card used in a distributed device, the distributed device further including a master control card, the service card being communicatively connected to the master control card and an NTP server respectively, the method comprising: Receive the first NTP request message sent by the main control card; wherein, the main control system time of the main control card sending the first NTP request message is consistent with the service system time of the service card; Based on the first current business system time, the device sending timestamp is encapsulated in the first NTP request message to obtain the second NTP request message, and the second NTP request message is sent to the NTP server; The system receives a second NTP response message sent by the NTP server and encapsulates a device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message; the second NTP response message is obtained by the NTP server encapsulating a server receiving timestamp and a server sending timestamp in the second NTP request message. The first NTP response message is sent to the main control card, so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card according to the network clock deviation.
2. The method according to claim 1, characterized in that, The step of encapsulating a device sending timestamp in the first NTP request message according to the first current business system time to obtain a second NTP request message includes: Obtain the pre-stored transmission delay compensation time; the transmission delay compensation time is the hardware transmission delay time of the service card; The sum of the first current business system time and the transmission delay compensation time is used as the device transmission timestamp and encapsulated into the first NTP request message to obtain the second NTP request message.
3. The method according to claim 1, characterized in that, The step of encapsulating the device's received timestamp in the second NTP response message according to the second current business system time to obtain the first NTP response message includes: Obtain the pre-stored reception delay compensation time; the reception delay compensation time is the hardware reception delay time of the service card; The sum of the second current business system time and the receiving delay compensation time is used as the device receiving timestamp and encapsulated into the second NTP response message to obtain the first NTP response message.
4. The method according to claim 1, characterized in that, After sending the first NTP response message to the main control card, the method further includes: The system receives the network clock deviation sent by the main control card and adjusts the service system time of the service card according to the network clock deviation.
5. The method according to claim 1, characterized in that, The method further includes: A device time request message is sent to the main control card, so that the main control card encapsulates the main control receiving timestamp and the main control sending timestamp in the device time request message, generates a device time response message, and sends the device time response message to the service card; wherein, the device time request message includes a service sending timestamp; Determine the service reception timestamp of the device time response message, and calculate the system clock deviation between the service system time and the main control system time based on the service reception timestamp, the service transmission timestamp in the device time response message, the main control reception timestamp, and the main control transmission timestamp. If the system clock deviation exceeds a preset deviation threshold, the business system time is adjusted according to the system clock deviation so that the business system time of the business card is consistent with the main control system time of the main control card.
6. A clock synchronization method, characterized in that, A master control card is used in a distributed device, the distributed device further including a service card, the service card being communicatively connected to the master control card and an NTP server respectively, the method comprising: When the service system time of the service card is consistent with the main control system time of the main control card, a first NTP request message is sent to the service card. The service card then encapsulates a device transmission timestamp in the first NTP request message based on the first current service system time to obtain a second NTP request message. The service card then sends the second NTP request message to the NTP server, receives a second NTP response message from the NTP server, and encapsulates a device reception timestamp in the second NTP response message based on the second current service system time to obtain a first NTP response message. The second NTP response message is obtained by the NTP server encapsulating a server reception timestamp and a server transmission timestamp in the second NTP request message. The system receives the first NTP response message sent by the service card, calculates the network clock deviation between itself and the NTP server based on the first NTP response message, and adjusts the time of the main control system based on the network clock deviation.
7. The method according to claim 6, characterized in that, The calculation of the network clock offset between the network and the NTP server based on the first NTP response message includes: Based on the device sending timestamp, the server receiving timestamp, the server sending timestamp, and the device receiving timestamp in the first NTP response message, calculate the network clock offset between the device and the NTP server.
8. A clock synchronization device, characterized in that, A service card used in a distributed device, the distributed device further including a master control card, the service card being communicatively connected to the master control card and an NTP server respectively, the device comprising: The receiving module is configured to receive a first NTP request message sent by the main control card when the service system time of the service card is consistent with the main control system time of the main control card. The encapsulation module is used to encapsulate the device sending timestamp in the first NTP request message according to the first current business system time, obtain the second NTP request message, and send the second NTP request message to the NTP server; The encapsulation module is further configured to receive a second NTP response message sent by the NTP server, and encapsulate a device receiving timestamp in the second NTP response message according to the second current business system time to obtain a first NTP response message; the second NTP response message is obtained by the NTP server encapsulating a server receiving timestamp and a server sending timestamp in the second NTP request message; The encapsulation module is further configured to send the first NTP response message to the main control card, so that the main control card can calculate the network clock deviation between the main control card and the NTP server based on the first NTP response message, and adjust the main control system time of the main control card based on the network clock deviation.
9. A clock synchronization device, characterized in that, A master control card used in a distributed device, the distributed device further including a service card, the service card being communicatively connected to the master control card and an NTP server respectively, the device comprising: The NTP module is used to send a first NTP request message to the service card when the service system time of the service card is consistent with the main control system time of the main control card. The service card then encapsulates a device transmission timestamp in the first NTP request message according to the first current service system time to obtain a second NTP request message, and sends the second NTP request message to the NTP server. The service card also receives a second NTP response message from the NTP server and encapsulates a device reception timestamp in the second NTP response message according to the second current service system time to obtain a first NTP response message. The second NTP response message is obtained by the NTP server encapsulating a server reception timestamp and a server transmission timestamp in the second NTP request message. The calculation module is used to receive the first NTP response message sent by the service card, calculate the network clock deviation between the system and the NTP server based on the first NTP response message, and adjust the time of the main control system based on the network clock deviation.
10. A circuit board, characterized in that, It includes a processor and a memory, the memory storing a computer program executable by the processor, the processor being able to execute the computer program to implement the method of any one of claims 1-5, or the method of any one of claims 6-7.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1-5, or the method of any one of claims 6-7.