window 驅動定時器

deferred procedure calls (DPCs)
簡介

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)。



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驅動中有兩種定時器


英文名 初始化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_routine

The IoTimer routine is a DPC that, if registered, is called once per second.
每秒運行一次的DPC.

參考
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-dpcs

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章