Skip to content

Commit

Permalink
[nix & verbatim] use PRINTF_FD to write rtl-event.jsonl
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei committed Dec 19, 2024
1 parent 052caec commit 3f993e9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
7 changes: 6 additions & 1 deletion nix/t1/conversion/sv-to-vcs-simulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ stdenv.mkDerivation rec {
"-y"
"$DWBB_DIR/sim_ver"
"+libext+.v"
]
# vsrc contains SV package, ensure it's the first
++ vsrc
++ [
"+define+PRINTF_FD=t1_log_pkg::log_fd"
"+define+PRINTF_COND=t1_log_pkg::log_cond"
"-F"
"${rtl}/filelist.f"
]
++ vsrc
++ lib.optionals (topModule != null) [
"-top"
topModule
Expand Down
10 changes: 4 additions & 6 deletions nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ stdenvNoCC.mkDerivation (rec {
profile = writeShellScriptBin "runSimProfile" ''
${emuDriver} \
${lib.escapeShellArgs emuDriverArgs} \
-simprofile time \
2> ${testCase.pname}-rtl-event.jsonl
-simprofile time
'';
};

Expand Down Expand Up @@ -65,20 +64,19 @@ stdenvNoCC.mkDerivation (rec {
emuDriverArgs="${lib.escapeShellArgs emuDriverArgs}"
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl"
rtlEventOutPath="rtl-event.jsonl"
echo "[nix] Running VCS ${testCase.pname} with args $emuDriverArgs"
printError() {
echo -e "\033[0;31m[nix]\033[0m: online driver run failed"
cat $rtlEventOutPath
echo -e "\033[0;31m[nix]\033[0m: Try rerun with '\033[0;34m$emuDriver $emuDriverArgs\033[0m'"
exit 1
}
export RUST_BACKTRACE=full
"$emuDriver" $emuDriverArgs 1> >(tee $out/online-drive-emu-journal) 2>$rtlEventOutPath || printError
"$emuDriver" $emuDriverArgs 1> >(tee $out/online-drive-emu-journal) || printError
echo "[nix] VCS run done"
Expand Down Expand Up @@ -117,7 +115,7 @@ stdenvNoCC.mkDerivation (rec {
set -e
echo "[nix] compressing event log"
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd
zstd $rtlEventOutPath -o "$out/rtl-event.jsonl.zstd"
rm $rtlEventOutPath
if [ -r perf.json ]; then
Expand Down
22 changes: 22 additions & 0 deletions t1emu/vsrc/VerbatimModule.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
package t1_log_pkg;
bit log_cond;
int log_fd;

function automatic void log_open(string log_path);
log_fd = $fopen(log_path, "w");
if (log_fd == 0) $fatal(1, "failed to open rtl event file for write");
log_cond = 1'b1;
endfunction

function automatic void log_close();
if (log_cond) begin
$fclose(log_fd);
log_cond = 1'b0;
log_fd = 0;
end
endfunction
endpackage

module VerbatimModule #(
parameter integer T1_DLEN,
parameter integer T1_VLEN,
Expand Down Expand Up @@ -67,6 +86,8 @@ module VerbatimModule #(
clock = 1'b0;
reset = 1'b1;

t1_log_pkg::log_open("rtl-event.jsonl");

`ifdef T1_ENABLE_TRACE
$value$plusargs("t1_dump_start=%d", dump_start);
$value$plusargs("t1_dump_end=%d", dump_end);
Expand Down Expand Up @@ -125,6 +146,7 @@ module VerbatimModule #(
end

final begin
t1_log_pkg::log_close();
t1_cosim_final();
end

Expand Down
22 changes: 22 additions & 0 deletions t1rocketemu/vsrc/VerbatimModule.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
package t1_log_pkg;
bit log_cond;
int log_fd;

function automatic void log_open(string log_path);
log_fd = $fopen(log_path, "w");
if (log_fd == 0) $fatal(1, "failed to open rtl event file for write");
log_cond = 1'b1;
endfunction

function automatic void log_close();
if (log_cond) begin
$fclose(log_fd);
log_cond = 1'b0;
log_fd = 0;
end
endfunction
endpackage

module VerbatimModule #(
parameter integer T1_DLEN,
parameter integer T1_VLEN,
Expand Down Expand Up @@ -73,6 +92,8 @@ module VerbatimModule #(
reset = 1'b1;
initFlag = 1'b1;

t1_log_pkg::log_open("rtl-event.jsonl");

`ifdef T1_ENABLE_TRACE
$value$plusargs("t1_dump_start=%d", dump_start);
$value$plusargs("t1_dump_end=%d", dump_end);
Expand Down Expand Up @@ -146,6 +167,7 @@ module VerbatimModule #(
end

final begin
t1_log_pkg::log_close();
t1_cosim_final();
end

Expand Down

0 comments on commit 3f993e9

Please sign in to comment.