Skip to content

Commit 5fe8c72

Browse files
committed
[trace-host] move mem_profile logic to different file
- Rename TraceInfo to reflect only being used by mem_profile Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent c1b3ed8 commit 5fe8c72

File tree

8 files changed

+225
-265
lines changed

8 files changed

+225
-265
lines changed

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ use crate::mem::shared_mem::HostSharedMemory;
7070
use crate::sandbox::SandboxConfiguration;
7171
use crate::sandbox::host_funcs::FunctionRegistry;
7272
use crate::sandbox::outb::handle_outb;
73-
#[cfg(feature = "trace_guest")]
74-
use crate::sandbox::trace::TraceInfo;
73+
#[cfg(feature = "mem_profile")]
74+
use crate::sandbox::trace::MemTraceInfo;
7575
#[cfg(crashdump)]
7676
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
7777
use crate::{Result, log_then_return, new_error};
@@ -297,8 +297,8 @@ pub(crate) struct HypervLinuxDriver {
297297
#[cfg(crashdump)]
298298
rt_cfg: SandboxRuntimeConfig,
299299
#[allow(dead_code)]
300-
#[cfg(feature = "trace_guest")]
301-
trace_info: TraceInfo,
300+
#[cfg(feature = "mem_profile")]
301+
trace_info: MemTraceInfo,
302302
}
303303

