Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vcs, palldium: support warmup, set difftest_perfCtrl_clean by DPI-C #506

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,13 @@ jobs:
make difftest_verilog PROFILE=../build/generated-src/difftest_profile.json NUMCORES=1 CONFIG=ZEL MFC=1
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 LogPerf and WarmUp)
run : |
cd $GITHUB_WORKSPACE/../xs-env
source ./env.sh
cd $GITHUB_WORKSPACE/../xs-env/NutShell
source ./env.sh
make clean
make simv VCS=verilator -j2
./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
39 changes: 33 additions & 6 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
#ifndef CONFIG_NO_DIFFTEST
#include "refproxy.h"
#endif // CONFIG_NO_DIFFTEST
#include "svdpi.h"
#include <common.h>
#include <locale.h>
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
#include "svdpi.h"
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT
#ifdef CONFIG_DIFFTEST_PERFCNT
#include "perf.h"
#endif // CONFIG_DIFFTEST_PERFCNT
Expand All @@ -44,6 +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_instr = 0;
static svScope difftest_endpoint_scope;
struct core_end_info_t {
bool core_trap[NUM_CORES];
double core_cpi[NUM_CORES];
Expand Down Expand Up @@ -84,6 +84,12 @@ extern "C" void set_overwrite_autoset() {
fclose(fp);
}

// 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) {
gcpt_restore_bin = (char *)malloc(256);
strcpy(gcpt_restore_bin, s);
Expand All @@ -94,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;
Expand Down Expand Up @@ -161,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())
Expand Down Expand Up @@ -239,11 +260,17 @@ extern "C" uint8_t simv_step() {
return SIMV_FAIL;
}

if (max_instrs != 0) { // 0 for no limit
for (int i = 0; i < NUM_CORES; i++) {
for (int i = 0; i < NUM_CORES; i++) {
auto trap = difftest[i]->get_trap_event();
if (warmup_instr != 0 && trap->instrCnt > warmup_instr) {
difftest_perfCtrl_clean();
warmup_instr = 0;
Info("Warmup finished. The performance counters will be reset.\n");
}

if (max_instrs != 0) { // 0 for no limit
if (core_end_info.core_trap[i])
continue;
auto trap = difftest[i]->get_trap_event();
if (max_instrs < trap->instrCnt) {
core_end_info.core_trap[i] = true;
core_end_info.core_trap_num++;
Expand Down
27 changes: 26 additions & 1 deletion src/test/vsrc/vcs/DifftestEndpoint.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +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" 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
Expand Down Expand Up @@ -81,6 +83,7 @@ longint overwrite_nbytes;

reg [63:0] max_instrs;
reg [63:0] max_cycles;
reg [63:0] warmup_instr;
reg [63:0] stuck_limit;

initial begin
Expand All @@ -100,12 +103,19 @@ initial begin
end
stuck_limit = 0;
`ifndef TB_NO_DPIC
set_difftest_endpoint_scope();
stuck_limit = get_stuck_limit();
// workload: bin file
if ($test$plusargs("workload")) begin
$value$plusargs("workload=%s", bin_file);
set_bin_file(bin_file);
end
// warmup for 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
$value$plusargs("flash=%s", flash_bin_file);
Expand Down Expand Up @@ -170,12 +180,27 @@ initial begin
end
end

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 = 0;
assign difftest_perfCtrl_clean = difftest_perfCtrl_clean_r;
assign difftest_uart_in_ch = 8'hff;

export "DPI-C" task set_perfCtrl_clean;
task set_perfCtrl_clean();
difftest_perfCtrl_clean_r <= 1'b1;
endtask

always @(posedge clock) begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use difftest_perfCtrl_clean_r for same nameing style.

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
if (!reset && difftest_uart_out_valid) begin
$fwrite(32'h8000_0001, "%c", difftest_uart_out_ch);
Expand Down