I found that latency of GPIO interrupt handlers is big and unstable.
On other ARM Cortex-A7 systems, for example i.MX6ULL, I used CONFIG_PREEMPT_RT enabled in kernel configuration to get interrupt latency stable in range 5-10 us.
Is it possible to use this option with Legato and WP76/77 modems? Any experience? Or other way to struggle with latency should be used?
I’m using GPIO interrupt in my linux kernel module.
I tested top half interrupt handler latencies, and it’s big, up to milliseconds latency. Test is made by switching logic level of other GPIO to see delay between interrupt signal rising edge, and second GPIO signal edge.
Average latency for GPIO interrupt for default kernel configuration is 600-700 microseconds. It corresponds to non-RT kernel configuration. That’s why I asked about PREEMPT_RT option and Legato.
increasing task priority and changing IRQ priority are on kernel level
If you want to test CONFIG_PREEMPT_RT, you can try to add this in yocto source “./kernel/arch/arm/configs/mdm9607_defconfig” and recompile yocto image to see if there is any improvement
Looks like linux 4.14.253 supplied with Legato 21.05 has no PREEMPT_RT patches included.
Because of this, interrupt priorities are also selected by the code in manage.c, and it’s impossible to change them from the kernel module. Or I’m wrong?
The same, previous release also has no PREEMPT_RT patch.
Of course, I downloaded compiled image, but no any change in latency.
Without of RT-patch Linux have no possibility to fine-tune priorities in the APIC. The code in manage.c is related to bottom half (or threaded IRQ context):
static int
setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
{
struct task_struct *t;
struct sched_param param = {
.sched_priority = MAX_USER_RT_PRIO/2,
};
if (!secondary) {
t = kthread_create(irq_thread, new, "irq/%d-%s", irq,
new->name);
I’m requesting interrupt with IRQF_NO_THREAD flag and by request_irq() routine. It means that interrupt handler should be called in HARDIRQ context, not in kernel thread context.
The request_threaded_irq() call has two handler pointers: first will be called in HARDIRQ context “top half”, and second is “bottom half” will be called in kernel thread context.
The problem is in that HARDIRQ context has too much latency…
I’m exploring I/O capabilities of WP76/77 modems to decide about of architecture of my future device.
For low speed SPI I found spi-gpio already included in the kernel, and it works fine, so, I don’t need to invent my own bicycle.
I also have other peripherals normally with separate Cortex-M MCU with FreeRTOS and my software.
On GPIO interrupt I need to check state of 4 other GPIO lines in 0.5 milliseconds. Because I normally use PREEMPT_RT, I saw no problem here. Using Linux 5.6 and i.MX6ULL, for example, I got interrupt latency around 10 microseconds for “top half”. However, with WP77 I got 600 microseconds latency in average today.
i saw some internal discussion on this topic saying Linux is not a good environment for servicing time-critical interrupts.
If the user is looking for guaranteed interrupt latencies, it might not be able to provide that.
But as best-effort measurements the user could write their application code and use Linux FTRACE capability to estimate probabilities of interrupts being serviced within a time limit.
Yes, right. Mainline Linux Kernel is not very suitable for hard-RT tasks.
Of course, I can try to integrate PREEMPT_RT patches to the kernel. However, I have no detail information about how tightly the modem part is integrated with application part. If Linux and Legato running on pure dedicated CPU kernel, then things should be much easier, because its role limited to download BLOBs to the modem and initialize IPC channels to communicate with the modem. Otherwise, changes in kernel may cause issues with LTE communication.