From: Elias Huhsovitz <e.huhsovitz@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Elias Huhsovitz <e.huhsovitz@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 [thread overview]
Message-ID: <20261124131858.135785-5-e.huhsovitz@proxmox.com> (raw)
In-Reply-To: <20261124131858.135785-1-e.huhsovitz@proxmox.com>
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 <e.huhsovitz@proxmox.com>
---
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
prev parent reply other threads:[~2026-11-24 13:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:18 [PATCH common/qemu-server v5 0/4] vCPU binding for qemu guests Elias Huhsovitz
2026-11-24 13:18 ` [PATCH qemu-server v5 1/4] helpers: return integer values for parse_number_sets Elias Huhsovitz
2026-11-24 13:18 ` [PATCH qemu-server v5 2/4] cpu: add cpu-binding Elias Huhsovitz
2026-11-24 13:18 ` [PATCH common v5 3/4] syscall: add sched_setaffinity Elias Huhsovitz
2026-11-24 13:18 ` Elias Huhsovitz [this message]
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=20261124131858.135785-5-e.huhsovitz@proxmox.com \
--to=e.huhsovitz@proxmox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.