Remove unused clear() function from the console renderer interface.
[dragonfly.git] / sys / kern / kern_clock.c
CommitLineData
8c10bfcf
MD
1/*
2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
984263bc
MD
34 * Copyright (c) 1997, 1998 Poul-Henning Kamp <phk@FreeBSD.org>
35 * Copyright (c) 1982, 1986, 1991, 1993
36 * The Regents of the University of California. All rights reserved.
37 * (c) UNIX System Laboratories, Inc.
38 * All or some portions of this file are derived from material licensed
39 * to the University of California by American Telephone and Telegraph
40 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
41 * the permission of UNIX System Laboratories, Inc.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
72 * $FreeBSD: src/sys/kern/kern_clock.c,v 1.105.2.10 2002/10/17 13:19:40 maxim Exp $
08f95c49 73 * $DragonFly: src/sys/kern/kern_clock.c,v 1.38 2005/04/24 02:01:08 dillon Exp $
984263bc
MD
74 */
75
76#include "opt_ntp.h"
77
78#include <sys/param.h>
79#include <sys/systm.h>
80#include <sys/dkstat.h>
81#include <sys/callout.h>
82#include <sys/kernel.h>
f5d21610 83#include <sys/kinfo.h>
984263bc
MD
84#include <sys/proc.h>
85#include <sys/malloc.h>
86#include <sys/resourcevar.h>
87#include <sys/signalvar.h>
88#include <sys/timex.h>
89#include <sys/timepps.h>
90#include <vm/vm.h>
91#include <sys/lock.h>
92#include <vm/pmap.h>
93#include <vm/vm_map.h>
94#include <sys/sysctl.h>
2689779e 95#include <sys/thread2.h>
984263bc
MD
96
97#include <machine/cpu.h>
98#include <machine/limits.h>
99#include <machine/smp.h>
100
101#ifdef GPROF
102#include <sys/gmon.h>
103#endif
104
105#ifdef DEVICE_POLLING
106extern void init_device_poll(void);
107extern void hardclock_device_poll(void);
108#endif /* DEVICE_POLLING */
109
402ed7e1 110static void initclocks (void *dummy);
984263bc
MD
111SYSINIT(clocks, SI_SUB_CLOCKS, SI_ORDER_FIRST, initclocks, NULL)
112
6ad39cae
MD
113/*
114 * Some of these don't belong here, but it's easiest to concentrate them.
f5d21610 115 * Note that cp_time counts in microseconds, but most userland programs
6ad39cae
MD
116 * just compare relative times against the total by delta.
117 */
f5d21610 118struct cp_time cp_time;
984263bc
MD
119
120SYSCTL_OPAQUE(_kern, OID_AUTO, cp_time, CTLFLAG_RD, &cp_time, sizeof(cp_time),
121 "LU", "CPU time statistics");
122
88c4d2f6
MD
123/*
124 * boottime is used to calculate the 'real' uptime. Do not confuse this with
125 * microuptime(). microtime() is not drift compensated. The real uptime
60b2809b
MD
126 * with compensation is nanotime() - bootime. boottime is recalculated
127 * whenever the real time is set based on the compensated elapsed time
128 * in seconds (gd->gd_time_seconds).
88c4d2f6 129 *
88c4d2f6
MD
130 * The gd_time_seconds and gd_cpuclock_base fields remain fairly monotonic.
131 * Slight adjustments to gd_cpuclock_base are made to phase-lock it to
132 * the real time.
133 */
134struct timespec boottime; /* boot time (realtime) for reference only */
88c4d2f6 135time_t time_second; /* read-only 'passive' uptime in seconds */
984263bc 136
5eb5a6bc
MD
137/*
138 * basetime is used to calculate the compensated real time of day. The
139 * basetime can be modified on a per-tick basis by the adjtime(),
140 * ntp_adjtime(), and sysctl-based time correction APIs.
141 *
142 * Note that frequency corrections can also be made by adjusting
143 * gd_cpuclock_base.
144 *
145 * basetime is a tail-chasing FIFO, updated only by cpu #0. The FIFO is
146 * used on both SMP and UP systems to avoid MP races between cpu's and
147 * interrupt races on UP systems.
148 */
149#define BASETIME_ARYSIZE 16
150#define BASETIME_ARYMASK (BASETIME_ARYSIZE - 1)
151static struct timespec basetime[BASETIME_ARYSIZE];
152static volatile int basetime_index;
153
154static int
155sysctl_get_basetime(SYSCTL_HANDLER_ARGS)
156{
157 struct timespec *bt;
158 int error;
159
160 bt = &basetime[basetime_index];
08f95c49 161 error = SYSCTL_OUT(req, bt, sizeof(*bt));
5eb5a6bc
MD
162 return (error);
163}
164
984263bc 165SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime, CTLFLAG_RD,
08f95c49 166 &boottime, timespec, "System boottime");
5eb5a6bc 167SYSCTL_PROC(_kern, OID_AUTO, basetime, CTLTYPE_STRUCT|CTLFLAG_RD, 0, 0,
08f95c49 168 sysctl_get_basetime, "S,timespec", "System basetime");
984263bc 169
88c4d2f6
MD
170static void hardclock(systimer_t info, struct intrframe *frame);
171static void statclock(systimer_t info, struct intrframe *frame);
172static void schedclock(systimer_t info, struct intrframe *frame);
5eb5a6bc 173static void getnanotime_nbt(struct timespec *nbt, struct timespec *tsp);
88c4d2f6
MD
174
175int ticks; /* system master ticks at hz */
da3639ef 176int clocks_running; /* tsleep/timeout clocks operational */
88c4d2f6
MD
177int64_t nsec_adj; /* ntpd per-tick adjustment in nsec << 32 */
178int64_t nsec_acc; /* accumulator */
984263bc 179
4026c000
JS
180/* NTPD time correction fields */
181int64_t ntp_tick_permanent; /* per-tick adjustment in nsec << 32 */
182int64_t ntp_tick_acc; /* accumulator for per-tick adjustment */
183int64_t ntp_delta; /* one-time correction in nsec */
184int64_t ntp_big_delta = 1000000000;
185int32_t ntp_tick_delta; /* current adjustment rate */
186int32_t ntp_default_tick_delta; /* adjustment rate for ntp_delta */
48590578
JS
187time_t ntp_leap_second; /* time of next leap second */
188int ntp_leap_insert; /* whether to insert or remove a second */
4026c000 189
984263bc 190/*
88c4d2f6 191 * Finish initializing clock frequencies and start all clocks running.
984263bc 192 */
88c4d2f6
MD
193/* ARGSUSED*/
194static void
195initclocks(void *dummy)
984263bc 196{
88c4d2f6
MD
197 cpu_initclocks();
198#ifdef DEVICE_POLLING
199 init_device_poll();
200#endif
201 /*psratio = profhz / stathz;*/
202 initclocks_pcpu();
da3639ef 203 clocks_running = 1;
984263bc
MD
204}
205
88c4d2f6
MD
206/*
207 * Called on a per-cpu basis
208 */
209void
210initclocks_pcpu(void)
211{
212 struct globaldata *gd = mycpu;
984263bc 213
88c4d2f6
MD
214 crit_enter();
215 if (gd->gd_cpuid == 0) {
216 gd->gd_time_seconds = 1;
217 gd->gd_cpuclock_base = cputimer_count();
218 } else {
219 /* XXX */
220 gd->gd_time_seconds = globaldata_find(0)->gd_time_seconds;
221 gd->gd_cpuclock_base = globaldata_find(0)->gd_cpuclock_base;
222 }
0d1dffdf
MD
223
224 /*
225 * Use a non-queued periodic systimer to prevent multiple ticks from
226 * building up if the sysclock jumps forward (8254 gets reset). The
227 * sysclock will never jump backwards. Our time sync is based on
228 * the actual sysclock, not the ticks count.
229 */
230 systimer_init_periodic_nq(&gd->gd_hardclock, hardclock, NULL, hz);
231 systimer_init_periodic_nq(&gd->gd_statclock, statclock, NULL, stathz);
88c4d2f6 232 /* XXX correct the frequency for scheduler / estcpu tests */
0d1dffdf 233 systimer_init_periodic_nq(&gd->gd_schedclock, schedclock,
8478264a 234 NULL, ESTCPUFREQ);
88c4d2f6
MD
235 crit_exit();
236}
984263bc
MD
237
238/*
88c4d2f6
MD
239 * This sets the current real time of day. Timespecs are in seconds and
240 * nanoseconds. We do not mess with gd_time_seconds and gd_cpuclock_base,
241 * instead we adjust basetime so basetime + gd_* results in the current
242 * time of day. This way the gd_* fields are guarenteed to represent
243 * a monotonically increasing 'uptime' value.
5eb5a6bc
MD
244 *
245 * When set_timeofday() is called from userland, the system call forces it
246 * onto cpu #0 since only cpu #0 can update basetime_index.
984263bc 247 */
88c4d2f6
MD
248void
249set_timeofday(struct timespec *ts)
250{
5eb5a6bc
MD
251 struct timespec *nbt;
252 int ni;
984263bc 253
88c4d2f6
MD
254 /*
255 * XXX SMP / non-atomic basetime updates
256 */
257 crit_enter();
5eb5a6bc
MD
258 ni = (basetime_index + 1) & BASETIME_ARYMASK;
259 nbt = &basetime[ni];
260 nanouptime(nbt);
261 nbt->tv_sec = ts->tv_sec - nbt->tv_sec;
262 nbt->tv_nsec = ts->tv_nsec - nbt->tv_nsec;
263 if (nbt->tv_nsec < 0) {
264 nbt->tv_nsec += 1000000000;
265 --nbt->tv_sec;
88c4d2f6 266 }
a81931cc
MD
267
268 /*
269 * Note that basetime diverges from boottime as the clock drift is
270 * compensated for, so we cannot do away with boottime. When setting
271 * the absolute time of day the drift is 0 (for an instant) and we
272 * can simply assign boottime to basetime.
273 *
274 * Note that nanouptime() is based on gd_time_seconds which is drift
275 * compensated up to a point (it is guarenteed to remain monotonically
276 * increasing). gd_time_seconds is thus our best uptime guess and
277 * suitable for use in the boottime calculation. It is already taken
278 * into account in the basetime calculation above.
279 */
5eb5a6bc 280 boottime.tv_sec = nbt->tv_sec;
4026c000 281 ntp_delta = 0;
5eb5a6bc
MD
282
283 /*
284 * We now have a new basetime, update the index.
285 */
286 cpu_mb1();
287 basetime_index = ni;
288
88c4d2f6
MD
289 crit_exit();
290}
291
984263bc 292/*
88c4d2f6
MD
293 * Each cpu has its own hardclock, but we only increments ticks and softticks
294 * on cpu #0.
295 *
296 * NOTE! systimer! the MP lock might not be held here. We can only safely
297 * manipulate objects owned by the current cpu.
984263bc 298 */
984263bc 299static void
88c4d2f6 300hardclock(systimer_t info, struct intrframe *frame)
984263bc 301{
88c4d2f6
MD
302 sysclock_t cputicks;
303 struct proc *p;
304 struct pstats *pstats;
305 struct globaldata *gd = mycpu;
984263bc
MD
306
307 /*
88c4d2f6
MD
308 * Realtime updates are per-cpu. Note that timer corrections as
309 * returned by microtime() and friends make an additional adjustment
310 * using a system-wise 'basetime', but the running time is always
311 * taken from the per-cpu globaldata area. Since the same clock
312 * is distributing (XXX SMP) to all cpus, the per-cpu timebases
313 * stay in synch.
314 *
315 * Note that we never allow info->time (aka gd->gd_hardclock.time)
fad57d0e
MD
316 * to reverse index gd_cpuclock_base, but that it is possible for
317 * it to temporarily get behind in the seconds if something in the
318 * system locks interrupts for a long period of time. Since periodic
319 * timers count events, though everything should resynch again
320 * immediately.
984263bc 321 */
88c4d2f6 322 cputicks = info->time - gd->gd_cpuclock_base;
fad57d0e 323 if (cputicks >= cputimer_freq) {
88c4d2f6
MD
324 ++gd->gd_time_seconds;
325 gd->gd_cpuclock_base += cputimer_freq;
326 }
984263bc
MD
327
328 /*
92b561b7
MD
329 * The system-wide ticks counter and NTP related timedelta/tickdelta
330 * adjustments only occur on cpu #0. NTP adjustments are accomplished
331 * by updating basetime.
984263bc 332 */
88c4d2f6 333 if (gd->gd_cpuid == 0) {
5eb5a6bc 334 struct timespec *nbt;
88c4d2f6
MD
335 struct timespec nts;
336 int leap;
5eb5a6bc 337 int ni;
984263bc 338
88c4d2f6 339 ++ticks;
984263bc 340
88c4d2f6
MD
341#ifdef DEVICE_POLLING
342 hardclock_device_poll(); /* mpsafe, short and quick */
343#endif /* DEVICE_POLLING */
984263bc 344
88c4d2f6
MD
345#if 0
346 if (tco->tc_poll_pps)
347 tco->tc_poll_pps(tco);
348#endif
5eb5a6bc 349
88c4d2f6 350 /*
5eb5a6bc
MD
351 * Calculate the new basetime index. We are in a critical section
352 * on cpu #0 and can safely play with basetime_index. Start
353 * with the current basetime and then make adjustments.
354 */
355 ni = (basetime_index + 1) & BASETIME_ARYMASK;
356 nbt = &basetime[ni];
357 *nbt = basetime[basetime_index];
358
359 /*
360 * Apply adjtime corrections. (adjtime() API)
361 *
362 * adjtime() only runs on cpu #0 so our critical section is
363 * sufficient to access these variables.
88c4d2f6 364 */
4026c000 365 if (ntp_delta != 0) {
5eb5a6bc 366 nbt->tv_nsec += ntp_tick_delta;
4026c000
JS
367 ntp_delta -= ntp_tick_delta;
368 if ((ntp_delta > 0 && ntp_delta < ntp_tick_delta) ||
369 (ntp_delta < 0 && ntp_delta > ntp_tick_delta)) {
5eb5a6bc 370 ntp_tick_delta = ntp_delta;
4026c000
JS
371 }
372 }
373
5eb5a6bc
MD
374 /*
375 * Apply permanent frequency corrections. (sysctl API)
376 */
4026c000
JS
377 if (ntp_tick_permanent != 0) {
378 ntp_tick_acc += ntp_tick_permanent;
379 if (ntp_tick_acc >= (1LL << 32)) {
5eb5a6bc 380 nbt->tv_nsec += ntp_tick_acc >> 32;
331bc6f8 381 ntp_tick_acc -= (ntp_tick_acc >> 32) << 32;
4026c000 382 } else if (ntp_tick_acc <= -(1LL << 32)) {
331bc6f8 383 /* Negate ntp_tick_acc to avoid shifting the sign bit. */
5eb5a6bc 384 nbt->tv_nsec -= (-ntp_tick_acc) >> 32;
331bc6f8 385 ntp_tick_acc += ((-ntp_tick_acc) >> 32) << 32;
4026c000
JS
386 }
387 }
388
5eb5a6bc
MD
389 if (nbt->tv_nsec >= 1000000000) {
390 nbt->tv_sec++;
391 nbt->tv_nsec -= 1000000000;
392 } else if (nbt->tv_nsec < 0) {
393 nbt->tv_sec--;
394 nbt->tv_nsec += 1000000000;
88c4d2f6
MD
395 }
396
397 /*
5eb5a6bc 398 * Another per-tick compensation. (for ntp_adjtime() API)
88c4d2f6 399 */
5eb5a6bc 400 if (nsec_adj != 0) {
88c4d2f6
MD
401 nsec_acc += nsec_adj;
402 if (nsec_acc >= 0x100000000LL) {
5eb5a6bc 403 nbt->tv_nsec += nsec_acc >> 32;
88c4d2f6
MD
404 nsec_acc = (nsec_acc & 0xFFFFFFFFLL);
405 } else if (nsec_acc <= -0x100000000LL) {
5eb5a6bc 406 nbt->tv_nsec -= -nsec_acc >> 32;
88c4d2f6
MD
407 nsec_acc = -(-nsec_acc & 0xFFFFFFFFLL);
408 }
5eb5a6bc
MD
409 if (nbt->tv_nsec >= 1000000000) {
410 nbt->tv_nsec -= 1000000000;
411 ++nbt->tv_sec;
412 } else if (nbt->tv_nsec < 0) {
413 nbt->tv_nsec += 1000000000;
414 --nbt->tv_sec;
415 }
416 }
417
418 /************************************************************
419 * LEAP SECOND CORRECTION *
420 ************************************************************
421 *
422 * Taking into account all the corrections made above, figure
423 * out the new real time. If the seconds field has changed
424 * then apply any pending leap-second corrections.
425 */
426 getnanotime_nbt(nbt, &nts);
427
428 /*
429 * Apply leap second (sysctl API)
430 */
431 if (ntp_leap_second) {
432 if (ntp_leap_second == nts.tv_sec) {
433 if (ntp_leap_insert)
434 nbt->tv_sec++;
435 else
436 nbt->tv_sec--;
437 ntp_leap_second--;
88c4d2f6 438 }
88c4d2f6
MD
439 }
440
441 /*
5eb5a6bc 442 * Apply leap second (ntp_adjtime() API)
88c4d2f6 443 */
88c4d2f6
MD
444 if (time_second != nts.tv_sec) {
445 leap = ntp_update_second(time_second, &nsec_adj);
5eb5a6bc
MD
446 nbt->tv_sec += leap;
447 time_second = nbt->tv_sec;
88c4d2f6
MD
448 nsec_adj /= hz;
449 }
5eb5a6bc
MD
450
451 /*
452 * Finally, our new basetime is ready to go live!
453 */
454 cpu_mb1();
455 basetime_index = ni;
88c4d2f6
MD
456 }
457
92b561b7
MD
458 /*
459 * softticks are handled for all cpus
460 */
461 hardclock_softtick(gd);
462
88c4d2f6
MD
463 /*
464 * ITimer handling is per-tick, per-cpu. I don't think psignal()
465 * is mpsafe on curproc, so XXX get the mplock.
466 */
467 if ((p = curproc) != NULL && try_mplock()) {
984263bc 468 pstats = p->p_stats;
88c4d2f6 469 if (frame && CLKF_USERMODE(frame) &&
984263bc
MD
470 timevalisset(&pstats->p_timer[ITIMER_VIRTUAL].it_value) &&
471 itimerdecr(&pstats->p_timer[ITIMER_VIRTUAL], tick) == 0)
472 psignal(p, SIGVTALRM);
473 if (timevalisset(&pstats->p_timer[ITIMER_PROF].it_value) &&
474 itimerdecr(&pstats->p_timer[ITIMER_PROF], tick) == 0)
475 psignal(p, SIGPROF);
88c4d2f6 476 rel_mplock();
984263bc 477 }
604e1e09 478 setdelayed();
88c4d2f6 479}
984263bc 480
88c4d2f6
MD
481/*
482 * The statistics clock typically runs at a 125Hz rate, and is intended
483 * to be frequency offset from the hardclock (typ 100Hz). It is per-cpu.
484 *
485 * NOTE! systimer! the MP lock might not be held here. We can only safely
486 * manipulate objects owned by the current cpu.
487 *
488 * The stats clock is responsible for grabbing a profiling sample.
489 * Most of the statistics are only used by user-level statistics programs.
490 * The main exceptions are p->p_uticks, p->p_sticks, p->p_iticks, and
491 * p->p_estcpu.
492 *
493 * Like the other clocks, the stat clock is called from what is effectively
494 * a fast interrupt, so the context should be the thread/process that got
495 * interrupted.
496 */
497static void
498statclock(systimer_t info, struct intrframe *frame)
499{
500#ifdef GPROF
501 struct gmonparam *g;
502 int i;
984263bc 503#endif
88c4d2f6
MD
504 thread_t td;
505 struct proc *p;
506 int bump;
507 struct timeval tv;
508 struct timeval *stv;
984263bc
MD
509
510 /*
88c4d2f6 511 * How big was our timeslice relative to the last time?
984263bc 512 */
88c4d2f6
MD
513 microuptime(&tv); /* mpsafe */
514 stv = &mycpu->gd_stattv;
515 if (stv->tv_sec == 0) {
516 bump = 1;
517 } else {
518 bump = tv.tv_usec - stv->tv_usec +
519 (tv.tv_sec - stv->tv_sec) * 1000000;
520 if (bump < 0)
521 bump = 0;
522 if (bump > 1000000)
523 bump = 1000000;
524 }
525 *stv = tv;
984263bc 526
88c4d2f6
MD
527 td = curthread;
528 p = td->td_proc;
984263bc 529
88c4d2f6
MD
530 if (frame && CLKF_USERMODE(frame)) {
531 /*
532 * Came from userland, handle user time and deal with
533 * possible process.
534 */
535 if (p && (p->p_flag & P_PROFIL))
536 addupc_intr(p, CLKF_PC(frame), 1);
537 td->td_uticks += bump;
984263bc 538
88c4d2f6
MD
539 /*
540 * Charge the time as appropriate
541 */
542 if (p && p->p_nice > NZERO)
f5d21610 543 cp_time.cp_nice += bump;
88c4d2f6 544 else
f5d21610 545 cp_time.cp_user += bump;
88c4d2f6
MD
546 } else {
547#ifdef GPROF
548 /*
549 * Kernel statistics are just like addupc_intr, only easier.
550 */
551 g = &_gmonparam;
552 if (g->state == GMON_PROF_ON && frame) {
553 i = CLKF_PC(frame) - g->lowpc;
554 if (i < g->textsize) {
555 i /= HISTFRACTION * sizeof(*g->kcount);
556 g->kcount[i]++;
557 }
558 }
559#endif
560 /*
561 * Came from kernel mode, so we were:
562 * - handling an interrupt,
563 * - doing syscall or trap work on behalf of the current
564 * user process, or
565 * - spinning in the idle loop.
566 * Whichever it is, charge the time as appropriate.
567 * Note that we charge interrupts to the current process,
568 * regardless of whether they are ``for'' that process,
569 * so that we know how much of its real time was spent
570 * in ``non-process'' (i.e., interrupt) work.
571 *
572 * XXX assume system if frame is NULL. A NULL frame
573 * can occur if ipi processing is done from an splx().
574 */
575 if (frame && CLKF_INTR(frame))
576 td->td_iticks += bump;
577 else
578 td->td_sticks += bump;
579
580 if (frame && CLKF_INTR(frame)) {
f5d21610 581 cp_time.cp_intr += bump;
88c4d2f6
MD
582 } else {
583 if (td == &mycpu->gd_idlethread)
f5d21610 584 cp_time.cp_idle += bump;
88c4d2f6 585 else
f5d21610 586 cp_time.cp_sys += bump;
88c4d2f6
MD
587 }
588 }
589}
590
591/*
0a3f9b47 592 * The scheduler clock typically runs at a 20Hz rate. NOTE! systimer,
88c4d2f6
MD
593 * the MP lock might not be held. We can safely manipulate parts of curproc
594 * but that's about it.
595 */
596static void
597schedclock(systimer_t info, struct intrframe *frame)
598{
599 struct proc *p;
600 struct pstats *pstats;
601 struct rusage *ru;
602 struct vmspace *vm;
603 long rss;
604
605 schedulerclock(NULL); /* mpsafe */
606 if ((p = curproc) != NULL) {
607 /* Update resource usage integrals and maximums. */
608 if ((pstats = p->p_stats) != NULL &&
609 (ru = &pstats->p_ru) != NULL &&
610 (vm = p->p_vmspace) != NULL) {
611 ru->ru_ixrss += pgtok(vm->vm_tsize);
612 ru->ru_idrss += pgtok(vm->vm_dsize);
613 ru->ru_isrss += pgtok(vm->vm_ssize);
614 rss = pgtok(vmspace_resident_count(vm));
615 if (ru->ru_maxrss < rss)
616 ru->ru_maxrss = rss;
617 }
b68b7282 618 }
984263bc
MD
619}
620
621/*
a94976ad
MD
622 * Compute number of ticks for the specified amount of time. The
623 * return value is intended to be used in a clock interrupt timed
624 * operation and guarenteed to meet or exceed the requested time.
625 * If the representation overflows, return INT_MAX. The minimum return
626 * value is 1 ticks and the function will average the calculation up.
627 * If any value greater then 0 microseconds is supplied, a value
628 * of at least 2 will be returned to ensure that a near-term clock
629 * interrupt does not cause the timeout to occur (degenerately) early.
630 *
631 * Note that limit checks must take into account microseconds, which is
632 * done simply by using the smaller signed long maximum instead of
633 * the unsigned long maximum.
634 *
635 * If ints have 32 bits, then the maximum value for any timeout in
636 * 10ms ticks is 248 days.
984263bc
MD
637 */
638int
a94976ad 639tvtohz_high(struct timeval *tv)
984263bc 640{
a94976ad 641 int ticks;
1fd87d54 642 long sec, usec;
984263bc 643
984263bc
MD
644 sec = tv->tv_sec;
645 usec = tv->tv_usec;
646 if (usec < 0) {
647 sec--;
648 usec += 1000000;
649 }
650 if (sec < 0) {
651#ifdef DIAGNOSTIC
652 if (usec > 0) {
653 sec++;
654 usec -= 1000000;
655 }
656 printf("tvotohz: negative time difference %ld sec %ld usec\n",
657 sec, usec);
658#endif
659 ticks = 1;
a94976ad
MD
660 } else if (sec <= INT_MAX / hz) {
661 ticks = (int)(sec * hz +
662 ((u_long)usec + (tick - 1)) / tick) + 1;
663 } else {
664 ticks = INT_MAX;
665 }
666 return (ticks);
667}
668
669/*
670 * Compute number of ticks for the specified amount of time, erroring on
671 * the side of it being too low to ensure that sleeping the returned number
672 * of ticks will not result in a late return.
673 *
674 * The supplied timeval may not be negative and should be normalized. A
675 * return value of 0 is possible if the timeval converts to less then
676 * 1 tick.
677 *
678 * If ints have 32 bits, then the maximum value for any timeout in
679 * 10ms ticks is 248 days.
680 */
681int
682tvtohz_low(struct timeval *tv)
683{
684 int ticks;
685 long sec;
686
687 sec = tv->tv_sec;
688 if (sec <= INT_MAX / hz)
689 ticks = (int)(sec * hz + (u_long)tv->tv_usec / tick);
984263bc 690 else
984263bc 691 ticks = INT_MAX;
a94976ad 692 return (ticks);
984263bc
MD
693}
694
a94976ad 695
984263bc
MD
696/*
697 * Start profiling on a process.
698 *
699 * Kernel profiling passes proc0 which never exits and hence
700 * keeps the profile clock running constantly.
701 */
702void
88c4d2f6 703startprofclock(struct proc *p)
984263bc 704{
984263bc
MD
705 if ((p->p_flag & P_PROFIL) == 0) {
706 p->p_flag |= P_PROFIL;
88c4d2f6 707#if 0 /* XXX */
984263bc
MD
708 if (++profprocs == 1 && stathz != 0) {
709 s = splstatclock();
6ad39cae 710 psdiv = psratio;
984263bc
MD
711 setstatclockrate(profhz);
712 splx(s);
713 }
88c4d2f6 714#endif
984263bc
MD
715 }
716}
717
718/*
719 * Stop profiling on a process.
720 */
721void
88c4d2f6 722stopprofclock(struct proc *p)
984263bc 723{
984263bc
MD
724 if (p->p_flag & P_PROFIL) {
725 p->p_flag &= ~P_PROFIL;
88c4d2f6 726#if 0 /* XXX */
984263bc
MD
727 if (--profprocs == 0 && stathz != 0) {
728 s = splstatclock();
6ad39cae 729 psdiv = 1;
984263bc
MD
730 setstatclockrate(stathz);
731 splx(s);
732 }
984263bc 733#endif
984263bc
MD
734 }
735}
736
737/*
738 * Return information about system clocks.
739 */
740static int
741sysctl_kern_clockrate(SYSCTL_HANDLER_ARGS)
742{
f5d21610 743 struct kinfo_clockinfo clkinfo;
984263bc
MD
744 /*
745 * Construct clockinfo structure.
746 */
f5d21610
JS
747 clkinfo.ci_hz = hz;
748 clkinfo.ci_tick = tick;
4026c000 749 clkinfo.ci_tickadj = ntp_default_tick_delta / 1000;
f5d21610
JS
750 clkinfo.ci_profhz = profhz;
751 clkinfo.ci_stathz = stathz ? stathz : hz;
984263bc
MD
752 return (sysctl_handle_opaque(oidp, &clkinfo, sizeof clkinfo, req));
753}
754
755SYSCTL_PROC(_kern, KERN_CLOCKRATE, clockrate, CTLTYPE_STRUCT|CTLFLAG_RD,
756 0, 0, sysctl_kern_clockrate, "S,clockinfo","");
757
984263bc
MD
758/*
759 * We have eight functions for looking at the clock, four for
760 * microseconds and four for nanoseconds. For each there is fast
761 * but less precise version "get{nano|micro}[up]time" which will
762 * return a time which is up to 1/HZ previous to the call, whereas
763 * the raw version "{nano|micro}[up]time" will return a timestamp
764 * which is as precise as possible. The "up" variants return the
765 * time relative to system boot, these are well suited for time
766 * interval measurements.
88c4d2f6
MD
767 *
768 * Each cpu independantly maintains the current time of day, so all
769 * we need to do to protect ourselves from changes is to do a loop
770 * check on the seconds field changing out from under us.
fad57d0e
MD
771 *
772 * The system timer maintains a 32 bit count and due to various issues
773 * it is possible for the calculated delta to occassionally exceed
774 * cputimer_freq. If this occurs the cputimer_freq64_nsec multiplication
775 * can easily overflow, so we deal with the case. For uniformity we deal
776 * with the case in the usec case too.
984263bc 777 */
984263bc
MD
778void
779getmicrouptime(struct timeval *tvp)
780{
88c4d2f6
MD
781 struct globaldata *gd = mycpu;
782 sysclock_t delta;
783
784 do {
785 tvp->tv_sec = gd->gd_time_seconds;
786 delta = gd->gd_hardclock.time - gd->gd_cpuclock_base;
787 } while (tvp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
788
789 if (delta >= cputimer_freq) {
790 tvp->tv_sec += delta / cputimer_freq;
791 delta %= cputimer_freq;
792 }
88c4d2f6
MD
793 tvp->tv_usec = (cputimer_freq64_usec * delta) >> 32;
794 if (tvp->tv_usec >= 1000000) {
795 tvp->tv_usec -= 1000000;
796 ++tvp->tv_sec;
984263bc
MD
797 }
798}
799
800void
801getnanouptime(struct timespec *tsp)
802{
88c4d2f6
MD
803 struct globaldata *gd = mycpu;
804 sysclock_t delta;
805
806 do {
807 tsp->tv_sec = gd->gd_time_seconds;
808 delta = gd->gd_hardclock.time - gd->gd_cpuclock_base;
809 } while (tsp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
810
811 if (delta >= cputimer_freq) {
812 tsp->tv_sec += delta / cputimer_freq;
813 delta %= cputimer_freq;
984263bc 814 }
fad57d0e 815 tsp->tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
984263bc
MD
816}
817
818void
88c4d2f6 819microuptime(struct timeval *tvp)
984263bc 820{
88c4d2f6
MD
821 struct globaldata *gd = mycpu;
822 sysclock_t delta;
823
824 do {
825 tvp->tv_sec = gd->gd_time_seconds;
826 delta = cputimer_count() - gd->gd_cpuclock_base;
827 } while (tvp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
828
829 if (delta >= cputimer_freq) {
830 tvp->tv_sec += delta / cputimer_freq;
831 delta %= cputimer_freq;
984263bc 832 }
fad57d0e 833 tvp->tv_usec = (cputimer_freq64_usec * delta) >> 32;
984263bc
MD
834}
835
836void
88c4d2f6 837nanouptime(struct timespec *tsp)
984263bc 838{
88c4d2f6
MD
839 struct globaldata *gd = mycpu;
840 sysclock_t delta;
841
842 do {
843 tsp->tv_sec = gd->gd_time_seconds;
844 delta = cputimer_count() - gd->gd_cpuclock_base;
845 } while (tsp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
846
847 if (delta >= cputimer_freq) {
848 tsp->tv_sec += delta / cputimer_freq;
849 delta %= cputimer_freq;
984263bc 850 }
fad57d0e 851 tsp->tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
984263bc
MD
852}
853
88c4d2f6
MD
854/*
855 * realtime routines
856 */
984263bc
MD
857
858void
88c4d2f6 859getmicrotime(struct timeval *tvp)
984263bc 860{
88c4d2f6 861 struct globaldata *gd = mycpu;
5eb5a6bc 862 struct timespec *bt;
88c4d2f6 863 sysclock_t delta;
984263bc 864
88c4d2f6
MD
865 do {
866 tvp->tv_sec = gd->gd_time_seconds;
867 delta = gd->gd_hardclock.time - gd->gd_cpuclock_base;
868 } while (tvp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
869
870 if (delta >= cputimer_freq) {
871 tvp->tv_sec += delta / cputimer_freq;
872 delta %= cputimer_freq;
873 }
88c4d2f6 874 tvp->tv_usec = (cputimer_freq64_usec * delta) >> 32;
984263bc 875
5eb5a6bc
MD
876 bt = &basetime[basetime_index];
877 tvp->tv_sec += bt->tv_sec;
878 tvp->tv_usec += bt->tv_nsec / 1000;
88c4d2f6
MD
879 while (tvp->tv_usec >= 1000000) {
880 tvp->tv_usec -= 1000000;
881 ++tvp->tv_sec;
984263bc 882 }
984263bc
MD
883}
884
885void
88c4d2f6 886getnanotime(struct timespec *tsp)
984263bc 887{
88c4d2f6 888 struct globaldata *gd = mycpu;
5eb5a6bc 889 struct timespec *bt;
88c4d2f6 890 sysclock_t delta;
984263bc 891
88c4d2f6
MD
892 do {
893 tsp->tv_sec = gd->gd_time_seconds;
894 delta = gd->gd_hardclock.time - gd->gd_cpuclock_base;
895 } while (tsp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
896
897 if (delta >= cputimer_freq) {
898 tsp->tv_sec += delta / cputimer_freq;
899 delta %= cputimer_freq;
900 }
88c4d2f6 901 tsp->tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
984263bc 902
5eb5a6bc
MD
903 bt = &basetime[basetime_index];
904 tsp->tv_sec += bt->tv_sec;
905 tsp->tv_nsec += bt->tv_nsec;
88c4d2f6
MD
906 while (tsp->tv_nsec >= 1000000000) {
907 tsp->tv_nsec -= 1000000000;
908 ++tsp->tv_sec;
984263bc 909 }
984263bc
MD
910}
911
5eb5a6bc
MD
912static void
913getnanotime_nbt(struct timespec *nbt, struct timespec *tsp)
914{
915 struct globaldata *gd = mycpu;
916 sysclock_t delta;
917
918 do {
919 tsp->tv_sec = gd->gd_time_seconds;
920 delta = gd->gd_hardclock.time - gd->gd_cpuclock_base;
921 } while (tsp->tv_sec != gd->gd_time_seconds);
922
923 if (delta >= cputimer_freq) {
924 tsp->tv_sec += delta / cputimer_freq;
925 delta %= cputimer_freq;
926 }
927 tsp->tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
928
929 tsp->tv_sec += nbt->tv_sec;
930 tsp->tv_nsec += nbt->tv_nsec;
931 while (tsp->tv_nsec >= 1000000000) {
932 tsp->tv_nsec -= 1000000000;
933 ++tsp->tv_sec;
934 }
935}
936
937
88c4d2f6
MD
938void
939microtime(struct timeval *tvp)
984263bc 940{
88c4d2f6 941 struct globaldata *gd = mycpu;
5eb5a6bc 942 struct timespec *bt;
88c4d2f6 943 sysclock_t delta;
984263bc 944
88c4d2f6
MD
945 do {
946 tvp->tv_sec = gd->gd_time_seconds;
947 delta = cputimer_count() - gd->gd_cpuclock_base;
948 } while (tvp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
949
950 if (delta >= cputimer_freq) {
951 tvp->tv_sec += delta / cputimer_freq;
952 delta %= cputimer_freq;
953 }
88c4d2f6 954 tvp->tv_usec = (cputimer_freq64_usec * delta) >> 32;
984263bc 955
5eb5a6bc
MD
956 bt = &basetime[basetime_index];
957 tvp->tv_sec += bt->tv_sec;
958 tvp->tv_usec += bt->tv_nsec / 1000;
88c4d2f6
MD
959 while (tvp->tv_usec >= 1000000) {
960 tvp->tv_usec -= 1000000;
961 ++tvp->tv_sec;
984263bc 962 }
984263bc
MD
963}
964
88c4d2f6
MD
965void
966nanotime(struct timespec *tsp)
967{
968 struct globaldata *gd = mycpu;
5eb5a6bc 969 struct timespec *bt;
88c4d2f6 970 sysclock_t delta;
984263bc 971
88c4d2f6
MD
972 do {
973 tsp->tv_sec = gd->gd_time_seconds;
974 delta = cputimer_count() - gd->gd_cpuclock_base;
975 } while (tsp->tv_sec != gd->gd_time_seconds);
fad57d0e
MD
976
977 if (delta >= cputimer_freq) {
978 tsp->tv_sec += delta / cputimer_freq;
979 delta %= cputimer_freq;
980 }
88c4d2f6 981 tsp->tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
984263bc 982
5eb5a6bc
MD
983 bt = &basetime[basetime_index];
984 tsp->tv_sec += bt->tv_sec;
985 tsp->tv_nsec += bt->tv_nsec;
88c4d2f6
MD
986 while (tsp->tv_nsec >= 1000000000) {
987 tsp->tv_nsec -= 1000000000;
988 ++tsp->tv_sec;
984263bc 989 }
984263bc
MD
990}
991
25b804e7
MD
992/*
993 * note: this is not exactly synchronized with real time. To do that we
994 * would have to do what microtime does and check for a nanoseconds overflow.
995 */
996time_t
997get_approximate_time_t(void)
998{
999 struct globaldata *gd = mycpu;
5eb5a6bc
MD
1000 struct timespec *bt;
1001
1002 bt = &basetime[basetime_index];
1003 return(gd->gd_time_seconds + bt->tv_sec);
25b804e7
MD
1004}
1005
984263bc
MD
1006int
1007pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps)
1008{
1009 pps_params_t *app;
1010 struct pps_fetch_args *fapi;
1011#ifdef PPS_SYNC
1012 struct pps_kcbind_args *kapi;
1013#endif
1014
1015 switch (cmd) {
1016 case PPS_IOC_CREATE:
1017 return (0);
1018 case PPS_IOC_DESTROY:
1019 return (0);
1020 case PPS_IOC_SETPARAMS:
1021 app = (pps_params_t *)data;
1022 if (app->mode & ~pps->ppscap)
1023 return (EINVAL);
1024 pps->ppsparam = *app;
1025 return (0);
1026 case PPS_IOC_GETPARAMS:
1027 app = (pps_params_t *)data;
1028 *app = pps->ppsparam;
1029 app->api_version = PPS_API_VERS_1;
1030 return (0);
1031 case PPS_IOC_GETCAP:
1032 *(int*)data = pps->ppscap;
1033 return (0);
1034 case PPS_IOC_FETCH:
1035 fapi = (struct pps_fetch_args *)data;
1036 if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)
1037 return (EINVAL);
1038 if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec)
1039 return (EOPNOTSUPP);
1040 pps->ppsinfo.current_mode = pps->ppsparam.mode;
1041 fapi->pps_info_buf = pps->ppsinfo;
1042 return (0);
1043 case PPS_IOC_KCBIND:
1044#ifdef PPS_SYNC
1045 kapi = (struct pps_kcbind_args *)data;
1046 /* XXX Only root should be able to do this */
1047 if (kapi->tsformat && kapi->tsformat != PPS_TSFMT_TSPEC)
1048 return (EINVAL);
1049 if (kapi->kernel_consumer != PPS_KC_HARDPPS)
1050 return (EINVAL);
1051 if (kapi->edge & ~pps->ppscap)
1052 return (EINVAL);
1053 pps->kcmode = kapi->edge;
1054 return (0);
1055#else
1056 return (EOPNOTSUPP);
1057#endif
1058 default:
1059 return (ENOTTY);
1060 }
1061}
1062
1063void
1064pps_init(struct pps_state *pps)
1065{
1066 pps->ppscap |= PPS_TSFMT_TSPEC;
1067 if (pps->ppscap & PPS_CAPTUREASSERT)
1068 pps->ppscap |= PPS_OFFSETASSERT;
1069 if (pps->ppscap & PPS_CAPTURECLEAR)
1070 pps->ppscap |= PPS_OFFSETCLEAR;
1071}
1072
1073void
88c4d2f6 1074pps_event(struct pps_state *pps, sysclock_t count, int event)
984263bc 1075{
88c4d2f6
MD
1076 struct globaldata *gd;
1077 struct timespec *tsp;
1078 struct timespec *osp;
5eb5a6bc 1079 struct timespec *bt;
88c4d2f6
MD
1080 struct timespec ts;
1081 sysclock_t *pcount;
1082#ifdef PPS_SYNC
1083 sysclock_t tcount;
1084#endif
1085 sysclock_t delta;
1086 pps_seq_t *pseq;
1087 int foff;
1088 int fhard;
1089
1090 gd = mycpu;
984263bc
MD
1091
1092 /* Things would be easier with arrays... */
1093 if (event == PPS_CAPTUREASSERT) {
1094 tsp = &pps->ppsinfo.assert_timestamp;
1095 osp = &pps->ppsparam.assert_offset;
1096 foff = pps->ppsparam.mode & PPS_OFFSETASSERT;
1097 fhard = pps->kcmode & PPS_CAPTUREASSERT;
1098 pcount = &pps->ppscount[0];
1099 pseq = &pps->ppsinfo.assert_sequence;
1100 } else {
1101 tsp = &pps->ppsinfo.clear_timestamp;
1102 osp = &pps->ppsparam.clear_offset;
1103 foff = pps->ppsparam.mode & PPS_OFFSETCLEAR;
1104 fhard = pps->kcmode & PPS_CAPTURECLEAR;
1105 pcount = &pps->ppscount[1];
1106 pseq = &pps->ppsinfo.clear_sequence;
1107 }
1108
984263bc
MD
1109 /* Nothing really happened */
1110 if (*pcount == count)
1111 return;
1112
1113 *pcount = count;
1114
88c4d2f6
MD
1115 do {
1116 ts.tv_sec = gd->gd_time_seconds;
1117 delta = count - gd->gd_cpuclock_base;
1118 } while (ts.tv_sec != gd->gd_time_seconds);
fad57d0e
MD
1119
1120 if (delta >= cputimer_freq) {
88c4d2f6
MD
1121 ts.tv_sec += delta / cputimer_freq;
1122 delta %= cputimer_freq;
1123 }
1124 ts.tv_nsec = (cputimer_freq64_nsec * delta) >> 32;
5eb5a6bc
MD
1125 bt = &basetime[basetime_index];
1126 ts.tv_sec += bt->tv_sec;
1127 ts.tv_nsec += bt->tv_nsec;
88c4d2f6
MD
1128 while (ts.tv_nsec >= 1000000000) {
1129 ts.tv_nsec -= 1000000000;
1130 ++ts.tv_sec;
984263bc 1131 }
984263bc
MD
1132
1133 (*pseq)++;
1134 *tsp = ts;
1135
1136 if (foff) {
1137 timespecadd(tsp, osp);
1138 if (tsp->tv_nsec < 0) {
1139 tsp->tv_nsec += 1000000000;
1140 tsp->tv_sec -= 1;
1141 }
1142 }
1143#ifdef PPS_SYNC
1144 if (fhard) {
1145 /* magic, at its best... */
1146 tcount = count - pps->ppscount[2];
1147 pps->ppscount[2] = count;
fad57d0e 1148 if (tcount >= cputimer_freq) {
64642171
JS
1149 delta = (1000000000 * (tcount / cputimer_freq) +
1150 cputimer_freq64_nsec *
fad57d0e
MD
1151 (tcount % cputimer_freq)) >> 32;
1152 } else {
1153 delta = (cputimer_freq64_nsec * tcount) >> 32;
1154 }
984263bc
MD
1155 hardpps(tsp, delta);
1156 }
1157#endif
1158}
88c4d2f6 1159