diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-05-08 15:27:56 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-05-10 02:39:28 +0000 |
commit | 2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b (patch) | |
tree | fefaf2c13796f8f2fa9a13b99b09c3b40ab5966b /vm_control | |
parent | 00c41c28bbc44b37fc8dcf5d2a5b4679f2aa4297 (diff) | |
parent | 03a54abf852984f696e7a101ff9590f05ebcba5b (diff) | |
download | crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.gz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.bz2 crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.lz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.xz crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.tar.zst crosvm-2f8d50adc97cc7fca6f710bd575b4f71ccb40f6b.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'vm_control')
-rw-r--r-- | vm_control/src/lib.rs | 110 |
1 files changed, 98 insertions, 12 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index b01f4af..a1d2964 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -123,6 +123,43 @@ pub struct BalloonStats { pub hugetlb_failures: Option<u64>, } +impl Display for BalloonStats { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{{")?; + if let Some(swap_in) = self.swap_in { + write!(f, "\n swap_in: {}", swap_in)?; + } + if let Some(swap_out) = self.swap_out { + write!(f, "\n swap_out: {}", swap_out)?; + } + if let Some(major_faults) = self.major_faults { + write!(f, "\n major_faults: {}", major_faults)?; + } + if let Some(minor_faults) = self.minor_faults { + write!(f, "\n minor_faults: {}", minor_faults)?; + } + if let Some(free_memory) = self.free_memory { + write!(f, "\n free_memory: {}", free_memory)?; + } + if let Some(total_memory) = self.total_memory { + write!(f, "\n total_memory: {}", total_memory)?; + } + if let Some(available_memory) = self.available_memory { + write!(f, "\n available_memory: {}", available_memory)?; + } + if let Some(disk_caches) = self.disk_caches { + write!(f, "\n disk_caches: {}", disk_caches)?; + } + if let Some(hugetlb_allocations) = self.hugetlb_allocations { + write!(f, "\n hugetlb_allocations: {}", hugetlb_allocations)?; + } + if let Some(hugetlb_failures) = self.hugetlb_failures { + write!(f, "\n hugetlb_failures: {}", hugetlb_failures)?; + } + write!(f, "\n}}") + } +} + #[derive(MsgOnSocket, Debug)] pub enum BalloonControlResult { Stats { @@ -413,7 +450,12 @@ pub enum VmMsyncRequest { /// Flush the content of a memory mapping to its backing file. /// `slot` selects the arena (as returned by `Vm::add_mmap_arena`). /// `offset` is the offset of the mapping to sync within the arena. - MsyncArena { slot: u32, offset: usize }, + /// `size` is the size of the mapping to sync within the arena. + MsyncArena { + slot: u32, + offset: usize, + size: usize, + }, } #[derive(MsgOnSocket, Debug)] @@ -434,11 +476,10 @@ impl VmMsyncRequest { pub fn execute(&self, vm: &mut Vm) -> VmMsyncResponse { use self::VmMsyncRequest::*; match *self { - MsyncArena { slot, offset } => { + MsyncArena { slot, offset, size } => { if let Some(arena) = vm.get_mmap_arena(slot) { - match arena.msync(offset) { - Ok(true) => VmMsyncResponse::Ok, - Ok(false) => VmMsyncResponse::Err(SysError::new(EINVAL)), + match arena.msync(offset, size) { + Ok(()) => VmMsyncResponse::Ok, Err(e) => match e { MmapError::SystemCallFailed(errno) => VmMsyncResponse::Err(errno), _ => VmMsyncResponse::Err(SysError::new(EINVAL)), @@ -509,11 +550,23 @@ fn register_memory( }; let addr = match allocation { - Some((Alloc::PciBar { bus, dev, bar }, offset)) => { + Some(( + Alloc::PciBar { + bus, + dev, + func, + bar, + }, + offset, + )) => { match allocator .mmio_allocator(MmioType::High) - .get(&Alloc::PciBar { bus, dev, bar }) - { + .get(&Alloc::PciBar { + bus, + dev, + func, + bar, + }) { Some((start_addr, length, _)) => { let address = *start_addr + offset; let range = *start_addr..*start_addr + *length; @@ -574,10 +627,30 @@ impl VmRequest { *run_mode = Some(VmRunMode::Running); VmResponse::Ok } - VmRequest::BalloonCommand(ref command) => match balloon_host_socket.send(command) { - Ok(_) => VmResponse::Ok, - Err(_) => VmResponse::Err(SysError::last()), - }, + VmRequest::BalloonCommand(BalloonControlCommand::Adjust { num_bytes }) => { + match balloon_host_socket.send(&BalloonControlCommand::Adjust { num_bytes }) { + Ok(_) => VmResponse::Ok, + Err(_) => VmResponse::Err(SysError::last()), + } + } + VmRequest::BalloonCommand(BalloonControlCommand::Stats) => { + match balloon_host_socket.send(&BalloonControlCommand::Stats {}) { + Ok(_) => match balloon_host_socket.recv() { + Ok(BalloonControlResult::Stats { + stats, + balloon_actual, + }) => VmResponse::BalloonStats { + stats, + balloon_actual, + }, + Err(e) => { + error!("balloon socket recv failed: {}", e); + VmResponse::Err(SysError::last()) + } + }, + Err(_) => VmResponse::Err(SysError::last()), + } + } VmRequest::DiskCommand { disk_index, ref command, @@ -639,6 +712,11 @@ pub enum VmResponse { slot: u32, desc: GpuMemoryDesc, }, + /// Results of balloon control commands. + BalloonStats { + stats: BalloonStats, + balloon_actual: u64, + }, /// Results of usb control commands. UsbResponse(UsbControlResult), } @@ -660,6 +738,14 @@ impl Display for VmResponse { "gpu memory allocated and registered to page frame number {:#x} and memory slot {}", pfn, slot ), + BalloonStats { + stats, + balloon_actual, + } => write!( + f, + "balloon size: {}\nballoon stats: {}", + balloon_actual, stats + ), UsbResponse(result) => write!(f, "usb control request get result {:?}", result), } } |