posix_clock_open: derive PHC index from device name if possible
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. Signed-off-by: Vladimir Oltean <olteanv@gmail.com>master
parent
cef87c6f03
commit
380d023abb
10
util.c
10
util.c
|
@ -211,6 +211,16 @@ clockid_t posix_clock_open(const char *device, int *phc_index)
|
||||||
/* check if device is valid phc device */
|
/* check if device is valid phc device */
|
||||||
clkid = phc_open(device);
|
clkid = phc_open(device);
|
||||||
if (clkid != CLOCK_INVALID) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
return clkid;
|
return clkid;
|
||||||
}
|
}
|
||||||
/* check if device is a valid ethernet device */
|
/* check if device is a valid ethernet device */
|
||||||
|
|
Loading…
Reference in New Issue