diff options
Diffstat (limited to 'src/crosvm/sys/linux.rs')
-rw-r--r-- | src/crosvm/sys/linux.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/crosvm/sys/linux.rs b/src/crosvm/sys/linux.rs index 2bfdb442b..f94096cde 100644 --- a/src/crosvm/sys/linux.rs +++ b/src/crosvm/sys/linux.rs @@ -164,6 +164,7 @@ use jail_warden::JailWardenImpl; #[cfg(feature = "pci-hotplug")] use jail_warden::PermissiveJailWarden; use libc; +use metrics::MetricsController; use minijail::Minijail; #[cfg(feature = "pci-hotplug")] use pci_hotplug_manager::PciHotPlugManager; @@ -1681,6 +1682,10 @@ where // access to those files will not be possible. info!("crosvm entering multiprocess mode"); } + + let (metrics_send, metrics_recv) = Tube::directional_pair().context("metrics tube")?; + metrics::initialize(metrics_send); + #[cfg(all(feature = "pci-hotplug", feature = "swap"))] let swap_device_helper = match &swap_controller { Some(swap_controller) => Some(swap_controller.create_device_helper()?), @@ -2211,6 +2216,7 @@ where guest_suspended_cvar, #[cfg(feature = "pvclock")] pvclock_host_tube, + metrics_recv, ) } @@ -3277,6 +3283,7 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>( #[cfg(feature = "registered_events")] reg_evt_rdtube: RecvTube, guest_suspended_cvar: Option<Arc<(Mutex<bool>, Condvar)>>, #[cfg(feature = "pvclock")] pvclock_host_tube: Option<Tube>, + metrics_tube: RecvTube, ) -> Result<ExitState> { #[derive(EventToken)] enum Token { @@ -3626,6 +3633,21 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>( .context("static device setup complete")?; } + let metrics_thread = if metrics::is_initialized() { + Some( + std::thread::Builder::new() + .name("metrics_thread".into()) + .spawn(move || { + if let Err(e) = MetricsController::new(vec![metrics_tube]).run() { + error!("Metrics controller error: {:?}", e); + } + }) + .context("metrics thread failed")?, + ) + } else { + None + }; + let mut exit_state = ExitState::Stop; let mut pvpanic_code = PvPanicCode::Unknown; #[cfg(feature = "registered_events")] @@ -3955,6 +3977,20 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>( // control sockets are closed when this function exits. mem::drop(linux); + // Drop the hotplug manager to tell the warden process to exit before we try to join + // the metrics thread. + #[cfg(feature = "pci-hotplug")] + mem::drop(hotplug_manager); + + // All our children should have exited by now, so closing our fd should + // terminate metrics. Then join so that everything gets flushed. + metrics::get_destructor().cleanup(); + if let Some(metrics_thread) = metrics_thread { + if let Err(e) = metrics_thread.join() { + error!("failed to exit irq handler thread: {:?}", e); + } + } + stdin() .set_canon_mode() .expect("failed to restore canonical mode for terminal"); @@ -4400,6 +4436,7 @@ fn jail_and_start_vu_device<T: VirtioDeviceBuilder>( base::syslog::push_descriptors(&mut keep_rds); cros_tracing::push_descriptors!(&mut keep_rds); + metrics::push_descriptors(&mut keep_rds); let jail_type = VirtioDeviceType::VhostUser; |