I need to read the current processor number in a WIN32 program.
How can this be done?
Better still, is there a way to do it WITHOUT having to write an ad-hoc
device driver?
Thanks for any clue,
Jean-François
PS. The reason I need to know this number is because I'm reading the CPU
Time Stamp Counter register for measuring very short durations.
On my system (a bi-processor) it happens that both processors have almost
the same counts at the same time. But I'm not sure it's guarantied to be the
case in general.
You can force your process to run on a particular processor using the Win32
API SetProcessAffinityMask().
Regards,
Brad
This is not guaranteed, use the affinity mask to bind the thread to a
particular CPU to guarantee this.
Max
JF
Yes there is!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/getprocessaffinitymask.asp
> But even if there were, what I actually need is a GetCurrentProcessor()!
There is not GetCurrentProcessor, because that is not relevant for user-mode
apps. They cannot run at elevated IRQL.
Leo Havmøller.
If you're running on a Pentium4 you can do CPUID (with eax = 1) and look at
the Local APIC ID in bits 31:24 of returned ebx. That will be unique for each
processor.
Don't know how to do it from user-mode on P5/P6 type processors.
Enio.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/getprocessaffinitymask.asp
> But even if there were, what I actually need is a GetCurrentProcessor()!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/multiple_processors.asp?frame=true.
The section on Thread Scheduling in "Inside Microsoft Windows 2000" (Solomon
and Russinovich) provides additional information.
Regards,
Brad
Don Burn
Egenera, Inc