All of lore.kernel.org
 help / color / mirror / Atom feed
* [dovetail][PATCH] irq_pipeline: tick: keep IRQ_TICK set on shutdown
@ 2026-11-17 18:32 Jan Kiszka
  2026-11-19 13:04 ` Philippe Gerum
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2026-11-17 18:32 UTC (permalink / raw)
  To: Xenomai, Philippe Gerum, Florian Bezdeka

From: Jan Kiszka <jan.kiszka@siemens.com>

IRQ_TICK is set on the interrupt of a pipelined clock event device by
tick_setup_device(), but cleared again by every call to
clockevents_shutdown(). Several paths shut down a tick device and
restart it later without going through tick_setup_device():

- tick_suspend_local() / tick_resume_local(), on suspend to RAM and
  on suspend to idle (tick_freeze/tick_unfreeze).
- tick_broadcast_control(TICK_BROADCAST_ON) while the broadcast
  device runs in periodic mode, undone by tick_setup_periodic() on
  TICK_BROADCAST_OFF.

In addition, per-CPU clock event devices share a single interrupt
descriptor, so shutting down the device on one CPU clears the mark
for all CPUs, including those still receiving ticks over it.

Once the mark is lost, the pipeline entry code stops saving the
interrupted registers for the in-band tick, which then accounts the
CPU time and reports RCU quiescent states based on stale registers.

Restoring the mark from clockevents_tick_resume() would only cover
the suspend paths. Make it sticky instead: once an interrupt has
driven a tick device, keep it marked. If the device stops being used
for ticks, the mark only causes the registers of a more recent
interrupt to be recorded, which is harmless.

As irq_switch_tick(irq, false) is no longer used, rename it to
irq_mark_tick() and clean up related bits.

Assisted-by: opencode:Opus-5.5
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

This is now one option to address the issue brought forward in
https://lore.kernel.org/xenomai/9b439d13-7d33-419d-9d4a-2b224bf5db7d@siemens.com/T/#u.

 include/linux/irq.h       |  4 ++--
 kernel/irq/manage.c       | 11 +++--------
 kernel/irq/settings.h     |  5 -----
 kernel/time/clockevents.c |  3 ---
 kernel/time/tick-common.c |  7 ++++++-
 5 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index b9e4f12271ed3..0862d64b7ee4f 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -1260,7 +1260,7 @@ static inline struct irq_chip_type *irq_data_get_chip_type(struct irq_data *d)
 
 #ifdef CONFIG_IRQ_PIPELINE
 int irq_switch_oob(unsigned int irq, bool on);
-void irq_switch_tick(unsigned int irq, bool on);
+void irq_mark_tick(unsigned int irq);
 void irq_clear_deferral(struct irq_desc *desc);
 void irq_clear_forward(struct irq_desc *desc);
 #else
@@ -1269,7 +1269,7 @@ static inline int irq_switch_oob(unsigned int irq, bool on)
 	return 0;
 }
 
-static inline void irq_switch_tick(unsigned int irq, bool on)
+static inline void irq_mark_tick(unsigned int irq)
 {
 }
 
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index bbd7c0208444f..943541b1c9fff 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -950,16 +950,11 @@ int irq_switch_oob(unsigned int irq, bool on)
 }
 EXPORT_SYMBOL_GPL(irq_switch_oob);
 
-void irq_switch_tick(unsigned int irq, bool on)
+void irq_mark_tick(unsigned int irq)
 {
-	scoped_irqdesc_get_and_lock(irq, 0) {
-		if (on)
-			irq_settings_set_tick(scoped_irqdesc);
-		else
-			irq_settings_clr_tick(scoped_irqdesc);
-	}
+	scoped_irqdesc_get_and_lock(irq, 0)
+		irq_settings_set_tick(scoped_irqdesc);
 }
-EXPORT_SYMBOL_GPL(irq_switch_tick);
 
 #endif /* CONFIG_IRQ_PIPELINE */
 
diff --git a/kernel/irq/settings.h b/kernel/irq/settings.h
index 0a57c2080cacd..d1336b82c248f 100644
--- a/kernel/irq/settings.h
+++ b/kernel/irq/settings.h
@@ -218,11 +218,6 @@ static inline bool irq_settings_is_tick(struct irq_desc *desc)
 	return desc->status_use_accessors & _IRQ_TICK;
 }
 
-static inline void irq_settings_clr_tick(struct irq_desc *desc)
-{
-	desc->status_use_accessors &= ~_IRQ_TICK;
-}
-
 static inline void irq_settings_set_tick(struct irq_desc *desc)
 {
 	desc->status_use_accessors |= _IRQ_TICK;
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 3cf30dead25d1..5138c17fd567d 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -12,7 +12,6 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/smp.h>
-#include <linux/irq.h>
 #include <linux/device.h>
 
 #include "tick-internal.h"
@@ -178,8 +177,6 @@ void clockevents_shutdown(struct clock_event_device *dev)
 	clockevents_switch_state(dev, CLOCK_EVT_STATE_SHUTDOWN);
 	dev->next_event = KTIME_MAX;
 	dev->next_event_forced = 0;
-	if (dev->features & CLOCK_EVT_FEAT_PIPELINE)
-		irq_switch_tick(dev->irq, false);
 }
 
 /**
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index bfb26d9d687ab..56e3ec9c754b3 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -245,8 +245,13 @@ static void tick_setup_device(struct tick_device *td,
 	if (!cpumask_equal(newdev->cpumask, cpumask))
 		irq_set_affinity(newdev->irq, cpumask);
 
+	/*
+	 * This mark is never cleared: tick devices may be shut down and
+	 * restarted without passing here again (suspend, periodic broadcast),
+	 * and per-CPU devices share a single interrupt descriptor.
+	 */
 	if (newdev->features & CLOCK_EVT_FEAT_PIPELINE)
-		irq_switch_tick(newdev->irq, true);
+		irq_mark_tick(newdev->irq);
 
 	/*
 	 * When global broadcasting is active, check if the current
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 18:32 [dovetail][PATCH] irq_pipeline: tick: keep IRQ_TICK set on shutdown Jan Kiszka
2026-11-19 13:04 ` Philippe Gerum

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.