1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
# Copyright 2023 Lary Gibaud
# SPDX-License-Identifier: GPL-3.0-or-later
import re
from pathlib import Path
def arm_big_little_first_group_ncpus(cpuinfo_path: Path = Path("/proc/cpuinfo")) -> int | None:
"""
Infer from /proc/cpuinfo on aarch64 if this is a big/little architecture
(if there is different processor models) and the number of cores in the
first model group.
https://en.wikipedia.org/wiki/ARM_big.LITTLE
:returns: the number of cores of the first model in the order given by
linux or None if not big/little architecture
"""
pattern = re.compile(r"^CPU part\s*: (\w+)$")
counter = 0
part = None
with open(cpuinfo_path) as cpuinfo:
for line in cpuinfo:
match = pattern.match(line)
if match:
grp = match.group(1)
if not part:
part = grp
counter += 1
elif part == grp:
counter += 1
else:
return counter
return None
|