diff options
author | Frederick Mayle <fmayle@google.com> | 2024-04-12 15:36:54 -0700 |
---|---|---|
committer | Frederick Mayle <fmayle@google.com> | 2024-04-15 13:00:06 -0700 |
commit | c223989d8457ecb2345a8d2831d8a1e599abcb0c (patch) | |
tree | 682de9eb6a3f88e0d15f30445ba3e0ec296edf6c /src/crosvm/sys/linux.rs | |
parent | 3eba8661914b15dc34bde33d6a8201cfc76c7675 (diff) | |
parent | b0967c6b2e6e17d23a50bb91c08c9bf712cffd00 (diff) | |
download | crosvm-c223989d8457ecb2345a8d2831d8a1e599abcb0c.tar.gz |
Merge remote-tracking branch 'aosp/upstream-main'
Had to update the rust version to compile the new nix version.
The metrics protos have been deleted upstream, so those `out` files are
deleted (and we don't need to `sed` them in the script).
Added default_team for `hypervisor` to satisify a lint error, will add
it everywhere else later.
* aosp/upstream-main: (86 commits)
Roll recipe dependencies (trivial).
devices: vhost-user: fix test flake
Roll recipe dependencies (trivial).
Cargo.lock: switch to tokio 1.29.1
Roll recipe dependencies (trivial).
Roll recipe dependencies (trivial).
Roll recipe dependencies (trivial).
cros_async: Tokio IoSource for windows
cros_async: Add AsyncFd to Tokio linux implementation
cros_async: Blocking tokio executor for linux
devices: Fix nested executor invocation in async virtio-console
cros_async: Move `concurrency` to Overlapped enum
Roll recipe dependencies (trivial).
Create a minimal virtualization and hypervisor integration test.
gpu_display: add max_num_displays to GpuParameters.
Roll recipe dependencies (trivial).
Roll recipe dependencies (trivial).
Roll recipe dependencies (trivial).
Refactor android display backend
e2e_tests: wait for restore to complete before sending commands
...
Bug: 332584046
Test: TH
Change-Id: I25dd0124d719a59c312ba31f060c1b37f1d2a1b6
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; |