]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CpuSet.pm
CpuSet short_string - avoid ranges like 0-0, 1-1, 2-2, ...
[pve-common.git] / src / PVE / CpuSet.pm
index 4004bb3bab1a620f137068f279e03982447bf77e..483405e194f2f35963a6480c7c049648d508ac85 100644 (file)
@@ -3,8 +3,20 @@ package PVE::CpuSet;
 use strict;
 use warnings;
 use PVE::Tools;
+use PVE::ProcFSTools;
 
-our $MAX_CPUID = 256; # should be enough for the next years
+my $MAX_CPUID;
+
+sub max_cpuid {
+
+    return $MAX_CPUID if defined($MAX_CPUID);
+
+    my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
+
+    $MAX_CPUID = $cpuinfo->{cpus} || 1;
+
+    return $MAX_CPUID;
+}
 
 sub new {
     my ($this) = @_;
@@ -12,7 +24,9 @@ sub new {
     my $class = ref($this) || $this;
 
     my $self = bless { members => {} }, $class;
-
+    
+    max_cpuid() if !defined($MAX_CPUID); # initialize $MAX_CPUID
+    
     return $self;
 }
 
@@ -150,8 +164,12 @@ sub short_string {
            $next = $cpu;
        } else {
            $res .= ',' if length($res);
-           $res .= "$last-$next";
-           $last = $next = undef;
+           if ($last != $next) {
+               $res .= "$last-$next";
+           } else {
+               $res .= "$last";
+           }
+           $last = $next = $cpu;
        }
     }