/* * timer_alarm - alarm system call. * * SIGALRM exception is sent to the caller task when specified * delay time is passed. If "msec" argument is 0, stop the * current running timer. */ int timer_alarm(u_long msec, u_long *remain) { struct timer *tmr; u_long left = 0; int s; s = splhigh(); tmr = &curtask->alarm; /* * If the timer is active, save the remaining time * before we update the timer setting. */ if (tmr->state == TM_ACTIVE) left = hztoms(time_remain(tmr->expire)); if (msec == 0) timer_stop(tmr); else timer_callout(tmr, msec, &alarm_expire, curtask); splx(s); if (remain != NULL) { if (copyout(&left, remain, sizeof(left))) return EFAULT; } return 0; }
/* * timer_delay - delay thread execution. * * The caller thread is blocked for the specified time. * Returns 0 on success, or the remaining time (msec) on * failure. */ u_long timer_delay(u_long msec) { struct timer *tmr; u_long remain = 0; int rc; rc = sched_tsleep(&delay_event, msec); if (rc != SLP_TIMEOUT) { tmr = &curthread->timeout; remain = hztoms(time_remain(tmr->expire)); } return remain; }
static void acpicpu_cstate_idle_enter(struct acpicpu_softc *sc, int state) { struct acpicpu_cstate *cs = &sc->sc_cstate[state]; uint32_t end, start, val; start = acpitimer_read_fast(NULL); switch (cs->cs_method) { case ACPICPU_C_STATE_FFH: case ACPICPU_C_STATE_HALT: acpicpu_md_cstate_enter(cs->cs_method, state); break; case ACPICPU_C_STATE_SYSIO: (void)AcpiOsReadPort(cs->cs_addr, &val, 8); break; } cs->cs_evcnt.ev_count++; end = acpitimer_read_fast(NULL); sc->sc_cstate_sleep = hztoms(acpitimer_delta(end, start)) * 1000; }