Skip to contentSkip to conversation

hrtimer: Reset hrtimer cpu base proper on CPU hotplug

PATCH In review Thomas Gleixner 4 participants 9 messages Jan 26, 2018 – Jan 31, 2018 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hrtimer: Reset hrtimer cpu base proper on CPU hotplug

The hrtimer interrupt code contains a hang detection and mitigation mechanism, which prevents that a long delayed hrtimer interrupt causes a continous retriggering of interrupts which prevent the system from making progress. If a hang is detected then the timer hardware is programmed with a certain delay into the future and a flag is set in the hrtimer cpu base which prevents newly enqueued timers from reprogramming the timer hardware prior to the chosen delay. The subsequent hrtimer interrupt after the delay clears the flag and resumes normal operation.

If such a hang happens in the last hrtimer interrupt before a CPU is unplugged then the hang_detected flag is set and stays that way when the CPU is plugged in again. At that point the timer hardware is not armed and it cannot be armed because the hang_detected flag is still active, so nothing clears that flag. As a consequence the CPU does not receive hrtimer interrupts and no timers expire on that CPU which results in RCU stalls and other malfunctions.

Clear the flag along with some other less critical members of the hrtimer cpu base to ensure starting from a clean state when a CPU is plugged in.

Thanks to Paul, Sebastian and Anna-Maria for their help to get down to the root cause of that hard to reproduce heisenbug. Once understood it's trivial and certainly justifies a brown paperbag.

Fixes 41d2e4949377 ("hrtimer: Tune hrtimer_interrupt hang logic")
---
 kernel/time/hrtimer.c |    3 +++
 1 file changed, 3 insertions(+)
