Skip to content

Commit

Permalink
[bug] get_cpus is not supporting cgroup2 #11635
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Mozgunova committed Jul 18, 2022
1 parent 442d112 commit 61a5d80
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions conan/tools/build/cpu.py
@@ -1,5 +1,6 @@
import math
import multiprocessing
import os

from conans.util.files import load

Expand All @@ -15,8 +16,18 @@ def _cpu_count():
try:
try:
# This is necessary to deduce docker cpu_count
cfs_quota_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"))
cfs_period_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_period_us"))
# cgroup2
if os.path.exists("/sys/fs/cgroup/cgroup.controllers"):
cpu_max = load("/sys/fs/cgroup/cpu.max").split()
if cpu_max[0] == "max":
return 1
elif len(cpu_max) == 1:
cfs_quota_us, cfs_period_us = int(cpu_max[0]), 1
else:
cfs_quota_us, cfs_period_us = map(int, cpu_max)
else: # cgroup1
cfs_quota_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"))
cfs_period_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_period_us"))
if cfs_quota_us > 0 and cfs_period_us > 0:
return int(math.ceil(cfs_quota_us / cfs_period_us))
except (EnvironmentError, TypeError):
Expand Down

0 comments on commit 61a5d80

Please sign in to comment.