2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)kern_time.c 8.1 (Berkeley) 6/10/93
34 * $FreeBSD: src/sys/kern/kern_time.c,v 1.68.2.1 2002/10/01 08:00:41 bde Exp $
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/sysproto.h>
41 #include <sys/resourcevar.h>
42 #include <sys/signalvar.h>
43 #include <sys/kernel.h>
44 #include <sys/sysent.h>
45 #include <sys/sysunion.h>
49 #include <sys/vnode.h>
50 #include <sys/sysctl.h>
51 #include <sys/kern_syscall.h>
53 #include <vm/vm_extern.h>
55 #include <sys/msgport2.h>
56 #include <sys/thread2.h>
57 #include <sys/mplock2.h>
62 * Time of day and interval timer support.
64 * These routines provide the kernel entry points to get and set
65 * the time-of-day and per-process interval timers. Subroutines
66 * here provide support for adding and subtracting timeval structures
67 * and decrementing interval timers, optionally reloading the interval
68 * timers when they expire.
71 static int settime(struct timeval *);
72 static void timevalfix(struct timeval *);
75 * Nanosleep tries very hard to sleep for a precisely requested time
76 * interval, down to 1uS. The administrator can impose a minimum delay
77 * and a delay below which we hard-loop instead of initiate a timer
78 * interrupt and sleep.
80 * For machines under high loads it might be beneficial to increase min_us
81 * to e.g. 1000uS (1ms) so spining processes sleep meaningfully.
83 static int nanosleep_min_us = 10;
84 static int nanosleep_hard_us = 100;
85 SYSCTL_INT(_kern, OID_AUTO, nanosleep_min_us, CTLFLAG_RW,
86 &nanosleep_min_us, 0, "")
87 SYSCTL_INT(_kern, OID_AUTO, nanosleep_hard_us, CTLFLAG_RW,
88 &nanosleep_hard_us, 0, "")
91 settime(struct timeval *tv)
93 struct timeval delta, tv1, tv2;
94 static struct timeval maxtime, laststep;
98 if ((origcpu = mycpu->gd_cpuid) != 0)
99 lwkt_setcpu_self(globaldata_find(0));
104 timevalsub(&delta, &tv1);
107 * If the system is secure, we do not allow the time to be
108 * set to a value earlier than 1 second less than the highest
109 * time we have yet seen. The worst a miscreant can do in
110 * this circumstance is "freeze" time. He couldn't go
113 * We similarly do not allow the clock to be stepped more
114 * than one second, nor more than once per second. This allows
115 * a miscreant to make the clock march double-time, but no worse.
117 if (securelevel > 1) {
118 if (delta.tv_sec < 0 || delta.tv_usec < 0) {
120 * Update maxtime to latest time we've seen.
122 if (tv1.tv_sec > maxtime.tv_sec)
125 timevalsub(&tv2, &maxtime);
126 if (tv2.tv_sec < -1) {
127 tv->tv_sec = maxtime.tv_sec - 1;
128 kprintf("Time adjustment clamped to -1 second\n");
131 if (tv1.tv_sec == laststep.tv_sec) {
135 if (delta.tv_sec > 1) {
136 tv->tv_sec = tv1.tv_sec + 1;
137 kprintf("Time adjustment clamped to +1 second\n");
143 ts.tv_sec = tv->tv_sec;
144 ts.tv_nsec = tv->tv_usec * 1000;
149 lwkt_setcpu_self(globaldata_find(origcpu));
159 kern_clock_gettime(clockid_t clock_id, struct timespec *ats)
167 case CLOCK_MONOTONIC:
181 sys_clock_gettime(struct clock_gettime_args *uap)
186 error = kern_clock_gettime(uap->clock_id, &ats);
188 error = copyout(&ats, uap->tp, sizeof(ats));
194 kern_clock_settime(clockid_t clock_id, struct timespec *ats)
196 struct thread *td = curthread;
200 if ((error = priv_check(td, PRIV_CLOCK_SETTIME)) != 0)
202 if (clock_id != CLOCK_REALTIME)
204 if (ats->tv_nsec < 0 || ats->tv_nsec >= 1000000000)
207 TIMESPEC_TO_TIMEVAL(&atv, ats);
208 error = settime(&atv);
216 sys_clock_settime(struct clock_settime_args *uap)
221 if ((error = copyin(uap->tp, &ats, sizeof(ats))) != 0)
225 error = kern_clock_settime(uap->clock_id, &ats);
234 kern_clock_getres(clockid_t clock_id, struct timespec *ts)
240 case CLOCK_MONOTONIC:
242 * Round up the result of the division cheaply
243 * by adding 1. Rounding up is especially important
244 * if rounding down would give 0. Perfect rounding
248 ts->tv_nsec = 1000000000 / sys_cputimer->freq + 1;
263 sys_clock_getres(struct clock_getres_args *uap)
268 error = kern_clock_getres(uap->clock_id, &ts);
270 error = copyout(&ts, uap->tp, sizeof(ts));
278 * This is a general helper function for nanosleep() (aka sleep() aka
281 * If there is less then one tick's worth of time left and
282 * we haven't done a yield, or the remaining microseconds is
283 * ridiculously low, do a yield. This avoids having
284 * to deal with systimer overheads when the system is under
285 * heavy loads. If we have done a yield already then use
286 * a systimer and an uninterruptable thread wait.
288 * If there is more then a tick's worth of time left,
289 * calculate the baseline ticks and use an interruptable
290 * tsleep, then handle the fine-grained delay on the next
291 * loop. This usually results in two sleeps occuring, a long one
297 ns1_systimer(systimer_t info, int in_ipi __unused,
298 struct intrframe *frame __unused)
300 lwkt_schedule(info->data);
304 nanosleep1(struct timespec *rqt, struct timespec *rmt)
307 struct timespec ts, ts2, ts3;
311 if (rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000)
313 /* XXX: imho this should return EINVAL at least for tv_sec < 0 */
314 if (rqt->tv_sec < 0 || (rqt->tv_sec == 0 && rqt->tv_nsec == 0))
317 timespecadd(&ts, rqt); /* ts = target timestamp compare */
318 TIMESPEC_TO_TIMEVAL(&tv, rqt); /* tv = sleep interval */
322 struct systimer info;
324 ticks = tv.tv_usec / ustick; /* approximate */
326 if (tv.tv_sec == 0 && ticks == 0) {
327 thread_t td = curthread;
328 if (tv.tv_usec > 0 && tv.tv_usec < nanosleep_min_us)
329 tv.tv_usec = nanosleep_min_us;
330 if (tv.tv_usec < nanosleep_hard_us) {
334 crit_enter_quick(td);
335 systimer_init_oneshot(&info, ns1_systimer,
337 lwkt_deschedule_self(td);
340 systimer_del(&info); /* make sure it's gone */
342 error = iscaught(td->td_lwp);
343 } else if (tv.tv_sec == 0) {
344 error = tsleep(&nanowait, PCATCH, "nanslp", ticks);
346 ticks = tvtohz_low(&tv); /* also handles overflow */
347 error = tsleep(&nanowait, PCATCH, "nanslp", ticks);
350 if (error && error != EWOULDBLOCK) {
351 if (error == ERESTART)
354 timespecsub(&ts, &ts2);
361 if (timespeccmp(&ts2, &ts, >=))
364 timespecsub(&ts3, &ts2);
365 TIMESPEC_TO_TIMEVAL(&tv, &ts3);
373 sys_nanosleep(struct nanosleep_args *uap)
379 error = copyin(uap->rqtp, &rqt, sizeof(rqt));
383 error = nanosleep1(&rqt, &rmt);
386 * copyout the residual if nanosleep was interrupted.
388 if (error && uap->rmtp) {
391 error2 = copyout(&rmt, uap->rmtp, sizeof(rmt));
402 sys_gettimeofday(struct gettimeofday_args *uap)
409 if ((error = copyout((caddr_t)&atv, (caddr_t)uap->tp,
414 error = copyout((caddr_t)&tz, (caddr_t)uap->tzp,
423 sys_settimeofday(struct settimeofday_args *uap)
425 struct thread *td = curthread;
430 if ((error = priv_check(td, PRIV_SETTIMEOFDAY)))
433 * Verify all parameters before changing time.
435 * NOTE: We do not allow the time to be set to 0.0, which also by
436 * happy coincidence works around a pkgsrc bulk build bug.
439 if ((error = copyin((caddr_t)uap->tv, (caddr_t)&atv,
442 if (atv.tv_usec < 0 || atv.tv_usec >= 1000000)
444 if (atv.tv_sec == 0 && atv.tv_usec == 0)
448 (error = copyin((caddr_t)uap->tzp, (caddr_t)&atz, sizeof(atz))))
452 if (uap->tv && (error = settime(&atv))) {
463 kern_adjtime_common(void)
465 if ((ntp_delta >= 0 && ntp_delta < ntp_default_tick_delta) ||
466 (ntp_delta < 0 && ntp_delta > -ntp_default_tick_delta))
467 ntp_tick_delta = ntp_delta;
468 else if (ntp_delta > ntp_big_delta)
469 ntp_tick_delta = 10 * ntp_default_tick_delta;
470 else if (ntp_delta < -ntp_big_delta)
471 ntp_tick_delta = -10 * ntp_default_tick_delta;
472 else if (ntp_delta > 0)
473 ntp_tick_delta = ntp_default_tick_delta;
475 ntp_tick_delta = -ntp_default_tick_delta;
479 kern_adjtime(int64_t delta, int64_t *odelta)
483 if ((origcpu = mycpu->gd_cpuid) != 0)
484 lwkt_setcpu_self(globaldata_find(0));
489 kern_adjtime_common();
493 lwkt_setcpu_self(globaldata_find(origcpu));
497 kern_get_ntp_delta(int64_t *delta)
501 if ((origcpu = mycpu->gd_cpuid) != 0)
502 lwkt_setcpu_self(globaldata_find(0));
509 lwkt_setcpu_self(globaldata_find(origcpu));
513 kern_reladjtime(int64_t delta)
517 if ((origcpu = mycpu->gd_cpuid) != 0)
518 lwkt_setcpu_self(globaldata_find(0));
522 kern_adjtime_common();
526 lwkt_setcpu_self(globaldata_find(origcpu));
530 kern_adjfreq(int64_t rate)
534 if ((origcpu = mycpu->gd_cpuid) != 0)
535 lwkt_setcpu_self(globaldata_find(0));
538 ntp_tick_permanent = rate;
542 lwkt_setcpu_self(globaldata_find(origcpu));
549 sys_adjtime(struct adjtime_args *uap)
551 struct thread *td = curthread;
553 int64_t ndelta, odelta;
556 if ((error = priv_check(td, PRIV_ADJTIME)))
558 error = copyin(uap->delta, &atv, sizeof(struct timeval));
563 * Compute the total correction and the rate at which to apply it.
564 * Round the adjustment down to a whole multiple of the per-tick
565 * delta, so that after some number of incremental changes in
566 * hardclock(), tickdelta will become zero, lest the correction
567 * overshoot and start taking us away from the desired final time.
569 ndelta = (int64_t)atv.tv_sec * 1000000000 + atv.tv_usec * 1000;
571 kern_adjtime(ndelta, &odelta);
575 atv.tv_sec = odelta / 1000000000;
576 atv.tv_usec = odelta % 1000000000 / 1000;
577 copyout(&atv, uap->olddelta, sizeof(struct timeval));
583 sysctl_adjtime(SYSCTL_HANDLER_ARGS)
588 if (req->newptr != NULL) {
589 if (priv_check(curthread, PRIV_ROOT))
591 error = SYSCTL_IN(req, &delta, sizeof(delta));
594 kern_reladjtime(delta);
598 kern_get_ntp_delta(&delta);
599 error = SYSCTL_OUT(req, &delta, sizeof(delta));
604 * delta is in nanoseconds.
607 sysctl_delta(SYSCTL_HANDLER_ARGS)
609 int64_t delta, old_delta;
612 if (req->newptr != NULL) {
613 if (priv_check(curthread, PRIV_ROOT))
615 error = SYSCTL_IN(req, &delta, sizeof(delta));
618 kern_adjtime(delta, &old_delta);
621 if (req->oldptr != NULL)
622 kern_get_ntp_delta(&old_delta);
623 error = SYSCTL_OUT(req, &old_delta, sizeof(old_delta));
628 * frequency is in nanoseconds per second shifted left 32.
629 * kern_adjfreq() needs it in nanoseconds per tick shifted left 32.
632 sysctl_adjfreq(SYSCTL_HANDLER_ARGS)
637 if (req->newptr != NULL) {
638 if (priv_check(curthread, PRIV_ROOT))
640 error = SYSCTL_IN(req, &freqdelta, sizeof(freqdelta));
645 kern_adjfreq(freqdelta);
648 if (req->oldptr != NULL)
649 freqdelta = ntp_tick_permanent * hz;
650 error = SYSCTL_OUT(req, &freqdelta, sizeof(freqdelta));
657 SYSCTL_NODE(_kern, OID_AUTO, ntp, CTLFLAG_RW, 0, "NTP related controls");
658 SYSCTL_PROC(_kern_ntp, OID_AUTO, permanent,
659 CTLTYPE_QUAD|CTLFLAG_RW, 0, 0,
660 sysctl_adjfreq, "Q", "permanent correction per second");
661 SYSCTL_PROC(_kern_ntp, OID_AUTO, delta,
662 CTLTYPE_QUAD|CTLFLAG_RW, 0, 0,
663 sysctl_delta, "Q", "one-time delta");
664 SYSCTL_OPAQUE(_kern_ntp, OID_AUTO, big_delta, CTLFLAG_RD,
665 &ntp_big_delta, sizeof(ntp_big_delta), "Q",
666 "threshold for fast adjustment");
667 SYSCTL_OPAQUE(_kern_ntp, OID_AUTO, tick_delta, CTLFLAG_RD,
668 &ntp_tick_delta, sizeof(ntp_tick_delta), "LU",
669 "per-tick adjustment");
670 SYSCTL_OPAQUE(_kern_ntp, OID_AUTO, default_tick_delta, CTLFLAG_RD,
671 &ntp_default_tick_delta, sizeof(ntp_default_tick_delta), "LU",
672 "default per-tick adjustment");
673 SYSCTL_OPAQUE(_kern_ntp, OID_AUTO, next_leap_second, CTLFLAG_RW,
674 &ntp_leap_second, sizeof(ntp_leap_second), "LU",
676 SYSCTL_INT(_kern_ntp, OID_AUTO, insert_leap_second, CTLFLAG_RW,
677 &ntp_leap_insert, 0, "insert or remove leap second");
678 SYSCTL_PROC(_kern_ntp, OID_AUTO, adjust,
679 CTLTYPE_QUAD|CTLFLAG_RW, 0, 0,
680 sysctl_adjtime, "Q", "relative adjust for delta");
683 * Get value of an interval timer. The process virtual and
684 * profiling virtual time timers are kept in the p_stats area, since
685 * they can be swapped out. These are kept internally in the
686 * way they are specified externally: in time until they expire.
688 * The real time interval timer is kept in the process table slot
689 * for the process, and its value (it_value) is kept as an
690 * absolute time rather than as a delta, so that it is easy to keep
691 * periodic real-time signals from drifting.
693 * Virtual time timers are processed in the hardclock() routine of
694 * kern_clock.c. The real time timer is processed by a timeout
695 * routine, called from the softclock() routine. Since a callout
696 * may be delayed in real time due to interrupt processing in the system,
697 * it is possible for the real time timeout routine (realitexpire, given below),
698 * to be delayed in real time past when it is supposed to occur. It
699 * does not suffice, therefore, to reload the real timer .it_value from the
700 * real time timers .it_interval. Rather, we compute the next time in
701 * absolute time the timer should go off.
706 sys_getitimer(struct getitimer_args *uap)
708 struct proc *p = curproc;
710 struct itimerval aitv;
712 if (uap->which > ITIMER_PROF)
714 lwkt_gettoken(&p->p_token);
715 if (uap->which == ITIMER_REAL) {
717 * Convert from absolute to relative time in .it_value
718 * part of real time timer. If time for real time timer
719 * has passed return 0, else return difference between
720 * current time and time for the timer to go off.
722 aitv = p->p_realtimer;
723 if (timevalisset(&aitv.it_value)) {
724 getmicrouptime(&ctv);
725 if (timevalcmp(&aitv.it_value, &ctv, <))
726 timevalclear(&aitv.it_value);
728 timevalsub(&aitv.it_value, &ctv);
731 aitv = p->p_timer[uap->which];
733 lwkt_reltoken(&p->p_token);
734 return (copyout(&aitv, uap->itv, sizeof (struct itimerval)));
741 sys_setitimer(struct setitimer_args *uap)
743 struct itimerval aitv;
745 struct itimerval *itvp;
746 struct proc *p = curproc;
749 if (uap->which > ITIMER_PROF)
752 if (itvp && (error = copyin((caddr_t)itvp, (caddr_t)&aitv,
753 sizeof(struct itimerval))))
755 if ((uap->itv = uap->oitv) &&
756 (error = sys_getitimer((struct getitimer_args *)uap)))
760 if (itimerfix(&aitv.it_value))
762 if (!timevalisset(&aitv.it_value))
763 timevalclear(&aitv.it_interval);
764 else if (itimerfix(&aitv.it_interval))
766 lwkt_gettoken(&p->p_token);
767 if (uap->which == ITIMER_REAL) {
768 if (timevalisset(&p->p_realtimer.it_value))
769 callout_stop_sync(&p->p_ithandle);
770 if (timevalisset(&aitv.it_value))
771 callout_reset(&p->p_ithandle,
772 tvtohz_high(&aitv.it_value), realitexpire, p);
773 getmicrouptime(&ctv);
774 timevaladd(&aitv.it_value, &ctv);
775 p->p_realtimer = aitv;
777 p->p_timer[uap->which] = aitv;
780 p->p_flags &= ~P_SIGVTALRM;
783 p->p_flags &= ~P_SIGPROF;
787 lwkt_reltoken(&p->p_token);
792 * Real interval timer expired:
793 * send process whose timer expired an alarm signal.
794 * If time is not set up to reload, then just return.
795 * Else compute next time timer should go off which is > current time.
796 * This is where delay in processing this timeout causes multiple
797 * SIGALRM calls to be compressed into one.
798 * tvtohz_high() always adds 1 to allow for the time until the next clock
799 * interrupt being strictly less than 1 clock tick, but we don't want
800 * that here since we want to appear to be in sync with the clock
801 * interrupt even when we're delayed.
804 realitexpire(void *arg)
807 struct timeval ctv, ntv;
809 p = (struct proc *)arg;
811 lwkt_gettoken(&p->p_token);
813 if (!timevalisset(&p->p_realtimer.it_interval)) {
814 timevalclear(&p->p_realtimer.it_value);
818 timevaladd(&p->p_realtimer.it_value,
819 &p->p_realtimer.it_interval);
820 getmicrouptime(&ctv);
821 if (timevalcmp(&p->p_realtimer.it_value, &ctv, >)) {
822 ntv = p->p_realtimer.it_value;
823 timevalsub(&ntv, &ctv);
824 callout_reset(&p->p_ithandle, tvtohz_low(&ntv),
830 lwkt_reltoken(&p->p_token);
835 * Check that a proposed value to load into the .it_value or
836 * .it_interval part of an interval timer is acceptable, and
837 * fix it to have at least minimal value (i.e. if it is less
838 * than the resolution of the clock, round it up.)
843 itimerfix(struct timeval *tv)
846 if (tv->tv_sec < 0 || tv->tv_sec > 100000000 ||
847 tv->tv_usec < 0 || tv->tv_usec >= 1000000)
849 if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < ustick)
850 tv->tv_usec = ustick;
855 * Decrement an interval timer by a specified number
856 * of microseconds, which must be less than a second,
857 * i.e. < 1000000. If the timer expires, then reload
858 * it. In this case, carry over (usec - old value) to
859 * reduce the value reloaded into the timer so that
860 * the timer does not drift. This routine assumes
861 * that it is called in a context where the timers
862 * on which it is operating cannot change in value.
865 itimerdecr(struct itimerval *itp, int usec)
868 if (itp->it_value.tv_usec < usec) {
869 if (itp->it_value.tv_sec == 0) {
870 /* expired, and already in next interval */
871 usec -= itp->it_value.tv_usec;
874 itp->it_value.tv_usec += 1000000;
875 itp->it_value.tv_sec--;
877 itp->it_value.tv_usec -= usec;
879 if (timevalisset(&itp->it_value))
881 /* expired, exactly at end of interval */
883 if (timevalisset(&itp->it_interval)) {
884 itp->it_value = itp->it_interval;
885 itp->it_value.tv_usec -= usec;
886 if (itp->it_value.tv_usec < 0) {
887 itp->it_value.tv_usec += 1000000;
888 itp->it_value.tv_sec--;
891 itp->it_value.tv_usec = 0; /* sec is already 0 */
896 * Add and subtract routines for timevals.
897 * N.B.: subtract routine doesn't deal with
898 * results which are before the beginning,
899 * it just gets very confused in this case.
903 timevaladd(struct timeval *t1, const struct timeval *t2)
906 t1->tv_sec += t2->tv_sec;
907 t1->tv_usec += t2->tv_usec;
912 timevalsub(struct timeval *t1, const struct timeval *t2)
915 t1->tv_sec -= t2->tv_sec;
916 t1->tv_usec -= t2->tv_usec;
921 timevalfix(struct timeval *t1)
924 if (t1->tv_usec < 0) {
926 t1->tv_usec += 1000000;
928 if (t1->tv_usec >= 1000000) {
930 t1->tv_usec -= 1000000;
935 * ratecheck(): simple time-based rate-limit checking.
938 ratecheck(struct timeval *lasttime, const struct timeval *mininterval)
940 struct timeval tv, delta;
943 getmicrouptime(&tv); /* NB: 10ms precision */
945 timevalsub(&delta, lasttime);
948 * check for 0,0 is so that the message will be seen at least once,
949 * even if interval is huge.
951 if (timevalcmp(&delta, mininterval, >=) ||
952 (lasttime->tv_sec == 0 && lasttime->tv_usec == 0)) {
961 * ppsratecheck(): packets (or events) per second limitation.
963 * Return 0 if the limit is to be enforced (e.g. the caller
964 * should drop a packet because of the rate limitation).
966 * maxpps of 0 always causes zero to be returned. maxpps of -1
967 * always causes 1 to be returned; this effectively defeats rate
970 * Note that we maintain the struct timeval for compatibility
971 * with other bsd systems. We reuse the storage and just monitor
972 * clock ticks for minimal overhead.
975 ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
980 * Reset the last time and counter if this is the first call
981 * or more than a second has passed since the last update of
985 if (lasttime->tv_sec == 0 || (u_int)(now - lasttime->tv_sec) >= hz) {
986 lasttime->tv_sec = now;
988 return (maxpps != 0);
990 (*curpps)++; /* NB: ignore potential overflow */
991 return (maxpps < 0 || *curpps < maxpps);