kernel/time/hrtimer.c +3 -0
@@ -655,7 +655,9 @@ static void hrtimer_reprogram(struct hrt
 static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base)
 {
 	base->expires_next = KTIME_MAX;
+	base->hang_detected = 0;
 	base->hres_active = 0;
+	base->next_timer = NULL;
 }
 
 /*
@@ -1589,6 +1591,7 @@ int hrtimers_prepare_cpu(unsigned int cp
 		timerqueue_init_head(&cpu_base->clock_base[i].active);
 	}
 
+	cpu_base->active_bases = 0;
 	cpu_base->cpu = cpu;
 	hrtimer_init_hres(cpu_base);
 	return 0;
#1 lore raw
Quoted 17 lines · Thomas Gleixner

The hrtimer interrupt code contains a hang detection and mitigation mechanism, which prevents that a long delayed hrtimer interrupt causes a continous retriggering of interrupts which prevent the system from making progress. If a hang is detected then the timer hardware is programmed with a certain delay into the future and a flag is set in the hrtimer cpu base which prevents newly enqueued timers from reprogramming the timer hardware prior to the chosen delay. The subsequent hrtimer interrupt after the delay clears the flag and resumes normal operation.

If such a hang happens in the last hrtimer interrupt before a CPU is unplugged then the hang_detected flag is set and stays that way when the CPU is plugged in again. At that point the timer hardware is not armed and it cannot be armed because the hang_detected flag is still active, so nothing clears that flag. As a consequence the CPU does not receive hrtimer interrupts and no timers expire on that CPU which results in RCU stalls and other malfunctions.

Quoted 6 lines

Clear the flag along with some other less critical members of the hrtimer cpu base to ensure starting from a clean state when a CPU is plugged in.

Thanks to Paul, Sebastian and Anna-Maria for their help to get down to the root cause of that hard to reproduce heisenbug. Once understood it's trivial and certainly justifies a brown paperbag.

Thank you very much, and I do know that feeling! After reading the commit log, I feel significantly less incompetent for having failed to find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

I have started an eight-hour seven-way test on the dreaded rcutorture TREE01 scenario. In the meantime, off to the train!

Thanx, Paul

Quoted 29 lines
Fixes 41d2e4949377 ("hrtimer: Tune hrtimer_interrupt hang logic")
---
 kernel/time/hrtimer.c |    3 +++
 1 file changed, 3 insertions(+)
kernel/time/hrtimer.c +3 -0
@@ -655,7 +655,9 @@ static void hrtimer_reprogram(struct hrt
 static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base)
 {
 	base->expires_next = KTIME_MAX;
+	base->hang_detected = 0;
 	base->hres_active = 0;
+	base->next_timer = NULL;
 }
 
 /*
@@ -1589,6 +1591,7 @@ int hrtimers_prepare_cpu(unsigned int cp
 		timerqueue_init_head(&cpu_base->clock_base[i].active);
 	}
 
+	cpu_base->active_bases = 0;
 	cpu_base->cpu = cpu;
 	hrtimer_init_hres(cpu_base);
 	return 0;
#2 lore raw
Quoted 25 lines · Paul E. McKenney
Quoted 17 lines · Thomas Gleixner

The hrtimer interrupt code contains a hang detection and mitigation mechanism, which prevents that a long delayed hrtimer interrupt causes a continous retriggering of interrupts which prevent the system from making progress. If a hang is detected then the timer hardware is programmed with a certain delay into the future and a flag is set in the hrtimer cpu base which prevents newly enqueued timers from reprogramming the timer hardware prior to the chosen delay. The subsequent hrtimer interrupt after the delay clears the flag and resumes normal operation.

If such a hang happens in the last hrtimer interrupt before a CPU is unplugged then the hang_detected flag is set and stays that way when the CPU is plugged in again. At that point the timer hardware is not armed and it cannot be armed because the hang_detected flag is still active, so nothing clears that flag. As a consequence the CPU does not receive hrtimer interrupts and no timers expire on that CPU which results in RCU stalls and other malfunctions.

Quoted 6 lines

Clear the flag along with some other less critical members of the hrtimer cpu base to ensure starting from a clean state when a CPU is plugged in.

Thanks to Paul, Sebastian and Anna-Maria for their help to get down to the root cause of that hard to reproduce heisenbug. Once understood it's trivial and certainly justifies a brown paperbag.

Quoted 7 lines

Thank you very much, and I do know that feeling! After reading the commit log, I feel significantly less incompetent for having failed to find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

I have started an eight-hour seven-way test on the dreaded rcutorture TREE01 scenario. In the meantime, off to the train!

And bozo here forgot to disable tracing, so the runs take much longer than the stated time. And because I applied against v4.15-rc9, which lacks the recent code to suppress stalls when dumping the trace log, all runs get RCU CPU stall warnings. :-/

But I can filter out those tracing-induced stall warnings easily enough, and thus far there have been 84 successful 30-minute runs out of 112 total, for no failures in 42 hours of TREE01 execution. Given the base failure rate of 0.33 per hour, the probability of this happening by chance is something like ten to the minus sixth power, so:

I will be running longer runs without tracing, but looking extremely good thus far! Thank you all very much!!!

Thanx, Paul

#3 lore raw
In reply to Paul E. McKenney
Quoted 2 lines · Paul E. McKenney

find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

It started to trigger better (or at all) on our test box with
modprobe kvm_intel preemption_timer=n

on the host kernel so maybe a completely unrelated change helped to trigger this.

Sebastian

#4 lore raw
Quoted 9 lines · Sebastian Sewior
Quoted 2 lines · Paul E. McKenney

find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

It started to trigger better (or at all) on our test box with
modprobe kvm_intel preemption_timer=n

on the host kernel so maybe a completely unrelated change helped to trigger this.

Good point!

And testing continues, currently at 108 hours of TREE01 without any waylayed timers, so looking good! ;-)

Just kicked off another 70 hours worth.

Thanx, Paul

#5 lore raw
Quoted 11 lines · Paul E. McKenney
Quoted 9 lines · Sebastian Sewior
Quoted 2 lines · Paul E. McKenney

find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

It started to trigger better (or at all) on our test box with
modprobe kvm_intel preemption_timer=n

on the host kernel so maybe a completely unrelated change helped to trigger this.

Quoted 6 lines

Good point!

And testing continues, currently at 108 hours of TREE01 without any waylayed timers, so looking good! ;-)

Just kicked off another 70 hours worth.

And those completed without incident for a total of 178 hours. I believe we can call this one fixed. Thank you all!!!

One question... Is the patch shown below needed, or is this just yet another case of me being confused? (The lack of it is not triggering, but...)

Thanx, Paul

------------------------------------------------------------------------

commit accb0edb85526a05b934eac49658d05ea0216fc4

Author: Paul E. McKenney <[email protected]>
Date:   Thu Dec 7 13:18:44 2017 -0800

timers: Ensure that timer_base ->clk accounts for time offline

The timer_base ->must_forward_clk is set to indicate that the next timer operation on that timer_base must check for passage of time. One instance of time passage is when the timer wheel goes idle, and another is when the corresponding CPU is offline. Note that it is not appropriate to set ->is_idle because that could result in IPIing an offline CPU. Therefore, this commit instead sets ->must_forward_clk at CPU-offline time.

kernel/time/timer.c +1 -0
index ffebcf878fba..94cce780c574 100644
@@ -1875,6 +1875,7 @@ int timers_dead_cpu(unsigned int cpu)
 
 		BUG_ON(old_base->running_timer);
 
+		old_base->must_forward_clk = true;
 		for (i = 0; i < WHEEL_SIZE; i++)
 			migrate_timer_list(new_base, old_base->vectors + i);
 
#6 lore raw
Quoted 17 lines · Paul E. McKenney
Quoted 16 lines · Paul E. McKenney
Quoted 9 lines · Sebastian Sewior
Quoted 2 lines · Paul E. McKenney

find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

It started to trigger better (or at all) on our test box with
modprobe kvm_intel preemption_timer=n

on the host kernel so maybe a completely unrelated change helped to trigger this.

Good point!

And testing continues, currently at 108 hours of TREE01 without any waylayed timers, so looking good! ;-)

Quoted 8 lines
Quoted 1 line

Just kicked off another 70 hours worth.

And those completed without incident for a total of 178 hours. I believe we can call this one fixed. Thank you all!!!

One question... Is the patch shown below needed, or is this just yet another case of me being confused? (The lack of it is not triggering, but...)

See commit 26456f87aca7

#7 lore raw
Quoted 21 lines · Thomas Gleixner
Quoted 19 lines · Paul E. McKenney
Quoted 17 lines · Paul E. McKenney
Quoted 9 lines · Sebastian Sewior
Quoted 2 lines · Paul E. McKenney

find this one. ;-) But it did pass rcutorture testing for a great many years, didn't it? :-/

It started to trigger better (or at all) on our test box with
modprobe kvm_intel preemption_timer=n

on the host kernel so maybe a completely unrelated change helped to trigger this.

Good point!

And testing continues, currently at 108 hours of TREE01 without any waylayed timers, so looking good! ;-)

Just kicked off another 70 hours worth.

Quoted 8 lines
Quoted 6 lines

And those completed without incident for a total of 178 hours. I believe we can call this one fixed. Thank you all!!!

One question... Is the patch shown below needed, or is this just yet another case of me being confused? (The lack of it is not triggering, but...)

See commit 26456f87aca7

Got it, thank you! I will remove my patch from my queue.

Thanx, Paul

#8 lore raw
In reply to Thomas Gleixner
hrtimer: Reset hrtimer cpu base proper on CPU hotplug
Commit-ID:  d5421ea43d30701e03cadc56a38854c36a8b4433
Gitweb:     https://git.kernel.org/tip/d5421ea43d30701e03cadc56a38854c36a8b4433
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 26 Jan 2018 14:54:32 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 27 Jan 2018 15:12:22 +0100

hrtimer: Reset hrtimer cpu base proper on CPU hotplug

The hrtimer interrupt code contains a hang detection and mitigation mechanism, which prevents that a long delayed hrtimer interrupt causes a continous retriggering of interrupts which prevent the system from making progress. If a hang is detected then the timer hardware is programmed with a certain delay into the future and a flag is set in the hrtimer cpu base which prevents newly enqueued timers from reprogramming the timer hardware prior to the chosen delay. The subsequent hrtimer interrupt after the delay clears the flag and resumes normal operation.

If such a hang happens in the last hrtimer interrupt before a CPU is unplugged then the hang_detected flag is set and stays that way when the CPU is plugged in again. At that point the timer hardware is not armed and it cannot be armed because the hang_detected flag is still active, so nothing clears that flag. As a consequence the CPU does not receive hrtimer interrupts and no timers expire on that CPU which results in RCU stalls and other malfunctions.

Clear the flag along with some other less critical members of the hrtimer cpu base to ensure starting from a clean state when a CPU is plugged in.

Thanks to Paul, Sebastian and Anna-Maria for their help to get down to the root cause of that hard to reproduce heisenbug. Once understood it's trivial and certainly justifies a brown paperbag.

Fixes 41d2e4949377 ("hrtimer: Tune hrtimer_interrupt hang logic")
Cc Peter Zijlstra <[email protected]>
Cc Sebastian Sewior <[email protected]>
Cc Anna-Maria Gleixner <[email protected]>
---
 kernel/time/hrtimer.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/time/hrtimer.c +3 -0
index d325208..aa9d2a2b 100644
@@ -655,7 +655,9 @@ static void hrtimer_reprogram(struct hrtimer *timer,
 static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base)
 {
 	base->expires_next = KTIME_MAX;
+	base->hang_detected = 0;
 	base->hres_active = 0;
+	base->next_timer = NULL;
 }
 
 /*
@@ -1589,6 +1591,7 @@ int hrtimers_prepare_cpu(unsigned int cpu)
 		timerqueue_init_head(&cpu_base->clock_base[i].active);
 	}
 
+	cpu_base->active_bases = 0;
 	cpu_base->cpu = cpu;
 	hrtimer_init_hres(cpu_base);
 	return 0;