1c0a31329SThomas Gleixner /* 2c0a31329SThomas Gleixner * include/linux/hrtimer.h 3c0a31329SThomas Gleixner * 4c0a31329SThomas Gleixner * hrtimers - High-resolution kernel timers 5c0a31329SThomas Gleixner * 6c0a31329SThomas Gleixner * Copyright(C) 2005, Thomas Gleixner <[email protected]> 7c0a31329SThomas Gleixner * Copyright(C) 2005, Red Hat, Inc., Ingo Molnar 8c0a31329SThomas Gleixner * 9c0a31329SThomas Gleixner * data type definitions, declarations, prototypes 10c0a31329SThomas Gleixner * 11c0a31329SThomas Gleixner * Started by: Thomas Gleixner and Ingo Molnar 12c0a31329SThomas Gleixner * 13c0a31329SThomas Gleixner * For licencing details see kernel-base/COPYING 14c0a31329SThomas Gleixner */ 15c0a31329SThomas Gleixner #ifndef _LINUX_HRTIMER_H 16c0a31329SThomas Gleixner #define _LINUX_HRTIMER_H 17c0a31329SThomas Gleixner 18c0a31329SThomas Gleixner #include <linux/rbtree.h> 19c0a31329SThomas Gleixner #include <linux/ktime.h> 20c0a31329SThomas Gleixner #include <linux/init.h> 21c0a31329SThomas Gleixner #include <linux/list.h> 22c0a31329SThomas Gleixner #include <linux/wait.h> 23c0a31329SThomas Gleixner 243c8aa39dSThomas Gleixner struct hrtimer_clock_base; 253c8aa39dSThomas Gleixner struct hrtimer_cpu_base; 263c8aa39dSThomas Gleixner 27c0a31329SThomas Gleixner /* 28c0a31329SThomas Gleixner * Mode arguments of xxx_hrtimer functions: 29c0a31329SThomas Gleixner */ 30c0a31329SThomas Gleixner enum hrtimer_mode { 31c9cb2e3dSThomas Gleixner HRTIMER_MODE_ABS, /* Time value is absolute */ 32c9cb2e3dSThomas Gleixner HRTIMER_MODE_REL, /* Time value is relative to now */ 33c0a31329SThomas Gleixner }; 34c0a31329SThomas Gleixner 35c9cb2e3dSThomas Gleixner /* 36c9cb2e3dSThomas Gleixner * Return values for the callback function 37c9cb2e3dSThomas Gleixner */ 38c0a31329SThomas Gleixner enum hrtimer_restart { 39c9cb2e3dSThomas Gleixner HRTIMER_NORESTART, /* Timer is not restarted */ 40c9cb2e3dSThomas Gleixner HRTIMER_RESTART, /* Timer must be restarted */ 41c0a31329SThomas Gleixner }; 42c0a31329SThomas Gleixner 43303e967fSThomas Gleixner /* 4454cdfdb4SThomas Gleixner * hrtimer callback modes: 4554cdfdb4SThomas Gleixner * 4654cdfdb4SThomas Gleixner * HRTIMER_CB_SOFTIRQ: Callback must run in softirq context 4754cdfdb4SThomas Gleixner * HRTIMER_CB_IRQSAFE: Callback may run in hardirq context 4854cdfdb4SThomas Gleixner * HRTIMER_CB_IRQSAFE_NO_RESTART: Callback may run in hardirq context and 4954cdfdb4SThomas Gleixner * does not restart the timer 508437fdc7SAndres Salomon * HRTIMER_CB_IRQSAFE_NO_SOFTIRQ: Callback must run in hardirq context 5154cdfdb4SThomas Gleixner * Special mode for tick emultation 5254cdfdb4SThomas Gleixner */ 5354cdfdb4SThomas Gleixner enum hrtimer_cb_mode { 5454cdfdb4SThomas Gleixner HRTIMER_CB_SOFTIRQ, 5554cdfdb4SThomas Gleixner HRTIMER_CB_IRQSAFE, 5654cdfdb4SThomas Gleixner HRTIMER_CB_IRQSAFE_NO_RESTART, 5754cdfdb4SThomas Gleixner HRTIMER_CB_IRQSAFE_NO_SOFTIRQ, 5854cdfdb4SThomas Gleixner }; 5954cdfdb4SThomas Gleixner 6054cdfdb4SThomas Gleixner /* 6154cdfdb4SThomas Gleixner * Values to track state of the timer 62303e967fSThomas Gleixner * 63303e967fSThomas Gleixner * Possible states: 64303e967fSThomas Gleixner * 65303e967fSThomas Gleixner * 0x00 inactive 66303e967fSThomas Gleixner * 0x01 enqueued into rbtree 67303e967fSThomas Gleixner * 0x02 callback function running 6854cdfdb4SThomas Gleixner * 0x04 callback pending (high resolution mode) 6954cdfdb4SThomas Gleixner * 7054cdfdb4SThomas Gleixner * Special case: 71303e967fSThomas Gleixner * 0x03 callback function running and enqueued 72303e967fSThomas Gleixner * (was requeued on another CPU) 73303e967fSThomas Gleixner * The "callback function running and enqueued" status is only possible on 74303e967fSThomas Gleixner * SMP. It happens for example when a posix timer expired and the callback 75303e967fSThomas Gleixner * queued a signal. Between dropping the lock which protects the posix timer 76303e967fSThomas Gleixner * and reacquiring the base lock of the hrtimer, another CPU can deliver the 77303e967fSThomas Gleixner * signal and rearm the timer. We have to preserve the callback running state, 78303e967fSThomas Gleixner * as otherwise the timer could be removed before the softirq code finishes the 79303e967fSThomas Gleixner * the handling of the timer. 80303e967fSThomas Gleixner * 813eb05676SLi Zefan * The HRTIMER_STATE_ENQUEUED bit is always or'ed to the current state to 82303e967fSThomas Gleixner * preserve the HRTIMER_STATE_CALLBACK bit in the above scenario. 83303e967fSThomas Gleixner * 84303e967fSThomas Gleixner * All state transitions are protected by cpu_base->lock. 85303e967fSThomas Gleixner */ 86303e967fSThomas Gleixner #define HRTIMER_STATE_INACTIVE 0x00 87303e967fSThomas Gleixner #define HRTIMER_STATE_ENQUEUED 0x01 88303e967fSThomas Gleixner #define HRTIMER_STATE_CALLBACK 0x02 8954cdfdb4SThomas Gleixner #define HRTIMER_STATE_PENDING 0x04 90303e967fSThomas Gleixner 91c0a31329SThomas Gleixner /** 92c0a31329SThomas Gleixner * struct hrtimer - the basic hrtimer structure 93c0a31329SThomas Gleixner * @node: red black tree node for time ordered insertion 94c0a31329SThomas Gleixner * @expires: the absolute expiry time in the hrtimers internal 95c0a31329SThomas Gleixner * representation. The time is related to the clock on 96c0a31329SThomas Gleixner * which the timer is based. 97c0a31329SThomas Gleixner * @function: timer expiry callback function 98c0a31329SThomas Gleixner * @base: pointer to the timer base (per cpu and per clock) 99303e967fSThomas Gleixner * @state: state information (See bit values above) 10054cdfdb4SThomas Gleixner * @cb_mode: high resolution timer feature to select the callback execution 10154cdfdb4SThomas Gleixner * mode 10254cdfdb4SThomas Gleixner * @cb_entry: list head to enqueue an expired timer into the callback list 10354cdfdb4SThomas Gleixner * @start_site: timer statistics field to store the site where the timer 10454cdfdb4SThomas Gleixner * was started 10554cdfdb4SThomas Gleixner * @start_comm: timer statistics field to store the name of the process which 10654cdfdb4SThomas Gleixner * started the timer 10754cdfdb4SThomas Gleixner * @start_pid: timer statistics field to store the pid of the task which 10854cdfdb4SThomas Gleixner * started the timer 109c0a31329SThomas Gleixner * 11054cdfdb4SThomas Gleixner * The hrtimer structure must be initialized by hrtimer_init() 111c0a31329SThomas Gleixner */ 112c0a31329SThomas Gleixner struct hrtimer { 113c0a31329SThomas Gleixner struct rb_node node; 114c0a31329SThomas Gleixner ktime_t expires; 115c9cb2e3dSThomas Gleixner enum hrtimer_restart (*function)(struct hrtimer *); 1163c8aa39dSThomas Gleixner struct hrtimer_clock_base *base; 117303e967fSThomas Gleixner unsigned long state; 11854cdfdb4SThomas Gleixner struct list_head cb_entry; 119*1b024690SRichard Kennedy enum hrtimer_cb_mode cb_mode; 12082f67cd9SIngo Molnar #ifdef CONFIG_TIMER_STATS 121*1b024690SRichard Kennedy int start_pid; 12282f67cd9SIngo Molnar void *start_site; 12382f67cd9SIngo Molnar char start_comm[16]; 12482f67cd9SIngo Molnar #endif 125c0a31329SThomas Gleixner }; 126c0a31329SThomas Gleixner 127c0a31329SThomas Gleixner /** 12800362e33SThomas Gleixner * struct hrtimer_sleeper - simple sleeper structure 12900362e33SThomas Gleixner * @timer: embedded timer structure 13000362e33SThomas Gleixner * @task: task to wake up 13100362e33SThomas Gleixner * 13200362e33SThomas Gleixner * task is set to NULL, when the timer expires. 13300362e33SThomas Gleixner */ 13400362e33SThomas Gleixner struct hrtimer_sleeper { 13500362e33SThomas Gleixner struct hrtimer timer; 13600362e33SThomas Gleixner struct task_struct *task; 13700362e33SThomas Gleixner }; 13800362e33SThomas Gleixner 13900362e33SThomas Gleixner /** 140d1d67174SAndres Salomon * struct hrtimer_clock_base - the timer base for a specific clock 14105fb6bf0SRandy Dunlap * @cpu_base: per cpu clock base 1423c8aa39dSThomas Gleixner * @index: clock type index for per_cpu support when moving a 1433c8aa39dSThomas Gleixner * timer to a base on another cpu. 144c0a31329SThomas Gleixner * @active: red black tree root node for the active timers 145288867ecSThomas Gleixner * @first: pointer to the timer node which expires first 146c0a31329SThomas Gleixner * @resolution: the resolution of the clock, in nanoseconds 147c0a31329SThomas Gleixner * @get_time: function to retrieve the current time of the clock 14892127c7aSThomas Gleixner * @softirq_time: the time when running the hrtimer queue in the softirq 14954cdfdb4SThomas Gleixner * @offset: offset of this clock to the monotonic base 150c0a31329SThomas Gleixner */ 1513c8aa39dSThomas Gleixner struct hrtimer_clock_base { 1523c8aa39dSThomas Gleixner struct hrtimer_cpu_base *cpu_base; 153c0a31329SThomas Gleixner clockid_t index; 154c0a31329SThomas Gleixner struct rb_root active; 155288867ecSThomas Gleixner struct rb_node *first; 156e2787630SThomas Gleixner ktime_t resolution; 157c0a31329SThomas Gleixner ktime_t (*get_time)(void); 15892127c7aSThomas Gleixner ktime_t softirq_time; 15954cdfdb4SThomas Gleixner #ifdef CONFIG_HIGH_RES_TIMERS 16054cdfdb4SThomas Gleixner ktime_t offset; 16154cdfdb4SThomas Gleixner #endif 1623c8aa39dSThomas Gleixner }; 1633c8aa39dSThomas Gleixner 1643c8aa39dSThomas Gleixner #define HRTIMER_MAX_CLOCK_BASES 2 1653c8aa39dSThomas Gleixner 1663c8aa39dSThomas Gleixner /* 1673c8aa39dSThomas Gleixner * struct hrtimer_cpu_base - the per cpu clock bases 1683c8aa39dSThomas Gleixner * @lock: lock protecting the base and associated clock bases 1693c8aa39dSThomas Gleixner * and timers 1703c8aa39dSThomas Gleixner * @clock_base: array of clock bases for this cpu 1713c8aa39dSThomas Gleixner * @curr_timer: the timer which is executing a callback right now 17254cdfdb4SThomas Gleixner * @expires_next: absolute time of the next event which was scheduled 17354cdfdb4SThomas Gleixner * via clock_set_next_event() 17454cdfdb4SThomas Gleixner * @hres_active: State of high resolution mode 17554cdfdb4SThomas Gleixner * @check_clocks: Indictator, when set evaluate time source and clock 17654cdfdb4SThomas Gleixner * event devices whether high resolution mode can be 17754cdfdb4SThomas Gleixner * activated. 17854cdfdb4SThomas Gleixner * @cb_pending: Expired timers are moved from the rbtree to this 17954cdfdb4SThomas Gleixner * list in the timer interrupt. The list is processed 18054cdfdb4SThomas Gleixner * in the softirq. 18154cdfdb4SThomas Gleixner * @nr_events: Total number of timer interrupt events 1823c8aa39dSThomas Gleixner */ 1833c8aa39dSThomas Gleixner struct hrtimer_cpu_base { 1843c8aa39dSThomas Gleixner spinlock_t lock; 1853c8aa39dSThomas Gleixner struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; 186d3d74453SPeter Zijlstra struct list_head cb_pending; 18754cdfdb4SThomas Gleixner #ifdef CONFIG_HIGH_RES_TIMERS 18854cdfdb4SThomas Gleixner ktime_t expires_next; 18954cdfdb4SThomas Gleixner int hres_active; 19054cdfdb4SThomas Gleixner unsigned long nr_events; 19154cdfdb4SThomas Gleixner #endif 192c0a31329SThomas Gleixner }; 193c0a31329SThomas Gleixner 19454cdfdb4SThomas Gleixner #ifdef CONFIG_HIGH_RES_TIMERS 19554cdfdb4SThomas Gleixner struct clock_event_device; 19654cdfdb4SThomas Gleixner 19754cdfdb4SThomas Gleixner extern void clock_was_set(void); 198995f054fSIngo Molnar extern void hres_timers_resume(void); 19954cdfdb4SThomas Gleixner extern void hrtimer_interrupt(struct clock_event_device *dev); 20054cdfdb4SThomas Gleixner 20154cdfdb4SThomas Gleixner /* 20254cdfdb4SThomas Gleixner * In high resolution mode the time reference must be read accurate 20354cdfdb4SThomas Gleixner */ 20454cdfdb4SThomas Gleixner static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer) 20554cdfdb4SThomas Gleixner { 20654cdfdb4SThomas Gleixner return timer->base->get_time(); 20754cdfdb4SThomas Gleixner } 20854cdfdb4SThomas Gleixner 2098f4d37ecSPeter Zijlstra static inline int hrtimer_is_hres_active(struct hrtimer *timer) 2108f4d37ecSPeter Zijlstra { 2118f4d37ecSPeter Zijlstra return timer->base->cpu_base->hres_active; 2128f4d37ecSPeter Zijlstra } 2138f4d37ecSPeter Zijlstra 21454cdfdb4SThomas Gleixner /* 21554cdfdb4SThomas Gleixner * The resolution of the clocks. The resolution value is returned in 21654cdfdb4SThomas Gleixner * the clock_getres() system call to give application programmers an 21754cdfdb4SThomas Gleixner * idea of the (in)accuracy of timers. Timer values are rounded up to 21854cdfdb4SThomas Gleixner * this resolution values. 21954cdfdb4SThomas Gleixner */ 220151db1fcSTony Breeds # define HIGH_RES_NSEC 1 221151db1fcSTony Breeds # define KTIME_HIGH_RES (ktime_t) { .tv64 = HIGH_RES_NSEC } 222151db1fcSTony Breeds # define MONOTONIC_RES_NSEC HIGH_RES_NSEC 22354cdfdb4SThomas Gleixner # define KTIME_MONOTONIC_RES KTIME_HIGH_RES 22454cdfdb4SThomas Gleixner 22554cdfdb4SThomas Gleixner #else 22654cdfdb4SThomas Gleixner 227151db1fcSTony Breeds # define MONOTONIC_RES_NSEC LOW_RES_NSEC 22854cdfdb4SThomas Gleixner # define KTIME_MONOTONIC_RES KTIME_LOW_RES 22954cdfdb4SThomas Gleixner 230becf8b5dSThomas Gleixner /* 231becf8b5dSThomas Gleixner * clock_was_set() is a NOP for non- high-resolution systems. The 232becf8b5dSThomas Gleixner * time-sorted order guarantees that a timer does not expire early and 233becf8b5dSThomas Gleixner * is expired in the next softirq when the clock was advanced. 234becf8b5dSThomas Gleixner */ 23554cdfdb4SThomas Gleixner static inline void clock_was_set(void) { } 23654cdfdb4SThomas Gleixner 237995f054fSIngo Molnar static inline void hres_timers_resume(void) { } 238995f054fSIngo Molnar 23954cdfdb4SThomas Gleixner /* 24054cdfdb4SThomas Gleixner * In non high resolution mode the time reference is taken from 24154cdfdb4SThomas Gleixner * the base softirq time variable. 24254cdfdb4SThomas Gleixner */ 24354cdfdb4SThomas Gleixner static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer) 24454cdfdb4SThomas Gleixner { 24554cdfdb4SThomas Gleixner return timer->base->softirq_time; 24654cdfdb4SThomas Gleixner } 24754cdfdb4SThomas Gleixner 2488f4d37ecSPeter Zijlstra static inline int hrtimer_is_hres_active(struct hrtimer *timer) 2498f4d37ecSPeter Zijlstra { 2508f4d37ecSPeter Zijlstra return 0; 2518f4d37ecSPeter Zijlstra } 25254cdfdb4SThomas Gleixner #endif 25354cdfdb4SThomas Gleixner 254d316c57fSThomas Gleixner extern ktime_t ktime_get(void); 255d316c57fSThomas Gleixner extern ktime_t ktime_get_real(void); 256becf8b5dSThomas Gleixner 257c0a31329SThomas Gleixner /* Exported timer functions: */ 258c0a31329SThomas Gleixner 259c0a31329SThomas Gleixner /* Initialize timers: */ 2607978672cSGeorge Anzinger extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, 2617978672cSGeorge Anzinger enum hrtimer_mode mode); 262c0a31329SThomas Gleixner 263237fc6e7SThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_TIMERS 264237fc6e7SThomas Gleixner extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, 265237fc6e7SThomas Gleixner enum hrtimer_mode mode); 266237fc6e7SThomas Gleixner 267237fc6e7SThomas Gleixner extern void destroy_hrtimer_on_stack(struct hrtimer *timer); 268237fc6e7SThomas Gleixner #else 269237fc6e7SThomas Gleixner static inline void hrtimer_init_on_stack(struct hrtimer *timer, 270237fc6e7SThomas Gleixner clockid_t which_clock, 271237fc6e7SThomas Gleixner enum hrtimer_mode mode) 272237fc6e7SThomas Gleixner { 273237fc6e7SThomas Gleixner hrtimer_init(timer, which_clock, mode); 274237fc6e7SThomas Gleixner } 275237fc6e7SThomas Gleixner static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } 276237fc6e7SThomas Gleixner #endif 277237fc6e7SThomas Gleixner 278c0a31329SThomas Gleixner /* Basic timer operations: */ 279c0a31329SThomas Gleixner extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, 280c0a31329SThomas Gleixner const enum hrtimer_mode mode); 281c0a31329SThomas Gleixner extern int hrtimer_cancel(struct hrtimer *timer); 282c0a31329SThomas Gleixner extern int hrtimer_try_to_cancel(struct hrtimer *timer); 283c0a31329SThomas Gleixner 284c9cb2e3dSThomas Gleixner static inline int hrtimer_restart(struct hrtimer *timer) 285c9cb2e3dSThomas Gleixner { 286c9cb2e3dSThomas Gleixner return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS); 287c9cb2e3dSThomas Gleixner } 288c0a31329SThomas Gleixner 289c0a31329SThomas Gleixner /* Query timers: */ 290c0a31329SThomas Gleixner extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer); 291c0a31329SThomas Gleixner extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp); 292c0a31329SThomas Gleixner 29369239749STony Lindgren extern ktime_t hrtimer_get_next_event(void); 29469239749STony Lindgren 295303e967fSThomas Gleixner /* 296303e967fSThomas Gleixner * A timer is active, when it is enqueued into the rbtree or the callback 297303e967fSThomas Gleixner * function is running. 298303e967fSThomas Gleixner */ 299c0a31329SThomas Gleixner static inline int hrtimer_active(const struct hrtimer *timer) 300c0a31329SThomas Gleixner { 301303e967fSThomas Gleixner return timer->state != HRTIMER_STATE_INACTIVE; 302c0a31329SThomas Gleixner } 303c0a31329SThomas Gleixner 30454cdfdb4SThomas Gleixner /* 30554cdfdb4SThomas Gleixner * Helper function to check, whether the timer is on one of the queues 30654cdfdb4SThomas Gleixner */ 30754cdfdb4SThomas Gleixner static inline int hrtimer_is_queued(struct hrtimer *timer) 30854cdfdb4SThomas Gleixner { 30954cdfdb4SThomas Gleixner return timer->state & 31054cdfdb4SThomas Gleixner (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING); 31154cdfdb4SThomas Gleixner } 31254cdfdb4SThomas Gleixner 3134346f654SOliver Hartkopp /* 3144346f654SOliver Hartkopp * Helper function to check, whether the timer is running the callback 3154346f654SOliver Hartkopp * function 3164346f654SOliver Hartkopp */ 3174346f654SOliver Hartkopp static inline int hrtimer_callback_running(struct hrtimer *timer) 3184346f654SOliver Hartkopp { 3194346f654SOliver Hartkopp return timer->state & HRTIMER_STATE_CALLBACK; 3204346f654SOliver Hartkopp } 3214346f654SOliver Hartkopp 322c0a31329SThomas Gleixner /* Forward a hrtimer so it expires after now: */ 3234d672e7aSDavide Libenzi extern u64 32444f21475SRoman Zippel hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); 325c0a31329SThomas Gleixner 3265e05ad7dSDavide Libenzi /* Forward a hrtimer so it expires after the hrtimer's current now */ 3274d672e7aSDavide Libenzi static inline u64 hrtimer_forward_now(struct hrtimer *timer, 3285e05ad7dSDavide Libenzi ktime_t interval) 3295e05ad7dSDavide Libenzi { 3305e05ad7dSDavide Libenzi return hrtimer_forward(timer, timer->base->get_time(), interval); 3315e05ad7dSDavide Libenzi } 3325e05ad7dSDavide Libenzi 33310c94ec1SThomas Gleixner /* Precise sleep: */ 33410c94ec1SThomas Gleixner extern long hrtimer_nanosleep(struct timespec *rqtp, 335080344b9SOleg Nesterov struct timespec __user *rmtp, 33610c94ec1SThomas Gleixner const enum hrtimer_mode mode, 33710c94ec1SThomas Gleixner const clockid_t clockid); 3381711ef38SToyo Abe extern long hrtimer_nanosleep_restart(struct restart_block *restart_block); 33910c94ec1SThomas Gleixner 34000362e33SThomas Gleixner extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, 34100362e33SThomas Gleixner struct task_struct *tsk); 34200362e33SThomas Gleixner 343c0a31329SThomas Gleixner /* Soft interrupt function to run the hrtimer queues: */ 344c0a31329SThomas Gleixner extern void hrtimer_run_queues(void); 345d3d74453SPeter Zijlstra extern void hrtimer_run_pending(void); 346c0a31329SThomas Gleixner 347c0a31329SThomas Gleixner /* Bootup initialization: */ 348c0a31329SThomas Gleixner extern void __init hrtimers_init(void); 349c0a31329SThomas Gleixner 35079bf2bb3SThomas Gleixner #if BITS_PER_LONG < 64 3514d672e7aSDavide Libenzi extern u64 ktime_divns(const ktime_t kt, s64 div); 35279bf2bb3SThomas Gleixner #else /* BITS_PER_LONG < 64 */ 3534d672e7aSDavide Libenzi # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) 35479bf2bb3SThomas Gleixner #endif 35579bf2bb3SThomas Gleixner 35688ad0bf6SIngo Molnar /* Show pending timers: */ 35788ad0bf6SIngo Molnar extern void sysrq_timer_list_show(void); 35888ad0bf6SIngo Molnar 35982f67cd9SIngo Molnar /* 36082f67cd9SIngo Molnar * Timer-statistics info: 36182f67cd9SIngo Molnar */ 36282f67cd9SIngo Molnar #ifdef CONFIG_TIMER_STATS 36382f67cd9SIngo Molnar 36482f67cd9SIngo Molnar extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf, 365c5c061b8SVenki Pallipadi void *timerf, char *comm, 366c5c061b8SVenki Pallipadi unsigned int timer_flag); 36782f67cd9SIngo Molnar 36882f67cd9SIngo Molnar static inline void timer_stats_account_hrtimer(struct hrtimer *timer) 36982f67cd9SIngo Molnar { 37082f67cd9SIngo Molnar timer_stats_update_stats(timer, timer->start_pid, timer->start_site, 371c5c061b8SVenki Pallipadi timer->function, timer->start_comm, 0); 37282f67cd9SIngo Molnar } 37382f67cd9SIngo Molnar 37482f67cd9SIngo Molnar extern void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer, 37582f67cd9SIngo Molnar void *addr); 37682f67cd9SIngo Molnar 37782f67cd9SIngo Molnar static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer) 37882f67cd9SIngo Molnar { 37982f67cd9SIngo Molnar __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0)); 38082f67cd9SIngo Molnar } 38182f67cd9SIngo Molnar 38282f67cd9SIngo Molnar static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer) 38382f67cd9SIngo Molnar { 38482f67cd9SIngo Molnar timer->start_site = NULL; 38582f67cd9SIngo Molnar } 38682f67cd9SIngo Molnar #else 38782f67cd9SIngo Molnar static inline void timer_stats_account_hrtimer(struct hrtimer *timer) 38882f67cd9SIngo Molnar { 38982f67cd9SIngo Molnar } 39082f67cd9SIngo Molnar 39182f67cd9SIngo Molnar static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer) 39282f67cd9SIngo Molnar { 39382f67cd9SIngo Molnar } 39482f67cd9SIngo Molnar 39582f67cd9SIngo Molnar static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer) 39682f67cd9SIngo Molnar { 39782f67cd9SIngo Molnar } 39882f67cd9SIngo Molnar #endif 39982f67cd9SIngo Molnar 400c0a31329SThomas Gleixner #endif 401