.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | | - * linux/kernel/time/tick-common.c |
---|
3 | | - * |
---|
4 | 3 | * This file contains the base functions to manage periodic tick |
---|
5 | 4 | * related events. |
---|
6 | 5 | * |
---|
7 | 6 | * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de> |
---|
8 | 7 | * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar |
---|
9 | 8 | * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner |
---|
10 | | - * |
---|
11 | | - * This code is licenced under the GPL version 2. For details see |
---|
12 | | - * kernel-base/COPYING. |
---|
13 | 9 | */ |
---|
14 | 10 | #include <linux/cpu.h> |
---|
15 | 11 | #include <linux/err.h> |
---|
.. | .. |
---|
21 | 17 | #include <linux/sched.h> |
---|
22 | 18 | #include <linux/module.h> |
---|
23 | 19 | #include <trace/events/power.h> |
---|
| 20 | +#include <trace/hooks/sched.h> |
---|
24 | 21 | |
---|
25 | 22 | #include <asm/irq_regs.h> |
---|
26 | 23 | |
---|
.. | .. |
---|
34 | 31 | * Tick next event: keeps track of the tick time |
---|
35 | 32 | */ |
---|
36 | 33 | ktime_t tick_next_period; |
---|
37 | | -ktime_t tick_period; |
---|
38 | 34 | |
---|
39 | 35 | /* |
---|
40 | 36 | * tick_do_timer_cpu is a timer core internal variable which holds the CPU NR |
---|
.. | .. |
---|
51 | 47 | * procedure also covers cpu hotplug. |
---|
52 | 48 | */ |
---|
53 | 49 | int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT; |
---|
| 50 | +#ifdef CONFIG_NO_HZ_FULL |
---|
| 51 | +/* |
---|
| 52 | + * tick_do_timer_boot_cpu indicates the boot CPU temporarily owns |
---|
| 53 | + * tick_do_timer_cpu and it should be taken over by an eligible secondary |
---|
| 54 | + * when one comes online. |
---|
| 55 | + */ |
---|
| 56 | +static int tick_do_timer_boot_cpu __read_mostly = -1; |
---|
| 57 | +#endif |
---|
54 | 58 | |
---|
55 | 59 | /* |
---|
56 | 60 | * Debugging: see timer_list.c |
---|
.. | .. |
---|
84 | 88 | write_seqcount_begin(&jiffies_seq); |
---|
85 | 89 | |
---|
86 | 90 | /* Keep track of the next tick event */ |
---|
87 | | - tick_next_period = ktime_add(tick_next_period, tick_period); |
---|
| 91 | + tick_next_period = ktime_add_ns(tick_next_period, TICK_NSEC); |
---|
88 | 92 | |
---|
89 | 93 | do_timer(1); |
---|
90 | 94 | write_seqcount_end(&jiffies_seq); |
---|
91 | 95 | raw_spin_unlock(&jiffies_lock); |
---|
92 | 96 | update_wall_time(); |
---|
| 97 | + trace_android_vh_jiffies_update(NULL); |
---|
93 | 98 | } |
---|
94 | 99 | |
---|
95 | 100 | update_process_times(user_mode(get_irq_regs())); |
---|
.. | .. |
---|
123 | 128 | * Setup the next period for devices, which do not have |
---|
124 | 129 | * periodic mode: |
---|
125 | 130 | */ |
---|
126 | | - next = ktime_add(next, tick_period); |
---|
| 131 | + next = ktime_add_ns(next, TICK_NSEC); |
---|
127 | 132 | |
---|
128 | 133 | if (!clockevents_program_event(dev, next, false)) |
---|
129 | 134 | return; |
---|
.. | .. |
---|
156 | 161 | !tick_broadcast_oneshot_active()) { |
---|
157 | 162 | clockevents_switch_state(dev, CLOCK_EVT_STATE_PERIODIC); |
---|
158 | 163 | } else { |
---|
159 | | - unsigned long seq; |
---|
| 164 | + unsigned int seq; |
---|
160 | 165 | ktime_t next; |
---|
161 | 166 | |
---|
162 | 167 | do { |
---|
.. | .. |
---|
169 | 174 | for (;;) { |
---|
170 | 175 | if (!clockevents_program_event(dev, next, false)) |
---|
171 | 176 | return; |
---|
172 | | - next = ktime_add(next, tick_period); |
---|
| 177 | + next = ktime_add_ns(next, TICK_NSEC); |
---|
173 | 178 | } |
---|
174 | 179 | } |
---|
175 | 180 | } |
---|
| 181 | + |
---|
| 182 | +#ifdef CONFIG_NO_HZ_FULL |
---|
| 183 | +static void giveup_do_timer(void *info) |
---|
| 184 | +{ |
---|
| 185 | + int cpu = *(unsigned int *)info; |
---|
| 186 | + |
---|
| 187 | + WARN_ON(tick_do_timer_cpu != smp_processor_id()); |
---|
| 188 | + |
---|
| 189 | + tick_do_timer_cpu = cpu; |
---|
| 190 | +} |
---|
| 191 | + |
---|
| 192 | +static void tick_take_do_timer_from_boot(void) |
---|
| 193 | +{ |
---|
| 194 | + int cpu = smp_processor_id(); |
---|
| 195 | + int from = tick_do_timer_boot_cpu; |
---|
| 196 | + |
---|
| 197 | + if (from >= 0 && from != cpu) |
---|
| 198 | + smp_call_function_single(from, giveup_do_timer, &cpu, 1); |
---|
| 199 | +} |
---|
| 200 | +#endif |
---|
176 | 201 | |
---|
177 | 202 | /* |
---|
178 | 203 | * Setup the tick device |
---|
.. | .. |
---|
193 | 218 | * this cpu: |
---|
194 | 219 | */ |
---|
195 | 220 | if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) { |
---|
196 | | - if (!tick_nohz_full_cpu(cpu)) |
---|
197 | | - tick_do_timer_cpu = cpu; |
---|
198 | | - else |
---|
199 | | - tick_do_timer_cpu = TICK_DO_TIMER_NONE; |
---|
| 221 | + tick_do_timer_cpu = cpu; |
---|
200 | 222 | tick_next_period = ktime_get(); |
---|
201 | | - tick_period = NSEC_PER_SEC / HZ; |
---|
| 223 | +#ifdef CONFIG_NO_HZ_FULL |
---|
| 224 | + /* |
---|
| 225 | + * The boot CPU may be nohz_full, in which case set |
---|
| 226 | + * tick_do_timer_boot_cpu so the first housekeeping |
---|
| 227 | + * secondary that comes up will take do_timer from |
---|
| 228 | + * us. |
---|
| 229 | + */ |
---|
| 230 | + if (tick_nohz_full_cpu(cpu)) |
---|
| 231 | + tick_do_timer_boot_cpu = cpu; |
---|
| 232 | + |
---|
| 233 | + } else if (tick_do_timer_boot_cpu != -1 && |
---|
| 234 | + !tick_nohz_full_cpu(cpu)) { |
---|
| 235 | + tick_take_do_timer_from_boot(); |
---|
| 236 | + tick_do_timer_boot_cpu = -1; |
---|
| 237 | + WARN_ON(tick_do_timer_cpu != cpu); |
---|
| 238 | +#endif |
---|
202 | 239 | } |
---|
203 | 240 | |
---|
204 | 241 | /* |
---|
.. | .. |
---|
340 | 377 | /* |
---|
341 | 378 | * Can the new device be used as a broadcast device ? |
---|
342 | 379 | */ |
---|
343 | | - tick_install_broadcast_device(newdev); |
---|
| 380 | + tick_install_broadcast_device(newdev, cpu); |
---|
344 | 381 | } |
---|
345 | 382 | |
---|
346 | 383 | /** |
---|