3 die "perl5 needed\n" unless ($] > 5);
10 #chop($ncpu = `sysctl -n hw.ncpu`);
11 #die "Found $ncpu CPUs; can only be run on systems with 1 CPU.\n" if ($ncpu > 1);
13 $driftfile = "/etc/ntp.drift";
14 $driftfile = $opt_d if defined($opt_d);
16 chop($timer = `sysctl -n kern.timecounter.hardware 2> /dev/null`);
21 open(DM, "/var/run/dmesg.boot");
23 # Timecounter "i8254" frequency 1193182 Hz
24 if (/^Timecounter "(\w+)"\s+/) {
32 $opt_t = $timer if !defined($opt_t);
34 if ($timer ne '') { # $timer found...
35 if ($opt_t ne '') { # - and $opt_t found
36 if ($timer ne $opt_t) { # - - and they differ
37 warn "You specified a $opt_t timer but I detected a $timer timer.\n";
40 } else { # - - and they are the same
43 } else { # - but no $opt_t specified; this is OK
46 } else { # No $timer found...
47 if ($opt_t ne '') { # - but $opt_t was specified
48 $timer = $opt_t; # - - so use it.
49 } else { # - and neither was $opt_t
50 warn "I can't tell what timer you have. Please specify one.\n";
56 open(DF, $driftfile) || die "Can't open driftfile ($driftfile): $!\n";
59 if (/^(-?\d+\.\d+)(\s\d)?$/) {
62 die "Bogus value in driftfile $driftfile: <$_>\n";
67 print "NTP drift is <$drift>\n";
69 # Convert from NTP's idea of PPM to a decimal equivalent
70 $freq_adj = int ( $drift * ( 10 ** 6 / 2 ** 20) );
71 print "normalized freq_adj is <$freq_adj>\n";
73 $freq_adj = int ( ( $freq_adj - 1 ) / 2 );
74 print "Applying freq_adj of <".-$freq_adj.">\n";
76 $sysctl = "machdep.".$timer."_freq";
78 chop($mach_freq = `sysctl -n $sysctl`);
80 print "$sysctl is <$mach_freq>\n";
82 $n_mach_freq = $mach_freq - $freq_adj;
84 if (defined($opt_n)) {
85 print "$sysctl $mach_freq -> $n_mach_freq\n";
87 print "i8254: ".`sysctl -w $sysctl=$n_mach_freq`;
91 print STDERR <<EOUsage
92 Usage: $0 [-d drift_file] [-n] [-t timer]
93 where "drift_file" defaults to /etc/ntp.drift
94 and "timer" is usually "tsc" or "i8254"
95 and "-n" says "don't really change anything, just say what would happen".