Wednesday, December 11, 2013

Interrupte Request Level (IRQL)

Each interrupt is mapped to a IRQL representing its relative priority to other interrupts.  When an interrupt happens, the system looks up the ISR via the IDT and assigns it to a processor..  If the IRQL of the CPU is lower than the IRQL of the interrupt, the thread is pre-empted, the IRQL of the CPU is raised to that of the ISR and the ISR is executed.  When the ISR completes, the IRQL of the CPU is lower to its previous value and the pre-empted code is resumed.

If the IRQL of the CPU is same as the ISR's, the ISR must wait till the current ISR completes.  Similarly, if the IRQL of the CPU is higher than the ISR's, the ISR will wait too.

Each IRQL is assigned a number.  PASSIVE_LEVEL is 0 which is the lowest.  All user mode programs run in PASSIVE_LEVEL as do common Kernel Mode Driver routines such as DriverEntry(), Unload, and IRP dispatch routines.

APC_LEVEL is 1.  DISPATCH_LEVEL in which the scheduler runs is set to 2.  Thread runing above DISPATCH_LEVEL will not be pre-empted as the scheduler will not run.  It means the code and data pages used by such thread must be pinned to memory and cannot be paged out.

The PROFILE_LEVEL is used by the timer used for profiling and is set to 27.  Between 2 and 27 are the hardware device IRQL known as DIRQL.

No comments: