tick: Assume timekeeping is correctly handed over upon last offline idle call
authorFrederic Weisbecker <frederic@kernel.org>
Sun, 25 Feb 2024 22:55:07 +0000 (23:55 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 26 Feb 2024 10:37:32 +0000 (11:37 +0100)
The timekeeping duty is handed over from the outgoing CPU on stop
machine, then the oneshot tick is stopped right after.  Therefore it's
guaranteed that the current CPU isn't the timekeeper upon its last call
to idle.

Besides, calling tick_nohz_idle_stop_tick() while the dying CPU goes
into idle suggests that the tick is going to be stopped while it is
actually stopped already from the appropriate CPU hotplug state.

Remove the confusing call and the obsolete case handling and convert it
to a sanity check that verifies the above assumption.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240225225508.11587-16-frederic@kernel.org
include/linux/tick.h
kernel/cpu.c
kernel/sched/idle.c
kernel/time/tick-common.c
kernel/time/tick-sched.c

index c7840ae8ebafbfb9c3964eb6c200f3c4cf878e1a..44fddfa93e18c86582c3cb767e210f4202b4083b 100644 (file)
@@ -29,8 +29,10 @@ static inline void tick_cleanup_dead_cpu(int cpu) { }
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_HOTPLUG_CPU)
 extern int tick_cpu_dying(unsigned int cpu);
+extern void tick_assert_timekeeping_handover(void);
 #else
 #define tick_cpu_dying NULL
+static inline void tick_assert_timekeeping_handover(void) { }
 #endif
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
index 5a8ad4f5ccf33695454bc4ebcb0385be83d6e3ff..7e84a7b0675ef225e4e11b1f2d8db357cf0371c4 100644 (file)
@@ -1399,6 +1399,7 @@ void cpuhp_report_idle_dead(void)
        struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
 
        BUG_ON(st->state != CPUHP_AP_OFFLINE);
+       tick_assert_timekeeping_handover();
        rcutree_report_cpu_dead();
        st->state = CPUHP_AP_IDLE_DEAD;
        /*
index 31231925f1ece276c96269a2516d4d00ff011420..b15d40cad7ea4ce3910150d7e4b88b8b003c643a 100644 (file)
@@ -291,7 +291,6 @@ static void do_idle(void)
                local_irq_disable();
 
                if (cpu_is_offline(cpu)) {
-                       tick_nohz_idle_stop_tick();
                        cpuhp_report_idle_dead();
                        arch_cpu_idle_dead();
                }
index 9cd09eea06d6e3bce6a1d28e035f1fc4e0faf452..fb0fdec8719a13ed5fd5eb66d13027e184dce5de 100644 (file)
@@ -396,6 +396,10 @@ int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
 EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
 
 #ifdef CONFIG_HOTPLUG_CPU
+void tick_assert_timekeeping_handover(void)
+{
+       WARN_ON_ONCE(tick_do_timer_cpu == smp_processor_id());
+}
 /*
  * Stop the tick and transfer the timekeeping job away from a dying cpu.
  */
index 89d16b8ea2c4fc3d02962ac22e203b480bae6d8b..269e21590df5368bd6fc84d422f44162501a3f31 100644 (file)
@@ -1160,18 +1160,7 @@ static bool report_idle_softirq(void)
 
 static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)
 {
-       /*
-        * If this CPU is offline and it is the one which updates
-        * jiffies, then give up the assignment and let it be taken by
-        * the CPU which runs the tick timer next. If we don't drop
-        * this here, the jiffies might be stale and do_timer() never
-        * gets invoked.
-        */
-       if (unlikely(!cpu_online(cpu))) {
-               if (cpu == tick_do_timer_cpu)
-                       tick_do_timer_cpu = TICK_DO_TIMER_NONE;
-               return false;
-       }
+       WARN_ON_ONCE(cpu_is_offline(cpu));
 
        if (unlikely(!tick_sched_flag_test(ts, TS_FLAG_NOHZ)))
                return false;