From: Harlan Stenn Date: Sat, 15 Sep 2012 03:42:10 +0000 (-0400) Subject: [Bug 1232] Convert SHM refclock to use struct timespec X-Git-Tag: NTP_4_2_7P305~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdfebe9d4bf847d51fd6e755b4f84fdc1464d16d;p=thirdparty%2Fntp.git [Bug 1232] Convert SHM refclock to use struct timespec bk: 5053f9121xxWDdPtG34aSxp9YMDFUw --- diff --git a/ChangeLog b/ChangeLog index 5dbab3a3a..b2de28dd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ * [Bug 752] Use proper ToS network packet markings for IPv4 and IPv6. +* [Bug 1232] Convert SHM refclock to use struct timespec. * [Bug 2263] broadcast server doesn't work for host with OS_MISSES_SPECIFIC_ROUTE_UPDATES. * [Bug 2271] Decode refclock types when built with --disable-all-clocks. diff --git a/ntpd/refclock_shm.c b/ntpd/refclock_shm.c index 6b156d159..49eed85ad 100644 --- a/ntpd/refclock_shm.c +++ b/ntpd/refclock_shm.c @@ -21,7 +21,7 @@ #undef fileno #include "ntp_refclock.h" #undef fileno -#include "timevalops.h" +#include "timespecops.h" #undef fileno #include "ntp_stdlib.h" @@ -326,44 +326,41 @@ int shm_peek( return 0; } if (shm->valid) { - struct timeval tvr; - struct timeval tvt; + struct timespec tvr; + struct timespec tvt; struct tm *t; char timestr[20]; /* "%Y-%m-%dT%H:%M:%S" + 1 */ int c; int ok = 1; - unsigned cns_new, rns_new, cns_valid, rns_valid; + unsigned cns_new, rns_new; int cnt; tvr.tv_sec = 0; - tvr.tv_usec = 0; + tvr.tv_nsec = 0; tvt.tv_sec = 0; - tvt.tv_usec = 0; + tvt.tv_nsec = 0; switch (shm->mode) { case 0: tvr.tv_sec = shm->receiveTimeStampSec; - tvr.tv_usec = shm->receiveTimeStampUSec; + tvr.tv_nsec = shm->receiveTimeStampUSec * 1000; rns_new = shm->receiveTimeStampNSec; tvt.tv_sec = shm->clockTimeStampSec; - tvt.tv_usec = shm->clockTimeStampUSec; + tvt.tv_nsec = shm->clockTimeStampUSec * 1000; cns_new = shm->clockTimeStampNSec; - rns_valid = ((unsigned) tvr.tv_usec) * 1000; - cns_valid = ((unsigned) tvt.tv_usec) * 1000; - /* Since these comparisons are between unsigned ** variables they are always well defined, and any ** (signed) underflow will turn into very large ** unsigned values, well above the 1000 cutoff */ - if ( ((cns_new - cns_valid) < 1000) - && ((rns_new - rns_valid) < 1000)) { - cns_valid = cns_new; - rns_valid = rns_new; + if ( ((cns_new - (unsigned)tvt.tv_nsec) < 1000) + && ((rns_new - (unsigned)tvr.tv_nsec) < 1000)) { + tvt.tv_nsec = cns_new; + tvr.tv_nsec = rns_new; } - // At this point [cr]ns_valid contains valid ns-level + // At this point tvr and tvt contains valid ns-level // timestamps, possibly generated by extending the - // old us_level timestamps + // old us-level timestamps break; @@ -371,29 +368,26 @@ int shm_peek( cnt = shm->count; tvr.tv_sec = shm->receiveTimeStampSec; - tvr.tv_usec = shm->receiveTimeStampUSec; + tvr.tv_nsec = shm->receiveTimeStampUSec * 1000; rns_new = shm->receiveTimeStampNSec; tvt.tv_sec = shm->clockTimeStampSec; - tvt.tv_usec = shm->clockTimeStampUSec; + tvt.tv_nsec = shm->clockTimeStampUSec * 1000; cns_new = shm->clockTimeStampNSec; ok = (cnt == shm->count); - rns_valid = ((unsigned) tvr.tv_usec) * 1000; - cns_valid = ((unsigned) tvt.tv_usec) * 1000; - /* Since these comparisons are between unsigned ** variables they are always well defined, and any ** (signed) underflow will turn into very large ** unsigned values, well above the 1000 cutoff */ - if ( ((cns_new - cns_valid) < 1000) - && ((rns_new - rns_valid) < 1000)) { - cns_valid = cns_new; - rns_valid = rns_new; + if ( ((cns_new - (unsigned)tvt.tv_nsec) < 1000) + && ((rns_new - (unsigned)tvr.tv_nsec) < 1000)) { + tvt.tv_nsec = cns_new; + tvr.tv_nsec = rns_new; } - // At this point [cr]ns_valid contains valid ns-level + // At this point tvr and tvt contains valid ns-level // timestamps, possibly generated by extending the - // old us_level timestamps + // old us-level timestamps break; @@ -408,22 +402,20 @@ int shm_peek( /* add ntpq -c cv timecode in ISO 8601 format */ strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", t); c = snprintf(pp->a_lastcode, sizeof(pp->a_lastcode), - "%s.%06ldZ", timestr, (long)tvt.tv_usec); + "%s.%09ldZ", timestr, (long)tvt.tv_nsec); pp->lencode = (c < sizeof(pp->a_lastcode)) ? c : 0; shm->valid = 0; if (ok) { - TVTOTS(&tvr,&pp->lastrec); - pp->lastrec.l_ui += JAN_1970; - /* pp->lasttime = current_time; */ + pp->lastrec = tspec_stamp_to_lfp(tvr); pp->polls++; pp->day = t->tm_yday+1; pp->hour = t->tm_hour; pp->minute = t->tm_min; pp->second = t->tm_sec; - pp->nsec = cns_valid; + pp->nsec = tvt.tv_nsec; peer->precision = shm->precision; pp->leap = shm->leap; } else {