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 3/5] fix #3593: Added vm core pinning qemu-server
Date: Wed,  8 Jun 2022 04:54:26 -0700	[thread overview]
Message-ID: <20220608115428.250668-4-daniel@bowdernet.com> (raw)
In-Reply-To: <20220608115428.250668-1-daniel@bowdernet.com>

Signed-off-by: Daniel Bowder <daniel@bowdernet.com>
---
 The third patch adds cpuset as a valid object in the qm conf file. A new type is created called 'pve-cpuset' so that the cpuset can go through some validation before passing it to the taskset command. The exec_taskset command is executed just after the 'post-start' hookscript, which ensures that there is a valid PID to pin.
 PVE/QemuServer.pm | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e9aa248..6b9abc0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -713,6 +713,11 @@ EODESCR
 	description => "Some (read-only) meta-information about this guest.",
 	optional => 1,
     },
+	cpuset => {
+	type => 'string', format => 'pve-cpuset',
+	description => "Specifies the cpu core numbers to pin the vm qemu processes to with 'taskset'.",
+	optional => 1,
+	},
 };
 
 my $cicustom_fmt = {
@@ -5802,6 +5807,8 @@ sub vm_start_nolock {
 
     PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
 
+    PVE::GuestHelpers::exec_taskset($conf, $vmid);
+
     return $res;
 }
 
@@ -8214,4 +8221,46 @@ sub check_volume_storage_type {
     return 1;
 }
 
+sub parse_cpuset {
+    my ($data) = @_;
+
+    my $res = "";
+
+	# Parse cpuset value
+	foreach my $value (PVE::Tools::split_list($data)) {
+		if ($value =~ m/^([0-9]+)-([0-9]+)$/) {
+			if (int($1) > int($2)) {
+				die "invalid cpuset value '$value', left value must be <= right\n";
+			}
+			my @range = (int($1) .. int($2));
+			for my $cpu (@range) {
+				$res .= "," . $cpu;
+			}
+		} elsif ($value =~ m/^([0-9]+)$/) {
+			$res .= "," . $1;
+		} else {
+			die "invalid cpuset value '$value'\n";
+		}
+	}
+
+	if (!$res) {
+		die "invalid cpuset '$data'\n";
+	}
+
+	# Trim leading ","
+    $res = substr($res, 1);
+    return $res;
+}
+
+PVE::JSONSchema::register_format('pve-cpuset', \&pve_verify_cpuset);
+sub pve_verify_cpuset {
+    my ($value, $noerr) = @_;
+
+    return $value if parse_cpuset($value);
+
+    return if $noerr;
+
+    die "unable to parse cpuset option\n";
+}
+
 1;
-- 
2.30.2




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

Thread overview: 14+ 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 ` [pve-devel] [PATCH 2/5] fix #3593: Added vm core pinning pve-guest-common Daniel Bowder
2022-06-08 11:54 ` Daniel Bowder [this message]
2022-06-08 14:45   ` [pve-devel] [PATCH 3/5] fix #3593: Added vm core pinning qemu-server 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
2022-06-09 15:46 [pve-devel] [PATCH 3/5] fix #3593: Added vm core pinning qemu-server 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-4-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