kimwalisch / primesieve

🚀 Fast prime number generator
BSD 2-Clause "Simplified" License
956 stars 123 forks source link

CpuInfo.cpp: Don't count physical CPU cores #105

Closed kimwalisch closed 2 years ago

kimwalisch commented 2 years ago

With big.LITTLE CPUs it becomes too difficult retrieve the number of physical CPU cores on Linux, the current code cpuCores_ = cpuThreads_ / threadsPerCore_ does not work anymore. CpuInfo.cpuCores_ is not used anywhere important so it is best to remove this feature for all operating systems (and only keep cpuThreads_ which is the number of logical CPU cores).

kimwalisch commented 2 years ago

Maybe also rename cpuThreads_ to logicalCpuCores_.

kimwalisch commented 2 years ago

For the Windows code it might make sense to abort after the CPU information of the 1st CPU core has been processed (instead of overwriting that data for all CPU cores). I guess the 1st CPU core is a performance core whereas the last cores are efficiency cores.

We could also use std::thread::hardware_concurrency() to count the number of logical CPU cores, but it is currently limited to maximum 64 CPU cores on Windows, so not entirely correct on an AMD threadripper: https://github.com/microsoft/STL/discussions/1230, https://devblogs.microsoft.com/oldnewthing/20200824-00/?p=104116,

kimwalisch commented 2 years ago

Rename CpuInfo::L?CacheSize() to CpuInfo::L?CacheBytes().

kimwalisch commented 2 years ago

It looks like /sys/devices/system/cpu/cpu0 on Linux is always a performance CPU core on Intel Hybrid CPUs. So the first few cores are performance cores and the last few cores are efficiency cores. Windows likely uses the same CPU core order scheme. I think I want to retrieve the cache sizes of a performance CPU core as it will provide the best single core performance in primesieve.

On 4/16/2021 10:04 PM, Jin Yao wrote:

    AlderLake uses a hybrid architecture utilizing Golden Cove cores
    (core cpu) and Gracemont cores (atom cpu). Each cpu has dedicated
    event list. Some events are available on core cpu, some events
    are available on atom cpu and some events can be available on both.

    Kernel exports new pmus "cpu_core" and "cpu_atom" through sysfs:
    /sys/devices/cpu_core
    /sys/devices/cpu_atom

    cat /sys/devices/cpu_core/cpus
    0-15

    cat /sys/devices/cpu_atom/cpus
    16-23