iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context
PATCH v2 1/2 iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context
On PREEMPT_RT enabled kernels unmarked hrtimers are moved into soft interrupt expiry mode by default.
The IIO hrtimer-trigger needs to run in hard interrupt context since it will end up calling generic_handle_irq() which has the requirement to run in hard interrupt context.
Explicitly specify that the timer needs to run in hard interrupt context by using the HRTIMER_MODE_REL_HARD flag.
---
Changes since v1:
* Also pass HRTIMER_MODE_REL_HARD to hrtimer_start().
--- drivers/iio/trigger/iio-trig-hrtimer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/trigger/iio-trig-hrtimer.c +2 -2
@@ -102,7 +102,7 @@ static int iio_trig_hrtimer_set_state(struct iio_trigger *trig, bool state)if (state)hrtimer_start (&trig_info->timer, trig_info->period, -HRTIMER_MODE_REL ); +HRTIMER_MODE_REL_HARD );else hrtimer_cancel (&trig_info->timer);
@@ -132,7 +132,7 @@ static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name) trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops; trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups; -hrtimer_init (&trig_info->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); +hrtimer_init (&trig_info->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_HARD ); trig_info->timer.function = iio_hrtimer_trig_handler; trig_info->sampling_frequency =HRTIMER_DEFAULT_SAMPLING_FREQUENCY ;
Signature · 1 line
2.20.1
PATCH v2 2/2 iio: sysfs-trigger: Mark irq_work to expire in hardirq context
Mark the IIO sysfs-trigger irq_work with IRQ_WORK_HARD_IRQ to ensure that it is always executed in hard interrupt context, even with PREEMPT_RT=y.
The IIO sysfs-trigger irq_work needs to run in hard interrupt context since it will end up calling generic_handle_irq() which has the requirement to run in hard interrupt context.
Note that the IRQ_WORK_HARD_IRQ flag, while it exists, does not seem to do anything in the mainline kernel yet. It does have an effect in the RT patchset though and presumably this is sooner or later going to be added to mainline as well.
---
No changes since v1.
--- drivers/iio/trigger/iio-trig-sysfs.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/trigger/iio-trig-sysfs.c +1 -0
@@ -161,6 +161,7 @@ static int iio_sysfs_trigger_probe(int id)iio_trigger_set_drvdata (t->trig, t);init_irq_work (&t->work, iio_sysfs_trigger_work); +atomic_set (&t->work.flags,IRQ_WORK_HARD_IRQ ); ret =iio_trigger_register (t->trig);if (ret)
Signature · 1 line
2.20.1
Quoted 7 lines · Lars-Peter Clausen
On
PREEMPT_RTenabled kernels unmarked hrtimers are moved into soft interrupt expiry mode by default.The IIO hrtimer-trigger needs to run in hard interrupt context since it will end up calling
generic_handle_irq()which has the requirement to run in hard interrupt context.
Quoted 6 lines
Explicitly specify that the timer needs to run in hard interrupt context by using the
HRTIMER_MODE_REL_HARDflag.Fixes f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")Reported-by Christian Eggers <[email protected]>Signed-off-by Lars-Peter Clausen <[email protected]>
If I remember correctly, this routine should only be used to poll the primary handler. There were patches for the "other" possible things that might happen so
for both.
Sebastian
Jonathan Cameron
maintainerQuoted 15 lines · On Tue, 17 Nov 2020 14:03:01 +0100 Sebastian Andrzej Siewior…
Quoted 7 lines · Lars-Peter Clausen
On
PREEMPT_RTenabled kernels unmarked hrtimers are moved into soft interrupt expiry mode by default.The IIO hrtimer-trigger needs to run in hard interrupt context since it will end up calling
generic_handle_irq()which has the requirement to run in hard interrupt context.Quoted 6 lines
Explicitly specify that the timer needs to run in hard interrupt context by using the
HRTIMER_MODE_REL_HARDflag.Fixes f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")Reported-by Christian Eggers <[email protected]>Signed-off-by Lars-Peter Clausen <[email protected]>
Quoted 5 lines
If I remember correctly, this routine should only be used to poll the primary handler. There were patches for the "other" possible things that might happen so
I've applied them both to the fixes-togreg branch fo iio.git but not marked them for stable. If you want them in specific stable releases then please request them explicitly after they've merged.
Thanks,
Jonathan
Quoted 4 lines
for both.
Sebastian