mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 02:35:06 -05:00
sys_linux: avoid blocking in reading of external PHC timestamp
The kernel has a common queue for all readers of a PHC device. With multiple PHC refclocks using the same device some reads blocked. PHC devices don't seem to support non-blocking reads. Use poll() to check if a timestamp is available before reading from the descriptor.
This commit is contained in:
11
sys_linux.c
11
sys_linux.c
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#if defined(FEAT_PHC) || defined(HAVE_LINUX_TIMESTAMPING)
|
#if defined(FEAT_PHC) || defined(HAVE_LINUX_TIMESTAMPING)
|
||||||
#include <linux/ptp_clock.h>
|
#include <linux/ptp_clock.h>
|
||||||
|
#include <poll.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_SCFILTER
|
#ifdef FEAT_SCFILTER
|
||||||
@@ -994,6 +995,16 @@ int
|
|||||||
SYS_Linux_ReadPHCExtTimestamp(int fd, struct timespec *phc_ts, int *channel)
|
SYS_Linux_ReadPHCExtTimestamp(int fd, struct timespec *phc_ts, int *channel)
|
||||||
{
|
{
|
||||||
struct ptp_extts_event extts_event;
|
struct ptp_extts_event extts_event;
|
||||||
|
struct pollfd pfd;
|
||||||
|
|
||||||
|
/* Make sure the read will not block in case we have multiple
|
||||||
|
descriptors of the same PHC (O_NONBLOCK does not work) */
|
||||||
|
pfd.fd = fd;
|
||||||
|
pfd.events = POLLIN;
|
||||||
|
if (poll(&pfd, 1, 0) != 1 || pfd.revents != POLLIN) {
|
||||||
|
DEBUG_LOG("Missing PHC extts event");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (read(fd, &extts_event, sizeof (extts_event)) != sizeof (extts_event)) {
|
if (read(fd, &extts_event, sizeof (extts_event)) != sizeof (extts_event)) {
|
||||||
DEBUG_LOG("Could not read PHC extts event");
|
DEBUG_LOG("Could not read PHC extts event");
|
||||||
|
|||||||
Reference in New Issue
Block a user