I want to find out what the L2 cache size is on the current processor. Fortunately, there is a library called cpu_features
which allows for that, and more. Internally, it uses the cpuid
instruction to get all of this information.
I am wondering, what would happen if I would try to use it on a hybrid architecture, like Alder Lake? Its efficiency and performance cores have different characteristics. I would assume that the cpuid
instruction returns the information about the core on which the current thread runs. So basically, if it would be scheduled to run on a performance core, it would describe the performance core.
The problem with that is that the OS can decide to later move the thread to an efficiency core, in which case, any information received from cpuid
can no longer be correct. And the program doesn't even know that it was migrated. This can be solved by manually "pinning" the thread to a core, by setting its affinity. To distinguish the performance and efficiency cores, I could pin the thread to every core in sequence and compare the results returned by cpuid
.
Still, I'd like to know if cpuid
results are indeed core-dependent, and if there is maybe a better way to query information about the processor that doesn't require having to loop through all the cores only to classify them into one of the two categories.