From: Frederic Weisbecker <frederic@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Peng Liu <liupeng17@lenovo.com>,
Joel Fernandes <joel@joelfernandes.org>
Subject: [PATCH 07/15] tick: Start centralizing tick related CPU hotplug operations
Date: Wed, 24 Jan 2024 18:04:51 +0100 [thread overview]
Message-ID: <20240124170459.24850-8-frederic@kernel.org> (raw)
In-Reply-To: <20240124170459.24850-1-frederic@kernel.org>
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: Frederic Weisbecker <frederic@kernel.org>
---
include/linux/cpuhotplug.h | 1 +
include/linux/tick.h | 8 ++++++--
kernel/cpu.c | 8 +++++---
kernel/time/tick-common.c | 17 +++++++++++------
4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 172d0a743e5d..74fcdd2b82c8 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -184,6 +184,7 @@ enum cpuhp_state {
CPUHP_AP_ARM64_ISNDEP_STARTING,
CPUHP_AP_SMPCFD_DYING,
CPUHP_AP_HRTIMERS_DYING,
+ CPUHP_AP_TICK_DYING,
CPUHP_AP_X86_TBOOT_DYING,
CPUHP_AP_ARM_CACHE_B15_RAC_DYING,
CPUHP_AP_ONLINE,
diff --git a/include/linux/tick.h b/include/linux/tick.h
index 716d17f31c45..afff4c207bd8 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -19,16 +19,20 @@ extern void __init tick_init(void);
extern void tick_suspend_local(void);
/* Should be core only, but XEN resume magic and ARM BL switcher require it */
extern void tick_resume_local(void);
-extern void tick_handover_do_timer(void);
extern void tick_cleanup_dead_cpu(int cpu);
#else /* CONFIG_GENERIC_CLOCKEVENTS */
static inline void tick_init(void) { }
static inline void tick_suspend_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) { }
#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)
extern void tick_freeze(void);
extern void tick_unfreeze(void);
diff --git a/kernel/cpu.c b/kernel/cpu.c
index e6ec3ba4950b..263508073da8 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1324,8 +1324,6 @@ static int take_cpu_down(void *_param)
*/
cpuhp_invoke_callback_range_nofail(false, cpu, st, target);
- /* Give up timekeeping duties */
- tick_handover_do_timer();
/* Remove CPU from timer broadcasting */
tick_offline_cpu(cpu);
/* Park the stopper thread */
@@ -2205,7 +2203,11 @@ static struct cpuhp_step cpuhp_hp_states[] = {
.startup.single = NULL,
.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
* state for synchronsization */
[CPUHP_AP_ONLINE] = {
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index 0084e1ae2583..a89ef450fda7 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -397,15 +397,20 @@ EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
#ifdef CONFIG_HOTPLUG_CPU
/*
- * Transfer the do_timer 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.
+ * Stop the tick and transfer the timekeeping job away from a dying cpu.
*/
-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);
+
+ return 0;
}
/*
--
2.43.0
next prev parent reply other threads:[~2024-01-24 17:05 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 17:04 [PATCH 00/15] timers/nohz cleanups and hotplug reorganization Frederic Weisbecker
2024-01-24 17:04 ` [PATCH 01/15] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Frederic Weisbecker
2024-01-25 9:12 ` Thomas Gleixner
2024-01-25 11:57 ` Frederic Weisbecker
2024-01-25 13:34 ` Thomas Gleixner
2024-01-25 14:35 ` Frederic Weisbecker
2024-01-24 17:04 ` [PATCH 02/15] tick/nohz: Remove duplicate between lowres and highres handlers Frederic Weisbecker
2024-01-25 9:32 ` Thomas Gleixner
2024-01-25 11:58 ` Frederic Weisbecker
2024-01-25 13:30 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 03/15] tick: Remove useless oneshot ifdeffery Frederic Weisbecker
2024-01-25 9:32 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 04/15] tick: Use IS_ENABLED() whenever possible Frederic Weisbecker
2024-01-25 9:33 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 05/15] tick: s/tick_nohz_stop_sched_tick/tick_nohz_full_stop_tick Frederic Weisbecker
2024-01-25 9:33 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 06/15] tick: No need to clear ts->next_tick again Frederic Weisbecker
2024-01-25 9:33 ` Thomas Gleixner
2024-01-24 17:04 ` Frederic Weisbecker [this message]
2024-01-25 9:36 ` [PATCH 07/15] tick: Start centralizing tick related CPU hotplug operations Thomas Gleixner
2024-01-24 17:04 ` [PATCH 08/15] tick: Move tick cancellation up to CPUHP_AP_TICK_DYING Frederic Weisbecker
2024-01-25 9:37 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 09/15] tick: Move broadcast " Frederic Weisbecker
2024-01-25 9:38 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 10/15] tick: Assume the tick can't be stopped in NOHZ_MODE_INACTIVE mode Frederic Weisbecker
2024-01-25 9:39 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 11/15] tick: Move got_idle_tick away from common flags Frederic Weisbecker
2024-01-25 9:40 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 12/15] tick: Move individual bit features to debuggable mask accesses Frederic Weisbecker
2024-01-25 9:41 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 13/15] tick: Split nohz and highres features from nohz_mode Frederic Weisbecker
2024-01-25 9:42 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 14/15] tick: Shut down low-res tick from dying CPU Frederic Weisbecker
2024-01-25 9:43 ` Thomas Gleixner
2024-01-24 17:04 ` [PATCH 15/15] tick: Assume timekeeping is correctly handed over upon last offline idle call Frederic Weisbecker
2024-01-25 9:43 ` Thomas Gleixner
-- strict thread matches above, loose matches on Subject: below --
2024-01-31 23:11 [PATCH 00/15 v2] timers/nohz cleanups and hotplug reorganization Frederic Weisbecker
2024-01-31 23:11 ` [PATCH 07/15] tick: Start centralizing tick related CPU hotplug operations Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240124170459.24850-8-frederic@kernel.org \
--to=frederic@kernel.org \
--cc=anna-maria@linutronix.de \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liupeng17@lenovo.com \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox