Subject: Re: PHC device sharing between PCI functions

From: Richard Cochran <[email-masked]>
Date: Wed, 3 Jul 2013 20:30:37 +0200

On Tue, Jul 02, 2013 at 04:17:42PM +0100, Ben Hutchings wrote:
> On Tue, 2013-07-02 at 16:24 +0200, Richard Cochran wrote:
> 
> > And if so, then how will the mutiple, read-only MAC clocks help other
> > guests? Seems kinda useless to me.
> 
> It would allow them to convert hardware timestamps or sync system time
> to NIC time.

Okay, so let's talk about HW time stamps. That is a separate issue
from the PHC. You would think that you could offer HW time stamping to
each VM guest using the MAC. But wait, how will the guests enable it?

They will have to call the HWTSTAMP ioctl. Unfortunately, your driver
is one of those that offers fine grained choices (as opposed to all
packets or none), and that means that the guests will be potentially
spoiling each others settings (unless you implement per-function
filters).

WRT the PHC, I guess you could offer:

- gettime	to all functions
- set/adjtime	works in one, throws error in others
- pps hook	to all functions

You just need to decide how to determine which function will have the
writable clock.

Also, it might be worth thinking about how well the pps interrupt will
work. When there are many guest, will the card produce multiple MSI
interrupts every second, on the second? That won't work too well, I
think.

As an alternative to the pps interrupt, the phc2sys program (from
linuxptp) can periodically read out the system and PHC times in a
tight loop in order to discipline the system clock. This works quite
well in practice, but, again, what happens when multiple guest all try
to read the PHC time over PCIe simultaneously?

Thanks,
Richard

BTW, I am working on adding Tx time stamping to the tuntap driver. My
motivation is be able to conveniently test some of the PTP aspects
(like Best Master Clock selection) over a virtual switch. I also
wonder whether this could be used to distribute the host's system time
to VM guests, and how well it would work.