From a92965b359f077d393f2b1b18e1467ae69bd5561 Mon Sep 17 00:00:00 2001 From: Olof Kindgren Date: Tue, 20 Feb 2024 09:43:33 +0100 Subject: [PATCH] Add cycle counter to servant testbench --- bench/servant_tb.cpp | 19 +++++++++++++++++++ servant.core | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/bench/servant_tb.cpp b/bench/servant_tb.cpp index b2248473..7641ab69 100644 --- a/bench/servant_tb.cpp +++ b/bench/servant_tb.cpp @@ -5,6 +5,8 @@ #include "verilated_vcd_c.h" #include "Vservant_sim.h" +#include + using namespace std; static bool done; @@ -126,6 +128,14 @@ int main(int argc, char **argv, char **env) if (arg_vcd_start[0]) vcd_start = atoi(arg_vcd_start+11); + int cur_cycle = 0; + int last_cycle = 0; + std::time_t last_time = std::time(nullptr); + int cps_file = 0; + const char *arg_cps = Verilated::commandArgsPlusMatch("cps="); + if (arg_cps[0]) + cps_file = open("cps", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU); + bool dump = false; top->wb_clk = 1; bool q = top->q; @@ -153,7 +163,16 @@ int main(int argc, char **argv, char **env) top->wb_clk = !top->wb_clk; main_time+=31.25; + if (cps_file) { + cur_cycle++; + if (std::time(nullptr) > last_time) { + dprintf(cps_file,"%d\n", (cur_cycle-last_cycle)/2); + last_cycle = cur_cycle; + last_time++; + } + } } + close(cps_file); close(tf); if (tfp) tfp->close(); diff --git a/servant.core b/servant.core index 3909c8f2..a7f5efb5 100644 --- a/servant.core +++ b/servant.core @@ -544,6 +544,7 @@ targets: parameters : - RISCV_FORMAL - "mdu? (MDU=1)" + - cps - firmware - memsize - signature @@ -577,6 +578,11 @@ parameters: description : Enable/Disable the Compressed extension paramtype : vlogparam + cps: + datatype : bool + description: Write simulated cycles per second to a text file named cps + paramtype : plusarg + firmware: datatype : file description : Preload RAM with a hex file at runtime (overrides memfile)