Hello, I'm trying to alter the Servo clock (if that's possible?). I'm working as an intern at a university. My next assignment is to implement a certain way to deal with asymmetric latencies. [link]http://kunz-pc.sce.carleton.ca/Thesis/ArifurThesis.pdf[/link]
Chapter 4^.
I was wondering if there is anyway to change what PTPD does with the timestamps in the delay request response mechanism?
I'm not sure if this makes any sense.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can do whatever you want with the timestamps. servo.c updateDelay() / updateOffset(), also protocol.c handleDelayResp(). Explore. I'm afraid you're not going to get any ready recipes here. If you have questions about any particular part of the source code or about any behaviour, feel free to ask, but you are not going to get answers to questions like "how do I implement X".
PTP already has a mechanism of dealing with latency asymmetries, and that's the P2P mode (which pretty much only makes sense if used with Transparent Clocks). If you have a mechanism to extract a->b and b->a latency, you can correct for those by populating the CorrectionField in either direction - Slave->Master (delayreq/resp) and Master->Slave (sync/fup).
Have you got a copy of the IEEE 1588 standard? If not, you should definitely acquire it from IEEE, ask if your university has access to IEEE Xplore. This and John Eidson's book on PTP "Measurement, Control and Communication using IEEE 1588". It only covers PTP V1, but explains most of theory behind PTP system design and operation. Anyhow, the standard document is a bible on its own.
Your Chapter 4 suggests implementing multi-master support where multiple masters are being tracked simultaneously and the best performing one is selected - or maybe some combining algorithm can be used. That is an indirect method of dealing with high PDV, but this is what many vendors do. PTP Telecom Profile for example actually specifies that a Telecom slave should be able to request sync from multiple masters in multiple domains simultaneously. PTPd can do this today, but the code is not modular enough to actually track the offsets separately. It is possible with some amount of work on the code, which is planned anyway.
You should definitely look for access to time sync conference papers: ISPCS conference, WSTS conference and ITSF conference. All of them every year present very valuable resources - ISPCS is more academic and the other two are more industry / practice oriented.
Cheers,
Wojciech
Last edit: Wojciech Owczarek 2015-07-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. I think you briefly read the wrong chapter. More precisely, I was talking about section 4.2 DAC model which explains another way to calculate/estimate the offsets and introduces a boundary to eliminate clock from update via bad samples.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I see it now. Bssically updateDelay() and updateOffset() is where it's at. This is where filtering is applied in ptpd, although PTPd operates on DelayMS and delaySM (T2 - T1) and (T4 - T3) separately as they are derived from two different message exchanges and are not subject to the same momentary conditions. You are free to experiment but my experience is that it's better to not update the clock than to use a saved value, because then you are accumulating error that isn't there - and even software-only clocks are usually stable enough in short term that if you miss a few updates, nothing critical will happen - unless you are operating with hardware only and are looking for near-perfect sync
PTPD 2.3.1 also uses two-stage filtering. Check the ptpd2.conf manual page for stat_filter and oultier_filter. The first stage is a statistical filter with a choice of min/max/mean/median over a sliding or interval window of selected number of samples (in high PDV scenarios you want the "lucky" packets so the min function usually works best). The second stage is what I would call "hysteresis-enhanced Peirce's outlier filter". This is an outlier filter that throws away bad samples using the Peirce's criterion (https://en.wikipedia.org/wiki/Peirce's_criterion), but it's self tuning - it keeps the ratio of discarded samples within configurable percentage bounds, thus preventing it from becoming too tight or too loose depending on conditions. A simple hysteresis control is used for that. It produces ugly results when there is an actual long-lasting change in the offset / delay (waits for a long time and then abruptly lets go), but can effectively prevent high numbers of very high offset spikes, even in a series. We're talking many milliseconds. The filter also has a step detection mechanism where it will block when offset is above a certain threshold. Have a look at dep/outlierfilter.c. I was going to do a paper on this but it's still in the works due to lack of time.
OK, PTPd also uses an IIR filter for Mean Path Delay on top of this all.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was wondering if you could explain in a simple but educational way how the servo clock works and what is going on in the updateDelay/Offset() code.
Thanks,
Hassaan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Where would I include code such as Int R = subtime(s2m delay) / subtime(m2s delay)
if R >=... && <= ... {
do this}
Kind of confused also because the master to slave delay and slave to master delay are calculated in two different functions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
They have to be calculated in different functions (or at least as two actions) because they come from separate message exchanges. I mean, you could update both in one function, just once you have all 4 timestamps, but PTPd does this differently. updateOffset() is the function that has both current values available. Offset is calculated after this block:
/* Take care of correctionField */
subTime(&ptpClock->delayMS,
&ptpClock->delayMS, correctionField);
After this block is where you have both latest delaySM and delayMS. You can do goto finish; if you want to throw away the offset.
You will see that just before finish:, we have ptpClock->clockcontrol.offsetOK = TRUE. If offsetOK is TRUE, the PI servo iterates and clock is updated. If it's FALSE, the update is skipped.
Cheers,
Wojciech
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
/* Take care of correctionField */
subTime(&ptpClock->delayMS,&ptpClock->delayMS,correctionField);/* Delay Asymmetry Ratio */
intratioR=*ptpClock->delayMS/*ptpClock->delaySM;if(ratioR>=0.97&&ratioR<=1.03){printf(ratioR);}
Does this make any sense? If it does, how can I check if it's working or not.
Last edit: Hassaan Hafeez 2015-07-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use sudo ptpd -c -g -b eth1 -D and I get no other console output than the default.
I tried to remove the if condition and just place the printf statement without the variable and still the same. I put the same code in both servo.c files and nothing is happening.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your messages probably go to syslog (/var/log/messages) because you used printf. You can try running -V to print all possible output to standard output.
However to send text to the correct log target (following configuration) please use the message macros defined in dep/ptpd_dep.h : INFO("..."), NOTICE("..."), etc.
They take varargs so you can use them just like printf.
Last edit: Wojciech Owczarek 2015-07-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So I think I understand the basic concepts now.
I created the helloworld.c file and used make helloworld followed with ./helloworld to execute it.
Where is the output of the ptpd compilation? I didn't set it I think..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I'm trying to alter the Servo clock (if that's possible?). I'm working as an intern at a university. My next assignment is to implement a certain way to deal with asymmetric latencies.
[link]http://kunz-pc.sce.carleton.ca/Thesis/ArifurThesis.pdf[/link]
Chapter 4^.
I was wondering if there is anyway to change what PTPD does with the timestamps in the delay request response mechanism?
I'm not sure if this makes any sense.
Hi,
You can do whatever you want with the timestamps. servo.c updateDelay() / updateOffset(), also protocol.c handleDelayResp(). Explore. I'm afraid you're not going to get any ready recipes here. If you have questions about any particular part of the source code or about any behaviour, feel free to ask, but you are not going to get answers to questions like "how do I implement X".
PTP already has a mechanism of dealing with latency asymmetries, and that's the P2P mode (which pretty much only makes sense if used with Transparent Clocks). If you have a mechanism to extract a->b and b->a latency, you can correct for those by populating the CorrectionField in either direction - Slave->Master (delayreq/resp) and Master->Slave (sync/fup).
Have you got a copy of the IEEE 1588 standard? If not, you should definitely acquire it from IEEE, ask if your university has access to IEEE Xplore. This and John Eidson's book on PTP "Measurement, Control and Communication using IEEE 1588". It only covers PTP V1, but explains most of theory behind PTP system design and operation. Anyhow, the standard document is a bible on its own.
Your Chapter 4 suggests implementing multi-master support where multiple masters are being tracked simultaneously and the best performing one is selected - or maybe some combining algorithm can be used. That is an indirect method of dealing with high PDV, but this is what many vendors do. PTP Telecom Profile for example actually specifies that a Telecom slave should be able to request sync from multiple masters in multiple domains simultaneously. PTPd can do this today, but the code is not modular enough to actually track the offsets separately. It is possible with some amount of work on the code, which is planned anyway.
You should definitely look for access to time sync conference papers: ISPCS conference, WSTS conference and ITSF conference. All of them every year present very valuable resources - ISPCS is more academic and the other two are more industry / practice oriented.
Cheers,
Wojciech
Last edit: Wojciech Owczarek 2015-07-06
Thanks. I think you briefly read the wrong chapter. More precisely, I was talking about section 4.2 DAC model which explains another way to calculate/estimate the offsets and introduces a boundary to eliminate clock from update via bad samples.
Hi,
Yes, I see it now. Bssically updateDelay() and updateOffset() is where it's at. This is where filtering is applied in ptpd, although PTPd operates on DelayMS and delaySM (T2 - T1) and (T4 - T3) separately as they are derived from two different message exchanges and are not subject to the same momentary conditions. You are free to experiment but my experience is that it's better to not update the clock than to use a saved value, because then you are accumulating error that isn't there - and even software-only clocks are usually stable enough in short term that if you miss a few updates, nothing critical will happen - unless you are operating with hardware only and are looking for near-perfect sync
PTPD 2.3.1 also uses two-stage filtering. Check the ptpd2.conf manual page for stat_filter and oultier_filter. The first stage is a statistical filter with a choice of min/max/mean/median over a sliding or interval window of selected number of samples (in high PDV scenarios you want the "lucky" packets so the min function usually works best). The second stage is what I would call "hysteresis-enhanced Peirce's outlier filter". This is an outlier filter that throws away bad samples using the Peirce's criterion (https://en.wikipedia.org/wiki/Peirce's_criterion), but it's self tuning - it keeps the ratio of discarded samples within configurable percentage bounds, thus preventing it from becoming too tight or too loose depending on conditions. A simple hysteresis control is used for that. It produces ugly results when there is an actual long-lasting change in the offset / delay (waits for a long time and then abruptly lets go), but can effectively prevent high numbers of very high offset spikes, even in a series. We're talking many milliseconds. The filter also has a step detection mechanism where it will block when offset is above a certain threshold. Have a look at dep/outlierfilter.c. I was going to do a paper on this but it's still in the works due to lack of time.
OK, PTPd also uses an IIR filter for Mean Path Delay on top of this all.
Thanks for your time and help. :)
I was wondering if you could explain in a simple but educational way how the servo clock works and what is going on in the updateDelay/Offset() code.
Thanks,
Hassaan
Where would I include code such as Int R = subtime(s2m delay) / subtime(m2s delay)
if R >=... && <= ... {
do this}
Kind of confused also because the master to slave delay and slave to master delay are calculated in two different functions.
They have to be calculated in different functions (or at least as two actions) because they come from separate message exchanges. I mean, you could update both in one function, just once you have all 4 timestamps, but PTPd does this differently. updateOffset() is the function that has both current values available. Offset is calculated after this block:
After this block is where you have both latest delaySM and delayMS. You can do
goto finish;
if you want to throw away the offset.You will see that just before finish:, we have
ptpClock->clockcontrol.offsetOK = TRUE
. If offsetOK is TRUE, the PI servo iterates and clock is updated. If it's FALSE, the update is skipped.Cheers,
Wojciech
How come when I put clockcontrol.offsetOK = FALSE;
followed by goto finish; in the else part of my statement, the delaySM is always 0?
Hmm, so say I have this code put in:
Does this make any sense? If it does, how can I check if it's working or not.
Last edit: Hassaan Hafeez 2015-07-14
updateOffset
should be executed every time, followUp message is received. If you run ptpd with -C option, you should see your output in console.I use sudo ptpd -c -g -b eth1 -D and I get no other console output than the default.
I tried to remove the if condition and just place the printf statement without the variable and still the same. I put the same code in both servo.c files and nothing is happening.
-C not -c
Same result
Here the pictures to what I have:
http://i62.tinypic.com/o8wb41.png
Terminal with "sudo ptpd -C -g -b eth1 -D" command running - http://i59.tinypic.com/206jxnn.png
Images are too big to format
Last edit: Hassaan Hafeez 2015-07-14
You can try DBG instead of printf.
Please don't forget \n line endings.
No change. What's DBGV?
Are you running correct executable? If you compile it and need to run in place, you must specify path, otherwise, you are running system command
sudo ptpd # run system's ptpd
sudo ./ptpd # run ptpd executable placed in current directory
How many -D you have, that many V you need (-1)
e.g
-D -> DBG works
-DD -> DBGV also works
-DDD -> DBGVV also works
Last edit: Jan Breuer 2015-07-14
Hassaan,
Your messages probably go to syslog (/var/log/messages) because you used printf. You can try running -V to print all possible output to standard output.
However to send text to the correct log target (following configuration) please use the message macros defined in
dep/ptpd_dep.h
:INFO("...")
,NOTICE("...")
, etc.They take varargs so you can use them just like printf.
Last edit: Wojciech Owczarek 2015-07-14
Do i do cd Downloads if the extracted file is in the downloads section?
@Wojciech I checked syslog and none of the statements I typed showed up.
I also tried INFO("..."), no change.
Last edit: Hassaan Hafeez 2015-07-14
As I wrote in previous answer
. (dot) is current directory
so, go to directory where output of compilation is placed and run
sudo ./ptpd -C -g -i eth1 -D
Please
Teaching programming and working with commandline is out of the scope of this discussion.
So I think I understand the basic concepts now.
I created the helloworld.c file and used make helloworld followed with ./helloworld to execute it.
Where is the output of the ptpd compilation? I didn't set it I think..
:-)
I think that in src folder.
It says command not found. When I try make ptpd, it gives me errors for incomplete types and undeclared functions.
http://i57.tinypic.com/mb3fjl.png
Last edit: Hassaan Hafeez 2015-07-14
OK, step by step
ptpd-2.3.1
and run terminal heresrc
,doc
,test
,tools
etc../configure
make
sudo src/ptpd2 -C -g -i eth1 -D
Alright did it on slave VM
Should I do the same for master VM but run sudo src/ptpd2 -W -i eth1 ?
Should I delete the other PTPd folders?
Last edit: Hassaan Hafeez 2015-07-14