Skip to content

Commit

Permalink
[nix] add vcs sim profile flow
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei committed Dec 9, 2024
1 parent 3e7e4f3 commit 17a61c0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
1 change: 1 addition & 0 deletions nix/pkgs/snps-fhs-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ lockedPkgs.buildFHSEnv {
nssmdns
fontconfig
numactl
python3
(krb5.overrideAttrs rec {
version = "1.18.2";
src = fetchurl {
Expand Down
8 changes: 8 additions & 0 deletions nix/t1/conversion/sv-to-vcs-simulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ stdenv.mkDerivation rec {

dontUnpack = true;

# VCS simulation profiling
# This is a debug feature, thus intentionally not exposed
# Enable it by changing line below to 'true'
enableProfile = false;

vcsArgs = [
"-sverilog"
"-full64"
Expand Down Expand Up @@ -56,6 +61,9 @@ stdenv.mkDerivation rec {
"-debug_access+pp+dmptf+thread"
"-kdb=common_elab,hgldd_all"
]
++ lib.optionals enableProfile [
"-simprofile"
]
++ vcsLinkLibs;

buildPhase = ''
Expand Down
7 changes: 3 additions & 4 deletions nix/t1/run/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ let
runVerilatorEmu = callPackage ./run-verilator-emu.nix { };
runVCSEmu_ = callPackage ./run-vcs-emu.nix { };
runFsdb2vcd = callPackage ./run-fsdb2vcd.nix { };
runVCSEmu = emulator: runVCSEmu_ { inherit emulator; };
runVCSEmuRT = emulator: runVCSEmu_ {
runVCSEmu = emulator: runVCSEmu_ {
inherit emulator;
dpilib = vcs-dpi-lib;
dpilib = if emulator.isRuntimeLoad then vcs-dpi-lib else null;
};

# cases is now { mlir = { hello = ...; ... }; ... }
Expand All @@ -39,7 +38,7 @@ let
innerMapper = caseName: case: {
verilator-emu = runVerilatorEmu verilator-emu case;
verilator-emu-trace = runVerilatorEmu verilator-emu-trace case;
vcs-emu = runVCSEmuRT vcs-emu-rtlink case;
vcs-emu = runVCSEmu vcs-emu-rtlink case;
vcs-emu-cover = runVCSEmu vcs-emu-cover case;
vcs-emu-trace = runVCSEmu vcs-emu-trace case;
vcs-prof-vcd = runFsdb2vcd (runVCSEmu vcs-emu-trace case);
Expand Down
62 changes: 49 additions & 13 deletions nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{ lib, stdenvNoCC, zstd, jq, offline-checker, snps-fhs-env }:
{ lib
, stdenvNoCC
, zstd
, jq
, offline-checker
, snps-fhs-env
, writeShellScriptBin
}:

{ emulator
, dpilib ? null
Expand All @@ -8,26 +15,55 @@ testCase:

assert lib.assertMsg (!emulator.isRuntimeLoad || (dpilib != null)) "dpilib must be set for rtlink emu";

stdenvNoCC.mkDerivation (finalAttr: {
stdenvNoCC.mkDerivation (rec {
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enableTrace "-trace");
nativeBuildInputs = [ zstd jq ];
__noChroot = true;

passthru.caseName = testCase.pname;
passthru = {
caseName = testCase.pname;

# to open 'profileReport.html' in firefox,
# set 'security.fileuri.strict_origin_policy = false' in 'about:config'
profile = writeShellScriptBin "runSimProfile" ''
${emuDriver} \
${lib.escapeShellArgs emuDriverArgs} \
-simprofile time \
2> ${testCase.pname}-rtl-event.jsonl
'';
};

emuDriver = "${emulator}/bin/${emulator.mainProgram}";
emuDriverArgs = lib.optionals emulator.isRuntimeLoad [
"-sv_root"
"${dpilib}/lib"
"-sv_lib"
"${dpilib.svLibName}"
]
++ [
"-exitstatus"
"-assert"
"global_finish_maxfail=10000"
"+t1_elf_file=${testCase}/bin/${testCase.pname}.elf"
]
++ lib.optionals emulator.enableCover [
"-cm"
"assert"
]
++ lib.optionals emulator.enableTrace [
"+t1_wave_path=${testCase.pname}.fsdb"
];

buildCommand = ''
${lib.optionalString emulator.enableProfile ''
echo "ERROR: 'enableProfile = true' is inherently nondetermistic"
echo " use 'nix run <...>.profile --impure' instead"
exit 1
''}
mkdir -p "$out"
emuDriverArgsArray=(
${lib.optionalString emulator.isRuntimeLoad "-sv_root ${dpilib}/lib -sv_lib ${dpilib.svLibName}"}
"-exitstatus"
"+t1_elf_file=${testCase}/bin/${testCase.pname}.elf"
${lib.optionalString emulator.enableTrace "+t1_wave_path=${testCase.pname}.fsdb"}
${lib.optionalString emulator.enableCover "-cm assert"}
"-assert global_finish_maxfail=10000"
)
emuDriverArgs="''${emuDriverArgsArray[@]}"
emuDriver="${emulator}/bin/${emulator.mainProgram}"
emuDriverArgs="${lib.escapeShellArgs emuDriverArgs}"
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl"
Expand Down

0 comments on commit 17a61c0

Please sign in to comment.