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:
Can cache line size and cache size change:
GetLogicalProcessorInformationEx, because processor is replaced at runtime_cpuid just because system contains processors with different cache properties, and subsequent calls are on a different processorThe practical reason for these questions is that I want to obtain this information only once, and cache it:
If a thread is scheduled to run on a core that belongs to a different processor group with a different number of processors, GetSystemInfo and GetLogicalProcessorInformation would return a different number of processors, which is the number of processors in the group that core belongs to.
On server-grade systems that support hot-adding CPUs, that number of processors can change as follows:
GetSystemInfo, GetLogicalProcessorInformation, and
GetLogicalProcessorInformationEx.GetLogicalProcessorInformationEx.On a virtual machine, the number of processors can also increase dynamically without hot-plugging.
You can simulate hot-adding processors using the PNPCPU tool. This is useful for testing the correctness of a piece of a code that depends on the number of processors.
It's possible to receive a notification from the system when a new processor is added by writing a device driver and registering a synchronous or asynchronous driver notification. I don't think this is possible without a device driver.
I think, on current systems, cache properties returned by GetLogicalProcessorInformationEx can only change on thread migration to another core or CPU where one or more of these properties are different. For example, on an Intel Lakefield processor, the properties of the L2 cache depend which core the thread is running because different cores have different L2 caches of different properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With