]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix fabs use on delay
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 12 Jun 2013 13:10:54 +0000 (15:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 12 Jun 2013 13:30:28 +0000 (15:30 +0200)
ntp_core.c
sources.c
sourcestats.c

index 4dca216cd1fecddb442f39dbe1bc1f73b934ef24..05e58860ec8686efda007ae5031e999027c4a983 100644 (file)
@@ -941,7 +941,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
     skew = (source_freq_hi - source_freq_lo) / 2.0;
     
     /* and then calculate peer dispersion */
-    epsilon = LCL_GetSysPrecisionAsQuantum() + now_err + skew * local_interval;
+    epsilon = LCL_GetSysPrecisionAsQuantum() + now_err + skew * fabs(local_interval);
     
   } else {
     /* If test3 failed, we probably can't calculate these quantities
@@ -988,8 +988,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
      the standard deviation of the offsets in the register is less than an
      administrator-defined value or the difference between measured offset
      and predicted offset is larger than the increase in delay */
-  if (!SRC_IsGoodSample(inst->source, -theta, delta, inst->max_delay_dev_ratio,
-        LCL_GetMaxClockError(), &sample_time)) {
+  if (!SRC_IsGoodSample(inst->source, -theta, fabs(delta),
+        inst->max_delay_dev_ratio, LCL_GetMaxClockError(), &sample_time)) {
     test4c = 0; /* Failed */
   } else {
     test4c = 1; /* Success */
@@ -1058,7 +1058,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
 
   /* Test 8 checks that the root delay and dispersion quoted in 
      the packet are appropriate */
-  if ((fabs(pkt_root_delay) >= NTP_MAX_DISPERSION) ||
+  if ((pkt_root_delay >= NTP_MAX_DISPERSION) ||
       (pkt_root_dispersion >= NTP_MAX_DISPERSION)) {
     test8 = 0; /* Failed */
   } else {
@@ -1078,7 +1078,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
   valid_header = test5 && test6 && test7i && test8;
   good_header = valid_header && test7ii;
 
-  root_delay = pkt_root_delay + delta;
+  root_delay = pkt_root_delay + fabs(delta);
   root_dispersion = pkt_root_dispersion + epsilon;
 
 #ifdef TRACEON
@@ -1158,7 +1158,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
 
       SRC_AccumulateSample(inst->source,
                            &sample_time,
-                           theta, delta, epsilon,
+                           theta, fabs(delta), epsilon,
                            root_delay, root_dispersion,
                            message->stratum, (NTP_Leap) pkt_leap);
 
index f44451aa3d3de2168a6dee5e5b801ae8f3012a5f..7a9cc63a62a58a7262f13756f0134cc84e6e8a4f 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -547,7 +547,7 @@ SRC_SelectSource(uint32_t match_refid)
                            &(si->variance),
                            &(si->select_ok));
 
-      si->root_distance = si->root_dispersion + 0.5 * fabs(si->root_delay);
+      si->root_distance = si->root_dispersion + 0.5 * si->root_delay;
       si->lo_limit = si->best_offset - si->root_distance;
       si->hi_limit = si->best_offset + si->root_distance;
 
index c3fb60047c6ddc8b3a3c199a7102c014b9cd9c8a..9fabe56de93f77b759fbc5567c314e3b08852590 100644 (file)
@@ -258,7 +258,7 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
   inst->sample_times[n] = *sample_time;
   inst->offsets[n] = offset;
   inst->orig_offsets[m] = offset;
-  inst->peer_delays[m] = fabs(peer_delay);
+  inst->peer_delays[m] = peer_delay;
   inst->peer_dispersions[m] = peer_dispersion;
   inst->root_delays[m] = root_delay;
   inst->root_dispersions[m] = root_dispersion;
@@ -334,7 +334,7 @@ find_best_sample_index(SST_Stats inst, double *times_back)
     elapsed = -times_back[i];
     assert(elapsed >= 0.0);
 
-    root_distance = inst->root_dispersions[j] + elapsed * inst->skew + 0.5 * fabs(inst->root_delays[j]);
+    root_distance = inst->root_dispersions[j] + elapsed * inst->skew + 0.5 * inst->root_delays[j];
     if (root_distance < best_root_distance) {
       best_root_distance = root_distance;
       best_index = i;