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
536 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need some help with Microsoft Visual Studio C++ 2003 5 74
Dialogbox API leak? 18 109
Outlook 13 84
I could not set window to top 4 45
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

726 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