7

I'm trying to run software which needs to get hardware timestamps using ptp. Therefore, I need to have /dev/ptp0 available. I'm running Linux/Ubuntu on a VMWare.

Is there a way to make this work on a VM?

Thanks!

Alessandro Giusa
  • 1,660
  • 15
  • 11

3 Answers3

9

in short: ptp_kvm.ko

# modprobe ptp_kvm
# ls /dev/ptp*
/dev/ptp0  /dev/ptp_kvm

in long:

Red Hat Enterprise Linux 7.5 and later provide a virtual PTP hardware clock (PHC), which enables the guests to synchronize to the host with a sub-microsecond accuracy.

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/chap-kvm_guest_timing_management#sect-KVM_guest_timing_management-Host-guest-time-sync (subscription-wall?)

To enable the PHC device, do the following inside a virtual machine:

Set the ptp_kvm module to load after reboot.

# echo ptp_kvm > /etc/modules-load.d/ptp_kvm.conf

Add the /dev/ptp0 clock as a reference to the chrony configuration:

# echo "refclock PHC /dev/ptp0 poll 2" >> /etc/chrony.conf

Restart the chrony daemon:

# systemctl restart chronyd

To verify the host-guest time synchronization has been configured correctly, use the chronyc sources command on a guest.

# chronyc sources
#* PHC0                          0   2   377     4     -6ns[   -6ns] +/-  726ns
vladis
  • 111
  • 1
  • 5
4

Simple answer VMware doesn't support linuxptp emulating ptp devices. Closest thing is find this on this website

FYI Running linuxptp on qemu-kvm

Run two virtual machines for GM and Slave and use recent Fedora, RHEL 6.5 7.0 Use virtual NIC emulationg e10000 (supports software timestamping) don't forget to define appropriate firewall rules to allow multi-cast dont' expect high precision and accuracy

Devidas
  • 2,479
  • 9
  • 24
  • Thank you for your answer. Is there no way to emulate the ptp hardware clock? I need it only for testing my application. Or is there any other way to get hardware timestamps? – Alessandro Giusa Jul 09 '18 at 12:07
  • never tried this but you can give [this](https://github.com/mlichvar/clknetsim) a try. it git repo simulating clock. may help. let me know i it worked. – Devidas Jul 09 '18 at 13:00
  • So thank you! I'm still trying to understand what it does...is it simulating a ptp hardware clock? Because this is what I would need... – Alessandro Giusa Jul 09 '18 at 14:55
2

It's now 2021, and I found out that if you're able to compile your own Linux Kernel, there is a built-in driver already. Enable it with make menuconfig:

Device Drivers --> PTP clock support --> KVM virtual PTP clock

Inside a KVM guest, a new /dev/ptp0 device will appear, as well as the following Kernel boot log:

pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
PTP clock support registered
Jesús Zazueta
  • 1,160
  • 1
  • 17
  • 32