Lines Matching full:timer
21 #include <linux/timer.h>
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.
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_add_expires(struct hrtimer *timer, ktime_t time) in hrtimer_add_expires() argument
117 timer->node.expires = ktime_add_safe(timer->node.expires, time); in hrtimer_add_expires()
118 timer->_softexpires = ktime_add_safe(timer->_softexpires, time); in hrtimer_add_expires()
121 static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns) in hrtimer_add_expires_ns() argument
123 timer->node.expires = ktime_add_ns(timer->node.expires, ns); in hrtimer_add_expires_ns()
124 timer->_softexpires = ktime_add_ns(timer->_softexpires, ns); in hrtimer_add_expires_ns()
127 static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer) in hrtimer_get_expires() argument
129 return timer->node.expires; in hrtimer_get_expires()
132 static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer) in hrtimer_get_softexpires() argument
134 return timer->_softexpires; in hrtimer_get_softexpires()
137 static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer) in hrtimer_get_expires_ns() argument
139 return ktime_to_ns(timer->node.expires); in hrtimer_get_expires_ns()
142 ktime_t hrtimer_cb_get_time(const struct hrtimer *timer);
144 static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer) in hrtimer_expires_remaining() argument
146 return ktime_sub(timer->node.expires, hrtimer_cb_get_time(timer)); in hrtimer_expires_remaining()
149 static inline int hrtimer_is_hres_active(struct hrtimer *timer) in hrtimer_is_hres_active() argument
152 timer->base->cpu_base->hres_active : 0; in hrtimer_is_hres_active()
169 __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now) in __hrtimer_expires_remaining_adjusted() argument
171 ktime_t rem = ktime_sub(timer->node.expires, now); in __hrtimer_expires_remaining_adjusted()
177 if (IS_ENABLED(CONFIG_TIME_LOW_RES) && timer->is_rel) in __hrtimer_expires_remaining_adjusted()
183 hrtimer_expires_remaining_adjusted(const struct hrtimer *timer) in hrtimer_expires_remaining_adjusted() argument
185 return __hrtimer_expires_remaining_adjusted(timer, hrtimer_cb_get_time(timer)); in hrtimer_expires_remaining_adjusted()
199 void hrtimer_cancel_wait_running(const struct hrtimer *timer);
201 static inline void hrtimer_cancel_wait_running(struct hrtimer *timer) in hrtimer_cancel_wait_running() argument
212 /* Exported timer functions: */
215 extern void hrtimer_setup(struct hrtimer *timer, enum hrtimer_restart (*function)(struct hrtimer *),
217 extern void hrtimer_setup_on_stack(struct hrtimer *timer,
224 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
226 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } in destroy_hrtimer_on_stack() argument
229 /* Basic timer operations: */
230 extern void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
235 * @timer: the timer to be added
237 * @mode: timer mode: absolute (HRTIMER_MODE_ABS) or
241 static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim, in hrtimer_start() argument
244 hrtimer_start_range_ns(timer, tim, 0, mode); in hrtimer_start()
247 extern int hrtimer_cancel(struct hrtimer *timer);
248 extern int hrtimer_try_to_cancel(struct hrtimer *timer);
250 static inline void hrtimer_start_expires(struct hrtimer *timer, in hrtimer_start_expires() argument
255 soft = hrtimer_get_softexpires(timer); in hrtimer_start_expires()
256 hard = hrtimer_get_expires(timer); in hrtimer_start_expires()
258 hrtimer_start_range_ns(timer, soft, delta, mode); in hrtimer_start_expires()
264 static inline void hrtimer_restart(struct hrtimer *timer) in hrtimer_restart() argument
266 hrtimer_start_expires(timer, HRTIMER_MODE_ABS); in hrtimer_restart()
270 extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
273 * hrtimer_get_remaining - get remaining time for the timer
274 * @timer: the timer to read
276 static inline ktime_t hrtimer_get_remaining(const struct hrtimer *timer) in hrtimer_get_remaining() argument
278 return __hrtimer_get_remaining(timer, false); in hrtimer_get_remaining()
284 extern bool hrtimer_active(const struct hrtimer *timer);
287 * hrtimer_is_queued - check, whether the timer is on one of the queues
288 * @timer: Timer to check
290 * Returns: True if the timer is queued, false otherwise
294 static inline bool hrtimer_is_queued(struct hrtimer *timer) in hrtimer_is_queued() argument
296 /* The READ_ONCE pairs with the update functions of timer->state */ in hrtimer_is_queued()
297 return !!(READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED); in hrtimer_is_queued()
301 * Helper function to check, whether the timer is running the callback
304 static inline int hrtimer_callback_running(struct hrtimer *timer) in hrtimer_callback_running() argument
306 return timer->base->running == timer; in hrtimer_callback_running()
310 * hrtimer_update_function - Update the timer's callback function
311 * @timer: Timer to update
314 * Only safe to call if the timer is not enqueued. Can be called in the callback function if the
315 * timer is not enqueued at the same time (see the comments above HRTIMER_STATE_ENQUEUED).
317 static inline void hrtimer_update_function(struct hrtimer *timer, in hrtimer_update_function() argument
321 guard(raw_spinlock_irqsave)(&timer->base->cpu_base->lock); in hrtimer_update_function()
323 if (WARN_ON_ONCE(hrtimer_is_queued(timer))) in hrtimer_update_function()
329 ACCESS_PRIVATE(timer, function) = function; in hrtimer_update_function()
334 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
337 * hrtimer_forward_now() - forward the timer expiry so it expires after now
338 * @timer: hrtimer to forward
341 * It is a variant of hrtimer_forward(). The timer will expire after the current
344 static inline u64 hrtimer_forward_now(struct hrtimer *timer, in hrtimer_forward_now() argument
347 return hrtimer_forward(timer, hrtimer_cb_get_time(timer), interval); in hrtimer_forward_now()