| |
@@ -185,17 +185,21 @@
|
| |
def get_qemu_smp_arg():
|
| |
"""Determine the number of CPUs that should be visible in the guest.
|
| |
See e.g. https://www.redhat.com/archives/libvirt-users/2017-June/msg00025.html
|
| |
- We want to match the number of host physical cores.
|
| |
+ We want to match the number of host physical cores, or to go with the value
|
| |
+ provided explicitly via the STR_CPU_LIMIT environment variable.
|
| |
"""
|
| |
- # We may be run in a cgroup with fewer cores available than physical.
|
| |
- available_cpu = int(subprocess.check_output(['nproc']).strip())
|
| |
- # https://stackoverflow.com/questions/6481005/how-to-obtain-the-number-of-cpus-cores-in-linux-from-the-command-line
|
| |
- core_sockets = set()
|
| |
- for line in subprocess.check_output(['lscpu', '-b', '-p=Core,Socket'], universal_newlines=True).split("\n"):
|
| |
- if line.startswith('#'):
|
| |
- continue
|
| |
- core_sockets.add(line.strip())
|
| |
- sockets = min(available_cpu, len(core_sockets))
|
| |
+ if os.environ.get('STR_CPU_LIMIT'):
|
| |
+ sockets = os.environ.get('STR_CPU_LIMIT')
|
| |
+ else:
|
| |
+ # We may be run in a cgroup with fewer cores available than physical.
|
| |
+ available_cpu = int(subprocess.check_output(['nproc']).strip())
|
| |
+ # https://stackoverflow.com/questions/6481005/how-to-obtain-the-number-of-cpus-cores-in-linux-from-the-command-line
|
| |
+ core_sockets = set()
|
| |
+ for line in subprocess.check_output(['lscpu', '-b', '-p=Core,Socket'], universal_newlines=True).split("\n"):
|
| |
+ if line.startswith('#'):
|
| |
+ continue
|
| |
+ core_sockets.add(line.strip())
|
| |
+ sockets = min(available_cpu, len(core_sockets))
|
| |
return '{},sockets={},cores=1,threads=1'.format(sockets, sockets)
|
| |
|
| |
|
| |
Fallback to previous method if the variable is empty or doesn't exist.