Skip to content

Commit

Permalink
Add support for Verilator v5.016 (#132)
Browse files Browse the repository at this point in the history
We'll only support Verilator versions older than v4.219 or newer than v5.015.

Verilator v4.225 changed the implementation for its thread pool, which affects our implementation for the in-memory snapshots LightSSS. We did not fixed the issue until v5.015. Therefore, we are currently supporting limited Verilator versions to support all features in difftest.

See verilator/verilator#3503 for more details.
  • Loading branch information
poemonsense committed Feb 26, 2024
1 parent 1b1cd4b commit ac60423
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/test/csrc/verilator/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,19 @@ void Emulator::snapshot_load(const char *filename) {
#endif

void Emulator::fork_child_init() {
#if EMU_THREAD > 1
#if VERILATOR_VERSION_INTEGER >= 4228000
dut_ptr->vlSymsp->__Vm_threadPoolp = new VlThreadPool(dut_ptr->contextp(), EMU_THREAD - 1);
#elif VERILATOR_VERSION_INTEGER >= 4210000
dut_ptr->vlSymsp->__Vm_threadPoolp = new VlThreadPool(dut_ptr->contextp(), EMU_THREAD - 1, 0);
#ifdef VERILATOR_VERSION_INTEGER // >= v4.220
#if VERILATOR_VERSION_INTEGER >= 5016000
// This will cause 288 bytes leaked for each one fork call.
// However, one million snapshots cause only 288MB leaks, which is still acceptable.
// See verilator/test_regress/t/t_wrapper_clone.cpp:48 to avoid leaks.
dut_ptr->atClone();
#else
#error Please use Verilator v5.016 or newer versions.
#endif // check VERILATOR_VERSION_INTEGER values
#elif EMU_THREADS > 1 // VERILATOR_VERSION_INTEGER not defined
#ifdef VERILATOR_4_210 // v4.210 <= version < 4.220
dut_ptr->vlSymsp->__Vm_threadPoolp = new VlThreadPool(dut_ptr->contextp(), EMU_THREAD - 1, 0);
#else // older than v4.210
dut_ptr->__Vm_threadPoolp = new VlThreadPool(dut_ptr->contextp(), EMU_THREAD - 1, 0);
#endif
#endif
Expand Down
5 changes: 2 additions & 3 deletions verilator.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EMU_TOP = SimTop

EMU_CSRC_DIR = $(abspath ./src/test/csrc)
EMU_CXXFILES = $(shell find $(EMU_CSRC_DIR) -name "*.cpp") $(SIM_CXXFILES) $(DIFFTEST_CXXFILES)
EMU_CXXFLAGS += -std=c++11 -static -Wall -I$(EMU_CSRC_DIR) -I$(SIM_CSRC_DIR) -I$(DIFFTEST_CSRC_DIR) -I$(PLUGIN_CHEAD_DIR)
EMU_CXXFLAGS += -std=c++14 -static -Wall -I$(EMU_CSRC_DIR) -I$(SIM_CSRC_DIR) -I$(DIFFTEST_CSRC_DIR) -I$(PLUGIN_CHEAD_DIR)
EMU_CXXFLAGS += -DVERILATOR -DNUM_CORES=$(NUM_CORES)
EMU_CXXFLAGS += $(shell sdl2-config --cflags) -fPIE
EMU_LDFLAGS += -lpthread -lSDL2 -ldl -lz -lsqlite3
Expand All @@ -42,10 +42,9 @@ endif

# Verilator version check
VERILATOR_VER_CMD = verilator --version | cut -f2 -d' ' | tr -d '.'
VERILATOR_VERSION = $(shell `$(VERILATOR_VER_CMD)`)

VERILATOR_4_210 := $(shell expr `$(VERILATOR_VER_CMD)` \>= 4210)
ifeq ($(VERILATOR_4_210),1)
EMU_CXXFLAGS += -DVERILATOR_4_210
VEXTRA_FLAGS += --instr-count-dpi 1
endif
VERILATOR_5_000 := $(shell expr `$(VERILATOR_VER_CMD)` \>= 5000)
Expand Down

0 comments on commit ac60423

Please sign in to comment.