summaryrefslogtreecommitdiffstats
path: root/usr.sbin/xntpd/util
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1994-09-29 23:04:24 +0000
committerwollman <wollman@FreeBSD.org>1994-09-29 23:04:24 +0000
commit1cba639cb2d728cbbb3866d923f8826a01269414 (patch)
tree18dfbc130c063c415f026919cb34f9b7d2c18322 /usr.sbin/xntpd/util
parent2bf66335a61004f895541f2c64c7fb1508224e34 (diff)
parent96f7e86b724c797f2b44beaaf956cf14550e57df (diff)
downloadFreeBSD-src-1cba639cb2d728cbbb3866d923f8826a01269414.zip
FreeBSD-src-1cba639cb2d728cbbb3866d923f8826a01269414.tar.gz
This commit was generated by cvs2svn to compensate for changes in r3215,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'usr.sbin/xntpd/util')
-rw-r--r--usr.sbin/xntpd/util/Makefile.tmpl2
-rw-r--r--usr.sbin/xntpd/util/ntptime.c27
-rw-r--r--usr.sbin/xntpd/util/precision.c87
-rw-r--r--usr.sbin/xntpd/util/timetrim.c2
4 files changed, 95 insertions, 23 deletions
diff --git a/usr.sbin/xntpd/util/Makefile.tmpl b/usr.sbin/xntpd/util/Makefile.tmpl
index be1681f..e30292f 100644
--- a/usr.sbin/xntpd/util/Makefile.tmpl
+++ b/usr.sbin/xntpd/util/Makefile.tmpl
@@ -1,5 +1,5 @@
#
-# Makefile.tmpl,v 3.1 1993/07/06 01:10:58 jbj Exp
+# Makefile.tmpl
#
PROGRAM= tickadj
#
diff --git a/usr.sbin/xntpd/util/ntptime.c b/usr.sbin/xntpd/util/ntptime.c
index 858fe7c..1515905 100644
--- a/usr.sbin/xntpd/util/ntptime.c
+++ b/usr.sbin/xntpd/util/ntptime.c
@@ -17,6 +17,7 @@
#include "ntp_fp.h"
#include "ntp_unixtime.h"
+#include "sys/timex.h"
#include "ntp_stdlib.h"
#ifndef SYS_DECOSF1
@@ -24,11 +25,9 @@
#endif /* SYS_DECOSF1 */
#ifdef KERNEL_PLL
-#include <sys/timex.h>
#define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
#define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
#else /* KERNEL_PLL */
-#include "ntp_timex.h"
#define SYS_ntp_adjtime NTP_SYSCALL_ADJ
#define SYS_ntp_gettime NTP_SYSCALL_GET
#endif /* KERNEL_PLL */
@@ -147,14 +146,16 @@ main(argc, argv)
#endif
if (cost) {
- for (c=0; c< sizeof times / sizeof times[0]; c++) {
+ for (c = 0; c < sizeof times / sizeof times[0]; c++) {
(void)ntp_gettime(&ntv);
- if (pll_control < 0) break;
+ if (pll_control < 0)
+ break;
times[c] = ntv.time.tv_usec;
}
if (pll_control >= 0) {
printf("[ us %06d:", times[0]);
- for (c=1; c< sizeof times / sizeof times[0]; c++) printf(" %d", times[c] - times[c-1]);
+ for (c = 1; c < sizeof times / sizeof times[0]; c++)
+ printf(" %d", times[c] - times[c - 1]);
printf(" ]\n");
}
}
@@ -169,7 +170,8 @@ main(argc, argv)
/*
* Fetch timekeeping data and display.
*/
- if ((status = ntp_gettime(&ntv)) < 0)
+ status = ntp_gettime(&ntv);
+ if (status < 0)
perror("ntp_gettime() call fails");
else {
printf("ntp_gettime() returns code %d\n", status);
@@ -182,13 +184,14 @@ main(argc, argv)
printf(" maximum error %ld us, estimated error %ld us.\n",
ntv.maxerror, ntv.esterror);
if (rawtime) printf(" ntptime=%x.%x unixtime=%x.%06d %s",
- ts.l_ui, ts.l_uf,
- ntv.time.tv_sec, ntv.time.tv_usec,
- ctime(&ntv.time.tv_sec));
+ ts.l_ui, ts.l_uf, ntv.time.tv_sec, ntv.time.tv_usec,
+ ctime(&ntv.time.tv_sec));
}
- if ((status = ntp_adjtime(&ntx)) < 0) perror((errno == EPERM) ?
- ">> Must be root to set kernel values\n>> ntp_adjtime() call fails" :
- ">> ntp_adjtime() call fails");
+ status = ntp_adjtime(&ntx);
+ if (status < 0)
+ perror((errno == EPERM) ?
+ "Must be root to set kernel values\nntp_adjtime() call fails" :
+ "ntp_adjtime() call fails");
else {
printf("ntp_adjtime() returns code %d\n", status);
ftemp = ntx.freq;
diff --git a/usr.sbin/xntpd/util/precision.c b/usr.sbin/xntpd/util/precision.c
index 69af19f..6961475 100644
--- a/usr.sbin/xntpd/util/precision.c
+++ b/usr.sbin/xntpd/util/precision.c
@@ -1,23 +1,27 @@
#include <sys/types.h>
#include <sys/time.h>
+#include "ntp_unixtime.h"
#define DEFAULT_SYS_PRECISION -99
+int default_get_resolution();
int default_get_precision();
int
main() {
- printf("log2(precision) = %d\n", default_get_precision());
+ printf("log2(resolution) = %d, log2(precision) = %d\n",
+ default_get_resolution(),
+ default_get_precision());
return 0;
}
-/* Find the precision of the system clock by watching how the current time
+/* Find the resolution of the system clock by watching how the current time
* changes as we read it repeatedly.
*
* struct timeval is only good to 1us, which may cause problems as machines
* get faster, but until then the logic goes:
*
- * If a machine has precision (i.e. accurate timing info) > 1us, then it will
+ * If a machine has resolution (i.e. accurate timing info) > 1us, then it will
* probably use the "unused" low order bits as a counter (to force time to be
* a strictly increaing variable), incrementing it each time any process
* requests the time [[ or maybe time will stand still ? ]].
@@ -28,7 +32,7 @@ main() {
* THEN this machine is "counting" with the low order bits
* ELIF this is not the first time round the loop
* THEN this machine *WAS* counting, and has now stepped
- * ELSE this machine has precision < time to read clock
+ * ELSE this machine has resolution < time to read clock
*
* SO: if it exits on the first loop, assume "full accuracy" (1us)
* otherwise, take the log2(observered difference, rounded UP)
@@ -47,9 +51,11 @@ main() {
#define MINSTEP 5 /* some systems increment uS on each call */
/* Don't use "1" as some *other* process may read too*/
/*We assume no system actually *ANSWERS* in this time*/
+#define MAXSTEP 20000 /* maximum clock increment (us) */
+#define MINLOOPS 5 /* minimum number of step samples */
#define MAXLOOPS HUSECS /* Assume precision < .1s ! */
-int default_get_precision()
+int default_get_resolution()
{
struct timeval tp;
struct timezone tzp;
@@ -57,7 +63,7 @@ int default_get_precision()
int i;
long diff;
long val;
- int minsteps = 2; /* need at least this many steps */
+ int minsteps = MINLOOPS; /* need at least this many steps */
gettimeofday(&tp, &tzp);
last = tp.tv_usec;
@@ -69,13 +75,76 @@ int default_get_precision()
last = tp.tv_usec;
}
- printf("precision calculation given %dus after %d loop%s\n",
+ printf("resolution = %ld usec after %d loop%s\n",
diff, i, (i==1) ? "" : "s");
diff = (diff *3)/2;
- if (i >= MAXLOOPS) diff = 1; /* No STEP, so FAST machine */
- if (i == 0) diff = 1; /* time to read clock >= precision */
+ if (i >= MAXLOOPS) {
+ printf(
+ " (Boy this machine is fast ! %d loops without a step)\n",
+ MAXLOOPS);
+ diff = 1; /* No STEP, so FAST machine */
+ }
+ if (i == 0) {
+ printf(
+" (The resolution is less than the time to read the clock -- Assume 1us)\n");
+ diff = 1; /* time to read clock >= resolution */
+ }
for (i=0, val=HUSECS; val>0; i--, val >>= 1) if (diff >= val) return i;
+ printf(" (Oh dear -- that wasn't expected ! I'll guess !)\n");
return DEFAULT_SYS_PRECISION /* Something's BUST, so lie ! */;
}
+/* ===== Rest of this code lifted straight from xntpd/ntp_proto.c ! ===== */
+
+/*
+ * This routine calculates the differences between successive calls to
+ * gettimeofday(). If a difference is less than zero, the us field
+ * has rolled over to the next second, so we add a second in us. If
+ * the difference is greater than zero and less than MINSTEP, the
+ * clock has been advanced by a small amount to avoid standing still.
+ * If the clock has advanced by a greater amount, then a timer interrupt
+ * has occurred and this amount represents the precision of the clock.
+ * In order to guard against spurious values, which could occur if we
+ * happen to hit a fat interrupt, we do this for MINLOOPS times and
+ * keep the minimum value obtained.
+ */
+int default_get_precision()
+{
+ struct timeval tp;
+ struct timezone tzp;
+ long last;
+ int i;
+ long diff;
+ long val;
+ long usec;
+
+ usec = 0;
+ val = MAXSTEP;
+ GETTIMEOFDAY(&tp, &tzp);
+ last = tp.tv_usec;
+ for (i = 0; i < MINLOOPS && usec < HUSECS;) {
+ GETTIMEOFDAY(&tp, &tzp);
+ diff = tp.tv_usec - last;
+ last = tp.tv_usec;
+ if (diff < 0)
+ diff += DUSECS;
+ usec += diff;
+ if (diff > MINSTEP) {
+ i++;
+ if (diff < val)
+ val = diff;
+ }
+ }
+ printf("precision = %ld usec after %d loop%s\n",
+ val, i, (i == 1) ? "" : "s");
+ if (usec >= HUSECS) {
+ printf(" (Boy this machine is fast ! usec was %ld)\n",
+ usec);
+ val = MINSTEP; /* val <= MINSTEP; fast machine */
+ }
+ diff = HUSECS;
+ for (i = 0; diff > val; i--)
+ diff >>= 1;
+ return (i);
+}
diff --git a/usr.sbin/xntpd/util/timetrim.c b/usr.sbin/xntpd/util/timetrim.c
index 052a587..a1635c1 100644
--- a/usr.sbin/xntpd/util/timetrim.c
+++ b/usr.sbin/xntpd/util/timetrim.c
@@ -1,5 +1,5 @@
/*
- * timetrim.c,v 3.1 1993/07/06 01:11:06 jbj Exp
+ * timetrim.c
*
* "timetrim" allows setting and adjustment of the system clock frequency
* trim parameter on Silicon Graphics machines. The trim value native
OpenPOWER on IntegriCloud