From 76fcdf2ca082ff871d6d5a958d3d262a09fd2676 Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Fri, 8 Nov 2024 22:33:20 +0800 Subject: [PATCH] [difftest] use `t1_max_commit_interval_coefficient` instead of `t1_timeout` --- difftest/dpi_t1emu/src/dpi.rs | 4 ---- difftest/dpi_t1emu/src/drive.rs | 12 ++++++++---- difftest/dpi_t1emu/src/lib.rs | 24 ++++++++++++++---------- difftest/dpi_t1rocketemu/src/drive.rs | 8 ++++---- difftest/dpi_t1rocketemu/src/lib.rs | 17 ++++++++++------- script/emu/src/Main.scala | 6 +++--- t1rocketemu/vsrc/ClockGen.sv | 2 +- 7 files changed, 40 insertions(+), 33 deletions(-) diff --git a/difftest/dpi_t1emu/src/dpi.rs b/difftest/dpi_t1emu/src/dpi.rs index 9ee11666a..74004db96 100644 --- a/difftest/dpi_t1emu/src/dpi.rs +++ b/difftest/dpi_t1emu/src/dpi.rs @@ -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, diff --git a/difftest/dpi_t1emu/src/drive.rs b/difftest/dpi_t1emu/src/drive.rs index ce9b71067..4653679a1 100644 --- a/difftest/dpi_t1emu/src/drive.rs +++ b/difftest/dpi_t1emu/src/drive.rs @@ -105,7 +105,7 @@ pub(crate) struct Driver { pub(crate) dlen: u32, - timeout: u64, + max_commit_interval: u64, // driver state last_commit_cycle: u64, @@ -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, @@ -204,6 +204,10 @@ 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 { @@ -211,9 +215,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; diff --git a/difftest/dpi_t1emu/src/lib.rs b/difftest/dpi_t1emu/src/lib.rs index b2b0344e6..9f1b76116 100644 --- a/difftest/dpi_t1emu/src/lib.rs +++ b/difftest/dpi_t1emu/src/lib.rs @@ -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, } } } diff --git a/difftest/dpi_t1rocketemu/src/drive.rs b/difftest/dpi_t1rocketemu/src/drive.rs index b20fb46c3..a9b643115 100644 --- a/difftest/dpi_t1rocketemu/src/drive.rs +++ b/difftest/dpi_t1rocketemu/src/drive.rs @@ -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, @@ -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, @@ -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; diff --git a/difftest/dpi_t1rocketemu/src/lib.rs b/difftest/dpi_t1rocketemu/src/lib.rs index 8709fbd2c..bc7e0ae84 100644 --- a/difftest/dpi_t1rocketemu/src/lib.rs +++ b/difftest/dpi_t1rocketemu/src/lib.rs @@ -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, } } } diff --git a/script/emu/src/Main.scala b/script/emu/src/Main.scala index 4fc68e5d8..fc4de7426 100644 --- a/script/emu/src/Main.scala +++ b/script/emu/src/Main.scala @@ -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") @@ -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) diff --git a/t1rocketemu/vsrc/ClockGen.sv b/t1rocketemu/vsrc/ClockGen.sv index 5d80dab4e..be2d13b41 100644 --- a/t1rocketemu/vsrc/ClockGen.sv +++ b/t1rocketemu/vsrc/ClockGen.sv @@ -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