7

I am trying to affinitise the completion of CompleteRequest to the CPU that originally issued the request. Is there a way to retrieve the CPU that issued the request during FdoDeviceControl or any onother way to see where the request came from before it entered the dispatch queue?

Thomas Kejser
  • 1,264
  • 1
  • 10
  • 30
  • Retrieving the CPU after that dispatch has happened is of course simple enough. But am I guaranteed that the callback function runs on the same core as the issues? – Thomas Kejser Jan 08 '13 at 09:06

1 Answers1

6

Once you are in a DPC routine it's too late to tell where the request originated. You need to call KeGetCurrentProcessorNumberEx() before you queue the request to a DPC queue. I assume the request is an IRP...?

David P
  • 153
  • 7
  • David, I am using KMDF to handle request so the IRP is wrapped in a WDFREQUEST struct. At the point I see the request, it ha already passed through an I/O queue – Thomas Kejser Jan 18 '13 at 11:02
  • If you are using KMDF then you need to call WdfDeviceInitSetIoInCallerContextCallback(). This will allow you to peek at the I/O request before it gets place onto the kmdf I/O queue, you will be running in the process context of the I/O initiator and you will be on the core that initiated the I/O. From there you can call KeGetCurrentProcessorNumberEx() and save the result. – David P Jan 20 '13 at 07:48
  • Listed as an answer David, thanks. On a related note, am I guarateed that EvtDeviceWdmIrpPreprocess is also called in the context of the client (I am using guaranteed forward progress queues, so I need to make sure I ALWAYS get the call, which it looks like SetIoInCallerContextCallback doesnt do) – Thomas Kejser Jan 21 '13 at 13:05
  • That's unusual, I think you should always get the callback using WdfDeviceInitSetIoInCallerContextCallback(). Make sure you call it before calling WdfDeviceCreate(). In any case if there is a filter driver above you then, the original context may be lost. – David P Jan 22 '13 at 00:47