Skip to content

Commit

Permalink
[difftest] use t1_max_commit_interval_coefficient instead of `t1_ti…
Browse files Browse the repository at this point in the history
…meout`
  • Loading branch information
Clo91eaf committed Nov 8, 2024
1 parent 1f41e75 commit afaeb18
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
4 changes: 0 additions & 4 deletions difftest/dpi_t1emu/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ pub static ISSUE_VALID: u32 = 1;
pub static ISSUE_FENCE: u32 = 2;
pub static ISSUE_EXIT: u32 = 3;

pub static WATCHDOG_CONTINUE: u8 = 0;
pub static WATCHDOG_TIMEOUT: u8 = 1;
pub static WATCHDOG_QUIT: u8 = 255;

#[repr(C, packed)]
pub(crate) struct Retire {
pub vxsat: u32,
Expand Down
12 changes: 8 additions & 4 deletions difftest/dpi_t1emu/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(crate) struct Driver {

pub(crate) dlen: u32,

timeout: u64,
max_commit_interval: u64,

// driver state
last_commit_cycle: u64,
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Driver {
success: false,

dlen: args.dlen,
timeout: args.timeout,
max_commit_interval: args.max_commit_interval,
last_commit_cycle: 0,

issued: 0,
Expand Down Expand Up @@ -204,16 +204,20 @@ impl Driver {
}

pub(crate) fn watchdog(&mut self) -> u8 {
const WATCHDOG_CONTINUE: u8 = 0;
const WATCHDOG_TIMEOUT: u8 = 1;
const WATCHDOG_QUIT: u8 = 255;

let tick = get_t();

if self.success {
trace!("[{tick}] watchdog quit");
return WATCHDOG_QUIT;
}

if tick - self.last_commit_cycle > self.timeout {
if tick - self.last_commit_cycle > self.max_commit_interval {
error!(
"[{tick}] watchdog timeout (last_commit_cycle={})",
"[{tick}] watchdog timeout since last commit (last_commit_cycle={})",
self.last_commit_cycle
);
return WATCHDOG_TIMEOUT;
Expand Down
24 changes: 14 additions & 10 deletions difftest/dpi_t1emu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ pub(crate) struct OnlineArgs {
/// ISA config
pub set: String,

// default to TIMEOUT_DEFAULT
pub timeout: u64,
// default to max_commit_interval * vlen / dlen
pub max_commit_interval: u64,
}

const TIMEOUT_DEFAULT: u64 = 100000000;
const MAX_COMMIT_INTERVAL_COEFFICIENT: u64 = 10_0000;

impl OnlineArgs {
pub fn from_plusargs(matcher: &PlusArgMatcher) -> Self {
let vlen = env!("DESIGN_VLEN").parse().unwrap();
let dlen = env!("DESIGN_DLEN").parse().unwrap();
let max_commit_interval_coefficient = matcher
.try_match("t1_max_commit_interval_coefficient")
.map(|x| x.parse().unwrap())
.unwrap_or(MAX_COMMIT_INTERVAL_COEFFICIENT);
let max_commit_interval = max_commit_interval_coefficient * vlen / dlen;

Self {
elf_file: matcher.match_("t1_elf_file").into(),
log_file: matcher.try_match("t1_log_file").map(|x| x.into()),

vlen: env!("DESIGN_VLEN").parse().unwrap(),
dlen: env!("DESIGN_DLEN").parse().unwrap(),
vlen,
dlen,
set: env!("SPIKE_ISA_STRING").parse().unwrap(),
timeout: matcher
.try_match("t1_timeout")
.map(|x| x.parse().unwrap())
.unwrap_or(TIMEOUT_DEFAULT),
max_commit_interval,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions difftest/dpi_t1rocketemu/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) struct Driver {
pub(crate) dlen: u32,
pub(crate) e_entry: u64,

timeout: u64,
max_commit_interval: u64,
last_commit_cycle: u64,

shadow_bus: ShadowBus,
Expand All @@ -53,7 +53,7 @@ impl Driver {
dlen: args.dlen,
e_entry,

timeout: args.timeout,
max_commit_interval: args.max_commit_interval,
last_commit_cycle: 0,

shadow_bus,
Expand Down Expand Up @@ -254,9 +254,9 @@ impl Driver {
return WATCHDOG_QUIT;
}

if tick - self.last_commit_cycle > self.timeout {
if tick - self.last_commit_cycle > self.max_commit_interval {
error!(
"[{tick}] watchdog timeout (last_commit_cycle={})",
"[{tick}] watchdog timeout since last commit (last_commit_cycle={})",
self.last_commit_cycle
);
return WATCHDOG_TIMEOUT;
Expand Down
17 changes: 10 additions & 7 deletions difftest/dpi_t1rocketemu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ pub(crate) struct OnlineArgs {
/// dlen config
pub dlen: u32,

// default to TIMEOUT_DEFAULT
pub timeout: u64,
// default to max_commit_interval
pub max_commit_interval: u64,
}

const TIMEOUT_DEFAULT: u64 = 100000000;
const MAX_COMMIT_INTERVAL_COEFFICIENT: u64 = 10_0000;

impl OnlineArgs {
pub fn from_plusargs(matcher: &PlusArgMatcher) -> Self {
let max_commit_interval_coefficient = matcher
.try_match("t1_max_commit_interval_coefficient")
.map(|x| x.parse().unwrap())
.unwrap_or(MAX_COMMIT_INTERVAL_COEFFICIENT);
let max_commit_interval = max_commit_interval_coefficient;

Self {
elf_file: matcher.match_("t1_elf_file").into(),
dlen: env!("DESIGN_DLEN").parse().unwrap(),
timeout: matcher
.try_match("t1_timeout")
.map(|x| x.parse().unwrap())
.unwrap_or(TIMEOUT_DEFAULT),
max_commit_interval,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ object Main:
doc = "Print the final emulator command line and exit"
) dryRun: Flag = Flag(false),
@arg(
name = "timeout",
name = "max-commit-interval-coefficient",
doc = "Specify maximum cycle count limit"
) timeout: Option[Int] = None,
) maxCommitIntervalCoefficient: Option[Int] = None,
leftOver: Leftover[String]
): Unit =
if leftOver.value.isEmpty then Logger.fatal("No test case name")
Expand Down Expand Up @@ -219,7 +219,7 @@ object Main:
emulator.toString(),
s"+t1_elf_file=${caseElfPath}"
)
++ optionals(timeout.isDefined, Seq(s"+t1_timeout=${timeout.getOrElse("unreachable")}"))
++ optionals(maxCommitIntervalCoefficient.isDefined, Seq(s"+t1_max_commit_interval_coefficient=${maxCommitIntervalCoefficient.getOrElse("unreachable")}"))
++ optionals(isTrace, Seq(s"+t1_wave_path=${outputPath / "wave.fsdb"}"))
++ optionals(isCover, Seq(s"-cm assert"))
++ optionals(!leftOverArguments.isEmpty, leftOverArguments)
Expand Down
2 changes: 1 addition & 1 deletion t1rocketemu/vsrc/ClockGen.sv
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module ClockGen(

// Args:
// +t1_elf_file=... : path of elf file
// +t1_timeout=... : (optional) max interval of inst commit, counted in cycle
// +t1_max_commit_interval_coefficient=... : (optional) max interval of inst commit, counted in cycle
t1_cosim_init();

`ifdef T1_ENABLE_TRACE
Expand Down

0 comments on commit afaeb18

Please sign in to comment.