Lines Matching +full:timer +full:-

1 // SPDX-License-Identifier: GPL-2.0
3 * hrtimers - High-resolution kernel timers
19 #include <linux/percpu-defs.h>
21 #include <linux/timer.h>
26 * HRTIMER_MODE_ABS - Time value is absolute
27 * HRTIMER_MODE_REL - Time value is relative to now
28 * HRTIMER_MODE_PINNED - Timer is bound to CPU (is only considered
29 * when starting the timer)
30 * HRTIMER_MODE_SOFT - Timer callback function will be executed in
32 * HRTIMER_MODE_HARD - Timer callback function will be executed in
59 * Values to track state of the timer
66 * The callback state is not part of the timer->state because clearing it would
67 * mean touching the timer after the callback, this makes it impossible to free
68 * the timer from the callback function.
72 * timer->base->cpu_base->running == timer
75 * status. It happens for example when a posix timer expired and the callback
76 * queued a signal. Between dropping the lock which protects the posix timer
78 * signal and rearm the timer.
80 * All state transitions are protected by cpu_base->lock.
86 * struct hrtimer_sleeper - simple sleeper structure
87 * @timer: embedded timer structure
90 * task is set to NULL, when the timer expires.
93 struct hrtimer timer; member
97 static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time) in hrtimer_set_expires() argument
99 timer->node.expires = time; in hrtimer_set_expires()
100 timer->_softexpires = time; in hrtimer_set_expires()
103 static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta) in hrtimer_set_expires_range() argument
105 timer->_softexpires = time; in hrtimer_set_expires_range()
106 timer->node.expires = ktime_add_safe(time, delta); in hrtimer_set_expires_range()
109 static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, u64 delta) in hrtimer_set_expires_range_ns() argument
111 timer->_softexpires = time; in hrtimer_set_expires_range_ns()
112 timer->node.expires = ktime_add_safe(time, ns_to_ktime(delta)); in hrtimer_set_expires_range_ns()
115 static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64) in hrtimer_set_expires_tv64() argument
117 timer->node.expires = tv64; in hrtimer_set_expires_tv64()
118 timer->_softexpires = tv64; in hrtimer_set_expires_tv64()
121 static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time) in hrtimer_add_expires() argument
123 timer->node.expires = ktime_add_safe(timer->node.expires, time); in hrtimer_add_expires()
124 timer->_softexpires = ktime_add_safe(timer->_softexpires, time); in hrtimer_add_expires()
127 static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns) in hrtimer_add_expires_ns() argument
129 timer->node.expires = ktime_add_ns(timer->node.expires, ns); in hrtimer_add_expires_ns()
130 timer->_softexpires = ktime_add_ns(timer->_softexpires, ns); in hrtimer_add_expires_ns()
133 static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer) in hrtimer_get_expires() argument
135 return timer->node.expires; in hrtimer_get_expires()
138 static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer) in hrtimer_get_softexpires() argument
140 return timer->_softexpires; in hrtimer_get_softexpires()
143 static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer) in hrtimer_get_expires_tv64() argument
145 return timer->node.expires; in hrtimer_get_expires_tv64()
147 static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer) in hrtimer_get_softexpires_tv64() argument
149 return timer->_softexpires; in hrtimer_get_softexpires_tv64()
152 static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer) in hrtimer_get_expires_ns() argument
154 return ktime_to_ns(timer->node.expires); in hrtimer_get_expires_ns()
157 static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer) in hrtimer_expires_remaining() argument
159 return ktime_sub(timer->node.expires, timer->base->get_time()); in hrtimer_expires_remaining()
162 static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer) in hrtimer_cb_get_time() argument
164 return timer->base->get_time(); in hrtimer_cb_get_time()
167 static inline int hrtimer_is_hres_active(struct hrtimer *timer) in hrtimer_is_hres_active() argument
170 timer->base->cpu_base->hres_active : 0; in hrtimer_is_hres_active()
187 __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now) in __hrtimer_expires_remaining_adjusted() argument
189 ktime_t rem = ktime_sub(timer->node.expires, now); in __hrtimer_expires_remaining_adjusted()
195 if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel) in __hrtimer_expires_remaining_adjusted()
196 rem -= hrtimer_resolution; in __hrtimer_expires_remaining_adjusted()
201 hrtimer_expires_remaining_adjusted(const struct hrtimer *timer) in hrtimer_expires_remaining_adjusted() argument
203 return __hrtimer_expires_remaining_adjusted(timer, in hrtimer_expires_remaining_adjusted()
204 timer->base->get_time()); in hrtimer_expires_remaining_adjusted()
218 void hrtimer_cancel_wait_running(const struct hrtimer *timer);
220 static inline void hrtimer_cancel_wait_running(struct hrtimer *timer) in hrtimer_cancel_wait_running() argument
226 /* Exported timer functions: */
229 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
231 extern void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function)(struct hrtimer *),
233 extern void hrtimer_setup_on_stack(struct hrtimer *timer,
240 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
242 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } in destroy_hrtimer_on_stack() argument
245 /* Basic timer operations: */
246 extern void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
250 * hrtimer_start - (re)start an hrtimer
251 * @timer: the timer to be added
253 * @mode: timer mode: absolute (HRTIMER_MODE_ABS) or
257 static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim, in hrtimer_start() argument
260 hrtimer_start_range_ns(timer, tim, 0, mode); in hrtimer_start()
263 extern int hrtimer_cancel(struct hrtimer *timer);
264 extern int hrtimer_try_to_cancel(struct hrtimer *timer);
266 static inline void hrtimer_start_expires(struct hrtimer *timer, in hrtimer_start_expires() argument
271 soft = hrtimer_get_softexpires(timer); in hrtimer_start_expires()
272 hard = hrtimer_get_expires(timer); in hrtimer_start_expires()
274 hrtimer_start_range_ns(timer, soft, delta, mode); in hrtimer_start_expires()
280 static inline void hrtimer_restart(struct hrtimer *timer) in hrtimer_restart() argument
282 hrtimer_start_expires(timer, HRTIMER_MODE_ABS); in hrtimer_restart()
286 extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
289 * hrtimer_get_remaining - get remaining time for the timer
290 * @timer: the timer to read
292 static inline ktime_t hrtimer_get_remaining(const struct hrtimer *timer) in hrtimer_get_remaining() argument
294 return __hrtimer_get_remaining(timer, false); in hrtimer_get_remaining()
300 extern bool hrtimer_active(const struct hrtimer *timer);
303 * hrtimer_is_queued - check, whether the timer is on one of the queues
304 * @timer: Timer to check
306 * Returns: True if the timer is queued, false otherwise
310 static inline bool hrtimer_is_queued(struct hrtimer *timer) in hrtimer_is_queued() argument
312 /* The READ_ONCE pairs with the update functions of timer->state */ in hrtimer_is_queued()
313 return !!(READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED); in hrtimer_is_queued()
317 * Helper function to check, whether the timer is running the callback
320 static inline int hrtimer_callback_running(struct hrtimer *timer) in hrtimer_callback_running() argument
322 return timer->base->running == timer; in hrtimer_callback_running()
326 * hrtimer_update_function - Update the timer's callback function
327 * @timer: Timer to update
330 * Only safe to call if the timer is not enqueued. Can be called in the callback function if the
331 * timer is not enqueued at the same time (see the comments above HRTIMER_STATE_ENQUEUED).
333 static inline void hrtimer_update_function(struct hrtimer *timer, in hrtimer_update_function() argument
336 guard(raw_spinlock_irqsave)(&timer->base->cpu_base->lock); in hrtimer_update_function()
338 if (WARN_ON_ONCE(hrtimer_is_queued(timer))) in hrtimer_update_function()
344 timer->function = function; in hrtimer_update_function()
349 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
352 * hrtimer_forward_now() - forward the timer expiry so it expires after now
353 * @timer: hrtimer to forward
356 * It is a variant of hrtimer_forward(). The timer will expire after the current
359 static inline u64 hrtimer_forward_now(struct hrtimer *timer, in hrtimer_forward_now() argument
362 return hrtimer_forward(timer, timer->base->get_time(), interval); in hrtimer_forward_now()