aboutsummaryrefslogtreecommitdiffstats
path: root/test/cpu_config.py
blob: b4e5d1ab767c6781d0b40be170ae8e3144fb0af5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import psutil

available_cpus = psutil.Process().cpu_affinity()
num_cpus = len(available_cpus)

max_vpp_cpus = os.getenv("MAX_VPP_CPUS", "auto").lower()

if max_vpp_cpus == "auto":
    max_vpp_cpus = num_cpus
else:
    try:
        max_vpp_cpus = int(max_vpp_cpus)
    except ValueError as e:
        raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
                         "values are a positive integer or 'auto'") from e
    if max_vpp_cpus <= 0:
        raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
                         "values are a positive integer or 'auto'")
    if max_vpp_cpus > num_cpus:
        max_vpp_cpus = num_cpus