Skip to content

Commit fa2beaf

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 fadcc56 commit fa2beaf

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
@@ -76,8 +76,8 @@ use crate::sandbox::SandboxConfiguration;
7676
use crate::sandbox::host_funcs::FunctionRegistry;
7777
use crate::sandbox::mem_mgr::MemMgrWrapper;
7878
use crate::sandbox::outb::handle_outb;
79-
#[cfg(feature = "trace_guest")]
80-
use crate::sandbox::trace::TraceInfo;
79+
#[cfg(feature = "mem_profile")]
80+
use crate::sandbox::trace::MemTraceInfo;
8181
#[cfg(crashdump)]
8282
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
8383
use crate::{Result, log_then_return, new_error};
@@ -321,8 +321,8 @@ pub(crate) struct HypervLinuxDriver {
321321
#[cfg(crashdump)]
322322
rt_cfg: SandboxRuntimeConfig,
323323
#[allow(dead_code)]
324-
#[cfg(feature = "trace_guest")]
325-
trace_info: TraceInfo,
324+
#[cfg(feature = "mem_profile")]
325+
trace_info: MemTraceInfo,
326326
}
327327

328328
impl HypervLinuxDriver {
@@ -345,7 +345,7 @@ impl HypervLinuxDriver {
345345
config: &SandboxConfiguration,
346346
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
347347
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
348-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
348+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
349349
) -> Result<Self> {
350350
let mshv = Mshv::new()?;
351351
let pr = Default::default();
@@ -456,7 +456,7 @@ impl HypervLinuxDriver {
456456
gdb_conn,
457457
#[cfg(crashdump)]
458458
rt_cfg,
459-
#[cfg(feature = "trace_guest")]
459+
#[cfg(feature = "mem_profile")]
460460
trace_info,
461461
};
462462

@@ -685,7 +685,7 @@ impl Hypervisor for HypervLinuxDriver {
685685
padded[..copy_len].copy_from_slice(&data[..copy_len]);
686686
let val = u32::from_le_bytes(padded);
687687

688-
#[cfg(feature = "trace_guest")]
688+
#[cfg(feature = "mem_profile")]
689689
{
690690
// We need to handle the borrow checker issue where we need both:
691691
// - &mut MemMgrWrapper (from self.mem_mgr.as_mut())
@@ -706,7 +706,7 @@ impl Hypervisor for HypervLinuxDriver {
706706
self.mem_mgr = Some(mem_mgr);
707707
}
708708

709-
#[cfg(not(feature = "trace_guest"))]
709+
#[cfg(not(feature = "mem_profile"))]
710710
{
711711
let mem_mgr = self
712712
.mem_mgr
@@ -1141,7 +1141,7 @@ impl Hypervisor for HypervLinuxDriver {
11411141
}
11421142

11431143
#[cfg(feature = "mem_profile")]
1144-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
1144+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
11451145
&mut self.trace_info
11461146
}
11471147
}
@@ -1232,12 +1232,8 @@ mod tests {
12321232
#[cfg(crashdump)]
12331233
guest_core_dump: true,
12341234
},
1235-
#[cfg(feature = "trace_guest")]
1236-
TraceInfo::new(
1237-
#[cfg(feature = "mem_profile")]
1238-
Arc::new(DummyUnwindInfo {}),
1239-
)
1240-
.unwrap(),
1235+
#[cfg(feature = "mem_profile")]
1236+
MemTraceInfo::new(Arc::new(DummyUnwindInfo {})).unwrap(),
12411237
)
12421238
.unwrap();
12431239
}

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ use crate::hypervisor::wrappers::WHvGeneralRegisters;
6060
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
6161
use crate::mem::ptr::{GuestPtr, RawPtr};
6262
use crate::mem::shared_mem::HostSharedMemory;
63-
#[cfg(feature = "trace_guest")]
64-
use crate::sandbox::TraceInfo;
63+
#[cfg(feature = "mem_profile")]
64+
use crate::sandbox::MemTraceInfo;
6565
use crate::sandbox::host_funcs::FunctionRegistry;
6666
use crate::sandbox::mem_mgr::MemMgrWrapper;
6767
use crate::sandbox::outb::handle_outb;
@@ -292,9 +292,9 @@ pub(crate) struct HypervWindowsDriver {
292292
gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
293293
#[cfg(crashdump)]
294294
rt_cfg: SandboxRuntimeConfig,
295-
#[cfg(feature = "trace_guest")]
295+
#[cfg(feature = "mem_profile")]
296296
#[allow(dead_code)]
297-
trace_info: TraceInfo,
297+
trace_info: MemTraceInfo,
298298
}
299299
/* This does not automatically impl Send because the host
300300
* address of the shared memory region is a raw pointer, which are
@@ -316,7 +316,7 @@ impl HypervWindowsDriver {
316316
mmap_file_handle: HandleWrapper,
317317
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
318318
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
319-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
319+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
320320
) -> Result<Self> {
321321
// create and setup hypervisor partition
322322
let mut partition = VMPartition::new(1)?;
@@ -370,7 +370,7 @@ impl HypervWindowsDriver {
370370
gdb_conn,
371371
#[cfg(crashdump)]
372372
rt_cfg,
373-
#[cfg(feature = "trace_guest")]
373+
#[cfg(feature = "mem_profile")]
374374
trace_info,
375375
};
376376

@@ -694,7 +694,7 @@ impl Hypervisor for HypervWindowsDriver {
694694
padded[..copy_len].copy_from_slice(&data[..copy_len]);
695695
let val = u32::from_le_bytes(padded);
696696

697-
#[cfg(feature = "trace_guest")]
697+
#[cfg(feature = "mem_profile")]
698698
{
699699
// We need to handle the borrow checker issue where we need both:
700700
// - &mut MemMgrWrapper (from self.mem_mgr.as_mut())
@@ -715,7 +715,7 @@ impl Hypervisor for HypervWindowsDriver {
715715
self.mem_mgr = Some(mem_mgr);
716716
}
717717

718-
#[cfg(not(feature = "trace_guest"))]
718+
#[cfg(not(feature = "mem_profile"))]
719719
{
720720
let mem_mgr = self
721721
.mem_mgr
@@ -1093,7 +1093,7 @@ impl Hypervisor for HypervWindowsDriver {
10931093
}
10941094

10951095
#[cfg(feature = "mem_profile")]
1096-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
1096+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
10971097
&mut self.trace_info
10981098
}
10991099
}

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ use crate::sandbox::SandboxConfiguration;
4848
use crate::sandbox::host_funcs::FunctionRegistry;
4949
use crate::sandbox::mem_mgr::MemMgrWrapper;
5050
use crate::sandbox::outb::handle_outb;
51-
#[cfg(feature = "trace_guest")]
52-
use crate::sandbox::trace::TraceInfo;
51+
#[cfg(feature = "mem_profile")]
52+
use crate::sandbox::trace::MemTraceInfo;
5353
#[cfg(crashdump)]
5454
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
5555
use crate::{Result, log_then_return, new_error};
@@ -305,9 +305,9 @@ pub(crate) struct KVMDriver {
305305
gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
306306
#[cfg(crashdump)]
307307
rt_cfg: SandboxRuntimeConfig,
308-
#[cfg(feature = "trace_guest")]
308+
#[cfg(feature = "mem_profile")]
309309
#[allow(dead_code)]
310-
trace_info: TraceInfo,
310+
trace_info: MemTraceInfo,
311311
}
312312

313313
impl KVMDriver {
@@ -325,7 +325,7 @@ impl KVMDriver {
325325
config: &SandboxConfiguration,
326326
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
327327
#[cfg(crashdump)] rt_cfg: SandboxRuntimeConfig,
328-
#[cfg(feature = "trace_guest")] trace_info: TraceInfo,
328+
#[cfg(feature = "mem_profile")] trace_info: MemTraceInfo,
329329
) -> Result<Self> {
330330
let kvm = Kvm::new()?;
331331

@@ -398,7 +398,7 @@ impl KVMDriver {
398398
gdb_conn,
399399
#[cfg(crashdump)]
400400
rt_cfg,
401-
#[cfg(feature = "trace_guest")]
401+
#[cfg(feature = "mem_profile")]
402402
trace_info,
403403
};
404404

@@ -619,7 +619,7 @@ impl Hypervisor for KVMDriver {
619619
padded[..copy_len].copy_from_slice(&data[..copy_len]);
620620
let value = u32::from_le_bytes(padded);
621621

622-
#[cfg(feature = "trace_guest")]
622+
#[cfg(feature = "mem_profile")]
623623
{
624624
// We need to handle the borrow checker issue where we need both:
625625
// - &mut MemMgrWrapper (from self.mem_mgr.as_mut())
@@ -640,7 +640,7 @@ impl Hypervisor for KVMDriver {
640640
self.mem_mgr = Some(mem_mgr);
641641
}
642642

643-
#[cfg(not(feature = "trace_guest"))]
643+
#[cfg(not(feature = "mem_profile"))]
644644
{
645645
let mem_mgr = self
646646
.mem_mgr
@@ -1033,7 +1033,7 @@ impl Hypervisor for KVMDriver {
10331033
}
10341034

10351035
#[cfg(feature = "mem_profile")]
1036-
fn trace_info_mut(&mut self) -> &mut TraceInfo {
1036+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo {
10371037
&mut self.trace_info
10381038
}
10391039
}

src/hyperlight_host/src/hypervisor/mod.rs

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

2828
/// Architecture-specific code for the hypervisor.
@@ -239,7 +239,7 @@ pub(crate) trait Hypervisor: Debug + Send {
239239

240240
/// Get a mutable reference of the trace info for the guest
241241
#[cfg(feature = "mem_profile")]
242-
fn trace_info_mut(&mut self) -> &mut TraceInfo;
242+
fn trace_info_mut(&mut self) -> &mut MemTraceInfo;
243243
}
244244

245245
/// 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
@@ -26,7 +26,7 @@ use tracing_log::format_trace;
2626

2727
use super::host_funcs::FunctionRegistry;
2828
use super::mem_mgr::MemMgrWrapper;
29-
#[cfg(feature = "trace_guest")]
29+
#[cfg(feature = "mem_profile")]
3030
use crate::hypervisor::Hypervisor;
3131
use crate::mem::mgr::SandboxMemoryManager;
3232
use crate::mem::shared_mem::HostSharedMemory;
@@ -149,7 +149,7 @@ fn outb_abort(mem_mgr: &mut MemMgrWrapper<HostSharedMemory>, data: u32) -> Resul
149149
pub(crate) fn handle_outb(
150150
mem_mgr: &mut MemMgrWrapper<HostSharedMemory>,
151151
host_funcs: Arc<Mutex<FunctionRegistry>>,
152-
#[cfg(feature = "trace_guest")] _hv: &mut dyn Hypervisor,
152+
#[cfg(feature = "mem_profile")] _hv: &mut dyn Hypervisor,
153153
port: u16,
154154
data: u32,
155155
) -> Result<()> {

0 commit comments

Comments
 (0)