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);
61 SDT_PROBE_ARGTYPE(callout_execute, kernel, , callout_start, 0,
63 SDT_PROBE_DEFINE(callout_execute, kernel, , 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;
231 for (cpu = 0; cpu <= mp_maxid; cpu++) {
232 if (cpu == timeout_cpu)
237 if (swi_add(NULL, "clock", softclock, cc, SWI_CLOCK,
238 INTR_MPSAFE, &cc->cc_cookie))
239 panic("died while creating standard software ithreads");
240 cc->cc_callout = NULL; /* Only cpu0 handles timeout(). */
241 cc->cc_callwheel = malloc(
242 sizeof(struct callout_tailq) * callwheelsize, M_CALLOUT,
244 callout_cpu_init(cc);
249 SYSINIT(start_softclock, SI_SUB_SOFTINTR, SI_ORDER_FIRST, start_softclock, NULL);
254 struct callout_cpu *cc;
259 * Process callouts at a very low cpu priority, so we don't keep the
260 * relatively high clock interrupt priority any longer than necessary.
264 mtx_lock_spin_flags(&cc->cc_lock, MTX_QUIET);
266 for (; (cc->cc_softticks - cc->cc_ticks) <= 0; cc->cc_softticks++) {
267 bucket = cc->cc_softticks & callwheelmask;
268 if (!TAILQ_EMPTY(&cc->cc_callwheel[bucket])) {
273 mtx_unlock_spin_flags(&cc->cc_lock, MTX_QUIET);
275 * swi_sched acquires the thread lock, so we don't want to call it
276 * with cc_lock held; incorrect locking order.
279 swi_sched(cc->cc_cookie, 0);
282 static struct callout_cpu *
283 callout_lock(struct callout *c)
285 struct callout_cpu *cc;
300 * The callout mechanism is based on the work of Adam M. Costello and
301 * George Varghese, published in a technical report entitled "Redesigning
302 * the BSD Callout and Timer Facilities" and modified slightly for inclusion
303 * in FreeBSD by Justin T. Gibbs. The original work on the data structures
304 * used in this implementation was published by G. Varghese and T. Lauck in
305 * the paper "Hashed and Hierarchical Timing Wheels: Data Structures for
306 * the Efficient Implementation of a Timer Facility" in the Proceedings of
307 * the 11th ACM Annual Symposium on Operating Systems Principles,
308 * Austin, Texas Nov 1987.
312 * Software (low priority) clock interrupt.
313 * Run periodic events from timeout queue.
318 struct callout_cpu *cc;
320 struct callout_tailq *bucket;
322 int steps; /* #steps since we last allowed interrupts */
328 struct bintime bt1, bt2;
330 static uint64_t maxdt = 36893488147419102LL; /* 2 msec */
331 static timeout_t *lastfunc;
334 #ifndef MAX_SOFTCLOCK_STEPS
335 #define MAX_SOFTCLOCK_STEPS 100 /* Maximum allowed value of steps. */
336 #endif /* MAX_SOFTCLOCK_STEPS */
343 cc = (struct callout_cpu *)arg;
345 while (cc->cc_softticks - 1 != cc->cc_ticks) {
347 * cc_softticks may be modified by hard clock, so cache
348 * it while we work on a given bucket.
350 curticks = cc->cc_softticks;
352 bucket = &cc->cc_callwheel[curticks & callwheelmask];
353 c = TAILQ_FIRST(bucket);
356 if (c->c_time != curticks) {
357 c = TAILQ_NEXT(c, c_links.tqe);
359 if (steps >= MAX_SOFTCLOCK_STEPS) {
361 /* Give interrupts a chance. */
369 void (*c_func)(void *);
371 struct lock_class *class;
372 struct lock_object *c_lock;
373 int c_flags, sharedlock;
375 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
376 TAILQ_REMOVE(bucket, c, c_links.tqe);
377 class = (c->c_lock != NULL) ?
378 LOCK_CLASS(c->c_lock) : NULL;
379 sharedlock = (c->c_flags & CALLOUT_SHAREDLOCK) ?
384 c_flags = c->c_flags;
385 if (c->c_flags & CALLOUT_LOCAL_ALLOC) {
386 c->c_flags = CALLOUT_LOCAL_ALLOC;
389 (c->c_flags & ~CALLOUT_PENDING);
394 if (c_lock != NULL) {
395 class->lc_lock(c_lock, sharedlock);
397 * The callout may have been cancelled
398 * while we switched locks.
401 class->lc_unlock(c_lock);
404 /* The callout cannot be stopped now. */
407 if (c_lock == &Giant.lock_object) {
410 "callout %p func %p arg %p",
414 CTR3(KTR_CALLOUT, "callout lock"
415 " %p func %p arg %p",
421 "callout mpsafe %p func %p arg %p",
427 THREAD_NO_SLEEPING();
428 SDT_PROBE(callout_execute, kernel, ,
429 callout_start, c, 0, 0, 0, 0);
431 SDT_PROBE(callout_execute, kernel, ,
432 callout_end, c, 0, 0, 0, 0);
433 THREAD_SLEEPING_OK();
436 bintime_sub(&bt2, &bt1);
437 if (bt2.frac > maxdt) {
438 if (lastfunc != c_func ||
439 bt2.frac > maxdt * 2) {
440 bintime2timespec(&bt2, &ts2);
442 "Expensive timeout(9) function: %p(%p) %jd.%09ld s\n",
444 (intmax_t)ts2.tv_sec,
451 CTR1(KTR_CALLOUT, "callout %p finished", c);
452 if ((c_flags & CALLOUT_RETURNUNLOCKED) == 0)
453 class->lc_unlock(c_lock);
457 * If the current callout is locally
458 * allocated (from timeout(9))
459 * then put it on the freelist.
461 * Note: we need to check the cached
462 * copy of c_flags because if it was not
463 * local, then it's not safe to deref the
466 if (c_flags & CALLOUT_LOCAL_ALLOC) {
467 KASSERT(c->c_flags ==
469 ("corrupted callout"));
471 SLIST_INSERT_HEAD(&cc->cc_callfree, c,
475 if (cc->cc_waiting) {
477 * There is someone waiting
478 * for the callout to complete.
482 wakeup(&cc->cc_waiting);
490 avg_depth += (depth * 1000 - avg_depth) >> 8;
491 avg_mpcalls += (mpcalls * 1000 - avg_mpcalls) >> 8;
492 avg_lockcalls += (lockcalls * 1000 - avg_lockcalls) >> 8;
493 avg_gcalls += (gcalls * 1000 - avg_gcalls) >> 8;
500 * Execute a function after a specified length of time.
503 * Cancel previous timeout function call.
505 * callout_handle_init --
506 * Initialize a handle so that using it with untimeout is benign.
508 * See AT&T BCI Driver Reference Manual for specification. This
509 * implementation differs from that one in that although an
510 * identification value is returned from timeout, the original
511 * arguments to timeout as well as the identifier are used to
512 * identify entries for untimeout.
514 struct callout_handle
515 timeout(ftn, arg, to_ticks)
520 struct callout_cpu *cc;
522 struct callout_handle handle;
524 cc = CC_CPU(timeout_cpu);
526 /* Fill in the next free callout structure. */
527 new = SLIST_FIRST(&cc->cc_callfree);
529 /* XXX Attempt to malloc first */
530 panic("timeout table full");
531 SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
532 callout_reset(new, to_ticks, ftn, arg);
533 handle.callout = new;
540 untimeout(ftn, arg, handle)
543 struct callout_handle handle;
545 struct callout_cpu *cc;
548 * Check for a handle that was initialized
549 * by callout_handle_init, but never used
550 * for a real timeout.
552 if (handle.callout == NULL)
555 cc = callout_lock(handle.callout);
556 if (handle.callout->c_func == ftn && handle.callout->c_arg == arg)
557 callout_stop(handle.callout);
562 callout_handle_init(struct callout_handle *handle)
564 handle->callout = NULL;
568 * New interface; clients allocate their own callout structures.
570 * callout_reset() - establish or change a timeout
571 * callout_stop() - disestablish a timeout
572 * callout_init() - initialize a callout structure so that it can
573 * safely be passed to callout_reset() and callout_stop()
575 * <sys/callout.h> defines three convenience macros:
577 * callout_active() - returns truth if callout has not been stopped,
578 * drained, or deactivated since the last time the callout was
580 * callout_pending() - returns truth if callout is still waiting for timeout
581 * callout_deactivate() - marks the callout as having been serviced
584 callout_reset_on(struct callout *c, int to_ticks, void (*ftn)(void *),
587 struct callout_cpu *cc;
591 * Don't allow migration of pre-allocated callouts lest they
594 if (c->c_flags & CALLOUT_LOCAL_ALLOC)
597 cc = callout_lock(c);
598 if (cc->cc_curr == c) {
600 * We're being asked to reschedule a callout which is
601 * currently in progress. If there is a lock then we
602 * can cancel the callout if it has not really started.
604 if (c->c_lock != NULL && !cc->cc_cancel)
605 cancelled = cc->cc_cancel = 1;
606 if (cc->cc_waiting) {
608 * Someone has called callout_drain to kill this
609 * callout. Don't reschedule.
611 CTR4(KTR_CALLOUT, "%s %p func %p arg %p",
612 cancelled ? "cancelled" : "failed to cancel",
613 c, c->c_func, c->c_arg);
618 if (c->c_flags & CALLOUT_PENDING) {
619 if (cc->cc_next == c) {
620 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
622 TAILQ_REMOVE(&cc->cc_callwheel[c->c_time & callwheelmask], c,
626 c->c_flags &= ~(CALLOUT_ACTIVE | CALLOUT_PENDING);
629 * If the lock must migrate we have to check the state again as
630 * we can't hold both the new and old locks simultaneously.
632 if (c->c_cpu != cpu) {
642 c->c_flags |= (CALLOUT_ACTIVE | CALLOUT_PENDING);
644 c->c_time = cc->cc_ticks + to_ticks;
645 TAILQ_INSERT_TAIL(&cc->cc_callwheel[c->c_time & callwheelmask],
647 CTR5(KTR_CALLOUT, "%sscheduled %p func %p arg %p in %d",
648 cancelled ? "re" : "", c, c->c_func, c->c_arg, to_ticks);
655 * Common idioms that can be optimized in the future.
658 callout_schedule_on(struct callout *c, int to_ticks, int cpu)
660 return callout_reset_on(c, to_ticks, c->c_func, c->c_arg, cpu);
664 callout_schedule(struct callout *c, int to_ticks)
666 return callout_reset_on(c, to_ticks, c->c_func, c->c_arg, c->c_cpu);
670 _callout_stop_safe(c, safe)
674 struct callout_cpu *cc;
675 struct lock_class *class;
676 int use_lock, sq_locked;
679 * Some old subsystems don't hold Giant while running a callout_stop(),
680 * so just discard this check for the moment.
682 if (!safe && c->c_lock != NULL) {
683 if (c->c_lock == &Giant.lock_object)
684 use_lock = mtx_owned(&Giant);
687 class = LOCK_CLASS(c->c_lock);
688 class->lc_assert(c->c_lock, LA_XLOCKED);
695 cc = callout_lock(c);
697 * If the callout isn't pending, it's not on the queue, so
698 * don't attempt to remove it from the queue. We can try to
699 * stop it by other means however.
701 if (!(c->c_flags & CALLOUT_PENDING)) {
702 c->c_flags &= ~CALLOUT_ACTIVE;
705 * If it wasn't on the queue and it isn't the current
706 * callout, then we can't stop it, so just bail.
708 if (cc->cc_curr != c) {
709 CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
710 c, c->c_func, c->c_arg);
713 sleepq_release(&cc->cc_waiting);
719 * The current callout is running (or just
720 * about to run) and blocking is allowed, so
721 * just wait for the current invocation to
724 while (cc->cc_curr == c) {
727 * Use direct calls to sleepqueue interface
728 * instead of cv/msleep in order to avoid
729 * a LOR between cc_lock and sleepqueue
730 * chain spinlocks. This piece of code
731 * emulates a msleep_spin() call actually.
733 * If we already have the sleepqueue chain
734 * locked, then we can safely block. If we
735 * don't already have it locked, however,
736 * we have to drop the cc_lock to lock
737 * it. This opens several races, so we
738 * restart at the beginning once we have
739 * both locks. If nothing has changed, then
740 * we will end up back here with sq_locked
745 sleepq_lock(&cc->cc_waiting);
752 sleepq_add(&cc->cc_waiting,
753 &cc->cc_lock.lock_object, "codrain",
755 sleepq_wait(&cc->cc_waiting, 0);
758 /* Reacquire locks previously released. */
762 } else if (use_lock && !cc->cc_cancel) {
764 * The current callout is waiting for its
765 * lock which we hold. Cancel the callout
766 * and return. After our caller drops the
767 * lock, the callout will be skipped in
771 CTR3(KTR_CALLOUT, "cancelled %p func %p arg %p",
772 c, c->c_func, c->c_arg);
774 KASSERT(!sq_locked, ("sleepqueue chain locked"));
777 CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
778 c, c->c_func, c->c_arg);
780 KASSERT(!sq_locked, ("sleepqueue chain still locked"));
784 sleepq_release(&cc->cc_waiting);
786 c->c_flags &= ~(CALLOUT_ACTIVE | CALLOUT_PENDING);
788 if (cc->cc_next == c) {
789 cc->cc_next = TAILQ_NEXT(c, c_links.tqe);
791 TAILQ_REMOVE(&cc->cc_callwheel[c->c_time & callwheelmask], c,
794 CTR3(KTR_CALLOUT, "cancelled %p func %p arg %p",
795 c, c->c_func, c->c_arg);
797 if (c->c_flags & CALLOUT_LOCAL_ALLOC) {
799 SLIST_INSERT_HEAD(&cc->cc_callfree, c, c_links.sle);
806 callout_init(c, mpsafe)
813 c->c_flags = CALLOUT_RETURNUNLOCKED;
815 c->c_lock = &Giant.lock_object;
818 c->c_cpu = timeout_cpu;
822 _callout_init_lock(c, lock, flags)
824 struct lock_object *lock;
829 KASSERT((flags & ~(CALLOUT_RETURNUNLOCKED | CALLOUT_SHAREDLOCK)) == 0,
830 ("callout_init_lock: bad flags %d", flags));
831 KASSERT(lock != NULL || (flags & CALLOUT_RETURNUNLOCKED) == 0,
832 ("callout_init_lock: CALLOUT_RETURNUNLOCKED with no lock"));
833 KASSERT(lock == NULL || !(LOCK_CLASS(lock)->lc_flags &
834 (LC_SPINLOCK | LC_SLEEPABLE)), ("%s: invalid lock class",
836 c->c_flags = flags & (CALLOUT_RETURNUNLOCKED | CALLOUT_SHAREDLOCK);
837 c->c_cpu = timeout_cpu;
840 #ifdef APM_FIXUP_CALLTODO
842 * Adjust the kernel calltodo timeout list. This routine is used after
843 * an APM resume to recalculate the calltodo timer list values with the
844 * number of hz's we have been sleeping. The next hardclock() will detect
845 * that there are fired timers and run softclock() to execute them.
847 * Please note, I have not done an exhaustive analysis of what code this
848 * might break. I am motivated to have my select()'s and alarm()'s that
849 * have expired during suspend firing upon resume so that the applications
850 * which set the timer can do the maintanence the timer was for as close
851 * as possible to the originally intended time. Testing this code for a
852 * week showed that resuming from a suspend resulted in 22 to 25 timers
853 * firing, which seemed independant on whether the suspend was 2 hours or
854 * 2 days. Your milage may vary. - Ken Key <key@cs.utk.edu>
857 adjust_timeout_calltodo(time_change)
858 struct timeval *time_change;
860 register struct callout *p;
861 unsigned long delta_ticks;
864 * How many ticks were we asleep?
865 * (stolen from tvtohz()).
868 /* Don't do anything */
869 if (time_change->tv_sec < 0)
871 else if (time_change->tv_sec <= LONG_MAX / 1000000)
872 delta_ticks = (time_change->tv_sec * 1000000 +
873 time_change->tv_usec + (tick - 1)) / tick + 1;
874 else if (time_change->tv_sec <= LONG_MAX / hz)
875 delta_ticks = time_change->tv_sec * hz +
876 (time_change->tv_usec + (tick - 1)) / tick + 1;
878 delta_ticks = LONG_MAX;
880 if (delta_ticks > INT_MAX)
881 delta_ticks = INT_MAX;
884 * Now rip through the timer calltodo list looking for timers
888 /* don't collide with softclock() */
890 for (p = calltodo.c_next; p != NULL; p = p->c_next) {
891 p->c_time -= delta_ticks;
893 /* Break if the timer had more time on it than delta_ticks */
897 /* take back the ticks the timer didn't use (p->c_time <= 0) */
898 delta_ticks = -p->c_time;
904 #endif /* APM_FIXUP_CALLTODO */