hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/kernel/time/tick-common.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
2
- * linux/kernel/time/tick-common.c
3
- *
43 * This file contains the base functions to manage periodic tick
54 * related events.
65 *
76 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
87 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
98 * 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.
139 */
1410 #include <linux/cpu.h>
1511 #include <linux/err.h>
....@@ -21,6 +17,7 @@
2117 #include <linux/sched.h>
2218 #include <linux/module.h>
2319 #include <trace/events/power.h>
20
+#include <trace/hooks/sched.h>
2421
2522 #include <asm/irq_regs.h>
2623
....@@ -34,7 +31,6 @@
3431 * Tick next event: keeps track of the tick time
3532 */
3633 ktime_t tick_next_period;
37
-ktime_t tick_period;
3834
3935 /*
4036 * tick_do_timer_cpu is a timer core internal variable which holds the CPU NR
....@@ -51,6 +47,14 @@
5147 * procedure also covers cpu hotplug.
5248 */
5349 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
5458
5559 /*
5660 * Debugging: see timer_list.c
....@@ -84,12 +88,13 @@
8488 write_seqcount_begin(&jiffies_seq);
8589
8690 /* 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);
8892
8993 do_timer(1);
9094 write_seqcount_end(&jiffies_seq);
9195 raw_spin_unlock(&jiffies_lock);
9296 update_wall_time();
97
+ trace_android_vh_jiffies_update(NULL);
9398 }
9499
95100 update_process_times(user_mode(get_irq_regs()));
....@@ -123,7 +128,7 @@
123128 * Setup the next period for devices, which do not have
124129 * periodic mode:
125130 */
126
- next = ktime_add(next, tick_period);
131
+ next = ktime_add_ns(next, TICK_NSEC);
127132
128133 if (!clockevents_program_event(dev, next, false))
129134 return;
....@@ -156,7 +161,7 @@
156161 !tick_broadcast_oneshot_active()) {
157162 clockevents_switch_state(dev, CLOCK_EVT_STATE_PERIODIC);
158163 } else {
159
- unsigned long seq;
164
+ unsigned int seq;
160165 ktime_t next;
161166
162167 do {
....@@ -169,10 +174,30 @@
169174 for (;;) {
170175 if (!clockevents_program_event(dev, next, false))
171176 return;
172
- next = ktime_add(next, tick_period);
177
+ next = ktime_add_ns(next, TICK_NSEC);
173178 }
174179 }
175180 }
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
176201
177202 /*
178203 * Setup the tick device
....@@ -193,12 +218,24 @@
193218 * this cpu:
194219 */
195220 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;
200222 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
202239 }
203240
204241 /*
....@@ -340,7 +377,7 @@
340377 /*
341378 * Can the new device be used as a broadcast device ?
342379 */
343
- tick_install_broadcast_device(newdev);
380
+ tick_install_broadcast_device(newdev, cpu);
344381 }
345382
346383 /**