public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Elias Huhsovitz <e.huhsovitz@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Elias Huhsovitz <e.huhsovitz@proxmox.com>
Subject: [PATCH proxmox-perl-rs v4 2/4] pve: cpu: add binding for pve-qemu-server-cpu crate
Date: Wed, 11 Nov 2026 16:20:25 +0100	[thread overview]
Message-ID: <20261111152027.260117-3-e.huhsovitz@proxmox.com> (raw)
In-Reply-To: <20261111152027.260117-1-e.huhsovitz@proxmox.com>

Expose the pve-qemu-server-cpu crate to Perl as PVE::RS::CPU::Bind. Two
functions are exported: (1) gen_vcpu_bindings: generate a binding map
that specifies the scheduler's affinity for each vCPU. (2) bind_vcpus:
given a binding map, uses set_schedaffinity(2) to set the scheduler's
affinity for each vCPU specified.

Add pve-qemu-server-cpu as a path dependency of pve-rs. The crate is
packaged as librust-pve-qemu-server-cpu-dev.

Originally-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Elias Huhsovitz <e.huhsovitz@proxmox.com>
---
 pve-rs/Cargo.toml               |  1 +
 pve-rs/Makefile                 |  1 +
 pve-rs/src/bindings/cpu/bind.rs | 42 +++++++++++++++++++++++++++++++++
 pve-rs/src/bindings/cpu/mod.rs  |  2 ++
 pve-rs/src/bindings/mod.rs      |  3 +++
 5 files changed, 49 insertions(+)
 create mode 100644 pve-rs/src/bindings/cpu/bind.rs
 create mode 100644 pve-rs/src/bindings/cpu/mod.rs

diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index d728dcd..994bbfb 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -53,6 +53,7 @@ proxmox-tfa = { version = "6.0.3", features = ["api"] }
 proxmox-time = "2"
 proxmox-ve-config = { version = "0.11.0", features = [ "frr" ] }
 proxmox-wireguard = { version = "0.1.2" }
+pve-qemu-server-cpu = "0.1"
 pve-qemu-server-pci = "0.1"
 
 # [patch.crates-io]
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index be0284d..3322023 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -26,6 +26,7 @@ PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \
 	--include-file=Fixup.pm
 
 PERLMOD_PACKAGES := \
+	  PVE::RS::CPU::Bind \
 	  PVE::RS::Firewall::SDN \
 	  PVE::RS::Notify \
 	  PVE::RS::NVML \
diff --git a/pve-rs/src/bindings/cpu/bind.rs b/pve-rs/src/bindings/cpu/bind.rs
new file mode 100644
index 0000000..b24b524
--- /dev/null
+++ b/pve-rs/src/bindings/cpu/bind.rs
@@ -0,0 +1,42 @@
+#[perlmod::package(name = "PVE::RS::CPU::Bind", lib = "pve_rs")]
+pub mod pve_rs_cpu_bind {
+    //! `PVE::RS::CPU::Bind` package.
+    //!
+    //! Exposes the vCPU binding entry points.
+    //! from [`pve_qemu_server_cpu`].
+
+    use anyhow::{Error, format_err};
+
+    /// Validate a `cpu-bind-map` for the given mode before the VM starts.
+    ///
+    /// `binding_info` is the raw config value (`cpu-bind-map`,
+    /// `cpu-binding-list`, `numa-binding-map`, or `numa-binding-list`,
+    /// depending on `mode`). Returns `Ok(())` on success; on error, the
+    /// returned string is suitable for `die` in Perl.
+
+    /// Generate a vCPU:host cpu(s) bindinbg map for a guest.
+    ///
+    /// Validates if the config is valid and returns the binding map as a JSON
+    /// encoded string.
+    #[export]
+    pub fn gen_vcpu_bindings(
+        mode: &str,
+        sockets: u32,
+        cores: u32,
+        affinity: &str,
+        cfg_json: &str,
+    ) -> Result<String, Error> {
+        pve_qemu_server_cpu::gen_vcpu_bindings(mode, sockets, cores, affinity, cfg_json)
+            .map_err(|e| format_err!("{e}"))
+    }
+
+    /// Apply the binding to a running VM.
+    ///
+    /// `cpuinfo_json` must be the JSON-encoded `query-cpus-fast` QMP
+    /// response.
+    #[export]
+    pub fn bind_vcpus(bind_map_json: &str, qmp_cpuinfo_json: &str) -> Result<(), Error> {
+        pve_qemu_server_cpu::bind_vcpus(bind_map_json, qmp_cpuinfo_json)
+            .map_err(|e| format_err!("{e}"))
+    }
+}
diff --git a/pve-rs/src/bindings/cpu/mod.rs b/pve-rs/src/bindings/cpu/mod.rs
new file mode 100644
index 0000000..3dd4427
--- /dev/null
+++ b/pve-rs/src/bindings/cpu/mod.rs
@@ -0,0 +1,2 @@
+mod bind;
+pub use bind::pve_rs_cpu_bind;
diff --git a/pve-rs/src/bindings/mod.rs b/pve-rs/src/bindings/mod.rs
index 9afcd4a..71b666e 100644
--- a/pve-rs/src/bindings/mod.rs
+++ b/pve-rs/src/bindings/mod.rs
@@ -1,5 +1,8 @@
 //! This contains all the perl bindings.
 
+mod cpu;
+pub use cpu::pve_rs_cpu_bind;
+
 mod nvml;
 pub use nvml::pve_rs_nvml;
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-11 15:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 15:20 [RFC proxmox-perl-rs/qemu-server/qemu-server-rs v4 0/4] vCPU binding for qemu guests Elias Huhsovitz
2026-11-11 15:20 ` [PATCH qemu-server-rs v4 1/4] cpu: add pve-qemu-server-cpu crate for vCPU binding Elias Huhsovitz
2026-11-11 15:20 ` Elias Huhsovitz [this message]
2026-11-11 15:20 ` [PATCH qemu-server v4 3/4] helpers: return integer values for parse_number_sets Elias Huhsovitz
2026-11-11 15:20 ` [PATCH qemu-server v4 4/4] cpu: add cpu binding Elias Huhsovitz

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=20261111152027.260117-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal