Re: [PATCH v2] tick/nohz_full: turn tick_do_timer_boot_cpu into boot_cpu_is_nohz_full
From: Nicholas Piggin
Date: Tue Jun 04 2024 - 01:08:34 EST
On Tue Jun 4, 2024 at 1:35 AM AEST, Oleg Nesterov wrote:
> We don't need to record the cpu number of the nohz_full boot CPU, a simple
> boolean is enough. We could even kill it, the "else if" branch could check
> tick_nohz_full_cpu(tick_do_timer_cpu) && !tick_nohz_full_cpu(cpu).
>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
Reviewed-by: Nicholas Piggin <npiggin@xxxxxxxxx>
> ---
> kernel/time/tick-common.c | 21 ++++-----------------
> 1 file changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
> index 27d0018c8b05..82c1b2206631 100644
> --- a/kernel/time/tick-common.c
> +++ b/kernel/time/tick-common.c
> @@ -49,15 +49,6 @@ ktime_t tick_next_period;
> * procedure also covers cpu hotplug.
> */
> int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT;
> -#ifdef CONFIG_NO_HZ_FULL
> -/*
> - * tick_do_timer_boot_cpu indicates the boot CPU temporarily owns
> - * tick_do_timer_cpu and it should be taken over by an eligible secondary
> - * when one comes online.
> - */
> -static int tick_do_timer_boot_cpu __read_mostly = -1;
> -#endif
> -
> /*
> * Debugging: see timer_list.c
> */
> @@ -192,6 +183,7 @@ static void tick_setup_device(struct tick_device *td,
> * First device setup ?
> */
> if (!td->evtdev) {
> + static bool boot_cpu_is_nohz_full __read_mostly;
> /*
> * If no cpu took the do_timer update, assign it to
> * this cpu:
> @@ -199,18 +191,14 @@ static void tick_setup_device(struct tick_device *td,
> if (READ_ONCE(tick_do_timer_cpu) == TICK_DO_TIMER_BOOT) {
> WRITE_ONCE(tick_do_timer_cpu, cpu);
> tick_next_period = ktime_get();
> -#ifdef CONFIG_NO_HZ_FULL
> /*
> * The boot CPU may be nohz_full, in which case the
> * first housekeeping secondary will take do_timer()
> * from us.
> */
> - if (tick_nohz_full_cpu(cpu))
> - tick_do_timer_boot_cpu = cpu;
> -
> - } else if (tick_do_timer_boot_cpu != -1 &&
> - !tick_nohz_full_cpu(cpu)) {
> - tick_do_timer_boot_cpu = -1;
> + boot_cpu_is_nohz_full = tick_nohz_full_cpu(cpu);
> + } else if (boot_cpu_is_nohz_full && !tick_nohz_full_cpu(cpu)) {
> + boot_cpu_is_nohz_full = false;
> /*
> * The boot CPU will stay in periodic (NOHZ disabled)
> * mode until clocksource_done_booting() called after
> @@ -221,7 +209,6 @@ static void tick_setup_device(struct tick_device *td,
> * check in tick_periodic() but this race is harmless.
> */
> WRITE_ONCE(tick_do_timer_cpu, cpu);
> -#endif
> }
>
> /*