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 5ACA01FF0B3 for ; Wed, 11 Nov 2026 16:21:18 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C368521681; Wed, 11 Nov 2026 16:21:07 +0100 (CET) From: Elias Huhsovitz To: pve-devel@lists.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 Message-ID: <20261111152027.260117-3-e.huhsovitz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261111152027.260117-1-e.huhsovitz@proxmox.com> References: <20261111152027.260117-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: 1794410459868 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.431 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: X7RZRKSI6GC763DTL6SDA77LRJN4WG7D X-Message-ID-Hash: X7RZRKSI6GC763DTL6SDA77LRJN4WG7D 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: 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 Signed-off-by: Elias Huhsovitz --- 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 { + 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