[pve-devel] [PATCH guest-common 1/1] helpers: move get_cpuunits helper from qemu-server

Fiona Ebner f.ebner at proxmox.com
Fri Oct 7 14:41:40 CEST 2022


while making it take the value directly instead of the config.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 src/PVE/GuestHelpers.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
index 0fe3fd6..f3a4202 100644
--- a/src/PVE/GuestHelpers.pm
+++ b/src/PVE/GuestHelpers.pm
@@ -3,6 +3,7 @@ package PVE::GuestHelpers;
 use strict;
 use warnings;
 
+use PVE::CGroup;
 use PVE::Tools;
 use PVE::Storage;
 
@@ -246,4 +247,19 @@ sub config_with_pending_array {
     return $res;
 }
 
+sub get_cpuunits {
+    my ($cpuunits) = @_;
+
+    my $is_cgroupv2 = PVE::CGroup::cgroup_mode() == 2;
+
+    return $is_cgroupv2 ? 100 : 1024 if !defined($cpuunits);
+
+    if ($is_cgroupv2) {
+	$cpuunits = 10000 if $cpuunits >= 10000; # v1 can be higher, so clamp v2 there
+    } else {
+	$cpuunits = 2 if $cpuunits < 2; # v2 can be lower, so clamp v1 there
+    }
+    return $cpuunits;
+}
+
 1;
-- 
2.30.2






More information about the pve-devel mailing list