135728b82SThomas Gleixner // SPDX-License-Identifier: GPL-2.0 2c0a31329SThomas Gleixner /* 3c0a31329SThomas Gleixner * hrtimers - High-resolution kernel timers 4c0a31329SThomas Gleixner * 5c0a31329SThomas Gleixner * Copyright(C) 2005, Thomas Gleixner <[email protected]> 6c0a31329SThomas Gleixner * Copyright(C) 2005, Red Hat, Inc., Ingo Molnar 7c0a31329SThomas Gleixner * 8c0a31329SThomas Gleixner * data type definitions, declarations, prototypes 9c0a31329SThomas Gleixner * 10c0a31329SThomas Gleixner * Started by: Thomas Gleixner and Ingo Molnar 11c0a31329SThomas Gleixner */ 12c0a31329SThomas Gleixner #ifndef _LINUX_HRTIMER_H 13c0a31329SThomas Gleixner #define _LINUX_HRTIMER_H 14c0a31329SThomas Gleixner 1532e29396SVincenzo Frascino #include <linux/hrtimer_defs.h> 1650d91c76SKent Overstreet #include <linux/hrtimer_types.h> 17c0a31329SThomas Gleixner #include <linux/init.h> 18c0a31329SThomas Gleixner #include <linux/list.h> 196060ef31SKent Overstreet #include <linux/percpu-defs.h> 2050d91c76SKent Overstreet #include <linux/rbtree.h> 21507e1231SHeiko Carstens #include <linux/timer.h> 22c0a31329SThomas Gleixner 23c0a31329SThomas Gleixner /* 24c0a31329SThomas Gleixner * Mode arguments of xxx_hrtimer functions: 2519b51cb5SAnna-Maria Gleixner * 2619b51cb5SAnna-Maria Gleixner * HRTIMER_MODE_ABS - Time value is absolute 2719b51cb5SAnna-Maria Gleixner * HRTIMER_MODE_REL - Time value is relative to now 2819b51cb5SAnna-Maria Gleixner * HRTIMER_MODE_PINNED - Timer is bound to CPU (is only considered 2919b51cb5SAnna-Maria Gleixner * when starting the timer) 3098ecadd4SAnna-Maria Gleixner * HRTIMER_MODE_SOFT - Timer callback function will be executed in 3198ecadd4SAnna-Maria Gleixner * soft irq context 32a67e4082SSebastian Andrzej Siewior * HRTIMER_MODE_HARD - Timer callback function will be executed in 33a67e4082SSebastian Andrzej Siewior * hard irq context even on PREEMPT_RT. 34c0a31329SThomas Gleixner */ 35c0a31329SThomas Gleixner enum hrtimer_mode { 3619b51cb5SAnna-Maria Gleixner HRTIMER_MODE_ABS = 0x00, 3719b51cb5SAnna-Maria Gleixner HRTIMER_MODE_REL = 0x01, 3819b51cb5SAnna-Maria Gleixner HRTIMER_MODE_PINNED = 0x02, 3998ecadd4SAnna-Maria Gleixner HRTIMER_MODE_SOFT = 0x04, 40ae6683d8SSebastian Andrzej Siewior HRTIMER_MODE_HARD = 0x08, 4119b51cb5SAnna-Maria Gleixner 4219b51cb5SAnna-Maria Gleixner HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED, 4319b51cb5SAnna-Maria Gleixner HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED, 4498ecadd4SAnna-Maria Gleixner 4598ecadd4SAnna-Maria Gleixner HRTIMER_MODE_ABS_SOFT = HRTIMER_MODE_ABS | HRTIMER_MODE_SOFT, 4698ecadd4SAnna-Maria Gleixner HRTIMER_MODE_REL_SOFT = HRTIMER_MODE_REL | HRTIMER_MODE_SOFT, 4798ecadd4SAnna-Maria Gleixner 4898ecadd4SAnna-Maria Gleixner HRTIMER_MODE_ABS_PINNED_SOFT = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_SOFT, 4998ecadd4SAnna-Maria Gleixner HRTIMER_MODE_REL_PINNED_SOFT = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_SOFT, 5098ecadd4SAnna-Maria Gleixner 51ae6683d8SSebastian Andrzej Siewior HRTIMER_MODE_ABS_HARD = HRTIMER_MODE_ABS | HRTIMER_MODE_HARD, 52ae6683d8SSebastian Andrzej Siewior HRTIMER_MODE_REL_HARD = HRTIMER_MODE_REL | HRTIMER_MODE_HARD, 53ae6683d8SSebastian Andrzej Siewior 54ae6683d8SSebastian Andrzej Siewior HRTIMER_MODE_ABS_PINNED_HARD = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_HARD, 55ae6683d8SSebastian Andrzej Siewior HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD, 56c0a31329SThomas Gleixner }; 57c0a31329SThomas Gleixner 58c9cb2e3dSThomas Gleixner /* 5954cdfdb4SThomas Gleixner * Values to track state of the timer 60303e967fSThomas Gleixner * 61303e967fSThomas Gleixner * Possible states: 62303e967fSThomas Gleixner * 63303e967fSThomas Gleixner * 0x00 inactive 64303e967fSThomas Gleixner * 0x01 enqueued into rbtree 6554cdfdb4SThomas Gleixner * 66887d9dc9SPeter Zijlstra * The callback state is not part of the timer->state because clearing it would 67887d9dc9SPeter Zijlstra * mean touching the timer after the callback, this makes it impossible to free 68887d9dc9SPeter Zijlstra * the timer from the callback function. 6953370d2eSThomas Gleixner * 70887d9dc9SPeter Zijlstra * Therefore we track the callback state in: 71887d9dc9SPeter Zijlstra * 72887d9dc9SPeter Zijlstra * timer->base->cpu_base->running == timer 73887d9dc9SPeter Zijlstra * 74887d9dc9SPeter Zijlstra * On SMP it is possible to have a "callback function running and enqueued" 75887d9dc9SPeter Zijlstra * status. It happens for example when a posix timer expired and the callback 76303e967fSThomas Gleixner * queued a signal. Between dropping the lock which protects the posix timer 77303e967fSThomas Gleixner * and reacquiring the base lock of the hrtimer, another CPU can deliver the 78887d9dc9SPeter Zijlstra * signal and rearm the timer. 79303e967fSThomas Gleixner * 80303e967fSThomas Gleixner * All state transitions are protected by cpu_base->lock. 81303e967fSThomas Gleixner */ 82303e967fSThomas Gleixner #define HRTIMER_STATE_INACTIVE 0x00 83303e967fSThomas Gleixner #define HRTIMER_STATE_ENQUEUED 0x01 84303e967fSThomas Gleixner 85c0a31329SThomas Gleixner /** 8600362e33SThomas Gleixner * struct hrtimer_sleeper - simple sleeper structure 8700362e33SThomas Gleixner * @timer: embedded timer structure 8800362e33SThomas Gleixner * @task: task to wake up 8900362e33SThomas Gleixner * 9000362e33SThomas Gleixner * task is set to NULL, when the timer expires. 9100362e33SThomas Gleixner */ 9200362e33SThomas Gleixner struct hrtimer_sleeper { 9300362e33SThomas Gleixner struct hrtimer timer; 9400362e33SThomas Gleixner struct task_struct *task; 9500362e33SThomas Gleixner }; 9600362e33SThomas Gleixner 9763ca243bSArjan van de Ven static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time) 9863ca243bSArjan van de Ven { 99998adc3dSJohn Stultz timer->node.expires = time; 100654c8e0bSArjan van de Ven timer->_softexpires = time; 10163ca243bSArjan van de Ven } 102654c8e0bSArjan van de Ven 103654c8e0bSArjan van de Ven static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta) 104654c8e0bSArjan van de Ven { 105654c8e0bSArjan van de Ven timer->_softexpires = time; 106998adc3dSJohn Stultz timer->node.expires = ktime_add_safe(time, delta); 107654c8e0bSArjan van de Ven } 108654c8e0bSArjan van de Ven 109da8b44d5SJohn Stultz static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, u64 delta) 110654c8e0bSArjan van de Ven { 111654c8e0bSArjan van de Ven timer->_softexpires = time; 112998adc3dSJohn Stultz timer->node.expires = ktime_add_safe(time, ns_to_ktime(delta)); 113654c8e0bSArjan van de Ven } 114654c8e0bSArjan van de Ven 11563ca243bSArjan van de Ven static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64) 11663ca243bSArjan van de Ven { 1172456e855SThomas Gleixner timer->node.expires = tv64; 1182456e855SThomas Gleixner timer->_softexpires = tv64; 11963ca243bSArjan van de Ven } 12063ca243bSArjan van de Ven 12163ca243bSArjan van de Ven static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time) 12263ca243bSArjan van de Ven { 123998adc3dSJohn Stultz timer->node.expires = ktime_add_safe(timer->node.expires, time); 124654c8e0bSArjan van de Ven timer->_softexpires = ktime_add_safe(timer->_softexpires, time); 12563ca243bSArjan van de Ven } 12663ca243bSArjan van de Ven 1277597bc94SDavid Howells static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns) 12863ca243bSArjan van de Ven { 129998adc3dSJohn Stultz timer->node.expires = ktime_add_ns(timer->node.expires, ns); 130654c8e0bSArjan van de Ven timer->_softexpires = ktime_add_ns(timer->_softexpires, ns); 13163ca243bSArjan van de Ven } 13263ca243bSArjan van de Ven 13363ca243bSArjan van de Ven static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer) 13463ca243bSArjan van de Ven { 135998adc3dSJohn Stultz return timer->node.expires; 13663ca243bSArjan van de Ven } 13763ca243bSArjan van de Ven 138654c8e0bSArjan van de Ven static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer) 139654c8e0bSArjan van de Ven { 140654c8e0bSArjan van de Ven return timer->_softexpires; 141654c8e0bSArjan van de Ven } 142654c8e0bSArjan van de Ven 14363ca243bSArjan van de Ven static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer) 14463ca243bSArjan van de Ven { 1452456e855SThomas Gleixner return timer->node.expires; 14663ca243bSArjan van de Ven } 147654c8e0bSArjan van de Ven static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer) 148654c8e0bSArjan van de Ven { 1492456e855SThomas Gleixner return timer->_softexpires; 150654c8e0bSArjan van de Ven } 15163ca243bSArjan van de Ven 15263ca243bSArjan van de Ven static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer) 15363ca243bSArjan van de Ven { 154998adc3dSJohn Stultz return ktime_to_ns(timer->node.expires); 15563ca243bSArjan van de Ven } 15663ca243bSArjan van de Ven 15763ca243bSArjan van de Ven static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer) 15863ca243bSArjan van de Ven { 159998adc3dSJohn Stultz return ktime_sub(timer->node.expires, timer->base->get_time()); 16063ca243bSArjan van de Ven } 16163ca243bSArjan van de Ven 16254cdfdb4SThomas Gleixner static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer) 16354cdfdb4SThomas Gleixner { 16454cdfdb4SThomas Gleixner return timer->base->get_time(); 16554cdfdb4SThomas Gleixner } 16654cdfdb4SThomas Gleixner 16728bfd18bSAnna-Maria Gleixner static inline int hrtimer_is_hres_active(struct hrtimer *timer) 16828bfd18bSAnna-Maria Gleixner { 16928bfd18bSAnna-Maria Gleixner return IS_ENABLED(CONFIG_HIGH_RES_TIMERS) ? 17028bfd18bSAnna-Maria Gleixner timer->base->cpu_base->hres_active : 0; 17128bfd18bSAnna-Maria Gleixner } 17228bfd18bSAnna-Maria Gleixner 17321d6d52aSThomas Gleixner #ifdef CONFIG_HIGH_RES_TIMERS 17421d6d52aSThomas Gleixner struct clock_event_device; 17521d6d52aSThomas Gleixner 17621d6d52aSThomas Gleixner extern void hrtimer_interrupt(struct clock_event_device *dev); 17721d6d52aSThomas Gleixner 178398ca17fSThomas Gleixner extern unsigned int hrtimer_resolution; 179398ca17fSThomas Gleixner 18054cdfdb4SThomas Gleixner #else 18154cdfdb4SThomas Gleixner 182d711b8b3SBorislav Petkov #define hrtimer_resolution (unsigned int)LOW_RES_NSEC 183398ca17fSThomas Gleixner 18454cdfdb4SThomas Gleixner #endif 18554cdfdb4SThomas Gleixner 186203cbf77SThomas Gleixner static inline ktime_t 187203cbf77SThomas Gleixner __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now) 188203cbf77SThomas Gleixner { 189203cbf77SThomas Gleixner ktime_t rem = ktime_sub(timer->node.expires, now); 190203cbf77SThomas Gleixner 191203cbf77SThomas Gleixner /* 192203cbf77SThomas Gleixner * Adjust relative timers for the extra we added in 193203cbf77SThomas Gleixner * hrtimer_start_range_ns() to prevent short timeouts. 194203cbf77SThomas Gleixner */ 195203cbf77SThomas Gleixner if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel) 1962456e855SThomas Gleixner rem -= hrtimer_resolution; 197203cbf77SThomas Gleixner return rem; 198203cbf77SThomas Gleixner } 199203cbf77SThomas Gleixner 200203cbf77SThomas Gleixner static inline ktime_t 201203cbf77SThomas Gleixner hrtimer_expires_remaining_adjusted(const struct hrtimer *timer) 202203cbf77SThomas Gleixner { 203203cbf77SThomas Gleixner return __hrtimer_expires_remaining_adjusted(timer, 204203cbf77SThomas Gleixner timer->base->get_time()); 205203cbf77SThomas Gleixner } 206203cbf77SThomas Gleixner 2079ec26907SThomas Gleixner #ifdef CONFIG_TIMERFD 2089ec26907SThomas Gleixner extern void timerfd_clock_was_set(void); 20966f7b0c8SThomas Gleixner extern void timerfd_resume(void); 2109ec26907SThomas Gleixner #else 2119ec26907SThomas Gleixner static inline void timerfd_clock_was_set(void) { } 21266f7b0c8SThomas Gleixner static inline void timerfd_resume(void) { } 2139ec26907SThomas Gleixner #endif 214b12a03ceSThomas Gleixner 2152e94d1f7SArjan van de Ven DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 2162e94d1f7SArjan van de Ven 217f61eff83SAnna-Maria Gleixner #ifdef CONFIG_PREEMPT_RT 218f61eff83SAnna-Maria Gleixner void hrtimer_cancel_wait_running(const struct hrtimer *timer); 219f61eff83SAnna-Maria Gleixner #else 220f61eff83SAnna-Maria Gleixner static inline void hrtimer_cancel_wait_running(struct hrtimer *timer) 221f61eff83SAnna-Maria Gleixner { 222f61eff83SAnna-Maria Gleixner cpu_relax(); 223f61eff83SAnna-Maria Gleixner } 224f61eff83SAnna-Maria Gleixner #endif 2252e94d1f7SArjan van de Ven 226c0a31329SThomas Gleixner /* Exported timer functions: */ 227c0a31329SThomas Gleixner 228c0a31329SThomas Gleixner /* Initialize timers: */ 2297978672cSGeorge Anzinger extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, 2307978672cSGeorge Anzinger enum hrtimer_mode mode); 231dbc1625fSSebastian Andrzej Siewior extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, 232dbc1625fSSebastian Andrzej Siewior enum hrtimer_mode mode); 233c0a31329SThomas Gleixner 234237fc6e7SThomas Gleixner #ifdef CONFIG_DEBUG_OBJECTS_TIMERS 235237fc6e7SThomas Gleixner extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, 236237fc6e7SThomas Gleixner enum hrtimer_mode mode); 237dbc1625fSSebastian Andrzej Siewior extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, 238dbc1625fSSebastian Andrzej Siewior clockid_t clock_id, 239dbc1625fSSebastian Andrzej Siewior enum hrtimer_mode mode); 240237fc6e7SThomas Gleixner 241237fc6e7SThomas Gleixner extern void destroy_hrtimer_on_stack(struct hrtimer *timer); 242237fc6e7SThomas Gleixner #else 243237fc6e7SThomas Gleixner static inline void hrtimer_init_on_stack(struct hrtimer *timer, 244237fc6e7SThomas Gleixner clockid_t which_clock, 245237fc6e7SThomas Gleixner enum hrtimer_mode mode) 246237fc6e7SThomas Gleixner { 247237fc6e7SThomas Gleixner hrtimer_init(timer, which_clock, mode); 248237fc6e7SThomas Gleixner } 249dbc1625fSSebastian Andrzej Siewior 250dbc1625fSSebastian Andrzej Siewior static inline void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, 251dbc1625fSSebastian Andrzej Siewior clockid_t clock_id, 252dbc1625fSSebastian Andrzej Siewior enum hrtimer_mode mode) 253dbc1625fSSebastian Andrzej Siewior { 254dbc1625fSSebastian Andrzej Siewior hrtimer_init_sleeper(sl, clock_id, mode); 255dbc1625fSSebastian Andrzej Siewior } 256dbc1625fSSebastian Andrzej Siewior 257237fc6e7SThomas Gleixner static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } 258237fc6e7SThomas Gleixner #endif 259237fc6e7SThomas Gleixner 260c0a31329SThomas Gleixner /* Basic timer operations: */ 26161699e13SThomas Gleixner extern void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, 262da8b44d5SJohn Stultz u64 range_ns, const enum hrtimer_mode mode); 2637f1e2ca9SPeter Zijlstra 26402a171afSThomas Gleixner /** 2656de6250cSAnna-Maria Gleixner * hrtimer_start - (re)start an hrtimer 26602a171afSThomas Gleixner * @timer: the timer to be added 26702a171afSThomas Gleixner * @tim: expiry time 2686de6250cSAnna-Maria Gleixner * @mode: timer mode: absolute (HRTIMER_MODE_ABS) or 2695da70160SAnna-Maria Gleixner * relative (HRTIMER_MODE_REL), and pinned (HRTIMER_MODE_PINNED); 2705da70160SAnna-Maria Gleixner * softirq based mode is considered for debug purpose only! 27102a171afSThomas Gleixner */ 27261699e13SThomas Gleixner static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim, 27302a171afSThomas Gleixner const enum hrtimer_mode mode) 27402a171afSThomas Gleixner { 27561699e13SThomas Gleixner hrtimer_start_range_ns(timer, tim, 0, mode); 27602a171afSThomas Gleixner } 27702a171afSThomas Gleixner 278c0a31329SThomas Gleixner extern int hrtimer_cancel(struct hrtimer *timer); 279c0a31329SThomas Gleixner extern int hrtimer_try_to_cancel(struct hrtimer *timer); 280c0a31329SThomas Gleixner 28161699e13SThomas Gleixner static inline void hrtimer_start_expires(struct hrtimer *timer, 28263ca243bSArjan van de Ven enum hrtimer_mode mode) 28363ca243bSArjan van de Ven { 284da8b44d5SJohn Stultz u64 delta; 285da8f2e17SArjan van de Ven ktime_t soft, hard; 286da8f2e17SArjan van de Ven soft = hrtimer_get_softexpires(timer); 287da8f2e17SArjan van de Ven hard = hrtimer_get_expires(timer); 288da8f2e17SArjan van de Ven delta = ktime_to_ns(ktime_sub(hard, soft)); 28961699e13SThomas Gleixner hrtimer_start_range_ns(timer, soft, delta, mode); 29063ca243bSArjan van de Ven } 29163ca243bSArjan van de Ven 29201656464SThomas Gleixner void hrtimer_sleeper_start_expires(struct hrtimer_sleeper *sl, 29301656464SThomas Gleixner enum hrtimer_mode mode); 29401656464SThomas Gleixner 29561699e13SThomas Gleixner static inline void hrtimer_restart(struct hrtimer *timer) 296c9cb2e3dSThomas Gleixner { 29761699e13SThomas Gleixner hrtimer_start_expires(timer, HRTIMER_MODE_ABS); 298c9cb2e3dSThomas Gleixner } 299c0a31329SThomas Gleixner 300c0a31329SThomas Gleixner /* Query timers: */ 301203cbf77SThomas Gleixner extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust); 302203cbf77SThomas Gleixner 30366981c37SMauro Carvalho Chehab /** 30466981c37SMauro Carvalho Chehab * hrtimer_get_remaining - get remaining time for the timer 30566981c37SMauro Carvalho Chehab * @timer: the timer to read 30666981c37SMauro Carvalho Chehab */ 307203cbf77SThomas Gleixner static inline ktime_t hrtimer_get_remaining(const struct hrtimer *timer) 308203cbf77SThomas Gleixner { 309203cbf77SThomas Gleixner return __hrtimer_get_remaining(timer, false); 310203cbf77SThomas Gleixner } 311c0a31329SThomas Gleixner 312c1ad348bSThomas Gleixner extern u64 hrtimer_get_next_event(void); 313a59855cdSRafael J. Wysocki extern u64 hrtimer_next_event_without(const struct hrtimer *exclude); 31469239749STony Lindgren 315887d9dc9SPeter Zijlstra extern bool hrtimer_active(const struct hrtimer *timer); 316c0a31329SThomas Gleixner 31756144737SEric Dumazet /** 31866981c37SMauro Carvalho Chehab * hrtimer_is_queued - check, whether the timer is on one of the queues 31956144737SEric Dumazet * @timer: Timer to check 32056144737SEric Dumazet * 32156144737SEric Dumazet * Returns: True if the timer is queued, false otherwise 32256144737SEric Dumazet * 32356144737SEric Dumazet * The function can be used lockless, but it gives only a current snapshot. 32454cdfdb4SThomas Gleixner */ 32556144737SEric Dumazet static inline bool hrtimer_is_queued(struct hrtimer *timer) 32654cdfdb4SThomas Gleixner { 32756144737SEric Dumazet /* The READ_ONCE pairs with the update functions of timer->state */ 32856144737SEric Dumazet return !!(READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED); 32954cdfdb4SThomas Gleixner } 33054cdfdb4SThomas Gleixner 3314346f654SOliver Hartkopp /* 3324346f654SOliver Hartkopp * Helper function to check, whether the timer is running the callback 3334346f654SOliver Hartkopp * function 3344346f654SOliver Hartkopp */ 3354346f654SOliver Hartkopp static inline int hrtimer_callback_running(struct hrtimer *timer) 3364346f654SOliver Hartkopp { 3373f0b9e8eSAnna-Maria Gleixner return timer->base->running == timer; 3384346f654SOliver Hartkopp } 3394346f654SOliver Hartkopp 340c0a31329SThomas Gleixner /* Forward a hrtimer so it expires after now: */ 3414d672e7aSDavide Libenzi extern u64 34244f21475SRoman Zippel hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); 343c0a31329SThomas Gleixner 34491e5a217SThomas Gleixner /** 345*ca2768bbSAnna-Maria Behnsen * hrtimer_forward_now() - forward the timer expiry so it expires after now 34691e5a217SThomas Gleixner * @timer: hrtimer to forward 34791e5a217SThomas Gleixner * @interval: the interval to forward 34891e5a217SThomas Gleixner * 349*ca2768bbSAnna-Maria Behnsen * It is a variant of hrtimer_forward(). The timer will expire after the current 350*ca2768bbSAnna-Maria Behnsen * time of the hrtimer clock base. See hrtimer_forward() for details. 35191e5a217SThomas Gleixner */ 3524d672e7aSDavide Libenzi static inline u64 hrtimer_forward_now(struct hrtimer *timer, 3535e05ad7dSDavide Libenzi ktime_t interval) 3545e05ad7dSDavide Libenzi { 3555e05ad7dSDavide Libenzi return hrtimer_forward(timer, timer->base->get_time(), interval); 3565e05ad7dSDavide Libenzi } 3575e05ad7dSDavide Libenzi 35810c94ec1SThomas Gleixner /* Precise sleep: */ 359ce41aaf4SAl Viro 360c0edd7c9SDeepa Dinamani extern int nanosleep_copyout(struct restart_block *, struct timespec64 *); 361ea2d1f7fSAndrei Vagin extern long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode, 36210c94ec1SThomas Gleixner const clockid_t clockid); 36310c94ec1SThomas Gleixner 364da8b44d5SJohn Stultz extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta, 365654c8e0bSArjan van de Ven const enum hrtimer_mode mode); 366351b3f7aSCarsten Emde extern int schedule_hrtimeout_range_clock(ktime_t *expires, 367da8b44d5SJohn Stultz u64 delta, 368da8b44d5SJohn Stultz const enum hrtimer_mode mode, 36990777713SAnna-Maria Gleixner clockid_t clock_id); 3707bb67439SArjan van de Ven extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode); 3717bb67439SArjan van de Ven 372c0a31329SThomas Gleixner /* Soft interrupt function to run the hrtimer queues: */ 373c0a31329SThomas Gleixner extern void hrtimer_run_queues(void); 374c0a31329SThomas Gleixner 375c0a31329SThomas Gleixner /* Bootup initialization: */ 376c0a31329SThomas Gleixner extern void __init hrtimers_init(void); 377c0a31329SThomas Gleixner 37888ad0bf6SIngo Molnar /* Show pending timers: */ 37988ad0bf6SIngo Molnar extern void sysrq_timer_list_show(void); 38088ad0bf6SIngo Molnar 38127590dc1SThomas Gleixner int hrtimers_prepare_cpu(unsigned int cpu); 38227590dc1SThomas Gleixner #ifdef CONFIG_HOTPLUG_CPU 3835c0930ccSThomas Gleixner int hrtimers_cpu_dying(unsigned int cpu); 38427590dc1SThomas Gleixner #else 3855c0930ccSThomas Gleixner #define hrtimers_cpu_dying NULL 38627590dc1SThomas Gleixner #endif 38727590dc1SThomas Gleixner 388c0a31329SThomas Gleixner #endif 389