From bd13bdbfc8c47a4dc59500973b4726d4dc2e9a1d Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 8 Sep 2022 13:29:43 -0700 Subject: [PATCH] windows: fix build without --features=stats Add a top-level stats feature that selects devices/stats and guard the uses of stats-related types with a cfg check. Fixes the Windows build when the stats feature is not enabled. No change in behavior when building with the win64 feature, as that selected the stats feature already. BUG=None TEST=cargo build --no-default-features Change-Id: I468f6c34509753d640ea002199da74e1729d25f7 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3885496 Reviewed-by: Noah Gold Commit-Queue: Daniel Verkamp --- Cargo.toml | 3 ++- src/crosvm/sys/windows.rs | 1 + src/sys/windows.rs | 7 ++++++- src/sys/windows/run_vcpu.rs | 24 ++++++++++++++++++------ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 755d0a7b61..83106afe22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,7 @@ all-linux = [ "virgl_renderer", "x", ] -win64 = ["devices/stats", "balloon", "haxm"] +win64 = ["stats", "balloon", "haxm"] audio = ["devices/audio"] audio_cras = ["devices/audio_cras"] balloon = ["devices/balloon", "vm_control/balloon"] @@ -149,6 +149,7 @@ plugin-render-server = [] power-monitor-powerd = ["arch/power-monitor-powerd"] qcow = ["disk/qcow"] slirp = ["devices/slirp"] +stats = ["devices/stats"] tpm = ["devices/tpm"] usb = ["devices/usb"] video-decoder = ["devices/video-decoder"] diff --git a/src/crosvm/sys/windows.rs b/src/crosvm/sys/windows.rs index cabc012745..b003c07f50 100644 --- a/src/crosvm/sys/windows.rs +++ b/src/crosvm/sys/windows.rs @@ -7,4 +7,5 @@ pub mod config; pub(crate) mod broker; pub(crate) mod exit; +#[cfg(feature = "stats")] pub(crate) mod stats; diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 97fcc2bd64..368de0c65d 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -210,6 +210,7 @@ use crate::crosvm::sys::config::IrqChipKind; use crate::crosvm::sys::windows::exit::Exit; use crate::crosvm::sys::windows::exit::ExitContext; use crate::crosvm::sys::windows::exit::ExitContextAnyhow; +#[cfg(feature = "stats")] use crate::crosvm::sys::windows::stats::StatisticsCollector; use crate::sys::windows::metrics::log_descriptor; use crate::sys::windows::metrics::MetricEventType; @@ -759,7 +760,7 @@ fn run_control( pvclock_host_tube: Option, map_request: Arc>>, mut gralloc: RutabagaGralloc, - stats: Option>>, + #[cfg(feature = "stats")] stats: Option>>, #[cfg(feature = "kiwi")] service_pipe_name: Option, ac97_host_tubes: Vec, memory_size_mb: u64, @@ -932,6 +933,7 @@ fn run_control( &exit_evt, &vm_evt_wrtube, &pvclock_host_tube, + #[cfg(feature = "stats")] &stats, host_cpu_topology, run_mode_arc.clone(), @@ -1353,6 +1355,7 @@ fn run_control( let _ = irq_join_handle.join(); + #[cfg(feature = "stats")] if let Some(stats) = stats { println!("Statistics Collected:\n{}", stats.lock()); println!("Statistics JSON:\n{}", stats.lock().json()); @@ -2126,6 +2129,7 @@ where let _render_node_host = (); + #[cfg(feature = "stats")] let stats = if cfg.exit_stats { Some(Arc::new(Mutex::new(StatisticsCollector::new()))) } else { @@ -2144,6 +2148,7 @@ where pvclock_host_tube, Arc::clone(&map_request), gralloc, + #[cfg(feature = "stats")] stats, #[cfg(feature = "kiwi")] cfg.service_pipe_name, diff --git a/src/sys/windows/run_vcpu.rs b/src/sys/windows/run_vcpu.rs index a252f4317a..22b8835e6d 100644 --- a/src/sys/windows/run_vcpu.rs +++ b/src/sys/windows/run_vcpu.rs @@ -85,7 +85,9 @@ use crate::bail_exit_code; use crate::crosvm::sys::windows::exit::Exit; use crate::crosvm::sys::windows::exit::ExitContext; use crate::crosvm::sys::windows::exit::ExitContextAnyhow; +#[cfg(feature = "stats")] use crate::crosvm::sys::windows::stats::StatisticsCollector; +#[cfg(feature = "stats")] use crate::crosvm::sys::windows::stats::VmExitStatistics; use crate::sys::windows::save_vcpu_tsc_offset; use crate::sys::windows::ExitState; @@ -275,7 +277,7 @@ impl VcpuRunThread { vm_evt_wrtube: SendTube, requires_pvclock_ctrl: bool, run_mode_arc: Arc, - stats: Option>>, + #[cfg(feature = "stats")] stats: Option>>, host_cpu_topology: bool, tsc_offset: Option, force_calibrated_tsc_leaf: bool, @@ -368,6 +370,7 @@ impl VcpuRunThread { mmio_bus, requires_pvclock_ctrl, run_mode_arc, + #[cfg(feature = "stats")] stats, #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] cpuid_context, @@ -559,7 +562,7 @@ pub fn run_all_vcpus( exit_evt: &Event, vm_evt_wrtube: &SendTube, pvclock_host_tube: &Option, - stats: &Option>>, + #[cfg(feature = "stats")] stats: &Option>>, host_cpu_topology: bool, run_mode_arc: Arc, tsc_sync_mitigations: TscSyncMitigations, @@ -636,6 +639,7 @@ pub fn run_all_vcpus( .exit_context(Exit::CloneTube, "failed to clone tube")?, pvclock_host_tube.is_none(), run_mode_arc.clone(), + #[cfg(feature = "stats")] stats.clone(), host_cpu_topology, tsc_offset, @@ -668,16 +672,21 @@ fn vcpu_loop( mmio_bus: Bus, requires_pvclock_ctrl: bool, run_mode_arc: Arc, - stats: Option>>, + #[cfg(feature = "stats")] stats: Option>>, #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] cpuid_context: CpuIdContext, ) -> Result where V: VcpuArch + 'static, { + #[cfg(feature = "stats")] let mut exit_stats = VmExitStatistics::new(); - mmio_bus.stats.lock().set_enabled(stats.is_some()); - io_bus.stats.lock().set_enabled(stats.is_some()); - exit_stats.set_enabled(stats.is_some()); + + #[cfg(feature = "stats")] + { + mmio_bus.stats.lock().set_enabled(stats.is_some()); + io_bus.stats.lock().set_enabled(stats.is_some()); + exit_stats.set_enabled(stats.is_some()); + } let mut save_tsc_offset = true; @@ -732,6 +741,7 @@ where save_tsc_offset = false; } + #[cfg(feature = "stats")] let start = exit_stats.start_stat(); match exit { @@ -893,6 +903,7 @@ where }, } + #[cfg(feature = "stats")] exit_stats.end_stat(&exit, start); } @@ -916,6 +927,7 @@ where } VmRunMode::Breakpoint => {} VmRunMode::Exiting => { + #[cfg(feature = "stats")] if let Some(stats) = stats { let mut collector = stats.lock(); collector.pio_bus_stats.push(io_bus.stats);