Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump VCPU from u8 to u32 #6446

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/src/aarch64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub fn create_fdt<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::BuildHash
guest_mem: &GuestMemoryMmap,
cmdline: &str,
vcpu_mpidr: Vec<u64>,
vcpu_topology: Option<(u8, u8, u8)>,
vcpu_topology: Option<(u32, u32, u32)>,
device_info: &HashMap<(DeviceType, String), T, S>,
gic_device: &Arc<Mutex<dyn Vgic>>,
initrd: &Option<InitramfsConfig>,
Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn write_fdt_to_memory(fdt_final: Vec<u8>, guest_mem: &GuestMemoryMmap) -> R
fn create_cpu_nodes(
fdt: &mut FdtWriter,
vcpu_mpidr: &[u64],
vcpu_topology: Option<(u8, u8, u8)>,
vcpu_topology: Option<(u32, u32, u32)>,
numa_nodes: &NumaNodes,
) -> FdtWriterResult<()> {
// See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml.
Expand Down
2 changes: 1 addition & 1 deletion arch/src/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn configure_system<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::Bui
guest_mem: &GuestMemoryMmap,
cmdline: &str,
vcpu_mpidr: Vec<u64>,
vcpu_topology: Option<(u8, u8, u8)>,
vcpu_topology: Option<(u32, u32, u32)>,
device_info: &HashMap<(DeviceType, String), T, S>,
initrd: &Option<super::InitramfsConfig>,
pci_space_info: &[PciSpaceInfo],
Expand Down
2 changes: 1 addition & 1 deletion devices/src/gic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Gic {

impl Gic {
pub fn new(
vcpu_count: u8,
vcpu_count: u32,
interrupt_manager: Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
vm: Arc<dyn hypervisor::Vm>,
) -> Result<Gic> {
Expand Down
10 changes: 5 additions & 5 deletions docs/cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ to set vCPUs options for Cloud Hypervisor.

```rust
struct CpusConfig {
boot_vcpus: u8,
max_vcpus: u8,
boot_vcpus: u32,
max_vcpus: u32,
topology: Option<CpuTopology>,
kvm_hyperv: bool,
max_phys_bits: u8,
Expand Down Expand Up @@ -54,7 +54,7 @@ For instance, if booting the VM with 2 vCPUs and a maximum of 6 vCPUs, it means
up to 4 vCPUs can be added later at runtime by resizing the VM.

The value must be greater than or equal to the number of boot vCPUs.
The value is an unsigned integer of 8 bits.
The value is an unsigned integer of 32 bits.

By default this option takes the value of `boot`, meaning vCPU hotplug is not
expected and can't be performed.
Expand Down Expand Up @@ -148,7 +148,7 @@ The affinity is described through the following structure:

```rust
struct CpuAffinity {
vcpu: u8,
vcpu: u32,
host_cpus: Vec<u8>,
}
```
Expand All @@ -164,7 +164,7 @@ brackets attached to `@` define the list of host CPUs the vCPU is allowed to
run onto.

Multiple values can be provided to define each list. Each value is an unsigned
integer of 8 bits.
integer of 32 bits.

For instance, if one needs to run vCPU 0 on host CPUs from 0 to 4, the syntax
using `-` will help define a contiguous range with `affinity=0@[0-4]`. The
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/src/kvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl vm::Vm for KvmVm {
///
fn create_vcpu(
&self,
id: u8,
id: u32,
vm_ops: Option<Arc<dyn VmOps>>,
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
let fd = self
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/src/mshv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ impl vm::Vm for MshvVm {
///
fn create_vcpu(
&self,
id: u8,
id: u32,
vm_ops: Option<Arc<dyn VmOps>>,
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
let vcpu_fd = self
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub trait Vm: Send + Sync + Any {
/// Unregister an event that will, when signaled, trigger the `gsi` IRQ.
fn unregister_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()>;
/// Creates a new KVM vCPU file descriptor and maps the memory corresponding
fn create_vcpu(&self, id: u8, vm_ops: Option<Arc<dyn VmOps>>) -> Result<Arc<dyn Vcpu>>;
fn create_vcpu(&self, id: u32, vm_ops: Option<Arc<dyn VmOps>>) -> Result<Arc<dyn Vcpu>>;
#[cfg(target_arch = "aarch64")]
fn create_vgic(&self, config: VgicConfig) -> Result<Arc<Mutex<dyn Vgic>>>;

Expand Down
2 changes: 1 addition & 1 deletion performance-metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct PerformanceTestControl {
queue_size: Option<u32>,
net_control: Option<(bool, bool)>, // First bool is for RX(true)/TX(false), second bool is for bandwidth or PPS
fio_control: Option<(FioOps, bool)>, // Second parameter controls whether we want bandwidth or IOPS
num_boot_vcpus: Option<u8>,
num_boot_vcpus: Option<u32>,
}

impl fmt::Display for PerformanceTestControl {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ch-remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ fn resize_config(
memory: Option<&str>,
balloon: Option<&str>,
) -> Result<String, Error> {
let desired_vcpus: Option<u8> = if let Some(cpus) = cpus {
let desired_vcpus: Option<u32> = if let Some(cpus) = cpus {
Some(cpus.parse().map_err(Error::InvalidCpuCount)?)
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ fn remote_command_w_output(api_socket: &str, command: &str, arg: Option<&str>) -

fn resize_command(
api_socket: &str,
desired_vcpus: Option<u8>,
desired_vcpus: Option<u32>,
desired_ram: Option<usize>,
desired_balloon: Option<usize>,
event_file: Option<&str>,
Expand Down
4 changes: 2 additions & 2 deletions vmm/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub struct VmmPingResponse {

#[derive(Clone, Deserialize, Serialize, Default, Debug)]
pub struct VmResizeData {
pub desired_vcpus: Option<u8>,
pub desired_vcpus: Option<u32>,
pub desired_ram: Option<u64>,
pub desired_balloon: Option<u64>,
}
Expand Down Expand Up @@ -316,7 +316,7 @@ pub trait RequestHandler {

fn vm_resize(
&mut self,
desired_vcpus: Option<u8>,
desired_vcpus: Option<u32>,
desired_ram: Option<u64>,
desired_balloon: Option<u64>,
) -> Result<(), VmError>;
Expand Down
4 changes: 2 additions & 2 deletions vmm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ impl CpusConfig {
.add("features");
parser.parse(cpus).map_err(Error::ParseCpus)?;

let boot_vcpus: u8 = parser
let boot_vcpus: u32 = parser
.convert("boot")
.map_err(Error::ParseCpus)?
.unwrap_or(DEFAULT_VCPUS);
let max_vcpus: u8 = parser
let max_vcpus: u32 = parser
.convert("max")
.map_err(Error::ParseCpus)?
.unwrap_or(boot_vcpus);
Expand Down
38 changes: 19 additions & 19 deletions vmm/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ macro_rules! round_up {
pub struct Vcpu {
// The hypervisor abstracted CPU.
vcpu: Arc<dyn hypervisor::Vcpu>,
id: u8,
id: u32,
#[cfg(target_arch = "aarch64")]
mpidr: u64,
saved_state: Option<CpuState>,
Expand All @@ -340,7 +340,7 @@ impl Vcpu {
/// * `vm_ops` - Optional object for exit handling.
/// * `cpu_vendor` - CPU vendor as reported by __cpuid(0x0)
pub fn new(
id: u8,
id: u32,
apic_id: u8,
vm: &Arc<dyn hypervisor::Vm>,
vm_ops: Option<Arc<dyn VmOps>>,
Expand Down Expand Up @@ -779,7 +779,7 @@ impl CpuManager {
Ok(())
}

fn create_vcpu(&mut self, cpu_id: u8, snapshot: Option<Snapshot>) -> Result<Arc<Mutex<Vcpu>>> {
fn create_vcpu(&mut self, cpu_id: u32, snapshot: Option<Snapshot>) -> Result<Arc<Mutex<Vcpu>>> {
info!("Creating vCPU: cpu_id = {}", cpu_id);

#[cfg(target_arch = "x86_64")]
Expand All @@ -791,7 +791,7 @@ impl CpuManager {

let mut vcpu = Vcpu::new(
cpu_id,
x2apic_id as u8,
x2apic_id as u32,
&self.vm,
Some(self.vm_ops.clone()),
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -872,7 +872,7 @@ impl CpuManager {
/// Only create new vCPUs if there aren't any inactive ones to reuse
fn create_vcpus(
&mut self,
desired_vcpus: u8,
desired_vcpus: u32,
snapshot: Option<Snapshot>,
) -> Result<Vec<Arc<Mutex<Vcpu>>>> {
let mut vcpus: Vec<Arc<Mutex<Vcpu>>> = vec![];
Expand All @@ -889,7 +889,7 @@ impl CpuManager {
}

// Only create vCPUs in excess of all the allocated vCPUs.
for cpu_id in self.vcpus.len() as u8..desired_vcpus {
for cpu_id in self.vcpus.len() as u32..desired_vcpus {
vcpus.push(self.create_vcpu(
cpu_id,
// TODO: The special format of the CPU id can be removed once
Expand Down Expand Up @@ -927,7 +927,7 @@ impl CpuManager {
fn start_vcpu(
&mut self,
vcpu: Arc<Mutex<Vcpu>>,
vcpu_id: u8,
vcpu_id: u32,
vcpu_thread_barrier: Arc<Barrier>,
inserting: bool,
) -> Result<()> {
Expand Down Expand Up @@ -1187,7 +1187,7 @@ impl CpuManager {
/// Start up as many vCPUs threads as needed to reach `desired_vcpus`
fn activate_vcpus(
&mut self,
desired_vcpus: u8,
desired_vcpus: u32,
inserting: bool,
paused: Option<bool>,
) -> Result<()> {
Expand All @@ -1213,7 +1213,7 @@ impl CpuManager {

// This reuses any inactive vCPUs as well as any that were newly created
for vcpu_id in self.present_vcpus()..desired_vcpus {
let vcpu = Arc::clone(&self.vcpus[vcpu_id as usize]);
let vcpu = Arc::clone(&self.vcpus[vcpu_id as u32]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work - you can't subscript with u32. Did you run clippy over all the commits? (or better - set up the pre-commit hook from CONTRIBUTING.md to do it for you.)

self.start_vcpu(vcpu, vcpu_id, vcpu_thread_barrier.clone(), inserting)?;
}

Expand All @@ -1222,7 +1222,7 @@ impl CpuManager {
Ok(())
}

fn mark_vcpus_for_removal(&mut self, desired_vcpus: u8) {
fn mark_vcpus_for_removal(&mut self, desired_vcpus: u32) {
// Mark vCPUs for removal, actual removal happens on ejection
for cpu_id in desired_vcpus..self.present_vcpus() {
self.vcpu_states[usize::from(cpu_id)].removing = true;
Expand All @@ -1241,7 +1241,7 @@ impl CpuManager {
false
}

fn remove_vcpu(&mut self, cpu_id: u8) -> Result<()> {
fn remove_vcpu(&mut self, cpu_id: u32) -> Result<()> {
info!("Removing vCPU: cpu_id = {}", cpu_id);
let state = &mut self.vcpu_states[usize::from(cpu_id)];
state.kill.store(true, Ordering::SeqCst);
Expand Down Expand Up @@ -1271,15 +1271,15 @@ impl CpuManager {
}

pub fn start_restored_vcpus(&mut self) -> Result<()> {
self.activate_vcpus(self.vcpus.len() as u8, false, Some(true))
self.activate_vcpus(self.vcpus.len() as u32, false, Some(true))
.map_err(|e| {
Error::StartRestoreVcpu(anyhow!("Failed to start restored vCPUs: {:#?}", e))
})?;

Ok(())
}

pub fn resize(&mut self, desired_vcpus: u8) -> Result<bool> {
pub fn resize(&mut self, desired_vcpus: u32) -> Result<bool> {
if desired_vcpus.cmp(&self.present_vcpus()) == cmp::Ordering::Equal {
return Ok(false);
}
Expand Down Expand Up @@ -1348,11 +1348,11 @@ impl CpuManager {
Ok(())
}

pub fn boot_vcpus(&self) -> u8 {
pub fn boot_vcpus(&self) -> u32 {
self.config.boot_vcpus
}

pub fn max_vcpus(&self) -> u8 {
pub fn max_vcpus(&self) -> u32 {
self.config.max_vcpus
}

Expand All @@ -1362,10 +1362,10 @@ impl CpuManager {
self.cpuid.clone()
}

fn present_vcpus(&self) -> u8 {
fn present_vcpus(&self) -> u32 {
self.vcpu_states
.iter()
.fold(0, |acc, state| acc + state.active() as u8)
.fold(0, |acc, state| acc + state.active() as u32)
}

#[cfg(target_arch = "aarch64")]
Expand All @@ -1384,7 +1384,7 @@ impl CpuManager {
.collect()
}

pub fn get_vcpu_topology(&self) -> Option<(u8, u8, u8)> {
pub fn get_vcpu_topology(&self) -> Option<(u32, u32, u32)> {
self.config
.topology
.clone()
Expand Down Expand Up @@ -2011,7 +2011,7 @@ impl Aml for CpuNotify {
}

struct CpuMethods {
max_vcpus: u8,
max_vcpus: u32,
dynamic: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ impl RequestHandler for Vmm {

fn vm_resize(
&mut self,
desired_vcpus: Option<u8>,
desired_vcpus: Option<u32>,
desired_ram: Option<u64>,
desired_balloon: Option<u64>,
) -> result::Result<(), VmError> {
Expand Down
2 changes: 1 addition & 1 deletion vmm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ impl Vm {

pub fn resize(
&mut self,
desired_vcpus: Option<u8>,
desired_vcpus: Option<u32>,
desired_memory: Option<u64>,
desired_balloon: Option<u64>,
) -> Result<()> {
Expand Down
6 changes: 3 additions & 3 deletions vmm/src/vm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use virtio_devices::RateLimiterConfig;

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct CpuAffinity {
pub vcpu: u8,
pub vcpu: u32,
pub host_cpus: Vec<usize>,
}

Expand Down Expand Up @@ -39,8 +39,8 @@ pub fn default_cpuconfig_max_phys_bits() -> u8 {

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct CpusConfig {
pub boot_vcpus: u8,
pub max_vcpus: u8,
pub boot_vcpus: u32,
pub max_vcpus: u32,
#[serde(default)]
pub topology: Option<CpuTopology>,
#[serde(default)]
Expand Down