1static volatile int print_tci = 1; 2 3/*- 4 * Copyright (c) 1997, 1998 Poul-Henning Kamp <phk@FreeBSD.org> 5 * Copyright (c) 1982, 1986, 1991, 1993 6 * The Regents of the University of California. All rights reserved. 7 * (c) UNIX System Laboratories, Inc. 8 * All or some portions of this file are derived from material licensed --- 25 unchanged lines hidden (view full) --- 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 |
42 * $Id: kern_clock.c,v 1.59 1998/03/26 20:51:31 phk Exp $ |
43 */ 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/dkstat.h> 48#include <sys/callout.h> 49#include <sys/kernel.h> 50#include <sys/proc.h> --- 41 unchanged lines hidden (view full) --- 92 93long tk_cancc; 94long tk_nin; 95long tk_nout; 96long tk_rawcc; 97 98struct timecounter *timecounter; 99 |
100time_t time_second; 101 |
102/* 103 * Clock handling routines. 104 * 105 * This code is written to operate with two timers that run independently of 106 * each other. 107 * 108 * The main timer, running hz times per second, is used to trigger interval 109 * timers, timeouts and rescheduling as needed. --- 23 unchanged lines hidden (view full) --- 133 134int stathz; 135int profhz; 136static int profprocs; 137int ticks; 138static int psdiv, pscnt; /* prof => stat divider */ 139int psratio; /* ratio: prof / stat */ 140 |
141volatile struct timeval mono_time; 142 143/* 144 * Initialize clock frequencies and start both clocks running. 145 */ 146/* ARGSUSED*/ 147static void 148initclocks(dummy) --- 70 unchanged lines hidden (view full) --- 219 softclock(); 220 } else 221 setsoftclock(); 222 } else if (softticks + 1 == ticks) 223 ++softticks; 224} 225 226/* |
227 * Compute number of ticks in the specified amount of time. |
228 */ 229int |
230tvtohz(tv) |
231 struct timeval *tv; 232{ 233 register unsigned long ticks; 234 register long sec, usec; 235 int s; 236 237 /* 238 * If the number of usecs in the whole seconds part of the time --- 10 unchanged lines hidden (view full) --- 249 * case but it is slightly slower and assumes that hz is integral. 250 * 251 * Otherwise, round the time difference down to the maximum 252 * representable value. 253 * 254 * If ints have 32 bits, then the maximum value for any timeout in 255 * 10ms ticks is 248 days. 256 */ |
257 sec = tv->tv_sec; 258 usec = tv->tv_usec; |
259 if (usec < 0) { 260 sec--; 261 usec += 1000000; 262 } 263 if (sec < 0) { 264#ifdef DIAGNOSTIC 265 if (usec > 0) { 266 sec++; 267 usec -= 1000000; 268 } |
269 printf("tvotohz: negative time difference %ld sec %ld usec\n", |
270 sec, usec); 271#endif 272 ticks = 1; 273 } else if (sec <= LONG_MAX / 1000000) 274 ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1)) 275 / tick + 1; 276 else if (sec <= LONG_MAX / hz) 277 ticks = sec * hz 278 + ((unsigned long)usec + (tick - 1)) / tick + 1; 279 else 280 ticks = LONG_MAX; 281 if (ticks > INT_MAX) 282 ticks = INT_MAX; 283 return (ticks); 284} 285 |
286 |
287/* |
288 * Compute number of hz until specified time. Used to 289 * compute third argument to timeout() from an absolute time. 290 */ 291int 292hzto(tv) 293 struct timeval *tv; 294{ 295 register long sec, usec; 296 struct timeval t2; 297 298 getmicrotime(&t2); 299 t2.tv_sec = tv->tv_sec - t2.tv_sec; 300 t2.tv_usec = tv->tv_usec - t2.tv_usec; 301 return (tvtohz(&t2)); 302} 303 304/* |
305 * Start profiling on a process. 306 * 307 * Kernel profiling passes proc0 which never exits and hence 308 * keeps the profile clock running constantly. 309 */ 310void 311startprofclock(p) 312 register struct proc *p; --- 332 unchanged lines hidden (view full) --- 645 tc = timecounter->other; 646 tco = tc->other; 647 *tc = *timecounter; 648 tc->other = tco; 649 tc->offset_sec = ts->tv_sec; 650 tc->offset_nano = (u_int64_t)ts->tv_nsec << 32; 651 tc->offset_micro = ts->tv_nsec / 1000; 652 tc->offset_count = tc->get_timecount(); |
653 time_second = tc->offset_sec; |
654 timecounter = tc; 655 splx(s); 656} 657 658void 659switch_timecounter(struct timecounter *newtc) 660{ 661 int s; --- 56 unchanged lines hidden (view full) --- 718 tc->frequency = tc->tweak->frequency; 719 tc->adjustment = tc->tweak->adjustment; 720 ntp_update_second(tc); /* XXX only needed if xntpd runs */ 721 tco_setscales(tc); 722 } 723 724 tc->offset_micro = (tc->offset_nano / 1000) >> 32; 725 |
726 time_second = tc->offset_sec; |
727 timecounter = tc; 728} 729 730static int 731sysctl_kern_timecounter_frequency SYSCTL_HANDLER_ARGS 732{ 733 734 return (sysctl_handle_opaque(oidp, &timecounter->tweak->frequency, --- 18 unchanged lines hidden --- |