Skip to content
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

[nix] Add vcs sim profile flow #887

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}";
FanShupei marked this conversation as resolved.
Show resolved Hide resolved
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the emuDriverArgs is escaped into bash string "'argA' 'argB' 'argC'", this might cause some unexpected behavior in future modification. But just left it here if it is ok for now.


rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl"

Expand Down