phc2sys: provide missing kernel headers for sysoff functionality

Currently it is very finicky to deploy linuxptp in an automated build
system and make KBUILD_OUTPUT pick up the output of "make
headers_install" in order for the application to make full use of the
features exposed by the runtime kernel. And the toolchain/libc will
almost certainly never contain recent enough kernel headers to be of any
use here. And there's no good reason for that: the application can probe
at runtime for the sysoff methods supported by the kernel anyway.

So let's provide the kernel definitions for sysoff, sysoff_precise and
sysoff_extended, such that SYSOFF_COMPILE_TIME_MISSING is not something
that will bother us any longer.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
master
Vladimir Oltean 2020-06-25 01:21:34 +03:00 committed by Richard Cochran
parent cb3fbc1010
commit 61c6a70898
3 changed files with 54 additions and 27 deletions

View File

@ -97,6 +97,58 @@ struct compat_ptp_clock_caps {
#endif /*LINUX_VERSION_CODE < 5.8*/
#ifndef PTP_MAX_SAMPLES
#define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
#endif /* PTP_MAX_SAMPLES */
#ifndef PTP_SYS_OFFSET
#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
struct ptp_sys_offset {
unsigned int n_samples; /* Desired number of measurements. */
unsigned int rsv[3]; /* Reserved for future use. */
/*
* Array of interleaved system/phc time stamps. The kernel
* will provide 2*n_samples + 1 time stamps, with the last
* one as a system time stamp.
*/
struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
};
#endif /* PTP_SYS_OFFSET */
#ifndef PTP_SYS_OFFSET_PRECISE
#define PTP_SYS_OFFSET_PRECISE \
_IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
struct ptp_sys_offset_precise {
struct ptp_clock_time device;
struct ptp_clock_time sys_realtime;
struct ptp_clock_time sys_monoraw;
unsigned int rsv[4]; /* Reserved for future use. */
};
#endif /* PTP_SYS_OFFSET_PRECISE */
#ifndef PTP_SYS_OFFSET_EXTENDED
#define PTP_SYS_OFFSET_EXTENDED \
_IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
struct ptp_sys_offset_extended {
unsigned int n_samples; /* Desired number of measurements. */
unsigned int rsv[3]; /* Reserved for future use. */
/*
* Array of [system, phc, system] time stamps. The kernel will provide
* 3*n_samples time stamps.
*/
struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
};
#endif /* PTP_SYS_OFFSET_EXTENDED */
#ifndef PTP_PIN_SETFUNC
enum ptp_pin_function {

View File

@ -27,8 +27,6 @@
#define NS_PER_SEC 1000000000LL
#ifdef PTP_SYS_OFFSET
static int64_t pctns(struct ptp_clock_time *t)
{
return t->sec * NS_PER_SEC + t->nsec;
@ -36,7 +34,6 @@ static int64_t pctns(struct ptp_clock_time *t)
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)) {
@ -46,9 +43,6 @@ static int sysoff_precise(int fd, int64_t *result, uint64_t *ts)
*result = pctns(&pso.sys_realtime) - pctns(&pso.device);
*ts = pctns(&pso.sys_realtime);
return SYSOFF_PRECISE;
#else
return SYSOFF_COMPILE_TIME_MISSING;
#endif
}
static int64_t sysoff_estimate(struct ptp_clock_time *pct, int extended,
@ -99,7 +93,6 @@ static int64_t sysoff_estimate(struct ptp_clock_time *pct, int extended,
static int sysoff_extended(int fd, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay)
{
#ifdef PTP_SYS_OFFSET_EXTENDED
struct ptp_sys_offset_extended pso;
memset(&pso, 0, sizeof(pso));
pso.n_samples = n_samples;
@ -109,9 +102,6 @@ static int sysoff_extended(int fd, int n_samples,
}
*result = sysoff_estimate(&pso.ts[0][0], 1, n_samples, ts, delay);
return SYSOFF_EXTENDED;
#else
return SYSOFF_COMPILE_TIME_MISSING;
#endif
}
static int sysoff_basic(int fd, int n_samples,
@ -140,7 +130,7 @@ int sysoff_measure(int fd, int method, int n_samples,
case SYSOFF_BASIC:
return sysoff_basic(fd, n_samples, result, ts, delay);
}
return SYSOFF_COMPILE_TIME_MISSING;
return SYSOFF_RUN_TIME_MISSING;
}
int sysoff_probe(int fd, int n_samples)
@ -164,18 +154,3 @@ int sysoff_probe(int fd, int n_samples)
return SYSOFF_RUN_TIME_MISSING;
}
#else /* !PTP_SYS_OFFSET */
int sysoff_measure(int fd, int method, int n_samples,
int64_t *result, uint64_t *ts, int64_t *delay)
{
return SYSOFF_COMPILE_TIME_MISSING;
}
int sysoff_probe(int fd, int n_samples)
{
return SYSOFF_COMPILE_TIME_MISSING;
}
#endif /* PTP_SYS_OFFSET */

View File

@ -19,9 +19,9 @@
*/
#include <stdint.h>
#include "missing.h"
enum {
SYSOFF_COMPILE_TIME_MISSING = -2,
SYSOFF_RUN_TIME_MISSING = -1,
SYSOFF_PRECISE,
SYSOFF_EXTENDED,