Time synchronization method, network device, and storage medium
By compensating for the time deviation and transmission delay between the slave clock and the master clock, the time synchronization accuracy problem caused by network asymmetry is solved, and higher time synchronization accuracy is achieved.
Patent Information
- Application Number
- CN202110640535.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-08
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-06-08
Smart Images

Figure CN115459871B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and in particular to a time synchronization method, network device, and storage medium. Background Technology
[0002] With the development of communication technology, data transmission speeds are increasing, and the requirements for time synchronization accuracy are also becoming more stringent. In distributed networks, the IEEE 1588 precision clock synchronization protocol standard for network measurement and control systems is mainly used to achieve time synchronization. In the process of synchronizing the slave clock with the master clock according to the IEEE 1588 protocol standard, the uplink transmission delay is required to equal the downlink transmission delay. However, in real-world environments, due to network asymmetry, the uplink transmission delay is not always equal to the downlink transmission delay, resulting in inaccurate calculated time deviation values and thus reducing the time synchronization accuracy of the slave clock.
[0003] Therefore, improving the time synchronization accuracy of the clock has become an urgent problem to be solved. Summary of the Invention
[0004] The main objective of this invention is to provide a time synchronization method, network device, and storage medium that effectively improves the time synchronization accuracy of the slave clock by compensating for the time deviation between the slave clock and the master clock.
[0005] In a first aspect, embodiments of the present invention provide a time synchronization method, comprising:
[0006] Obtain the time deviation value between the slave clock and the master clock; perform deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation; adjust the time of the slave clock according to the time deviation value after deviation compensation so that the slave clock and the master clock achieve time synchronization.
[0007] Secondly, embodiments of the present invention also provide a network device, the network device including a slave clock, a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for implementing communication between the processor and the memory, wherein the slave clock is used to synchronize time with the master clock in the host computer, and the computer program, when executed by the processor, implements the time synchronization method as described above.
[0008] Thirdly, embodiments of the present invention also provide a storage medium for computer-readable storage, characterized in that the storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of any of the time synchronization methods provided in this specification.
[0009] This invention provides a time synchronization method, network device, and storage medium. By acquiring the time deviation value between the slave clock and the master clock and performing deviation compensation on the time deviation value, a time deviation value after deviation compensation can be obtained, thereby improving the accuracy of the time deviation value. By adjusting the time of the slave clock according to the time deviation value after deviation compensation, the slave clock and the master clock can be synchronized, thus effectively improving the time synchronization accuracy of the slave clock.
[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a schematic diagram of the structure of a time synchronization system provided in an embodiment of the present invention;
[0013] Figure 2 This is a schematic block diagram of the structure of a network device provided in an embodiment of the present invention;
[0014] Figure 3 This is a schematic flowchart of a time synchronization method provided in an embodiment of the present invention;
[0015] Figure 4 This is a schematic flowchart illustrating a sub-step for determining the actual time deviation value provided in an embodiment of the present invention;
[0016] Figure 5 This is a schematic diagram illustrating time synchronization between a slave clock and a master clock, provided by an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.
[0019] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0020] This invention provides a time synchronization method, a network device, and a storage medium. The time synchronization method can be applied to a network device, and by compensating for the time deviation between the slave clock and the master clock, the time synchronization accuracy of the slave clock can be effectively improved.
[0021] Please see Figure 1 , Figure 1 This is a schematic diagram of the structure of a time synchronization system provided in an embodiment of the present invention. Figure 1 As shown, the time synchronization system includes a master clock and at least one slave clock. Each slave clock can synchronize with the master clock.
[0022] For example, the slave clock can be the clock in the network device, and the master clock can be the clock in the master controller.
[0023] For example, the slave clock and the master clock can be clocks in the same network device.
[0024] It should be noted that network devices can include, but are not limited to, repeaters, bridges, routers, gateways, firewalls, and switches. In a distributed network, the slave clock in a network device can periodically synchronize with the master clock in the master controller to ensure that the slave clock's time is as consistent as possible with the master clock's time.
[0025] In some embodiments, the network device may obtain the time deviation value between the slave clock and the master clock; perform deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation; and adjust the time of the slave clock according to the time deviation value after deviation compensation so that the slave clock and the master clock can achieve time synchronization.
[0026] Please see Figure 2 , Figure 2 This is a schematic block diagram of the structure of a network device provided in an embodiment of the present invention.
[0027] Please see Figure 2The network device 1000 may include a processor 1001, a memory 1002, and a slave clock 1003. The processor 1001 and the memory 1002 may be connected via a bus, such as an I2C (Inter-integrated Circuit) bus or any suitable bus.
[0028] The memory 1002 may include a non-volatile storage medium and internal memory. The non-volatile storage medium may store an operating system and a computer program. The computer program includes program instructions that, when executed, cause the processor to perform any time synchronization method.
[0029] Among them, the slave clock 1003 is used to synchronize time with the master clock in the master controller.
[0030] The processor 1001 provides computing and control capabilities to support the operation of the entire network device 1000.
[0031] In one embodiment, the processor 1001 is configured to run a computer program stored in the memory 1002, and to perform the following steps when executing the computer program:
[0032] Obtain the time deviation value between the slave clock and the master clock; perform deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation; adjust the time of the slave clock according to the time deviation value after deviation compensation so that the slave clock and the master clock achieve time synchronization.
[0033] In one embodiment, the processor 1001 is also configured to implement:
[0034] Obtain the transmission delay between the slave clock and the master clock; perform delay compensation on the transmission delay to obtain the transmission delay after delay compensation;
[0035] In one embodiment, when the processor 1001 performs deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation, it is configured to:
[0036] Based on the transmission delay after delay compensation, a deviation compensation value corresponding to the time deviation value is determined; deviation compensation is performed on the time deviation value according to the deviation compensation value to obtain the time deviation value after deviation compensation.
[0037] In one embodiment, when implementing delay compensation for the transmission delay, the processor 1001 is configured to:
[0038] Determine the delay compensation value corresponding to the transmission delay, and perform delay compensation on the transmission delay based on the delay compensation value.
[0039] In one embodiment, before determining the delay compensation value corresponding to the transmission delay, the processor 1001 is further configured to:
[0040] Within the same time synchronization period, determine the actual time deviation value when the slave clock synchronizes with the slave clock.
[0041] In one embodiment, the processor 1001, in addition to determining the delay compensation value corresponding to the transmission delay, is further configured to:
[0042] The delay compensation value is determined based on the time deviation value and the actual time deviation value.
[0043] In one embodiment, when determining the actual time deviation value when the slave clock is synchronized with the slave clock, the processor 1001 is configured to:
[0044] Within the time synchronization period, the number of interactions between the slave clock and the master clock during time synchronization is determined; based on the sending and receiving times corresponding to every two sets of adjacent synchronization messages within the time synchronization period, at least one first frequency deviation value corresponding to the slave clock is determined, where the first frequency deviation value is the frequency deviation value when the slave clock and the master clock perform time synchronization within the time synchronization period; based on the precise time protocol, at least one first time deviation value corresponding to the slave clock is determined, where the first time deviation value is the time deviation value when the slave clock and the master clock perform time synchronization within the time synchronization period; and based on all the first frequency deviation values, the number of interactions, and all the first time deviation values, the actual time deviation value is determined.
[0045] In one embodiment, when the processor 1001 determines the deviation compensation value corresponding to the time deviation value based on the transmission delay after delay compensation, it is configured to:
[0046] Based on the transmission delay after delay compensation, the slave clock is controlled to synchronize with the master clock, and the second frequency deviation value corresponding to the slave clock in every two adjacent time synchronization cycles is determined; based on all the second frequency deviation values and the preset number of deviation compensations, the deviation compensation value is determined.
[0047] In one embodiment, the two adjacent time synchronization periods include a first time synchronization period and a second time synchronization period; when determining the second frequency deviation value corresponding to the slave clock in every two adjacent time synchronization periods, the processor 1001 is configured to:
[0048] Determine the first actual time deviation value of the slave clock within the first time synchronization period; determine the second actual time deviation value of the slave clock within the second time synchronization period; and determine the second frequency deviation value based on the first actual time deviation value and the second actual time deviation value.
[0049] In one embodiment, when the processor 1001 determines the deviation compensation value based on all the second frequency deviation values and a preset number of deviation compensations, it is configured to:
[0050] Determine the total frequency deviation value corresponding to all the second frequency deviation values; determine the corresponding average frequency deviation value based on the number of deviation compensations and the total frequency deviation value; determine the deviation compensation value based on the average frequency deviation value.
[0051] The processor 1001 can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0052] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0053] Please see Figure 3 , Figure 3 This is a schematic flowchart illustrating a time synchronization method provided in an embodiment of the present invention. This time synchronization method can be applied to network devices to compensate for the time deviation between the slave clock and the master clock, effectively improving the time synchronization accuracy of the slave clock. The time synchronization method includes steps S10 to S30.
[0054] Step S10: Obtain the time deviation value between the slave clock and the master clock.
[0055] For example, the time synchronization method provided in this embodiment of the invention can be applied to time synchronization scenarios such as distributed Ethernet system clock synchronization system, IEEE1588 protocol clock synchronization system, ultra-high precision clock synchronization and base station clock synchronization. It can improve the time synchronization accuracy of the slave clock by compensating for the time deviation value of the slave clock when the slave clock is synchronized with the master clock.
[0056] It should be noted that the IEEE 1588 precision clock synchronization protocol standard for network measurement and control systems can be used to achieve time synchronization between slave clocks and the master clock. The basic function of the IEEE 1588 protocol standard is to keep all slave clocks in a distributed network synchronized with the master clock, and it defines a Precision Time Protocol (PTP) to achieve time synchronization.
[0057] For example, based on the Precision Time Protocol (PTP), the time synchronization process between a slave clock and a master clock may include an offset measurement phase and a delay measurement phase. The offset measurement phase involves measuring the time offset between the master and slave clocks and eliminating the time offset on the slave clock. The delay measurement phase is used to determine the transmission delay of messages between the master and slave clocks. It can be understood that the time offset refers to the time difference between the master and slave clocks during time synchronization. The time offset is represented as offset. The transmission delay refers to the delay time in which messages are transmitted in the network, and is represented as delay.
[0058] For example, the time offset may include a downlink time offset value offset↓ and an uplink time offset value offset↑, wherein the downlink time offset value offset↓ represents the time offset between the slave clock and the master clock when the master clock sends a synchronization message to the slave clock; the uplink time offset value offset↑ represents the time offset between the slave clock and the master clock when the slave clock sends a delay request message to the master clock.
[0059] For example, the transmission delay includes downlink transmission delay (delay↓) and uplink transmission delay (delay↑). Downlink transmission delay (delay↓) refers to the network transmission delay time between the master clock and the slave clock; uplink transmission delay (delay↑) refers to the network transmission delay time between the slave clock and the master clock.
[0060] In some embodiments, the time synchronization method provided by the present invention may further include: obtaining the transmission delay between the slave clock and the master clock. It should be noted that the transmission delay can be obtained when obtaining the time deviation value between the slave clock and the master clock.
[0061] The process of obtaining the time deviation between the slave clock and the master clock may include: obtaining the synchronization message sending time, synchronization message receiving time, delay request message sending time, and delay request message receiving time during the synchronization interaction between the slave clock and the master clock based on a precise time protocol; if the uplink time deviation is equal to the downlink time deviation and the uplink transmission delay is equal to the downlink transmission delay, then the time deviation is determined based on the synchronization message sending time, synchronization message receiving time, delay request message sending time, and delay request message receiving time.
[0062] The process of obtaining the transmission delay between the slave clock and the master clock may include: if the uplink time deviation is equal to the downlink time deviation and the uplink transmission delay is equal to the downlink transmission delay, then the transmission delay is determined based on the synchronization message sending time, the synchronization message receiving time, the delay request message sending time, and the delay request message receiving time.
[0063] For example, the time deviation and transmission delay between the slave clock and the master clock can be obtained based on a precise time protocol. For instance, during the deviation measurement phase, the master clock can send a synchronization message to the slave clock at regular intervals and record the transmission time as t1; when the slave clock receives the synchronization message, it records the reception time as t2. The synchronization message transmission time t1 can be sent from the master clock to the slave clock via a follow message. During the delay measurement phase, the slave clock sends a delay request message to the master clock and records the current time t3 simultaneously, where t3 is the transmission time of the delay request message. When the master clock receives the delay request message, it records the reception time as t4 and sends the reception time t4 to the slave clock via a delay response message.
[0064] For example, according to the Precision Time Protocol, the relationship between the time deviation value and the transmission delay can be derived as follows:
[0065] t2-t1 = delay↓ + offset↓
[0066] t4-t3 = delay↑ - offset↑
[0067] In some embodiments, when the downlink time offset value (offset↓) equals the uplink time offset value (offset↑) and the uplink transmission delay (delay↑) equals the downlink transmission delay (delay↓), the time offset value (offset) and the transmission delay (delay) are as follows:
[0068] delay = [(t2-t1)+(t4-t3)] / 2
[0069] offset = [(t2-t1)-(t4-t3)] / 2
[0070] In some embodiments, to ensure the validity of the data, when obtaining the time deviation value between the slave clock and the master clock and the transmission delay, extreme values can be removed or the average value can be taken for the time deviation value and the transmission delay.
[0071] By obtaining the transmission delay and time deviation values between the slave clock and the master clock, subsequent delay compensation and time deviation compensation can be performed to reduce the synchronization error between the slave clock and the master clock, effectively improving the time synchronization accuracy of the slave clock.
[0072] Step S20: Perform deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation.
[0073] It should be noted that the aforementioned time offset and transmission delay values are obtained under the premise that the downlink time offset (↓) equals the uplink time offset (↑) and the downlink transmission delay (↓) equals the uplink transmission delay (↑). However, in real-world environments, due to network transmission asymmetry, the downlink transmission delay (↓) and uplink transmission delay (↑) can be affected by factors such as intermediate device strategies, network load, and asymmetric transmission paths. Therefore, the downlink transmission delay (↓) may not equal the uplink transmission delay (↑). Furthermore, due to the influence of clock state characteristics, such as the crystal oscillator type, frequency stability, and temperature characteristics, the downlink time offset (↓) may not equal the uplink time offset (↑). In this embodiment of the invention, compensation is needed for the transmission delay and time offset values to improve the time synchronization accuracy of the clock. It should be noted that delay compensation is one process within the time offset value offset compensation.
[0074] For example, the transmission delay can first be compensated to obtain a delay-compensated transmission delay; then, based on the delay-compensated transmission delay, the time deviation value can be compensated to obtain a time deviation value. This allows the slave clock's time to be adjusted according to the time deviation value after compensation, enabling the slave clock to synchronize with the master clock and effectively improving the slave clock's time synchronization accuracy. In this embodiment of the invention, how to compensate for the transmission delay and how to compensate for the time deviation value will be described in detail.
[0075] It is understandable that both delay compensation and time deviation compensation aim to reduce the synchronization error between the slave and master clocks. For example, delay compensation and deviation compensation can be performed periodically to gradually reduce the synchronization error between the slave and master clocks.
[0076] In some embodiments, after obtaining the transmission delay between the slave clock and the master clock, delay compensation can be performed on the transmission delay to obtain a delay-compensated transmission delay. The delay compensation can include: determining a delay compensation value corresponding to the transmission delay, and performing delay compensation on the transmission delay based on the delay compensation value.
[0077] For example, before determining the delay compensation value corresponding to the transmission delay, the actual time deviation value when the slave clock synchronizes with the master clock can also be determined within the same time synchronization period. It should be noted that within a time synchronization period, the slave clock and master clock will exchange synchronization messages multiple times; at each synchronization message exchange, the current time deviation value will be calculated. The actual time deviation value is obtained by averaging multiple time deviation values generated within the same time synchronization period. The synchronization messages are those generated during the deviation measurement phase and the delay measurement phase.
[0078] Please see Figure 4 , Figure 4 This is a schematic flowchart of a sub-step for determining the actual time deviation value provided by an embodiment of the present invention, which may specifically include the following steps S201 to S204.
[0079] Step S201: Within the time synchronization period, determine the number of interactions when the slave clock and the master clock synchronize their time.
[0080] For example, the number of interactions between the slave clock and the master clock during time synchronization within the same time synchronization period can be determined. The number of interactions, n, can be represented as such. The number of interactions, n, can be determined based on the actual situation, for example, it can be determined based on the clock frequencies of the slave and master clocks; the specific value is not limited here.
[0081] Step S202: Based on the sending time and receiving time corresponding to every two groups of adjacent synchronization messages within the time synchronization period, determine at least one first frequency deviation value corresponding to the slave clock. The first frequency deviation value is the frequency deviation value when the slave clock and the master clock perform time synchronization within the time synchronization period.
[0082] It should be noted that each pair of adjacent synchronization messages can include the i-th synchronization message and the (i-1)-th synchronization message within the time synchronization period. Each time synchronization includes a deviation measurement phase and a delay measurement phase. Therefore, the transmission time includes the synchronization message transmission time t1 and the delay request message transmission time t3; the reception time includes the recording synchronization message reception time t2 and the delay request message reception time t4.
[0083] For example, during the i-th synchronization message exchange, according to the Precision Time Protocol (PTP), the relationship between the time deviation value and the transmission delay can be obtained as follows:
[0084]
[0085]
[0086] Since the interaction time between two adjacent synchronization messages is extremely short, the downlink transmission delay (delay↓) and the uplink transmission delay (delay↑) remain constant. Therefore, the following relationship exists between the downlink transmission delay (delay↓) and the uplink transmission delay (delay↑) in every two sets of adjacent synchronization messages:
[0087] delay i-1 ↓ = delay i ↓
[0088] delay i-1 ↑ = delay i ↑
[0089] Therefore, at least one first frequency deviation value corresponding to the clock can be determined as follows:
[0090]
[0091] In the formula, Δt i This indicates the frequency deviation value.
[0092] By determining the transmission and reception times of every two adjacent sets of synchronization messages within the time synchronization period, at least one first frequency deviation value corresponding to the clock can be determined.
[0093] Step S203: Based on the precise time protocol, determine at least one first time deviation value corresponding to the slave clock, wherein the first time deviation value is the time deviation value when the slave clock and the master clock synchronize time within the time synchronization period.
[0094] For example, based on a precise time protocol, at least one first time deviation value corresponding to a clock is determined, wherein the first time deviation value can be represented as offset. i First time deviation value (offset) i It can be obtained from the following formula:
[0095] offset i =T d +Δt i +θ i
[0096] In the formula, offset iθ represents the time deviation value during the i-th message exchange; i Indicates other types of random errors; T d This represents the actual time deviation value within a time synchronization period.
[0097] Step S204: Determine the actual time deviation value based on all the first frequency deviation values, the number of interactions, and all the first time deviation values.
[0098] It should be noted that due to random error θ i As the number of interactions increases, the random error θ i The mean of θ approaches 0, therefore, the random error θ i It can be ignored.
[0099] For example, the actual time deviation value is determined based on all first frequency deviation values, the number of interactions, and all first time deviation values, as shown below:
[0100]
[0101] The actual time deviation value T can be calculated using the above formula. d .
[0102] By using all first frequency deviation values, the number of interactions, and all first time deviation values, the actual time deviation value corresponding to the clock within the same time synchronization period can be accurately determined.
[0103] In this embodiment of the invention, the actual time deviation value T when the slave clock and slave clock synchronize are determined. d Then, based on the actual time deviation value T d Determine the delay compensation value corresponding to the transmission delay.
[0104] In some embodiments, determining the delay compensation value corresponding to the transmission delay may include: determining the delay compensation value based on the time deviation value and the actual time deviation value.
[0105] For example, the delay compensation value can be represented as C1, and the delay compensation value C1 can be calculated by the following formula:
[0106] C1 = offset - T d
[0107] In the formula, offset represents the time deviation value; the unit of the delay compensation value C1 can be ns.
[0108] For example, the transmission delay is compensated based on the delay compensation value C1 to obtain the delay-compensated transmission delay. The delay-compensated transmission delay can be represented as Tdelay, as shown below:
[0109] Tdelay = delay + C1
[0110] After compensating for the transmission delay based on the delay compensation value C1, the time deviation between the slave clock and the master clock can be expressed as Toffset. It can be understood that delay compensation reduces the synchronization error between the slave clock and the master clock by C1; after delay compensation, the time deviation value Toffset equals the actual time deviation value T. d .
[0111] By compensating for transmission delay, the accuracy of transmission delay can be effectively improved, thereby improving the time synchronization accuracy of the slave clock.
[0112] In this embodiment of the invention, after delay compensation for transmission delay, in order to further improve the time synchronization accuracy of the slave clock, deviation compensation for time deviation value is also required.
[0113] In some embodiments, time deviation compensation may include: determining a deviation compensation value corresponding to the time deviation value based on the transmission delay after delay compensation; and performing deviation compensation on the time deviation value according to the deviation compensation value to obtain a time deviation value after deviation compensation.
[0114] It should be noted that after delay compensation, it can be determined that the uplink transmission delay is equal to the downlink transmission delay. Therefore, this embodiment of the invention determines the deviation compensation value corresponding to the time deviation value while keeping the transmission delay constant.
[0115] In some implementations, determining the deviation compensation value corresponding to the time deviation value based on the transmission delay after delay compensation may include: controlling the slave clock to synchronize with the master clock according to the transmission delay after delay compensation, and determining the second frequency deviation value corresponding to the slave clock in every two adjacent time synchronization cycles; determining the deviation compensation value based on all the second frequency deviation values and a preset number of deviation compensations.
[0116] It should be noted that since the frequency stability of the clock crystal oscillator affects the clock frequency, the impact of the frequency deviation of the slave clock on the synchronization error needs to be considered. By determining the deviation compensation value based on the frequency deviation, the influence of the crystal oscillator's frequency stability on time synchronization can be eliminated, thereby improving the time synchronization accuracy of the slave clock.
[0117] For example, based on the transmission delay after delay compensation, the slave clock can be controlled to perform multiple time synchronizations with the master clock, and the actual time deviation value within the same time synchronization period can be calculated. Since the actual time deviation value is Toffset after delay compensation, the calculated actual time deviation value is Toffset during the j-th time synchronization. j .
[0118] For example, two adjacent time synchronization periods include a first time synchronization period and a second time synchronization period.
[0119] For example, when determining the second frequency deviation value corresponding to the slave clock in every two adjacent time synchronization periods, the first actual time deviation value corresponding to the slave clock in the first time synchronization period can be determined first; then, the second actual time deviation value corresponding to the slave clock in the second time synchronization period can be determined; and the second frequency deviation value can be determined based on the first actual time deviation value and the second actual time deviation value.
[0120] For example, within the first time synchronization period, the calculated first actual time deviation value is Toffset. j-1 Within the second time synchronization period, the calculated second actual time deviation value is Toffset. j The calculation of the first actual time deviation value and the second actual time deviation value can be found in the detailed explanation of the above embodiment for determining the actual time deviation value when the slave clock and slave clock synchronize, and the specific process will not be repeated here.
[0121] In some embodiments, to ensure the validity of the calculated actual time deviation value, when calculating the actual time deviation value within the same time synchronization period, extreme values can be removed or the average value can be taken.
[0122] For example, the second frequency deviation value is determined by the following formula:
[0123] ΔO j =Toffset j -Toffset j-1
[0124] In the formula, ΔO j This represents the second frequency deviation value corresponding to the j-th time synchronization. In this invention, the second frequency deviation values corresponding to multiple time synchronization periods can be calculated to obtain multiple second frequency deviation values.
[0125] In some implementations, determining the deviation compensation value based on all second frequency deviation values and a preset number of deviation compensations may include: determining the total frequency deviation value corresponding to all second frequency deviation values; determining the corresponding average frequency deviation value based on the number of deviation compensations and the total frequency deviation value; and determining the deviation compensation value based on the average frequency deviation value.
[0126] For example, the preset number of deviation compensations is denoted as m. The number of deviation compensations m can be determined according to the actual situation, and the specific value is not limited here.
[0127] In this embodiment of the invention, the deviation compensation value can be determined by the following formula:
[0128]
[0129] In the formula, This represents the total frequency deviation corresponding to all second frequency deviation values; This represents the average frequency deviation, i.e., the deviation compensation value C2. The unit of the deviation compensation value C2 can be ns.
[0130] After determining the deviation compensation value corresponding to the time deviation value, the time deviation value can be compensated based on the deviation compensation value to obtain the time deviation value after deviation compensation. For example, the time deviation value after deviation compensation can be determined by summing the deviation compensation value and the actual time deviation value. It can be understood that after delay compensation, the current time deviation value is equal to the actual time deviation value.
[0131] For example, the time deviation value after deviation compensation can be represented as offset′, which is obtained by the following formula:
[0132] offset′=Toffset+C2
[0133] In the formula, Toffset represents the actual time deviation value.
[0134] By determining the deviation compensation value corresponding to the time deviation value, the time deviation value can be compensated according to the deviation compensation value to obtain the time deviation value after deviation compensation.
[0135] Step S30: Adjust the time of the slave clock according to the time deviation value after deviation compensation, so that the slave clock and the master clock can be synchronized.
[0136] For example, after obtaining the time deviation value offset′ after deviation compensation, the slave clock time can be adjusted according to the time deviation value offset′. For instance, the slave clock time can be increased by C2, thereby reducing the synchronization error between the slave clock and the master clock by C2.
[0137] By adjusting the slave clock's time based on the time deviation value after deviation compensation, the slave clock and master clock can be synchronized, which can reduce the synchronization error between the slave clock and master clock and effectively improve the time synchronization accuracy of the slave clock.
[0138] Please see Figure 5 , Figure 5 This is a schematic diagram illustrating time synchronization between a slave clock and a master clock according to an embodiment of the present invention. Figure 5 As shown, at time T1, the synchronization error between the slave clock and the master clock is E; at time T2, for example after delay compensation, the synchronization error between the slave clock and the master clock is E-C1; at time T3, for example after deviation compensation, the synchronization error between the slave clock and the master clock is E-C1-C2. Since the synchronization error between the slave clock and the master clock gradually decreases, the time synchronization accuracy of the slave clock can be improved.
[0139] In this embodiment of the invention, after adjusting the slave clock time based on the time deviation value after deviation compensation, new delay compensation C1 and deviation compensation C2 can be calculated periodically, and the slave clock time can be adjusted based on the new delay compensation C1 and deviation compensation C2. This maintains the time synchronization accuracy of the slave clock.
[0140] The time synchronization method, network device, and storage medium provided in the above embodiments, by acquiring the transmission delay and time deviation values between the slave clock and the master clock, can subsequently perform delay compensation for the transmission delay and deviation compensation for the time deviation values, thereby reducing the synchronization error between the slave clock and the master clock and effectively improving the time synchronization accuracy of the slave clock. By determining at least one first frequency deviation value corresponding to the slave clock based on the transmission and reception times corresponding to every two adjacent sets of synchronization messages within the time synchronization period, and by accurately determining the actual time deviation corresponding to the slave clock within the same time synchronization period based on all first frequency deviation values, the number of interactions, and all first time deviation values, the actual time deviation corresponding to the slave clock within the same time synchronization period can be accurately determined. The time difference can be effectively improved by compensating for the transmission delay, thereby improving the time synchronization accuracy of the slave clock. By determining the deviation compensation value based on the frequency deviation, the influence of crystal oscillator frequency stability on time synchronization can be eliminated, thus improving the time synchronization accuracy of the slave clock. By determining the deviation compensation value corresponding to the time deviation, the time deviation can be compensated based on the compensation value to obtain the time deviation value after deviation compensation. Adjusting the slave clock's time based on the time deviation value after deviation compensation enables time synchronization between the slave and master clocks, reducing the synchronization error between them and effectively improving the time synchronization accuracy of the slave clock.
[0141] This invention also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs that can be executed by one or more processors to implement the steps of any of the time synchronization methods provided in the specification of this invention.
[0142] For example, when the program is loaded by the processor, it can perform the following steps:
[0143] Obtain the time deviation value between the slave clock and the master clock; perform deviation compensation on the time deviation value to obtain the time deviation value after deviation compensation; adjust the time of the slave clock according to the time deviation value after deviation compensation so that the slave clock and the master clock achieve time synchronization.
[0144] The storage medium can be an internal storage unit of the network device described in the foregoing embodiments, such as the hard drive or memory of the network device. Alternatively, the storage medium can be an external storage device of the network device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the network device.
[0145] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware embodiments, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0146] It should be understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. It should be noted that, herein, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0147] The sequence numbers of the above embodiments of the present invention are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The above descriptions are only specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A time synchronization method, characterized in that, The method includes: Obtain the time offset between the slave clock and the master clock, as well as the transmission delay; Determine the delay compensation value corresponding to the transmission delay, and perform delay compensation on the transmission delay according to the delay compensation value to obtain the transmission delay after delay compensation; Based on the transmission delay after delay compensation, determine the deviation compensation value corresponding to the time deviation value; The time deviation value is compensated according to the deviation compensation value to obtain the time deviation value after deviation compensation. The time of the slave clock is adjusted according to the time deviation value after deviation compensation, so that the slave clock and the master clock are synchronized.
2. The time synchronization method according to claim 1, characterized in that, Before determining the delay compensation value corresponding to the transmission delay, the method further includes: Within the same time synchronization period, determine the actual time deviation value when the slave clock synchronizes with the slave clock; Determining the delay compensation value corresponding to the transmission delay includes: The delay compensation value is determined based on the time deviation value and the actual time deviation value.
3. The time synchronization method according to claim 2, characterized in that, Determining the actual time deviation value when the slave clock synchronizes with the slave clock includes: Within the time synchronization period, determine the number of interactions when the slave clock and the master clock synchronize their time. Based on the transmission and reception times of every two adjacent sets of synchronization messages within the time synchronization period, at least one first frequency deviation value corresponding to the slave clock is determined, where the first frequency deviation value is the time synchronization period. The frequency deviation value when the slave clock and the master clock are synchronized; Based on a precise time protocol, at least one first time deviation value is determined for the slave clock, wherein the first time deviation value is the time deviation value when the slave clock synchronizes with the master clock within the time synchronization period; The actual time deviation value is determined based on all the first frequency deviation values, the number of interactions, and all the first time deviation values.
4. The time synchronization method according to claim 1, characterized in that, The step of determining the deviation compensation value corresponding to the time deviation value based on the transmission delay after delay compensation includes: Based on the transmission delay after delay compensation, the slave clock is controlled to synchronize with the master clock, and the second frequency deviation value of the slave clock in every two adjacent time synchronization cycles is determined. The deviation compensation value is determined based on all the second frequency deviation values and the preset number of deviation compensations.
5. The time synchronization method according to claim 4, characterized in that, The two adjacent time synchronization periods include First time synchronization period and second time synchronization period; Determining the second frequency deviation value of the slave clock in every two adjacent time synchronization cycles includes: Determine the first actual time deviation value corresponding to the slave clock within the first time synchronization period; Determine the second actual time deviation value corresponding to the slave clock within the second time synchronization period; The second frequency deviation value is determined based on the first actual time deviation value and the second actual time deviation value.
6. The time synchronization method according to claim 4, characterized in that, The step of determining the deviation compensation value based on all the second frequency deviation values and the preset number of deviation compensations includes: Determine the total frequency deviation value corresponding to all the second frequency deviation values; Based on the number of deviation compensations and the total frequency deviation, determine the corresponding average frequency deviation. The deviation compensation value is determined based on the average frequency deviation.
7. A network device, characterized in that, Includes processor, memory, and slave clock; The memory is used to store programs; The slave clock is used to synchronize time with the master clock in the master controller; The processor is configured to execute the program and, in executing the program, implement the time synchronization method as described in any one of claims 1 to 6.
8. A storage medium for readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the time synchronization method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Clock synchronization method and device
CN107395307A
