DPC and APC

An asynchronous procedure call (APC) is a function that executes asynchronously. APCs are similar to deferred procedure calls (DPCs), but unlike DPCs, APCs execute within the context of a particular thread . Drivers (other than file systems and file-system filter drivers) do not use APCs directly, but other parts of the operating system do, so you need to be aware of how APCs work.

 

The Windows operating system uses three kinds of APCs:

  • User APCs run strictly in user mode and only when the current thread is in an alertable wait state. The operating system uses user APCs to implement mechanisms such as overlapped I/O and the QueueUserApc Win32 routine.
  • Normal kernel APCs run in kernel mode at IRQL = PASSIVE_LEVEL. A normal kernel APC preempts all user-mode code, including user APCs. Normal kernel APCs are generally used by file systems and file-system filter drivers.
  • Special kernel APCs run in kernel mode at IRQL = APC_LEVEL. A special kernel APC preempts user-mode code and kernel-mode code that executes at IRQL = PASSIVE_LEVEL, including both user APCs and normal kernel APCs. The operating system uses special kernel APCs to handle operations such as I/O request completion. 

Deferred procedure calls (DPCs). Any driver that has an ISR typically also has at least one DpcForIsr or CustomDpc routine to complete processing of interrupt-driven I/O operations. A typical lowest-level driver's DpcForIsr or CustomDpc routine does the following:

  • Finishes handling an I/O operation that the ISR began processing.
  • Dequeues the next IRP so that the driver can begin processing it.
  • Completes the current IRP, if possible.

Sometimes the current IRP can't be completed because several data transfers are required, or a recoverable error was detected. In these cases, the DpcForIsr or CustomDpc routine typically reprograms the device for either another transfer or a retry of the last operation.

 

DPC在Driver的中断处理中经常使用。ISR通过调用IoRequestDpc激活DPC routine,处理中断引起而不能在ISR中处理的I/O操作。这些操作大多需要较长时间,且不能在较高的IRQL上运行。

 

APC在底层Driver中较少使用,多用于User APP和File System Driver中。和DPC的最大区别在于APC运行在某个特定线程的上下文中,而DPC运行在任意线程上下文(Arbitrary Thread Context)中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值