Skip to content

Commit

Permalink
[difftest] add "success" field in perf.json
Browse files Browse the repository at this point in the history
It indicates "online dpi" finishes normally , rather than terminated due to timeout.
  • Loading branch information
FanShupei committed Sep 5, 2024
1 parent 7c44541 commit ea2c089
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions difftest/dpi_common/src/util.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion difftest/dpi_t1/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions difftest/dpi_t1/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub(crate) struct Driver {
scope: SvScope,

dump_control: DumpControl,
pub(crate) success: bool,

pub(crate) dlen: u32,

Expand Down Expand Up @@ -132,6 +133,7 @@ impl Driver {

scope,
dump_control,
success: false,

dlen: args.dlen,
timeout: args.timeout,
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion difftest/dpi_t1rocket/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions difftest/dpi_t1rocket/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub(crate) struct Driver {
shadow_mem: ShadowMem,

pub(crate) quit: bool,
pub(crate) success: bool,
}

impl Driver {
Expand All @@ -142,6 +143,7 @@ impl Driver {
shadow_mem,

quit: false,
success: false,
}
}

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit ea2c089

Please sign in to comment.