local: add support for clock_gettime()
Use clock_gettime() to read the system clock in nanosecond resolution.
This commit is contained in:
parent
cfe706f032
commit
8d89610ff6
4 changed files with 26 additions and 19 deletions
26
configure
vendored
26
configure
vendored
|
@ -569,6 +569,21 @@ then
|
|||
fi
|
||||
fi
|
||||
|
||||
if test_code 'clock_gettime()' 'time.h' '' '' \
|
||||
'clock_gettime(CLOCK_REALTIME, NULL);'
|
||||
then
|
||||
add_def HAVE_CLOCK_GETTIME
|
||||
else
|
||||
if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \
|
||||
'clock_gettime(CLOCK_REALTIME, NULL);'
|
||||
then
|
||||
add_def HAVE_CLOCK_GETTIME
|
||||
EXTRA_LIBS="$EXTRA_LIBS -lrt"
|
||||
else
|
||||
try_phc=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$EXTRA_LIBS" \
|
||||
'return getaddrinfo(0, 0, 0, 0);'
|
||||
then
|
||||
|
@ -676,16 +691,7 @@ if [ $feat_refclock = "1" ] && [ $feat_phc = "1" ] && [ $try_phc = "1" ] && \
|
|||
test_code '<linux/ptp_clock.h>' 'sys/ioctl.h linux/ptp_clock.h' '' '' \
|
||||
'ioctl(1, PTP_CLOCK_GETCAPS, 0);'
|
||||
then
|
||||
if test_code 'clock_gettime()' 'time.h' '' '' 'clock_gettime(0, NULL);'; then
|
||||
add_def FEAT_PHC
|
||||
else
|
||||
if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \
|
||||
'clock_gettime(0, NULL);'
|
||||
then
|
||||
EXTRA_LIBS="$EXTRA_LIBS -lrt"
|
||||
add_def FEAT_PHC
|
||||
fi
|
||||
fi
|
||||
add_def FEAT_PHC
|
||||
fi
|
||||
|
||||
if [ $try_setsched = "1" ] && \
|
||||
|
|
12
local.c
12
local.c
|
@ -350,19 +350,21 @@ void LCL_RemoveDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void
|
|||
}
|
||||
|
||||
/* ================================================== */
|
||||
/* At the moment, this is just gettimeofday(), because
|
||||
I can't think of a Unix system where it would not be */
|
||||
|
||||
void
|
||||
LCL_ReadRawTime(struct timespec *ts)
|
||||
{
|
||||
#if HAVE_CLOCK_GETTIME
|
||||
if (clock_gettime(CLOCK_REALTIME, ts) < 0)
|
||||
LOG_FATAL(LOGF_Local, "clock_gettime() failed : %s", strerror(errno));
|
||||
#else
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday(&tv, NULL) < 0) {
|
||||
LOG_FATAL(LOGF_Local, "gettimeofday() failed");
|
||||
}
|
||||
if (gettimeofday(&tv, NULL) < 0)
|
||||
LOG_FATAL(LOGF_Local, "gettimeofday() failed : %s", stderror(errno));
|
||||
|
||||
UTI_TimevalToTimespec(&tv, ts);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
3
local.h
3
local.h
|
@ -31,8 +31,7 @@
|
|||
|
||||
#include "sysincl.h"
|
||||
|
||||
/* Read the system clock. This is analogous to gettimeofday(),
|
||||
but with the timezone information ignored */
|
||||
/* Read the system clock */
|
||||
extern void LCL_ReadRawTime(struct timespec *ts);
|
||||
|
||||
/* Read the system clock, corrected according to all accumulated
|
||||
|
|
|
@ -452,8 +452,8 @@ SYS_Linux_EnableSystemCallFilter(int level)
|
|||
{
|
||||
const int syscalls[] = {
|
||||
/* Clock */
|
||||
SCMP_SYS(adjtimex), SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday),
|
||||
SCMP_SYS(time),
|
||||
SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday),
|
||||
SCMP_SYS(settimeofday), SCMP_SYS(time),
|
||||
/* Process */
|
||||
SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getrlimit),
|
||||
SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), SCMP_SYS(rt_sigprocmask),
|
||||
|
|
Loading…
Reference in a new issue