mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
vmm: cpu: Add the CpuManager onto the IO bus
This allows the kernel (via ACPI based controls) to query and control the CPU state. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
39a1b8f4db
commit
1da0ff395d
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
use std::os::unix::thread::JoinHandleExt;
|
use std::os::unix::thread::JoinHandleExt;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Barrier, Mutex, RwLock};
|
use std::sync::{Arc, Barrier, Mutex, RwLock, Weak};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::{fmt, io, result};
|
use std::{fmt, io, result};
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ use libc::{c_void, siginfo_t};
|
|||||||
|
|
||||||
use crate::device_manager::DeviceManager;
|
use crate::device_manager::DeviceManager;
|
||||||
|
|
||||||
use devices::ioapic;
|
use devices::{ioapic, BusDevice};
|
||||||
use kvm_ioctls::*;
|
use kvm_ioctls::*;
|
||||||
|
|
||||||
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
|
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
|
||||||
@ -110,6 +110,9 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Failed to join on vCPU threads
|
/// Failed to join on vCPU threads
|
||||||
ThreadCleanup,
|
ThreadCleanup,
|
||||||
|
|
||||||
|
/// Cannot add legacy device to Bus.
|
||||||
|
BusError(devices::BusError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -329,7 +332,7 @@ impl Vcpu {
|
|||||||
|
|
||||||
pub struct CpuManager {
|
pub struct CpuManager {
|
||||||
boot_vcpus: u8,
|
boot_vcpus: u8,
|
||||||
io_bus: Arc<devices::Bus>,
|
io_bus: Weak<devices::Bus>,
|
||||||
mmio_bus: Arc<devices::Bus>,
|
mmio_bus: Arc<devices::Bus>,
|
||||||
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
||||||
vm_memory: Arc<RwLock<GuestMemoryMmap>>,
|
vm_memory: Arc<RwLock<GuestMemoryMmap>>,
|
||||||
@ -341,6 +344,12 @@ pub struct CpuManager {
|
|||||||
threads: Vec<thread::JoinHandle<()>>,
|
threads: Vec<thread::JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BusDevice for CpuManager {
|
||||||
|
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {}
|
||||||
|
|
||||||
|
fn write(&mut self, _base: u64, _offset: u64, data: &[u8]) {}
|
||||||
|
}
|
||||||
|
|
||||||
impl CpuManager {
|
impl CpuManager {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
boot_vcpus: u8,
|
boot_vcpus: u8,
|
||||||
@ -349,10 +358,10 @@ impl CpuManager {
|
|||||||
fd: Arc<VmFd>,
|
fd: Arc<VmFd>,
|
||||||
cpuid: CpuId,
|
cpuid: CpuId,
|
||||||
reset_evt: EventFd,
|
reset_evt: EventFd,
|
||||||
) -> Arc<Mutex<CpuManager>> {
|
) -> Result<Arc<Mutex<CpuManager>>> {
|
||||||
let cpu_manager = Arc::new(Mutex::new(CpuManager {
|
let cpu_manager = Arc::new(Mutex::new(CpuManager {
|
||||||
boot_vcpus,
|
boot_vcpus,
|
||||||
io_bus: device_manager.io_bus().clone(),
|
io_bus: Arc::downgrade(&device_manager.io_bus().clone()),
|
||||||
mmio_bus: device_manager.mmio_bus().clone(),
|
mmio_bus: device_manager.mmio_bus().clone(),
|
||||||
ioapic: device_manager.ioapic().clone(),
|
ioapic: device_manager.ioapic().clone(),
|
||||||
vm_memory: guest_memory,
|
vm_memory: guest_memory,
|
||||||
@ -365,6 +374,15 @@ impl CpuManager {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
cpu_manager
|
cpu_manager
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.io_bus
|
||||||
|
.upgrade()
|
||||||
|
.unwrap()
|
||||||
|
.insert(cpu_manager.clone(), 0x0cd8, 0xc)
|
||||||
|
.map_err(Error::BusError)?;
|
||||||
|
|
||||||
|
Ok(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.
|
||||||
@ -383,7 +401,7 @@ impl CpuManager {
|
|||||||
let mut vcpu = Vcpu::new(
|
let mut vcpu = Vcpu::new(
|
||||||
cpu_id,
|
cpu_id,
|
||||||
&self.fd,
|
&self.fd,
|
||||||
self.io_bus.clone(),
|
self.io_bus.clone().upgrade().unwrap(),
|
||||||
self.mmio_bus.clone(),
|
self.mmio_bus.clone(),
|
||||||
ioapic,
|
ioapic,
|
||||||
creation_ts,
|
creation_ts,
|
||||||
|
@ -428,7 +428,8 @@ impl Vm {
|
|||||||
fd,
|
fd,
|
||||||
cpuid,
|
cpuid,
|
||||||
reset_evt,
|
reset_evt,
|
||||||
);
|
)
|
||||||
|
.map_err(Error::CpuManager)?;
|
||||||
|
|
||||||
Ok(Vm {
|
Ok(Vm {
|
||||||
kernel,
|
kernel,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user