• Welcome to Valhalla Legends Archive.
 

Processor affinity in Windows NT kernel mode drivers

Started by Skywing, May 24, 2003, 04:23 PM

Previous topic - Next topic

Skywing

Does anybody know how to query the affinity mask of a thread in a kernel mode driver?

Also, is it possible to "lock" the affinity mask of a thread while it's in kernel mode and handling an IRP?

I need to make sure some MSR accesses are always made on the same processor for a multiprocessor driver.

Edit: After poking around in the documentation for a couple hours, I finally came up with this:
QuoteKeGetCurrentProcessorNumber
ULONG
 KeGetCurrentProcessorNumber( );
KeGetCurrentProcessorNumber returns the system-assigned number of the current processor on which the caller is running.

Include
ntddk.h

Comments
KeGetCurrentProcessorNumber can be called by NT drivers to debug spin lock usage on SMP machines during driver development. An NT driver also might call KeGetCurrentProcessorNumber if it maintained some per-processor data and attempted to reduce cache-line contention.

The number of processors in an SMP machine is a zero-based value.

If the call to KeGetCurrentProcessorNumber occurs at IRQL < DISPATCH_LEVEL, a processor switch can occur between instructions. Consequently, callers of KeGetCurrentProcessorNumber usually run at IRQL >= DISPATCH_LEVEL.

I've posted this since it's rather well hidden within the DDK documentation.