test suite reviews and discussions
 help / color / mirror / Atom feed
From: Wei Ling <weix.ling@intel.com>
To: dts@dpdk.org
Cc: Wei Ling <weix.ling@intel.com>
Subject: [dts][PATCH V7] framework/qemu_kvm: pin VM's threads to vhost CPU lcore
Date: Thu, 22 Dec 2022 09:48:38 +0800	[thread overview]
Message-ID: <20221222014838.173362-1-weix.ling@intel.com> (raw)

1)Pin VM's threads to vhost CPU lcore after start VM.
2)Fix add_vm_daemon method issue.
3)Modify the pin_threads() to pin the VM's threads to vhost CPU lcores.

Signed-off-by: Wei Ling <weix.ling@intel.com>
---
 framework/qemu_kvm.py | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/framework/qemu_kvm.py b/framework/qemu_kvm.py
index 20aa8008..dd8e7857 100644
--- a/framework/qemu_kvm.py
+++ b/framework/qemu_kvm.py
@@ -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"
@@ -1377,6 +1377,10 @@ class QEMUKvm(VirtBase):
 
         self.__get_pci_mapping()
 
+        # pin VM threads with host CPU cores
+        lcores = self.vcpus_pinned_to_vm.split(" ")
+        self.pin_threads(lcores=lcores)
+
         # query status
         self.update_status()
 
@@ -2004,13 +2008,32 @@ class QEMUKvm(VirtBase):
     def pin_threads(self, lcores):
         """
         Pin thread to assigned cores
-        """
-        thread_reg = r"CPU #(\d+): .* thread_id=(\d+)"
+        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+)"
         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 VM's threads, 1 lcore will pin multiple VM's threads"
             )
+            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), "#")
-- 
2.25.1


             reply	other threads:[~2022-12-22  1:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22  1:48 Wei Ling [this message]
2022-12-22  8:26 ` lijuan.tu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221222014838.173362-1-weix.ling@intel.com \
    --to=weix.ling@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).