mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-31 18:15:20 +00:00
vmm: Encase CpuManager within an Arc<Mutex<>>
This is necessary to be able to add the CpuManager onto the IO bus. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
d7dc1a9226
commit
1ac1231292
@ -349,8 +349,8 @@ impl CpuManager {
|
||||
fd: Arc<VmFd>,
|
||||
cpuid: CpuId,
|
||||
reset_evt: EventFd,
|
||||
) -> CpuManager {
|
||||
CpuManager {
|
||||
) -> Arc<Mutex<CpuManager>> {
|
||||
let cpu_manager = Arc::new(Mutex::new(CpuManager {
|
||||
boot_vcpus,
|
||||
io_bus: device_manager.io_bus().clone(),
|
||||
mmio_bus: device_manager.mmio_bus().clone(),
|
||||
@ -362,7 +362,9 @@ impl CpuManager {
|
||||
vcpus_pause_signalled: Arc::new(AtomicBool::new(false)),
|
||||
threads: Vec::with_capacity(boot_vcpus as usize),
|
||||
reset_evt,
|
||||
}
|
||||
}));
|
||||
|
||||
cpu_manager
|
||||
}
|
||||
|
||||
// Starts all the vCPUs that the VM is booting with. Blocks until all vCPUs are running.
|
||||
|
@ -43,7 +43,7 @@ use std::io;
|
||||
use std::ops::Deref;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::{result, str, thread};
|
||||
use vm_allocator::{GsiApic, SystemAllocator};
|
||||
use vm_memory::guest_memory::FileOffset;
|
||||
@ -205,7 +205,7 @@ pub struct Vm {
|
||||
on_tty: bool,
|
||||
signals: Option<Signals>,
|
||||
state: RwLock<VmState>,
|
||||
cpu_manager: cpu::CpuManager,
|
||||
cpu_manager: Arc<Mutex<cpu::CpuManager>>,
|
||||
}
|
||||
|
||||
fn get_host_cpu_phys_bits() -> u8 {
|
||||
@ -564,7 +564,11 @@ impl Vm {
|
||||
signals.close();
|
||||
}
|
||||
|
||||
self.cpu_manager.shutdown().map_err(Error::CpuManager)?;
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.shutdown()
|
||||
.map_err(Error::CpuManager)?;
|
||||
|
||||
// Wait for all the threads to finish
|
||||
for thread in self.threads.drain(..) {
|
||||
@ -581,7 +585,11 @@ impl Vm {
|
||||
|
||||
state.valid_transition(new_state)?;
|
||||
|
||||
self.cpu_manager.pause().map_err(Error::CpuManager)?;
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.pause()
|
||||
.map_err(Error::CpuManager)?;
|
||||
|
||||
*state = new_state;
|
||||
|
||||
@ -594,7 +602,11 @@ impl Vm {
|
||||
|
||||
state.valid_transition(new_state)?;
|
||||
|
||||
self.cpu_manager.resume().map_err(Error::CpuManager)?;
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.resume()
|
||||
.map_err(Error::CpuManager)?;
|
||||
|
||||
// And we're back to the Running state.
|
||||
*state = new_state;
|
||||
@ -623,6 +635,8 @@ impl Vm {
|
||||
let entry_addr = self.load_kernel()?;
|
||||
|
||||
self.cpu_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.start_boot_vcpus(entry_addr)
|
||||
.map_err(Error::CpuManager)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user