From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 0E0E91FF066 for ; Tue, 24 Nov 2026 14:19:18 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3A9C8215FA; Tue, 24 Nov 2026 14:19:15 +0100 (CET) From: Elias Huhsovitz To: pve-devel@lists.proxmox.com Subject: [PATCH common v5 4/4] cpuset: generalize to improve usability for sysfs cpusets. Date: Tue, 24 Nov 2026 14:18:58 +0100 Message-ID: <20261124131858.135785-5-e.huhsovitz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124131858.135785-1-e.huhsovitz@proxmox.com> References: <20261124131858.135785-1-e.huhsovitz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795526351416 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.398 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SOKVDJOAQBQRNQCILILO5WP4HYV4MMIW X-Message-ID-Hash: SOKVDJOAQBQRNQCILILO5WP4HYV4MMIW X-MailFrom: e.huhsovitz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Elias Huhsovitz X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add from_str/from_path to create cpuset directly from string/path. Utilize from_path in existing new_from_path subroutine. Add intersect between two CpuSet. Add member_keys to get a list of all unsorted members. Remove redundant for loop in is_equal by adding guard clause that compares set sizes. Signed-off-by: Elias Huhsovitz --- src/PVE/CpuSet.pm | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index 7023b8f..1f6de4c 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -15,6 +15,18 @@ sub new { return $self; } +sub from_str { + my ($class, $s) = @_; + my (undef, $members) = PVE::CpuSet::parse_cpuset($s); + return $class->new($members); +} + +sub from_path { + my ($class, $path) = @_; + my $content = PVE::File::file_read_first_line($path) // ''; + return $class->from_str($content); +} + # Create a new set with the contents of a cgroup-v1 subdirectory. # Deprecated: sub new_from_cgroup { @@ -24,7 +36,7 @@ sub new_from_cgroup { } # Create a new set from the contents of a complete path to a cgroup directory. -sub new_from_path { +sub new_from_path { # TODO: naming is inaccurate and should be changed to e.g. 'from_cgroup_path' my ($class, $path, $effective) = @_; my $filename; @@ -38,11 +50,7 @@ sub new_from_path { $filename = "$path/cpuset.cpus"; } - my $set_text = PVE::File::file_read_first_line($filename) // ''; - - my ($count, $members) = parse_cpuset($set_text); - - return $class->new($members); + return $class->from_path($filename); } sub parse_cpuset { @@ -122,6 +130,16 @@ sub delete { return $count; } +sub intersect { + my ($self, $other) = @_; + + my $res = __PACKAGE__->new(); + for my $cpu (keys $self->{members}->%*) { + $res->insert($cpu) if $other->has($cpu); + } + return $res; +} + sub has { my ($self, $cpuid) = @_; @@ -136,6 +154,11 @@ sub members { return @sorted_members; } +sub member_keys { + my ($self) = @_; + return keys %{ $self->{members} }; +} + sub size { my ($self) = @_; @@ -148,11 +171,10 @@ sub is_equal { my $members1 = $self->{members}; my $members2 = $set2->{members}; + return 0 if keys(%$members1) != keys(%$members2); + foreach my $id (keys %$members1) { - return 0 if !$members2->{$id}; - } - foreach my $id (keys %$members2) { - return 0 if !$members1->{$id}; + return 0 if !exists $members2->{$id}; } return 1; -- 2.47.3