Re: [RESEND PATCH v13 1/9] timers/migration: Postpone online/offline callbacks registration to late initcall

Frederic Weisbecker
2025-10-30T14:07:28Z

Le Mon, Oct 20, 2025 at 01:27:54PM +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.
>
> 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.
>
> 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);
> +}

I just worked on a fix in the timer migration code and this made me realize
my suggestion was plain wrong.

The CPU doing the prepare work for the target must be online because we must
guarantee that the old top level is active since we unconditionally propagate
its active state to the new top.

And if we do that late call to tmigr_cpu_online (after most CPUs have booted)
then we break that guarantee.

So I fear we can't do that and we must go back to your previous idea which
consisted in sending IPIs to apply isolation on late stage.

Sorry about the late brain :-s

--
Frederic Weisbecker
SUSE Labs