Skip to content

Commit

Permalink
Enable cosimulation for multicore
Browse files Browse the repository at this point in the history
  • Loading branch information
farzamgl authored and dpetrisko committed Jun 27, 2020
1 parent 9dc18c0 commit 64a7783
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 54 deletions.
10 changes: 4 additions & 6 deletions bp_top/test/common/bp_nonsynth_cosim.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module bp_nonsynth_cosim
, input freeze_i
, input en_i

, input [31:0] num_core_i
, input [`BSG_SAFE_CLOG2(num_core_p)-1:0] mhartid_i
, input [63:0] config_file_i
, input [31:0] cosim_instr_i
Expand All @@ -32,23 +33,20 @@ module bp_nonsynth_cosim
, input interrupt_v_i
, input [dword_width_p-1:0] cause_i

, output logic [num_core_p-1:0] finish_o
, output logic finish_o
);

import "DPI-C" context function void init_dromajo(string cfg_f_name);
import "DPI-C" context function void dromajo_init(string cfg_f_name, int hartid, int ncpus);
import "DPI-C" context function bit dromajo_step(int hart_id,
longint pc,
int insn,
longint wdata);
import "DPI-C" context function void dromajo_trap(int hart_id, longint cause);

logic finish;

always_ff @(negedge reset_i)
if (en_i)
begin
$display("Running with Dromajo cosimulation");
init_dromajo(config_file_i);
dromajo_init(config_file_i, mhartid_i, num_core_i);
end

bp_be_decode_s decode_r;
Expand Down
12 changes: 9 additions & 3 deletions bp_top/test/common/dromajo_cosim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
#include "stdlib.h"
#include <string>

using namespace std;

dromajo_cosim_state_t* dromajo_pointer;
uint64_t d_address = 0;
uint64_t d_count = 0;

extern "C" void init_dromajo(char* cfg_f_name) {
char *argv[] = {(char*)"Variane", cfg_f_name};
extern "C" void dromajo_init(char* cfg_f_name, int hartid, int ncpus) {

dromajo_pointer = dromajo_cosim_init(2, argv);
if(hartid == 0) {
cout << "Running with Dromajo cosimulation" << endl;
string ncpus_str = "--ncpus=" + to_string(ncpus);
char *argv[] = {(char*)"", cfg_f_name, (char*)(&ncpus_str[0])};
dromajo_pointer = dromajo_cosim_init(3, argv);
}
}

extern "C" bool dromajo_step(int hart_id,
Expand Down
80 changes: 35 additions & 45 deletions bp_top/test/tb/bp_tethered/testbench.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ module testbench

`declare_bp_me_if(paddr_width_p, cce_block_width_p, lce_id_width_p, lce_assoc_p)

initial begin
if (num_core_p > 1) begin
assert (cosim_p == 0) else $error("cosim_p not supported for num_core_p > 1");
end
end

logic [num_core_p-1:0] program_finish_lo;
logic cosim_finish_lo;
logic [num_core_p-1:0] cosim_finish_lo;

bp_cce_mem_msg_s proc_mem_cmd_lo;
logic proc_mem_cmd_v_lo, proc_mem_cmd_ready_li;
Expand Down Expand Up @@ -280,7 +274,7 @@ bind bp_be_top
,.reset_i(reset_i)
,.freeze_i(be_checker.scheduler.int_regfile.cfg_bus.freeze)

,.mhartid_i(cfg_bus.core_id)
,.mhartid_i(be_checker.scheduler.int_regfile.cfg_bus.core_id)

,.decode_i(be_calculator.reservation_n.decode)

Expand All @@ -293,43 +287,39 @@ bind bp_be_top
,.rd_data_i(be_checker.scheduler.wb_pkt.rd_data)
);

if (num_core_p == 1)
begin : cosim
bind bp_be_top
bp_nonsynth_cosim
#(.bp_params_p(bp_params_p))
cosim
(.clk_i(clk_i)
,.reset_i(reset_i)
,.freeze_i(be_checker.scheduler.int_regfile.cfg_bus.freeze)
,.en_i(testbench.cosim_p == 1)
,.cosim_instr_i(testbench.cosim_instr_p)

,.mhartid_i(be_checker.scheduler.int_regfile.cfg_bus.core_id)
// Want to pass config file as a parameter, but cannot in Verilator 4.025
// Parameter-resolved constants must not use dotted references
,.config_file_i(testbench.cosim_cfg_file_p)

,.decode_i(be_calculator.reservation_n.decode)

,.commit_v_i(be_calculator.commit_pkt.instret)
,.commit_pc_i(be_calculator.commit_pkt.pc)
,.commit_instr_i(be_calculator.commit_pkt.instr)

,.rd_w_v_i(be_checker.scheduler.wb_pkt.rd_w_v)
,.rd_addr_i(be_checker.scheduler.wb_pkt.rd_addr)
,.rd_data_i(be_checker.scheduler.wb_pkt.rd_data)

,.interrupt_v_i(be_mem.csr.trap_pkt_cast_o._interrupt)
,.cause_i(be_mem.csr.trap_pkt_cast_o.cause)

,.finish_o(testbench.cosim_finish_lo)
);
end
else
begin : no_cosim
assign cosim_finish_lo = '0;
end
bind bp_be_top
bp_nonsynth_cosim
#(.bp_params_p(bp_params_p))
cosim
(.clk_i(clk_i)
,.reset_i(reset_i)
,.freeze_i(be_checker.scheduler.int_regfile.cfg_bus.freeze)
,.en_i(testbench.cosim_p == 1)
,.cosim_instr_i(testbench.cosim_instr_p)

,.num_core_i(testbench.num_core_p)
,.mhartid_i(be_checker.scheduler.int_regfile.cfg_bus.core_id)
// Want to pass config file as a parameter, but cannot in Verilator 4.025
// Parameter-resolved constants must not use dotted references
,.config_file_i(testbench.cosim_cfg_file_p)

,.decode_i(be_calculator.reservation_n.decode)

,.commit_v_i(be_calculator.commit_pkt.instret)
,.commit_pc_i(be_calculator.commit_pkt.pc)
,.commit_instr_i(be_calculator.commit_pkt.instr)

,.rd_w_v_i(be_checker.scheduler.wb_pkt.rd_w_v)
,.rd_addr_i(be_checker.scheduler.wb_pkt.rd_addr)
,.rd_data_i(be_checker.scheduler.wb_pkt.rd_data)

,.interrupt_v_i(be_mem.csr.trap_pkt_cast_o._interrupt)
,.cause_i(be_mem.csr.trap_pkt_cast_o.cause)
// TODO: Find a way to access the finish_o signals for each core
,.finish_o()
);

assign cosim_finish_lo = '0;

bind bp_be_top
bp_be_nonsynth_perf
Expand Down

0 comments on commit 64a7783

Please sign in to comment.