blob: b4e5d1ab767c6781d0b40be170ae8e3144fb0af5 [file] [log] [blame]
Klement Sekera558ceab2021-04-08 19:37:41 +02001import os
2import psutil
3
4available_cpus = psutil.Process().cpu_affinity()
5num_cpus = len(available_cpus)
6
7max_vpp_cpus = os.getenv("MAX_VPP_CPUS", "auto").lower()
8
9if max_vpp_cpus == "auto":
10 max_vpp_cpus = num_cpus
11else:
12 try:
13 max_vpp_cpus = int(max_vpp_cpus)
14 except ValueError as e:
15 raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
16 "values are a positive integer or 'auto'") from e
17 if max_vpp_cpus <= 0:
18 raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
19 "values are a positive integer or 'auto'")
20 if max_vpp_cpus > num_cpus:
21 max_vpp_cpus = num_cpus