Skip to content

Commit 26456f8

Browse files
committed
timers: Reinitialize per cpu bases on hotplug
The timer wheel bases are not (re)initialized on CPU hotplug. That leaves them with a potentially stale clk and next_expiry valuem, which can cause trouble then the CPU is plugged. Add a prepare callback which forwards the clock, sets next_expiry to far in the future and reset the control flags to a known state. Set base->must_forward_clk so the first timer which is queued will try to forward the clock to current jiffies. Fixes: 500462a ("timers: Switch to a non-cascading wheel") Reported-by: Paul E. McKenney <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Sebastian Siewior <[email protected]> Cc: Anna-Maria Gleixner <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1712272152200.2431@nanos
1 parent ced6d5c commit 26456f8

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

include/linux/cpuhotplug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum cpuhp_state {
8686
CPUHP_MM_ZSWP_POOL_PREPARE,
8787
CPUHP_KVM_PPC_BOOK3S_PREPARE,
8888
CPUHP_ZCOMP_PREPARE,
89-
CPUHP_TIMERS_DEAD,
89+
CPUHP_TIMERS_PREPARE,
9090
CPUHP_MIPS_SOC_PREPARE,
9191
CPUHP_BP_PREPARE_DYN,
9292
CPUHP_BP_PREPARE_DYN_END = CPUHP_BP_PREPARE_DYN + 20,

include/linux/timer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ unsigned long round_jiffies_up(unsigned long j);
207207
unsigned long round_jiffies_up_relative(unsigned long j);
208208

209209
#ifdef CONFIG_HOTPLUG_CPU
210+
int timers_prepare_cpu(unsigned int cpu);
210211
int timers_dead_cpu(unsigned int cpu);
211212
#else
212-
#define timers_dead_cpu NULL
213+
#define timers_prepare_cpu NULL
214+
#define timers_dead_cpu NULL
213215
#endif
214216

215217
#endif

kernel/cpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,9 @@ static struct cpuhp_step cpuhp_bp_states[] = {
12771277
* before blk_mq_queue_reinit_notify() from notify_dead(),
12781278
* otherwise a RCU stall occurs.
12791279
*/
1280-
[CPUHP_TIMERS_DEAD] = {
1280+
[CPUHP_TIMERS_PREPARE] = {
12811281
.name = "timers:dead",
1282-
.startup.single = NULL,
1282+
.startup.single = timers_prepare_cpu,
12831283
.teardown.single = timers_dead_cpu,
12841284
},
12851285
/* Kicks the plugged cpu into life */

kernel/time/timer.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,21 @@ static void migrate_timer_list(struct timer_base *new_base, struct hlist_head *h
18531853
}
18541854
}
18551855

1856+
int timers_prepare_cpu(unsigned int cpu)
1857+
{
1858+
struct timer_base *base;
1859+
int b;
1860+
1861+
for (b = 0; b < NR_BASES; b++) {
1862+
base = per_cpu_ptr(&timer_bases[b], cpu);
1863+
base->clk = jiffies;
1864+
base->next_expiry = base->clk + NEXT_TIMER_MAX_DELTA;
1865+
base->is_idle = false;
1866+
base->must_forward_clk = true;
1867+
}
1868+
return 0;
1869+
}
1870+
18561871
int timers_dead_cpu(unsigned int cpu)
18571872
{
18581873
struct timer_base *old_base;

0 commit comments

Comments
 (0)