From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8FE3A1FF137 for ; Tue, 17 Feb 2026 15:15:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0B1DD3436; Tue, 17 Feb 2026 15:15:18 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [RFC proxmox 5/5] resource-scheduling: implement Add and Default for {Dynamic,Static}ServiceStats Date: Tue, 17 Feb 2026 15:13:59 +0100 Message-ID: <20260217141437.584852-6-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217141437.584852-1-d.kral@proxmox.com> References: <20260217141437.584852-1-d.kral@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1771337676258 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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: W3RQRLLJJW5WH7265T4T4R6JQRSL46CU X-Message-ID-Hash: W3RQRLLJJW5WH7265T4T4R6JQRSL46CU X-MailFrom: d.kral@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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This allows for more elegant code to aggregate multiple {Dynamic,Static}ServiceStats, e.g., for building service bundles. Signed-off-by: Daniel Kral --- proxmox-resource-scheduling/src/pve_dynamic.rs | 17 ++++++++++++++++- proxmox-resource-scheduling/src/pve_static.rs | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/proxmox-resource-scheduling/src/pve_dynamic.rs b/proxmox-resource-scheduling/src/pve_dynamic.rs index 4f480612..21a15e81 100644 --- a/proxmox-resource-scheduling/src/pve_dynamic.rs +++ b/proxmox-resource-scheduling/src/pve_dynamic.rs @@ -1,8 +1,10 @@ use serde::{Deserialize, Serialize}; +use std::ops::Add; + use crate::scheduler::{NodeStats, ServiceStats}; -#[derive(Clone, Copy, Serialize, Deserialize)] +#[derive(Clone, Copy, Default, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// Dynamic usage stats of a node. pub struct DynamicNodeStats { @@ -51,3 +53,16 @@ impl From for ServiceStats { } } } + +impl Add for DynamicServiceStats { + type Output = Self; + + fn add(self, rhs: Self) -> Self { + Self { + cpu: self.cpu + rhs.cpu, + maxcpu: self.maxcpu + rhs.maxcpu, + mem: self.mem + rhs.mem, + maxmem: self.maxmem + rhs.maxmem, + } + } +} diff --git a/proxmox-resource-scheduling/src/pve_static.rs b/proxmox-resource-scheduling/src/pve_static.rs index b269c44f..c96da100 100644 --- a/proxmox-resource-scheduling/src/pve_static.rs +++ b/proxmox-resource-scheduling/src/pve_static.rs @@ -1,6 +1,8 @@ use anyhow::Error; use serde::{Deserialize, Serialize}; +use std::ops::Add; + use crate::scheduler::{ClusterUsage, NodeStats, NodeUsage, ServiceStats}; #[derive(Clone, Serialize, Deserialize)] @@ -59,7 +61,7 @@ fn add_cpu_usage(old: f64, max: f64, add: f64) -> f64 { } } -#[derive(Clone, Copy, Serialize, Deserialize)] +#[derive(Clone, Copy, Default, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// Static usage information of an HA resource. pub struct StaticServiceUsage { @@ -80,6 +82,17 @@ impl From for ServiceStats { } } +impl Add for StaticServiceUsage { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self { + maxcpu: self.maxcpu + rhs.maxcpu, + maxmem: self.maxmem + rhs.maxmem, + } + } +} + /// Scores candidate `nodes` to start a `service` on. Scoring is done according to the static memory /// and CPU usages of the nodes as if the service would already be running on each. /// -- 2.47.3