1

How to get the number of Performance cores, also known as P-cores in a script?

Optionally, how to get the number of Efficient-cores or Low Power Efficient-cores? (This question does not concern me right now, but it seems fitting and could be of use to future readers. Otherwise, disregard this part.)

Note: if you want to know the number of Physical cores, which would also include Efficient-cores and Low Power Efficient-cores, you can refer to this SO. If you want to list the cores for manual reading and understanding, you can refer to this SO.
This question is specifically on how to find the number of P-cores, from a script.

VasyaNovikov
  • 3,656

1 Answers1

0

To do it in a script, use:

lscpu --all --extended=core | tail --lines=+2 | sort | uniq --repeated | wc -l

To understand the underlying machinery, start with the command lscpu --all --extended. You will see which CPUs you have, and to which cores they belong. Afterwards, you can alter the command to only output the "core" column via --extended=core, then remove the first line to focus on the numbers in that column via tail --lines=+2, then sort the lines alphabetically via sort, then remove lines that do not have duplicates via the uniq command, then count the number of remaining lines via wc -l.

VasyaNovikov
  • 3,656