1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 03:19:47 +03:00
pmbootstrap/pmb/parse/cpuinfo.py
Oliver Smith 36dd53f402
Run ruff check --fix (MR 2357)
Now that we have target-version = "py310" in [tool.ruff] in
pyproject.toml, ruff check complains about using typing.Optional and
typing.Union instead of newer syntax. Run the tool to fix it.
2024-07-16 00:26:35 +02:00

32 lines
1,006 B
Python

# Copyright 2023 Lary Gibaud
# SPDX-License-Identifier: GPL-3.0-or-later
import re
def arm_big_little_first_group_ncpus() -> 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("/proc/cpuinfo") 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