deferred procedure calls (DPCs)
簡介windows
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-dpc-objects
Because ISRs must execute as quickly as possible, drivers must usually postpone the completion of servicing an interrupt until after the ISR returns. Therefore, the system provides support for deferred procedure calls (DPCs), which can be queued from ISRs and which are executed at a later time and at a lower IRQL than the ISR.
由於中斷服務例程(ISR)必須執行越快越好(執行時間越短越好),驅動一般中斷服務的完成工做推遲到ISR返回以後。因此,操做系統提供了一種叫延遲例程調用(DPC),它先在ISR過程當中插入隊列(待執行隊列),然後在低於ISR的IRQL或是事後的定時器來執行它。
Each DPC is associated with a system-defined DPC object. The system supplies one DPC object for each device object. The system initializes this DPC object when a driver registers a DPC routine known as the DpcForIsr routine. A driver can create additional DPC objects if more than one DPC is needed. These extra DPCs are known as CustomDpc routines.
每一個DPC都會關聯一個系統定義的DPC對象(程序可見的就是一個結構體)。系統爲每一個device object提供了一個DPC對象,當驅動註冊一個DPC例程到DPCForIsr(我猜是系統提供的隊列,API:IoDpcRoutine),系統初始化DPC對象。驅動也能夠建立額外的DPC。額外的DPC是用戶級(API:KdeferredRoutine)。ide
DPC object contents should not be directly referenced by drivers. The object's structure is not documented. Drivers do not have access to the system-supplied DPC object assigned to each device object. Drivers allocate storage for extra DPCs, but the contents of these DPC objects should only be referenced by system routines.
DPC對象的內容沒必要被驅動直接使用。對象的結構沒有公開。驅動不不能夠訪問系統分配給每個設備對象的DPC對象。驅動爲額外的DPC申請內存,這些DPC的內容也只被系統例程訪問。
DPC objects and DPCs can also be used with timers. For more information, see Timer Objects and DPCs.
windows驅動中有兩種定時器post
英文名 | 初始化API | 特色 | |
---|---|---|---|
IO定時器 | ioTimer 基於DPC | void IoTimerRoutine( _DEVICE_OBJECT *DeviceObject, PVOID Context) | 每一device都有一個定時器,此類定時器依賴device.IO定時器是DPC的一個變種. |
DPC定時器 | Ketimer 基於KTIMER | KeInitializeDpc | 不依賴device. |
ioTimer
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nc-wdm-io_timer_routineui
The IoTimer routine is a DPC that, if registered, is called once per second.
每秒運行一次的DPC.this
參考
window驅動內核元素介紹
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/eprocess操作系統
KTIMER與DPC介紹
https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/timer-objects-and-dpcsorm