On 8/1/2020 10:46 AM, Vladimir Oltean wrote:
> Currently the PHC index is retrieved only through an ethtool ioctl if
> the PHC is specified as an Ethernet interface. If it's a char device
> such as /dev/ptp5, the phc_index will remain unpopulated. Try to infer
> it from the char device's path.
>
> This is useful when trying to determine whether multiple clocks are in
> fact the same (such as /dev/ptp3 and sw1p3), just compare their PHC
> index.
>
Makes sense. The header already indicates the phc_index will be set if
any, so I think this is good.
> Signed-off-by: Vladimir Oltean <olte...@gmail.com>
> ---
> util.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/util.c b/util.c
> index 296dd59a08c1..027d694ea854 100644
> --- a/util.c
> +++ b/util.c
> @@ -211,6 +211,16 @@ clockid_t posix_clock_open(const char *device, int
> *phc_index)
> /* check if device is valid phc device */
> clkid = phc_open(device);
> if (clkid != CLOCK_INVALID) {
> + if (!strncmp(device, "/dev/ptp", strlen("/dev/ptp"))) {
> + int r = get_ranged_int(device + strlen("/dev/ptp"),
> + phc_index, 0, 65535);
> + if (r) {
> + fprintf(stderr,
> + "failed to parse PHC index from %s\n",
> + device);
> + return -1;
> + }
Here, we are making the implicit assumption that all ptp clock devices
will always have /dev/ptpX format. I don't think anyone is crazy enough
to rename these devices...
An alternative (requiring kernel implementation maybe?) would be to read
the phc index from the kernel somehow. It doesn't look like this is
exported anywhere else besides the name.
Since we don't actually expect these devices to have names changed by
userspace, I think this is acceptable.
> + }
> return clkid;
> }
> /* check if device is a valid ethernet device */
>
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel