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

View File

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

View File

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