public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Bowder <daniel@bowdernet.com>
To: pve-devel@lists.proxmox.com
Cc: Daniel Bowder <daniel@bowdernet.com>
Subject: [pve-devel] [PATCH 2/5] fix #3593: Added vm core pinning pve-guest-common
Date: Wed,  8 Jun 2022 04:54:25 -0700	[thread overview]
Message-ID: <20220608115428.250668-3-daniel@bowdernet.com> (raw)
In-Reply-To: <20220608115428.250668-1-daniel@bowdernet.com>

Signed-off-by: Daniel Bowder <daniel@bowdernet.com>
---
 The second patch adds a utility function to obtain the pid of the VM, then calls taskset on that pid with the cpuset in the qm conf. This execution of taskset pins the VMs process to the defined cpu cores. This utility function acts similarly to the exec_hookscript utility function. In fact, in the third patch this utility function will be called just after the "post-start" call to hookscript.
 src/PVE/GuestHelpers.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
index 0fe3fd6..a8f54fa 100644
--- a/src/PVE/GuestHelpers.pm
+++ b/src/PVE/GuestHelpers.pm
@@ -82,6 +82,30 @@ sub guest_migration_lock {
     return $res;
 }
 
+sub exec_taskset {
+	my ($conf, $vmid) = @_;
+
+	return if !$conf->{cpuset};
+
+	eval {
+		# Obtain the vm PID from /run/qemu-server/$vmid.pid
+		PVE::Tools::run_command(
+			[ "cat", "/run/qemu-server/$vmid.pid" ],
+			outfunc => sub {
+				my $line = shift;
+				if ($line =~ m/^([0-9]+)$/) {
+					# Pin the PID to the cpuset
+					PVE::Tools::run_command(
+						[ "taskset", "--cpu-list", "--all-tasks", "--pid", $conf->{cpuset}, $1 ]
+					);
+				} else {
+					warn "cpuset error: failed to obtain vm process id.\n";
+				}
+			}
+		);
+	};
+}
+
 sub check_hookscript {
     my ($volid, $storecfg) = @_;
 
-- 
2.30.2




  parent reply	other threads:[~2022-06-08 11:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 11:54 [pve-devel] [PATCH 0/5] fix #3593: Added vm core pinning Daniel Bowder
2022-06-08 11:54 ` [pve-devel] [PATCH 1/5] fix #3593: Added vm core pinning pve-docs Daniel Bowder
2022-06-08 14:20   ` Matthias Heiserer
2022-06-08 11:54 ` Daniel Bowder [this message]
2022-06-08 11:54 ` [pve-devel] [PATCH 3/5] fix #3593: Added vm core pinning qemu-server Daniel Bowder
2022-06-08 14:45   ` Matthias Heiserer
2022-06-08 11:54 ` [pve-devel] [PATCH 4/5] fix #3593: Added vm core pinning proxmox-widget-toolkit Daniel Bowder
2022-06-08 11:54 ` [pve-devel] [PATCH 5/5] fix #3593: Added vm core pinning pve-manager Daniel Bowder
2022-06-08 14:39   ` Matthias Heiserer
2022-06-08 13:00 ` [pve-devel] [PATCH 0/5] fix #3593: Added vm core pinning Matthias Heiserer
2022-06-08 13:21   ` Daniel Bowder
2022-06-08 13:32     ` Matthias Heiserer
2022-06-08 13:43       ` Daniel Bowder

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=20220608115428.250668-3-daniel@bowdernet.com \
    --to=daniel@bowdernet.com \
    --cc=pve-devel@lists.proxmox.com \
    /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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal