From ea2c089b035d6dfe6dfd04501cbc54b4b2197f25 Mon Sep 17 00:00:00 2001 From: Shupei Fan Date: Thu, 5 Sep 2024 13:30:35 +0000 Subject: [PATCH] [difftest] add "success" field in perf.json It indicates "online dpi" finishes normally , rather than terminated due to timeout. --- difftest/dpi_common/src/util.rs | 5 +++-- difftest/dpi_t1/src/dpi.rs | 4 +++- difftest/dpi_t1/src/drive.rs | 3 +++ difftest/dpi_t1rocket/src/dpi.rs | 4 +++- difftest/dpi_t1rocket/src/drive.rs | 3 +++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/difftest/dpi_common/src/util.rs b/difftest/dpi_common/src/util.rs index 282b367fc..c1302c241 100644 --- a/difftest/dpi_common/src/util.rs +++ b/difftest/dpi_common/src/util.rs @@ -1,9 +1,10 @@ //! utility functions -pub fn write_perf_json(cycle: u64) { +pub fn write_perf_json(cycle: u64, success: bool) { let mut content = String::new(); content += "{\n"; - content += &format!(" \"total_cycles\": {cycle}\n"); + content += &format!(" \"total_cycles\": {cycle},\n"); + content += &format!(" \"success\": {success}\n"); content += "}\n"; match std::fs::write("perf.json", &content) { diff --git a/difftest/dpi_t1/src/dpi.rs b/difftest/dpi_t1/src/dpi.rs index d24defd9e..34094905b 100644 --- a/difftest/dpi_t1/src/dpi.rs +++ b/difftest/dpi_t1/src/dpi.rs @@ -231,7 +231,9 @@ unsafe extern "C" fn t1_cosim_init() { #[no_mangle] unsafe extern "C" fn t1_cosim_final() { - dpi_common::util::write_perf_json(crate::get_t()); + TARGET.with(|driver| { + dpi_common::util::write_perf_json(crate::get_t(), driver.success); + }) } /// evaluate at every 1024 cycles, return reason = 0 to continue simulation, diff --git a/difftest/dpi_t1/src/drive.rs b/difftest/dpi_t1/src/drive.rs index be1102774..8a39ffc94 100644 --- a/difftest/dpi_t1/src/drive.rs +++ b/difftest/dpi_t1/src/drive.rs @@ -103,6 +103,7 @@ pub(crate) struct Driver { scope: SvScope, dump_control: DumpControl, + pub(crate) success: bool, pub(crate) dlen: u32, @@ -132,6 +133,7 @@ impl Driver { scope, dump_control, + success: false, dlen: args.dlen, timeout: args.timeout, @@ -261,6 +263,7 @@ impl Driver { get_t(), se.pc ); + self.success = true; IssueData { meta: ISSUE_EXIT, ..Default::default() } } else { self.spike_runner.commit_queue.pop_back(); diff --git a/difftest/dpi_t1rocket/src/dpi.rs b/difftest/dpi_t1rocket/src/dpi.rs index c522a34fc..a7b82f000 100644 --- a/difftest/dpi_t1rocket/src/dpi.rs +++ b/difftest/dpi_t1rocket/src/dpi.rs @@ -284,7 +284,9 @@ unsafe extern "C" fn t1rocket_cosim_init() { #[no_mangle] unsafe extern "C" fn t1rocket_cosim_final() { - dpi_common::util::write_perf_json(crate::get_t()); + TARGET.with(|driver| { + dpi_common::util::write_perf_json(crate::get_t(), driver.success); + }); } /// evaluate at every 1024 cycles, return reason = 0 to continue simulation, diff --git a/difftest/dpi_t1rocket/src/drive.rs b/difftest/dpi_t1rocket/src/drive.rs index af72cf530..68b38ae16 100644 --- a/difftest/dpi_t1rocket/src/drive.rs +++ b/difftest/dpi_t1rocket/src/drive.rs @@ -121,6 +121,7 @@ pub(crate) struct Driver { shadow_mem: ShadowMem, pub(crate) quit: bool, + pub(crate) success: bool, } impl Driver { @@ -142,6 +143,7 @@ impl Driver { shadow_mem, quit: false, + success: false, } } @@ -305,6 +307,7 @@ impl Driver { let exit_data_slice = data[..4].try_into().expect("slice with incorrect length"); if u32::from_le_bytes(exit_data_slice) == EXIT_CODE { info!("driver is ready to quit"); + self.success = true; self.quit = true; } }