1)Support pin VM's thread to vhost CPU lcore.
2)Fix add_vm_daemon method issue.
Signed-off-by: Wei Ling <weix.ling@intel.com>
---
framework/qemu_kvm.py | 50 ++++++++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 13 deletions(-)
@@ -1241,7 +1241,7 @@ class QEMUKvm(VirtBase):
By default VM will start with the daemonize status.
Not support starting it on the stdin now.
"""
- if "daemon" in list(options.keys()) and options["enable"] == "no":
+ if "enable" in list(options.keys()) and options["enable"] == "no":
pass
else:
daemon_boot_line = "-daemonize"
@@ -1365,7 +1365,7 @@ class QEMUKvm(VirtBase):
self.migrate_port = int(m.group(1))
- def _start_vm(self):
+ def _start_vm(self, pin_threads=True):
"""
Start VM.
"""
@@ -1377,6 +1377,11 @@ class QEMUKvm(VirtBase):
self.__get_pci_mapping()
+ # pin VM threads with host CPU cores
+ if pin_threads:
+ lcores = self.vcpus_pinned_to_vm.split(" ")
+ self.pin_threads(lcores=lcores)
+
# query status
self.update_status()
@@ -1385,7 +1390,7 @@ class QEMUKvm(VirtBase):
# when vm is waiting for migration, can't ping
if self.vm_status is not ST_PAUSE:
- self.__wait_vm_ready()
+ self.__wait_vm_ready(pin_threads=pin_threads)
self.__wait_vmnet_ready()
@@ -1445,7 +1450,7 @@ class QEMUKvm(VirtBase):
return logged_in
- def __wait_vm_ready(self):
+ def __wait_vm_ready(self, pin_threads=True):
logged_in = self.__ping_vm()
if not logged_in:
if not self.restarted:
@@ -1454,7 +1459,7 @@ class QEMUKvm(VirtBase):
self.vm_status = ST_NOTSTART
self._stop_vm()
self.restarted = True
- self._start_vm()
+ self._start_vm(pin_threads=pin_threads)
else:
raise StartVMFailedException(
"Not response in %d seconds!!!" % self.START_TIMEOUT
@@ -2003,14 +2008,33 @@ class QEMUKvm(VirtBase):
def pin_threads(self, lcores):
"""
- Pin thread to assigned cores
+ Pin thread to assigned cores.
+ If threads <= lcores, like: threads=[427756, 427757], lcores=[48, 49, 50]:
+ taskset -pc 48 427756
+ taskset -pc 49 427757
+
+ If threads > lcores, like threads=[427756, 427757, 427758, 427759, 427760], lcores=[48,49,50]
+ taskset -pc 48 427756
+ taskset -pc 49 427757
+ taskset -pc 50 427758
+ taskset -pc 48 427759
+ taskset -pc 49 427760
"""
- thread_reg = r"CPU #(\d+): .* thread_id=(\d+)"
+ thread_reg = r"CPU #\d+: thread_id=(\d+)"
output = self.__monitor_session("info", "cpus")
- thread_cores = re.findall(thread_reg, output)
- cores_map = list(zip(thread_cores, lcores))
- for thread_info, core_id in cores_map:
- cpu_id, thread_id = thread_info
- self.host_session.send_expect(
- "taskset -pc %d %s" % (core_id, thread_id), "#"
+ threads = re.findall(thread_reg, output)
+ if len(threads) <= len(lcores):
+ map = list(zip(threads, lcores))
+ else:
+ self.host_logger.warning(
+ "lcores is less than threads, please check the 'number' and 'cpupin' config."
)
+ lcore_len = len(lcores)
+ for item in threads:
+ thread_idx = threads.index(item)
+ if thread_idx >= lcore_len:
+ lcore_idx = thread_idx % lcore_len
+ lcores.append(lcores[lcore_idx])
+ map = list(zip(threads, lcores))
+ for thread, lcore in map:
+ self.host_session.send_expect("taskset -pc %s %s" % (lcore, thread), "#")