Skip to content

Commit

Permalink
Fix cgroup2 "max" case #11635
Browse files Browse the repository at this point in the history
When $MAX == "max", there is no limit on the cpu usage set
Use multiprocessing.cpu_count() function in that case
  • Loading branch information
Maria Mozgunova committed Jul 21, 2022
1 parent 1fb20cf commit 9e43328
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions conan/tools/build/cpu.py
Expand Up @@ -16,15 +16,15 @@ def _cpu_count():
try:
try:
# This is necessary to deduce docker cpu_count
cfs_quota_us = cfs_period_us = 0
# 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)
if cpu_max[0] != "max":
if len(cpu_max) == 1:
cfs_quota_us, cfs_period_us = int(cpu_max[0]), 100_000
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"))
Expand Down

0 comments on commit 9e43328

Please sign in to comment.