sysoff: Add support for PTP_SYS_OFFSET_PRECISE ioctl.

This ioctl uses cross timestamping for a more accurate measurement of
the offset. It is supported on some onboard Intel NICs using the e1000e
driver and a virtual PHC with the ptp_kvm driver.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2018-11-12 17:28:00 +01:00 committed by Richard Cochran
parent 93baf34adb
commit 192b8e315c
2 changed files with 22 additions and 0 deletions

View File

@ -22,6 +22,7 @@
#include <sys/ioctl.h>
#include <linux/ptp_clock.h>
#include "print.h"
#include "sysoff.h"
#define NS_PER_SEC 1000000000LL
@ -39,6 +40,23 @@ static struct {
uint64_t timestamp;
} samples[PTP_MAX_SAMPLES];
static int sysoff_precise(int fd, int64_t *result, uint64_t *ts)
{
#ifdef PTP_SYS_OFFSET_PRECISE
struct ptp_sys_offset_precise pso;
memset(&pso, 0, sizeof(pso));
if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, &pso)) {
pr_debug("ioctl PTP_SYS_OFFSET_PRECISE: %m");
return SYSOFF_RUN_TIME_MISSING;
}
*result = pctns(&pso.sys_realtime) - pctns(&pso.device);
*ts = pctns(&pso.sys_realtime);
return SYSOFF_PRECISE;
#else
return SYSOFF_COMPILE_TIME_MISSING;
#endif
}
static void insertion_sort(int length, int64_t interval, int64_t offset, uint64_t ts)
{
int i = length - 1;
@ -91,6 +109,9 @@ int sysoff_measure(int fd, int method, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay)
{
switch (method) {
case SYSOFF_PRECISE:
*delay = 0;
return sysoff_precise(fd, result, ts);
case SYSOFF_BASIC:
return sysoff_basic(fd, n_samples, result, ts, delay);
}

View File

@ -23,6 +23,7 @@
enum {
SYSOFF_COMPILE_TIME_MISSING = -2,
SYSOFF_RUN_TIME_MISSING = -1,
SYSOFF_PRECISE,
SYSOFF_BASIC,
SYSOFF_LAST,
};