I run my NT service on an Intel Core2 based Win2k3 machine where I need to iterate through all logical CPUs (all bits in process affinity). To do so I call GetProcessAffinityMask() to retrieve the system affinity mask and then switch the process to each processor in turn:
DWORD systemMask;
GetProcessAffinityMask( ... &systemMask );
DWORD processorId = 1;
while( systemMask != 0 ) {
SetProcessAffinityMask(... processorId );
Sleep( 1 ); // to be sure that it shifts to that processor
systemMask >>= 1;
processorId <<= 1;
}
On each iteration I invoke code from here to retrieve the current processor APIC id. The problem is that for different processors it sometimes returns identical APIC ids. According to documentation each processor in the system must have an identical id.
I tried debugging this - checked whether Windows actually changes the affinity:
while( systemMask != 0 ) {
SetProcessAffinityMask(... processorId );
Sleep( 1 ); // to be sure that it shifts to that processor
DWORD tempAffinity;
GetProcessAffinityMask( ... &tempAffinity );
// run APIC id detection code here
systemMask >>= 1;
processorId <<= 1;
}
It returns exactly the affinity mask I expect but APIC ids can still be the same for different processors.
Is there an explanation to this weird situation?