xref: /reactos/media/doc/INTERNALS (revision 9393fc32)
1*c2c66affSColin FinckA collection of articles on kernel internals, please add to this
2*c2c66affSColin Finck
3*c2c66affSColin Finck------------------------------------------------------------------------------
4*c2c66affSColin FinckIRQ level
5*c2c66affSColin Finck------------------------------------------------------------------------------
6*c2c66affSColin Finck
7*c2c66affSColin FinckIRQ level (IRQL) is a per-processor state in ReactOS used to coordinate
8*c2c66affSColin Finckexecution between ISRs and between threads. There are several levels
9*c2c66affSColin Finck
10*c2c66affSColin Finck       PASSIVE_LEVEL, APC_LEVEL: The normal level for user mode and most
11*c2c66affSColin Finck       kernel mode code. At the moment APC_LEVEL is unused.
12*c2c66affSColin Finck
13*c2c66affSColin Finck       DISPATCH_LEVEL: At this level all irqs are still allowed but thread
14*c2c66affSColin Finck       rescheduling on the current processor is disabled. This is used by
15*c2c66affSColin Finck       the spinlock synchronization primitive to implement its uniprocessor
16*c2c66affSColin Finck       semantics (multiprocessor is more complex). It is also used for some
17*c2c66affSColin Finck       other forms of synchronization, DPCs for example. Many APIs are
18*c2c66affSColin Finck       unavailable at this IRQL, usually those that might have to wait. It
19*c2c66affSColin Finck       is recommended that you don't spend too much time at this IRQL
20*c2c66affSColin Finck       otherwise system responsiveness will be reduced.
21*c2c66affSColin Finck
22*c2c66affSColin Finck       > DISPATCH_LEVEL: Each irq is assigned a priority (which will be
23*c2c66affSColin Finck       greater than DISPATCH_LEVEL). At an irq's priority level that irq,
24*c2c66affSColin Finck       lower priority irqs and thread rescheduling are disabled. Higher
25*c2c66affSColin Finck       priority irqs can still run. Very few APIs are available at IRQLs
26*c2c66affSColin Finck       greater than DISPATCH_LEVEL.
27*c2c66affSColin Finck
28*c2c66affSColin Finck       HIGH_LEVEL: All irqs are disabled.
29*c2c66affSColin Finck
30*c2c66affSColin Finck-------------------------------------------------------------------------------
31*c2c66affSColin FinckDPCs
32*c2c66affSColin Finck-------------------------------------------------------------------------------
33*c2c66affSColin Finck
34*c2c66affSColin FinckIt is a design goal not to spend too much time in ISRs, for this reason
35*c2c66affSColin FinckISRs should postpone most processing till it can run at a lower IRQL. The
36*c2c66affSColin Finckmechanism for this is a Deferred Procedure Call (DPC). When a DPC object is
37*c2c66affSColin Finckcreated, it is associated with a function. The DPC object can then be inserted
38*c2c66affSColin Finckin the DPC queue from an ISR. If the IRQL on return from the ISR is less than
39*c2c66affSColin FinckDISPATCH_LEVEL the DPC queue will be drained, otherwise this will happen when
40*c2c66affSColin Finckthe IRQL level drops below DISPATCH_LEVEL or the processor becomes idle. When
41*c2c66affSColin Finckthe DPC queue is drained each DPC object is removed and the associated
42*c2c66affSColin Finckfunction is called at DISPATCH_LEVEL. A DPC object can only be inserted once,
43*c2c66affSColin Finckfurther insertions before it is removed will have no effect.
44