mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 11:05:46 +00:00
vmm: cpu: Factorize vcpu starting code
Anticipating the need for a slightly different function for restoring vCPUs, this patch factorizes most of the vCPU creation, so that it can be reused for migration purposes. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
722f9b6628
commit
f787c409c4
@ -721,17 +721,14 @@ impl CpuManager {
|
|||||||
Ok(cpuid)
|
Ok(cpuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate_vcpus(&mut self, desired_vcpus: u8, entry_point: Option<EntryPoint>) -> Result<()> {
|
fn start_vcpu(
|
||||||
if desired_vcpus > self.max_vcpus {
|
&mut self,
|
||||||
return Err(Error::DesiredVCPUCountExceedsMax);
|
cpu_id: u8,
|
||||||
}
|
creation_ts: std::time::Instant,
|
||||||
|
vcpu_thread_barrier: Arc<Barrier>,
|
||||||
let creation_ts = std::time::Instant::now();
|
entry_point: Option<EntryPoint>,
|
||||||
let vcpu_thread_barrier = Arc::new(Barrier::new(
|
inserting: bool,
|
||||||
(desired_vcpus - self.present_vcpus() + 1) as usize,
|
) -> Result<()> {
|
||||||
));
|
|
||||||
|
|
||||||
for cpu_id in self.present_vcpus()..desired_vcpus {
|
|
||||||
let ioapic = if let Some(ioapic) = &self.ioapic {
|
let ioapic = if let Some(ioapic) = &self.ioapic {
|
||||||
Some(ioapic.clone())
|
Some(ioapic.clone())
|
||||||
} else {
|
} else {
|
||||||
@ -747,8 +744,6 @@ impl CpuManager {
|
|||||||
creation_ts,
|
creation_ts,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let vcpu_thread_barrier = vcpu_thread_barrier.clone();
|
|
||||||
|
|
||||||
let reset_evt = self.reset_evt.try_clone().unwrap();
|
let reset_evt = self.reset_evt.try_clone().unwrap();
|
||||||
let vcpu_kill_signalled = self.vcpus_kill_signalled.clone();
|
let vcpu_kill_signalled = self.vcpus_kill_signalled.clone();
|
||||||
let vcpu_pause_signalled = self.vcpus_pause_signalled.clone();
|
let vcpu_pause_signalled = self.vcpus_pause_signalled.clone();
|
||||||
@ -815,7 +810,29 @@ impl CpuManager {
|
|||||||
// On hot plug calls into this function entry_point is None. It is for
|
// On hot plug calls into this function entry_point is None. It is for
|
||||||
// those hotplug CPU additions that we need to set the inserting flag.
|
// those hotplug CPU additions that we need to set the inserting flag.
|
||||||
self.vcpu_states[usize::from(cpu_id)].handle = handle;
|
self.vcpu_states[usize::from(cpu_id)].handle = handle;
|
||||||
self.vcpu_states[usize::from(cpu_id)].inserting = entry_point.is_none();
|
self.vcpu_states[usize::from(cpu_id)].inserting = inserting;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn activate_vcpus(&mut self, desired_vcpus: u8, entry_point: Option<EntryPoint>) -> Result<()> {
|
||||||
|
if desired_vcpus > self.max_vcpus {
|
||||||
|
return Err(Error::DesiredVCPUCountExceedsMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
let creation_ts = std::time::Instant::now();
|
||||||
|
let vcpu_thread_barrier = Arc::new(Barrier::new(
|
||||||
|
(desired_vcpus - self.present_vcpus() + 1) as usize,
|
||||||
|
));
|
||||||
|
|
||||||
|
for cpu_id in self.present_vcpus()..desired_vcpus {
|
||||||
|
self.start_vcpu(
|
||||||
|
cpu_id,
|
||||||
|
creation_ts,
|
||||||
|
vcpu_thread_barrier.clone(),
|
||||||
|
entry_point,
|
||||||
|
entry_point.is_none(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unblock all CPU threads.
|
// Unblock all CPU threads.
|
||||||
|
Loading…
Reference in New Issue
Block a user