SCCS-vsn: usr.sbin/timed/timed/networkdelta.c 8.2
-static char sccsid[] = "@(#)networkdelta.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)networkdelta.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#ifdef sgi
#endif /* not lint */
#ifdef sgi
if (numdelta == 1)
return 0;
if (numdelta == 1)
return 0;
+ /* get average of trusted values */
if (trace)
fprintf(fd, "median of %d values starting at %ld is about ",
numdelta, med);
if (trace)
fprintf(fd, "median of %d values starting at %ld is about ",
numdelta, med);
+ /* get median of all trusted values, using average as initial guess */
+ eps = med - x[0];
med = median(med, &eps, &x[0], xp+1, VALID_RANGE);
med = median(med, &eps, &x[0], xp+1, VALID_RANGE);
- /*
- * compute the median of all values near the good median
+ /* Compute the median of all good values.
+ * Good values are those of all clocks, including untrusted clocks,
+ * that are
+ * - trusted and somewhat close to the median of the
+ * trusted clocks
+ * - trusted or untrusted and very close to the median of the
+ * trusted clocks
*/
hidelta = med + GOOD_RANGE;
lodelta = med - GOOD_RANGE;
*/
hidelta = med + GOOD_RANGE;
lodelta = med - GOOD_RANGE;
float xx = *xptr;
dum = xx - a;
float xx = *xptr;
dum = xx - a;
- if (dum != 0.0) { /* avoid dividing by 0 */
+ if (dum != 0.0) { /* avoid dividing by 0 */
if (dum > 0.0) {
npts++;
if (xx < xp)
if (dum > 0.0) {
npts++;
if (xx < xp)
if (ap-am < gnuf || sum == 0) {
if (trace)
fprintf(fd,
if (ap-am < gnuf || sum == 0) {
if (trace)
fprintf(fd,
- "%ld in %d passes; early out balance=%d\n",
+ "%ld in %d passes;"
+ " early out balance=%d\n",
(long)a, pass, npts);
return a; /* guess was good enough */
}
(long)a, pass, npts);
return a; /* guess was good enough */
}
aa = (sumx/sum-a)*AMP;
if (npts >= 2) { /* guess was too low */
am = a;
aa = (sumx/sum-a)*AMP;
if (npts >= 2) { /* guess was too low */
am = a;
- aa = xp + max(0.0, aa);;
- if (aa > ap)
+ aa = xp + max(0.0, aa);
+ if (aa >= ap)
- } else if (npts <= -2) { /* guess was two high */
+ } else if (npts <= -2) { /* guess was two high */
- aa = xm + min(0.0, aa);;
- if (aa < am)
+ aa = xm + min(0.0, aa);
+ if (aa <= am)
aa = (a + am)/2;
} else {
aa = (a + am)/2;
} else {
if (a == aa) {
if (trace)
if (a == aa) {
if (trace)
- fprintf(fd,
- "%ld in %d passes; force out balance=%d\n",
+ fprintf(fd, "%ld in %d passes;"
+ " force out balance=%d\n",
(long)a, pass, npts);
return a;
}
(long)a, pass, npts);
return a;
}
- } else if (npts != 0) { /* odd number of points */
+ } else if (npts != 0) { /* odd number of points */
if (npts > 0)
a = xp;
else
if (npts > 0)
a = xp;
else