linuxptp

reading timestamp using Linuxptp


I've started learning about TSN and the use under Linux by opensource project Linuxptp.

I want to write simple Talker application, after syncing clocks using ptp4l & phc2sys scripts.

How do I use/read the timestamp within executed application?

How does this sync works under multiple Ethernet interfaces Linux environment. if one port is synced to a master clock through one ethernet port, it would sync linux main clock? that is for one linux environment PTP can be synced to only one Master ?

Thanks!


Solution

  • In Time Sensitive Networks there will be 1 Grandmaster(GM) Node and several Slaves nodes
    
    So, How this time synchronization works is that On every boot up all the devices in the network will share their capability information such as their time source, priority values, mac address info etc.,
    based on those information shared by all the devices they'll select the most accurate time providing device as Grandmaster(GM)(usually device with GPS as its time source)
    
    Once this is done GM would start sending Sync and Follow Up message which is used by all the Slaves nodes to calculate the time difference between slave node clock and Grandmaster clock
    Similarly, Slave nodes would send PDelay Request messages to calculate Link Delay and adjust the Slave Clock to Grandmaster Clock
    
    So, coming to reading the synchronized time from the Slave Node would be through 
    man page of clock_gettime:
    https://linux.die.net/man/3/clock_gettime
    
    // Calculate time taken by a request
    
    struct timespec requestStart, requestEnd;
    clock_gettime(CLOCK_REALTIME, &requestStart);
    function_call();
    clock_gettime(CLOCK_REALTIME, &requestEnd);