Thomas Gleixner | 35728b8 | 2018-10-31 19:21:09 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 2 | /* |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 3 | * hrtimers - High-resolution kernel timers |
| 4 | * |
| 5 | * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de> |
| 6 | * Copyright(C) 2005, Red Hat, Inc., Ingo Molnar |
| 7 | * |
| 8 | * data type definitions, declarations, prototypes |
| 9 | * |
| 10 | * Started by: Thomas Gleixner and Ingo Molnar |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 11 | */ |
| 12 | #ifndef _LINUX_HRTIMER_H |
| 13 | #define _LINUX_HRTIMER_H |
| 14 | |
Vincenzo Frascino | 32e2939 | 2019-06-22 15:02:07 +0200 | [diff] [blame] | 15 | #include <linux/hrtimer_defs.h> |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 16 | #include <linux/rbtree.h> |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/list.h> |
Stephen Rothwell | 40b8606 | 2008-10-15 14:20:28 +1100 | [diff] [blame] | 19 | #include <linux/percpu.h> |
Heiko Carstens | 507e123 | 2009-06-23 17:38:15 +0200 | [diff] [blame] | 20 | #include <linux/timer.h> |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 21 | #include <linux/timerqueue.h> |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 22 | |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 23 | struct hrtimer_clock_base; |
| 24 | struct hrtimer_cpu_base; |
| 25 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 26 | /* |
| 27 | * Mode arguments of xxx_hrtimer functions: |
Anna-Maria Gleixner | 19b51cb | 2017-12-21 11:41:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * HRTIMER_MODE_ABS - Time value is absolute |
| 30 | * HRTIMER_MODE_REL - Time value is relative to now |
| 31 | * HRTIMER_MODE_PINNED - Timer is bound to CPU (is only considered |
| 32 | * when starting the timer) |
Anna-Maria Gleixner | 98ecadd | 2017-12-21 11:41:55 +0100 | [diff] [blame] | 33 | * HRTIMER_MODE_SOFT - Timer callback function will be executed in |
| 34 | * soft irq context |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 35 | */ |
| 36 | enum hrtimer_mode { |
Anna-Maria Gleixner | 19b51cb | 2017-12-21 11:41:36 +0100 | [diff] [blame] | 37 | HRTIMER_MODE_ABS = 0x00, |
| 38 | HRTIMER_MODE_REL = 0x01, |
| 39 | HRTIMER_MODE_PINNED = 0x02, |
Anna-Maria Gleixner | 98ecadd | 2017-12-21 11:41:55 +0100 | [diff] [blame] | 40 | HRTIMER_MODE_SOFT = 0x04, |
Sebastian Andrzej Siewior | ae6683d | 2019-07-26 20:30:51 +0200 | [diff] [blame] | 41 | HRTIMER_MODE_HARD = 0x08, |
Anna-Maria Gleixner | 19b51cb | 2017-12-21 11:41:36 +0100 | [diff] [blame] | 42 | |
| 43 | HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED, |
| 44 | HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED, |
Anna-Maria Gleixner | 98ecadd | 2017-12-21 11:41:55 +0100 | [diff] [blame] | 45 | |
| 46 | HRTIMER_MODE_ABS_SOFT = HRTIMER_MODE_ABS | HRTIMER_MODE_SOFT, |
| 47 | HRTIMER_MODE_REL_SOFT = HRTIMER_MODE_REL | HRTIMER_MODE_SOFT, |
| 48 | |
| 49 | HRTIMER_MODE_ABS_PINNED_SOFT = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_SOFT, |
| 50 | HRTIMER_MODE_REL_PINNED_SOFT = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_SOFT, |
| 51 | |
Sebastian Andrzej Siewior | ae6683d | 2019-07-26 20:30:51 +0200 | [diff] [blame] | 52 | HRTIMER_MODE_ABS_HARD = HRTIMER_MODE_ABS | HRTIMER_MODE_HARD, |
| 53 | HRTIMER_MODE_REL_HARD = HRTIMER_MODE_REL | HRTIMER_MODE_HARD, |
| 54 | |
| 55 | HRTIMER_MODE_ABS_PINNED_HARD = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_HARD, |
| 56 | HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD, |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 59 | /* |
| 60 | * Return values for the callback function |
| 61 | */ |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 62 | enum hrtimer_restart { |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 63 | HRTIMER_NORESTART, /* Timer is not restarted */ |
| 64 | HRTIMER_RESTART, /* Timer must be restarted */ |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 67 | /* |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 68 | * Values to track state of the timer |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 69 | * |
| 70 | * Possible states: |
| 71 | * |
| 72 | * 0x00 inactive |
| 73 | * 0x01 enqueued into rbtree |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 74 | * |
Peter Zijlstra | 887d9dc | 2015-06-11 14:46:48 +0200 | [diff] [blame] | 75 | * The callback state is not part of the timer->state because clearing it would |
| 76 | * mean touching the timer after the callback, this makes it impossible to free |
| 77 | * the timer from the callback function. |
Thomas Gleixner | 53370d2 | 2011-03-10 18:26:33 +0100 | [diff] [blame] | 78 | * |
Peter Zijlstra | 887d9dc | 2015-06-11 14:46:48 +0200 | [diff] [blame] | 79 | * Therefore we track the callback state in: |
| 80 | * |
| 81 | * timer->base->cpu_base->running == timer |
| 82 | * |
| 83 | * On SMP it is possible to have a "callback function running and enqueued" |
| 84 | * status. It happens for example when a posix timer expired and the callback |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 85 | * queued a signal. Between dropping the lock which protects the posix timer |
| 86 | * and reacquiring the base lock of the hrtimer, another CPU can deliver the |
Peter Zijlstra | 887d9dc | 2015-06-11 14:46:48 +0200 | [diff] [blame] | 87 | * signal and rearm the timer. |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 88 | * |
| 89 | * All state transitions are protected by cpu_base->lock. |
| 90 | */ |
| 91 | #define HRTIMER_STATE_INACTIVE 0x00 |
| 92 | #define HRTIMER_STATE_ENQUEUED 0x01 |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 93 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 94 | /** |
| 95 | * struct hrtimer - the basic hrtimer structure |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 96 | * @node: timerqueue node, which also manages node.expires, |
| 97 | * the absolute expiry time in the hrtimers internal |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 98 | * representation. The time is related to the clock on |
Thomas Gleixner | 592aa99 | 2008-10-20 16:38:19 +0200 | [diff] [blame] | 99 | * which the timer is based. Is setup by adding |
| 100 | * slack to the _softexpires value. For non range timers |
| 101 | * identical to _softexpires. |
| 102 | * @_softexpires: the absolute earliest expiry time of the hrtimer. |
| 103 | * The time which was given as expiry time when the timer |
| 104 | * was armed. |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 105 | * @function: timer expiry callback function |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 106 | * @base: pointer to the timer base (per cpu and per clock) |
Thomas Gleixner | 303e967 | 2007-02-16 01:27:51 -0800 | [diff] [blame] | 107 | * @state: state information (See bit values above) |
Thomas Gleixner | 203cbf77 | 2016-01-14 16:54:46 +0000 | [diff] [blame] | 108 | * @is_rel: Set if the timer was armed relative |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 109 | * @is_soft: Set if hrtimer will be expired in soft interrupt context. |
Thomas Gleixner | 0ab6a3d | 2019-07-30 20:15:25 +0200 | [diff] [blame] | 110 | * @is_hard: Set if hrtimer will be expired in hard interrupt context |
| 111 | * even on RT. |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 112 | * |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 113 | * The hrtimer structure must be initialized by hrtimer_init() |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 114 | */ |
| 115 | struct hrtimer { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 116 | struct timerqueue_node node; |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 117 | ktime_t _softexpires; |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 118 | enum hrtimer_restart (*function)(struct hrtimer *); |
| 119 | struct hrtimer_clock_base *base; |
Thomas Gleixner | 203cbf77 | 2016-01-14 16:54:46 +0000 | [diff] [blame] | 120 | u8 state; |
| 121 | u8 is_rel; |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 122 | u8 is_soft; |
Thomas Gleixner | 0ab6a3d | 2019-07-30 20:15:25 +0200 | [diff] [blame] | 123 | u8 is_hard; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /** |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 127 | * struct hrtimer_sleeper - simple sleeper structure |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 128 | * @timer: embedded timer structure |
| 129 | * @task: task to wake up |
| 130 | * |
| 131 | * task is set to NULL, when the timer expires. |
| 132 | */ |
| 133 | struct hrtimer_sleeper { |
| 134 | struct hrtimer timer; |
| 135 | struct task_struct *task; |
| 136 | }; |
| 137 | |
Thomas Gleixner | b8e3841 | 2015-04-14 21:08:44 +0000 | [diff] [blame] | 138 | #ifdef CONFIG_64BIT |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 139 | # define __hrtimer_clock_base_align ____cacheline_aligned |
Thomas Gleixner | b8e3841 | 2015-04-14 21:08:44 +0000 | [diff] [blame] | 140 | #else |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 141 | # define __hrtimer_clock_base_align |
Thomas Gleixner | b8e3841 | 2015-04-14 21:08:44 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 144 | /** |
Andres Salomon | d1d6717 | 2007-03-06 01:42:07 -0800 | [diff] [blame] | 145 | * struct hrtimer_clock_base - the timer base for a specific clock |
Randy Dunlap | 05fb6bf | 2007-02-28 20:12:13 -0800 | [diff] [blame] | 146 | * @cpu_base: per cpu clock base |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 147 | * @index: clock type index for per_cpu support when moving a |
| 148 | * timer to a base on another cpu. |
Vitaliy Ivanov | 4d258b2 | 2011-06-27 19:07:08 +0300 | [diff] [blame] | 149 | * @clockid: clock id for per_cpu support |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 150 | * @seq: seqcount around __run_hrtimer |
| 151 | * @running: pointer to the currently running hrtimer |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 152 | * @active: red black tree root node for the active timers |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 153 | * @get_time: function to retrieve the current time of the clock |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 154 | * @offset: offset of this clock to the monotonic base |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 155 | */ |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 156 | struct hrtimer_clock_base { |
| 157 | struct hrtimer_cpu_base *cpu_base; |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 158 | unsigned int index; |
Thomas Gleixner | ab8177b | 2011-05-20 13:05:15 +0200 | [diff] [blame] | 159 | clockid_t clockid; |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 160 | seqcount_t seq; |
| 161 | struct hrtimer *running; |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 162 | struct timerqueue_head active; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 163 | ktime_t (*get_time)(void); |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 164 | ktime_t offset; |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 165 | } __hrtimer_clock_base_align; |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 166 | |
John Stultz | e06383d | 2010-12-14 19:37:07 -0800 | [diff] [blame] | 167 | enum hrtimer_base_type { |
John Stultz | e06383d | 2010-12-14 19:37:07 -0800 | [diff] [blame] | 168 | HRTIMER_BASE_MONOTONIC, |
Thomas Gleixner | 68fa61c | 2011-05-20 23:14:04 +0200 | [diff] [blame] | 169 | HRTIMER_BASE_REALTIME, |
Thomas Gleixner | a3ed0e43 | 2018-04-25 15:33:38 +0200 | [diff] [blame] | 170 | HRTIMER_BASE_BOOTTIME, |
John Stultz | 90adda9 | 2013-01-21 17:00:11 -0800 | [diff] [blame] | 171 | HRTIMER_BASE_TAI, |
Anna-Maria Gleixner | 98ecadd | 2017-12-21 11:41:55 +0100 | [diff] [blame] | 172 | HRTIMER_BASE_MONOTONIC_SOFT, |
| 173 | HRTIMER_BASE_REALTIME_SOFT, |
Thomas Gleixner | a3ed0e43 | 2018-04-25 15:33:38 +0200 | [diff] [blame] | 174 | HRTIMER_BASE_BOOTTIME_SOFT, |
Anna-Maria Gleixner | 98ecadd | 2017-12-21 11:41:55 +0100 | [diff] [blame] | 175 | HRTIMER_BASE_TAI_SOFT, |
John Stultz | e06383d | 2010-12-14 19:37:07 -0800 | [diff] [blame] | 176 | HRTIMER_MAX_CLOCK_BASES, |
| 177 | }; |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 178 | |
Anna-Maria Gleixner | 1fbc78b | 2017-12-21 11:41:32 +0100 | [diff] [blame] | 179 | /** |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 180 | * struct hrtimer_cpu_base - the per cpu clock bases |
| 181 | * @lock: lock protecting the base and associated clock bases |
| 182 | * and timers |
Viresh Kumar | cddd024 | 2014-06-22 01:29:15 +0200 | [diff] [blame] | 183 | * @cpu: cpu number |
Thomas Gleixner | ab8177b | 2011-05-20 13:05:15 +0200 | [diff] [blame] | 184 | * @active_bases: Bitfield to mark bases with active timers |
Thomas Gleixner | 868a3e9 | 2015-04-14 21:08:37 +0000 | [diff] [blame] | 185 | * @clock_was_set_seq: Sequence counter of clock was set events |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 186 | * @hres_active: State of high resolution mode |
Anna-Maria Gleixner | 28bfd18 | 2017-12-21 11:41:42 +0100 | [diff] [blame] | 187 | * @in_hrtirq: hrtimer_interrupt() is currently executing |
Thomas Gleixner | 41d2e49 | 2009-11-13 17:05:44 +0100 | [diff] [blame] | 188 | * @hang_detected: The last hrtimer interrupt detected a hang |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 189 | * @softirq_activated: displays, if the softirq is raised - update of softirq |
| 190 | * related settings is not required then. |
Thomas Gleixner | 41d2e49 | 2009-11-13 17:05:44 +0100 | [diff] [blame] | 191 | * @nr_events: Total number of hrtimer interrupt events |
| 192 | * @nr_retries: Total number of hrtimer interrupt retries |
| 193 | * @nr_hangs: Total number of hrtimer interrupt hangs |
| 194 | * @max_hang_time: Maximum time spent in hrtimer_interrupt |
Anna-Maria Gleixner | f61eff8 | 2019-07-26 20:30:59 +0200 | [diff] [blame^] | 195 | * @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are |
| 196 | * expired |
| 197 | * @timer_waiters: A hrtimer_cancel() invocation waits for the timer |
| 198 | * callback to finish. |
Anna-Maria Gleixner | 07a9a7e | 2017-12-21 11:41:44 +0100 | [diff] [blame] | 199 | * @expires_next: absolute time of the next event, is required for remote |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 200 | * hrtimer enqueue; it is the total first expiry time (hard |
| 201 | * and soft hrtimer are taken into account) |
Anna-Maria Gleixner | eb27926 | 2017-12-21 11:41:45 +0100 | [diff] [blame] | 202 | * @next_timer: Pointer to the first expiring timer |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 203 | * @softirq_expires_next: Time to check, if soft queues needs also to be expired |
| 204 | * @softirq_next_timer: Pointer to the first expiring softirq based timer |
Thomas Gleixner | ab8177b | 2011-05-20 13:05:15 +0200 | [diff] [blame] | 205 | * @clock_base: array of clock bases for this cpu |
Thomas Gleixner | 895bdfa | 2015-04-14 21:08:49 +0000 | [diff] [blame] | 206 | * |
| 207 | * Note: next_timer is just an optimization for __remove_hrtimer(). |
| 208 | * Do not dereference the pointer because it is not reliable on |
| 209 | * cross cpu removals. |
Thomas Gleixner | 3c8aa39 | 2007-02-16 01:27:50 -0800 | [diff] [blame] | 210 | */ |
| 211 | struct hrtimer_cpu_base { |
Thomas Gleixner | ecb49d1 | 2009-11-17 16:36:54 +0100 | [diff] [blame] | 212 | raw_spinlock_t lock; |
Viresh Kumar | cddd024 | 2014-06-22 01:29:15 +0200 | [diff] [blame] | 213 | unsigned int cpu; |
John Stultz | f55a6fa | 2012-07-10 18:43:19 -0400 | [diff] [blame] | 214 | unsigned int active_bases; |
Thomas Gleixner | 868a3e9 | 2015-04-14 21:08:37 +0000 | [diff] [blame] | 215 | unsigned int clock_was_set_seq; |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 216 | unsigned int hres_active : 1, |
| 217 | in_hrtirq : 1, |
| 218 | hang_detected : 1, |
| 219 | softirq_activated : 1; |
Anna-Maria Gleixner | 11a9fe0 | 2017-12-21 11:41:46 +0100 | [diff] [blame] | 220 | #ifdef CONFIG_HIGH_RES_TIMERS |
Thomas Gleixner | a6ffebc | 2015-04-14 21:08:34 +0000 | [diff] [blame] | 221 | unsigned int nr_events; |
Anna-Maria Gleixner | da21c5a | 2017-12-21 11:41:41 +0100 | [diff] [blame] | 222 | unsigned short nr_retries; |
| 223 | unsigned short nr_hangs; |
Thomas Gleixner | a6ffebc | 2015-04-14 21:08:34 +0000 | [diff] [blame] | 224 | unsigned int max_hang_time; |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 225 | #endif |
Anna-Maria Gleixner | f61eff8 | 2019-07-26 20:30:59 +0200 | [diff] [blame^] | 226 | #ifdef CONFIG_PREEMPT_RT |
| 227 | spinlock_t softirq_expiry_lock; |
| 228 | atomic_t timer_waiters; |
| 229 | #endif |
Anna-Maria Gleixner | 07a9a7e | 2017-12-21 11:41:44 +0100 | [diff] [blame] | 230 | ktime_t expires_next; |
Anna-Maria Gleixner | eb27926 | 2017-12-21 11:41:45 +0100 | [diff] [blame] | 231 | struct hrtimer *next_timer; |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 232 | ktime_t softirq_expires_next; |
| 233 | struct hrtimer *softirq_next_timer; |
Thomas Gleixner | f24444b | 2011-05-20 13:02:58 +0200 | [diff] [blame] | 234 | struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; |
Thomas Gleixner | 6d9a141 | 2015-04-14 21:08:42 +0000 | [diff] [blame] | 235 | } ____cacheline_aligned; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 236 | |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 237 | static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time) |
| 238 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 239 | timer->node.expires = time; |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 240 | timer->_softexpires = time; |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 241 | } |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 242 | |
| 243 | static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta) |
| 244 | { |
| 245 | timer->_softexpires = time; |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 246 | timer->node.expires = ktime_add_safe(time, delta); |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 247 | } |
| 248 | |
John Stultz | da8b44d | 2016-03-17 14:20:51 -0700 | [diff] [blame] | 249 | static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, u64 delta) |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 250 | { |
| 251 | timer->_softexpires = time; |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 252 | timer->node.expires = ktime_add_safe(time, ns_to_ktime(delta)); |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 255 | static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64) |
| 256 | { |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 257 | timer->node.expires = tv64; |
| 258 | timer->_softexpires = tv64; |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time) |
| 262 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 263 | timer->node.expires = ktime_add_safe(timer->node.expires, time); |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 264 | timer->_softexpires = ktime_add_safe(timer->_softexpires, time); |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 265 | } |
| 266 | |
David Howells | 7597bc94 | 2008-11-05 17:38:47 +0000 | [diff] [blame] | 267 | static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns) |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 268 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 269 | timer->node.expires = ktime_add_ns(timer->node.expires, ns); |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 270 | timer->_softexpires = ktime_add_ns(timer->_softexpires, ns); |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer) |
| 274 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 275 | return timer->node.expires; |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 278 | static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer) |
| 279 | { |
| 280 | return timer->_softexpires; |
| 281 | } |
| 282 | |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 283 | static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer) |
| 284 | { |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 285 | return timer->node.expires; |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 286 | } |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 287 | static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer) |
| 288 | { |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 289 | return timer->_softexpires; |
Arjan van de Ven | 654c8e0 | 2008-09-01 15:47:08 -0700 | [diff] [blame] | 290 | } |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 291 | |
| 292 | static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer) |
| 293 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 294 | return ktime_to_ns(timer->node.expires); |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer) |
| 298 | { |
John Stultz | 998adc3 | 2010-09-20 19:19:17 -0700 | [diff] [blame] | 299 | return ktime_sub(timer->node.expires, timer->base->get_time()); |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 302 | static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer) |
| 303 | { |
| 304 | return timer->base->get_time(); |
| 305 | } |
| 306 | |
Anna-Maria Gleixner | 28bfd18 | 2017-12-21 11:41:42 +0100 | [diff] [blame] | 307 | static inline int hrtimer_is_hres_active(struct hrtimer *timer) |
| 308 | { |
| 309 | return IS_ENABLED(CONFIG_HIGH_RES_TIMERS) ? |
| 310 | timer->base->cpu_base->hres_active : 0; |
| 311 | } |
| 312 | |
Thomas Gleixner | 21d6d52 | 2015-04-14 21:08:35 +0000 | [diff] [blame] | 313 | #ifdef CONFIG_HIGH_RES_TIMERS |
| 314 | struct clock_event_device; |
| 315 | |
| 316 | extern void hrtimer_interrupt(struct clock_event_device *dev); |
| 317 | |
John Stultz | f55a6fa | 2012-07-10 18:43:19 -0400 | [diff] [blame] | 318 | extern void clock_was_set_delayed(void); |
| 319 | |
Thomas Gleixner | 398ca17 | 2015-04-14 21:08:27 +0000 | [diff] [blame] | 320 | extern unsigned int hrtimer_resolution; |
| 321 | |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 322 | #else |
| 323 | |
Borislav Petkov | d711b8b | 2015-06-06 11:30:00 +0200 | [diff] [blame] | 324 | #define hrtimer_resolution (unsigned int)LOW_RES_NSEC |
Thomas Gleixner | 398ca17 | 2015-04-14 21:08:27 +0000 | [diff] [blame] | 325 | |
John Stultz | f55a6fa | 2012-07-10 18:43:19 -0400 | [diff] [blame] | 326 | static inline void clock_was_set_delayed(void) { } |
| 327 | |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 328 | #endif |
| 329 | |
Thomas Gleixner | 203cbf77 | 2016-01-14 16:54:46 +0000 | [diff] [blame] | 330 | static inline ktime_t |
| 331 | __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now) |
| 332 | { |
| 333 | ktime_t rem = ktime_sub(timer->node.expires, now); |
| 334 | |
| 335 | /* |
| 336 | * Adjust relative timers for the extra we added in |
| 337 | * hrtimer_start_range_ns() to prevent short timeouts. |
| 338 | */ |
| 339 | if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel) |
Thomas Gleixner | 2456e85 | 2016-12-25 11:38:40 +0100 | [diff] [blame] | 340 | rem -= hrtimer_resolution; |
Thomas Gleixner | 203cbf77 | 2016-01-14 16:54:46 +0000 | [diff] [blame] | 341 | return rem; |
| 342 | } |
| 343 | |
| 344 | static inline ktime_t |
| 345 | hrtimer_expires_remaining_adjusted(const struct hrtimer *timer) |
| 346 | { |
| 347 | return __hrtimer_expires_remaining_adjusted(timer, |
| 348 | timer->base->get_time()); |
| 349 | } |
| 350 | |
Thomas Gleixner | b12a03c | 2011-05-02 16:48:57 +0200 | [diff] [blame] | 351 | extern void clock_was_set(void); |
Thomas Gleixner | 9ec2690 | 2011-05-20 16:18:50 +0200 | [diff] [blame] | 352 | #ifdef CONFIG_TIMERFD |
| 353 | extern void timerfd_clock_was_set(void); |
| 354 | #else |
| 355 | static inline void timerfd_clock_was_set(void) { } |
| 356 | #endif |
Thomas Gleixner | b12a03c | 2011-05-02 16:48:57 +0200 | [diff] [blame] | 357 | extern void hrtimers_resume(void); |
| 358 | |
Arjan van de Ven | 2e94d1f | 2008-09-10 16:06:00 -0700 | [diff] [blame] | 359 | DECLARE_PER_CPU(struct tick_device, tick_cpu_device); |
Arjan van de Ven | 2e94d1f | 2008-09-10 16:06:00 -0700 | [diff] [blame] | 360 | |
Anna-Maria Gleixner | f61eff8 | 2019-07-26 20:30:59 +0200 | [diff] [blame^] | 361 | #ifdef CONFIG_PREEMPT_RT |
| 362 | void hrtimer_cancel_wait_running(const struct hrtimer *timer); |
| 363 | #else |
| 364 | static inline void hrtimer_cancel_wait_running(struct hrtimer *timer) |
| 365 | { |
| 366 | cpu_relax(); |
| 367 | } |
| 368 | #endif |
Arjan van de Ven | 2e94d1f | 2008-09-10 16:06:00 -0700 | [diff] [blame] | 369 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 370 | /* Exported timer functions: */ |
| 371 | |
| 372 | /* Initialize timers: */ |
George Anzinger | 7978672c | 2006-02-01 03:05:11 -0800 | [diff] [blame] | 373 | extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, |
| 374 | enum hrtimer_mode mode); |
Sebastian Andrzej Siewior | dbc1625 | 2019-07-26 20:30:50 +0200 | [diff] [blame] | 375 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, |
| 376 | enum hrtimer_mode mode); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 377 | |
Thomas Gleixner | 237fc6e | 2008-04-30 00:55:04 -0700 | [diff] [blame] | 378 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
| 379 | extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, |
| 380 | enum hrtimer_mode mode); |
Sebastian Andrzej Siewior | dbc1625 | 2019-07-26 20:30:50 +0200 | [diff] [blame] | 381 | extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, |
| 382 | clockid_t clock_id, |
| 383 | enum hrtimer_mode mode); |
Thomas Gleixner | 237fc6e | 2008-04-30 00:55:04 -0700 | [diff] [blame] | 384 | |
| 385 | extern void destroy_hrtimer_on_stack(struct hrtimer *timer); |
| 386 | #else |
| 387 | static inline void hrtimer_init_on_stack(struct hrtimer *timer, |
| 388 | clockid_t which_clock, |
| 389 | enum hrtimer_mode mode) |
| 390 | { |
| 391 | hrtimer_init(timer, which_clock, mode); |
| 392 | } |
Sebastian Andrzej Siewior | dbc1625 | 2019-07-26 20:30:50 +0200 | [diff] [blame] | 393 | |
| 394 | static inline void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, |
| 395 | clockid_t clock_id, |
| 396 | enum hrtimer_mode mode) |
| 397 | { |
| 398 | hrtimer_init_sleeper(sl, clock_id, mode); |
| 399 | } |
| 400 | |
Thomas Gleixner | 237fc6e | 2008-04-30 00:55:04 -0700 | [diff] [blame] | 401 | static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } |
| 402 | #endif |
| 403 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 404 | /* Basic timer operations: */ |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 405 | extern void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, |
John Stultz | da8b44d | 2016-03-17 14:20:51 -0700 | [diff] [blame] | 406 | u64 range_ns, const enum hrtimer_mode mode); |
Peter Zijlstra | 7f1e2ca | 2009-03-13 12:21:27 +0100 | [diff] [blame] | 407 | |
Thomas Gleixner | 02a171a | 2015-04-14 21:09:10 +0000 | [diff] [blame] | 408 | /** |
Anna-Maria Gleixner | 6de6250 | 2017-12-21 11:41:34 +0100 | [diff] [blame] | 409 | * hrtimer_start - (re)start an hrtimer |
Thomas Gleixner | 02a171a | 2015-04-14 21:09:10 +0000 | [diff] [blame] | 410 | * @timer: the timer to be added |
| 411 | * @tim: expiry time |
Anna-Maria Gleixner | 6de6250 | 2017-12-21 11:41:34 +0100 | [diff] [blame] | 412 | * @mode: timer mode: absolute (HRTIMER_MODE_ABS) or |
Anna-Maria Gleixner | 5da7016 | 2017-12-21 11:41:57 +0100 | [diff] [blame] | 413 | * relative (HRTIMER_MODE_REL), and pinned (HRTIMER_MODE_PINNED); |
| 414 | * softirq based mode is considered for debug purpose only! |
Thomas Gleixner | 02a171a | 2015-04-14 21:09:10 +0000 | [diff] [blame] | 415 | */ |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 416 | static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim, |
| 417 | const enum hrtimer_mode mode) |
Thomas Gleixner | 02a171a | 2015-04-14 21:09:10 +0000 | [diff] [blame] | 418 | { |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 419 | hrtimer_start_range_ns(timer, tim, 0, mode); |
Thomas Gleixner | 02a171a | 2015-04-14 21:09:10 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 422 | extern int hrtimer_cancel(struct hrtimer *timer); |
| 423 | extern int hrtimer_try_to_cancel(struct hrtimer *timer); |
| 424 | |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 425 | static inline void hrtimer_start_expires(struct hrtimer *timer, |
| 426 | enum hrtimer_mode mode) |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 427 | { |
John Stultz | da8b44d | 2016-03-17 14:20:51 -0700 | [diff] [blame] | 428 | u64 delta; |
Arjan van de Ven | da8f2e1 | 2008-09-07 10:47:46 -0700 | [diff] [blame] | 429 | ktime_t soft, hard; |
| 430 | soft = hrtimer_get_softexpires(timer); |
| 431 | hard = hrtimer_get_expires(timer); |
| 432 | delta = ktime_to_ns(ktime_sub(hard, soft)); |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 433 | hrtimer_start_range_ns(timer, soft, delta, mode); |
Arjan van de Ven | 63ca243 | 2008-09-01 14:35:02 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Thomas Gleixner | 0165646 | 2019-07-30 21:03:53 +0200 | [diff] [blame] | 436 | void hrtimer_sleeper_start_expires(struct hrtimer_sleeper *sl, |
| 437 | enum hrtimer_mode mode); |
| 438 | |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 439 | static inline void hrtimer_restart(struct hrtimer *timer) |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 440 | { |
Thomas Gleixner | 61699e13 | 2015-04-14 21:09:23 +0000 | [diff] [blame] | 441 | hrtimer_start_expires(timer, HRTIMER_MODE_ABS); |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame] | 442 | } |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 443 | |
| 444 | /* Query timers: */ |
Thomas Gleixner | 203cbf77 | 2016-01-14 16:54:46 +0000 | [diff] [blame] | 445 | extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust); |
| 446 | |
| 447 | static inline ktime_t hrtimer_get_remaining(const struct hrtimer *timer) |
| 448 | { |
| 449 | return __hrtimer_get_remaining(timer, false); |
| 450 | } |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 451 | |
Thomas Gleixner | c1ad348 | 2015-04-14 21:08:58 +0000 | [diff] [blame] | 452 | extern u64 hrtimer_get_next_event(void); |
Rafael J. Wysocki | a59855c | 2018-04-03 23:17:00 +0200 | [diff] [blame] | 453 | extern u64 hrtimer_next_event_without(const struct hrtimer *exclude); |
Tony Lindgren | 6923974 | 2006-03-06 15:42:45 -0800 | [diff] [blame] | 454 | |
Peter Zijlstra | 887d9dc | 2015-06-11 14:46:48 +0200 | [diff] [blame] | 455 | extern bool hrtimer_active(const struct hrtimer *timer); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 456 | |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 457 | /* |
| 458 | * Helper function to check, whether the timer is on one of the queues |
| 459 | */ |
| 460 | static inline int hrtimer_is_queued(struct hrtimer *timer) |
| 461 | { |
Peter Zijlstra | ca10949 | 2008-11-25 12:43:51 +0100 | [diff] [blame] | 462 | return timer->state & HRTIMER_STATE_ENQUEUED; |
Thomas Gleixner | 54cdfdb | 2007-02-16 01:28:11 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Oliver Hartkopp | 4346f65 | 2008-04-30 23:04:37 +0200 | [diff] [blame] | 465 | /* |
| 466 | * Helper function to check, whether the timer is running the callback |
| 467 | * function |
| 468 | */ |
| 469 | static inline int hrtimer_callback_running(struct hrtimer *timer) |
| 470 | { |
Anna-Maria Gleixner | 3f0b9e8 | 2017-12-21 11:41:40 +0100 | [diff] [blame] | 471 | return timer->base->running == timer; |
Oliver Hartkopp | 4346f65 | 2008-04-30 23:04:37 +0200 | [diff] [blame] | 472 | } |
| 473 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 474 | /* Forward a hrtimer so it expires after now: */ |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 475 | extern u64 |
Roman Zippel | 44f2147 | 2006-03-26 01:38:06 -0800 | [diff] [blame] | 476 | hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 477 | |
Thomas Gleixner | 91e5a217 | 2015-04-13 21:02:22 +0000 | [diff] [blame] | 478 | /** |
| 479 | * hrtimer_forward_now - forward the timer expiry so it expires after now |
| 480 | * @timer: hrtimer to forward |
| 481 | * @interval: the interval to forward |
| 482 | * |
| 483 | * Forward the timer expiry so it will expire after the current time |
| 484 | * of the hrtimer clock base. Returns the number of overruns. |
| 485 | * |
| 486 | * Can be safely called from the callback function of @timer. If |
| 487 | * called from other contexts @timer must neither be enqueued nor |
| 488 | * running the callback and the caller needs to take care of |
| 489 | * serialization. |
| 490 | * |
| 491 | * Note: This only updates the timer expiry value and does not requeue |
| 492 | * the timer. |
| 493 | */ |
Davide Libenzi | 4d672e7 | 2008-02-04 22:27:26 -0800 | [diff] [blame] | 494 | static inline u64 hrtimer_forward_now(struct hrtimer *timer, |
| 495 | ktime_t interval) |
Davide Libenzi | 5e05ad7 | 2008-02-04 22:27:25 -0800 | [diff] [blame] | 496 | { |
| 497 | return hrtimer_forward(timer, timer->base->get_time(), interval); |
| 498 | } |
| 499 | |
Thomas Gleixner | 10c94ec | 2006-01-09 20:52:35 -0800 | [diff] [blame] | 500 | /* Precise sleep: */ |
Al Viro | ce41aaf | 2017-06-07 09:42:32 +0100 | [diff] [blame] | 501 | |
Deepa Dinamani | c0edd7c | 2017-06-24 11:45:06 -0700 | [diff] [blame] | 502 | extern int nanosleep_copyout(struct restart_block *, struct timespec64 *); |
Thomas Gleixner | 938e7cf | 2017-06-13 23:34:33 +0200 | [diff] [blame] | 503 | extern long hrtimer_nanosleep(const struct timespec64 *rqtp, |
Thomas Gleixner | 10c94ec | 2006-01-09 20:52:35 -0800 | [diff] [blame] | 504 | const enum hrtimer_mode mode, |
| 505 | const clockid_t clockid); |
| 506 | |
John Stultz | da8b44d | 2016-03-17 14:20:51 -0700 | [diff] [blame] | 507 | extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta, |
Sebastian Andrzej Siewior | dbc1625 | 2019-07-26 20:30:50 +0200 | [diff] [blame] | 508 | const enum hrtimer_mode mode); |
Carsten Emde | 351b3f7 | 2010-04-02 22:40:19 +0200 | [diff] [blame] | 509 | extern int schedule_hrtimeout_range_clock(ktime_t *expires, |
John Stultz | da8b44d | 2016-03-17 14:20:51 -0700 | [diff] [blame] | 510 | u64 delta, |
| 511 | const enum hrtimer_mode mode, |
Anna-Maria Gleixner | 9077771 | 2017-12-21 11:41:33 +0100 | [diff] [blame] | 512 | clockid_t clock_id); |
Arjan van de Ven | 7bb6743 | 2008-08-31 08:05:58 -0700 | [diff] [blame] | 513 | extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode); |
| 514 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 515 | /* Soft interrupt function to run the hrtimer queues: */ |
| 516 | extern void hrtimer_run_queues(void); |
| 517 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 518 | /* Bootup initialization: */ |
| 519 | extern void __init hrtimers_init(void); |
| 520 | |
Ingo Molnar | 88ad0bf6 | 2007-02-16 01:28:16 -0800 | [diff] [blame] | 521 | /* Show pending timers: */ |
| 522 | extern void sysrq_timer_list_show(void); |
| 523 | |
Thomas Gleixner | 27590dc | 2016-07-15 10:41:04 +0200 | [diff] [blame] | 524 | int hrtimers_prepare_cpu(unsigned int cpu); |
| 525 | #ifdef CONFIG_HOTPLUG_CPU |
| 526 | int hrtimers_dead_cpu(unsigned int cpu); |
| 527 | #else |
| 528 | #define hrtimers_dead_cpu NULL |
| 529 | #endif |
| 530 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 531 | #endif |