Skip to content

Commit

Permalink
fix(Linux): cpu_count_cores() method giampaolo#2 on aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jun 15, 2024
1 parent 38660d2 commit de9fdd8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ def cpu_count_cores():
# Method #2
mapping = {}
current_info = {}
# 'physical id' / 'cpu cores' not supported on e.g. aarch64
# https://github.com/torvalds/linux/blob/v6.9/arch/arm64/kernel/cpuinfo.c#L193-L258
# fall-back to processor count in this case
processor_count = 0
with open_binary('%s/cpuinfo' % get_procfs_path()) as f:
for line in f:
line = line.strip().lower()
Expand All @@ -711,9 +715,11 @@ def cpu_count_cores():
if line.startswith((b'physical id', b'cpu cores')):
key, value = line.split(b'\t:', 1)
current_info[key] = int(value)
elif line.startswith(b'processor\t:'):
processor_count += 1

result = sum(mapping.values())
return result or None # mimic os.cpu_count()
return result or processor_count or None # mimic os.cpu_count()


def cpu_stats():
Expand Down

0 comments on commit de9fdd8

Please sign in to comment.