Search code examples
clinuxlinux-kernelarmirq

What is the irq latency due to the operating system?


  • How can I estimate the irq latency on ARM processor?
  • What is the definition for irq latency?

Solution

  • Mats and Nemanja give some good information on interrupt latency. There are two is one more issue I would add, to the three given by Mats.

    1. Other simultaneous/near simultaneous interrupts.
    2. OS latency added due to masking interrupts. Edit: This is in Mats answer, just not explained as much.

    If a single core is processing interrupts, then when multiple interrupts occur at the same time, usually there is some resolution priority. However, interrupts are often disabled in the interrupt handler unless priority interrupt handling is enabled. So for example, a slow NAND flash IRQ is signaled and running and then an Ethernet interrupt occurs, it may be delayed until the NAND flash IRQ finishes. Of course, if you have priorty interrupts and you are concerned about the NAND flash interrupt, then things can actually be worse, if the Ethernet is given priority.

    The second issue is when mainline code clears/sets the interrupt flag. Typically this is done with something like,

    mrs   r9, cpsr
    biceq r9, r9, #PSR_I_BIT
    

    Check arch/arm/include/asm/irqflags.h in the Linux source for many macros used by main line code. A typical sequence is like this,

    lock interrupts;
    manipulate some flag in struct;
    unlock interrupts;
    

    A very large interrupt latency can be introduced if that struct results in a page fault. The interrupts will be masked for the duration of the page fault handler.

    The Cortex-A9 has lots of lock free instructions that can prevent this by never masking interrupts; because of better assembler instructions than swp/swpb. This second issue is much like the IRQ latency due to ldm/stm type instructions (these are just the longest instructions to run).

    Finally, a lot of the technical discussions will assume zero-wait state RAM. It is likely that the cache will need to be filled and if you know your memory data rate (maybe 2-4 machine cycles), then the worst case code path would multiply by this.

    Whether you have SMP interrupt handling, priority interrupts, and lock free main line depends on your kernel configuration and version; these are issues for the OS. Other issues are intrinsic to the CPU/SOC interrupt controller, and to the interrupt code itself.