Clock time synchronization method, control device, storage medium and system
By binding the network card packetization interrupt thread and packet transmission thread to different CPUs on the client and server, the problem of unstable packet delay in the NTP clock timing method is solved, and higher timing accuracy is achieved.
Patent Information
- Application Number
- CN202211364806.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-02
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-11-02
AI Technical Summary
The existing NTP clock timing method is interrupted by the packet reception interrupt processing because the network card driver updates the packet transmission time, resulting in unstable packet delay and affecting the timing accuracy.
The packet collection interrupt thread and packet transmission thread of the client and server network card are bound to different CPUs respectively, reducing the delay in packet transmission and reception process and ensuring the accuracy of timestamp recording.
Improves the accuracy of clock timing, stabilizes packet delay, and improves the accuracy of NTP timing.
Smart Images

Figure CN115801170B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network technologies, and particularly to a clock synchronization method, a control device, a storage medium, and a system. Background Art
[0002] NTP (Network Time Protocol) is a protocol used to synchronize computer time. It can synchronize a computer with its server or clock source (such as a quartz clock, GPS, etc.), and can also provide highly accurate time correction (less than 1 millisecond difference from the standard on a LAN, dozens of milliseconds on a WAN), and can prevent malicious protocol attacks by means of encrypted confirmation.
[0003] The most typical time synchronization method of NTP is the Client / Server method. The client first sends an NTP packet to the server, which contains the timestamp T1 when the packet leaves the client; when the server receives the packet, it fills in the timestamp T2 when the packet arrives and the timestamp T3 when the packet leaves in sequence, and then immediately returns the packet to the client; when the client receives the response packet, it records the timestamp T4 when the packet is returned. The client can calculate two key parameters based on the above four time parameters: the round-trip delay d of the NTP packet = ((T2 - T1) + (T4 - T3)), and the clock deviation t between the client and the server = ((T2 - T1) - (T4 - T3)) / 2; the client uses the clock deviation to adjust the local clock to make its time consistent with the server time.
[0004] Existing optimization schemes and disadvantages for NTP accuracy include: updating timestamps based on the hardware network card layer, and the recorded time only includes the transmission time of the packet in the network. The disadvantage is that when the server is ready to send and receive packets (i.e., the timestamp T3 when the packet leaves has been recorded), since the priority of receiving and sending is higher than the priority of sending packets, it will be interrupted by other packet receiving programs, and the unsent packet will be sent only after the packet receiving interruption is processed. At this time, the packet sending time will increase the uncertain delay time of the packet receiving interruption processing, resulting in the packet sending time not being the real packet sending time, causing inaccurate time synchronization. Summary of the Invention
[0005] An object of an embodiment of the present invention is to provide a clock synchronization method, which can solve the problem of inaccurate NTP time synchronization in the prior art.
[0006] To achieve the above object, an embodiment of the present invention provides a clock time synchronization method, which is applied to a client. The clock time synchronization method includes: sending a time synchronization request message through a first CPU of the client, where the time synchronization request message includes a first timestamp when the time synchronization request message leaves the client; receiving, by a second CPU of the client, a corresponding time synchronization response message sent by the server for the time synchronization request message, and recording a fourth timestamp when the time synchronization response message arrives at the client to the time synchronization response message. The time synchronization response message includes a second timestamp recorded by a third CPU of the server when the time synchronization request message arrives at the server and a third timestamp recorded by a fourth CPU of the server when the time synchronization response message leaves the server; synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0007] Optionally, before sending the time synchronization request message through the first CPU of the client, it further includes: selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate.
[0008] Optionally, the selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate includes: selecting two CPUs with the lowest usage rates from at least two CPUs of the client as the first CPU and the second CPU.
[0009] Optionally, the synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp includes: uploading the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to an NTP server, so that the NTP server synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0010] An embodiment of the present invention further provides a clock time synchronization method, which is applied to a server. The clock time synchronization method includes: receiving a time synchronization request message sent by a client through a third CPU of the server, and recording a second timestamp when the time synchronization request message arrives at the server. The time synchronization request message includes a first timestamp recorded by a first CPU of the client when the time synchronization request message leaves the client; recording a third timestamp when the time synchronization request message leaves the server through a fourth CPU of the server, and loading the second timestamp and the third timestamp into the time synchronization request message to generate a time synchronization response message; sending the time synchronization response message to the client, so that a second CPU of the client obtains the time synchronization response message and records a fourth timestamp when the time synchronization response message arrives at the client. In the time synchronization response message, the client synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0011] Optionally, before receiving the time synchronization request message sent by the client through the third CPU of the server, it further includes: selecting the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate.
[0012] Optionally, the selecting the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate includes: selecting the two CPUs with the lowest usage rates from at least two CPUs of the server as the third CPU and the fourth CPU.
[0013] Optionally, the synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp includes: uploading the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to an NTP server, so that the NTP server synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0014] An embodiment of the present invention further provides a control device for a client. The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the clock time synchronization method for a client according to any one of the above.
[0015] An embodiment of the present invention further provides a control device for a server. The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement any one of the above clock synchronization methods for the server.
[0016] An embodiment of the present invention further provides a machine-readable storage medium, characterized in that instructions are stored on the machine-readable storage medium, and the instructions cause the machine to execute any one of the above clock synchronization methods for the client or any one of the above clock synchronization methods for the server.
[0017] Through the above technical solution, in the embodiment of the present invention, the packet receiving interrupt thread and the packet sending thread of the client network card and / or the server network card are respectively bound to different CPUs. When the packet sending process is interrupted by the packet receiving process during execution, it will not cause packet sending delay, and thus will not cause the problem of unstable time, effectively improving the synchronization accuracy.
[0018] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent specific implementation part. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings are used to provide a further understanding of the embodiments of the present invention, and constitute a part of the specification, and are used to explain the embodiments of the present invention together with the following specific implementation manners, but do not constitute a limitation to the embodiments of the present invention. In the drawings:
[0020] Figure 1 is a schematic diagram of the process of adjusting the local clock through clock deviation in the prior art;
[0021] Figure 2 is Optimization Scheme 1 for NTP synchronization accuracy;
[0022] Figure 3 is Optimization Scheme 2 for NTP synchronization accuracy;
[0023] Figure 4 is a schematic diagram of the process of the client clock synchronization method provided by the embodiment of the present invention;
[0024] Figure 5 is a schematic diagram of the processing flow of the example packet sending thread;
[0025] Figure 6 is a schematic diagram of the processing flow of the example packet receiving interrupt thread;
[0026] Figure 7 is a schematic diagram of the processing flow of packet sending and receiving in the prior art;
[0027] Figure 8 is a schematic diagram of the process of the server clock synchronization method provided by the embodiment of the present invention. Detailed implementation manners
[0028] The following details the specific implementation manners of the embodiments of the present invention with reference to the accompanying drawings. It should be understood that the specific implementation manners described herein are only for explaining and illustrating the embodiments of the present invention, and are not used to limit the embodiments of the present invention.
[0029] Before describing the embodiments of the present invention in detail, a brief introduction to the prior art and the design concept of the embodiments of the present invention is given.
[0030] Figure 1 shows the process of adjusting the local clock through clock deviation in the prior art. Please refer to Figure 1 , in the NTP Client / Server time synchronization mode, the round-trip delay d of the NTP packet and the clock deviation t between the client and the server can be expressed by the following formula:
[0031] t = ((T2 - T1) - (T4 - T3)) / 2 (1)
[0032] d = ((T2 - T1) + (T4 - T3)) (2)
[0033] where, T1 is the timestamp when the packet leaves the client, T2 is the timestamp when the server receives the packet, T3 is the timestamp when the packet leaves the server, and T4 is the timestamp when the client receives the response packet.
[0034] It can be seen from formulas (1) and (2) that the round-trip delay d and the clock deviation t between the client and the server are only related to the difference between T2 and T1 and the difference between T3 and T4, and have nothing to do with the difference between T2 and T3, that is, the final result has nothing to do with the time required for the server to process the request. Therefore, to optimize the NTP time synchronization accuracy, it is also necessary to stabilize the difference between T2 and T1 and the difference between T3 and T4, so that the time in the updated NTP packet is closer to the actual packet sending and receiving time of the physical network card.
[0035] As Figure 2 shown in the NTP time synchronization accuracy optimization scheme, with the support of the hardware network card, T1, T2, T3, and T4 in the NTP packet are updated, and the recorded time only includes the transmission time of the packet in the network; however, this optimization scheme requires specific hardware support and has poor versatility.
[0036] As Figure 3The optimized solution for NTP time synchronization accuracy shown in the figure uses software to update T1, T2, T3, and T4, and sinks the action of updating the time to the network card driver. The hardware network card layer updates the timestamp, and the recorded time includes the transmission time of the packet in the network card and the network. Only software support is required, and the versatility is relatively high. However, when the network card driver finishes updating the packet sending time and is interrupted by the packet receiving interrupt, when the packet receiving interrupt processing finishes and continues to send the unsent packets, the delay of packet sending needs to add the uncertain time T_intr of packet receiving interrupt processing, which will cause the delay of packet sending to be unstable.
[0037] The embodiment of the present invention is improved on Figure 3 the optimized solution described above to stabilize the packet sending and receiving delay.
[0038] Figure 4 is a schematic flowchart of the client clock time synchronization method provided by the embodiment of the present invention. Please refer to Figure 4 , which is applied to the client. The client has at least two CPUs. The method may include the following steps:
[0039] Step S110: Send a time synchronization request packet through the first CPU of the client. The time synchronization request packet includes the first timestamp when the time synchronization request packet leaves the client.
[0040] Among them, in the driver layer of the gateway of the client, the client packet receiving interrupt thread is configured to the first CPU, and the client packet sending thread is configured to the second CPU.
[0041] The embodiment of the present invention uses software to update the first timestamp T1 (and the fourth timestamp T4), sinks the action of updating the time to the network card driver, and uses the CPU binding technology to bind the packet receiving interrupt thread and the packet sending thread of the network card to different CPUs (for example, CPUx and CPUy) respectively to improve the efficiency of the network card and reduce the delay in the packet sending and receiving process.
[0042] Before step S110, it further includes: selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate.
[0043] Preferably, the selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate includes: selecting the two CPUs with the lowest usage rates from at least two CPUs of the client as the first CPU and the second CPU.
[0044] For example, in a multi-core system, the CPUs can be divided into a control core (e.g., CPU0) and data cores (e.g., CPUx - z). The services of the device to which the multi-core system belongs can be divided into real-time services and non-real-time services. Non-real-time services and system tasks can be bound to the same core (e.g., the control core CPU0); services with relatively high real-time requirements, such as the NTP service, can be bound to the data cores CPUx - z. For example, two cores with relatively low utilization rates can be selected from CPUx - z to process the packet receiving service and packet sending service of NTP respectively, so as to improve the processing speed of the packet receiving service and packet sending service of NTP. For example, bind the packet receiving interrupt thread (e.g., thread thread_rx) to CPUx, and the packet sending thread (e.g., thread thread_tx) to CPUy, where x!= y. For a dual-core system, x can be 0, that is, CPUx is the control core.
[0045] Figure 5 The processing flow of the packet sending thread thread_tx is shown. For example, CPUy responds to the packet sending, judges the packet sending type. If the packet sending type is the time synchronization request packet of NTP CLIENT, after updating the time of the first timestamp T1 in the packet, it sends the packet.
[0046] Preferably, in the embodiment of the present invention, when performing step S110, it may further include: when receiving a service packet, the service packet can be received through the packet receiving interrupt thread.
[0047] For example, if a service packet with a relatively high priority is received and there is no extra data core to process the service packet, if the packet receiving interrupt thread is not in use, the service packet can be received through the packet receiving interrupt thread. That is, it can improve the CPU utilization rate and also improve the service processing efficiency.
[0048] Step S120: Receive, through the second CPU of the client, the corresponding time synchronization response packet sent by the server for the time synchronization request packet, and record the fourth timestamp when the time synchronization response packet arrives at the client to the time synchronization response packet. The time synchronization response packet includes the second timestamp recorded by the third CPU of the server when the time synchronization request packet arrives at the server and the third timestamp when the time synchronization response packet leaves the server recorded by the fourth CPU of the server.
[0049] Wherein, the server receives the time synchronization request packet through the server packet receiving interrupt thread, and sends the corresponding time synchronization response packet through the server packet sending thread. Wherein, in the driver layer of the gateway of the server, the server packet receiving interrupt thread is configured to the third CPU, and the server packet sending thread is configured to the fourth CPU.
[0050] Illustrated by way of example, the server packet receiving interruption thread of the server receives the time synchronization request message, determines the NTP message type. If the NTP message type is the time synchronization request message of NTP CLIENT, after updating the time of the second timestamp T2 in the message, the time synchronization request message is reported to the NTP protocol; the server packet sending thread of the server sends the corresponding time synchronization response message, and the fourth CPU of the server responds to send the packet. It determines the packet sending type. If the packet sending type is the time synchronization response message of NTP SERVER, after updating the time of the third timestamp T3 in the message, it sends the packet; the client receives the corresponding time synchronization response message through the client packet receiving interruption thread.
[0051] Step S130: Synchronize the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0052] Preferably, step S130 includes: uploading the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to the NTP server, so that the NTP server synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0053] Figure 6 The processing flow of the packet receiving interruption thread thread_rx is shown. Illustrated by way of example, CPUx responds to receive the packet, determines the NTP message type. If the NTP message type is the time synchronization response message of NTP SERVER, after updating the time of the fourth timestamp T2 in the message, the time synchronization response message is reported to the NTP protocol.
[0054] Preferably, the clock deviation in step S130 can be calculated by formula (1), that is:
[0055] Clock deviation t = ((second timestamp T2 - first timestamp T1) - (fourth timestamp T4 - third timestamp T3)) / 2.
[0056] Preferably, the method may further include: calculating the network delay d between the client and the server according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp, where the network delay can be calculated by formula (2), that is:
[0057] Network delay d = (second timestamp T2 - first timestamp T1) + (fourth timestamp T4 - third timestamp T3).
[0058] Figure 7 The processing flow of the existing packet receiving and sending is shown. Please refer to Figure 7, Packet reception is triggered by an interrupt, and packet transmission is triggered by the platform protocol, and there is a concurrent situation.
[0059] The time consumed for packet transmission TX_start and TX_end is T_tx; the time consumed for packet reception RX-start and RX_end is T_rx. Due to the high interrupt priority, there is a situation where TX-start, RX_start, RX_end, and TX_end are processed simultaneously. Therefore, the packet transmission delay T = T_tx + T_rx, and the packet reception delay T = T_rx.
[0060] In the embodiment of the present invention, as Figure 5 and Figure 6 shown, packet reception is triggered by an interrupt, and packet transmission is triggered by the platform protocol, and no concurrent situation will occur.
[0061] The time consumed for packet transmission TX_start and TX_end on CPUx is T_tx; the time consumed for packet reception RX-start and RX_end on CPUy is T_rx. At this time, x!= y, and the packet sending and receiving processes are processed on different CPUs. The packet transmission delay T = T_tx, and the packet reception delay T = T_rx.
[0062] Accordingly, in the embodiment of the present invention, the packet reception interrupt thread and the packet transmission thread of the client network card are respectively bound to different CPUs. When the packet transmission process is interrupted by the packet reception interrupt process, it will not cause packet transmission delay, and thus will not cause the problem of time instability, effectively improving the time synchronization accuracy.
[0063] Figure 8 is a flowchart of the server clock time synchronization method provided by the embodiment of the present invention. Please refer to Figure 8 , which is applied to a server. The server has at least two CPUs. The method may include the following steps:
[0064] Step S210: Receive the time synchronization request message sent by the client through the third CPU of the server, and record the second timestamp when the time synchronization request message arrives at the server. The time synchronization request message includes the first timestamp when the time synchronization request message leaves the client recorded by the first CPU of the client.
[0065] Among them, in the driver layer of the gateway of the server, configure the server packet reception interrupt thread to the third CPU, and configure the server packet transmission thread to the fourth CPU.
[0066] Similar to the client, in the embodiment of the present invention, the server also uses software to update the second timestamp T2 (and the third timestamp T3), sinking the action of updating the time into the network card driver; and using the CPU binding technology, binding the packet receiving interrupt thread (for example, thread thread_rx) and the packet sending thread (for example, thread thread_tx) of the server network card to different CPUs (for example, CPUx and CPUy) respectively, improving the efficiency of the network card and reducing the latency in the process of packet receiving and sending.
[0067] Preferably, before step S210, it further includes: selecting the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate.
[0068] Preferably, the selecting the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate includes: selecting the two CPUs with the lowest usage rates from at least two CPUs of the server as the third CPU and the fourth CPU.
[0069] Illustrated by an example, the third CPU and the fourth CPU are determined according to the CPU usage rate of the server, where the server CPU includes a control core and a data core, the control core is used to process non-real-time services and system tasks, the data core is used to process real-time services, and the third CPU and the fourth CPU are the data cores. The method of determining the third CPU and the fourth CPU is similar to the method of determining the first CPU and the second CPU above, and will not be elaborated here.
[0070] When executing step S210, the clock synchronization method may further include: when receiving a service packet, the service packet can be received through the packet receiving interrupt thread. That is, it can improve the CPU usage rate and also improve the service processing efficiency.
[0071] Step S220: Record the third timestamp when the time synchronization request packet leaves the server through the fourth CPU of the server, and load the second timestamp and the third timestamp into the time synchronization request packet to generate a time synchronization response packet.
[0072] Figure 6 Illustrates the processing flow of the packet receiving interrupt thread thread_rx. By way of example, CPUx responds to packet reception, judges the NTP packet type. If the NTP packet type is a time synchronization request packet of NTP CLIENT, after updating the time of the second timestamp T2 in the packet, the time synchronization request packet is reported to the NTP protocol.
[0073] Step S230: Send the time synchronization response message to the client, so that the second CPU of the client can obtain the time synchronization response message and record the fourth timestamp when the time synchronization response message arrives at the client. In the time synchronization response message, the client performs time synchronization on the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0074] Preferably, step S230 includes: uploading the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to the NTP server, so that the NTP server performs time synchronization on the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
[0075] Send the corresponding time synchronization response message through the packet sending thread. Figure 5 Shows the processing flow of the packet sending thread thread_tx. By way of example, CPUy responds to packet sending, determines the packet sending type. If the packet sending type is a time synchronization response message of the NTP SERVER, after updating the time of the third timestamp T3 in the message, the packet is sent.
[0076] The client receives the corresponding time synchronization response message through the packet receiving interrupt thread, updates the fourth timestamp when the time synchronization response message reaches the client to the time synchronization response message, and reports the time synchronization response message to the NTP protocol, and performs NTP time synchronization according to the first timestamp T1, the second timestamp T2, the third timestamp T3, and the fourth timestamp T4.
[0077] Accordingly, in the embodiment of the present invention, the packet receiving interrupt thread and the packet sending thread of the server network card are respectively bound to different CPUs. When the packet sending process is interrupted by the packet receiving process, it will not cause packet sending delay, and thus cause the problem of unstable time, effectively improving the time synchronization accuracy.
[0078] The embodiment of the present invention further provides a control device for a client. The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the clock time synchronization method according to steps S110-S130.
[0079] Among them, the processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and precise time synchronization of NTP is achieved by adjusting the kernel parameters.
[0080] The memory may include non-permanent memory in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0081] An embodiment of the present invention further provides a control device for a server. The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the clock synchronization method according to steps S210-S230.
[0082] Among them, the processor contains a kernel, and the kernel retrieves corresponding program units from the memory. One or more kernels can be set, and precise clock synchronization of NTP is achieved by adjusting the kernel parameters.
[0083] The memory may include non-permanent memory in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0084] An embodiment of the present invention further provides a machine-readable storage medium. Instructions are stored on the machine-readable storage medium, and the instructions cause the machine to execute the clock synchronization method described in steps S110-S130 or the clock synchronization method described in steps S210-S230.
[0085] An embodiment of the present invention further provides a clock synchronization system. The clock synchronization system includes the control device of the client described above, the gateway configured by the client, the control device of the server described above, and the gateway configured by the server.
[0086] An embodiment of the present invention provides a device. The device includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, it implements the clock synchronization method described in steps S110-S130 or the clock synchronization method described in steps S210-S230. The device herein may be a server, a PC, a PAD, a mobile phone, etc.
[0087] The detailed technical content and effects of the control device of the client, the control device of the server, the machine-readable storage medium, and the clock synchronization system provided by the embodiments of the present invention are similar to those of the clock synchronization method described in S110-S130 and the clock synchronization method described in steps S210-S230, and will not be elaborated here.
[0088] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an all-hardware embodiment, an all-software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) that contain computer-usable program code.
[0089] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be realized by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, so that the instructions executed by the processors of the computer or other programmable data processing devices generate means for realizing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0090] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means realizes the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0091] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for realizing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0092] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0093] The memory may include non-permanent memory in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
[0094] A computer-readable medium includes both permanent and non-permanent, removable and non-removable media and can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media such as modulated data signals and carrier waves.
[0095] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0096] The above are only embodiments of the present application and are not used to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A clock time synchronization method, characterized in that Applied to a client, the client having at least two CPUs, the method includes: Sending a time synchronization request message through the first CPU of the client, the time synchronization request message including a first timestamp when the time synchronization request message leaves the client; Receiving, through the second CPU of the client, a corresponding time synchronization response message sent by the server for the time synchronization request message, and recording a fourth timestamp when the time synchronization response message arrives at the client to the time synchronization response message, the time synchronization response message including a second timestamp recorded by the third CPU of the server when the time synchronization request message arrives at the server and a third timestamp recorded by the fourth CPU of the server when the time synchronization response message leaves the server; Synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp, wherein the packet sending thread and the packet receiving interrupt thread of the network card of the client are respectively bound to the first CPU and the second CPU; In the step of sending a time synchronization request message through the first CPU of the client, when a service message is received and there is no extra CPU to process the service message, the service message is received through the packet receiving interrupt thread.
2. The method according to claim 1, wherein Before sending the time synchronization request message through the first CPU of the client, it further includes: Selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate.
3. The method according to claim 2, wherein The selecting the first CPU and the second CPU from at least two CPUs of the client according to the CPU usage rate includes: Selecting the two CPUs with the lowest usage rates from at least two CPUs of the client as the first CPU and the second CPU.
4. The method according to claim 1, wherein The synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp includes: Uploading the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to an NTP server, so that the NTP server synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
5. A clock time synchronization method, characterized in that, Applied to a server, the server having at least two CPUs, the method includes: Receiving, through the third CPU of the server, a time synchronization request message sent by the client, and recording a second timestamp when the time synchronization request message arrives at the server, the time synchronization request message including a first timestamp recorded by the first CPU of the client when the time synchronization request message leaves the client; Recording, through the fourth CPU of the server, a third timestamp when the time synchronization request message leaves the server, and loading the second timestamp and the third timestamp into the time synchronization request message to generate a time synchronization response message; Send the time synchronization response message to the client, so that the second CPU of the client can obtain the time synchronization response message and record the fourth timestamp when the time synchronization response message arrives at the client. In the time synchronization response message, the client synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp. Wherein, the packet receiving interrupt thread and the packet sending thread of the network card of the server are respectively bound to the third CPU and the fourth CPU. In the step of receiving the time synchronization request message sent by the client through the third CPU of the server, when a service message is received and there is no extra CPU to process the service message, the service message is received through the packet receiving interrupt thread.
6. The method according to claim 5, wherein Before receiving the time synchronization request message sent by the client through the third CPU of the server, it further includes: Select the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate.
7. The method according to claim 6, wherein The selecting the third CPU and the fourth CPU from at least two CPUs of the server according to the CPU usage rate includes: Select the two CPUs with the lowest usage rates from at least two CPUs of the server as the third CPU and the fourth CPU.
8. The method according to claim 7, characterized in that The synchronizing the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp includes: Upload the time synchronization request message and the time synchronization response message containing the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp to the NTP server, so that the NTP server synchronizes the clock of the client according to the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp.
9. A control device for a client, characterized in that, The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the clock synchronization method according to any one of claims 1-4.
10. A control device for a server, characterized in that, The control device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. The processor executes the computer program to implement the clock synchronization method according to any one of claims 5-8.
11. A machine-readable storage medium, characterized in that, Instructions are stored on the machine-readable storage medium, and the instructions cause the machine to execute the clock synchronization method according to any one of claims 1-4 or the clock synchronization method according to any one of claims 5-8.
Citation Information
Patent Citations
Time synchronization method and system
CN111385048A
Session synchronization method, apparatus and system, and first node, second node and medium
WO2022184085A1