Solved

IODeviceControl call doesn't seem to execute in the context (process/thread processor affinity) of the calling DLL

Posted on 2006-11-29
5
529 Views
Last Modified: 2012-05-05
I've written a DLL that creates a driver service, starts it and then uses IODeviceControl to read some information from the driver.  I am trying to use either SetThreadAffinityMask or GetProcessAffinityMask/SetProcessAffinityMask to set the process/thread affinity to each core in the system, one at a time, in order to read a CPU specific MSR (via the device driver).  This is done in a loop, where the loop cycles for each cpu detected.

Psuedo-code that illustrates what I am trying to do:

for ( i = 0 ; i < numProcessorsDetected; i++ ) {

    SetProcessAffinityMask(); //set process to run only on the CPU 0, then CPU 1, then CPU2, then...

    IODeviceControl(); //get some information from my driver

    //do something with data return from IODeviceControl call
}

    SetProcessAffinityMask(); // back to all CPUs running

It appears that the mask is being set correctly but the driver is not executing code in the context of my calling user mode DLL.  Is this a limitation of the Window's IO subsystem?  Am I going to need to set affinity in kernel mode to ensure that the assembly code utilitized in the driver routine is actually running on the CPU that I need it to run on?

I am really confused on where to go next.  I really don't want to have to mess with my driver and create DPCs just to do this.  I would much rather do the coding in user mode as the driver is working great right now.

I can't find information ANYWHERE on this subject.  Anything anyone can add would be extremely helpful.
0
Comment
Question by:kjboughton
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 18038433
>>IODeviceControl

Did yo umean 'DeviceIoControl()'?

>>It appears that the mask is being set correctly but the driver is not executing code in the context of my calling
>>user mode DL

The call is execited in the context of the kernel. If it was executed in your call context, that would not be in kernel mode. As the docs state "The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the specified operation.". This does not mean calling a function in the driver.
0
 

Author Comment

by:kjboughton
ID: 18039767
correct, should read DeviceIoControl - don't know why I wrote that and didn't catch it.

I understand your context comment - does this mean the only way to set driver processor affinity is to use a DPC in which I set the processor affinity using kernel level calls?  If so I'm in trouble because my driver experience is still young and thats going to be a steep learning curve (probably lots of self-induced BSODs).
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 18040845
Yes, if you want to set the processor affinity of your driver's thread in kernel mode, that has to be inside the driver itself. The call is 'ZwSetInformationThread()' with the 'ThreadAffinityMask' parameter.
0
 

Author Comment

by:kjboughton
ID: 18042785
Undocumented.  Nice.  I can't really tell if it is doing anything.  Kernel debugging is not my forte.
0
 
LVL 86

Expert Comment

by:jkr
ID: 18046360
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now