Skip to contentSkip to conversation

iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context

PATCH In review Lars-Peter Clausen 3 participants 4 messages Nov 17, 2020 – Nov 21, 2020 IIO

lore
Share & tools
lore
#0 lore raw

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.

Fixes f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")

---
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
index f59bf8d58586..410de837d041 100644
@@ -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
#1 lore raw

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
index e09e58072872..10a3fd29362b 100644
@@ -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
Acked-by on v2 1/2
#2 lore raw
In reply to Lars-Peter Clausen
Quoted 7 lines · Lars-Peter Clausen

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.

Quoted 6 lines

Explicitly specify that the timer needs to run in hard interrupt context by using the HRTIMER_MODE_REL_HARD flag.

Fixes f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")

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

maintainer
#3 lore raw
Quoted 15 lines · On Tue, 17 Nov 2020 14:03:01 +0100 Sebastian Andrzej Siewior…
Quoted 7 lines · Lars-Peter Clausen

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.

Quoted 6 lines

Explicitly specify that the timer needs to run in hard interrupt context by using the HRTIMER_MODE_REL_HARD flag.

Fixes f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")
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