vmm: store CPU affinity lists as slices

Each affinity host CPU list is copied from configuration.
It is only iterated afterwards, so a boxed slice is enough.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
This commit is contained in:
Philipp Schuster
2026-05-14 11:04:19 +02:00
committed by Rob Bradford
parent 74392eccae
commit 29e2319247
3 changed files with 8 additions and 8 deletions

View File

@@ -719,7 +719,7 @@ impl CpusConfig {
v.0.iter() v.0.iter()
.map(|(e1, e2)| CpuAffinity { .map(|(e1, e2)| CpuAffinity {
vcpu: *e1, vcpu: *e1,
host_cpus: e2.clone(), host_cpus: e2.clone().into_boxed_slice(),
}) })
.collect() .collect()
}); });
@@ -3694,16 +3694,16 @@ mod unit_tests {
CpusConfig { CpusConfig {
boot_vcpus: 2, boot_vcpus: 2,
max_vcpus: 2, max_vcpus: 2,
affinity: Some(vec![ affinity: Some(Box::new([
CpuAffinity { CpuAffinity {
vcpu: 0, vcpu: 0,
host_cpus: vec![0, 2], host_cpus: Box::new([0, 2]),
}, },
CpuAffinity { CpuAffinity {
vcpu: 1, vcpu: 1,
host_cpus: vec![1, 3], host_cpus: Box::new([1, 3]),
} }
]), ])),
..Default::default() ..Default::default()
}, },
); );

View File

@@ -716,7 +716,7 @@ pub struct CpuManager {
#[cfg_attr(target_arch = "aarch64", allow(dead_code))] #[cfg_attr(target_arch = "aarch64", allow(dead_code))]
acpi_address: Option<GuestAddress>, acpi_address: Option<GuestAddress>,
proximity_domain_per_cpu: BTreeMap<u32, u32>, proximity_domain_per_cpu: BTreeMap<u32, u32>,
affinity: BTreeMap<u32, Vec<usize>>, affinity: BTreeMap<u32, Box<[usize]>>,
dynamic: bool, dynamic: bool,
hypervisor: Arc<dyn hypervisor::Hypervisor>, hypervisor: Arc<dyn hypervisor::Hypervisor>,
#[cfg(feature = "sev_snp")] #[cfg(feature = "sev_snp")]

View File

@@ -30,7 +30,7 @@ pub(crate) trait ApplyLandlock {
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct CpuAffinity { pub struct CpuAffinity {
pub vcpu: u32, pub vcpu: u32,
pub host_cpus: Vec<usize>, pub host_cpus: Box<[usize]>,
} }
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
@@ -76,7 +76,7 @@ pub struct CpusConfig {
#[serde(default = "default_cpuconfig_max_phys_bits")] #[serde(default = "default_cpuconfig_max_phys_bits")]
pub max_phys_bits: u8, pub max_phys_bits: u8,
#[serde(default)] #[serde(default)]
pub affinity: Option<Vec<CpuAffinity>>, pub affinity: Option<Box<[CpuAffinity]>>,
#[serde(default)] #[serde(default)]
pub features: CpuFeatures, pub features: CpuFeatures,
#[serde(default = "default_cpusconfig_nested")] #[serde(default = "default_cpusconfig_nested")]