]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1232] Convert SHM refclock to use struct timespec
authorHarlan Stenn <stenn@ntp.org>
Sat, 15 Sep 2012 03:42:10 +0000 (23:42 -0400)
committerHarlan Stenn <stenn@ntp.org>
Sat, 15 Sep 2012 03:42:10 +0000 (23:42 -0400)
bk: 5053f9121xxWDdPtG34aSxp9YMDFUw

ChangeLog
ntpd/refclock_shm.c

index 5dbab3a3a7bb18a972ee0f422168bca0b1928691..b2de28dd2ab835bad274b92048d82452fa1d83c9 100644 (file)
--- 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.
index 6b156d1597a7623c8d9b813c253bb3900cb1aa83..49eed85adfe0bced1d285058d8ba6af768b77bd7 100644 (file)
@@ -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 {