Wednesday, January 13, 2016

All about FIQs(Fast Interrupt reQuest)

A traditional question asked in Interviews :- 

Explain FIQ and its usage 

I would like to cover this whole topic here. Though all information related to this topic is available on web however its highly scattered. I have accumulated all that here.


Fast Interrupt reQuest  is a higher priority interrupt. This means that it will always have precedence over regular interrupts and  regular interrupts won’t mask or interrupt an FIQ, while an FIQ will mask or interrupt any IRQ.  

Many systems do not use FIQs at all, or use it in a way analogous to the non-maskable (NMI) interrupt found on other processors (although FIQ is software maskable on most ARM processors).

Important  Difference between FIQ and IRQs :-

First, FIQs are executed in a dedicated execution mode, and this FIQ mode has 7 dedicated registers, from r8 to r14. This allows to have persistent values between each FIQ handler code, and avoids the overhead of pushing and popping in the handler. The second thing to know is that, unlike the regular IRQ handlers, the FIQ handler has to be written using ARM assembly, mostly because the C compiler won’t produce any code that can use only these r8 to r14 registers.


FIQs are mostly not used by Linux kernel, however there are exceptions. Please read on ...


Few Real applications of FIQ 

FIQ can perhaps best be used to eliminate the need for a DMA unit in certain low cost systems. In FIQ mode , the register used by ARM is a different set hence which can be used for a FIFO interrupt of data transfer just like the DMA. This is only possible because ARM provides extra number of registers for FIQ mode.

FIQ is used for Secure Worlds in ARM TrustZone implementations, to distinguish interrupts from "secure" interrupt sources. The precise determination of what might be a secure interrupt source and how that should be handled differently from a normal interrupt depends on the implementations.

Even ARM supports this;  From ARM infocenter :-

"The model recommended by ARM is the use of IRQ as a Normal world interrupt source, and FIQ as the Secure world source. IRQ is the most common interrupt source in use in most operating environments, so the use of FIQ as the secure interrupt should mean the fewest modifications to existing software. If the processor is running the correct virtual core when an interrupt occurs there is no switch to the monitor and the interrupt is handled locally in the current world. If the core is in the other world when an interrupt occurs the hardware traps to the monitor, the monitor software causes a context switch and jumps to the restored world, at which point the interrupt is taken"

FIQ for spinlock debugging and Hardlock up scenarios :- 


In simple words, if the a ARM system faces deadlock due to spinlocks, the spin lock debug will only show stack trace of the current CPU that stuck due to the lock. however at the same time , if we can get the trace of all other CPUs, it makes easy for developers to debug issues in multicore systems. 

To address this problem the FIQ was used for  arch_trigger_all_cpu_backtrace() 

All cpu backtrace is called by the spinlock debugging code when it thinks the system might have locked up. It works by sending IPIs (inter-processor interrupts - refer callback  send_IPI_all in Linux kernel code) that raise FIQ on the CPUs  and, because it uses FIQ, these processors respond and issue a stack trace even if they are locked up and have interrupts masked. Note that when spinlock locks out, the local interrupts gets disabled so  the same applies as most embedded system would like to go for a recovery even though the kernel locks out. The FIQs can also used as a recovery mechanism for many such cases in order to get more debug information which watchdog may not provide.

Note that the IPI gets only applied to multi-core or smp systems, Please check the patch implemented for avoiding sending IPI for UP(uniprocessor) systems.

FIQs are also used by Hardware performance monitoring (Please click on the link to read more on the topics) 


References :-





No comments:

Post a Comment