From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <daniel@bowdernet.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 4783D71303
 for <pve-devel@lists.proxmox.com>; Wed,  8 Jun 2022 13:55:25 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 3F1057737
 for <pve-devel@lists.proxmox.com>; Wed,  8 Jun 2022 13:54:55 +0200 (CEST)
Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com
 [IPv6:2607:f8b0:4864:20::532])
 (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 81647772E
 for <pve-devel@lists.proxmox.com>; Wed,  8 Jun 2022 13:54:54 +0200 (CEST)
Received: by mail-pg1-x532.google.com with SMTP id q140so3610571pgq.6
 for <pve-devel@lists.proxmox.com>; Wed, 08 Jun 2022 04:54:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=bowdernet.com; s=google;
 h=from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding;
 bh=GasF4efsgcmNTX1CFksBul33vzg61lxIGw0TiNkye/I=;
 b=UwOpWXHE2KXgNtG4KPcluDaBbwPYhDShFbHYIZ/9krDhGbM5mXd1CJZ2z79/q9oOa8
 zm3mvkiHwKMSipQjbIECSuNrd/iKyhMvebuISW2z62IaoNrieJtBxMPlpQXMQ0Dsn2eI
 waVv597iMVJH3vcTDu24tNx2DVhPsLpwAbn9jhL05m/f3bqrDA0n5sIC0JQtVKpeYutJ
 X5gLqQYQYvQ5igA5gdBAmgFg7jANQlWiZoKlGZwpSrzuBR+QX6zjxCD1xBAo2+aPo3n0
 q5osyZH8MLA915Xu45IPnSM7HsjSHRB9Orc4BKOXKnvw1x74lz0xAIWogcvA9K0EX0Yl
 mtyw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references:mime-version:content-transfer-encoding;
 bh=GasF4efsgcmNTX1CFksBul33vzg61lxIGw0TiNkye/I=;
 b=4R3GaIF54gAXlwjGckl8hu8O3EbNkPluyVASAi9OmoorX7RDEgZEWnOVN/hAG4KPQd
 Pf4ygO+i/dNaYX2EBJR8dFFlCxwALBGK+pNRwWC/P7j3VXqf7jI7B2I7KYSFvCFDwR7V
 i69bMOXxxgrQW0wtU8ifaJ9hQxeBM04JcpIgwyDU5RMkFtnBgIJK9Ha/7XJkAZ1rLK+/
 EakdkoEvh+Yy3xIUu2RJfCwDWPyPU0/YeGKc/itdL6chSThgzYknT72yJNeb8tk4hNN0
 Rn5TUfIL7LRh39FvlNoLcMJwyS9sz0d6Ns9lk6vuYst8fkbt/BEpaZHOlHtKGsixUqwS
 zDBQ==
X-Gm-Message-State: AOAM530ufPx7gM1W/nz1+dYvEOk7tutqRNrbIsKhsCTeOrX8g42ryJCC
 FLENkXYGYSag10H9sqjooj9xOWOTbWPH4Ac8
X-Google-Smtp-Source: ABdhPJyekuvtM1qXROhH/twswdaNAImF7P7zKjyv91CK/MW7NhDb6urvJ56FnlPmG6LfeCwci3fJdQ==
X-Received: by 2002:a63:c00c:0:b0:3f6:103:5bc1 with SMTP id
 h12-20020a63c00c000000b003f601035bc1mr29725763pgg.404.1654689287069; 
 Wed, 08 Jun 2022 04:54:47 -0700 (PDT)
Received: from pve-dev.dbnet.in (c-24-19-168-226.hsd1.wa.comcast.net.
 [24.19.168.226]) by smtp.gmail.com with ESMTPSA id
 t6-20020a654b86000000b003fba6db1b50sm14902820pgq.85.2022.06.08.04.54.46
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 08 Jun 2022 04:54:46 -0700 (PDT)
From: Daniel Bowder <daniel@bowdernet.com>
To: pve-devel@lists.proxmox.com
Cc: Daniel Bowder <daniel@bowdernet.com>
Date: Wed,  8 Jun 2022 04:54:26 -0700
Message-Id: <20220608115428.250668-4-daniel@bowdernet.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220608115428.250668-1-daniel@bowdernet.com>
References: <20220608115428.250668-1-daniel@bowdernet.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
 RCVD_IN_DNSWL_NONE     -0.0001 Sender listed at https://www.dnswl.org/,
 no trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm, bowdernet.com]
X-Mailman-Approved-At: Wed, 08 Jun 2022 14:30:46 +0200
Subject: [pve-devel] [PATCH 3/5] fix #3593: Added vm core pinning qemu-server
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 08 Jun 2022 11:55:25 -0000

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