[Git][NTPsec/ntpsec][master] 2 commits: Adapt JJY druver to not use deprecated gettineofday() call.
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Sep 28 03:30:08 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
86126624 by Eric S. Raymond at 2016-09-27T23:09:57-04:00
Adapt JJY druver to not use deprecated gettineofday() call.
- - - - -
93376b10 by Eric S. Raymond at 2016-09-27T23:19:34-04:00
Convert bumpclock.c to use non-deprecated time calls.
- - - - -
2 changed files:
- ntpd/refclock_jjy.c
- ntpfrob/bumpclock.c
Changes:
=====================================
ntpd/refclock_jjy.c
=====================================
--- a/ntpd/refclock_jjy.c
+++ b/ntpd/refclock_jjy.c
@@ -165,7 +165,7 @@ struct jjyunit {
/* Telephone JJY auto measurement of the loopback delay */
bool bLoopbackMode ;
short iLoopbackCount ;
- struct timeval sendTime[MAX_LOOPBACK], delayTime[MAX_LOOPBACK] ;
+ struct timespec sendTime[MAX_LOOPBACK], delayTime[MAX_LOOPBACK] ;
bool bLoopbackTimeout[MAX_LOOPBACK] ;
short iLoopbackValidCount ;
/* Telephone JJY timer */
@@ -2978,17 +2978,18 @@ teljjy_setDelay ( struct peer *peer, struct jjyunit *up )
char sLog [ 60 ] ;
int milliSecond, microSecond ;
- gettimeofday( &(up->delayTime[up->iLoopbackCount]), NULL ) ;
+ clock_gettime(CLOCK_REALTIME,
+ &(up->delayTime[up->iLoopbackCount]));
up->delayTime[up->iLoopbackCount].tv_sec -= up->sendTime[up->iLoopbackCount].tv_sec ;
- up->delayTime[up->iLoopbackCount].tv_usec -= up->sendTime[up->iLoopbackCount].tv_usec ;
- if ( up->delayTime[up->iLoopbackCount].tv_usec < 0 ) {
+ up->delayTime[up->iLoopbackCount].tv_nsec -= up->sendTime[up->iLoopbackCount].tv_nsec ;
+ if ( up->delayTime[up->iLoopbackCount].tv_nsec < 0 ) {
up->delayTime[up->iLoopbackCount].tv_sec -- ;
- up->delayTime[up->iLoopbackCount].tv_usec += 1000000 ;
+ up->delayTime[up->iLoopbackCount].tv_nsec += 1000000000 ;
}
- milliSecond = up->delayTime[up->iLoopbackCount].tv_usec / 1000 ;
- microSecond = up->delayTime[up->iLoopbackCount].tv_usec - milliSecond * 1000 ;
+ milliSecond = up->delayTime[up->iLoopbackCount].tv_nsec / 1000000 ;
+ microSecond = (up->delayTime[up->iLoopbackCount].tv_nsec/1000) - milliSecond * 1000 ;
milliSecond += up->delayTime[up->iLoopbackCount].tv_sec * 1000 ;
snprintf( sLog, sizeof(sLog), JJY_CLOCKSTATS_MESSAGE_LOOPBACK_DELAY,
@@ -3010,14 +3011,14 @@ static int
teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
{
- struct timeval maxTime, minTime, averTime ;
+ struct timespec maxTime, minTime, averTime ;
int i ;
int minIndex = 0, maxIndex = 0, iAverCount = 0 ;
int iThresholdSecond, iThresholdMicroSecond ;
int iPercent ;
- minTime.tv_sec = minTime.tv_usec = 0 ;
- maxTime.tv_sec = maxTime.tv_usec = 0 ;
+ minTime.tv_sec = minTime.tv_nsec = 0 ;
+ maxTime.tv_sec = maxTime.tv_nsec = 0 ;
iThresholdSecond = TELJJY_LOOPBACK_DELAY_THRESHOLD / 1000 ;
iThresholdMicroSecond = ( TELJJY_LOOPBACK_DELAY_THRESHOLD - ( TELJJY_LOOPBACK_DELAY_THRESHOLD / 1000 ) * 1000 ) * 1000 ;
@@ -3028,26 +3029,26 @@ teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
if ( up->bLoopbackTimeout[i]
|| up->delayTime[i].tv_sec > iThresholdSecond
|| ( up->delayTime[i].tv_sec == iThresholdSecond
- && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) {
+ && up->delayTime[i].tv_nsec/1000 > iThresholdMicroSecond ) ) {
continue ;
}
if ( up->iLoopbackValidCount == 0 ) {
minTime.tv_sec = up->delayTime[i].tv_sec ;
- minTime.tv_usec = up->delayTime[i].tv_usec ;
+ minTime.tv_nsec = up->delayTime[i].tv_nsec ;
maxTime.tv_sec = up->delayTime[i].tv_sec ;
- maxTime.tv_usec = up->delayTime[i].tv_usec ;
+ maxTime.tv_nsec = up->delayTime[i].tv_nsec ;
minIndex = maxIndex = i ;
} else if ( minTime.tv_sec > up->delayTime[i].tv_sec
|| ( minTime.tv_sec == up->delayTime[i].tv_sec
- && minTime.tv_usec > up->delayTime[i].tv_usec ) ) {
+ && minTime.tv_nsec > up->delayTime[i].tv_nsec ) ) {
minTime.tv_sec = up->delayTime[i].tv_sec ;
- minTime.tv_usec = up->delayTime[i].tv_usec ;
+ minTime.tv_nsec = up->delayTime[i].tv_nsec ;
minIndex = i ;
} else if ( maxTime.tv_sec < up->delayTime[i].tv_sec
|| ( maxTime.tv_sec == up->delayTime[i].tv_sec
- && maxTime.tv_usec < up->delayTime[i].tv_usec ) ) {
+ && maxTime.tv_nsec < up->delayTime[i].tv_nsec ) ) {
maxTime.tv_sec = up->delayTime[i].tv_sec ;
- maxTime.tv_usec = up->delayTime[i].tv_usec ;
+ maxTime.tv_nsec = up->delayTime[i].tv_nsec ;
maxIndex = i ;
}
up->iLoopbackValidCount ++ ;
@@ -3057,13 +3058,13 @@ teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
return -1 ;
}
- averTime.tv_usec = 0;
+ averTime.tv_nsec = 0;
for ( i = 0 ; i < MAX_LOOPBACK && i < up->iLoopbackCount ; i ++ ) {
if ( up->bLoopbackTimeout[i]
|| up->delayTime[i].tv_sec > iThresholdSecond
|| ( up->delayTime[i].tv_sec == iThresholdSecond
- && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) {
+ && up->delayTime[i].tv_nsec/1000 > iThresholdMicroSecond ) ) {
continue ;
}
if ( up->iLoopbackValidCount >= 3 && i == maxIndex ) {
@@ -3072,7 +3073,7 @@ teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
if ( up->iLoopbackValidCount >= 4 && i == minIndex ) {
continue ;
}
- averTime.tv_usec += up->delayTime[i].tv_usec ;
+ averTime.tv_nsec += up->delayTime[i].tv_nsec ;
iAverCount ++ ;
}
@@ -3089,7 +3090,7 @@ teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
/* Average delay time in milli second */
- return ( ( averTime.tv_usec / iAverCount ) * iPercent ) / 100000 ;
+ return ( ( (averTime.tv_nsec / 1000) / iAverCount ) * iPercent ) / 100000 ;
}
@@ -3367,7 +3368,8 @@ teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) {
/* Loopback character and timestamp */
- gettimeofday( &(up->sendTime[up->iLoopbackCount]), NULL ) ;
+ clock_gettime(CLOCK_REALTIME,
+ &(up->sendTime[up->iLoopbackCount]));
up->bLoopbackMode = true ;
} else {
/* Regular command */
=====================================
ntpfrob/bumpclock.c
=====================================
--- a/ntpfrob/bumpclock.c
+++ b/ntpfrob/bumpclock.c
@@ -1,57 +1,60 @@
/*
* Hack to bump the system time for testing ntpd response.
* Must be run as root.
- * Arg is microseconds, default is 100000.
+ * Arg is microseconds.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
+#include <time.h>
+
+#define NANOSECONDS 100000000
void bumpclock(int bump)
{
- struct timeval was, set, now;
+ struct timespec was, set, now;
int rc1, rc2, rc3;
int er1, er2, er3;
printf("Bumping clock by %d microseconds.\n", bump);
- rc1 = gettimeofday(&was, NULL);
+ rc1 = clock_gettime(CLOCK_REALTIME, &was);
er1 = errno;
set = was;
+ bump *= 1000;
/* coverity[tainted_data] */
- set.tv_usec += bump;
- while (set.tv_usec >= 1000000 ) {
- set.tv_usec -= 1000000;
+ set.tv_nsec += bump;
+ while (set.tv_nsec >= NANOSECONDS ) {
+ set.tv_nsec -= NANOSECONDS;
set.tv_sec +=1;
}
- while (set.tv_usec <= 0 ) {
- set.tv_usec += 1000000;
+ while (set.tv_nsec <= 0 ) {
+ set.tv_nsec += NANOSECONDS;
set.tv_sec -=1;
}
- rc2 = settimeofday(&set, NULL);
+ rc2 = clock_settime(CLOCK_REALTIME, &set);
er2 = errno;
- rc3 = gettimeofday(&now, NULL);
+ rc3 = clock_gettime(CLOCK_REALTIME, &now);
er3 = errno;
/* Defer printing so it doesn't distort timing. */
if (rc1)
printf("Couldn't get time: %s\n", strerror(er1));
else
- printf("Was: %ld.%06ld\n", (long)was.tv_sec, (long)was.tv_usec);
+ printf("Was: %ld.%09ld\n", (long)was.tv_sec, (long)was.tv_nsec);
if (rc2) {
printf("Couldn't set time: %s\n", strerror(er2));
- printf("Try: %ld.%06ld\n", (long)set.tv_sec, (long)set.tv_usec);
+ printf("Try: %ld.%09ld\n", (long)set.tv_sec, (long)set.tv_nsec);
} else
- printf("Set: %ld.%06ld\n", (long)set.tv_sec, (long)set.tv_usec);
+ printf("Set: %ld.%09ld\n", (long)set.tv_sec, (long)set.tv_nsec);
if (rc3)
printf("Couldn't set time: %s\n", strerror(er3));
else
- printf("Now: %ld.%06ld\n", (long)now.tv_sec, (long)now.tv_usec);
+ printf("Now: %ld.%09ld\n", (long)now.tv_sec, (long)now.tv_nsec);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/eacf97cdc5b9c863c85cb039e6b91e607008e54e...93376b101e822d8c630acb9d5f3684dff1632000
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160928/9bd8ce7c/attachment.html>
More information about the vc
mailing list