summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/scripts/calc_tickadj.in
blob: 32eae12964a2b1282f37e27ad88a31d92c2e71fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! @PATH_PERL@
#
# drift of 104.8576 -> +1 tick.  Base  of 10000 ticks.
#
# 970306 HMS Deal with nanoseconds.  Fix sign of adjustments.

$df="/etc/ntp.drift";
# Assumes a 100Hz box with "tick" of 10000
# Someday, we might call "tickadj" for better values...
$base=10000;	# tick: 1,000,000 / HZ
$cvt=104.8576;	# 2 ** 20 / $base
$v1=0.;
$v2="";

if (open(DF, $df))
  {
    if ($_=<DF>)
      {
        ($v1, $v2) = split;
      }

    while ($v1 < 0)
      {
        $v1 += $cvt;
        $base--;
      }

    while ($v1 > $cvt)
      {
        $v1 -= $cvt;
        $base++;
      }
  }

printf("%.3f (drift)\n", $v1);

printf("%d usec; %d nsec\n", $base, ($base + ($v1/$cvt)) * 1000);

OpenPOWER on IntegriCloud