mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +00:00
vmm: Update NUMA node distances internally
Based on the NumaConfig which now provides distance information, we can internally update the list of NUMA nodes with the exact distances they should be located from other nodes. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a5a29134ca
commit
9548e7e857
@ -67,6 +67,7 @@ struct HotPlugState {
|
|||||||
pub struct NumaNode {
|
pub struct NumaNode {
|
||||||
memory_regions: Vec<Arc<GuestRegionMmap>>,
|
memory_regions: Vec<Arc<GuestRegionMmap>>,
|
||||||
cpus: Vec<u8>,
|
cpus: Vec<u8>,
|
||||||
|
distances: BTreeMap<u32, u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumaNode {
|
impl NumaNode {
|
||||||
@ -81,6 +82,14 @@ impl NumaNode {
|
|||||||
pub fn cpus_mut(&mut self) -> &mut Vec<u8> {
|
pub fn cpus_mut(&mut self) -> &mut Vec<u8> {
|
||||||
&mut self.cpus
|
&mut self.cpus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn distances(&self) -> &BTreeMap<u32, u8> {
|
||||||
|
&self.distances
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn distances_mut(&mut self) -> &mut BTreeMap<u32, u8> {
|
||||||
|
&mut self.distances
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type NumaNodes = BTreeMap<u32, NumaNode>;
|
pub type NumaNodes = BTreeMap<u32, NumaNode>;
|
||||||
@ -366,6 +375,7 @@ impl MemoryManager {
|
|||||||
NumaNode {
|
NumaNode {
|
||||||
memory_regions: vec![region.clone()],
|
memory_regions: vec![region.clone()],
|
||||||
cpus: Vec::new(),
|
cpus: Vec::new(),
|
||||||
|
distances: BTreeMap::new(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,9 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Failed serializing into JSON
|
/// Failed serializing into JSON
|
||||||
SerializeJson(serde_json::Error),
|
SerializeJson(serde_json::Error),
|
||||||
|
|
||||||
|
/// Invalid configuration for NUMA.
|
||||||
|
InvalidNumaConfig,
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -339,12 +342,30 @@ impl Vm {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut mm = memory_manager.lock().unwrap();
|
let mut mm = memory_manager.lock().unwrap();
|
||||||
let numa_nodes = mm.numa_nodes_mut();
|
let numa_nodes = mm.numa_nodes_mut();
|
||||||
|
let existing_nodes: Vec<u32> = numa_nodes.keys().cloned().collect();
|
||||||
|
|
||||||
for config in configs.iter() {
|
for config in configs.iter() {
|
||||||
if let Some(cpus) = &config.cpus {
|
if let Some(node) = numa_nodes.get_mut(&config.id) {
|
||||||
if let Some(node) = numa_nodes.get_mut(&config.id) {
|
if let Some(cpus) = &config.cpus {
|
||||||
node.cpus_mut().extend(cpus);
|
node.cpus_mut().extend(cpus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(distances) = &config.distances {
|
||||||
|
for distance in distances.iter() {
|
||||||
|
let dest = distance.destination;
|
||||||
|
let dist = distance.distance;
|
||||||
|
|
||||||
|
if !existing_nodes.contains(&dest) {
|
||||||
|
error!("Unknown destination NUMA node {}", dest);
|
||||||
|
return Err(Error::InvalidNumaConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
node.distances_mut().insert(dest, dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error!("Unknown NUMA node {}", config.id);
|
||||||
|
return Err(Error::InvalidNumaConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user