Menu

PTPD Source Code?

Help
2015-07-06
2015-07-16
1 2 > >> (Page 1 of 2)
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-06

    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.

     
  • Wojciech Owczarek

    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
  • Hassaan Hafeez

    Hassaan Hafeez - 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.

     
  • Wojciech Owczarek

    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.

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-06

    Thanks for your time and help. :)

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-08

    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

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-13

    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.

     
  • Wojciech Owczarek

    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

     
    • Hassaan Hafeez

      Hassaan Hafeez - 2015-07-16

      How come when I put clockcontrol.offsetOK = FALSE;
      followed by goto finish; in the else part of my statement, the delaySM is always 0?

       
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    Hmm, so say I have this code put in:

    /* Take care of correctionField */
    subTime(&ptpClock->delayMS,
        &ptpClock->delayMS, correctionField);
    
    /* Delay Asymmetry Ratio */
    int ratioR = *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
  • Jan Breuer

    Jan Breuer - 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.

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    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.

     
  • Jan Breuer

    Jan Breuer - 2015-07-14

    -C not -c

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    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
  • Jan Breuer

    Jan Breuer - 2015-07-14

    You can try DBG instead of printf.
    Please don't forget \n line endings.

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    No change. What's DBGV?

     
  • Jan Breuer

    Jan Breuer - 2015-07-14

    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
  • Wojciech Owczarek

    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
  • Hassaan Hafeez

    Hassaan Hafeez - 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
  • Jan Breuer

    Jan Breuer - 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

    • learn some basics of Linux (command line, shell)
    • create your own minimal "hello world" program using one c file and makefile
    • try to execute your program
    • try to modify, rebuild and rerun your program
    • come again and we will be happy to answer your questions

    Teaching programming and working with commandline is out of the scope of this discussion.

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    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..

     
  • Jan Breuer

    Jan Breuer - 2015-07-14

    :-)

    I think that in src folder.

     
  • Hassaan Hafeez

    Hassaan Hafeez - 2015-07-14

    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
  • Jan Breuer

    Jan Breuer - 2015-07-14

    OK, step by step

    1. download https://sourceforge.net/projects/ptpd/files/ptpd/2.3.1/ptpd-2.3.1.tar.gz
    2. unpack it somewhere
    3. go to unpacked folder ptpd-2.3.1 and run terminal here
    4. you should see directories src, doc, test, tools etc.
    5. run ./configure
    6. run make
    7. run sudo src/ptpd2 -C -g -i eth1 -D
     
    • Hassaan Hafeez

      Hassaan Hafeez - 2015-07-14

      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
1 2 > >> (Page 1 of 2)

Log in to post a comment.