All of lore.kernel.org
 help / color / mirror / Atom feed
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 15/16] tick: Assume timekeeping is correctly handed over upon last offline idle call
Date: Sun, 25 Feb 2024 23:55:07 +0100	[thread overview]
Message-ID: <20240225225508.11587-16-frederic@kernel.org> (raw)
In-Reply-To: <20240225225508.11587-1-frederic@kernel.org>

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.

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 include/linux/tick.h      |  2 ++
 kernel/cpu.c              |  1 +
 kernel/sched/idle.c       |  1 -
 kernel/time/tick-common.c |  4 ++++
 kernel/time/tick-sched.c  | 13 +------------
 5 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/include/linux/tick.h b/include/linux/tick.h
index c7840ae8ebaf..44fddfa93e18 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -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)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 5a8ad4f5ccf3..7e84a7b0675e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -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;
 	/*
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 31231925f1ec..b15d40cad7ea 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -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();
 		}
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index 9cd09eea06d6..fb0fdec8719a 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -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.
  */
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 89d16b8ea2c4..269e21590df5 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -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;
-- 
2.43.0


  parent reply	other threads:[~2024-02-25 22:55 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-25 22:54 [PATCH 00/16 v3] timers/nohz cleanups and hotplug reorganization Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 01/16] tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer() Frederic Weisbecker
2024-02-26  8:14   ` Thomas Gleixner
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Peng Liu
2024-02-25 22:54 ` [PATCH 02/16] tick/nohz: Remove duplicate between lowres and highres handlers Frederic Weisbecker
2024-02-26  8:15   ` Thomas Gleixner
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Peng Liu
2024-02-25 22:54 ` [PATCH 03/16] tick: Remove useless oneshot ifdeffery Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: " tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 04/16] tick: Use IS_ENABLED() whenever possible Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 05/16] tick: s/tick_nohz_stop_sched_tick/tick_nohz_full_stop_tick Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: Rename tick_nohz_stop_sched_tick() to tick_nohz_full_stop_tick() tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 06/16] tick: No need to clear ts->next_tick again Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] tick/sched: Don't clear ts::next_tick again in can_stop_idle_tick() tip-bot2 for Frederic Weisbecker
2024-02-25 22:54 ` [PATCH 07/16] tick: Start centralizing tick related CPU hotplug operations Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 08/16] tick: Move tick cancellation up to CPUHP_AP_TICK_DYING Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 09/16] tick: Move broadcast " Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 10/16] tick: Assume the tick can't be stopped in NOHZ_MODE_INACTIVE mode Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 11/16] tick: Move got_idle_tick away from common flags Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 12/16] tick: Move individual bit features to debuggable mask accesses Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 13/16] tick: Split nohz and highres features from nohz_mode Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 14/16] tick: Shut down low-res tick from dying CPU Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` Frederic Weisbecker [this message]
2024-02-26 22:24   ` [tip: timers/core] tick: Assume timekeeping is correctly handed over upon last offline idle call tip-bot2 for Frederic Weisbecker
2024-02-25 22:55 ` [PATCH 16/16] timers: Assert no next dyntick timer look-up while CPU is offline Frederic Weisbecker
2024-02-26 22:24   ` [tip: timers/core] " tip-bot2 for 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=20240225225508.11587-16-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.