Clock synchronization method, device, electronic device and storage medium
By using the backup clock to correct the time of the local slave clock when two consecutive clock cycles between the master clock and the local slave clock are greater than the preset deviation value, the problem of low clock synchronization accuracy and unstable network is solved, and the clock synchronization is improved reliability and accuracy.
Patent Information
- Application Number
- CN202210736278.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2042-06-27
AI Technical Summary
In the prior art, the clock synchronization method causes the local slave clock to be low after the master clock is disturbed for a long time, which leads to network instability problems.
When the two consecutive clock cycles between the master clock and the local slave clock are greater than the preset deviation value, the time of the backup clock is used to correct the time of the local slave clock to improve the accuracy of clock synchronization and anti-interference ability.
Improve the reliability and accuracy of clock synchronization, and weaken the network instability caused by low clock synchronization accuracy.
Smart Images

Figure CN115085850B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a clock synchronization method, device, electronic equipment and storage medium. Background Art
[0002] The clock frequency and phase differences of each network element in the digital network must be limited within the allowable error range to ensure the stable transmission of digital bit streams between network elements. In this process, accurate clock synchronization between network elements is necessary. Summary of the invention
[0003] The purpose of the embodiments of the present invention is to provide a clock synchronization method, device, electronic device and storage medium to achieve accurate clock synchronization. The specific technical solution is as follows:
[0004] In a first aspect, an embodiment of the present invention provides a clock synchronization method, the method comprising:
[0005] When the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value, obtaining the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle; wherein the second clock cycle is the next clock cycle of the first clock cycle;
[0006] Determine the number of the second time deviations greater than the preset deviation value to obtain a first number;
[0007] Determine the number of the third time deviations greater than the preset deviation value to obtain a second number;
[0008] When the first number is greater than the second number, the time of the local slave clock is corrected by using the time of the backup clock in a clock cycle after the preset number of clock cycles.
[0009] Optionally, the method further comprises:
[0010] When the first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out;
[0011] When the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value, the first time deviation and the time of the backup clock are filtered out, and the time of the local slave clock is not corrected;
[0012] When the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out.
[0013] Optionally, the obtaining of the second time deviation between the master clock and the local slave clock in each clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle includes:
[0014] For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock;
[0015] Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock;
[0016] The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
[0017] Optionally, the method further comprises:
[0018] When the first number is not greater than the second number, the time of the local slave clock is corrected by using the time of the master clock in the clock cycle after the preset number of clock cycles, and the time of the backup clock is filtered out.
[0019] Optionally, the method further comprises:
[0020] The time of the local slave clock for the preset number of clock cycles is not corrected.
[0021] In a second aspect, an embodiment of the present invention provides a clock synchronization device, the device comprising:
[0022] A deviation acquisition module, used for acquiring, when the first time deviations between the master clock and the local slave clock in the first clock cycle and the second clock cycle are both greater than a preset deviation value, the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle; wherein the second clock cycle is the next clock cycle of the first clock cycle;
[0023] A first determining module, configured to determine the number of the second time deviations greater than the preset deviation value, to obtain a first number;
[0024] A second determining module, used to determine the number of the third time deviations greater than the preset deviation value to obtain a second number;
[0025] A clock synchronization module is used to correct the time of the local slave clock using the time of the backup clock in a clock cycle after the preset number of clock cycles when the first number of times is greater than the second number of times.
[0026] Optionally, the device further comprises:
[0027] A first synchronization module, configured to, when a first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than a preset deviation value, use the time of the master clock to correct the time of the local slave clock and filter out the time of the backup clock;
[0028] A clock filtering module, configured to filter out the first time deviation and the time of the backup clock, and not correct the time of the local slave clock, when the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value;
[0029] The second synchronization module is used to use the time of the master clock to correct the time of the local slave clock and filter out the time of the backup clock when the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value.
[0030] Optionally, the deviation acquisition module acquires a second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and a third time deviation between the backup clock and the local slave clock in each clock cycle, including:
[0031] For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock;
[0032] Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock;
[0033] The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
[0034] Optionally, the device further comprises:
[0035] A third synchronization module is used to, when the first number is not greater than the second number, use the time of the master clock to correct the time of the local slave clock in the clock cycle after the preset number of clock cycles, and filter out the time of the backup clock.
[0036] Optionally, the device further comprises:
[0037] The pause correction module is used for not correcting the time of the local slave clock for the preset number of clock cycles.
[0038] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0039] Memory, used to store computer programs;
[0040] The processor is used to implement any of the above-mentioned method steps when executing the program stored in the memory.
[0041] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the method steps described above is implemented.
[0042] An embodiment of the present invention further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described method steps.
[0043] The embodiments of the present invention provide a clock synchronization method, device, electronic device and storage medium, which realize accurate clock synchronization.
[0044] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0046] Figure 1 It is a schematic diagram of a clock synchronization method in the related art;
[0047] Figure 2 A schematic diagram of a clock synchronization method according to an embodiment of the present invention;
[0048] Figure 3 A schematic diagram of a clock synchronization method provided by an embodiment of the present invention;
[0049] Figure 4 A schematic diagram of the structure of a clock synchronization device provided by an embodiment of the present invention;
[0050] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field based on this application belong to the scope of protection of the present invention.
[0052] The clock frequency and phase differences of each network element in the digital network must be limited within the allowable error range to ensure the stable transmission of the digital bit stream between the network elements. In the case of inconsistent clock frequencies between network elements in the digital network, the stable transmission of the digital bit stream between the network elements will be affected, resulting in the loss or duplication of code elements, which will lead to damage to the transmitted digital bit stream. In the related art, the NTP (Network Time Protocol) protocol is used to synchronize the clocks between network elements. NTP is a software method. In practice, the transmission of digital bit streams between network elements is affected by the link delay as well as the internal processing delay of various physical devices, which makes the accuracy of clock synchronization low.
[0053] A clock synchronization method in the prior art, such as Figure 1 As shown, the time deviation between the local slave clock and the master clock is obtained for the first time, the master-slave clock time deviation is obtained, and the master-slave clock time deviation is compared to see whether it is greater than the set deviation value. If it is greater, the time deviation is filtered out, and if it is not greater, the master clock time is used to directly correct the local slave clock system time. Further, the time deviation between the local slave clock and the master clock is obtained for the second time, and the time deviation is compared to see whether it is greater than the set deviation value. If it is greater, the local slave clock system time is corrected according to the time deviation, and if it is not greater, the master clock time is used to directly correct the local slave clock system time.
[0054] However, the inventors found that Figure 1In the clock synchronization method shown, when the master clock is disturbed for a long time, the time deviation between the local slave clock and the master clock will continue to exceed the set deviation value. The time deviation is then used to correct the local slave clock system time, which will result in low time synchronization accuracy for the local slave clock, and thus easily cause instability problems in the network where the master clock is located and the local device.
[0055] To solve the above problem, an embodiment of the present invention provides a clock synchronization method. When the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value, the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle are obtained; wherein the second clock cycle is the next clock cycle of the first clock cycle; the number of second time deviations greater than the preset deviation value is determined to obtain a first number; the number of third time deviations greater than the preset deviation value is determined to obtain a second number; when the first number is greater than the second number, the time of the backup clock is used to correct the time of the local slave clock in the clock cycle after the preset number of clock cycles.
[0056] In an embodiment of the present invention, a method of master clock and backup clock redundancy is adopted. When the first time deviation between the master clock and the local slave clock is greater than a preset deviation value in two consecutive clock cycles, it indicates that the master clock is unstable due to interference, and an anti-long-time interference protection method is started to detect the first number of times that the second time deviation between the master clock and the local slave clock is greater than the preset deviation value within a preset number of clock cycles, and the second number of times that the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value. When the first number is greater than the second number, it indicates that the master clock is subject to long-term interference, and the time of the backup clock is enabled to synchronize the time of the local slave clock. This can increase the anti-interference capability of the master clock while improving the clock synchronization reliability, improve the clock synchronization accuracy, and further reduce the network instability caused by the low clock synchronization accuracy.
[0057] The clock synchronization method provided by the present invention is described in detail below through specific embodiments.
[0058] The clock synchronization method provided in the embodiment of the present invention can be applied to any electronic device that needs clock synchronization, such as a terminal, a server, etc. The clock synchronization method provided in the embodiment of the present invention can be implemented based on the 1588V2 protocol formulated by the IEEE (Institute of Electrical and Electronics Engineers). The IEEE1588V2 protocol timestamps the location closest to both ends of the line to facilitate link delay measurement, thereby achieving higher time synchronization accuracy.
[0059] See also Figure 2 , Figure 2 A clock synchronization method provided in an embodiment of the present invention includes:
[0060] S201, when the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value, obtain the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle.
[0061] In an embodiment of the present invention, a master clock and a backup clock are deployed, wherein the device where the master clock is located, the device where the backup clock is located, and the local device are all different devices, and the initial time of the master clock and the backup clock is the same. The clock synchronization method provided in the embodiment of the present invention is applied to the local device that needs to perform clock synchronization. In the embodiment of the present invention, clock synchronization is performed in clock cycles. For example, a clock cycle can represent a corresponding time period from when a data packet is sent between the device where the master clock is located and the local device to when the next data packet starts to be sent.
[0062] In one example, a local device receives the time of a master clock of a first clock cycle, further calculates the deviation between the time of the master clock of the first clock cycle and the time of a local slave clock, obtains the first time deviation between the master clock of the first clock cycle and the local slave clock, determines whether the first time deviation between the master clock of the first clock cycle and the local slave clock is greater than a preset deviation value, and if so, receives the time of a master clock of a second clock cycle, calculates the deviation between the time of the master clock of the second clock cycle and the time of the local slave clock, obtains the first time deviation between the master clock of the second clock cycle and the local slave clock, determines whether the first time deviation between the master clock of the second clock cycle and the local slave clock is greater than a preset deviation value, and if so, determines that the first time deviation between the master clock of the first clock cycle and the second clock cycle and the local slave clock is greater than the preset deviation value. Wherein, the preset deviation value can be set according to actual needs, and the second clock cycle is the next clock cycle of the first clock cycle.
[0063] In some embodiments, the process of determining that the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value may further include:
[0064] When the first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out;
[0065] When the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value, the first time deviation and the time of the backup clock are filtered out, and the time of the local slave clock is not corrected;
[0066] When the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out.
[0067] When the local slave clock performs clock synchronization, the local device receives the time of the master clock and the time of the backup clock in the first clock cycle, calculates the deviation between the time of the master clock in the first clock cycle and the time of the local slave clock, obtains the first time deviation between the master clock and the local slave clock in the first clock cycle, and determines whether the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than a preset deviation value. If the first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than the preset deviation value, it indicates that the master clock is stable, and the time of the local slave clock is corrected by the time of the master clock, and the time of the backup clock is filtered out. If the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value, that is, there is a first time deviation between the master clock and the local slave clock that exceeds the allowable deviation value, indicating that the master clock is subject to accidental interference, at this time, the first time deviation and the time of the backup clock are filtered out, and the time of the local slave clock is not corrected in this clock cycle.
[0068] Further, the time of the master clock and the time of the backup clock in the second clock cycle are received, the deviation between the time of the master clock in the second clock cycle and the time of the local slave clock is calculated, and the first time deviation between the master clock and the local slave clock in the second clock cycle is obtained. It is determined whether the first time deviation between the master clock and the local slave clock in the second clock cycle is greater than a preset deviation value. When the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value, it indicates that the master clock is stable, and the time of the master clock is used to correct the time of the local slave clock, and the time of the backup clock is filtered out. When the first time deviation between the master clock and the local slave clock in the second clock cycle is greater than the preset deviation value, it is determined that the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle are both greater than the preset deviation value, that is, the time deviation between the master clock and the local slave clock in two consecutive clock cycles is greater than the preset deviation value, indicating that the master clock is unstable due to interference. At this time, the first time deviation and the time of the backup clock are first filtered out, and the time of the local slave clock is not corrected in this clock cycle. The anti-long-term interference protection method is started to obtain the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle, so as to synchronize the local slave clock based on the obtained second time deviation and third time deviation.
[0069] The first clock cycle may be any clock cycle in the process of clock synchronization of the local slave clock, and the preset number may be set according to actual needs.
[0070] In some embodiments, obtaining a second time deviation between a master clock and a local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and a third time deviation between a backup clock and a local slave clock in each clock cycle may include:
[0071] For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock;
[0072] Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock;
[0073] The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
[0074] When the time deviation between the master clock and the local slave clock in two consecutive clock cycles is greater than the preset deviation value, for each clock cycle of a preset number of clock cycles after the second clock cycle, the first time of the master clock and the second time of the backup clock are received, and the deviation between the first time of the master clock and the third time of the local slave clock, as well as the deviation between the second time of the backup clock and the third time of the local slave clock are calculated respectively, to obtain the second time deviation between the master clock and the local slave clock, and the third time deviation between the backup clock and the local slave clock.
[0075] See also Figure 2 , S202, determine the number of second time deviations greater than a preset deviation value, and obtain a first number.
[0076] S203, determining the number of third time deviations greater than a preset deviation value, and obtaining a second number.
[0077] After obtaining the second time deviation between the master clock and the local slave clock of each clock cycle and the third time deviation between the backup clock and the local slave clock of each clock cycle within a preset number of clock cycles after the second clock cycle, the number of second time deviations and third time deviations greater than the preset deviation value are counted respectively to obtain the first number and the second number.
[0078] S204: When the first number is greater than the second number, the time of the local slave clock is corrected using the time of the backup clock in a clock cycle after a preset number of clock cycles.
[0079] If, within the above-mentioned preset number of clock cycles, the second time deviation between the master clock and the local slave clock is greater than the first number of times the preset deviation value is exceeded, and is greater than the second number of times the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value, it indicates that the master clock is subject to long-term interference. At this time, the time of the backup clock is enabled to synchronize the time of the local slave clock. Specifically, the time of the backup clock is used to correct the time of the local slave clock in the clock cycle after the preset number of clock cycles.
[0080] In an embodiment of the present invention, a method of master clock and backup clock redundancy is adopted. When the first time deviation between the master clock and the local slave clock is greater than a preset deviation value in two consecutive clock cycles, it indicates that the master clock is unstable due to interference, and an anti-long-time interference protection method is started to detect the first number of times that the second time deviation between the master clock and the local slave clock is greater than the preset deviation value within a preset number of clock cycles, and the second number of times that the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value. When the first number is greater than the second number, it indicates that the master clock is subject to long-term interference, and the time of the backup clock is enabled to synchronize the time of the local slave clock. This can increase the anti-interference capability of the master clock while improving the clock synchronization reliability, improve the clock synchronization accuracy, and further reduce the network instability caused by the low clock synchronization accuracy.
[0081] In some embodiments, the method may further include: when the first number is not greater than the second number, in a clock cycle after a preset number of clock cycles, using the time of the master clock to correct the time of the local slave clock and filtering out the time of the backup clock.
[0082] If, within the above-mentioned preset number of clock cycles, the second time deviation between the master clock and the local slave clock is greater than the first number of times the preset deviation value is obtained, but is not greater than the second number of times the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value, it indicates that the master clock is relatively accurate relative to the backup clock. At this time, the time of the master clock continues to be used to synchronize the time of the local slave clock. Specifically, in the clock cycle after the preset number of clock cycles, the time of the master clock is used to correct the time of the local slave clock, and the time of the backup clock is filtered out.
[0083] In some embodiments, the above method may further include: not correcting the time of the local slave clock for a preset number of clock cycles.
[0084] Within the above-mentioned preset number of clock cycles, it is detected whether the first number of times that the second time deviation between the master clock and the local slave clock is greater than the preset deviation value is greater than the second number of times that the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value, so as to determine whether the master clock is subject to long-term interference. In this process, the time of the local slave clock for the preset number of clock cycles is not corrected, thereby avoiding the use of the interfered master clock to synchronize the time of the local slave clock.
[0085] For example, Figure 3As shown, in an embodiment of the present invention, a master clock and a backup clock are deployed, and a local device receives the time of the master clock and the time of the backup clock in the first clock cycle, calculates the deviation between the time of the master clock and the time of the local slave clock in the first clock cycle, and obtains the master clock time deviation. When the master clock time deviation is greater than a preset deviation value, the time deviation and the time of the backup clock are filtered out, and the time of the local slave clock is not corrected in this clock cycle. Further, the time of the master clock and the backup clock in the second clock cycle are received, and the deviation between the time of the master clock and the time of the local slave clock in the second clock cycle is calculated. When the second deviation is still greater than the preset deviation value, the anti-long-time interference protection method is started, and the deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle is obtained to obtain the master clock time deviation, and the deviation between the backup clock and the local slave clock in each clock cycle is obtained to obtain the backup clock time deviation. In the case where the master clock time deviation between the master clock and the local slave clock is greater than the preset deviation value for the first time within a preset number of clock cycles, and is greater than the second time that the standby clock time deviation between the standby clock and the local slave clock is greater than the preset deviation value, it indicates that the master clock is disturbed for a long time, and the time of the standby clock is enabled to synchronize the time of the local slave clock. Specifically, the time of the local slave clock is corrected according to the time of the standby clock. In the case where the master clock time deviation obtained in the first clock cycle is not greater than the preset deviation value, the master clock time deviation obtained in the second clock cycle is not greater than the preset deviation value, and in the case where the master clock time deviation between the master clock and the local slave clock is greater than the preset deviation value for the first time within a preset number of clock cycles, and is not greater than the second time that the standby clock time deviation between the standby clock and the local slave clock is greater than the preset deviation value, the time of the local slave clock is corrected according to the time of the master clock.
[0086] Corresponding to the clock synchronization method provided in the above embodiment, the embodiment of the present invention also provides a clock synchronization device, such as Figure 4 As shown, the device comprises:
[0087] The deviation acquisition module 401 is used to acquire the second time deviation between the master clock and the local slave clock of each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock of each clock cycle, when the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value; wherein the second clock cycle is the next clock cycle of the first clock cycle;
[0088] A first determining module 402 is used to determine the number of second time deviations greater than a preset deviation value to obtain a first number;
[0089] A second determining module 403 is used to determine the number of third time deviations greater than a preset deviation value to obtain a second number;
[0090] The clock synchronization module 404 is configured to, when the first number is greater than the second number, correct the time of the local slave clock using the time of the backup clock in a clock cycle after a preset number of clock cycles.
[0091] In an embodiment of the present invention, a method of master clock and backup clock redundancy is adopted. When the first time deviation between the master clock and the local slave clock is greater than a preset deviation value in two consecutive clock cycles, it indicates that the master clock is unstable due to interference, and an anti-long-time interference protection method is started to detect the first number of times that the second time deviation between the master clock and the local slave clock is greater than the preset deviation value within a preset number of clock cycles, and the second number of times that the third time deviation between the backup clock and the local slave clock is greater than the preset deviation value. When the first number is greater than the second number, it indicates that the master clock is subject to long-term interference, and the time of the backup clock is enabled to synchronize the time of the local slave clock. This can increase the anti-interference capability of the master clock while improving the clock synchronization reliability, improve the clock synchronization accuracy, and further reduce the network instability caused by the low clock synchronization accuracy.
[0092] In some embodiments, the above apparatus further comprises:
[0093] A first synchronization module is used to correct the time of the local slave clock using the time of the master clock and filter out the time of the backup clock when a first time deviation between the master clock and the local slave clock in a first clock cycle is not greater than a preset deviation value;
[0094] A clock filtering module, configured to filter out the first time deviation and the time of the backup clock, without correcting the time of the local slave clock, when the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than a preset deviation value;
[0095] The second synchronization module is used to use the time of the master clock to correct the time of the local slave clock and filter out the time of the backup clock when the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than a preset deviation value.
[0096] In some embodiments, the deviation acquisition module 401 acquires the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle, including:
[0097] For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock;
[0098] Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock;
[0099] The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
[0100] In some embodiments, the above also includes:
[0101] The third synchronization module is used to use the time of the master clock to correct the time of the local slave clock in the clock cycle after a preset number of clock cycles when the first number is not greater than the second number, and filter out the time of the backup clock.
[0102] In some embodiments, the above apparatus further comprises:
[0103] The pause correction module is used for not correcting the time of the local slave clock for a preset number of clock cycles.
[0104] The embodiment of the present invention further provides an electronic device, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0105] Memory 503, used for storing computer programs;
[0106] The processor 501 is used to implement the steps of any of the above-mentioned clock synchronization methods when executing the program stored in the memory 503 to achieve the same technical effect.
[0107] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0108] The communication interface is used for communication between the above electronic device and other devices.
[0109] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0110] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0111] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned clock synchronization methods are implemented to achieve the same technical effect.
[0112] In another embodiment provided by the present invention, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer executes the steps of any one of the clock synchronization methods in the above embodiments to achieve the same technical effect.
[0113] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0114] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0115] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device / electronic device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0116] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A clock synchronization method, characterized in that: The method comprises: When the first time deviation between the master clock and the local slave clock in the first clock cycle and the second clock cycle is greater than the preset deviation value, obtaining the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle; wherein the second clock cycle is the next clock cycle of the first clock cycle; Determine the number of the second time deviations greater than the preset deviation value to obtain a first number; Determine the number of the third time deviations greater than the preset deviation value to obtain a second number; When the first number is greater than the second number, the time of the local slave clock is corrected by using the time of the backup clock in a clock cycle after the preset number of clock cycles.
2. The method according to claim 1, characterized in that The method further comprises: When the first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out; When the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value, the first time deviation and the time of the backup clock are filtered out, and the time of the local slave clock is not corrected; When the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value, the time of the local slave clock is corrected by using the time of the master clock, and the time of the backup clock is filtered out.
3. The method according to claim 1, characterized in that The second time deviation between the master clock and the local slave clock in each clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle is obtained include: For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock; Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock; The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
4. The method according to claim 1, characterized in that: The method further comprises: When the first number is not greater than the second number, the time of the local slave clock is corrected by using the time of the master clock in the clock cycle after the preset number of clock cycles, and the time of the backup clock is filtered out.
5. The method according to claim 1, characterized in that The method further comprises: The time of the local slave clock for the preset number of clock cycles is not corrected.
6. A clock synchronization device, characterized in that: The device comprises: A deviation acquisition module, used for acquiring, when the first time deviations between the master clock and the local slave clock in the first clock cycle and the second clock cycle are both greater than a preset deviation value, the second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and the third time deviation between the backup clock and the local slave clock in each clock cycle; wherein the second clock cycle is the next clock cycle of the first clock cycle; A first determining module, configured to determine the number of the second time deviations greater than the preset deviation value, to obtain a first number; A second determining module, used to determine the number of the third time deviations greater than the preset deviation value to obtain a second number; A clock synchronization module is used to correct the time of the local slave clock using the time of the backup clock in a clock cycle after the preset number of clock cycles when the first number of times is greater than the second number of times.
7. The device according to claim 6, characterized in that The device also includes: A first synchronization module, configured to, when a first time deviation between the master clock and the local slave clock in the first clock cycle is not greater than a preset deviation value, use the time of the master clock to correct the time of the local slave clock and filter out the time of the backup clock; A clock filtering module, configured to filter out the first time deviation and the time of the backup clock, and not correct the time of the local slave clock, when the first time deviation between the master clock and the local slave clock in the first clock cycle is greater than the preset deviation value; The second synchronization module is used to use the time of the master clock to correct the time of the local slave clock and filter out the time of the backup clock when the first time deviation between the master clock and the local slave clock in the second clock cycle is not greater than the preset deviation value.
8. The device according to claim 6, characterized in that The deviation acquisition module acquires a second time deviation between the master clock and the local slave clock in each clock cycle within a preset number of clock cycles after the second clock cycle, and a third time deviation between the backup clock and the local slave clock in each clock cycle, including: For each clock cycle of a preset number of clock cycles after the second clock cycle, receiving a first time corresponding to the master clock and a second time corresponding to the backup clock; Calculate the deviation between the first time corresponding to the master clock and the third time corresponding to the local slave clock to obtain a second time deviation between the master clock and the local slave clock; The deviation between the second time corresponding to the standby clock and the third time corresponding to the local slave clock is calculated to obtain a third time deviation between the standby clock and the local slave clock.
9. The device according to claim 6, characterized in that The device also includes: A third synchronization module is used to, when the first number is not greater than the second number, use the time of the master clock to correct the time of the local slave clock in the clock cycle after the preset number of clock cycles, and filter out the time of the backup clock.
10. The device according to claim 6, characterized in that The device also includes: The pause correction module is used for not correcting the time of the local slave clock for the preset number of clock cycles.
11. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 5 when executing a program stored in a memory.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 5 are implemented.
