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