MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / create_vcpu

Method create_vcpu

vmm/src/cpu.rs:963–1007  ·  view source on GitHub ↗
(
        &mut self,
        cpu_id: u32,
        snapshot: Option<&Snapshot>,
    )

Source from the content-addressed store, hash-verified

961 }
962
963 fn create_vcpu(
964 &mut self,
965 cpu_id: u32,
966 snapshot: Option<&Snapshot>,
967 ) -> Result<Arc<Mutex<Vcpu>>> {
968 info!("Creating vCPU: cpu_id = {cpu_id}");
969
970 #[cfg(target_arch = "x86_64")]
971 let topology = self.get_vcpu_topology();
972 #[cfg(target_arch = "x86_64")]
973 let x2apic_id = arch::x86_64::get_x2apic_id(cpu_id, topology);
974 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
975 let x2apic_id = cpu_id;
976
977 let mut vcpu = Vcpu::new(
978 cpu_id,
979 x2apic_id,
980 self.vm.as_ref(),
981 Some(self.vm_ops.clone()),
982 #[cfg(target_arch = "x86_64")]
983 self.hypervisor.get_cpu_vendor(),
984 )?;
985
986 if let Some(snapshot) = snapshot {
987 // AArch64 vCPUs should be initialized after created.
988 #[cfg(target_arch = "aarch64")]
989 vcpu.init(self.vm.as_ref())?;
990
991 let state: CpuState = snapshot.to_state().map_err(|e| {
992 Error::VcpuCreate(anyhow!("Could not get vCPU state from snapshot {e:?}"))
993 })?;
994 vcpu.vcpu
995 .set_state(&state)
996 .map_err(|e| Error::VcpuCreate(anyhow!("Could not set the vCPU state {e:?}")))?;
997
998 vcpu.saved_state = Some(state);
999 }
1000
1001 let vcpu = Arc::new(Mutex::new(vcpu));
1002
1003 // Adding vCPU to the CpuManager's vCPU list.
1004 self.vcpus.push(vcpu.clone());
1005
1006 Ok(vcpu)
1007 }
1008
1009 pub fn configure_vcpu(
1010 &self,

Callers 12

newMethod · 0.45
create_vcpusMethod · 0.45
test_setlintFunction · 0.45
test_setup_fpuFunction · 0.45
test_setup_msrsFunction · 0.45
test_setup_regs_for_pvhFunction · 0.45
test_setup_regsFunction · 0.45
test_read_mpidrFunction · 0.45
test_get_set_mpstateFunction · 0.45
test_vmFunction · 0.45

Calls 9

get_x2apic_idFunction · 0.85
newFunction · 0.85
get_vcpu_topologyMethod · 0.80
get_cpu_vendorMethod · 0.80
to_stateMethod · 0.80
cloneMethod · 0.45
initMethod · 0.45
set_stateMethod · 0.45
pushMethod · 0.45

Tested by 10

test_setlintFunction · 0.36
test_setup_fpuFunction · 0.36
test_setup_msrsFunction · 0.36
test_setup_regs_for_pvhFunction · 0.36
test_setup_regsFunction · 0.36
test_read_mpidrFunction · 0.36
test_get_set_mpstateFunction · 0.36
test_vmFunction · 0.36