2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * From: @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_kdtrace.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/callout.h>
46 #include <sys/condvar.h>
47 #include <sys/interrupt.h>
48 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mutex.h>
55 #include <sys/sleepqueue.h>
56 #include <sys/sysctl.h>
59 SDT_PROVIDER_DEFINE(callout_execute);
60 SDT_PROBE_DEFINE(callout_execute, kernel, , callout_start, callout-start);
61 SDT_PROBE_ARGTYPE(callout_execute, kernel, , callout_start, 0,
63 SDT_PROBE_DEFINE(callout_execute, kernel, , callout_end, callout-end);
64 SDT_PROBE_ARGTYPE(callout_execute, kernel, , callout_end, 0,
68 SYSCTL_INT(_debug, OID_AUTO, to_avg_depth, CTLFLAG_RD, &avg_depth, 0,
69 "Average number of items examined per softclock call. Units = 1/1000");
70 static int avg_gcalls;
71 SYSCTL_INT(_debug, OID_AUTO, to_avg_gcalls, CTLFLAG_RD, &avg_gcalls, 0,
72 "Average number of Giant callouts made per softclock call. Units = 1/1000");
73 static int avg_lockcalls;
74 SYSCTL_INT(_debug, OID_AUTO, to_avg_lockcalls, CTLFLAG_RD, &avg_lockcalls, 0,
75 "Average number of lock callouts made per softclock call. Units = 1/1000");
76 static int avg_mpcalls;
77 SYSCTL_INT(_debug, OID_AUTO, to_avg_mpcalls, CTLFLAG_RD, &avg_mpcalls, 0,
78 "Average number of MP callouts made per softclock call. Units = 1/1000");
81 * allocate more timeout table slots when table overflows.
83 int callwheelsize, callwheelbits, callwheelmask;
86 * There is one struct callout_cpu per cpu, holding all relevant
87 * state for the callout processing thread on the individual CPU.
89 * cc_ticks is incremented once per tick in callout_cpu().
90 * It tracks the global 'ticks' but in a way that the individual
91 * threads should not worry about races in the order in which
92 * hardclock() and hardclock_cpu() run on the various CPUs.
93 * cc_softclock is advanced in callout_cpu() to point to the
94 * first entry in cc_callwheel that may need handling. In turn,
95 * a softclock() is scheduled so it can serve the various entries i
96 * such that cc_softclock <= i <= cc_ticks .
97 * XXX maybe cc_softclock and cc_ticks should be volatile ?
99 * cc_ticks is also used in callout_reset_cpu() to determine
100 * when the callout should be served.
104 struct callout *cc_callout;
105 struct callout_tailq *cc_callwheel;
106 struct callout_list cc_callfree;
107 struct callout *cc_next;
108 struct callout *cc_curr;
117 struct callout_cpu cc_cpu[MAXCPU];
118 #define CC_CPU(cpu) (&cc_cpu[(cpu)])
119 #define CC_SELF() CC_CPU(PCPU_GET(cpuid))
121 struct callout_cpu cc_cpu;
122 #define CC_CPU(cpu) &cc_cpu
123 #define CC_SELF() &cc_cpu
125 #define CC_LOCK(cc) mtx_lock_spin(&(cc)->cc_lock)
126 #define CC_UNLOCK(cc) mtx_unlock_spin(&(cc)->cc_lock)
128 static int timeout_cpu;
130 MALLOC_DEFINE(M_CALLOUT, "callout", "Callout datastructures");
134 * cc_curr - If a callout is in progress, it is curr_callout.
135 * If curr_callout is non-NULL, threads waiting in
136 * callout_drain() will be woken up as soon as the
137 * relevant callout completes.
138 * cc_cancel - Changing to 1 with both callout_lock and c_lock held
139 * guarantees that the current callout will not run.
140 * The softclock() function sets this to 0 before it
141 * drops callout_lock to acquire c_lock, and it calls
142 * the handler only if curr_cancelled is still 0 after
143 * c_lock is successfully acquired.
144 * cc_waiting - If a thread is waiting in callout_drain(), then
145 * callout_wait is nonzero. Set only when
146 * curr_callout is non-NULL.
150 * kern_timeout_callwheel_alloc() - kernel low level callwheel initialization
152 * This code is called very early in the kernel initialization sequence,
153 * and may be called more then once.
156 kern_timeout_callwheel_alloc(caddr_t v)
158 struct callout_cpu *cc;
160 timeout_cpu = PCPU_GET(cpuid);
161 cc = CC_CPU(timeout_cpu);
163 * Calculate callout wheel size
165 for (callwheelsize = 1, callwheelbits = 0;
166 callwheelsize < ncallout;
167 callwheelsize <<= 1, ++callwheelbits)
169 callwheelmask = callwheelsize - 1;
171 cc->cc_callout = (struct callout *)v;
172 v = (caddr_t)(cc->cc_callout + ncallout);
173 cc->cc_callwheel = (struct callout_tailq *)v;
174 v = (caddr_t)(cc->cc_callwheel + callwheelsize);
179 callout_cpu_init(struct callout_cpu *cc)
184 mtx_init(&cc->cc_lock, "callout", NULL, MTX_SPIN | MTX_RECURSE);
185 SLIST_INIT(&cc->cc_callfree);
186 for (i = 0; i < callwheelsize; i++) {
187 TAILQ_INIT(&cc->cc_callwheel[i]);
189 if (cc->cc_callout == NULL)
191 for (i = 0; i < ncallout; i++) {
192 c = &cc->cc_callout[i];
194 c->c_flags = CALLOUT_LOCAL_ALLOC;
195 SLIST_INSERT_HEAD(&cc->cc_callfree, c, c_links.sle);
200 * kern_timeout_callwheel_init() - initialize previously reserved callwheel
203 * This code is called just once, after the space reserved for the
204 * callout wheel has been finalized.
207 kern_timeout_callwheel_init(void)
209 callout_cpu_init(CC_CPU(timeout_cpu));
213 * Start standard softclock thread.
218 start_softclock(void *dummy)
220 struct callout_cpu *cc;
225 cc = CC_CPU(timeout_cpu);
226 if (swi_add(&clk_intr_event, "clock", softclock, cc, SWI_CLOCK,
227 INTR_MPSAFE, &softclock_ih))
228 panic("died while creating standard software ithreads");
229 cc->cc_cookie = softclock_ih;
232 if (cpu == timeout_cpu)
235 if (swi_add(NULL, "clock", softclock, cc, SWI_CLOCK,
236 INTR_MPSAFE, &cc->cc_cookie))
237 panic("died while creating standard software ithreads");
238 cc->cc_callout = NULL; /* Only cpu0 handles timeout(). */
239 cc->cc_callwheel = malloc(
240 sizeof(struct callout_tailq) * callwheelsize, M_CALLOUT,
242 callout_cpu_init(cc);
247 SYSINIT(start_softclock, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softclock, NULL);
252 struct callout_cpu *cc;
257 * Process callouts at a very low cpu priority, so we don't keep the
258 * relatively high clock interrupt priority any longer than necessary.
262 mtx_lock_spin_flags(&cc->cc_lock, MTX_QUIET);
264 for (; (cc->cc_softticks - cc->cc_ticks) <= 0; cc->cc_softticks++) {
265 bucket = cc->cc_softticks & callwheelmask;
266 if (!TAILQ_EMPTY(&cc->cc_callwheel[bucket])) {
271 mtx_unlock_spin_flags(&cc->cc_lock, MTX_QUIET);
273 * swi_sched acquires the thread lock, so we don't want to call it
274 * with cc_lock held; incorrect locking order.
277 swi_sched(cc->cc_cookie, 0);
280 static struct callout_cpu *
281 callout_lock(struct callout *c)
283 struct callout_cpu *cc;
298 * The callout mechanism is based on the work of Adam M. Costello and
299 * George Varghese, published in a technical report entitled "Redesigning
300 * the BSD Callout and Timer Facilities" and modified slightly for inclusion
301 * in FreeBSD by Justin T. Gibbs. The original work on the data structures
302 * used in this implementation was published by G. Varghese and T. Lauck in
303 * the paper "Hashed and Hierarchical Timing Wheels: Data Structures for
304 * the Efficient Implementation of a Timer Facility" in the Proceedings of
305 * the 11th ACM Annual Symposium on Operating Systems Principles,
306 * Austin, Texas Nov 1987.
310 * Software (low priority) clock interrupt.
311 * Run periodic events from timeout queue.
316 struct callout_cpu *cc;
318 struct callout_tailq *bucket;
320 int steps; /* #steps since we last allowed interrupts */
326 struct bintime bt1, bt2;
328 static uint64_t maxdt = 36893488147419102LL; /* 2 msec */
329 static timeout_t *lastfunc;
332 #ifndef MAX_SOFTCLOCK_STEPS
333 #define MAX_SOFTCLOCK_STEPS 100 /* Maximum allowed value of steps. */
334 #endif /* MAX_SOFTCLOCK_STEPS */
341 cc = (struct callout_cpu *)arg;
343 while (cc->cc_softticks - 1 != cc->cc_ticks) {
345 * cc_softticks may be modified by hard clock, so cache
346 * it while we work on a given bucket.
348 curticks = cc->cc_softticks;
350 bucket = &cc->cc_callwheel[curticks & callwheelmask];
351 c = TAILQ_FIRST(bucket);
354 if (c->c_time != curticks) {
355 c = TAILQ_NEXT(c, c_links.tqe);
357 if (steps >= MAX_SOFTCLOCK_STEPS) {
359 /* Give interrupts a chance. */
367 void (*c_func)(void *);
369 struct lock_class *class;
370 struct lock_object *c_lock;
371 int c_flags, sharedlock;
373 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
374 TAILQ_REMOVE(bucket, c, c_links.tqe);
375 class = (c->c_lock != NULL) ?
376 LOCK_CLASS(c->c_lock) : NULL;
377 sharedlock = (c->c_flags & CALLOUT_SHAREDLOCK) ?
382 c_flags = c->c_flags;
383 if (c->c_flags & CALLOUT_LOCAL_ALLOC) {
384 c->c_flags = CALLOUT_LOCAL_ALLOC;
387 (c->c_flags & ~CALLOUT_PENDING);
392 if (c_lock != NULL) {
393 class->lc_lock(c_lock, sharedlock);
395 * The callout may have been cancelled
396 * while we switched locks.
399 class->lc_unlock(c_lock);
402 /* The callout cannot be stopped now. */
405 if (c_lock == &Giant.lock_object) {
408 "callout %p func %p arg %p",
412 CTR3(KTR_CALLOUT, "callout lock"
413 " %p func %p arg %p",
419 "callout mpsafe %p func %p arg %p",
425 THREAD_NO_SLEEPING();
426 SDT_PROBE(callout_execute, kernel, ,
427 callout_start, c, 0, 0, 0, 0);
429 SDT_PROBE(callout_execute, kernel, ,
430 callout_end, c, 0, 0, 0, 0);
431 THREAD_SLEEPING_OK();
434 bintime_sub(&bt2, &bt1);
435 if (bt2.frac > maxdt) {
436 if (lastfunc != c_func ||
437 bt2.frac > maxdt * 2) {
438 bintime2timespec(&bt2, &ts2);
440 "Expensive timeout(9) function: %p(%p) %jd.%09ld s\n",
442 (intmax_t)ts2.tv_sec,
449 CTR1(KTR_CALLOUT, "callout %p finished", c);
450 if ((c_flags & CALLOUT_RETURNUNLOCKED) == 0)
451 class->lc_unlock(c_lock);
455 * If the current callout is locally
456 * allocated (from timeout(9))
457 * then put it on the freelist.
459 * Note: we need to check the cached
460 * copy of c_flags because if it was not
461 * local, then it's not safe to deref the
464 if (c_flags & CALLOUT_LOCAL_ALLOC) {
465 KASSERT(c->c_flags ==
467 ("corrupted callout"));
469 SLIST_INSERT_HEAD(&cc->cc_callfree, c,
473 if (cc->cc_waiting) {
475 * There is someone waiting
476 * for the callout to complete.
480 wakeup(&cc->cc_waiting);
488 avg_depth += (depth * 1000 - avg_depth) >> 8;
489 avg_mpcalls += (mpcalls * 1000 - avg_mpcalls) >> 8;
490 avg_lockcalls += (lockcalls * 1000 - avg_lockcalls) >> 8;
491 avg_gcalls += (gcalls * 1000 - avg_gcalls) >> 8;
498 * Execute a function after a specified length of time.
501 * Cancel previous timeout function call.
503 * callout_handle_init --
504 * Initialize a handle so that using it with untimeout is benign.
506 * See AT&T BCI Driver Reference Manual for specification. This
507 * implementation differs from that one in that although an
508 * identification value is returned from timeout, the original
509 * arguments to timeout as well as the identifier are used to
510 * identify entries for untimeout.
512 struct callout_handle
513 timeout(ftn, arg, to_ticks)
518 struct callout_cpu *cc;
520 struct callout_handle handle;
522 cc = CC_CPU(timeout_cpu);
524 /* Fill in the next free callout structure. */
525 new = SLIST_FIRST(&cc->cc_callfree);
527 /* XXX Attempt to malloc first */
528 panic("timeout table full");
529 SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
530 callout_reset(new, to_ticks, ftn, arg);
531 handle.callout = new;
538 untimeout(ftn, arg, handle)
541 struct callout_handle handle;
543 struct callout_cpu *cc;
546 * Check for a handle that was initialized
547 * by callout_handle_init, but never used
548 * for a real timeout.
550 if (handle.callout == NULL)
553 cc = callout_lock(handle.callout);
554 if (handle.callout->c_func == ftn && handle.callout->c_arg == arg)
555 callout_stop(handle.callout);
560 callout_handle_init(struct callout_handle *handle)
562 handle->callout = NULL;
566 * New interface; clients allocate their own callout structures.
568 * callout_reset() - establish or change a timeout
569 * callout_stop() - disestablish a timeout
570 * callout_init() - initialize a callout structure so that it can
571 * safely be passed to callout_reset() and callout_stop()
573 * <sys/callout.h> defines three convenience macros:
575 * callout_active() - returns truth if callout has not been stopped,
576 * drained, or deactivated since the last time the callout was
578 * callout_pending() - returns truth if callout is still waiting for timeout
579 * callout_deactivate() - marks the callout as having been serviced
582 callout_reset_on(struct callout *c, int to_ticks, void (*ftn)(void *),
585 struct callout_cpu *cc;
589 * Don't allow migration of pre-allocated callouts lest they
592 if (c->c_flags & CALLOUT_LOCAL_ALLOC)
595 cc = callout_lock(c);
596 if (cc->cc_curr == c) {
598 * We're being asked to reschedule a callout which is
599 * currently in progress. If there is a lock then we
600 * can cancel the callout if it has not really started.
602 if (c->c_lock != NULL && !cc->cc_cancel)
603 cancelled = cc->cc_cancel = 1;
604 if (cc->cc_waiting) {
606 * Someone has called callout_drain to kill this
607 * callout. Don't reschedule.
609 CTR4(KTR_CALLOUT, "%s %p func %p arg %p",
610 cancelled ? "cancelled" : "failed to cancel",
611 c, c->c_func, c->c_arg);
616 if (c->c_flags & CALLOUT_PENDING) {
617 if (cc->cc_next == c) {
618 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
620 TAILQ_REMOVE(&cc->cc_callwheel[c->c_time & callwheelmask], c,
624 c->c_flags &= ~(CALLOUT_ACTIVE | CALLOUT_PENDING);
627 * If the lock must migrate we have to check the state again as
628 * we can't hold both the new and old locks simultaneously.
630 if (c->c_cpu != cpu) {
640 c->c_flags |= (CALLOUT_ACTIVE | CALLOUT_PENDING);
642 c->c_time = cc->cc_ticks + to_ticks;
643 TAILQ_INSERT_TAIL(&cc->cc_callwheel[c->c_time & callwheelmask],
645 CTR5(KTR_CALLOUT, "%sscheduled %p func %p arg %p in %d",
646 cancelled ? "re" : "", c, c->c_func, c->c_arg, to_ticks);
653 * Common idioms that can be optimized in the future.
656 callout_schedule_on(struct callout *c, int to_ticks, int cpu)
658 return callout_reset_on(c, to_ticks, c->c_func, c->c_arg, cpu);
662 callout_schedule(struct callout *c, int to_ticks)
664 return callout_reset_on(c, to_ticks, c->c_func, c->c_arg, c->c_cpu);
668 _callout_stop_safe(c, safe)
672 struct callout_cpu *cc;
673 struct lock_class *class;
674 int use_lock, sq_locked;
677 * Some old subsystems don't hold Giant while running a callout_stop(),
678 * so just discard this check for the moment.
680 if (!safe && c->c_lock != NULL) {
681 if (c->c_lock == &Giant.lock_object)
682 use_lock = mtx_owned(&Giant);
685 class = LOCK_CLASS(c->c_lock);
686 class->lc_assert(c->c_lock, LA_XLOCKED);
693 cc = callout_lock(c);
695 * If the callout isn't pending, it's not on the queue, so
696 * don't attempt to remove it from the queue. We can try to
697 * stop it by other means however.
699 if (!(c->c_flags & CALLOUT_PENDING)) {
700 c->c_flags &= ~CALLOUT_ACTIVE;
703 * If it wasn't on the queue and it isn't the current
704 * callout, then we can't stop it, so just bail.
706 if (cc->cc_curr != c) {
707 CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
708 c, c->c_func, c->c_arg);
711 sleepq_release(&cc->cc_waiting);
717 * The current callout is running (or just
718 * about to run) and blocking is allowed, so
719 * just wait for the current invocation to
722 while (cc->cc_curr == c) {
725 * Use direct calls to sleepqueue interface
726 * instead of cv/msleep in order to avoid
727 * a LOR between cc_lock and sleepqueue
728 * chain spinlocks. This piece of code
729 * emulates a msleep_spin() call actually.
731 * If we already have the sleepqueue chain
732 * locked, then we can safely block. If we
733 * don't already have it locked, however,
734 * we have to drop the cc_lock to lock
735 * it. This opens several races, so we
736 * restart at the beginning once we have
737 * both locks. If nothing has changed, then
738 * we will end up back here with sq_locked
743 sleepq_lock(&cc->cc_waiting);
750 sleepq_add(&cc->cc_waiting,
751 &cc->cc_lock.lock_object, "codrain",
753 sleepq_wait(&cc->cc_waiting, 0);
756 /* Reacquire locks previously released. */
760 } else if (use_lock && !cc->cc_cancel) {
762 * The current callout is waiting for its
763 * lock which we hold. Cancel the callout
764 * and return. After our caller drops the
765 * lock, the callout will be skipped in
769 CTR3(KTR_CALLOUT, "cancelled %p func %p arg %p",
770 c, c->c_func, c->c_arg);
772 KASSERT(!sq_locked, ("sleepqueue chain locked"));
775 CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
776 c, c->c_func, c->c_arg);
778 KASSERT(!sq_locked, ("sleepqueue chain still locked"));
782 sleepq_release(&cc->cc_waiting);
784 c->c_flags &= ~(CALLOUT_ACTIVE | CALLOUT_PENDING);
786 if (cc->cc_next == c) {
787 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
789 TAILQ_REMOVE(&cc->cc_callwheel[c->c_time & callwheelmask], c,
792 CTR3(KTR_CALLOUT, "cancelled %p func %p arg %p",
793 c, c->c_func, c->c_arg);
795 if (c->c_flags & CALLOUT_LOCAL_ALLOC) {
797 SLIST_INSERT_HEAD(&cc->cc_callfree, c, c_links.sle);
804 callout_init(c, mpsafe)
811 c->c_flags = CALLOUT_RETURNUNLOCKED;
813 c->c_lock = &Giant.lock_object;
816 c->c_cpu = timeout_cpu;
820 _callout_init_lock(c, lock, flags)
822 struct lock_object *lock;
827 KASSERT((flags & ~(CALLOUT_RETURNUNLOCKED | CALLOUT_SHAREDLOCK)) == 0,
828 ("callout_init_lock: bad flags %d", flags));
829 KASSERT(lock != NULL || (flags & CALLOUT_RETURNUNLOCKED) == 0,
830 ("callout_init_lock: CALLOUT_RETURNUNLOCKED with no lock"));
831 KASSERT(lock == NULL || !(LOCK_CLASS(lock)->lc_flags &
832 (LC_SPINLOCK | LC_SLEEPABLE)), ("%s: invalid lock class",
834 c->c_flags = flags & (CALLOUT_RETURNUNLOCKED | CALLOUT_SHAREDLOCK);
835 c->c_cpu = timeout_cpu;
838 #ifdef APM_FIXUP_CALLTODO
840 * Adjust the kernel calltodo timeout list. This routine is used after
841 * an APM resume to recalculate the calltodo timer list values with the
842 * number of hz's we have been sleeping. The next hardclock() will detect
843 * that there are fired timers and run softclock() to execute them.
845 * Please note, I have not done an exhaustive analysis of what code this
846 * might break. I am motivated to have my select()'s and alarm()'s that
847 * have expired during suspend firing upon resume so that the applications
848 * which set the timer can do the maintanence the timer was for as close
849 * as possible to the originally intended time. Testing this code for a
850 * week showed that resuming from a suspend resulted in 22 to 25 timers
851 * firing, which seemed independant on whether the suspend was 2 hours or
852 * 2 days. Your milage may vary. - Ken Key <key@cs.utk.edu>
855 adjust_timeout_calltodo(time_change)
856 struct timeval *time_change;
858 register struct callout *p;
859 unsigned long delta_ticks;
862 * How many ticks were we asleep?
863 * (stolen from tvtohz()).
866 /* Don't do anything */
867 if (time_change->tv_sec < 0)
869 else if (time_change->tv_sec <= LONG_MAX / 1000000)
870 delta_ticks = (time_change->tv_sec * 1000000 +
871 time_change->tv_usec + (tick - 1)) / tick + 1;
872 else if (time_change->tv_sec <= LONG_MAX / hz)
873 delta_ticks = time_change->tv_sec * hz +
874 (time_change->tv_usec + (tick - 1)) / tick + 1;
876 delta_ticks = LONG_MAX;
878 if (delta_ticks > INT_MAX)
879 delta_ticks = INT_MAX;
882 * Now rip through the timer calltodo list looking for timers
886 /* don't collide with softclock() */
888 for (p = calltodo.c_next; p != NULL; p = p->c_next) {
889 p->c_time -= delta_ticks;
891 /* Break if the timer had more time on it than delta_ticks */
895 /* take back the ticks the timer didn't use (p->c_time <= 0) */
896 delta_ticks = -p->c_time;
902 #endif /* APM_FIXUP_CALLTODO */