xnticks_t xnthread_get_timeout(xnthread_t *thread, xnticks_t tsc_ns) { xnticks_t timeout; xntimer_t *timer; if (!xnthread_test_state(thread,XNDELAY)) return 0LL; if (xntimer_running_p(&thread->rtimer)) timer = &thread->rtimer; else if (xntimer_running_p(&thread->ptimer)) timer = &thread->ptimer; else return 0LL; /* * The caller should have masked IRQs while collecting the * timeout(s), so no tick could be announced in the meantime, * and all timeouts would always use the same epoch * value. Obviously, this can't be a valid assumption for * aperiodic timers, which values are based on the hardware * TSC, and as such the current time will change regardless of * the interrupt state; for this reason, we use the "tsc_ns" * input parameter (TSC converted to nanoseconds) the caller * has passed us as the epoch value instead. */ if (xntbase_periodic_p(xnthread_time_base(thread))) return xntimer_get_timeout(timer); timeout = xntimer_get_date(timer); if (timeout <= tsc_ns) return 1; return timeout - tsc_ns; }
/** * @fn xnticks_t xntimer_get_date(struct xntimer *timer) * * @brief Return the absolute expiration date. * * Return the next expiration date of a timer as an absolute count of * nanoseconds. * * @param timer The address of a valid timer descriptor. * * @return The expiration date in nanoseconds. The special value * XN_INFINITE is returned if @a timer is currently disabled. * * @coretags{unrestricted, atomic-entry} */ xnticks_t xntimer_get_date(struct xntimer *timer) { if (!xntimer_running_p(timer)) return XN_INFINITE; return xnclock_ticks_to_ns(xntimer_clock(timer), xntimer_expiry(timer)); }
xnticks_t xnthread_get_period(xnthread_t *thread) { xnticks_t period = 0; /* * The current thread period might be: * - the value of the timer interval for periodic threads (ns/ticks) * - or, the value of the alloted round-robin quantum (ticks) * - or zero, meaning "no periodic activity". */ if (xntimer_running_p(&thread->ptimer)) period = xntimer_get_interval(&thread->ptimer); else if (xnthread_test_state(thread,XNRRB)) period = xnthread_time_slice(thread); return period; }
/** * @fn xnticks_t xntimer_get_timeout(struct xntimer *timer) * * @brief Return the relative expiration date. * * This call returns the count of nanoseconds remaining until the * timer expires. * * @param timer The address of a valid timer descriptor. * * @return The count of nanoseconds until expiry. The special value * XN_INFINITE is returned if @a timer is currently disabled. It * might happen that the timer expires when this service runs (even if * the associated handler has not been fired yet); in such a case, 1 * is returned. * * @coretags{unrestricted, atomic-entry} */ xnticks_t xntimer_get_timeout(struct xntimer *timer) { struct xnclock *clock; xnticks_t expiry, now; if (!xntimer_running_p(timer)) return XN_INFINITE; clock = xntimer_clock(timer); now = xnclock_read_raw(clock); expiry = xntimer_expiry(timer); if (expiry < now) return 1; /* Will elapse shortly. */ return xnclock_ticks_to_ns(clock, expiry - now); }