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:
Rob Bradford 2019-11-11 14:31:11 +00:00 committed by Sebastien Boeuf
parent d7dc1a9226
commit 1ac1231292
2 changed files with 24 additions and 8 deletions

View File

@ -349,8 +349,8 @@ impl CpuManager {
fd: Arc<VmFd>, fd: Arc<VmFd>,
cpuid: CpuId, cpuid: CpuId,
reset_evt: EventFd, reset_evt: EventFd,
) -> CpuManager { ) -> Arc<Mutex<CpuManager>> {
CpuManager { let cpu_manager = Arc::new(Mutex::new(CpuManager {
boot_vcpus, boot_vcpus,
io_bus: device_manager.io_bus().clone(), io_bus: device_manager.io_bus().clone(),
mmio_bus: device_manager.mmio_bus().clone(), mmio_bus: device_manager.mmio_bus().clone(),
@ -362,7 +362,9 @@ impl CpuManager {
vcpus_pause_signalled: Arc::new(AtomicBool::new(false)), vcpus_pause_signalled: Arc::new(AtomicBool::new(false)),
threads: Vec::with_capacity(boot_vcpus as usize), threads: Vec::with_capacity(boot_vcpus as usize),
reset_evt, reset_evt,
} }));
cpu_manager
} }
// Starts all the vCPUs that the VM is booting with. Blocks until all vCPUs are running. // Starts all the vCPUs that the VM is booting with. Blocks until all vCPUs are running.

View File

@ -43,7 +43,7 @@ use std::io;
use std::ops::Deref; use std::ops::Deref;
use std::os::unix::io::FromRawFd; use std::os::unix::io::FromRawFd;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use std::{result, str, thread}; use std::{result, str, thread};
use vm_allocator::{GsiApic, SystemAllocator}; use vm_allocator::{GsiApic, SystemAllocator};
use vm_memory::guest_memory::FileOffset; use vm_memory::guest_memory::FileOffset;
@ -205,7 +205,7 @@ pub struct Vm {
on_tty: bool, on_tty: bool,
signals: Option<Signals>, signals: Option<Signals>,
state: RwLock<VmState>, state: RwLock<VmState>,
cpu_manager: cpu::CpuManager, cpu_manager: Arc<Mutex<cpu::CpuManager>>,
} }
fn get_host_cpu_phys_bits() -> u8 { fn get_host_cpu_phys_bits() -> u8 {
@ -564,7 +564,11 @@ impl Vm {
signals.close(); 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 // Wait for all the threads to finish
for thread in self.threads.drain(..) { for thread in self.threads.drain(..) {
@ -581,7 +585,11 @@ impl Vm {
state.valid_transition(new_state)?; 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; *state = new_state;
@ -594,7 +602,11 @@ impl Vm {
state.valid_transition(new_state)?; 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. // And we're back to the Running state.
*state = new_state; *state = new_state;
@ -623,6 +635,8 @@ impl Vm {
let entry_addr = self.load_kernel()?; let entry_addr = self.load_kernel()?;
self.cpu_manager self.cpu_manager
.lock()
.unwrap()
.start_boot_vcpus(entry_addr) .start_boot_vcpus(entry_addr)
.map_err(Error::CpuManager)?; .map_err(Error::CpuManager)?;