-
Notifications
You must be signed in to change notification settings - Fork 103
feat: add design version info at runtime #508
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,10 @@ RTL_DIR = $(BUILD_DIR)/rtl | |
| RTL_SUFFIX ?= sv | ||
| SIM_TOP_V = $(RTL_DIR)/$(SIM_TOP).$(RTL_SUFFIX) | ||
|
|
||
| # get design version info | ||
| VERSION_COMMIT_ID := $(shell git -C $(DESIGN_DIR) rev-parse --short HEAD) | ||
| VERSION_IS_DIRTY := $(shell git -C $(DESIGN_DIR) diff --quiet HEAD || echo "-dirty") | ||
|
|
||
| # generate difftest files for non-chisel design. | ||
| .DEFAULT_GOAL := difftest_verilog | ||
| ifeq ($(MFC), 1) | ||
|
|
@@ -227,6 +231,12 @@ ifeq ($(CXX_NO_WARNING),1) | |
| SIM_CXXFLAGS += -Werror | ||
| endif | ||
|
|
||
| # Generate Version Info File (Always) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to generate this header. See below comments for |
||
| VERSION_HEADER = $(GEN_CSRC_DIR)/version.h | ||
| .PHONY: $(VERSION_HEADER) | ||
| $(VERSION_HEADER): | ||
| @echo "#define STR_COMMIT_ID \"$(VERSION_COMMIT_ID)\"\n#define STR_IS_DIRTY \"$(VERSION_IS_DIRTY)\"" > $@ | ||
|
|
||
| include verilator.mk | ||
| include vcs.mk | ||
| include palladium.mk | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| ***************************************************************************************/ | ||
|
|
||
| #include "common.h" | ||
| #include "version.h" | ||
| #include <locale.h> | ||
| #include <signal.h> | ||
|
|
||
|
|
@@ -70,6 +71,8 @@ void common_init_without_assertion(const char *program_name) { | |
| elf_name = elf_name ? elf_name + 1 : program_name; | ||
| Info("%s compiled at %s, %s\n", elf_name, __DATE__, __TIME__); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Info("%s(" DUT_VERSION_STRING ", " DIFFTEST_VERSION_STRING ") compiled at " __DATE__ ", __TIME__ " \n", elf_name); |
||
|
|
||
| Info("Source Code Version: %s%s\n", STR_COMMIT_ID, STR_IS_DIRTY); | ||
|
|
||
| // set buffer for stderr | ||
| setbuf(stderr, mybuf); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,7 +108,7 @@ VCS_FLAGS += $(EXTRA) | |
|
|
||
| VCS_VSRC_DIR = $(abspath ./src/test/vsrc/vcs) | ||
| VCS_VFILES = $(SIM_VSRC) $(shell find $(VCS_VSRC_DIR) -name "*.v") | ||
| $(VCS_TARGET): $(SIM_TOP_V) $(VCS_CXXFILES) $(VCS_VFILES) | ||
| $(VCS_TARGET): $(SIM_TOP_V) $(VCS_CXXFILES) $(VCS_VFILES) $(VERSION_HEADER) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are passing versions with C macros, there's no need to creating the headers here. |
||
| $(VCS) $(VCS_FLAGS) $(SIM_TOP_V) $(VCS_CXXFILES) $(VCS_VFILES) | ||
| ifeq ($(VCS),verilator) | ||
| $(MAKE) -s -C $(VCS_BUILD_DIR) -f V$(VCS_TOP).mk | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check whether
gitexists?I think we can simply pass them as a C macro.
SIM_CXXFLAGS += -DDUT_VERSION_STRING=\\\"${VERSION_COMMIT_ID}${VERSION_IS_DIRTY}\\\"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, for two reasons.
VSimTop.mk, which won't be update as long as verilator is not triggered again.common.cpp(and its timestamp) is never changed. In that way, the compiling systemmakewill think the compiled resultcommon.ois always up-to-date and no need to be re-compiled. Hence the commit id will always keep the old one when the whole project is compiled for the first time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check git is a good proposal. I'm considering to genenrate the commit info string in the design repo and pass it to difftest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Difftest commit info is also valuable, but I think it's better to:
git status --porcelain, since the main repo commit has included the submodule commit info.Which one do you think is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what we want as this dut version should be the same as the generated verilog, not the git repo.
Consider this case:
make emuis generated with version A. We checkout it to version B. If we enforce amake emuagain, the timestamp will be changed to version B. This is not what we want.The DUT version should be exactly matching the verilog code, which is passed at verilator build time instead of the current git commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
difftest is a general co-sim framework for RISC-V processors, not only for XiangShan.
The reason we use
githere is for the general-purpose usage. If XiangShan, or other DUTs, want a more complicated version string, they should pass the string by command lineDUT_VERSION_STRING=XXX.