How can I get a /dev/ptp0 ptp hardware clock on a VM running Linux?
Asked Answered
D

3

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!

Disrespectful answered 9/7, 2018 at 11:42 Comment(0)
L
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
Leander answered 24/11, 2019 at 21:20 Comment(0)
P
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

Padua answered 9/7, 2018 at 12:3 Comment(3)
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?Disrespectful
never tried this but you can give this a try. it git repo simulating clock. may help. let me know i it worked.Padua
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...Disrespectful
B
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 <[email protected]>
PTP clock support registered
Blinding answered 28/6, 2021 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.