From 99c63adcefbeab907201c03df6710a135882db16 Mon Sep 17 00:00:00 2001 From: klin02 Date: Mon, 25 Nov 2024 16:46:30 +0800 Subject: [PATCH] Seperate common scope for later interface, format Code --- .github/workflows/main.yml | 4 +-- src/test/csrc/vcs/vcs_main.cpp | 42 ++++++++++++++++------------ src/test/vsrc/vcs/DifftestEndpoint.v | 32 ++++++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a73ff681f..804d4cf0f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -451,7 +451,7 @@ jobs: make simv VCS=verilator WITH_CHISELDB=0 WITH_CONSTANTIN=0 IOTRACE_ZSTD=1 ./build/simv +workload=../ready-to-run/microbench.bin +e=0 +diff=../ready-to-run/riscv64-nemu-interpreter-so +iotrace-name=../iotrace - - name: Verilator Build with VCS Top (with LogPerfHelper and Warmup) + - name: Verilator Build with VCS Top (with LogPerf and WarmUp) run : | cd $GITHUB_WORKSPACE/../xs-env source ./env.sh @@ -459,4 +459,4 @@ jobs: source ./env.sh make clean make simv VCS=verilator -j2 - ./build/simv +workload=./ready-to-run/microbench.bin +b=0 +e=-1 +max-instrs=5000 +warmup-inst=1000 +diff=./ready-to-run/riscv64-nemu-interpreter-so + ./build/simv +workload=./ready-to-run/microbench.bin +b=0 +e=-1 +diff=./ready-to-run/riscv64-nemu-interpreter-so +max-instrs=5000 +warmup_instr=1000 diff --git a/src/test/csrc/vcs/vcs_main.cpp b/src/test/csrc/vcs/vcs_main.cpp index 32e1edaae..3088cdaba 100644 --- a/src/test/csrc/vcs/vcs_main.cpp +++ b/src/test/csrc/vcs/vcs_main.cpp @@ -42,8 +42,8 @@ static bool enable_difftest = true; static uint64_t max_instrs = 0; static char *workload_list = NULL; static uint32_t overwrite_nbytes = 0xe00; -static uint64_t warmup_instrs = 0; -static svScope wamupScope; +static uint64_t warmup_instr = 0; +static svScope difftest_endpoint_scope; struct core_end_info_t { bool core_trap[NUM_CORES]; double core_cpi[NUM_CORES]; @@ -57,8 +57,6 @@ enum { SIMV_FAIL, } simv_state; -extern "C" void clear_perfcnt(); - extern "C" void set_bin_file(char *s) { printf("ram image:%s\n", s); strcpy(bin_file, s); @@ -86,15 +84,10 @@ extern "C" void set_overwrite_autoset() { fclose(fp); } -// The workload warms up and clears the instruction counter -extern "C" void set_warmup_insts(uint64_t warmup_inst) { - warmup_instrs = warmup_inst; - wamupScope = svGetScope(); - if (wamupScope == NULL) { - printf("Error: Could not retrieve wamup scope, set first\n"); - assert(wamupScope); - } - printf("set warmp insts %ld\n", warmup_inst); +// Support workload warms up and clean LogPerf after warmup instrs +extern "C" void set_warmup_instr(uint64_t instrs) { + warmup_instr = instrs; + printf("Warmup instrs:%ld\n", instrs); } extern "C" void set_gcpt_bin(char *s) { @@ -107,6 +100,10 @@ extern "C" void set_max_instrs(uint64_t mc) { max_instrs = mc; } +extern "C" void set_difftest_endpoint_scope() { + difftest_endpoint_scope = svGetScope(); +} + extern "C" uint64_t get_stuck_limit() { #ifdef CONFIG_NO_DIFFTEST return 0; @@ -174,6 +171,17 @@ extern "C" void set_simjtag() { enable_simjtag = true; } +extern "C" void set_perfCtrl_clean(); + +void difftest_perfCtrl_clean() { + if (difftest_endpoint_scope == NULL) { + printf("Error: Could not retrieve DifftestEndpoint scope, set first\n"); + assert(difftest_endpoint_scope); + } + svSetScope(difftest_endpoint_scope); + set_perfCtrl_clean(); +} + extern "C" uint8_t simv_init() { if (workload_list != NULL) { if (switch_workload()) @@ -254,12 +262,10 @@ extern "C" uint8_t simv_step() { for (int i = 0; i < NUM_CORES; i++) { auto trap = difftest[i]->get_trap_event(); - if (warmup_instrs != 0 && trap->instrCnt > warmup_instrs) { - svSetScope(wamupScope); - clear_perfcnt(); - warmup_instrs = 0; + if (warmup_instr != 0 && trap->instrCnt > warmup_instr) { + difftest_perfCtrl_clean(); + warmup_instr = 0; Info("Warmup finished. The performance counters will be reset.\n"); - eprintf("core-%d warmup-cycle %ld warmup-instrs %ld\n", i, trap->cycleCnt, trap->instrCnt); } if (max_instrs != 0) { // 0 for no limit diff --git a/src/test/vsrc/vcs/DifftestEndpoint.v b/src/test/vsrc/vcs/DifftestEndpoint.v index eeae96081..ff58e99a6 100644 --- a/src/test/vsrc/vcs/DifftestEndpoint.v +++ b/src/test/vsrc/vcs/DifftestEndpoint.v @@ -50,7 +50,8 @@ import "DPI-C" function void set_max_instrs(longint mc); import "DPI-C" function longint get_stuck_limit(); import "DPI-C" function void set_overwrite_nbytes(longint len); import "DPI-C" function void set_overwrite_autoset(); -import "DPI-C" context function void set_warmup_insts(longint workload_inst); +import "DPI-C" function void set_warmup_instr(longint instrs); +import "DPI-C" context function void set_difftest_endpoint_scope(); `ifdef WITH_DRAMSIM3 import "DPI-C" function void simv_tick(); `endif // WITH_DRAMSIM3 @@ -82,7 +83,7 @@ longint overwrite_nbytes; reg [63:0] max_instrs; reg [63:0] max_cycles; -reg [63:0] warmup_instrs; +reg [63:0] warmup_instr; reg [63:0] stuck_limit; initial begin @@ -102,17 +103,18 @@ initial begin end stuck_limit = 0; `ifndef TB_NO_DPIC + set_difftest_endpoint_scope(); stuck_limit = get_stuck_limit(); - warmup_instrs = 0; // workload: bin file if ($test$plusargs("workload")) begin $value$plusargs("workload=%s", bin_file); set_bin_file(bin_file); end // warmup for instrs - if ($test$plusargs("warmup-inst")) begin - $value$plusargs("warmup-inst=%d", warmup_instrs); - set_warmup_insts(warmup_instrs); + warmup_instr = 0; + if ($test$plusargs("warmup_instr")) begin + $value$plusargs("warmup_instr=%d", warmup_instr); + set_warmup_instr(warmup_instr); end // boot flash image: bin file if ($test$plusargs("flash")) begin @@ -178,21 +180,25 @@ initial begin end end -reg dpic_perfCtrl_clean; +reg difftest_perfCtrl_clean_r; assign difftest_logCtrl_begin = difftest_logCtrl_begin_r; assign difftest_logCtrl_end = difftest_logCtrl_end_r; assign difftest_logCtrl_level = 0; -assign difftest_perfCtrl_clean = dpic_perfCtrl_clean; +assign difftest_perfCtrl_clean = difftest_perfCtrl_clean_r; assign difftest_uart_in_ch = 8'hff; -export "DPI-C" task clear_perfcnt; -task clear_perfcnt(); - dpic_perfCtrl_clean = 1'b1; +export "DPI-C" task set_perfCtrl_clean; +task set_perfCtrl_clean(); + difftest_perfCtrl_clean_r <= 1'b1; endtask always @(posedge clock) begin - if (dpic_perfCtrl_clean == 1'b1) - dpic_perfCtrl_clean = 1'b0; + if (reset) begin + difftest_perfCtrl_clean_r <= 1'b0; + end + else if (difftest_perfCtrl_clean_r) begin + difftest_perfCtrl_clean_r <= 1'b0; + end end always @(posedge clock) begin