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