Commit 3ad6eb06 authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Thomas Gleixner

tick: Start centralizing tick related CPU hotplug operations

During the CPU offlining process, the various timer tick features are
shut down from scattered places, sometimes from teardown callbacks on
stop machine, sometimes through explicit calls, sometimes from the
control CPU after the CPU died. The reason why these shutdown operations
are spread around is not always clear and it makes the tick lifecycle
hard to follow.

The tick should be shut down in order from highest to lowest level:

On stop machine from the dying CPU (high-level):

 1) Hand-over the timekeeping duty (tick_handover_do_timer())
 2) Cancel the tick implementation called by the clockevent callback
    (tick_cancel_sched_timer())
 3) Shutdown broadcasting (tick_offline_cpu() / tick_broadcast_offline())

On stop machine from the dying CPU (low-level):

 4) Shutdown clockevents drivers (CPUHP_AP_*_TIMER_STARTING states)

From the control CPU after the CPU died (low-level):

 5) Shutdown/unregister/cleanup clockevents for the dead CPU
    (tick_cleanup_dead_cpu())

Instead the current order is 2, 4 (both from CPU hotplug states), then
1 and 3 through direct calls. This layout and order don't make much
sense. The operations 1, 2, 3 should be gathered together and in order.

Sort this situation with creating a new TICK shut-down CPU hotplug state
and start with introducing the timekeeping duty hand-over there. The
state must precede hrtimers migration because the tick hrtimer will be
stopped from it in a further patch.
Signed-off-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240225225508.11587-8-frederic@kernel.org
parent 60313c21
...@@ -184,6 +184,7 @@ enum cpuhp_state { ...@@ -184,6 +184,7 @@ enum cpuhp_state {
CPUHP_AP_ARM64_ISNDEP_STARTING, CPUHP_AP_ARM64_ISNDEP_STARTING,
CPUHP_AP_SMPCFD_DYING, CPUHP_AP_SMPCFD_DYING,
CPUHP_AP_HRTIMERS_DYING, CPUHP_AP_HRTIMERS_DYING,
CPUHP_AP_TICK_DYING,
CPUHP_AP_X86_TBOOT_DYING, CPUHP_AP_X86_TBOOT_DYING,
CPUHP_AP_ARM_CACHE_B15_RAC_DYING, CPUHP_AP_ARM_CACHE_B15_RAC_DYING,
CPUHP_AP_ONLINE, CPUHP_AP_ONLINE,
......
...@@ -19,16 +19,20 @@ extern void __init tick_init(void); ...@@ -19,16 +19,20 @@ extern void __init tick_init(void);
extern void tick_suspend_local(void); extern void tick_suspend_local(void);
/* Should be core only, but XEN resume magic and ARM BL switcher require it */ /* Should be core only, but XEN resume magic and ARM BL switcher require it */
extern void tick_resume_local(void); extern void tick_resume_local(void);
extern void tick_handover_do_timer(void);
extern void tick_cleanup_dead_cpu(int cpu); extern void tick_cleanup_dead_cpu(int cpu);
#else /* CONFIG_GENERIC_CLOCKEVENTS */ #else /* CONFIG_GENERIC_CLOCKEVENTS */
static inline void tick_init(void) { } static inline void tick_init(void) { }
static inline void tick_suspend_local(void) { } static inline void tick_suspend_local(void) { }
static inline void tick_resume_local(void) { } static inline void tick_resume_local(void) { }
static inline void tick_handover_do_timer(void) { }
static inline void tick_cleanup_dead_cpu(int cpu) { } static inline void tick_cleanup_dead_cpu(int cpu) { }
#endif /* !CONFIG_GENERIC_CLOCKEVENTS */ #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
#if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_HOTPLUG_CPU)
extern int tick_cpu_dying(unsigned int cpu);
#else
#define tick_cpu_dying NULL
#endif
#if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND) #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
extern void tick_freeze(void); extern void tick_freeze(void);
extern void tick_unfreeze(void); extern void tick_unfreeze(void);
......
...@@ -1324,8 +1324,6 @@ static int take_cpu_down(void *_param) ...@@ -1324,8 +1324,6 @@ static int take_cpu_down(void *_param)
*/ */
cpuhp_invoke_callback_range_nofail(false, cpu, st, target); cpuhp_invoke_callback_range_nofail(false, cpu, st, target);
/* Give up timekeeping duties */
tick_handover_do_timer();
/* Remove CPU from timer broadcasting */ /* Remove CPU from timer broadcasting */
tick_offline_cpu(cpu); tick_offline_cpu(cpu);
/* Park the stopper thread */ /* Park the stopper thread */
...@@ -2205,7 +2203,11 @@ static struct cpuhp_step cpuhp_hp_states[] = { ...@@ -2205,7 +2203,11 @@ static struct cpuhp_step cpuhp_hp_states[] = {
.startup.single = NULL, .startup.single = NULL,
.teardown.single = hrtimers_cpu_dying, .teardown.single = hrtimers_cpu_dying,
}, },
[CPUHP_AP_TICK_DYING] = {
.name = "tick:dying",
.startup.single = NULL,
.teardown.single = tick_cpu_dying,
},
/* Entry state on starting. Interrupts enabled from here on. Transient /* Entry state on starting. Interrupts enabled from here on. Transient
* state for synchronsization */ * state for synchronsization */
[CPUHP_AP_ONLINE] = { [CPUHP_AP_ONLINE] = {
......
...@@ -397,15 +397,20 @@ EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control); ...@@ -397,15 +397,20 @@ EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
/* /*
* Transfer the do_timer job away from a dying cpu. * Stop the tick and transfer the timekeeping job away from a dying cpu.
*
* Called with interrupts disabled. No locking required. If
* tick_do_timer_cpu is owned by this cpu, nothing can change it.
*/ */
void tick_handover_do_timer(void) int tick_cpu_dying(unsigned int dying_cpu)
{ {
if (tick_do_timer_cpu == smp_processor_id()) /*
* If the current CPU is the timekeeper, it's the only one that
* can safely hand over its duty. Also all online CPUs are in
* stop machine, guaranteed not to be idle, therefore it's safe
* to pick any online successor.
*/
if (tick_do_timer_cpu == dying_cpu)
tick_do_timer_cpu = cpumask_first(cpu_online_mask); tick_do_timer_cpu = cpumask_first(cpu_online_mask);
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment