#StackBounty: #windows #winapi #processor #cpuid In which cases GetSystemInfo/GetLogicalProcessorInformationEx returns different proces…

Bounty: 100

There are Windows API functions to obtain CPU and CPU Cache topology.

GetSystemInfo fills SYSTEM_INFO with dwActiveProcessorMask and dwNumberOfProcessors.

GetLogicalProcessorInformationEx can be used to have more precise information about each processor, like cache size, cache line size, cache associativity, etc. Some of this information can be obtained by _cpuidex as well.

I’m asking in which cases the obtained values for one call are not consistent with obtained values for another call, if both calls are made without program restart.

Specifically, can CPU count change:

  • Should user hibernate, install new processor, and wake the system? Or even this wouldn’t work?
  • Or operating system / hardware can just dynamically decide to plug in another processor?
  • Or it can be achieved with virtual machines, but not on real hardware?

Can cache line size and cache size change:

  • For GetLogicalProcessorInformationEx, because processor is replaced at runtime
  • For _cpuid just because system contains processors with different cache properties, and subsequent calls are on a different processor

The practical reason for these questions is that I want to obtain this information only once, and cache it:

  • I’m going to use it for allocator tuning, so changing allocation strategy for already allocated memory is likely to cause memory corruption.
  • These function may be expensive, they may be kernel calls, which I want to avoid


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.