Skip to content

Commit

Permalink
Seperate common scope for later interface, format Code
Browse files Browse the repository at this point in the history
  • Loading branch information
klin02 committed Nov 25, 2024
1 parent 11970f8 commit 99c63ad
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,12 @@ 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
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 +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
42 changes: 24 additions & 18 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
32 changes: 19 additions & 13 deletions src/test/vsrc/vcs/DifftestEndpoint.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99c63ad

Please sign in to comment.