Search code examples
androidmultithreadingarm64

How do I find out the relative performance of cores on an Android device?


Sometimes, one needs to know how many fast/intermediate/slow cores a physical Android device has, so as to be able to pin threads to them for computationally intensive activities. Is there a way to find out at run-time? There are far too many models in circulation to list in an app.


Solution

  • This is provided by the Linux kernel. From the ADB shell:

    $ ls -l /sys/devices/system/cpu/cpu*/cpu_capacity
    -r--r--r-- 1 root root 4096 2024-02-18 13:20 /sys/devices/system/cpu/cpu0/cpu_capacity
    -r--r--r-- 1 root root 4096 2024-02-18 13:20 /sys/devices/system/cpu/cpu1/cpu_capacity
    ...
    -r--r--r-- 1 root root 4096 2024-02-18 13:20 /sys/devices/system/cpu/cpu7/cpu_capacity
    

    The files' contents give the relative performance of the CPUs:

    $ cat /sys/devices/system/cpu/cpu*/cpu_capacity
    397
    397
    397
    397
    1003
    1003
    1003
    1024 
    

    The numbers are normalised so that the fastest cpu(s) on the device are reported as 1024, and the slower ones as smaller numbers. These figures are from a Samsung Galaxy A52 5G, running Android 14, with kernel 5.4.233. /sys should be easily readable from apps, as opposed to the shell (I don't actually produce apps, just libraries that are tested in the ADB shell).

    The oldest device I have access to where cpu_capacity exists is a nameless Android 10 tablet with kernel 4.14. It exists in everything with a newer kernel I've tried. It does not exist in Android 9 with kernel 4.9 on an IoT development board. Looking at the list of Android Common Kernels, it appears that devices that launched with Android 11 or later should always have cpu_capacity, but devices that launched with earlier versions of Android may lack it.

    The higher-numbered cores are usually the fast ones, but this is not always true: a Samsung Galaxy Tab 7A Lite running Android 12 with kernel 4.19 had the faster cores at the lower numbers - and still has after an update to Android 14, still with the same kernel version.