Search code examples
linuxcpu-corescpuid

How to detect heterogeneous CPU topologies on Linux?


Many recent CPUs out there--Alder Lake from Intel and many big.LITTLE designs from ARM--have heterogeneous CPU topologies: some cores are faster than others. There exists good ways to detect such CPUs on Windows and macOS, but Linux/Android seems lacking.

On x86, there is a CPUID bit: leaf 7 page 0 EDX bit 15. But ARM's CPUID equivalent is privileged, so OS help is required.

Is there a good way on Linux to detect this?

For posterity:

  • On Windows, use GetLogicalProcessorInformationEx to enumerate packages and cores, then look for .Processor.EfficiencyClass being different values among cores (queries using RelationProcessorCore).
  • On macOS, use sysctlbyname on hw.nperflevels and check whether it exists and its value is greater than 1.

Solution

  • I think (not that I've ever used the programming interface) that you're after libhwloc's cpuset.

    From aptitude show hwloc:

    Description: Hierarchical view of the machine - utilities Hardware Locality (hwloc) provides a portable abstraction (across OS, versions, architectures, ...) of the hierarchical topology of modern architectures. It primarily aims at helping high-performance computing applications with gathering information about the hardware so as to exploit it accordingly and efficiently.

    hwloc provides a hierarchical view of the machine, NUMA memory nodes, sockets, shared caches, cores and simultaneous multithreading. It also gathers various attributes such as cache and memory information.

    hwloc supports old kernels not having sysfs topology information, with knowledge of cpusets, offline cpus, and Kerrighed support

    This package contains utilities to show the topology of the machine (lstopo and hwloc-ls), manipulate cpu masks (hwloc-calc), and bind processes (hwloc-bind). Homepage: https://www.open-mpi.org/projects/hwloc/