aboutsummaryrefslogtreecommitdiffstats
path: root/tools/load_gen
diff options
context:
space:
mode:
authorSridhar K. N. Rao <sridhar.rao@spirent.com>2018-12-05 20:39:10 +0530
committerSridhar K. N. Rao <sridhar.rao@spirent.com>2018-12-05 20:40:35 +0530
commit1df0cf272aab762edc95ee2e7bbe26a17a58c882 (patch)
tree16c6577e652b0f7e7da7acf816b3264ee7072b2e /tools/load_gen
parent3b1253f1ef1f6719a120bb449a1d9174c0d8319d (diff)
loadgen: Affinitize Stressor-VM Threads.
This patch affinitizes stressor-vm threads. The code is reused from vnfs/qemu/qemu.py Change-Id: I4a525b133bf0799a06d0961379961cfcc89c357a Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Diffstat (limited to 'tools/load_gen')
-rw-r--r--tools/load_gen/stressorvm/stressor_vm.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/tools/load_gen/stressorvm/stressor_vm.py b/tools/load_gen/stressorvm/stressor_vm.py
index f4936743..82329d2b 100644
--- a/tools/load_gen/stressorvm/stressor_vm.py
+++ b/tools/load_gen/stressorvm/stressor_vm.py
@@ -16,8 +16,12 @@
Wrapper file to create and manage Stressor-VM as loadgen
"""
+import locale
import logging
import os
+import re
+import subprocess
+import time
from tools import tasks
from tools.load_gen.load_gen import ILoadGenerator
from conf import settings as S
@@ -90,8 +94,42 @@ class QemuVM(tasks.Process):
'Removing content of shared directory...', True)
self._running = False
+ def affinitize_nn(self):
+ """
+ Affinitize the SMP cores of a NN instance.
+ This function is same as the one in vnfs/qemu/qemu.py
+
+ :returns: None
+ """
+ thread_id = (r'.* CPU #%d: .* thread_id=(\d+)')
+ cur_locale = locale.getdefaultlocale()[1]
+ proc = subprocess.Popen(
+ ('echo', 'info cpus'), stdout=subprocess.PIPE)
+ while not os.path.exists(self._monitor):
+ time.sleep(1)
+ output = subprocess.check_output(
+ ('sudo', 'socat', '-', 'UNIX-CONNECT:%s' % self._monitor),
+ stdin=proc.stdout)
+ proc.wait()
+
+ # calculate the number of CPUs specified by NN_SMP
+ cpu_nr = int(S.getValue('NN_SMP')[self._number])
+ # pin each NN's core to host core based on configured BINDING
+ for cpu in range(0, cpu_nr):
+ match = None
+ guest_thread_binding = S.getValue('NN_CORE_BINDING')[self._number]
+ for line in output.decode(cur_locale).split('\n'):
+ match = re.search(thread_id % cpu, line)
+ if match:
+ self._affinitize_pid(guest_thread_binding[cpu],
+ match.group(1))
+ break
+ if not match:
+ self._logger.error('Failed to affinitize guest core #%d. Could'
+ ' not parse tid.', cpu)
+
-# pylint: disable=super-init-not-called
+# pylint: disable=super-init-not-called,unused-argument
class StressorVM(ILoadGenerator):
"""
Wrapper Class for Load-Generation through stressor-vm
@@ -107,6 +145,7 @@ class StressorVM(ILoadGenerator):
"""
for nvm in self.qvm_list:
nvm.start()
+ nvm.affinitize_nn()
def kill(self, signal='-9', sleep=2):
"""