.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | | - * linux/kernel/time/tick-sched.c |
---|
3 | | - * |
---|
4 | 3 | * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de> |
---|
5 | 4 | * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar |
---|
6 | 5 | * Copyright(C) 2006-2007 Timesys Corp., Thomas Gleixner |
---|
.. | .. |
---|
8 | 7 | * No idle tick implementation for low and high resolution timers |
---|
9 | 8 | * |
---|
10 | 9 | * Started by: Thomas Gleixner and Ingo Molnar |
---|
11 | | - * |
---|
12 | | - * Distribute under GPLv2. |
---|
13 | 10 | */ |
---|
14 | 11 | #include <linux/cpu.h> |
---|
15 | 12 | #include <linux/err.h> |
---|
.. | .. |
---|
26 | 23 | #include <linux/module.h> |
---|
27 | 24 | #include <linux/irq_work.h> |
---|
28 | 25 | #include <linux/posix-timers.h> |
---|
29 | | -#include <linux/timer.h> |
---|
30 | 26 | #include <linux/context_tracking.h> |
---|
31 | 27 | #include <linux/mm.h> |
---|
| 28 | +#include <trace/hooks/sched.h> |
---|
32 | 29 | |
---|
33 | 30 | #include <asm/irq_regs.h> |
---|
34 | 31 | |
---|
.. | .. |
---|
57 | 54 | */ |
---|
58 | 55 | static void tick_do_update_jiffies64(ktime_t now) |
---|
59 | 56 | { |
---|
60 | | - unsigned long ticks = 0; |
---|
| 57 | + unsigned long ticks = 1; |
---|
61 | 58 | ktime_t delta; |
---|
62 | 59 | |
---|
63 | 60 | /* |
---|
64 | | - * Do a quick check without holding jiffies_lock: |
---|
65 | | - * The READ_ONCE() pairs with two updates done later in this function. |
---|
| 61 | + * Do a quick check without holding jiffies_lock. The READ_ONCE() |
---|
| 62 | + * pairs with the update done later in this function. |
---|
| 63 | + * |
---|
| 64 | + * This is also an intentional data race which is even safe on |
---|
| 65 | + * 32bit in theory. If there is a concurrent update then the check |
---|
| 66 | + * might give a random answer. It does not matter because if it |
---|
| 67 | + * returns then the concurrent update is already taking care, if it |
---|
| 68 | + * falls through then it will pointlessly contend on jiffies_lock. |
---|
| 69 | + * |
---|
| 70 | + * Though there is one nasty case on 32bit due to store tearing of |
---|
| 71 | + * the 64bit value. If the first 32bit store makes the quick check |
---|
| 72 | + * return on all other CPUs and the writing CPU context gets |
---|
| 73 | + * delayed to complete the second store (scheduled out on virt) |
---|
| 74 | + * then jiffies can become stale for up to ~2^32 nanoseconds |
---|
| 75 | + * without noticing. After that point all CPUs will wait for |
---|
| 76 | + * jiffies lock. |
---|
| 77 | + * |
---|
| 78 | + * OTOH, this is not any different than the situation with NOHZ=off |
---|
| 79 | + * where one CPU is responsible for updating jiffies and |
---|
| 80 | + * timekeeping. If that CPU goes out for lunch then all other CPUs |
---|
| 81 | + * will operate on stale jiffies until it decides to come back. |
---|
66 | 82 | */ |
---|
67 | | - delta = ktime_sub(now, READ_ONCE(last_jiffies_update)); |
---|
68 | | - if (delta < tick_period) |
---|
| 83 | + if (ktime_before(now, READ_ONCE(tick_next_period))) |
---|
69 | 84 | return; |
---|
70 | 85 | |
---|
71 | 86 | /* Reevaluate with jiffies_lock held */ |
---|
72 | | - write_seqlock(&jiffies_lock); |
---|
73 | | - |
---|
74 | | - delta = ktime_sub(now, last_jiffies_update); |
---|
75 | | - if (delta >= tick_period) { |
---|
76 | | - |
---|
77 | | - delta = ktime_sub(delta, tick_period); |
---|
78 | | - /* Pairs with the lockless read in this function. */ |
---|
79 | | - WRITE_ONCE(last_jiffies_update, |
---|
80 | | - ktime_add(last_jiffies_update, tick_period)); |
---|
81 | | - |
---|
82 | | - /* Slow path for long timeouts */ |
---|
83 | | - if (unlikely(delta >= tick_period)) { |
---|
84 | | - s64 incr = ktime_to_ns(tick_period); |
---|
85 | | - |
---|
86 | | - ticks = ktime_divns(delta, incr); |
---|
87 | | - |
---|
88 | | - /* Pairs with the lockless read in this function. */ |
---|
89 | | - WRITE_ONCE(last_jiffies_update, |
---|
90 | | - ktime_add_ns(last_jiffies_update, |
---|
91 | | - incr * ticks)); |
---|
92 | | - } |
---|
93 | | - do_timer(++ticks); |
---|
94 | | - |
---|
95 | | - /* Keep the tick_next_period variable up to date */ |
---|
96 | | - tick_next_period = ktime_add(last_jiffies_update, tick_period); |
---|
97 | | - } else { |
---|
98 | | - write_sequnlock(&jiffies_lock); |
---|
| 87 | + raw_spin_lock(&jiffies_lock); |
---|
| 88 | + if (ktime_before(now, tick_next_period)) { |
---|
| 89 | + raw_spin_unlock(&jiffies_lock); |
---|
99 | 90 | return; |
---|
100 | 91 | } |
---|
101 | | - write_sequnlock(&jiffies_lock); |
---|
| 92 | + |
---|
| 93 | + write_seqcount_begin(&jiffies_seq); |
---|
| 94 | + |
---|
| 95 | + delta = ktime_sub(now, tick_next_period); |
---|
| 96 | + if (unlikely(delta >= TICK_NSEC)) { |
---|
| 97 | + /* Slow path for long idle sleep times */ |
---|
| 98 | + s64 incr = TICK_NSEC; |
---|
| 99 | + |
---|
| 100 | + ticks += ktime_divns(delta, incr); |
---|
| 101 | + |
---|
| 102 | + last_jiffies_update = ktime_add_ns(last_jiffies_update, |
---|
| 103 | + incr * ticks); |
---|
| 104 | + } else { |
---|
| 105 | + last_jiffies_update = ktime_add_ns(last_jiffies_update, |
---|
| 106 | + TICK_NSEC); |
---|
| 107 | + } |
---|
| 108 | + |
---|
| 109 | + do_timer(ticks); |
---|
| 110 | + |
---|
| 111 | + /* |
---|
| 112 | + * Keep the tick_next_period variable up to date. WRITE_ONCE() |
---|
| 113 | + * pairs with the READ_ONCE() in the lockless quick check above. |
---|
| 114 | + */ |
---|
| 115 | + WRITE_ONCE(tick_next_period, |
---|
| 116 | + ktime_add_ns(last_jiffies_update, TICK_NSEC)); |
---|
| 117 | + |
---|
| 118 | + write_seqcount_end(&jiffies_seq); |
---|
| 119 | + raw_spin_unlock(&jiffies_lock); |
---|
102 | 120 | update_wall_time(); |
---|
103 | 121 | } |
---|
104 | 122 | |
---|
.. | .. |
---|
109 | 127 | { |
---|
110 | 128 | ktime_t period; |
---|
111 | 129 | |
---|
112 | | - write_seqlock(&jiffies_lock); |
---|
| 130 | + raw_spin_lock(&jiffies_lock); |
---|
| 131 | + write_seqcount_begin(&jiffies_seq); |
---|
113 | 132 | /* Did we start the jiffies update yet ? */ |
---|
114 | | - if (last_jiffies_update == 0) |
---|
| 133 | + if (last_jiffies_update == 0) { |
---|
| 134 | + u32 rem; |
---|
| 135 | + |
---|
| 136 | + /* |
---|
| 137 | + * Ensure that the tick is aligned to a multiple of |
---|
| 138 | + * TICK_NSEC. |
---|
| 139 | + */ |
---|
| 140 | + div_u64_rem(tick_next_period, TICK_NSEC, &rem); |
---|
| 141 | + if (rem) |
---|
| 142 | + tick_next_period += TICK_NSEC - rem; |
---|
| 143 | + |
---|
115 | 144 | last_jiffies_update = tick_next_period; |
---|
| 145 | + } |
---|
116 | 146 | period = last_jiffies_update; |
---|
117 | | - write_sequnlock(&jiffies_lock); |
---|
| 147 | + write_seqcount_end(&jiffies_seq); |
---|
| 148 | + raw_spin_unlock(&jiffies_lock); |
---|
118 | 149 | return period; |
---|
119 | 150 | } |
---|
| 151 | + |
---|
| 152 | +#define MAX_STALLED_JIFFIES 5 |
---|
120 | 153 | |
---|
121 | 154 | static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) |
---|
122 | 155 | { |
---|
.. | .. |
---|
129 | 162 | * into a long sleep. If two CPUs happen to assign themselves to |
---|
130 | 163 | * this duty, then the jiffies update is still serialized by |
---|
131 | 164 | * jiffies_lock. |
---|
| 165 | + * |
---|
| 166 | + * If nohz_full is enabled, this should not happen because the |
---|
| 167 | + * tick_do_timer_cpu never relinquishes. |
---|
132 | 168 | */ |
---|
133 | | - if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE) |
---|
134 | | - && !tick_nohz_full_cpu(cpu)) |
---|
| 169 | + if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) { |
---|
| 170 | +#ifdef CONFIG_NO_HZ_FULL |
---|
| 171 | + WARN_ON_ONCE(tick_nohz_full_running); |
---|
| 172 | +#endif |
---|
135 | 173 | tick_do_timer_cpu = cpu; |
---|
| 174 | + } |
---|
136 | 175 | #endif |
---|
137 | 176 | |
---|
138 | 177 | /* Check, if the jiffies need an update */ |
---|
139 | | - if (tick_do_timer_cpu == cpu) |
---|
| 178 | + if (tick_do_timer_cpu == cpu) { |
---|
140 | 179 | tick_do_update_jiffies64(now); |
---|
| 180 | + trace_android_vh_jiffies_update(NULL); |
---|
| 181 | + } |
---|
| 182 | + |
---|
| 183 | + /* |
---|
| 184 | + * If jiffies update stalled for too long (timekeeper in stop_machine() |
---|
| 185 | + * or VMEXIT'ed for several msecs), force an update. |
---|
| 186 | + */ |
---|
| 187 | + if (ts->last_tick_jiffies != jiffies) { |
---|
| 188 | + ts->stalled_jiffies = 0; |
---|
| 189 | + ts->last_tick_jiffies = READ_ONCE(jiffies); |
---|
| 190 | + } else { |
---|
| 191 | + if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) { |
---|
| 192 | + tick_do_update_jiffies64(now); |
---|
| 193 | + ts->stalled_jiffies = 0; |
---|
| 194 | + ts->last_tick_jiffies = READ_ONCE(jiffies); |
---|
| 195 | + } |
---|
| 196 | + } |
---|
141 | 197 | |
---|
142 | 198 | if (ts->inidle) |
---|
143 | 199 | ts->got_idle_tick = 1; |
---|
.. | .. |
---|
174 | 230 | #ifdef CONFIG_NO_HZ_FULL |
---|
175 | 231 | cpumask_var_t tick_nohz_full_mask; |
---|
176 | 232 | bool tick_nohz_full_running; |
---|
| 233 | +EXPORT_SYMBOL_GPL(tick_nohz_full_running); |
---|
177 | 234 | static atomic_t tick_dep_mask; |
---|
178 | 235 | |
---|
179 | 236 | static bool check_tick_dependency(atomic_t *dep) |
---|
.. | .. |
---|
197 | 254 | |
---|
198 | 255 | if (val & TICK_DEP_MASK_CLOCK_UNSTABLE) { |
---|
199 | 256 | trace_tick_stop(0, TICK_DEP_MASK_CLOCK_UNSTABLE); |
---|
| 257 | + return true; |
---|
| 258 | + } |
---|
| 259 | + |
---|
| 260 | + if (val & TICK_DEP_MASK_RCU) { |
---|
| 261 | + trace_tick_stop(0, TICK_DEP_MASK_RCU); |
---|
| 262 | + return true; |
---|
| 263 | + } |
---|
| 264 | + |
---|
| 265 | + if (val & TICK_DEP_MASK_RCU_EXP) { |
---|
| 266 | + trace_tick_stop(0, TICK_DEP_MASK_RCU_EXP); |
---|
200 | 267 | return true; |
---|
201 | 268 | } |
---|
202 | 269 | |
---|
.. | .. |
---|
232 | 299 | |
---|
233 | 300 | static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = { |
---|
234 | 301 | .func = nohz_full_kick_func, |
---|
| 302 | + .flags = ATOMIC_INIT(IRQ_WORK_HARD_IRQ), |
---|
235 | 303 | }; |
---|
236 | 304 | |
---|
237 | 305 | /* |
---|
.. | .. |
---|
326 | 394 | preempt_enable(); |
---|
327 | 395 | } |
---|
328 | 396 | } |
---|
| 397 | +EXPORT_SYMBOL_GPL(tick_nohz_dep_set_cpu); |
---|
329 | 398 | |
---|
330 | 399 | void tick_nohz_dep_clear_cpu(int cpu, enum tick_dep_bits bit) |
---|
331 | 400 | { |
---|
.. | .. |
---|
333 | 402 | |
---|
334 | 403 | atomic_andnot(BIT(bit), &ts->tick_dep_mask); |
---|
335 | 404 | } |
---|
| 405 | +EXPORT_SYMBOL_GPL(tick_nohz_dep_clear_cpu); |
---|
336 | 406 | |
---|
337 | 407 | /* |
---|
338 | | - * Set a per-task tick dependency. Posix CPU timers need this in order to elapse |
---|
339 | | - * per task timers. |
---|
| 408 | + * Set a per-task tick dependency. RCU need this. Also posix CPU timers |
---|
| 409 | + * in order to elapse per task timers. |
---|
340 | 410 | */ |
---|
341 | 411 | void tick_nohz_dep_set_task(struct task_struct *tsk, enum tick_dep_bits bit) |
---|
342 | 412 | { |
---|
343 | | - /* |
---|
344 | | - * We could optimize this with just kicking the target running the task |
---|
345 | | - * if that noise matters for nohz full users. |
---|
346 | | - */ |
---|
347 | | - tick_nohz_dep_set_all(&tsk->tick_dep_mask, bit); |
---|
| 413 | + if (!atomic_fetch_or(BIT(bit), &tsk->tick_dep_mask)) { |
---|
| 414 | + if (tsk == current) { |
---|
| 415 | + preempt_disable(); |
---|
| 416 | + tick_nohz_full_kick(); |
---|
| 417 | + preempt_enable(); |
---|
| 418 | + } else { |
---|
| 419 | + /* |
---|
| 420 | + * Some future tick_nohz_full_kick_task() |
---|
| 421 | + * should optimize this. |
---|
| 422 | + */ |
---|
| 423 | + tick_nohz_full_kick_all(); |
---|
| 424 | + } |
---|
| 425 | + } |
---|
348 | 426 | } |
---|
| 427 | +EXPORT_SYMBOL_GPL(tick_nohz_dep_set_task); |
---|
349 | 428 | |
---|
350 | 429 | void tick_nohz_dep_clear_task(struct task_struct *tsk, enum tick_dep_bits bit) |
---|
351 | 430 | { |
---|
352 | 431 | atomic_andnot(BIT(bit), &tsk->tick_dep_mask); |
---|
353 | 432 | } |
---|
| 433 | +EXPORT_SYMBOL_GPL(tick_nohz_dep_clear_task); |
---|
354 | 434 | |
---|
355 | 435 | /* |
---|
356 | 436 | * Set a per-taskgroup tick dependency. Posix CPU timers need this in order to elapse |
---|
.. | .. |
---|
400 | 480 | tick_nohz_full_running = true; |
---|
401 | 481 | } |
---|
402 | 482 | |
---|
403 | | -static int tick_nohz_cpu_down(unsigned int cpu) |
---|
| 483 | +bool tick_nohz_cpu_hotpluggable(unsigned int cpu) |
---|
404 | 484 | { |
---|
405 | 485 | /* |
---|
406 | | - * The boot CPU handles housekeeping duty (unbound timers, |
---|
407 | | - * workqueues, timekeeping, ...) on behalf of full dynticks |
---|
| 486 | + * The tick_do_timer_cpu CPU handles housekeeping duty (unbound |
---|
| 487 | + * timers, workqueues, timekeeping, ...) on behalf of full dynticks |
---|
408 | 488 | * CPUs. It must remain online when nohz full is enabled. |
---|
409 | 489 | */ |
---|
410 | 490 | if (tick_nohz_full_running && tick_do_timer_cpu == cpu) |
---|
411 | | - return -EBUSY; |
---|
412 | | - return 0; |
---|
| 491 | + return false; |
---|
| 492 | + return true; |
---|
| 493 | +} |
---|
| 494 | + |
---|
| 495 | +static int tick_nohz_cpu_down(unsigned int cpu) |
---|
| 496 | +{ |
---|
| 497 | + return tick_nohz_cpu_hotpluggable(cpu) ? 0 : -EBUSY; |
---|
413 | 498 | } |
---|
414 | 499 | |
---|
415 | 500 | void __init tick_nohz_init(void) |
---|
.. | .. |
---|
431 | 516 | return; |
---|
432 | 517 | } |
---|
433 | 518 | |
---|
434 | | - cpu = smp_processor_id(); |
---|
| 519 | + if (IS_ENABLED(CONFIG_PM_SLEEP_SMP) && |
---|
| 520 | + !IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU)) { |
---|
| 521 | + cpu = smp_processor_id(); |
---|
435 | 522 | |
---|
436 | | - if (cpumask_test_cpu(cpu, tick_nohz_full_mask)) { |
---|
437 | | - pr_warn("NO_HZ: Clearing %d from nohz_full range for timekeeping\n", |
---|
438 | | - cpu); |
---|
439 | | - cpumask_clear_cpu(cpu, tick_nohz_full_mask); |
---|
| 523 | + if (cpumask_test_cpu(cpu, tick_nohz_full_mask)) { |
---|
| 524 | + pr_warn("NO_HZ: Clearing %d from nohz_full range " |
---|
| 525 | + "for timekeeping\n", cpu); |
---|
| 526 | + cpumask_clear_cpu(cpu, tick_nohz_full_mask); |
---|
| 527 | + } |
---|
440 | 528 | } |
---|
441 | 529 | |
---|
442 | 530 | for_each_cpu(cpu, tick_nohz_full_mask) |
---|
.. | .. |
---|
631 | 719 | hrtimer_set_expires(&ts->sched_timer, ts->last_tick); |
---|
632 | 720 | |
---|
633 | 721 | /* Forward the time to expire in the future */ |
---|
634 | | - hrtimer_forward(&ts->sched_timer, now, tick_period); |
---|
| 722 | + hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); |
---|
635 | 723 | |
---|
636 | | - if (ts->nohz_mode == NOHZ_MODE_HIGHRES) |
---|
637 | | - hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED); |
---|
638 | | - else |
---|
| 724 | + if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { |
---|
| 725 | + hrtimer_start_expires(&ts->sched_timer, |
---|
| 726 | + HRTIMER_MODE_ABS_PINNED_HARD); |
---|
| 727 | + } else { |
---|
639 | 728 | tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); |
---|
| 729 | + } |
---|
640 | 730 | |
---|
641 | 731 | /* |
---|
642 | 732 | * Reset to make sure next tick stop doesn't get fooled by past |
---|
.. | .. |
---|
653 | 743 | static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) |
---|
654 | 744 | { |
---|
655 | 745 | u64 basemono, next_tick, next_tmr, next_rcu, delta, expires; |
---|
656 | | - unsigned long seq, basejiff; |
---|
| 746 | + unsigned long basejiff; |
---|
| 747 | + unsigned int seq; |
---|
657 | 748 | |
---|
658 | 749 | /* Read jiffies and the time when jiffies were updated last */ |
---|
659 | 750 | do { |
---|
660 | | - seq = read_seqbegin(&jiffies_lock); |
---|
| 751 | + seq = read_seqcount_begin(&jiffies_seq); |
---|
661 | 752 | basemono = last_jiffies_update; |
---|
662 | 753 | basejiff = jiffies; |
---|
663 | | - } while (read_seqretry(&jiffies_lock, seq)); |
---|
| 754 | + } while (read_seqcount_retry(&jiffies_seq, seq)); |
---|
664 | 755 | ts->last_jiffies = basejiff; |
---|
665 | 756 | ts->timer_expires_base = basemono; |
---|
666 | 757 | |
---|
.. | .. |
---|
780 | 871 | */ |
---|
781 | 872 | if (!ts->tick_stopped) { |
---|
782 | 873 | calc_load_nohz_start(); |
---|
783 | | - cpu_load_update_nohz_start(); |
---|
784 | 874 | quiet_vmstat(); |
---|
785 | 875 | |
---|
786 | 876 | ts->last_tick = hrtimer_get_expires(&ts->sched_timer); |
---|
.. | .. |
---|
797 | 887 | if (unlikely(expires == KTIME_MAX)) { |
---|
798 | 888 | if (ts->nohz_mode == NOHZ_MODE_HIGHRES) |
---|
799 | 889 | hrtimer_cancel(&ts->sched_timer); |
---|
| 890 | + else |
---|
| 891 | + tick_program_event(KTIME_MAX, 1); |
---|
800 | 892 | return; |
---|
801 | 893 | } |
---|
802 | 894 | |
---|
803 | 895 | if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { |
---|
804 | | - hrtimer_start(&ts->sched_timer, tick, HRTIMER_MODE_ABS_PINNED); |
---|
| 896 | + hrtimer_start(&ts->sched_timer, tick, |
---|
| 897 | + HRTIMER_MODE_ABS_PINNED_HARD); |
---|
805 | 898 | } else { |
---|
806 | 899 | hrtimer_set_expires(&ts->sched_timer, tick); |
---|
807 | 900 | tick_program_event(tick, 1); |
---|
.. | .. |
---|
827 | 920 | { |
---|
828 | 921 | /* Update jiffies first */ |
---|
829 | 922 | tick_do_update_jiffies64(now); |
---|
830 | | - cpu_load_update_nohz_stop(); |
---|
831 | 923 | |
---|
832 | 924 | /* |
---|
833 | 925 | * Clear the timer idle flag, so we avoid IPIs on remote queueing and |
---|
.. | .. |
---|
890 | 982 | if (need_resched()) |
---|
891 | 983 | return false; |
---|
892 | 984 | |
---|
893 | | - if (unlikely(local_softirq_pending() && cpu_online(cpu))) { |
---|
| 985 | + if (unlikely(local_softirq_pending())) { |
---|
894 | 986 | static int ratelimit; |
---|
895 | 987 | |
---|
896 | 988 | if (ratelimit < 10 && |
---|
897 | 989 | (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) { |
---|
898 | | - pr_warn("NOHZ: local_softirq_pending %02x\n", |
---|
| 990 | + pr_warn("NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #%02x!!!\n", |
---|
899 | 991 | (unsigned int) local_softirq_pending()); |
---|
900 | 992 | ratelimit++; |
---|
901 | 993 | } |
---|
.. | .. |
---|
909 | 1001 | */ |
---|
910 | 1002 | if (tick_do_timer_cpu == cpu) |
---|
911 | 1003 | return false; |
---|
912 | | - /* |
---|
913 | | - * Boot safety: make sure the timekeeping duty has been |
---|
914 | | - * assigned before entering dyntick-idle mode, |
---|
915 | | - */ |
---|
916 | | - if (tick_do_timer_cpu == TICK_DO_TIMER_NONE) |
---|
| 1004 | + |
---|
| 1005 | + /* Should not happen for nohz-full */ |
---|
| 1006 | + if (WARN_ON_ONCE(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) |
---|
917 | 1007 | return false; |
---|
918 | 1008 | } |
---|
919 | 1009 | |
---|
.. | .. |
---|
1031 | 1121 | } |
---|
1032 | 1122 | |
---|
1033 | 1123 | /** |
---|
| 1124 | + * tick_nohz_get_next_hrtimer - return the next expiration time for the hrtimer |
---|
| 1125 | + * or the tick, whatever that expires first. Note that, if the tick has been |
---|
| 1126 | + * stopped, it returns the next hrtimer. |
---|
| 1127 | + * |
---|
| 1128 | + * Called from power state control code with interrupts disabled |
---|
| 1129 | + */ |
---|
| 1130 | +ktime_t tick_nohz_get_next_hrtimer(void) |
---|
| 1131 | +{ |
---|
| 1132 | + return __this_cpu_read(tick_cpu_device.evtdev)->next_event; |
---|
| 1133 | +} |
---|
| 1134 | + |
---|
| 1135 | +/** |
---|
1034 | 1136 | * tick_nohz_get_sleep_length - return the expected length of the current sleep |
---|
1035 | 1137 | * @delta_next: duration until the next event if the tick cannot be stopped |
---|
1036 | 1138 | * |
---|
.. | .. |
---|
1082 | 1184 | |
---|
1083 | 1185 | return ts->idle_calls; |
---|
1084 | 1186 | } |
---|
| 1187 | +EXPORT_SYMBOL_GPL(tick_nohz_get_idle_calls_cpu); |
---|
1085 | 1188 | |
---|
1086 | 1189 | /** |
---|
1087 | 1190 | * tick_nohz_get_idle_calls - return the current idle calls counter value |
---|
.. | .. |
---|
1100 | 1203 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
---|
1101 | 1204 | unsigned long ticks; |
---|
1102 | 1205 | |
---|
1103 | | - if (vtime_accounting_cpu_enabled()) |
---|
| 1206 | + if (vtime_accounting_enabled_this_cpu()) |
---|
1104 | 1207 | return; |
---|
1105 | 1208 | /* |
---|
1106 | 1209 | * We stopped the tick in idle. Update process times would miss the |
---|
.. | .. |
---|
1178 | 1281 | tick_sched_do_timer(ts, now); |
---|
1179 | 1282 | tick_sched_handle(ts, regs); |
---|
1180 | 1283 | |
---|
1181 | | - /* No need to reprogram if we are running tickless */ |
---|
1182 | | - if (unlikely(ts->tick_stopped)) |
---|
| 1284 | + if (unlikely(ts->tick_stopped)) { |
---|
| 1285 | + /* |
---|
| 1286 | + * The clockevent device is not reprogrammed, so change the |
---|
| 1287 | + * clock event device to ONESHOT_STOPPED to avoid spurious |
---|
| 1288 | + * interrupts on devices which might not be truly one shot. |
---|
| 1289 | + */ |
---|
| 1290 | + tick_program_event(KTIME_MAX, 1); |
---|
1183 | 1291 | return; |
---|
| 1292 | + } |
---|
1184 | 1293 | |
---|
1185 | | - hrtimer_forward(&ts->sched_timer, now, tick_period); |
---|
| 1294 | + hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); |
---|
1186 | 1295 | tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); |
---|
1187 | 1296 | } |
---|
1188 | 1297 | |
---|
.. | .. |
---|
1214 | 1323 | * Recycle the hrtimer in ts, so we can share the |
---|
1215 | 1324 | * hrtimer_forward with the highres code. |
---|
1216 | 1325 | */ |
---|
1217 | | - hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
---|
| 1326 | + hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); |
---|
1218 | 1327 | /* Get the next period */ |
---|
1219 | 1328 | next = tick_init_jiffy_update(); |
---|
1220 | 1329 | |
---|
1221 | 1330 | hrtimer_set_expires(&ts->sched_timer, next); |
---|
1222 | | - hrtimer_forward_now(&ts->sched_timer, tick_period); |
---|
| 1331 | + hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); |
---|
1223 | 1332 | tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); |
---|
1224 | 1333 | tick_nohz_activate(ts, NOHZ_MODE_LOWRES); |
---|
1225 | 1334 | } |
---|
.. | .. |
---|
1259 | 1368 | * High resolution timer specific code |
---|
1260 | 1369 | */ |
---|
1261 | 1370 | #ifdef CONFIG_HIGH_RES_TIMERS |
---|
1262 | | - |
---|
1263 | | -static void (*wake_callback)(void); |
---|
1264 | | - |
---|
1265 | | -void register_tick_sched_wakeup_callback(void (*cb)(void)) |
---|
1266 | | -{ |
---|
1267 | | - if (!wake_callback) |
---|
1268 | | - wake_callback = cb; |
---|
1269 | | - else |
---|
1270 | | - pr_warn("tick-sched wake cb already exists; skipping.\n"); |
---|
1271 | | -} |
---|
1272 | | -EXPORT_SYMBOL_GPL(register_tick_sched_wakeup_callback); |
---|
1273 | | - |
---|
1274 | 1371 | /* |
---|
1275 | 1372 | * We rearm the timer until we get disabled by the idle code. |
---|
1276 | 1373 | * Called with interrupts disabled. |
---|
.. | .. |
---|
1288 | 1385 | * Do not call, when we are not in irq context and have |
---|
1289 | 1386 | * no valid regs pointer |
---|
1290 | 1387 | */ |
---|
1291 | | - if (regs) { |
---|
| 1388 | + if (regs) |
---|
1292 | 1389 | tick_sched_handle(ts, regs); |
---|
1293 | | - if (wake_callback && tick_do_timer_cpu == smp_processor_id()) { |
---|
1294 | | - /* |
---|
1295 | | - * wakeup user if needed |
---|
1296 | | - */ |
---|
1297 | | - wake_callback(); |
---|
1298 | | - } |
---|
1299 | | - } |
---|
1300 | 1390 | else |
---|
1301 | 1391 | ts->next_tick = 0; |
---|
1302 | 1392 | |
---|
.. | .. |
---|
1304 | 1394 | if (unlikely(ts->tick_stopped)) |
---|
1305 | 1395 | return HRTIMER_NORESTART; |
---|
1306 | 1396 | |
---|
1307 | | - hrtimer_forward(timer, now, tick_period); |
---|
| 1397 | + hrtimer_forward(timer, now, TICK_NSEC); |
---|
1308 | 1398 | |
---|
1309 | 1399 | return HRTIMER_RESTART; |
---|
1310 | 1400 | } |
---|
.. | .. |
---|
1330 | 1420 | /* |
---|
1331 | 1421 | * Emulate tick processing via per-CPU hrtimers: |
---|
1332 | 1422 | */ |
---|
1333 | | - hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
---|
| 1423 | + hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); |
---|
1334 | 1424 | ts->sched_timer.function = tick_sched_timer; |
---|
1335 | 1425 | |
---|
1336 | 1426 | /* Get the next period (per-CPU) */ |
---|
.. | .. |
---|
1338 | 1428 | |
---|
1339 | 1429 | /* Offset the tick to avert jiffies_lock contention. */ |
---|
1340 | 1430 | if (sched_skew_tick) { |
---|
1341 | | - u64 offset = ktime_to_ns(tick_period) >> 1; |
---|
| 1431 | + u64 offset = TICK_NSEC >> 1; |
---|
1342 | 1432 | do_div(offset, num_possible_cpus()); |
---|
1343 | 1433 | offset *= smp_processor_id(); |
---|
1344 | 1434 | hrtimer_add_expires_ns(&ts->sched_timer, offset); |
---|
1345 | 1435 | } |
---|
1346 | 1436 | |
---|
1347 | | - hrtimer_forward(&ts->sched_timer, now, tick_period); |
---|
1348 | | - hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED); |
---|
| 1437 | + hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); |
---|
| 1438 | + hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED_HARD); |
---|
1349 | 1439 | tick_nohz_activate(ts, NOHZ_MODE_HIGHRES); |
---|
1350 | 1440 | } |
---|
1351 | 1441 | #endif /* HIGH_RES_TIMERS */ |
---|
.. | .. |
---|
1412 | 1502 | tick_nohz_switch_to_nohz(); |
---|
1413 | 1503 | return 0; |
---|
1414 | 1504 | } |
---|
1415 | | - |
---|
1416 | | -ktime_t *get_next_event_cpu(unsigned int cpu) |
---|
1417 | | -{ |
---|
1418 | | - return &(per_cpu(tick_cpu_device, cpu).evtdev->next_event); |
---|
1419 | | -} |
---|
1420 | | -EXPORT_SYMBOL_GPL(get_next_event_cpu); |
---|