aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/QemuUtils.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py
index 3751cd6da9..16ade29167 100644
--- a/resources/libraries/python/QemuUtils.py
+++ b/resources/libraries/python/QemuUtils.py
@@ -53,8 +53,6 @@ class QemuUtils(object):
self._qemu_opt['huge_allocate'] = False
# Default image for CSIT virl setup
self._qemu_opt['disk_image'] = '/var/lib/vm/vhost-nested.img'
- # Affinity of qemu processes
- self._qemu_opt['affinity'] = False
# VM node info dict
self._vm_info = {
'type': NodeType.VM,
@@ -128,13 +126,28 @@ class QemuUtils(object):
"""
self._qemu_opt['disk_image'] = disk_image
- def qemu_set_affinity(self, mask):
- """Set qemu affinity by taskset with cpu mask.
+ def qemu_set_affinity(self, *host_cpus):
+ """Set qemu affinity by getting thread PIDs via QMP and taskset to list
+ of CPU cores.
- :param mask: Hex CPU mask.
- :type mask: str
+ :param host_cpus: List of CPU cores.
+ :type host_cpus: list
"""
- self._qemu_opt['affinity'] = mask
+ qemu_cpus = self._qemu_qmp_exec('query-cpus')['return']
+
+ if len(qemu_cpus) != len(host_cpus):
+ logger.debug('Host CPU count {0}, Qemu Thread count {1}'.format(
+ len(host_cpus), len(qemu_cpus)))
+ raise ValueError('Host CPU count must match Qemu Thread count')
+
+ for qemu_cpu, host_cpu in zip(qemu_cpus, host_cpus):
+ cmd = 'taskset -p {0} {1}'.format(hex(1 << int(host_cpu)),
+ qemu_cpu['thread_id'])
+ (ret_code, _, stderr) = self._ssh.exec_command_sudo(cmd)
+ if int(ret_code) != 0:
+ logger.debug('Set affinity failed {0}'.format(stderr))
+ raise RuntimeError('Set affinity failed on {0}'.format(
+ self._node['host']))
def qemu_set_node(self, node):
"""Set node to run QEMU on.
@@ -409,12 +422,9 @@ class QemuUtils(object):
'-device isa-serial,chardev=qga0'
# Graphic setup
graphic = '-monitor none -display none -vga none'
- qbin = 'taskset {0} {1}'.format(self._qemu_opt.get('affinity'),
- self.__QEMU_BIN) if self._qemu_opt.get(
- 'affinity') else self.__QEMU_BIN
# Run QEMU
cmd = '{0} {1} {2} {3} {4} -hda {5} {6} {7} {8} {9}'.format(
- qbin, self._qemu_opt.get('smp'), mem, ssh_fwd,
+ self.__QEMU_BIN, self._qemu_opt.get('smp'), mem, ssh_fwd,
self._qemu_opt.get('options'),
self._qemu_opt.get('disk_image'), qmp, serial, qga, graphic)
(ret_code, _, stderr) = self._ssh.exec_command_sudo(cmd, timeout=300)