304304
impl HypervLinuxDriver {
@@ -321,7 +321,7 @@ impl HypervLinuxDriver {
321321
config: &SandboxConfiguration,
322322
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
323323
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
324-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
324+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
325325
) -> Result<Self> {
326326
let mshv = Mshv::new()?;
327327
let pr = Default::default();
@@ -429,7 +429,7 @@ impl HypervLinuxDriver {
429429
gdb_conn,
430430
#[cfg(crashdump)]
431431
rt_cfg,
432-
#[cfg(feature = "trace_guest")]
432+
#[cfg(feature = "mem_profile")]
433433
trace_info,
434434
};
435435

@@ -595,7 +595,7 @@ impl Hypervisor for HypervLinuxDriver {
595595
padded[..copy_len].copy_from_slice(&data[..copy_len]);
596596
let val = u32::from_le_bytes(padded);
597597

598-
#[cfg(feature = "trace_guest")]
598+
#[cfg(feature = "mem_profile")]
599599
{
600600
// We need to handle the borrow checker issue where we need both:
601601
// - &mut SandboxMemoryManager (from self.mem_mgr)
@@ -616,7 +616,7 @@ impl Hypervisor for HypervLinuxDriver {
616616
self.mem_mgr = Some(mem_mgr);
617617
}
618618

619-
#[cfg(not(feature = "trace_guest"))]
619+
#[cfg(not(feature = "mem_profile"))]
620620
{
621621
let mem_mgr = self
622622
.mem_mgr
@@ -1087,7 +1087,7 @@ impl Hypervisor for HypervLinuxDriver {
10871087
}
10881088

10891089
#[cfg(feature = "mem_profile")]
1090-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
1090+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
10911091
&mut self.trace_info
10921092
}
10931093
}
@@ -1178,12 +1178,8 @@ mod tests {
11781178
#[cfg(crashdump)]
11791179
guest_core_dump: true,
11801180
},
1181-
#[cfg(feature = "trace_guest")]
1182-
TraceInfo::new(
1183-
#[cfg(feature = "mem_profile")]
1184-
Arc::new(DummyUnwindInfo {}),
1185-
)
1186-
.unwrap(),
1181+
#[cfg(feature = "mem_profile")]
1182+
MemTraceInfo::new(Arc::new(DummyUnwindInfo {})).unwrap(),
11871183
)
11881184
.unwrap();
11891185
}

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
4949
use crate::mem::mgr::SandboxMemoryManager;
5050
use crate::mem::ptr::{GuestPtr, RawPtr};
5151
use crate::mem::shared_mem::HostSharedMemory;
52-
#[cfg(feature = "trace_guest")]
53-
use crate::sandbox::TraceInfo;
5452
use crate::sandbox::host_funcs::FunctionRegistry;
5553
use crate::sandbox::outb::handle_outb;
54+
#[cfg(feature = "mem_profile")]
55+
use crate::sandbox::trace::MemTraceInfo;
5656
#[cfg(crashdump)]
5757
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
5858
use crate::{Result, debug, log_then_return, new_error};
@@ -274,9 +274,9 @@ pub(crate) struct HypervWindowsDriver {
274274
gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
275275
#[cfg(crashdump)]
276276
rt_cfg: SandboxRuntimeConfig,
277-
#[cfg(feature = "trace_guest")]
277+
#[cfg(feature = "mem_profile")]
278278
#[allow(dead_code)]
279-
trace_info: TraceInfo,
279+
trace_info: MemTraceInfo,
280280
}
281281
/* This does not automatically impl Send because the host
282282
* address of the shared memory region is a raw pointer, which are
@@ -298,7 +298,7 @@ impl HypervWindowsDriver {
298298
mmap_file_handle: HandleWrapper,
299299
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
300300
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
301-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
301+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
302302
) -> Result<Self> {
303303
// create and setup hypervisor partition
304304
let mut partition = VMPartition::new(1)?;
@@ -350,7 +350,7 @@ impl HypervWindowsDriver {
350350
gdb_conn,
351351
#[cfg(crashdump)]
352352
rt_cfg,
353-
#[cfg(feature = "trace_guest")]
353+
#[cfg(feature = "mem_profile")]
354354
trace_info,
355355
};
356356

@@ -502,7 +502,7 @@ impl Hypervisor for HypervWindowsDriver {
502502
padded[..copy_len].copy_from_slice(&data[..copy_len]);
503503
let val = u32::from_le_bytes(padded);
504504

505-
#[cfg(feature = "trace_guest")]
505+
#[cfg(feature = "mem_profile")]
506506
{
507507
// We need to handle the borrow checker issue where we need both:
508508
// - &mut SandboxMemoryManager (from self.mem_mgr.as_mut())
@@ -523,7 +523,7 @@ impl Hypervisor for HypervWindowsDriver {
523523
self.mem_mgr = Some(mem_mgr);
524524
}
525525

526-
#[cfg(not(feature = "trace_guest"))]
526+
#[cfg(not(feature = "mem_profile"))]
527527
{
528528
let mem_mgr = self
529529
.mem_mgr
@@ -933,7 +933,7 @@ impl Hypervisor for HypervWindowsDriver {
933933
}
934934

935935
#[cfg(feature = "mem_profile")]
936-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
936+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
937937
&mut self.trace_info
938938
}
939939
}

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ use crate::mem::shared_mem::HostSharedMemory;
4343
use crate::sandbox::SandboxConfiguration;
4444
use crate::sandbox::host_funcs::FunctionRegistry;
4545
use crate::sandbox::outb::handle_outb;
46-
#[cfg(feature = "trace_guest")]
47-
use crate::sandbox::trace::TraceInfo;
46+
#[cfg(feature = "mem_profile")]
47+
use crate::sandbox::trace::MemTraceInfo;
4848
#[cfg(crashdump)]
4949
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
5050
use crate::{Result, log_then_return, new_error};
@@ -284,9 +284,9 @@ pub(crate) struct KVMDriver {
284284
gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
285285
#[cfg(crashdump)]
286286
rt_cfg: SandboxRuntimeConfig,
287-
#[cfg(feature = "trace_guest")]
287+
#[cfg(feature = "mem_profile")]
288288
#[allow(dead_code)]
289-
trace_info: TraceInfo,
289+
trace_info: MemTraceInfo,
290290
}
291291

292292
impl KVMDriver {
@@ -304,7 +304,7 @@ impl KVMDriver {
304304
config: &SandboxConfiguration,
305305
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
306306
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
307-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
307+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
308308
) -> Result<Self> {
309309
let kvm = Kvm::new()?;
310310

@@ -375,7 +375,7 @@ impl KVMDriver {
375375
gdb_conn,
376376
#[cfg(crashdump)]
377377
rt_cfg,
378-
#[cfg(feature = "trace_guest")]
378+
#[cfg(feature = "mem_profile")]
379379
trace_info,
380380
};
381381

@@ -572,7 +572,7 @@ impl Hypervisor for KVMDriver {
572572
padded[..copy_len].copy_from_slice(&data[..copy_len]);
573573
let value = u32::from_le_bytes(padded);
574574

575-
#[cfg(feature = "trace_guest")]
575+
#[cfg(feature = "mem_profile")]
576576
{
577577
// We need to handle the borrow checker issue where we need both:
578578
// - &mut SandboxMemoryManager (from self.mem_mgr.as_mut())
@@ -593,7 +593,7 @@ impl Hypervisor for KVMDriver {
593593
self.mem_mgr = Some(mem_mgr);
594594
}
595595

596-
#[cfg(not(feature = "trace_guest"))]
596+
#[cfg(not(feature = "mem_profile"))]
597597
{
598598
let mem_mgr = self
599599
.mem_mgr
@@ -1022,7 +1022,7 @@ impl Hypervisor for KVMDriver {
10221022
}
10231023

10241024
#[cfg(feature = "mem_profile")]
1025-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
1025+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
10261026
&mut self.trace_info
10271027
}
10281028
}

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::hypervisor::regs::{
2525
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
2626
use crate::metrics::METRIC_GUEST_CANCELLATION;
2727
#[cfg(feature = "mem_profile")]
28-
use crate::sandbox::trace::TraceInfo;
28+
use crate::sandbox::trace::MemTraceInfo;
2929
use crate::{HyperlightError, Result, log_then_return};
3030

3131
/// HyperV-on-linux functionality
@@ -315,7 +315,7 @@ pub(crate) trait Hypervisor: Debug + Send {
315315

316316
/// Get a mutable reference of the trace info for the guest
317317
#[cfg(feature = "mem_profile")]
318-
fn trace_info_mut(&mut self) -> &mut TraceInfo;
318+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo;
319319
}
320320

321321
/// Returns a Some(HyperlightExit::AccessViolation(..)) if the given gpa doesn't have

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::{Span, instrument};
2525
use tracing_log::format_trace;
2626

2727
use super::host_funcs::FunctionRegistry;
28-
#[cfg(feature = "trace_guest")]
28+
#[cfg(feature = "mem_profile")]
2929
use crate::hypervisor::Hypervisor;
3030
use crate::mem::mgr::SandboxMemoryManager;
3131
use crate::mem::shared_mem::HostSharedMemory;
@@ -148,7 +148,7 @@ fn outb_abort(mem_mgr: &mut SandboxMemoryManager<HostSharedMemory>, data: u32) -
148148
pub(crate) fn handle_outb(
149149
mem_mgr: &mut SandboxMemoryManager<HostSharedMemory>,
150150
host_funcs: Arc<Mutex<FunctionRegistry>>,
151-
#[cfg(feature = "trace_guest")] _hv: &mut dyn Hypervisor,
151+
#[cfg(feature = "mem_profile")] _hv: &mut dyn Hypervisor,
152152
port: u16,
153153
data: u32,
154154
) -> Result<()> {

0 commit comments

Comments
 (0)