-
Notifications
You must be signed in to change notification settings - Fork 68
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
feat: add design version info at runtime #508
base: master
Are you sure you want to change the base?
Conversation
Recently, we have added version info of the design code (the commit id) in the XiangShan RTL code. This patch adds the version info in the emu/simv program. Now the emu/simv program will print the commit id of design when initializing. This patch also resolves the issue where the emu build time would not update when re-compiling. Now, with each build, `version.h` is re-generated, causing `common.cpp`, the source code file which contains printing logic, to be recompiled, which subsequently triggers a relink of `emu`. This process takes a few seconds, which is longer than before, but still acceptable.
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.
Version strings are valuable. Some suggestions to improve the code.
@@ -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") |
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
git
exists? -
I think we can simply pass them as a C macro.
SIM_CXXFLAGS += -DDUT_VERSION_STRING=\\\"${VERSION_COMMIT_ID}${VERSION_IS_DIRTY}\\\"
- Maybe we can also add the DIFFTEST_VERSION_STRING.
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.
- I think we can simply pass them as a C macro.
SIM_CXXFLAGS += -DDUT_VERSION_STRING=\\\"${VERSION_COMMIT_ID}${VERSION_IS_DIRTY}\\\"
This won't work, for two reasons.
- Verilator writes all FLAGS into
VSimTop.mk
, which won't be update as long as verilator is not triggered again. - The original source code file
common.cpp
(and its timestamp) is never changed. In that way, the compiling systemmake
will think the compiled resultcommon.o
is 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:
- add all submodules commit info
difftest: asdfqwe
yunsuan: qwerasd
...
- or, record detail dirty info by
git status --porcelain
, since the main repo commit has included the submodule commit info.
M difftest
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.
- Verilator writes all FLAGS into
VSimTop.mk
, which won't be update as long as verilator is not triggered again.
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 emu
is generated with version A. We checkout it to version B. If we enforce a make emu
again, 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.
- add all submodules commit info
difftest is a general co-sim framework for RISC-V processors, not only for XiangShan.
The reason we use git
here is for the general-purpose usage. If XiangShan, or other DUTs, want a more complicated version string, they should pass the string by command line DUT_VERSION_STRING=XXX
.
@@ -227,6 +231,12 @@ ifeq ($(CXX_NO_WARNING),1) | |||
SIM_CXXFLAGS += -Werror | |||
endif | |||
|
|||
# Generate Version Info File (Always) |
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.
There is no need to generate this header. See below comments for common.cpp
@@ -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__); |
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.
- There's no need to add one more line for the version string. We can simply add them to the
elf_name
.
Info("%s(" DUT_VERSION_STRING ", " DIFFTEST_VERSION_STRING ") compiled at " __DATE__ ", __TIME__ " \n", elf_name);
@@ -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) |
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.
Since we are passing versions with C macros, there's no need to creating the headers here.
I don't fully understand this issue. What is the case that the build time is not updated? I think when C++ files (or other dependencies) change, it is rebuilt with build time updated. Otherwise, |
TL;NR: the timestamp-based tool ( Although the value of the marco Acctually I'm not confident with this fix. There is also some hash-based cache of souce file (maybe from
Now, I acctually want to write the date and time into the |
When
This is unacceptable because every time of Besides, we have said a lot of times to avoid using |
For difftest, as a cosim framework, we are only considering the general-purpose usage. A version tag is welcomed, and we can add it to the emu build message. We can also add the git commit info as the default message. But that's all we will do in this difftest PR.
This is the core reason I'm rejecting the I want to note that, what difftest accepts as the DUT is the Verilog files, not any git repo or Chisel code. The reason we are supporting the git commit info as the default option is to support the general-purpose usage. That's also why we need a git checker. This fundamental design choice to separate the DUT and the cosim framework will reject some of your proposals, including
|
Acctually, I have tried the following methods:
Do you have any suggestion? I will keep trying to find the best way to solve this problem. I understand that difftest is an general-purpose cosim framework. The complex version info would be genetated by the DUT project, but I suggest that the difftest may give space for such requirement, as it can't be achieved with just the DUT project alone. |
I think simply passing the version tag (along with the verilog source files) when As you mentioned, this version tag macro will be written in the For simplicity, we can use the current git commit when How do you think of this? Is there any issue where this implementation won't work?
Yes. Much appreciate we can discuss this issue separately -- whether the timestamps should be updated (with |
I think there is still two problems:
By the way, I don't get the gap between the version of verilog files and the version of the repo. The verilog files are just from the repo or generated from the repo. |
Yes. This is what we want: Verilator only re-verilates the design only when
Yes. We don't want to recompile it (because the RTL is not changed).
I see. Maybe we are not clear for this. Basically, the build process for
Every time we are at step 3, Specifically, this
Every time we are at step 2, DiffTest accepts a version tag of the DUT (the version of verilog files) and writes it to the Does this make sense to you? |
Ok, I understand the gap between you and me. There is two version tag, for DUT and for difftest.
For this problem, I'm writing an new issue. I will explain it there. |
Yes.
Agree. I'm not sure how we can force re-compiling If we succeed doing this, the Considering that this case (change difftest versions after |
That's why I introduced the |
This seems an approach with high overhead bringing minor improvements. I think DUT version tags are much more valuable than DiffTest tags. Maybe we can only implement the DUT version tag now in this PR. Frankly speaking, for advanced users, they should know that they are updating the DiffTest repo. For beginner users, they should never checking out the difftest repo on their own. Technically, I propose we find better methods before implementing the real DiffTest tags. |
Recently, we have added version info of the design code (the commit id) in the XiangShan RTL code. This patch adds the version info in the emu/simv program. Now the emu/simv program will print the commit id of design when initializing.
This patch may also resolve the issue where the emu build time would not update when re-compiling. Now, with each build,
version.h
is re-generated, causingcommon.cpp
, the source code file which contains printing logic, to be recompiled, which subsequently triggers a relink ofemu
. This process takes a few seconds, which is longer than before, but still acceptable.