Skip to content

Commit

Permalink
vcs: add the versatility of soft reset
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokamikami committed Feb 23, 2024
1 parent bd9168b commit 1abfe14
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
47 changes: 22 additions & 25 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ static char *flash_bin_file = NULL;
static bool enable_difftest = true;
static uint64_t max_instrs = 0;

static int checkpoint_reset (char * file_name);
static char *checkpoint_list_path = NULL;
static uint32_t checkpoin_idx = 0;
static int ram_path_reset(char *file_name);
static char *work_load_list_path = NULL;

extern "C" void set_bin_file(char *s) {
printf("ram image:%s\n",s);
Expand All @@ -65,9 +64,9 @@ extern "C" void set_diff_ref_so(char *s) {
}

extern "C" void difftest_checkpoint_list (char * path) {
checkpoint_list_path = (char *)malloc(256);
strcpy(checkpoint_list_path,path);
printf("set checkpoint list path %s \n",checkpoint_list_path);
work_load_list_path = (char *)malloc(256);
strcpy(work_load_list_path, path);
printf("set checkpoint list path %s \n", work_load_list_path);
}

extern "C" void set_no_diff() {
Expand Down Expand Up @@ -159,7 +158,7 @@ extern "C" void simv_nstep(uint8_t step) {
break;
}
}
if (simv_result && checkpoint_list_path == NULL) {
if (simv_result && work_load_list_path == NULL) {
difftest_finish();
difftest_deferred_result();
}
Expand All @@ -174,7 +173,7 @@ extern "C" int simv_nstep(uint8_t step) {
for(int i = 0; i < step; i++) {
int ret = simv_step();
if(ret) {
if (checkpoint_list_path == NULL) {
if (work_load_list_path == NULL) {
difftest_finish();
}
return ret;
Expand All @@ -184,18 +183,18 @@ extern "C" int simv_nstep(uint8_t step) {
}
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT

static uint64_t checkpoint_list_head = 0;
static uint64_t work_load_list_head = 0;
extern "C" char difftest_ram_reload() {
assert(checkpoint_list_path);
assert(work_load_list_path);

FILE * fp = fopen(checkpoint_list_path,"r");
FILE * fp = fopen(work_load_list_path, "r");
char file_name[128] = {0};
if (fp == nullptr) {
printf("Can't open fp file '%s'", checkpoint_list_path);
printf("Can't open fp file '%s'", work_load_list_path);
return 1;
}

fseek(fp, checkpoint_list_head, SEEK_SET);
fseek(fp, work_load_list_head, SEEK_SET);

if (feof(fp)) {
printf("the fp no more checkpoint \n");
Expand All @@ -205,9 +204,9 @@ extern "C" char difftest_ram_reload() {
return 1;
}

checkpoint_list_head = checkpoint_list_head + strlen(file_name);
work_load_list_head = work_load_list_head + strlen(file_name);

if (checkpoint_reset(file_name)) {
if (ram_path_reset(file_name)) {
return 1;
}

Expand All @@ -219,23 +218,21 @@ extern "C" char difftest_ram_reload() {
return 0;
}

static int checkpoint_reset (char * file_name) {
static int ram_path_reset(char *file_name) {
int line_len = strlen(file_name);

if(file_name[0] == '\0') {
return 1;
}

if ('\n' == file_name[line_len - 1]) {
file_name[line_len - 1] = '\0';
}
char * str1 = strrchr(file_name, '/');
if (str1 != NULL)
str1 ++;
else
return 1;

if (sscanf(str1,"_%d_0.%ld_.gz", &checkpoin_idx, &max_instrs) != 2) {
printf("get max instrs error \n");
assert(0);
if (sscanf(file_name, "%s %ld", &bin_file, &max_instrs) != 2) {
printf("no more work load\n");
return 1;
}

strcpy(bin_file, file_name);
return 0;
}
30 changes: 15 additions & 15 deletions src/test/vsrc/vcs/top.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "DPI-C" function void set_diff_ref_so(string diff_so);
import "DPI-C" function void set_no_diff();
import "DPI-C" function void simv_init();
import "DPI-C" function void set_max_instrs(longint mc);
import "DPI-C" function void difftest_checkpoint_list(string path);
import "DPI-C" function void difftest_workload_list(string path);
import "DPI-C" function byte difftest_ram_reload();
`ifndef CONFIG_DIFFTEST_DEFERRED_RESULT
import "DPI-C" function int simv_nstep(int step);
Expand Down Expand Up @@ -60,13 +60,13 @@ string bin_file;
string flash_bin_file;
string wave_type;
string diff_ref_so;
string ckpt_list;
string workload_list;

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

reg ckpt_list_en;
reg xs_rst_en;
reg workload_list_en;
reg soft_rst_en;

initial begin
`ifndef WIRE_CLK
Expand Down Expand Up @@ -129,11 +129,11 @@ initial begin
if ($test$plusargs("no-diff")) begin
set_no_diff();
end
// set checkpoint run list
if ($test$plusargs("ckpt-list")) begin
$value$plusargs("ckpt-list=%s", ckpt_list);
difftest_checkpoint_list(ckpt_list);
ckpt_list_en = 1;
// set workload run list
if ($test$plusargs("workload-list")) begin
$value$plusargs("workload-list=%s", workload_list);
difftest_workload_list(workload_list);
workload_list_en = 1;
end
`endif // TB_NO_DPIC
// max cycles to execute, no limit for default
Expand All @@ -158,7 +158,7 @@ end
reg [7:0] reset_counter;
initial reset_counter = 0;
always @(posedge clock) begin
if (xs_rst_en) begin
if (soft_rst_en) begin
reset_counter <= 8'd0;
reset <= 1'b1;
$display("soft rst CPU core");
Expand Down Expand Up @@ -224,9 +224,9 @@ reg [63:0] n_cycles;
always @(posedge clock) begin
if (reset) begin
n_cycles <= 64'h0;
xs_rst_en<= 1'b0;
soft_rst_en<= 1'b0;
end
else if(!xs_rst_en) begin
else if(!soft_rst_en) begin
n_cycles <= n_cycles + 64'h1;

// max cycles
Expand All @@ -243,8 +243,8 @@ always @(posedge clock) begin
`ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
else if (simv_result) begin
$display("DIFFTEST FAILED at cycle %d", n_cycles);
if (simv_result == STATE_LIMIT_EXCEEDED && ckpt_list_en == 1'b1)begin
xs_rst_en <= 1'b1;
if (simv_result == STATE_LIMIT_EXCEEDED && workload_list_en == 1'b1)begin
soft_rst_en <= 1'b1;
end
else begin
$finish();
Expand All @@ -266,7 +266,7 @@ end
`ifndef TB_NO_DPIC
//soft rst
always @(posedge clock)begin
if (!reset & xs_rst_en) begin
if (!reset & soft_rst_en) begin
if(difftest_ram_reload() == 8'd1) begin
$display("run checkpoint end");
$finish();
Expand Down

0 comments on commit 1abfe14

Please sign in to comment.