Index: dev/atapiscsi/atapiscsi.c =================================================================== RCS file: /cvs/src/sys/dev/atapiscsi/atapiscsi.c,v retrieving revision 1.103 diff -u -p -r1.103 atapiscsi.c --- dev/atapiscsi/atapiscsi.c 14 Sep 2014 14:17:24 -0000 1.103 +++ dev/atapiscsi/atapiscsi.c 21 Jul 2015 01:51:34 -0000 @@ -613,7 +613,7 @@ wdc_atapi_the_machine(struct channel_sof enum atapi_context ctxt) { int idx = 0; - extern int ticks; + int tick = ticks(); int timeout_delay = hz / 10; if (xfer->c_flags & C_POLL) { @@ -637,7 +637,7 @@ wdc_atapi_the_machine(struct channel_sof struct atapi_return_args retargs = ARGS_INIT; (xfer->next)(chp, xfer, - xfer->endticks && (ticks - xfer->endticks >= 0), + xfer->endticks && (tick - xfer->endticks >= 0), &retargs); if (retargs.timeout != -1) @@ -646,7 +646,7 @@ wdc_atapi_the_machine(struct channel_sof * can be just microseconds before the tick changes. */ xfer->endticks = - max((retargs.timeout * hz) / 1000, 1) + 1 + ticks; + max((retargs.timeout * hz) / 1000, 1) + 1 + tick; if (xfer->next == NULL) { if (xfer->c_flags & C_POLL_MACHINE) @@ -661,7 +661,7 @@ wdc_atapi_the_machine(struct channel_sof if (retargs.expect_irq) { int timeout_period; chp->ch_flags |= WDCF_IRQ_WAIT; - timeout_period = xfer->endticks - ticks; + timeout_period = xfer->endticks - tick; if (timeout_period < 1) timeout_period = 1; timeout_add(&chp->ch_timo, timeout_period); Index: dev/ic/ar5008.c =================================================================== RCS file: /cvs/src/sys/dev/ic/ar5008.c,v retrieving revision 1.29 diff -u -p -r1.29 ar5008.c --- dev/ic/ar5008.c 14 Mar 2015 03:38:47 -0000 1.29 +++ dev/ic/ar5008.c 21 Jul 2015 01:51:35 -0000 @@ -2395,8 +2395,7 @@ ar5008_hw_init(struct athn_softc *sc, st ar5008_init_chains(sc); if (sc->flags & ATHN_FLAG_OLPC) { - extern int ticks; - sc->olpc_ticks = ticks; + sc->olpc_ticks = ticks(); ops->olpc_init(sc); } Index: dev/ic/athn.c =================================================================== RCS file: /cvs/src/sys/dev/ic/athn.c,v retrieving revision 1.86 diff -u -p -r1.86 athn.c --- dev/ic/athn.c 14 Mar 2015 03:38:47 -0000 1.86 +++ dev/ic/athn.c 21 Jul 2015 01:51:35 -0000 @@ -1225,10 +1225,10 @@ athn_iter_func(void *arg, struct ieee802 void athn_calib_to(void *arg) { - extern int ticks; struct athn_softc *sc = arg; struct athn_ops *ops = &sc->ops; struct ieee80211com *ic = &sc->sc_ic; + int t = ticks(); int s; s = splnet(); @@ -1236,8 +1236,8 @@ athn_calib_to(void *arg) /* Do periodic (every 4 minutes) PA calibration. */ if (AR_SREV_9285_11_OR_LATER(sc) && !AR_SREV_9380_10_OR_LATER(sc) && - (ticks - (sc->pa_calib_ticks + 240 * hz)) >= 0) { - sc->pa_calib_ticks = ticks; + (t - (sc->pa_calib_ticks + 240 * hz)) >= 0) { + sc->pa_calib_ticks = t; if (AR_SREV_9271(sc)) ar9271_pa_calib(sc); else @@ -1246,8 +1246,8 @@ athn_calib_to(void *arg) /* Do periodic (every 30 seconds) temperature compensation. */ if ((sc->flags & ATHN_FLAG_OLPC) && - ticks >= sc->olpc_ticks + 30 * hz) { - sc->olpc_ticks = ticks; + t >= sc->olpc_ticks + 30 * hz) { + sc->olpc_ticks = t; ops->olpc_temp_compensation(sc); } @@ -1286,8 +1286,7 @@ athn_init_calib(struct athn_softc *sc, s if (!AR_SREV_9380_10_OR_LATER(sc)) { /* Do PA calibration. */ if (AR_SREV_9285_11_OR_LATER(sc)) { - extern int ticks; - sc->pa_calib_ticks = ticks; + sc->pa_calib_ticks = ticks(); if (AR_SREV_9271(sc)) ar9271_pa_calib(sc); else Index: dev/pci/drm/drmP.h =================================================================== RCS file: /cvs/src/sys/dev/pci/drm/drmP.h,v retrieving revision 1.196 diff -u -p -r1.196 drmP.h --- dev/pci/drm/drmP.h 30 May 2015 18:09:26 -0000 1.196 +++ dev/pci/drm/drmP.h 21 Jul 2015 01:51:35 -0000 @@ -91,8 +91,6 @@ #define DRM_WAKEUP(x) wakeup(x) -extern int ticks; - #define drm_msleep(x, msg) mdelay(x) extern struct cfdriver drm_cd; Index: dev/pci/drm/drm_linux.h =================================================================== RCS file: /cvs/src/sys/dev/pci/drm/drm_linux.h,v retrieving revision 1.33 diff -u -p -r1.33 drm_linux.h --- dev/pci/drm/drm_linux.h 16 Jul 2015 18:48:51 -0000 1.33 +++ dev/pci/drm/drm_linux.h 21 Jul 2015 01:51:35 -0000 @@ -294,9 +294,9 @@ do { \ \ sleep_setup(&sls, &wq, 0, "drmwet"); \ sleep_setup_timeout(&sls, ret); \ - deadline = ticks + ret; \ + deadline = ticks() + ret; \ sleep_finish(&sls, !(condition)); \ - ret = deadline - ticks; \ + ret = deadline - ticks(); \ error = sleep_finish_timeout(&sls); \ if (ret < 0 || error == EWOULDBLOCK) \ ret = 0; \ @@ -322,9 +322,9 @@ do { \ sleep_setup(&sls, &wq, PCATCH, "drmweti"); \ sleep_setup_timeout(&sls, ret); \ sleep_setup_signal(&sls, PCATCH); \ - deadline = ticks + ret; \ + deadline = ticks() + ret; \ sleep_finish(&sls, !(condition)); \ - ret = deadline - ticks; \ + ret = deadline - ticks(); \ error1 = sleep_finish_timeout(&sls); \ error = sleep_finish_signal(&sls); \ if (ret < 0 || error1 == EWOULDBLOCK) \ @@ -485,8 +485,7 @@ extern struct timespec ns_to_timespec(co extern int64_t timeval_to_ns(const struct timeval *); extern struct timeval ns_to_timeval(const int64_t); -extern int ticks; -#define jiffies ticks +#define jiffies ticks() #undef HZ #define HZ hz Index: dev/usb/if_ugl.c =================================================================== RCS file: /cvs/src/sys/dev/usb/if_ugl.c,v retrieving revision 1.13 diff -u -p -r1.13 if_ugl.c --- dev/usb/if_ugl.c 24 Jun 2015 09:40:54 -0000 1.13 +++ dev/usb/if_ugl.c 21 Jul 2015 01:51:35 -0000 @@ -154,8 +154,6 @@ int ugldebug = 0; #define DPRINTFN(n,x) #endif -extern int ticks; - /* * Various supported device vendors/products. */ @@ -217,6 +215,7 @@ ugl_attach(struct device *parent, struct usb_endpoint_descriptor_t *ed; int i; u_int16_t macaddr_hi; + int tick = ticks(); DPRINTFN(5,(" : ugl_attach: sc=%p, dev=%p", sc, dev)); @@ -255,7 +254,7 @@ ugl_attach(struct device *parent, struct macaddr_hi = htons(0x2acb); bcopy(&macaddr_hi, &sc->sc_arpcom.ac_enaddr[0], sizeof(u_int16_t)); - bcopy(&ticks, &sc->sc_arpcom.ac_enaddr[2], sizeof(u_int32_t)); + bcopy(&tick, &sc->sc_arpcom.ac_enaddr[2], sizeof(u_int32_t)); sc->sc_arpcom.ac_enaddr[5] = (u_int8_t)(sc->sc_dev.dv_unit); printf("%s: address %s\n", Index: kern/kern_clock.c =================================================================== RCS file: /cvs/src/sys/kern/kern_clock.c,v retrieving revision 1.88 diff -u -p -r1.88 kern_clock.c --- kern/kern_clock.c 11 Jun 2015 16:03:04 -0000 1.88 +++ kern/kern_clock.c 21 Jul 2015 01:51:35 -0000 @@ -97,7 +97,7 @@ int stathz; int schedhz; int profhz; int profprocs; -int ticks; +unsigned int clockticks; static int psdiv, pscnt; /* prof => stat divider */ int psratio; /* ratio: prof / stat */ Index: kern/kern_timeout.c =================================================================== RCS file: /cvs/src/sys/kern/kern_timeout.c,v retrieving revision 1.43 diff -u -p -r1.43 kern_timeout.c --- kern/kern_timeout.c 20 Jul 2015 23:47:20 -0000 1.43 +++ kern/kern_timeout.c 21 Jul 2015 01:51:35 -0000 @@ -42,7 +42,7 @@ /* * Timeouts are kept in a hierarchical timing wheel. The to_time is the value - * of the global variable "ticks" when the timeout should be called. There are + * of the global "ticks" when the timeout should be called. There are * four levels with 256 buckets each. See 'Scheme 7' in * "Hashed and Hierarchical Timing Wheels: Efficient Data Structures for * Implementing a Timer Facility" by George Varghese and Tony Lauck. @@ -137,7 +137,7 @@ struct mutex timeout_mutex = MUTEX_INITI * be positive or negative so comparing it with anything is dangerous. * The only way we can use the to->to_time value in any predictable way * is when we calculate how far in the future `to' will timeout - - * "to->to_time - ticks". The result will always be positive for future + * "to->to_time - ticks()". The result will always be positive for future * timeouts and 0 or negative for due timeouts. */ @@ -165,6 +165,7 @@ timeout_add(struct timeout *new, int to_ { int old_time; int ret = 1; + int now = ticks(); #ifdef DIAGNOSTIC if (!(new->to_flags & TIMEOUT_INITIALIZED)) @@ -176,7 +177,7 @@ timeout_add(struct timeout *new, int to_ mtx_enter(&timeout_mutex); /* Initialize the time here, it won't change. */ old_time = new->to_time; - new->to_time = to_ticks + ticks; + new->to_time = to_ticks + now; new->to_flags &= ~TIMEOUT_TRIGGERED; /* @@ -185,7 +186,7 @@ timeout_add(struct timeout *new, int to_ * and let it be rescheduled later. */ if (new->to_flags & TIMEOUT_ONQUEUE) { - if (new->to_time - ticks < old_time - ticks) { + if (new->to_time - now < old_time - now) { CIRCQ_REMOVE(&new->to_list); CIRCQ_INSERT(&new->to_list, &timeout_todo); } @@ -300,19 +301,21 @@ timeout_del(struct timeout *to) int timeout_hardclock_update(void) { + extern unsigned int clockticks; + int t; int ret; mtx_enter(&timeout_mutex); - ticks++; + t = ++clockticks; - MOVEBUCKET(0, ticks); - if (MASKWHEEL(0, ticks) == 0) { - MOVEBUCKET(1, ticks); - if (MASKWHEEL(1, ticks) == 0) { - MOVEBUCKET(2, ticks); - if (MASKWHEEL(2, ticks) == 0) - MOVEBUCKET(3, ticks); + MOVEBUCKET(0, t); + if (MASKWHEEL(0, t) == 0) { + MOVEBUCKET(1, t); + if (MASKWHEEL(1, t) == 0) { + MOVEBUCKET(2, t); + if (MASKWHEEL(2, t) == 0) + MOVEBUCKET(3, t); } } ret = !CIRCQ_EMPTY(&timeout_todo); @@ -326,6 +329,7 @@ softclock(void *arg) { struct timeout *to; void (*fn)(void *); + int tick = ticks(); mtx_enter(&timeout_mutex); while (!CIRCQ_EMPTY(&timeout_todo)) { @@ -334,14 +338,14 @@ softclock(void *arg) CIRCQ_REMOVE(&to->to_list); /* If due run it, otherwise insert it into the right bucket. */ - if (to->to_time - ticks > 0) { + if (to->to_time - tick > 0) { CIRCQ_INSERT(&to->to_list, - &BUCKET((to->to_time - ticks), to->to_time)); + &BUCKET((to->to_time - tick), to->to_time)); } else { #ifdef DEBUG - if (to->to_time - ticks < 0) + if (to->to_time - tick < 0) printf("timeout delayed %d\n", to->to_time - - ticks); + tick); #endif to->to_flags &= ~TIMEOUT_ONQUEUE; to->to_flags |= TIMEOUT_TRIGGERED; @@ -363,14 +367,18 @@ timeout_adjust_ticks(int adj) { struct timeout *to; struct circq *p; + extern unsigned int clockticks; int new_ticks, b; + int tick; /* adjusting the monotonic clock backwards would be a Bad Thing */ if (adj <= 0) return; mtx_enter(&timeout_mutex); - new_ticks = ticks + adj; + tick = clockticks; + clockticks += adj; + new_ticks = clockticks; for (b = 0; b < nitems(timeout_wheel); b++) { p = CIRCQ_FIRST(&timeout_wheel[b]); while (p != &timeout_wheel[b]) { @@ -378,13 +386,12 @@ timeout_adjust_ticks(int adj) p = CIRCQ_FIRST(p); /* when moving a timeout forward need to reinsert it */ - if (to->to_time - ticks < adj) + if (to->to_time - tick < adj) to->to_time = new_ticks; CIRCQ_REMOVE(&to->to_list); CIRCQ_INSERT(&to->to_list, &timeout_todo); } } - ticks = new_ticks; mtx_leave(&timeout_mutex); } #endif @@ -404,7 +411,7 @@ db_show_callout_bucket(struct circq *buc to = timeout_from_circq(p); db_find_sym_and_offset((db_addr_t)to->to_func, &name, &offset); name = name ? name : "?"; - db_printf("%9d %2td/%-4td %p %s\n", to->to_time - ticks, + db_printf("%9d %2td/%-4td %p %s\n", to->to_time - ticks(), (bucket - timeout_wheel) / WHEELSIZE, bucket - timeout_wheel, to->to_arg, name); } @@ -415,7 +422,7 @@ db_show_callout(db_expr_t addr, int hadd { int b; - db_printf("ticks now: %d\n", ticks); + db_printf("ticks now: %d\n", ticks()); db_printf(" ticks wheel arg func\n"); db_show_callout_bucket(&timeout_todo); Index: kern/subr_pool.c =================================================================== RCS file: /cvs/src/sys/kern/subr_pool.c,v retrieving revision 1.186 diff -u -p -r1.186 subr_pool.c --- kern/subr_pool.c 20 Jul 2015 23:47:20 -0000 1.186 +++ kern/subr_pool.c 21 Jul 2015 01:51:35 -0000 @@ -686,7 +686,7 @@ pool_put(struct pool *pp, void *v) */ pp->pr_nidle++; - ph->ph_tick = ticks; + ph->ph_tick = ticks(); TAILQ_REMOVE(&pp->pr_partpages, ph, ph_pagelist); TAILQ_INSERT_TAIL(&pp->pr_emptypages, ph, ph_pagelist); pool_update_curpage(pp); @@ -698,7 +698,7 @@ pool_put(struct pool *pp, void *v) /* is it time to free a page? */ if (pp->pr_nidle > pp->pr_maxpages && (ph = TAILQ_FIRST(&pp->pr_emptypages)) != NULL && - (ticks - ph->ph_tick) > (hz * pool_wait_free)) { + (ticks() - ph->ph_tick) > (hz * pool_wait_free)) { freeph = ph; pool_p_remove(pp, freeph); } @@ -1381,7 +1381,7 @@ pool_gc_pages(void *null) /* is it time to free a page? */ if (pp->pr_nidle > pp->pr_minpages && (ph = TAILQ_FIRST(&pp->pr_emptypages)) != NULL && - (ticks - ph->ph_tick) > (hz * pool_wait_gc)) { + (ticks() - ph->ph_tick) > (hz * pool_wait_gc)) { freeph = ph; pool_p_remove(pp, freeph); } else Index: net/bpf.c =================================================================== RCS file: /cvs/src/sys/net/bpf.c,v retrieving revision 1.120 diff -u -p -r1.120 bpf.c --- net/bpf.c 16 Jun 2015 11:09:39 -0000 1.120 +++ net/bpf.c 21 Jul 2015 01:51:35 -0000 @@ -71,9 +71,6 @@ #define PRINET 26 /* interruptible */ -/* from kern/kern_clock.c; incremented each clock tick. */ -extern int ticks; - /* * The default read buffer size is patchable. */ @@ -375,6 +372,7 @@ int bpfread(dev_t dev, struct uio *uio, int ioflag) { struct bpf_d *d; + int t = ticks(); int error; int s; @@ -398,7 +396,7 @@ bpfread(dev_t dev, struct uio *uio, int * we can then figure out when we're done reading. */ if (d->bd_rtout != -1 && d->bd_rdStart == 0) - d->bd_rdStart = ticks; + d->bd_rdStart = t; else d->bd_rdStart = 0; @@ -431,7 +429,7 @@ bpfread(dev_t dev, struct uio *uio, int /* User requested non-blocking I/O */ error = EWOULDBLOCK; } else { - if ((d->bd_rdStart + d->bd_rtout) < ticks) { + if ((d->bd_rdStart + d->bd_rtout) < t) { error = tsleep((caddr_t)d, PRINET|PCATCH, "bpf", d->bd_rtout); } else @@ -1041,7 +1039,7 @@ bpfpoll(dev_t dev, int events, struct pr * started waiting. */ if (d->bd_rtout != -1 && d->bd_rdStart == 0) - d->bd_rdStart = ticks; + d->bd_rdStart = ticks(); selrecord(p, &d->bd_sel); } splx(s); @@ -1075,7 +1073,7 @@ bpfkqfilter(dev_t dev, struct knote *kn) D_GET(d); SLIST_INSERT_HEAD(klist, kn, kn_selnext); if (d->bd_rtout != -1 && d->bd_rdStart == 0) - d->bd_rdStart = ticks; + d->bd_rdStart = ticks(); splx(s); return (0); @@ -1377,7 +1375,7 @@ bpf_catchpacket(struct bpf_d *d, u_char bpf_wakeup(d); } - if (d->bd_rdStart && (d->bd_rtout + d->bd_rdStart < ticks)) { + if (d->bd_rdStart && (d->bd_rtout + d->bd_rdStart < ticks())) { /* * we could be selecting on the bpf, and we * may have timeouts set. We got here by getting Index: net/if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.354 diff -u -p -r1.354 if.c --- net/if.c 20 Jul 2015 22:54:29 -0000 1.354 +++ net/if.c 21 Jul 2015 01:51:35 -0000 @@ -155,7 +155,6 @@ int if_cloners_count; struct timeout net_tick_to; void net_tick(void *); -int net_livelocked(void); int ifq_congestion; struct taskq *softnettq; @@ -843,17 +842,13 @@ if_clone_list(struct if_clonereq *ifcr) void if_congestion(void) { - extern int ticks; - - ifq_congestion = ticks; + ifq_congestion = ticks(); } int if_congested(void) { - extern int ticks; - - return (ticks - ifq_congestion <= (hz / 100)); + return (ticks() - ifq_congestion <= (hz / 100)); } #define equal(a1, a2) \ @@ -2287,32 +2282,22 @@ u_int net_livelocks; void net_tick(void *null) { - extern int ticks; + int t = ticks(); - if (ticks - net_ticks > 1) + if (t - net_ticks > 1) net_livelocks++; - net_ticks = ticks; + net_ticks = t; timeout_add(&net_tick_to, 1); } -int -net_livelocked() -{ - extern int ticks; - - return (ticks - net_ticks > 1); -} - void if_rxr_init(struct if_rxring *rxr, u_int lwm, u_int hwm) { - extern int ticks; - memset(rxr, 0, sizeof(*rxr)); - rxr->rxr_adjusted = ticks; + rxr->rxr_adjusted = ticks(); rxr->rxr_cwm = rxr->rxr_lwm = lwm; rxr->rxr_hwm = hwm; } @@ -2320,9 +2305,9 @@ if_rxr_init(struct if_rxring *rxr, u_int static inline void if_rxr_adjust_cwm(struct if_rxring *rxr) { - extern int ticks; + int t = ticks(); - if (net_livelocked()) { + if ((t - net_ticks) > 1) { if (rxr->rxr_cwm > rxr->rxr_lwm) rxr->rxr_cwm--; else @@ -2332,16 +2317,15 @@ if_rxr_adjust_cwm(struct if_rxring *rxr) else if (rxr->rxr_cwm < rxr->rxr_hwm) rxr->rxr_cwm++; - rxr->rxr_adjusted = ticks; + rxr->rxr_adjusted = t; } u_int if_rxr_get(struct if_rxring *rxr, u_int max) { - extern int ticks; u_int diff; - if (ticks - rxr->rxr_adjusted >= 1) { + if (ticks() - rxr->rxr_adjusted >= 1) { /* we're free to try for an adjustment */ if_rxr_adjust_cwm(rxr); } Index: net80211/ieee80211_crypto_tkip.c =================================================================== RCS file: /cvs/src/sys/net80211/ieee80211_crypto_tkip.c,v retrieving revision 1.24 diff -u -p -r1.24 ieee80211_crypto_tkip.c --- net80211/ieee80211_crypto_tkip.c 15 Jul 2015 22:16:42 -0000 1.24 +++ net80211/ieee80211_crypto_tkip.c 21 Jul 2015 01:51:35 -0000 @@ -500,7 +500,7 @@ ieee80211_tkip_deauth(void *arg, struct void ieee80211_michael_mic_failure(struct ieee80211com *ic, u_int64_t tsc) { - extern int ticks; + int t = ticks(); if (ic->ic_flags & IEEE80211_F_COUNTERM) return; /* countermeasures already active */ @@ -519,8 +519,8 @@ ieee80211_michael_mic_failure(struct iee * seconds have passed since the most recent previous MIC failure. */ if (ic->ic_tkip_micfail == 0 || - ticks - (ic->ic_tkip_micfail + 60 * hz) >= 0) { - ic->ic_tkip_micfail = ticks; + t - (ic->ic_tkip_micfail + 60 * hz) >= 0) { + ic->ic_tkip_micfail = t; ic->ic_tkip_micfail_last_tsc = tsc; return; } @@ -559,7 +559,7 @@ ieee80211_michael_mic_failure(struct iee break; } - ic->ic_tkip_micfail = ticks; + ic->ic_tkip_micfail = t; ic->ic_tkip_micfail_last_tsc = tsc; } Index: sys/kernel.h =================================================================== RCS file: /cvs/src/sys/sys/kernel.h,v retrieving revision 1.17 diff -u -p -r1.17 kernel.h --- sys/kernel.h 20 Jul 2015 23:47:20 -0000 1.17 +++ sys/kernel.h 21 Jul 2015 01:51:35 -0000 @@ -54,7 +54,6 @@ extern int tick; /* usec per tick (1000 extern int tickfix; /* periodic tick adj. tick not integral */ extern int tickfixinterval; /* interval at which to apply adjustment */ extern int tickadj; /* "standard" clock skew, us./tick */ -extern int ticks; /* # of hardclock ticks */ extern int hz; /* system clock's frequency */ extern int stathz; /* statistics clock's frequency */ extern int profhz; /* profiling clock's frequency */ Index: sys/systm.h =================================================================== RCS file: /cvs/src/sys/sys/systm.h,v retrieving revision 1.108 diff -u -p -r1.108 systm.h --- sys/systm.h 11 Jun 2015 16:03:04 -0000 1.108 +++ sys/systm.h 21 Jul 2015 01:51:35 -0000 @@ -240,6 +240,13 @@ void startprofclock(struct process *); void stopprofclock(struct process *); void setstatclockrate(int); +static inline int +ticks(void) +{ + extern unsigned int clockticks; + return (clockticks); +} + struct sleep_state; void sleep_setup(struct sleep_state *, const volatile void *, int, const char *);