tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem
Subsystems (3)
PATCH 1/1 tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem
For CONFIG_NO_HZ_FULL systems, the tick_do_timer_cpu cannot be offlined. However, cpu_is_hotpluggable() still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.
Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring tick_nohz_cpu_down(). ]
--- drivers/base/cpu.c | 3 ++- include/linux/tick.h | 2 ++ kernel/time/tick-sched.c | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-)
drivers/base/cpu.c +2 -1
@@ -487,7 +487,8 @@ static const struct attribute_group *cpu_root_attr_groups[] = {bool cpu_is_hotpluggable (unsigned int cpu) {struct device *dev =get_cpu_device (cpu); - return dev && container_of(dev, struct cpu, dev)->hotpluggable; + return dev && container_of(dev, struct cpu, dev)->hotpluggable + &&tick_nohz_cpu_hotpluggable (cpu); }EXPORT_SYMBOL_GPL (cpu_is_hotpluggable);
include/linux/tick.h +2 -0
@@ -216,6 +216,7 @@ extern void tick_nohz_dep_set_signal(struct task_struct *tsk, enum tick_dep_bits bit);extern void tick_nohz_dep_clear_signal (struct signal_struct *signal,enum tick_dep_bits bit); +extern bool tick_nohz_cpu_hotpluggable (unsigned int cpu);/* * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases
@@ -280,6 +281,7 @@ static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }static inline void tick_nohz_dep_set_cpu (int cpu,enum tick_dep_bits bit) { }static inline void tick_nohz_dep_clear_cpu (int cpu,enum tick_dep_bits bit) { } +static inline bool tick_nohz_cpu_hotpluggable (unsigned int cpu) {return true; }static inline void tick_dep_set (enum tick_dep_bits bit) { }static inline void tick_dep_clear (enum tick_dep_bits bit) { }
kernel/time/tick-sched.c +11 -1
@@ -510,7 +510,7 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running = true; } -static int tick_nohz_cpu_down (unsigned int cpu) +static int tick_nohz_cpu_hotplug_ret (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound
@@ -522,6 +522,16 @@ static int tick_nohz_cpu_down(unsigned int cpu)return 0 ; } +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu); +} + +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu) ==0 ; +} +void __init tick_nohz_init (void ) {int cpu, ret;
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
Quoted 10 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]
Thanks for your fantastic work
I applied this fix to linux-5.15.y, and perform new round of rcu torture test on PPC VM of Open Source Lab of Oregon State University. Could you please wait for the test to finish?
The test results of linux-5.15.y before your patch can be viewed at [1] The patched source code of linux-5.15.y can be viewed at [2] The ongoing test of patched linux-5.15.y can be viewed at [3]
[1] http://140.211.169.189/linux-stable-rc/tools/testing/selftests/rcutorture/res/2023.01.18-13.22.39-torture/
[2] http://140.211.169.189/linux-stable-rc/
[3] http://140.211.169.189/linux-stable-rc/tools/testing/selftests/rcutorture/res/2023.01.19-23.40.55-torture/
Hope to continue to benefit the community.
Thank you all
Zhouyi
Quoted 82 lines
Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>--- drivers/base/cpu.c | 3 ++- include/linux/tick.h | 2 ++ kernel/time/tick-sched.c | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-)drivers/base/cpu.c +2
-1@@ -487,7 +487,8 @@ static const struct attribute_group *cpu_root_attr_groups[] = {bool cpu_is_hotpluggable (unsigned int cpu) {struct device *dev =get_cpu_device (cpu); - return dev && container_of(dev, struct cpu, dev)->hotpluggable; + return dev && container_of(dev, struct cpu, dev)->hotpluggable + &&tick_nohz_cpu_hotpluggable (cpu); }EXPORT_SYMBOL_GPL (cpu_is_hotpluggable);include/linux/tick.h +2
-0@@ -216,6 +216,7 @@ extern void tick_nohz_dep_set_signal(struct task_struct *tsk, enum tick_dep_bits bit);extern void tick_nohz_dep_clear_signal (struct signal_struct *signal,enum tick_dep_bits bit); +extern bool tick_nohz_cpu_hotpluggable (unsigned int cpu);/* * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases @@ -280,6 +281,7 @@ static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }static inline void tick_nohz_dep_set_cpu (int cpu,enum tick_dep_bits bit) { }static inline void tick_nohz_dep_clear_cpu (int cpu,enum tick_dep_bits bit) { } +static inline bool tick_nohz_cpu_hotpluggable (unsigned int cpu) {return true; }static inline void tick_dep_set (enum tick_dep_bits bit) { }static inline void tick_dep_clear (enum tick_dep_bits bit) { }kernel/time/tick-sched.c +11
-2@@ -510,7 +510,7 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running = true; } -static int tick_nohz_cpu_down (unsigned int cpu) +static int tick_nohz_cpu_hotplug_ret (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound @@ -522,6 +522,16 @@ static int tick_nohz_cpu_down(unsigned int cpu)return 0 ; } +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu); +} + +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu) ==0 ; +} +void __init tick_nohz_init (void ) {int cpu, ret; --2.39.0.246.g2a6d74b583-goog
Zhouyi Zhou
Tested-byQuoted 18 lines · Zhouyi Zhou
Quoted 10 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]Thanks for your fantastic work
I applied this fix to linux-5.15.y, and perform new round of rcu torture test on PPC VM of Open Source Lab of Oregon State University. Could you please wait for the test to finish?
Quoted 7 lines
The test results of linux-5.15.y before your patch can be viewed at [1] The patched source code of linux-5.15.y can be viewed at [2] The ongoing test of patched linux-5.15.y can be viewed at [3]
[1] http://140.211.169.189/linux-stable-rc/tools/testing/selftests/rcutorture/res/2023.01.18-13.22.39-torture/
[2] http://140.211.169.189/linux-stable-rc/
[3] http://140.211.169.189/linux-stable-rc/tools/testing/selftests/rcutorture/res/2023.01.19-23.40.55-torture/
The rcutorture test on [3] has finished, by comparing the logs of [1] and [3], we can see Joel's patch fix the HOTPLUG problem without bring any new issues.
Thanks
Zhouyi
Quoted 87 lines
Hope to continue to benefit the community.
Thank you all
ZhouyiQuoted 82 lines
Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>--- drivers/base/cpu.c | 3 ++- include/linux/tick.h | 2 ++ kernel/time/tick-sched.c | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-)drivers/base/cpu.c +2
-1@@ -487,7 +487,8 @@ static const struct attribute_group *cpu_root_attr_groups[] = {bool cpu_is_hotpluggable (unsigned int cpu) {struct device *dev =get_cpu_device (cpu); - return dev && container_of(dev, struct cpu, dev)->hotpluggable; + return dev && container_of(dev, struct cpu, dev)->hotpluggable + &&tick_nohz_cpu_hotpluggable (cpu); }EXPORT_SYMBOL_GPL (cpu_is_hotpluggable);include/linux/tick.h +2
-0@@ -216,6 +216,7 @@ extern void tick_nohz_dep_set_signal(struct task_struct *tsk, enum tick_dep_bits bit);extern void tick_nohz_dep_clear_signal (struct signal_struct *signal,enum tick_dep_bits bit); +extern bool tick_nohz_cpu_hotpluggable (unsigned int cpu);/* * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases @@ -280,6 +281,7 @@ static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }static inline void tick_nohz_dep_set_cpu (int cpu,enum tick_dep_bits bit) { }static inline void tick_nohz_dep_clear_cpu (int cpu,enum tick_dep_bits bit) { } +static inline bool tick_nohz_cpu_hotpluggable (unsigned int cpu) {return true; }static inline void tick_dep_set (enum tick_dep_bits bit) { }static inline void tick_dep_clear (enum tick_dep_bits bit) { }kernel/time/tick-sched.c +11
-2@@ -510,7 +510,7 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running = true; } -static int tick_nohz_cpu_down (unsigned int cpu) +static int tick_nohz_cpu_hotplug_ret (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound @@ -522,6 +522,16 @@ static int tick_nohz_cpu_down(unsigned int cpu)return 0 ; } +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu); +} + +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu) ==0 ; +} +void __init tick_nohz_init (void ) {int cpu, ret; --2.39.0.246.g2a6d74b583-goog
Quoted 10 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]
Quoted 8 lines
Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>
Also want to cc: stable on the patch?
Anyway, for the driver core portion:
Quoted 24 lines · Greg Kroah-Hartman
Quoted 10 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]Quoted 8 lines
Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>
Quoted 1 line
Also want to cc: stable on the patch?
Oh sure, sorry. For some reason I thought Sasha and your AI scripts were looking at the Linux-kernel list as well. Or are they, and a Cc to stable is just to be doubly sure?
Quoted 1 line
Anyway, for the driver core portion:
Thanks!
- Joel
Quoted 2 lines
Greg Kroah-Hartman
maintainerQuoted 24 lines · Joel Fernandes
Quoted 24 lines · Greg Kroah-Hartman
Quoted 18 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>
Quoted 5 lines
Quoted 1 line
Also want to cc: stable on the patch?
Oh sure, sorry. For some reason I thought Sasha and your AI scripts were looking at the Linux-kernel list as well. Or are they, and a Cc to stable is just to be doubly sure?
As per the rules we have had for the last 15+ years, always add a cc:
stable to be sure that the patch will be considered for stable releases. If not, you are on you own and sometimes we might notice it, others not.
See:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for the details.
thanks,
greg k-h
Quoted 34 lines · Greg Kroah-Hartman
Quoted 24 lines · Joel Fernandes
Quoted 24 lines
Quoted 3 lines · Greg Kroah-Hartman
Quoted 18 lines · Joel Fernandes (Google)
For
CONFIG_NO_HZ_FULLsystems, thetick_do_timer_cpucannot be offlined. However,cpu_is_hotpluggable()still returns true for those CPUs. This causes torture tests that do offlining to end up trying to offline this CPU causing test failures. Such failure happens on all architectures.Fix it by asking the opinion of the nohz subsystem on whether the CPU can be hotplugged.
[ Apply Frederic Weisbecker feedback on refactoring
tick_nohz_cpu_down(). ]Cc Frederic Weisbecker <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Zhouyi Zhou <[email protected]>Cc Will Deacon <[email protected]>Cc Marc Zyngier <[email protected]>Cc rcu <[email protected]>Fixes 2987557f52b9 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")Signed-off-by Joel Fernandes (Google) <[email protected]>Quoted 5 lines
Quoted 1 line
Also want to cc: stable on the patch?
Oh sure, sorry. For some reason I thought Sasha and your AI scripts were looking at the Linux-kernel list as well. Or are they, and a Cc to stable is just to be doubly sure?
Quoted 7 lines
As per the rules we have had for the last 15+ years, always add a cc:
stable to be sure that the patch will be considered for stable releases. If not, you are on you own and sometimes we might notice it, others not.See:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for the details.
Ah my bad, I did read that already but somehow assumed anything merged with a Fixes tag was already considered for stable. I will always Cc stable henceforth if I want something in stable.
Thank you!
- Joel
Quoted 4 lines
thanks,
greg k-h
Frederic Weisbecker
maintainerQuoted 7 lines · Joel Fernandes (Google)
(quoted diff) +1
-1-static int tick_nohz_cpu_down(unsigned int cpu) +static int tick_nohz_cpu_hotplug_ret(unsigned int cpu) { /* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound@@ -522,6 +522,16 @@ static int tick_nohz_cpu_down(unsigned int cpu) return 0;
Review static int tick_nohz_cpu_down(unsigned int cpu) · line 532
Quoted 10 lines
(quoted diff) +8
-0} +static int tick_nohz_cpu_down(unsigned int cpu) +{ + return tick_nohz_cpu_hotplug_ret(cpu); +} + +bool tick_nohz_cpu_hotpluggable(unsigned int cpu) +{ + return tick_nohz_cpu_hotplug_ret(cpu) == 0;
This is still calling the hotplug function for the CPU in order to know if the CPU is hotpluggable...
Why not:
kernel/time/tick-sched.c +8 -3
@@ -532,7 +532,7 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running = true; } -static int tick_nohz_cpu_down (unsigned int cpu) +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound
@@ -540,8 +540,13 @@ static int tick_nohz_cpu_down(unsigned int cpu)* CPUs. It must remain online when nohz full is enabled. */ if (tick_nohz_full_running && tick_do_timer_cpu == cpu) -return -EBUSY ; -return 0 ; +return false; +return true; +} + +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotpluggable (cpu) ?0 : -EBUSY ; }void __init tick_nohz_init (void )
Quoted 6 lines
(quoted diff) +0
-0void __init tick_nohz_init(void) { int cpu, ret;Signature · 1 line
2.39.0.246.g2a6d74b583-goog
Quoted 43 lines · Frederic Weisbecker
Quoted 7 lines · Joel Fernandes (Google)
kernel/time/tick-sched.c +1
-1-static int tick_nohz_cpu_down (unsigned int cpu) +static int tick_nohz_cpu_hotplug_ret (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound @@ -522,6 +522,16 @@ static int tick_nohz_cpu_down(unsigned int cpu)return 0 ;kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 532
Quoted 10 lines
kernel/time/tick-sched.c +8
-0} +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu); +} + +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) +{ +return tick_nohz_cpu_hotplug_ret (cpu) ==0 ;This is still calling the hotplug function for the CPU in order to know if the CPU is hotpluggable...
Why not:
kernel/time/tick-sched.c +1
-2@@ -532,7 +532,7 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running = true; } -static int tick_nohz_cpu_down (unsigned int cpu) +bool tick_nohz_cpu_hotpluggable (unsigned int cpu) {/* * The tick_do_timer_cpu CPU handles housekeeping duty (unbound @@ -540,8 +540,13 @@ static int tick_nohz_cpu_down(unsigned int cpu)* CPUs. It must remain online when nohz full is enabled. */ if (tick_nohz_full_running && tick_do_timer_cpu == cpu) -return -EBUSY ;
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 551
Quoted 10 lines
kernel/time/tick-sched.c +7
-1-return 0 ; +return false; +return true; +} + +static int tick_nohz_cpu_down (unsigned int cpu) +{ +return tick_nohz_cpu_hotpluggable (cpu) ?0 : -EBUSY ; }
Yes, this looks better. I will do it this way. Thanks!
- Joel