[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
Medium Priority
?
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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…
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.
Suggested Courses

650 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