irq_pipeline: tick: keep IRQ_TICK set on shutdown
PATCH 1/1 irq_pipeline: tick: keep IRQ_TICK set on shutdown
From: Jan Kiszka <[email protected]>
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.
---
This is now one option to address the issue brought forward in
https://lore.kernel.org/xenomai/[email protected]/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(-)
include/linux/irq.h +2 -2
@@ -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) { }
kernel/irq/manage.c +3 -8
@@ -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 */
kernel/irq/settings.h +0 -5
@@ -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;
kernel/time/clockevents.c +0 -3
@@ -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); }/**
kernel/time/tick-common.c +6 -1
@@ -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
Signature · 1 line
2.47.3
Philippe Gerum
AppliedQuoted 136 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
IRQ_TICKis set on the interrupt of a pipelined clock event device bytick_setup_device(), but cleared again by every call toclockevents_shutdown(). Several paths shut down a tick device and restart it later without going throughtick_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 bytick_setup_periodic()onTICK_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 toirq_mark_tick()and clean up related bits.Assisted-by opencode:Opus-5.5Signed-off-by Jan Kiszka <[email protected]>---
This is now one option to address the issue brought forward in
https://lore.kernel.org/xenomai/[email protected]/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(-)include/linux/irq.h +2
-2@@ -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) { }kernel/irq/manage.c +3
-8@@ -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 */ kernel/irq/settings.h +0
-5@@ -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;kernel/time/clockevents.c +0
-3@@ -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); }/** kernel/time/tick-common.c +1
-0@@ -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); +/*
kernel/time/tick-common.c static void tick_setup_device(struct tick_device *td, · line 257
Quoted 10 lines
kernel/time/tick-common.c +5
-1+* 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
Merged, thanks.
Signature · 1 line
Philippe.