If the PHC specified with the phc_index or -p option is a virtual clock
of the interface, bind sockets to the virtual clock instead of the real
clock to get correct timestamps.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 port.c  | 7 ++++++-
 ptp4l.8 | 7 +++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/port.c b/port.c
index cfa57b8..ced09ae 100644
--- a/port.c
+++ b/port.c
@@ -3204,7 +3204,12 @@ struct port *port_open(const char *phc_device,
                pr_warning("%s: get_ts_info not supported", p->log_name);
        } else if (p->phc_index >= 0 &&
                   p->phc_index != interface_phc_index(interface)) {
-               if (p->jbod) {
+               if (rtnl_iface_has_vclock(interface_name(interface),
+                                         p->phc_index)) {
+                       pr_info("%s: /dev/ptp%d is virtual clock",
+                               p->log_name, p->phc_index);
+                       interface_set_vclock(interface, p->phc_index);
+               } else if (p->jbod) {
                        pr_warning("%s: just a bunch of devices", p->log_name);
                        p->phc_index = interface_phc_index(interface);
                } else if (phc_device) {
diff --git a/ptp4l.8 b/ptp4l.8
index 5ef471b..71a414c 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -377,8 +377,11 @@ The default is 0 (disabled).
 .TP
 .B phc_index
 Specifies the index of the PHC to be used for synchronization with hardware
-timestamping. The default is -1, which means the index will be set to the PHC
-associated with the interface, or the device specified by the \fB-p\fP option.
+timestamping. This option is useful with virtual clocks running on top of a
+free-running physical clock (created by writing to
+/sys/class/ptp/ptp*/n_vclocks).
+The default is -1, which means the index will be set to the PHC associated with
+the interface, or the device specified by the \fB-p\fP option.
 .TP
 .B udp_ttl
 Specifies the Time to live (TTL) value for IPv4 multicast messages and the hop
-- 
2.35.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to