/* * Tock is an abstract clock. It counts from 0 to MAX_TOCKS and * back to 0 again. Typically tick is a free-running count register. * * At any time, one alarm can be set anywhere inside [0, MAX_TOCKS]. * Once tock reaches the set value, an interrupt happens and a callback * routine, tock_expire(), is called. * * A pending alarm can be replaced by a new alarm. * * A seoncd interrupt is not required to happen after the alarm expires * and if no new alarm is set. * * Typically tock alarm is implemented with a hardware timer. * * Optionally the tock can support an additional periodic alarm. This is * useful for slightly more efficient support of the legacy jiffies. * Typically a second hardware timer is used in implementation. * * must define the following: * * . define tock_t * e.g., typedef unsigned int tock_t * * . define signed_tock_t (for elapsed time in tocks) * e.g., typedef int signed_tock_t * * . define MAX_TOCKS - valid tocks is between 0 and MAX_TOCKS, inclusive * MAX_TOCKS should be (tock_t)-1. * * . (optionally) define tock_before/after * tock_before(a,b) * tock_after(a,b) * tock_before_eq(a,b) * tock_after_eq(a,b) * #define HAS_TICK_COMPARISON * * . tock_t get_tocks(void) * - return current tick read * * . singed_tock_t tock_to_nsec(singed_tock_t) * . singed_tock_t nsec_to_tock(singed_tock_t) * - note, type is singed_tock_t, can be negative * * . int schedule_next_alarm(tock_t t) * - return non-zero to indicate the time has passed t. * return 0 to indiciate an interrupt has been scheduled * Called with interrupt turned off * * . int support_periodic_alarm(void) * - return non-zero if we can set up schedule_periodic alarm * * . int schedule_periodic_alarm(tock_t delay, tock_t period) * - set up a periodic alarm. It should not skew w.r.t. to tock counts. */ #include #ifndef HAS_TICK_COMPARISON #define tock_after(a,b) \ (typecheck(tock_t, a) && \ typecheck(tock_t, b) && \ ((singed_tock_t)(b) - (singed_tock_t)(a) < 0)) #define tock_before(a,b) tock_after(b,a) #define tock_after_eq(a,b) \ (typecheck(tock_t, a) && \ typecheck(tock_t, b) && \ ((singed_tock_t)(a) - (singed_tock_t)(b) >= 0)) #define tock_before_eq(a,b) tock_after_eq(b,a) #define tock_round(a) (a) #endif /* HAS_TICK_COMPARISON */ /* * call this routine when tock alarm expires. Periodic indicates whether * the interrupt is caused solely by periodic alarm or not. */ asmlinkage void tock_expire(struct pt_regs *regs, int periodic);