0

I'm currently trying to determine the quantities of cpus in each cpu cluster of a big.LITTLE architecture from userspace.

I'm looking at files on sysfs to see if any of them can give the information I need. I noticed that /sys/devices/system/cpu/cpuX/uevent can give me the processor type for that cpu id, so I could get the cluster size by parsing it.
The file is given like this:

OF_NAME=cpu
OF_FULLNAME=/cpus/cpu@100
OF_TYPE=cpu
OF_COMPATIBLE_0=arm,cortex-a53
OF_COMPATIBLE_1=arm,armv8
OF_COMPATIBLE_N=2
MODALIAS=cpu:type:aarch64:feature:,0000,0001,0002,0003,0004,0005,0006,0007

Where I could parse the name cortex-a53 and then define the cluster by it, since the other cluster would have cortex-a73 instead. But that seems like a lot of work just to find out the cluster size.

When looking at /sys/devices/system/cpu/cpuX/topology, I noticed that the physical_package_id maps exactly to the distribution of cores in my architecture: 6 little cores and 2 big cores.

After searching a bit, I found that the physical_package_id represents the physical socket to which the cpu belongs.

Can I determine to which cluster of a big.LITTLE architecture a core belongs by looking at its physical socket?

EDIT: I ran this script to find out the CPU topology:

CPU_NUMBER=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)
LAST_INDEX="$(($CPU_NUMBER-1))"

for i in $(seq 0 $LAST_INDEX)
do
    echo "Core $i: "
    cat /sys/devices/system/cpu/cpu$i/topology/physical_package_id
done
0

After hopping around in the linux source code. I believe that my assumptions are correct and it seems, for what I could understand, that they use the physical_package_id to identify the cluster in the driver for big.LITTLE architectures in the two following methods.

static inline int raw_cpu_to_cluster(int cpu)
{
    return topology_physical_package_id(cpu);
}
static inline int cpu_to_cluster(int cpu)
{
    return is_bL_switching_enabled() ?
        MAX_CLUSTERS : raw_cpu_to_cluster(cpu);
}

And then use it to get the frequency table in another method, which is part of what I want to do as well:

static int bL_cpufreq_init(struct cpufreq_policy *policy)
{
    u32 cur_cluster = cpu_to_cluster(policy->cpu);

   /* Some code here */

   policy->freq_table = freq_table[cur_cluster];

   /* Some more code here */
}

So I believe I can count the number of CPU cores in each cluster by looking at the physical_package_id for each one of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.