Lines Matching +full:over +full:- +full:current +full:- +full:active +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
4 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
5 * Copyright(C) 2006-2007 Timesys Corp., Thomas Gleixner
7 * High-resolution kernel timers
9 * In contrast to the low-resolution timeout API, aka timer wheel,
50 #include "tick-internal.h"
54 * cpu_base->active
57 #define HRTIMER_ACTIVE_HARD ((1U << MASK_SHIFT) - 1)
119 [0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES,
136 * timer->base->cpu_base
155 * means that all timers which are tied to this base via timer->base are
162 * possible to set timer->base = &migration_base and drop the lock: the timer
168 __acquires(&timer->base->lock) in lock_hrtimer_base()
173 base = READ_ONCE(timer->base); in lock_hrtimer_base()
175 raw_spin_lock_irqsave(&base->cpu_base->lock, *flags); in lock_hrtimer_base()
176 if (likely(base == timer->base)) in lock_hrtimer_base()
179 raw_spin_unlock_irqrestore(&base->cpu_base->lock, *flags); in lock_hrtimer_base()
187 * event on the target cpu. When high resolution is enabled, we cannot
189 * late. To keep it simple, we handle the high resolution enabled and
192 * Called with cpu_base->lock of target cpu held.
199 expires = ktime_sub(hrtimer_get_expires(timer), new_base->offset); in hrtimer_check_target()
200 return expires < new_base->cpu_base->expires_next; in hrtimer_check_target()
215 * We switch the timer base to a power-optimized selected CPU target,
217 * - NO_HZ_COMMON is enabled
218 * - timer migration is enabled
219 * - the timer callback is not running
220 * - the timer is not the first expiring timer on the new target
223 * to the current CPU or leave it on the previously assigned CPU if
232 int basenum = base->index; in switch_hrtimer_base()
237 new_base = &new_cpu_base->clock_base[basenum]; in switch_hrtimer_base()
244 * the event source in the high resolution case. The softirq in switch_hrtimer_base()
253 WRITE_ONCE(timer->base, &migration_base); in switch_hrtimer_base()
254 raw_spin_unlock(&base->cpu_base->lock); in switch_hrtimer_base()
255 raw_spin_lock(&new_base->cpu_base->lock); in switch_hrtimer_base()
259 raw_spin_unlock(&new_base->cpu_base->lock); in switch_hrtimer_base()
260 raw_spin_lock(&base->cpu_base->lock); in switch_hrtimer_base()
262 WRITE_ONCE(timer->base, base); in switch_hrtimer_base()
265 WRITE_ONCE(timer->base, new_base); in switch_hrtimer_base()
285 __acquires(&timer->base->cpu_base->lock) in lock_hrtimer_base()
287 struct hrtimer_clock_base *base = timer->base; in lock_hrtimer_base()
289 raw_spin_lock_irqsave(&base->cpu_base->lock, *flags); in lock_hrtimer_base()
313 tmp = dclc < 0 ? -dclc : dclc; in __ktime_divns()
322 return dclc < 0 ? -tmp : tmp; in __ktime_divns()
352 return ((struct hrtimer *) addr)->function; in hrtimer_debug_hint()
357 * - an active object is initialized
375 * - an active object is activated
376 * - an unknown non-static object is activated
391 * - an active object is freed
448 debug_object_init_on_stack(&sl->timer, &hrtimer_debug_descr); in hrtimer_init_sleeper_on_stack()
489 __next_base(struct hrtimer_cpu_base *cpu_base, unsigned int *active) in __next_base() argument
493 if (!*active) in __next_base()
496 idx = __ffs(*active); in __next_base()
497 *active &= ~(1U << idx); in __next_base()
499 return &cpu_base->clock_base[idx]; in __next_base()
502 #define for_each_active_base(base, cpu_base, active) \ argument
503 while ((base = __next_base((cpu_base), &(active))))
507 unsigned int active, in __hrtimer_next_event_base() argument
513 for_each_active_base(base, cpu_base, active) { in __hrtimer_next_event_base()
517 next = timerqueue_getnext(&base->active); in __hrtimer_next_event_base()
527 expires = ktime_sub(hrtimer_get_expires(timer), base->offset); in __hrtimer_next_event_base()
535 if (timer->is_soft) in __hrtimer_next_event_base()
536 cpu_base->softirq_next_timer = timer; in __hrtimer_next_event_base()
538 cpu_base->next_timer = timer; in __hrtimer_next_event_base()
542 * clock_was_set() might have changed base->offset of any of in __hrtimer_next_event_base()
560 * hrtimer_run_softirq(), hrtimer_update_softirq_timer() will re-add these bases.
567 * - HRTIMER_ACTIVE_ALL,
568 * - HRTIMER_ACTIVE_SOFT, or
569 * - HRTIMER_ACTIVE_HARD.
574 unsigned int active; in __hrtimer_get_next_event() local
578 if (!cpu_base->softirq_activated && (active_mask & HRTIMER_ACTIVE_SOFT)) { in __hrtimer_get_next_event()
579 active = cpu_base->active_bases & HRTIMER_ACTIVE_SOFT; in __hrtimer_get_next_event()
580 cpu_base->softirq_next_timer = NULL; in __hrtimer_get_next_event()
582 active, KTIME_MAX); in __hrtimer_get_next_event()
584 next_timer = cpu_base->softirq_next_timer; in __hrtimer_get_next_event()
588 active = cpu_base->active_bases & HRTIMER_ACTIVE_HARD; in __hrtimer_get_next_event()
589 cpu_base->next_timer = next_timer; in __hrtimer_get_next_event()
590 expires_next = __hrtimer_next_event_base(cpu_base, NULL, active, in __hrtimer_get_next_event()
606 if (!cpu_base->softirq_activated) { in hrtimer_update_next_event()
612 cpu_base->softirq_expires_next = soft; in hrtimer_update_next_event()
617 * If a softirq timer is expiring first, update cpu_base->next_timer in hrtimer_update_next_event()
621 cpu_base->next_timer = cpu_base->softirq_next_timer; in hrtimer_update_next_event()
630 ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset; in hrtimer_update_base()
631 ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset; in hrtimer_update_base()
632 ktime_t *offs_tai = &base->clock_base[HRTIMER_BASE_TAI].offset; in hrtimer_update_base()
634 ktime_t now = ktime_get_update_offsets_now(&base->clock_was_set_seq, in hrtimer_update_base()
637 base->clock_base[HRTIMER_BASE_REALTIME_SOFT].offset = *offs_real; in hrtimer_update_base()
638 base->clock_base[HRTIMER_BASE_BOOTTIME_SOFT].offset = *offs_boot; in hrtimer_update_base()
639 base->clock_base[HRTIMER_BASE_TAI_SOFT].offset = *offs_tai; in hrtimer_update_base()
645 * Is the high resolution mode active ?
650 cpu_base->hres_active : 0; in __hrtimer_hres_active()
662 cpu_base->expires_next = expires_next; in __hrtimer_reprogram()
665 * If hres is not active, hardware does not have to be in __hrtimer_reprogram()
669 * leave the hang delay active in the hardware. We want the in __hrtimer_reprogram()
681 if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected) in __hrtimer_reprogram()
690 * Called with interrupts disabled and base->lock held
699 if (skip_equal && expires_next == cpu_base->expires_next) in hrtimer_force_reprogram()
702 __hrtimer_reprogram(cpu_base, cpu_base->next_timer, expires_next); in hrtimer_force_reprogram()
705 /* High resolution timer related functions */
709 * High resolution timer enabled ?
716 * Enable / Disable high resolution mode
726 * hrtimer_high_res_enabled - query, if the highres mode is enabled
736 * Switch to high resolution mode
743 pr_warn("Could not switch to high resolution mode on CPU %u\n", in hrtimer_switch_to_hres()
744 base->cpu); in hrtimer_switch_to_hres()
747 base->hres_active = 1; in hrtimer_switch_to_hres()
767 * - CONFIG_HIGH_RES_TIMERS is enabled.
768 * - CONFIG_NOHZ_COMMON is enabled
779 * When high resolution mode or nohz is active, then the offsets of in retrigger_next_event()
783 * If high resolution mode is active then the next expiring timer in retrigger_next_event()
795 raw_spin_lock(&base->lock); in retrigger_next_event()
801 raw_spin_unlock(&base->lock); in retrigger_next_event()
809 * Called with interrupts disabled and base->cpu_base.lock held
814 struct hrtimer_clock_base *base = timer->base; in hrtimer_reprogram()
815 ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset); in hrtimer_reprogram()
821 * expiry time which is less than base->offset. Set it to 0. in hrtimer_reprogram()
826 if (timer->is_soft) { in hrtimer_reprogram()
831 * first hard hrtimer on the remote CPU - in hrtimer_reprogram()
834 struct hrtimer_cpu_base *timer_cpu_base = base->cpu_base; in hrtimer_reprogram()
836 if (timer_cpu_base->softirq_activated) in hrtimer_reprogram()
839 if (!ktime_before(expires, timer_cpu_base->softirq_expires_next)) in hrtimer_reprogram()
842 timer_cpu_base->softirq_next_timer = timer; in hrtimer_reprogram()
843 timer_cpu_base->softirq_expires_next = expires; in hrtimer_reprogram()
845 if (!ktime_before(expires, timer_cpu_base->expires_next) || in hrtimer_reprogram()
851 * If the timer is not on the current cpu, we cannot reprogram in hrtimer_reprogram()
854 if (base->cpu_base != cpu_base) in hrtimer_reprogram()
857 if (expires >= cpu_base->expires_next) in hrtimer_reprogram()
864 if (cpu_base->in_hrtirq) in hrtimer_reprogram()
867 cpu_base->next_timer = timer; in hrtimer_reprogram()
873 unsigned int active) in update_needs_ipi() argument
889 seq = cpu_base->clock_was_set_seq; in update_needs_ipi()
893 * If the sequence did not change over the update then the in update_needs_ipi()
896 if (seq == cpu_base->clock_was_set_seq) in update_needs_ipi()
904 if (cpu_base->in_hrtirq) in update_needs_ipi()
913 active &= cpu_base->active_bases; in update_needs_ipi()
915 for_each_active_base(base, cpu_base, active) { in update_needs_ipi()
918 next = timerqueue_getnext(&base->active); in update_needs_ipi()
919 expires = ktime_sub(next->expires, base->offset); in update_needs_ipi()
920 if (expires < cpu_base->expires_next) in update_needs_ipi()
924 if (base->clockid < HRTIMER_BASE_MONOTONIC_SOFT) in update_needs_ipi()
926 if (cpu_base->softirq_activated) in update_needs_ipi()
928 if (expires < cpu_base->softirq_expires_next) in update_needs_ipi()
939 * vs. CLOCK_MONOTONIC. When high resolution timers are enabled, then this
968 raw_spin_lock_irqsave(&cpu_base->lock, flags); in clock_was_set()
973 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in clock_was_set()
1019 __releases(&timer->base->cpu_base->lock) in unlock_hrtimer_base()
1021 raw_spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags); in unlock_hrtimer_base()
1025 * hrtimer_forward - forward the timer expiry
1051 if (WARN_ON(timer->state & HRTIMER_STATE_ENQUEUED)) in hrtimer_forward()
1077 * enqueue_hrtimer - internal function to (re)start a timer
1089 WARN_ON_ONCE(!base->cpu_base->online); in enqueue_hrtimer()
1091 base->cpu_base->active_bases |= 1 << base->index; in enqueue_hrtimer()
1094 WRITE_ONCE(timer->state, HRTIMER_STATE_ENQUEUED); in enqueue_hrtimer()
1096 return timerqueue_add(&base->active, &timer->node); in enqueue_hrtimer()
1100 * __remove_hrtimer - internal function to remove a timer
1104 * High resolution timer mode reprograms the clock event device when the
1113 struct hrtimer_cpu_base *cpu_base = base->cpu_base; in __remove_hrtimer()
1114 u8 state = timer->state; in __remove_hrtimer()
1117 WRITE_ONCE(timer->state, newstate); in __remove_hrtimer()
1121 if (!timerqueue_del(&base->active, &timer->node)) in __remove_hrtimer()
1122 cpu_base->active_bases &= ~(1 << base->index); in __remove_hrtimer()
1126 * cpu_base->next_timer. This happens when we remove the first in __remove_hrtimer()
1128 * cpu_base->next_timer. So the worst thing what can happen is in __remove_hrtimer()
1132 if (reprogram && timer == cpu_base->next_timer) in __remove_hrtimer()
1143 u8 state = timer->state; in remove_hrtimer()
1149 * Remove the timer and force reprogramming when high in remove_hrtimer()
1150 * resolution mode is active and the timer is on the current in remove_hrtimer()
1157 reprogram = base->cpu_base == this_cpu_ptr(&hrtimer_bases); in remove_hrtimer()
1185 timer->is_rel = mode & HRTIMER_MODE_REL; in hrtimer_update_lowres()
1186 if (timer->is_rel) in hrtimer_update_lowres()
1205 * hrtimer. cpu_base->softirq_expires_next needs to be updated! in hrtimer_update_softirq_timer()
1211 * cpu_base->*next_timer is recomputed by __hrtimer_get_next_event() in hrtimer_update_softirq_timer()
1212 * cpu_base->*expires_next is only set by hrtimer_reprogram() in hrtimer_update_softirq_timer()
1214 hrtimer_reprogram(cpu_base->softirq_next_timer, reprogram); in hrtimer_update_softirq_timer()
1228 * reprogram on removal, keep the timer local to the current CPU in __hrtimer_start_range_ns()
1232 force_local = base->cpu_base == this_cpu_ptr(&hrtimer_bases); in __hrtimer_start_range_ns()
1233 force_local &= base->cpu_base->next_timer == timer; in __hrtimer_start_range_ns()
1236 * Remove an active timer from the queue. In case it is not queued in __hrtimer_start_range_ns()
1237 * on the current CPU, make sure that remove_hrtimer() updates the in __hrtimer_start_range_ns()
1240 * If it's on the current CPU and the first expiring timer, then in __hrtimer_start_range_ns()
1249 tim = ktime_add_safe(tim, base->get_time()); in __hrtimer_start_range_ns()
1268 * Timer was forced to stay on the current CPU to avoid in __hrtimer_start_range_ns()
1272 hrtimer_force_reprogram(new_base->cpu_base, 1); in __hrtimer_start_range_ns()
1277 * hrtimer_start_range_ns - (re)start an hrtimer
1291 if (WARN_ON_ONCE(!timer->function)) in hrtimer_start_range_ns()
1299 WARN_ON_ONCE(!(mode & HRTIMER_MODE_SOFT) ^ !timer->is_soft); in hrtimer_start_range_ns()
1301 WARN_ON_ONCE(!(mode & HRTIMER_MODE_HARD) ^ !timer->is_hard); in hrtimer_start_range_ns()
1313 * hrtimer_try_to_cancel - try to deactivate a timer
1318 * * 0 when the timer was not active
1319 * * 1 when the timer was active
1320 * * -1 when the timer is currently executing the callback function and
1327 int ret = -1; in hrtimer_try_to_cancel()
1330 * Check lockless first. If the timer is not active (neither in hrtimer_try_to_cancel()
1353 spin_lock_init(&base->softirq_expiry_lock); in hrtimer_cpu_base_init_expiry_lock()
1358 spin_lock(&base->softirq_expiry_lock); in hrtimer_cpu_base_lock_expiry()
1363 spin_unlock(&base->softirq_expiry_lock); in hrtimer_cpu_base_unlock_expiry()
1369 * If there is a waiter for cpu_base->expiry_lock, then it was waiting for
1376 if (atomic_read(&cpu_base->timer_waiters)) { in hrtimer_sync_wait_running()
1377 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_sync_wait_running()
1378 spin_unlock(&cpu_base->softirq_expiry_lock); in hrtimer_sync_wait_running()
1379 spin_lock(&cpu_base->softirq_expiry_lock); in hrtimer_sync_wait_running()
1380 raw_spin_lock_irq(&cpu_base->lock); in hrtimer_sync_wait_running()
1393 * - If the caller is on a remote CPU then it has to spin wait for the timer
1396 * - If the caller originates from the task which preempted the timer
1403 struct hrtimer_clock_base *base = READ_ONCE(timer->base); in hrtimer_cancel_wait_running()
1409 if (!timer->is_soft || is_migration_base(base)) { in hrtimer_cancel_wait_running()
1421 atomic_inc(&base->cpu_base->timer_waiters); in hrtimer_cancel_wait_running()
1422 spin_lock_bh(&base->cpu_base->softirq_expiry_lock); in hrtimer_cancel_wait_running()
1423 atomic_dec(&base->cpu_base->timer_waiters); in hrtimer_cancel_wait_running()
1424 spin_unlock_bh(&base->cpu_base->softirq_expiry_lock); in hrtimer_cancel_wait_running()
1438 * hrtimer_cancel - cancel a timer and wait for the handler to finish.
1442 * 0 when the timer was not active
1443 * 1 when the timer was active
1460 * __hrtimer_get_remaining - get remaining time for the timer
1482 * hrtimer_get_next_event - get the time until next expiry event
1492 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_get_next_event()
1497 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_get_next_event()
1503 * hrtimer_next_event_without - time until next expiry event w/o one timer
1506 * Returns the next expiry time over all timers except for the @exclude one or
1515 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_next_event_without()
1518 unsigned int active; in hrtimer_next_event_without() local
1520 if (!cpu_base->softirq_activated) { in hrtimer_next_event_without()
1521 active = cpu_base->active_bases & HRTIMER_ACTIVE_SOFT; in hrtimer_next_event_without()
1523 active, KTIME_MAX); in hrtimer_next_event_without()
1525 active = cpu_base->active_bases & HRTIMER_ACTIVE_HARD; in hrtimer_next_event_without()
1526 expires = __hrtimer_next_event_base(cpu_base, exclude, active, in hrtimer_next_event_without()
1530 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_next_event_without()
1578 timer->is_soft = softtimer; in __hrtimer_init()
1579 timer->is_hard = !!(mode & HRTIMER_MODE_HARD); in __hrtimer_init()
1580 timer->base = &cpu_base->clock_base[base]; in __hrtimer_init()
1581 timerqueue_init(&timer->node); in __hrtimer_init()
1585 * hrtimer_init - initialize a timer to the given clock
1605 * A timer is active, when it is enqueued into the rbtree or the
1617 base = READ_ONCE(timer->base); in hrtimer_active()
1618 seq = raw_read_seqcount_begin(&base->seq); in hrtimer_active()
1620 if (timer->state != HRTIMER_STATE_INACTIVE || in hrtimer_active()
1621 base->running == timer) in hrtimer_active()
1624 } while (read_seqcount_retry(&base->seq, seq) || in hrtimer_active()
1625 base != READ_ONCE(timer->base)); in hrtimer_active()
1635 * - queued: the timer is queued
1636 * - callback: the timer is being ran
1637 * - post: the timer is inactive or (re)queued
1639 * On the read side we ensure we observe timer->state and cpu_base->running
1641 * This includes timer->base changing because sequence numbers alone are
1645 * a false negative if the read side got smeared over multiple consecutive
1652 unsigned long flags) __must_hold(&cpu_base->lock) in __run_hrtimer()
1658 lockdep_assert_held(&cpu_base->lock); in __run_hrtimer()
1661 base->running = timer; in __run_hrtimer()
1664 * Separate the ->running assignment from the ->state assignment. in __run_hrtimer()
1667 * hrtimer_active() cannot observe base->running == NULL && in __run_hrtimer()
1668 * timer->state == INACTIVE. in __run_hrtimer()
1670 raw_write_seqcount_barrier(&base->seq); in __run_hrtimer()
1673 fn = timer->function; in __run_hrtimer()
1681 timer->is_rel = false; in __run_hrtimer()
1688 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in __run_hrtimer()
1696 raw_spin_lock_irq(&cpu_base->lock); in __run_hrtimer()
1703 * Note: Because we dropped the cpu_base->lock above, in __run_hrtimer()
1708 !(timer->state & HRTIMER_STATE_ENQUEUED)) in __run_hrtimer()
1712 * Separate the ->running assignment from the ->state assignment. in __run_hrtimer()
1715 * hrtimer_active() cannot observe base->running.timer == NULL && in __run_hrtimer()
1716 * timer->state == INACTIVE. in __run_hrtimer()
1718 raw_write_seqcount_barrier(&base->seq); in __run_hrtimer()
1720 WARN_ON_ONCE(base->running != timer); in __run_hrtimer()
1721 base->running = NULL; in __run_hrtimer()
1728 unsigned int active = cpu_base->active_bases & active_mask; in __hrtimer_run_queues() local
1730 for_each_active_base(base, cpu_base, active) { in __hrtimer_run_queues()
1734 basenow = ktime_add(now, base->offset); in __hrtimer_run_queues()
1736 while ((node = timerqueue_getnext(&base->active))) { in __hrtimer_run_queues()
1750 * are right-of a not yet expired timer, because that in __hrtimer_run_queues()
1770 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_run_softirq()
1775 cpu_base->softirq_activated = 0; in hrtimer_run_softirq()
1778 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_run_softirq()
1785 * High resolution timer interrupt
1795 BUG_ON(!cpu_base->hres_active); in hrtimer_interrupt()
1796 cpu_base->nr_events++; in hrtimer_interrupt()
1797 dev->next_event = KTIME_MAX; in hrtimer_interrupt()
1799 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_interrupt()
1802 cpu_base->in_hrtirq = 1; in hrtimer_interrupt()
1804 * We set expires_next to KTIME_MAX here with cpu_base->lock in hrtimer_interrupt()
1810 cpu_base->expires_next = KTIME_MAX; in hrtimer_interrupt()
1812 if (!ktime_before(now, cpu_base->softirq_expires_next)) { in hrtimer_interrupt()
1813 cpu_base->softirq_expires_next = KTIME_MAX; in hrtimer_interrupt()
1814 cpu_base->softirq_activated = 1; in hrtimer_interrupt()
1826 cpu_base->expires_next = expires_next; in hrtimer_interrupt()
1827 cpu_base->in_hrtirq = 0; in hrtimer_interrupt()
1828 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_interrupt()
1832 cpu_base->hang_detected = 0; in hrtimer_interrupt()
1838 * - tracing in hrtimer_interrupt()
1839 * - long lasting callbacks in hrtimer_interrupt()
1840 * - being scheduled away when running in a VM in hrtimer_interrupt()
1847 * the current time. in hrtimer_interrupt()
1849 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_interrupt()
1851 cpu_base->nr_retries++; in hrtimer_interrupt()
1860 cpu_base->nr_hangs++; in hrtimer_interrupt()
1861 cpu_base->hang_detected = 1; in hrtimer_interrupt()
1862 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_interrupt()
1865 if ((unsigned int)delta > cpu_base->max_hang_time) in hrtimer_interrupt()
1866 cpu_base->max_hang_time = (unsigned int) delta; in hrtimer_interrupt()
1888 if (td && td->evtdev) in __hrtimer_peek_ahead_timers()
1889 hrtimer_interrupt(td->evtdev); in __hrtimer_peek_ahead_timers()
1922 raw_spin_lock_irqsave(&cpu_base->lock, flags); in hrtimer_run_queues()
1925 if (!ktime_before(now, cpu_base->softirq_expires_next)) { in hrtimer_run_queues()
1926 cpu_base->softirq_expires_next = KTIME_MAX; in hrtimer_run_queues()
1927 cpu_base->softirq_activated = 1; in hrtimer_run_queues()
1932 raw_spin_unlock_irqrestore(&cpu_base->lock, flags); in hrtimer_run_queues()
1942 struct task_struct *task = t->task; in hrtimer_wakeup()
1944 t->task = NULL; in hrtimer_wakeup()
1952 * hrtimer_sleeper_start_expires - Start a hrtimer sleeper timer
1969 if (IS_ENABLED(CONFIG_PREEMPT_RT) && sl->timer.is_hard) in hrtimer_sleeper_start_expires()
1972 hrtimer_start_expires(&sl->timer, mode); in hrtimer_sleeper_start_expires()
1993 * OTOH, privileged real-time user space applications rely on the in __hrtimer_init_sleeper()
1994 * low latency of hard interrupt wakeups. If the current task is in in __hrtimer_init_sleeper()
1995 * a real-time scheduling class, mark the mode for hard interrupt in __hrtimer_init_sleeper()
1999 if (task_is_realtime(current) && !(mode & HRTIMER_MODE_SOFT)) in __hrtimer_init_sleeper()
2003 __hrtimer_init(&sl->timer, clock_id, mode); in __hrtimer_init_sleeper()
2004 sl->timer.function = hrtimer_wakeup; in __hrtimer_init_sleeper()
2005 sl->task = current; in __hrtimer_init_sleeper()
2009 * hrtimer_init_sleeper - initialize sleeper to the given clock
2017 debug_init(&sl->timer, clock_id, mode); in hrtimer_init_sleeper()
2025 switch(restart->nanosleep.type) { in nanosleep_copyout()
2028 if (put_old_timespec32(ts, restart->nanosleep.compat_rmtp)) in nanosleep_copyout()
2029 return -EFAULT; in nanosleep_copyout()
2033 if (put_timespec64(ts, restart->nanosleep.rmtp)) in nanosleep_copyout()
2034 return -EFAULT; in nanosleep_copyout()
2039 return -ERESTART_RESTARTBLOCK; in nanosleep_copyout()
2050 if (likely(t->task)) in do_nanosleep()
2053 hrtimer_cancel(&t->timer); in do_nanosleep()
2056 } while (t->task && !signal_pending(current)); in do_nanosleep()
2060 if (!t->task) in do_nanosleep()
2063 restart = ¤t->restart_block; in do_nanosleep()
2064 if (restart->nanosleep.type != TT_NONE) { in do_nanosleep()
2065 ktime_t rem = hrtimer_expires_remaining(&t->timer); in do_nanosleep()
2074 return -ERESTART_RESTARTBLOCK; in do_nanosleep()
2082 hrtimer_init_sleeper_on_stack(&t, restart->nanosleep.clockid, in hrtimer_nanosleep_restart()
2084 hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); in hrtimer_nanosleep_restart()
2098 slack = current->timer_slack_ns; in hrtimer_nanosleep()
2099 if (rt_task(current)) in hrtimer_nanosleep()
2105 if (ret != -ERESTART_RESTARTBLOCK) in hrtimer_nanosleep()
2110 ret = -ERESTARTNOHAND; in hrtimer_nanosleep()
2114 restart = ¤t->restart_block; in hrtimer_nanosleep()
2115 restart->nanosleep.clockid = t.timer.base->clockid; in hrtimer_nanosleep()
2116 restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer); in hrtimer_nanosleep()
2131 return -EFAULT; in SYSCALL_DEFINE2()
2134 return -EINVAL; in SYSCALL_DEFINE2()
2136 current->restart_block.fn = do_no_restart_syscall; in SYSCALL_DEFINE2()
2137 current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; in SYSCALL_DEFINE2()
2138 current->restart_block.nanosleep.rmtp = rmtp; in SYSCALL_DEFINE2()
2153 return -EFAULT; in SYSCALL_DEFINE2()
2156 return -EINVAL; in SYSCALL_DEFINE2()
2158 current->restart_block.fn = do_no_restart_syscall; in SYSCALL_DEFINE2()
2159 current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; in SYSCALL_DEFINE2()
2160 current->restart_block.nanosleep.compat_rmtp = rmtp; in SYSCALL_DEFINE2()
2167 * Functions related to boot-time initialization:
2175 struct hrtimer_clock_base *clock_b = &cpu_base->clock_base[i]; in hrtimers_prepare_cpu()
2177 clock_b->cpu_base = cpu_base; in hrtimers_prepare_cpu()
2178 seqcount_raw_spinlock_init(&clock_b->seq, &cpu_base->lock); in hrtimers_prepare_cpu()
2179 timerqueue_init_head(&clock_b->active); in hrtimers_prepare_cpu()
2182 cpu_base->cpu = cpu; in hrtimers_prepare_cpu()
2191 /* Clear out any left over state from a CPU down operation */ in hrtimers_cpu_starting()
2192 cpu_base->active_bases = 0; in hrtimers_cpu_starting()
2193 cpu_base->hres_active = 0; in hrtimers_cpu_starting()
2194 cpu_base->hang_detected = 0; in hrtimers_cpu_starting()
2195 cpu_base->next_timer = NULL; in hrtimers_cpu_starting()
2196 cpu_base->softirq_next_timer = NULL; in hrtimers_cpu_starting()
2197 cpu_base->expires_next = KTIME_MAX; in hrtimers_cpu_starting()
2198 cpu_base->softirq_expires_next = KTIME_MAX; in hrtimers_cpu_starting()
2199 cpu_base->online = 1; in hrtimers_cpu_starting()
2211 while ((node = timerqueue_getnext(&old_base->active))) { in migrate_hrtimer_list()
2218 * timer could be seen as !active and just vanish away in migrate_hrtimer_list()
2222 timer->base = new_base; in migrate_hrtimer_list()
2249 raw_spin_lock(&old_base->lock); in hrtimers_cpu_dying()
2250 raw_spin_lock_nested(&new_base->lock, SINGLE_DEPTH_NESTING); in hrtimers_cpu_dying()
2253 migrate_hrtimer_list(&old_base->clock_base[i], in hrtimers_cpu_dying()
2254 &new_base->clock_base[i]); in hrtimers_cpu_dying()
2265 raw_spin_unlock(&new_base->lock); in hrtimers_cpu_dying()
2266 old_base->online = 0; in hrtimers_cpu_dying()
2267 raw_spin_unlock(&old_base->lock); in hrtimers_cpu_dying()
2282 * schedule_hrtimeout_range_clock - sleep until timeout
2308 return -EINTR; in schedule_hrtimeout_range_clock()
2315 if (rt_task(current)) in schedule_hrtimeout_range_clock()
2330 return !t.task ? 0 : -EINTR; in schedule_hrtimeout_range_clock()
2335 * schedule_hrtimeout_range - sleep until timeout
2340 * Make the current task sleep until the given expiry time has
2342 * the current task state has been set (see set_current_state()).
2350 * You can set the task state as follows -
2352 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
2353 * pass before the routine returns unless the current task is explicitly
2356 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
2357 * delivered to the current task or the current task is explicitly woken
2360 * The current task state is guaranteed to be TASK_RUNNING when this
2365 * by an explicit wakeup, it returns -EINTR.
2376 * schedule_hrtimeout - sleep until timeout
2380 * Make the current task sleep until the given expiry time has
2382 * the current task state has been set (see set_current_state()).
2384 * You can set the task state as follows -
2386 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
2387 * pass before the routine returns unless the current task is explicitly
2390 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
2391 * delivered to the current task or the current task is explicitly woken
2394 * The current task state is guaranteed to be TASK_RUNNING when this
2399 * by an explicit wakeup, it returns -EINTR.