mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 05:31:32 +00:00
feature(krata): first pass on cpu hotplug support (#340)
* fix(runtime): adjust memory resources inside a transaction * feature(krata): first pass on cpu hotplug support
This commit is contained in:
@ -30,7 +30,8 @@ pub struct ZoneLaunchRequest {
|
||||
pub initrd: Vec<u8>,
|
||||
pub uuid: Option<Uuid>,
|
||||
pub name: Option<String>,
|
||||
pub cpus: u32,
|
||||
pub target_cpus: u32,
|
||||
pub max_cpus: u32,
|
||||
pub target_memory: u64,
|
||||
pub max_memory: u64,
|
||||
pub env: HashMap<String, String>,
|
||||
@ -195,7 +196,8 @@ impl ZoneLauncher {
|
||||
|
||||
let config = DomainConfig {
|
||||
base: BaseDomainConfig {
|
||||
max_vcpus: request.cpus,
|
||||
max_vcpus: request.max_cpus,
|
||||
target_vcpus: request.target_cpus,
|
||||
max_mem_mb: request.max_memory,
|
||||
target_mem_mb: request.target_memory,
|
||||
kernel: request.kernel,
|
||||
|
@ -1,11 +1,11 @@
|
||||
use std::{fs, path::PathBuf, str::FromStr, sync::Arc};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use krataloopdev::LoopControl;
|
||||
use std::{fs, path::PathBuf, str::FromStr, sync::Arc};
|
||||
use tokio::sync::Semaphore;
|
||||
use uuid::Uuid;
|
||||
|
||||
use xenclient::XenClient;
|
||||
use xenplatform::domain::XEN_EXTRA_MEMORY_KB;
|
||||
use xenstore::{XsdClient, XsdInterface};
|
||||
|
||||
use self::{
|
||||
@ -226,33 +226,62 @@ impl Runtime {
|
||||
Ok(uuid)
|
||||
}
|
||||
|
||||
pub async fn set_max_memory(&self, domid: u32, max_memory_bytes: u64) -> Result<()> {
|
||||
pub async fn set_memory_resources(
|
||||
&self,
|
||||
domid: u32,
|
||||
target_memory_bytes: u64,
|
||||
max_memory_bytes: u64,
|
||||
) -> Result<()> {
|
||||
let mut max_memory_bytes = max_memory_bytes + (XEN_EXTRA_MEMORY_KB * 1024);
|
||||
if target_memory_bytes > max_memory_bytes {
|
||||
max_memory_bytes = target_memory_bytes + (XEN_EXTRA_MEMORY_KB * 1024);
|
||||
}
|
||||
|
||||
self.context
|
||||
.xen
|
||||
.call
|
||||
.set_max_mem(domid, max_memory_bytes / 1024)
|
||||
.await?;
|
||||
let domain_path = self.context.xen.store.get_domain_path(domid).await?;
|
||||
let tx = self.context.xen.store.transaction().await?;
|
||||
let max_memory_path = format!("{}/memory/static-max", domain_path);
|
||||
self.context
|
||||
.xen
|
||||
.store
|
||||
.write_string(max_memory_path, &(max_memory_bytes / 1024).to_string())
|
||||
tx.write_string(max_memory_path, &(max_memory_bytes / 1024).to_string())
|
||||
.await?;
|
||||
let target_memory_path = format!("{}/memory/target", domain_path);
|
||||
tx.write_string(
|
||||
target_memory_path,
|
||||
&(target_memory_bytes / 1024).to_string(),
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_target_memory(&self, domid: u32, target_memory_bytes: u64) -> Result<()> {
|
||||
pub async fn set_cpu_resources(&self, domid: u32, target_cpus: u32) -> Result<()> {
|
||||
let domain_path = self.context.xen.store.get_domain_path(domid).await?;
|
||||
let target_memory_path = format!("{}/memory/target", domain_path);
|
||||
self.context
|
||||
let cpus = self
|
||||
.context
|
||||
.xen
|
||||
.store
|
||||
.write_string(
|
||||
target_memory_path,
|
||||
&(target_memory_bytes / 1024).to_string(),
|
||||
.list(&format!("{}/cpu", domain_path))
|
||||
.await?;
|
||||
let tx = self.context.xen.store.transaction().await?;
|
||||
for cpu in cpus {
|
||||
let Some(id) = cpu.parse::<u32>().ok() else {
|
||||
continue;
|
||||
};
|
||||
let available = if id >= target_cpus {
|
||||
"offline"
|
||||
} else {
|
||||
"online"
|
||||
};
|
||||
tx.write_string(
|
||||
format!("{}/cpu/{}/availability", domain_path, id),
|
||||
available,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user