Summary of the invention
The defective poor for the universality that overcomes time synchronized in the active computer network application, that precision is low, the present invention proposes a kind of high-accuracy time synchronizing apparatus, system and method that is used for computer network.
According to an aspect of the present invention; A kind of time synchronism equipment that is used for network system has been proposed; Comprise; GTP transceiver, MAC controller, transceive data bag buffer queue and PCIe endpoint controller is characterized in that, said time synchronism equipment also comprises one or more timestamp insert module and one or more time synchronized algorithm PCS time stamp generator based on prediction;
Wherein, said PCS time stamp generator is used for receiving and sending synchronizing clock signals, and generation time stabs; Said timestamp insert module is connected with PCS time stamp generator, MAC controller and transceive data bag buffer queue respectively, said timestamp is inserted into the physical link layer of packet; Said timestamp insert module is before the packet that receives from said MAC controller outputs to the formation of reception packet buffering, to insert timestamp; The packet that sends in the packet buffering formation inserted timestamp before sending to said MAC controller.
Wherein, said PCS time stamp generator is according to frequency preset control word and crystal oscillator clock signal, and output time stabs.
Wherein, said PCS time stamp generator receives synchronised clock input signal and crystal oscillator clock signal, and according to the frequency preset control word, generation time stabs and offers said timestamp insert module.
Wherein, said PCS time stamp generator comprises:
Direct synthesizer is used for producing clock frequency according to reference clock signal and frequency control word;
The high bit register of timestamp, the low bit register of timestamp and timestamp low counter are used to receive the clock frequency that said direct synthesizer produces, and output time stabs the timestamp insert module or is provided for the master clock timestamp.
According to a further aspect in the invention, propose a kind of clock synchronization system that is used for network system, comprised a plurality of described time synchronism equipments; Wherein, One of them of said a plurality of time synchronism equipments be as main equipment, remaining time synchronism equipment as slave unit, said main equipment produces synchronised clock output signal; Remaining slave unit receives said synchronised clock output signal, realizes the time synchronized of system.
Wherein, the PCS time stamp generator of said main equipment is according to frequency preset control word and crystal oscillator clock signal, and output time stabs to the timestamp insert module of said main equipment and said slave unit.
Wherein, said slave unit PCS time stamp generator receives said synchronised clock output signal and crystal oscillator clock signal, and according to the frequency preset control word, generation time stabs the timestamp insert module that offers slave unit.
According to another aspect of the invention, proposed a kind of method for synchronizing time that uses above-mentioned clock synchronization system, having comprised:
Step 10), slave unit receive the synchronised clock output signal of main equipment, the current time of reading this slave unit;
Step 20), obtain time difference Δ t between reading for the third time and read for the second time and read for the second time and reading for the first time
2With Δ t
1
Step 30), obtain the frequency signal of reference clock;
wherein; N is the FREQUENCY CONTROL word bit number;
is the original frequency control word; Upgrade said frequency control word,
wherein m is the timestamp precision;
Step 40), adjust the clock frequency of slave unit through frequency control word
; And calculate the frequency control word
that upgrades and use said frequency control word
adjustment slave unit clock frequency, realize the synchronous of system.
Wherein, said method also comprises:
Step 50), calculate the double time difference Δ t that slave unit reads main equipment
i=T
i-T
I-1Obtain the error e in reading for twice
0(i) and e
1(i),
e
1(i)=2
m-Δ t
i, the calculated rate control word
Through
The clock frequency of adjustment slave unit.
The present invention utilizes hardware circuit to realize timestamp being write down timestamp the position move on to physical link layer, has eliminated buffer delay in the common software timestamp and interrupt response time and has postponed the influence that brings; (Prediction-based Clock Synchronization PCS) has realized that the precision clock of each measured node is synchronous through the time synchronized algorithm based on prediction; The present invention has improved the timestamp precision, can guarantee that each measured node timestamp error is no more than 100ns, reaches and the precision that adopts the GPS locking phase to work as.
Embodiment
Below in conjunction with accompanying drawing and specific embodiment a kind of high-accuracy time synchronizing apparatus, system and method that is used for computer network provided by the invention is described in detail.
Fig. 1 illustrates the synchronous overall plan of split-second precision according to an embodiment of the invention; As shown in Figure 1; At first utilize hardware circuit (such as similar structures such as FPGA, PLA) to realize the timestamp generative circuit; The rise time synchronizer writes down the position with timestamp and moves on to physical link layer, eliminates buffer delay in the common software approach timestamp and interrupt response time and postpones the influence that brings; Each synchronizer is connected mutually; Set a main synchronizer; Need synchronous equipment to be connected to form clock synchronization system all; (Prediction-based ClockSynchronization PCS) realizes the clock precise synchronization of each node device in this clock synchronization system, to use time synchronized algorithm based on prediction.In the present embodiment, make up the timestamp generative circuit through FPGA, likewise, describe based on following principle to the timestamp generative circuit, the timestamp generative circuit also can use PLA, ASIC or other integrated circuits to realize.In the present embodiment, when using timestamp generative circuit structure clock synchronization system, utilize RS422 to connect synchronizer, likewise, the present invention also can use known such as other interconnection techniques such as RS484, RS232 or USB, PCI.In the time synchronized system that makes up, use said PCS method for synchronizing time, realize the high-precise synchronization of institute's connection device.
Fig. 2 receives the position view that adds timestamp in the scene for network packet; Receive in the scene at legacy network interface card packet; Packet in the user's space territory arrives NIC based on concrete application program; NIC is transferred to host memory with packet according to procotol (such as TCP/IP), through the packet that interrupts notifying driver handles to receive.Response of host interrupts, and copies the packet of receiving to the upper-layer protocol stack and handles, and the packet after the processing finally arrives application program.As shown in Figure 2, in this process, timestamp can add in a plurality of positions: media interviews control (Media Access Control, MAC) layer, Drive Layer and application layer.It is different that the diverse location joining day is stabbed the influence that postponed by buffer delay and interrupt response time; It is also different that timestamp and packet arrive the deviation of actual time; Wherein, take second place in the influenced minimum of MAC layer, Drive Layer, application layer is suffered has the greatest impact; Difference is at Millisecond.This deviation of definition is the timestamp additive error in the embodiments of the invention.
Fig. 3 is the timestamp deviation sketch map that crystal oscillator produced with same nominal frequency, and it is unstable that the clock that generation time stabs receives crystal oscillator shake and drift to influence its speed, thereby the timestamp of generation also can have deviation in time.
Fig. 4 is a neighbouring sample packet interval of timestamps sketch map among Fig. 3, and the two is to stab deviation by same nominal value crystal oscillator institute generation time.Thus, the deviation that definition is caused by the crystal oscillator instability among the present invention is the error of timestamp own.So the timestamp error that defines in the embodiments of the invention is made up of error of timestamp own and timestamp additive error, improves timing tracking accuracy and need set about from reducing error of timestamp own and additive error.
In the embodiments of the invention, timestamp is write down the position move on to physical link layer, by hardware circuit timestamp is joined in the application system, Fig. 5 is the timestamp synchronizer structure chart of the specific embodiment according to the present invention.Owing to after packet leaves MAC, stab with regard to the joining day, the feasible influencing factor that can get rid of various software delays in the timestamp additive error is brought up to nanosecond with the timestamp precision.
In the present embodiment, this circuitry structure realizes based on FPGA, can be applied in the network interface card this circuit structure or in other network measure equipment.
As shown in Figure 5, this time synchronism equipment comprises GTP (general packet radio service tunnel agreement) transceiver, MAC controller, transceive data bag buffer queue (reception data packet queue among the figure and transmission data packet queue) and PCIe (PCI Express) endpoint controller.The synchronised clock input and output directly link to each other with MAC controller through transceive data bag buffer queue in the existing equipment, control through software approach and realize synchronously.In the present embodiment; This time synchronized system, device also comprises one or more timestamp insert module and one or more PCS time stamp generator; Wherein, the PCS time stamp generator receives and sends synchronised clock, receives the control signal of packet handler; Be connected with the timestamp insert module; Control time is stabbed insert module, and the timestamp insert module is connected with PCS time stamp generator, MAC controller, packet handler and transceive data bag buffer queue respectively, timestamp is inserted into the physical link layer of network data.In the present embodiment, two timestamp insert modules shown in the figure, the present invention can use a timestamp insert module.
Need each synchronous parts through the input of the synchronised clock shown in Fig. 5, output interconnection (can be any type of serial input or other known connected mode on the physical connection); The clock signal that the PCS time stamp generator produces (for example is input to the timestamp insert module; The content of transfer of data is the timestamp information of 64 bits), in the timestamp insert module, clock signal is inserted in the network packet that receives or send.
Fig. 6 illustrates the detailed circuit of the PCS time stamp generator shown in Fig. 5, and is as shown in Figure 6, and the core of said generator is a direct synthesizer, and the control word adjustment generates clock frequency through adjusting frequency.In the present embodiment, the timestamp register is 64bit altogether, and high 32bit value representative is hanged down the 32bit value representation mark of second since 0 second number in morning on January 1st, 1970.The highest resolution that this expression mode can reach is 2
-32S, i.e. 233ps, and, be set to 0 through hanging down 32-mbit, can obtain resolution is 2
-mThe clock of s.The high 32bit of timestamp register counts initial value second and is write by main frame when the initialization through driver, therefore requires the main frame time to have a second class precision, and this can conveniently realize through Network Time Protocol; Low 32bit fractional part second is produced by internal counter, and counter is at direct synthesizer output clock frequency f
SynFollowing counting, the full back of meter produces carry signal, and high 32bit count value adds 1.
As shown in Figure 6, each parts links to each other through data wire, and wherein reference clock is the clock that external crystal-controlled oscillation shown in Figure 5 is imported, and frequency control word is that frequency preset is regulated parameter; The output valve of direct synthesizer is deposited in the timestamp low counter; The carry signal of timestamp low counter is input in the high bit register of timestamp, and when node is host node, this carry signal also will produce output pulse signal and offer from node; The value of the low bit register of high bit register of timestamp and timestamp is sent to the timestamp insert module; When node is during from node, the input pulse that utilizes host node to provide produces interrupt signal, and notice drives and reads the value that the current time stabs register.
Fig. 7 illustrates the detailed circuit of timestamp insert module shown in Figure 5; As shown in Figure 7; The packet that receives is deposited earlier in the register, before this packet outputs to the reception data packet queue, inserts present clock information (the present clock value is produced by hardware timestamping generative circuit shown in Figure 6) then; The data of sending in the data packet queue were also deposited earlier in the register before sending, and sent to MAC behind the insertion present clock; Wherein, data clock information is inserted the physical link layer of data.
In another embodiment of the present invention, the present invention proposes a kind of clock synchronization system, comprises a plurality of above-mentioned time synchronism equipments; Wherein, one of them of a plurality of time synchronism equipments produces synchronised clock output signal as main equipment; Said remaining time synchronism equipment as slave unit; Receive the synchronised clock output signal that main equipment sends,, realize the time synchronized of system through the time stamp generator of this equipment and the handled of timestamp insert module.All slave units are interconnected with this main synchronizer or link to each other respectively, constitute clock synchronization system, and said connected mode includes but not limited to RS484, RS232, RS422 and USB.The PCS time stamp generator of main equipment is according to frequency preset control word and crystal oscillator clock signal, and output time stabs to the timestamp insert module of said main equipment and said slave unit.Slave unit PCS time stamp generator receives said synchronised clock output signal and crystal oscillator clock signal, and according to the frequency preset control word, generation time stabs the timestamp insert module that offers this equipment.
A kind of clock synchronization algorithm (Prediction-based ClockSynchronization based on prediction has also been proposed among the present invention; PCS) accomplish a plurality of internodal clock synchronizations through said system; Need specify a host node to send reference clock when multinode is synchronous, be called from node with the synchronous node of host node, the appointment of main and subordinate node is decided according to application demand; Have no added limitations, interconnect through asynchronous serial bus between main and subordinate node.In the time of synchronously host node every at a distance from pulse of 1s output to respectively from node, receive pulse from node after, time for reading is stabbed register, measures one second result, adjustment DDS frequency control word expectation next second synchronism deviation minimum.Sequential sketch map of the present invention is as shown in Figure 8, and the present invention is divided into startup and synchronous two stages.
The startup stage:
The 0th step started from node, after the pulse per second (PPS) that receives host node output from node PCS time stamp generator, from Time Stamp Counter, read current time T
0, produce the driving of interrupt signal notice simultaneously and read this value;
In the 1st step, after the pulse per second (PPS) that receives host node output from node PCS time stamp generator once more, from Time Stamp Counter, read current time T
1, produce interrupt signal notice simultaneously and drive and read this value, drive the time value of utilizing the 0th step and the 1st step to read and calculate the 0th and go on foot and the 1st time difference Δ t between going on foot
1=T
1-T
0
In the 2nd step, after the pulse per second (PPS) that receives host node output from node PCS time stamp generator for the 3rd time, from Time Stamp Counter, read current time T
2, produce interrupt signal notice simultaneously and drive and read this value, drive the time value of utilizing the 1st step and the 2nd step to read and calculate the 1st and go on foot and the 2nd time difference Δ t between going on foot
2=T
2-T
1, and the formula below utilizing calculates the actual frequency of reference clock (crystal oscillator output);
Wherein N is the FREQUENCY CONTROL word bit number, and the present embodiment intermediate value is 32;
Be the original frequency control word, the present embodiment intermediate value is 0xABCC7712; The formula that drives below utilizing calculates new frequency control word
wherein m is the timestamp precision, and the present embodiment intermediate value is 24;
In the 3rd step, after the pulse per second (PPS) that receives host node output from node PCS time stamp generator the 4th, from Time Stamp Counter, read current time T
3, produce interrupt signal notice simultaneously and drive and read this value, drive the time value of utilizing the 2nd step and the 3rd step to read and calculate the 2nd and go on foot and the 3rd time difference Δ t between going on foot
3=T
3-T
2Use frequency control word
the adjustment clock frequency that calculates the 2nd step from node PCS time stamp generator, and calculate new frequency control word
by the formula that drives below utilizing
In the 4th step, after the pulse per second (PPS) that receives host node output from node PCS time stamp generator the 5th, from Time Stamp Counter, read current time T
4, produce the driving of interrupt signal notice simultaneously and read this value, use the frequency control word that calculates the 3rd step from node PCS time stamp generator
The adjustment clock frequency, and the formula that is gone on foot by driving utilization the top the 3rd calculates new frequency control word
So far, finish the startup stage.
B. synchronous phase:
Through the startup stage 4 steps whole after, synchronous from nodal clock and host node clock, but consider the unsteadiness of clock crystal oscillator, need continuous frequency of amendment control word from node, thereby keep long-term synchronous with host node;
1. after the pulse per second (PPS) that receives host node output from node PCS time stamp generator, from Time Stamp Counter, read current time T
i, produce the driving of interrupt signal notice simultaneously and read this value, drive and calculate the time difference Δ t that interrupts continuously for twice
i=T
i-T
I-1
2. drive and calculate preceding two step predicated error e
0(i) and e
1(i):
e
1(i)=2
m-Δ t
i, the computing formula that is not limited to provide in the present embodiment when calculating predicated error, the variable implication is ditto said in the formula;
3 from the node PCS timestamp generator used to calculate the last loop frequency control word?
Drive calculate next frequency control word?
Different frequency control words can make that the clock frequency that direct synthesizer is synthesized among Fig. 6 is different, if find from node host node in twice pulse spacing the time walked soon, need so and will turn down from the frequency control word of node, otherwise, transfer big.Through continuous adjustment, can guarantee to reach unanimity from nodal clock and host node clock.
When carrying out the synchronous and synchronism detection of concrete equipment, the equipment that needs are synchronous utilizes asynchronous serial connecting line interconnection (for example RS422) according to shown in Figure 10.Figure 10 is in order to verify the experimental situation of performance of the present invention; Network tester adopts Spirent company's T estCenter; Utilize its gigabit module to send test packet; Through optical splitter one road flow is divided into the two-way same traffic, is connected to two test nodes through isometric optical patchcord, it is constantly identical that packet arrives two test nodes.Two test nodes are installed on the high-performance server respectively.Mounting strap has two network interface cards of said synchronizer, starts the driven in synchronism method, and utilizes RS422 to connect two network interface cards and can carry out synchronously or test.
Figure 11 is two hours results of two card timestamp deviations adopting the PCS synchronized algorithm, and wherein abscissa is the Measuring Time point, and ordinate is two card timestamp deviations (unit is nanosecond), and is visible from the result, and the timestamp deviation is between-50ns~180ns.Figure 12 is for adopting two 12 hours statisticses of blocking the timestamp deviations of PCS synchronized algorithm; Wherein abscissa is the timestamp deviation; The frequency that ordinate occurs for this deviation; Visible from the result, the PCS algorithm has been accomplished the synchronous of two equipment well through the control word of adjusting frequency, and the most of the time is stabbed Deviation Control within 0~100ns.Figure 13 has shown the predicated error of PCS algorithm, and wherein abscissa is the Measuring Time point, and ordinate is two card timestamp deviations (unit is nanosecond), from the visible predicated error of result mainly be distributed in-50ns~50ns within.
What should explain at last is; Above embodiment is only in order to describe technical scheme of the present invention rather than the present technique method is limited; The present invention can extend to other modification, variation, application and embodiment on using, and therefore thinks that all such modifications, variation, application, embodiment are in spirit of the present invention and teachings.