12

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
janekb04
  • 4,304
  • 2
  • 20
  • 51
  • See [this](https://stackoverflow.com/a/72245739/3740047) post. – Sedenion Oct 13 '22 at 06:04
  • Yes, `cpuid" results are core-dependent. The OS should return the processor topology somehow, I'm not sure the APIs caught up yet. If you cannot reliably get the topology from the OS, you are better off pinning a thread to each core (beware of how the L2 is shared across E-cores). – Margaret Bloom Oct 13 '22 at 08:53
  • 1
    Indeed, [Intel has an example for Windows](https://www.intel.com/content/www/us/en/developer/articles/guide/12th-gen-intel-core-processor-gamedev-guide.html) – Margaret Bloom Oct 13 '22 at 09:36

0 Answers0