[PATCH v10 1/8] timers/migration: Postpone online/offline callbacks registration to late initcall

Gabriele Monaco posted 8 patches 1 month, 4 weeks ago
There is a newer version of this series
[PATCH v10 1/8] timers/migration: Postpone online/offline callbacks registration to late initcall
Posted by Gabriele Monaco 1 month, 4 weeks ago
From: Frederic Weisbecker <frederic@kernel.org>

During the early boot process, the default clocksource used for
timekeeping is the jiffies. Better clocksources can only be selected
once clocksource_done_booting() is called as an fs initcall.

NOHZ can only be enabled after that stage, making global timer migration
irrelevant up to that point.

Therefore, don't bother with trashing the cache within that tree from
the SMP bootup until NOHZ even matters.

Make the CPUs available to the tree on late initcall, after the right
clocksource had a chance to be selected. This will also simplify the
handling of domain isolated CPUs on further patches.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
 kernel/time/timer_migration.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index c0c54dc5314c..891891794b92 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1481,6 +1481,16 @@ static int tmigr_cpu_online(unsigned int cpu)
 	return 0;
 }
 
+/*
+ * NOHZ can only be enabled after clocksource_done_booting(). Don't
+ * bother trashing the cache in the tree before.
+ */
+static int __init tmigr_late_init(void)
+{
+	return cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online",
+				 tmigr_cpu_online, tmigr_cpu_offline);
+}
+
 static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl,
 			     int node)
 {
@@ -1843,18 +1853,10 @@ static int __init tmigr_init(void)
 
 	ret = cpuhp_setup_state(CPUHP_TMIGR_PREPARE, "tmigr:prepare",
 				tmigr_cpu_prepare, NULL);
-	if (ret)
-		goto err;
-
-	ret = cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online",
-				tmigr_cpu_online, tmigr_cpu_offline);
-	if (ret)
-		goto err;
-
-	return 0;
-
 err:
-	pr_err("Timer migration setup failed\n");
+	if (ret)
+		pr_err("Timer migration setup failed\n");
 	return ret;
 }
 early_initcall(tmigr_init);
+late_initcall(tmigr_late_init);
-- 
2.50.1
Re: [PATCH v10 1/8] timers/migration: Postpone online/offline callbacks registration to late initcall
Posted by Frederic Weisbecker 1 month, 4 weeks ago
Le Wed, Aug 06, 2025 at 11:38:48AM +0200, Gabriele Monaco a écrit :
> From: Frederic Weisbecker <frederic@kernel.org>
> 
> During the early boot process, the default clocksource used for
> timekeeping is the jiffies. Better clocksources can only be selected
> once clocksource_done_booting() is called as an fs initcall.
> 
> NOHZ can only be enabled after that stage, making global timer migration
> irrelevant up to that point.
> 
> Therefore, don't bother with trashing the cache within that tree from
> the SMP bootup until NOHZ even matters.

I think I made a mistake with this sentence. Actually the timers are not
propagated to the tree before nohz is enabled. So the sentence should
actually be:

"The tree remains inactive before NOHZ is enabled anyway. Therefore it
makes sense to enable each CPUs to the tree only once that is setup."

Thanks.
-- 
Frederic Weisbecker
SUSE Labs