Skip to content
Open
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
45 changes: 45 additions & 0 deletions scripts/build-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,44 @@ run_step() {
# In order to run code on error, we must handle errors manually
set +e;

# Initialize timing arrays
declare -a STEP_START_TIME
declare -a STEP_END_TIME
declare -a STEP_DESCRIPTION
STEPS=11

function begin_step
{
thisStepNum=$1;
thisStepDesc=$2;
STEP_DESCRIPTION[$thisStepNum]=$thisStepDesc
STEP_START_TIME[$thisStepNum]=$(date +%s.%N 2>/dev/null || date +%s)
echo " ========== BEGINNING STEP $thisStepNum: $thisStepDesc =========="
}
function print_timing_table
{
echo ""
echo "Per-step timing"
printf "%-8s %-15s %-18s %-20s %s\n" "Step #" "Wall Time (s)" "% of Total Time" "Cumulative Time (s)" "Description"
echo "--------------------------------------------------------------------------------------------------------"

local -a wt
local total=0 cumulative=0
for ((i=1; i<=STEPS; i++)); do
[[ -z "${STEP_START_TIME[$i]}" || -z "${STEP_END_TIME[$i]}" ]] && continue
wt[$i]=$(awk "BEGIN {printf \"%.0f\", ${STEP_END_TIME[$i]} - ${STEP_START_TIME[$i]}}")
total=$(awk "BEGIN {printf \"%.0f\", $total + ${wt[$i]}}")
done

for ((i=1; i<=STEPS; i++)); do
[[ -z "${wt[$i]}" ]] && continue
cumulative=$(awk "BEGIN {printf \"%.0f\", $cumulative + ${wt[$i]}}")
local pct=$(awk -v w="${wt[$i]}" -v t="$total" "BEGIN {if (t > 0) printf \"%.0f\", (w/t)*100; else printf \"%.0f\", 0}")
printf "%-8s %-15.0f %-18.0f %-20.0f %s\n" "$i" "${wt[$i]}" "$pct" "$cumulative" "${STEP_DESCRIPTION[$i]}"
done
printf "%-8s %-15.0f\n" "Total" "$total"
echo ""
}
function exit_if_last_command_failed
{
local exitcode=$?;
Expand Down Expand Up @@ -223,6 +255,7 @@ END_CONDA_ACTIVATE
$CONDA_ACTIVATE_PREAMBLE
conda activate $CONDA_ENV_NAME
source $CYDIR/scripts/fix-open-files.sh"
STEP_END_TIME[1]=$(date +%s.%N 2>/dev/null || date +%s)
fi

if [ -z ${CONDA_DEFAULT_ENV+x} ]; then
Expand All @@ -234,6 +267,7 @@ if run_step "2"; then
begin_step "2" "Initializing Chipyard submodules"
$CYDIR/scripts/init-submodules-no-riscv-tools.sh --full
exit_if_last_command_failed
STEP_END_TIME[2]=$(date +%s.%N 2>/dev/null || date +%s)
fi

# build extra toolchain collateral (i.e. spike, pk, riscv-tests, libgloss)
Expand All @@ -250,13 +284,15 @@ if run_step "3"; then
fi
$CYDIR/scripts/build-toolchain-extra.sh $TOOLCHAIN_TYPE -p $PREFIX
exit_if_last_command_failed
STEP_END_TIME[3]=$(date +%s.%N 2>/dev/null || date +%s)
fi

# run ctags for code navigation
if run_step "4"; then
begin_step "4" "Running ctags for code navigation"
$CYDIR/scripts/gen-tags.sh
exit_if_last_command_failed
STEP_END_TIME[4]=$(date +%s.%N 2>/dev/null || date +%s)
fi

# precompile chipyard scala sources
Expand All @@ -267,6 +303,7 @@ if run_step "5"; then
make launch-sbt SBT_COMMAND=";project tapeout; compile" &&
popd
exit_if_last_command_failed
STEP_END_TIME[5]=$(date +%s.%N 2>/dev/null || date +%s)
fi

# setup firesim
Expand All @@ -275,6 +312,7 @@ if run_step "6"; then
$CYDIR/scripts/firesim-setup.sh &&
$CYDIR/sims/firesim/gen-tags.sh
exit_if_last_command_failed
STEP_END_TIME[6]=$(date +%s.%N 2>/dev/null || date +%s)

# precompile firesim scala sources
if run_step "7"; then
Expand All @@ -290,6 +328,7 @@ if run_step "6"; then
)
exit_if_last_command_failed
popd
STEP_END_TIME[7]=$(date +%s.%N 2>/dev/null || date +%s)
fi
fi

Expand All @@ -307,10 +346,12 @@ if run_step "8"; then
./marshal $VERBOSE_FLAG build br-base.json &&
./marshal $VERBOSE_FLAG build bare-base.json
exit_if_last_command_failed
STEP_END_TIME[9]=$(date +%s.%N 2>/dev/null || date +%s)
fi
popd
# Ensure FireMarshal CLI is on PATH in env.sh (idempotent)
replace_content env.sh build-setup-marshal "# line auto-generated by build-setup.sh\n__DIR=\"$CYDIR\"\nPATH=\\$__DIR/software/firemarshal:\\$PATH"
STEP_END_TIME[8]=$(date +%s.%N 2>/dev/null || date +%s)
fi

if run_step "10"; then
Expand Down Expand Up @@ -341,6 +382,7 @@ if run_step "10"; then
-g $GITHUB_TOKEN
fi
exit_if_last_command_failed
STEP_END_TIME[10]=$(date +%s.%N 2>/dev/null || date +%s)
fi


Expand All @@ -349,8 +391,11 @@ if run_step "11"; then
begin_step "11" "Cleaning up repository"
$CYDIR/scripts/repo-clean.sh
exit_if_last_command_failed
STEP_END_TIME[11]=$(date +%s.%N 2>/dev/null || date +%s)
fi

print_timing_table

echo "Setup complete!"

} 2>&1 | tee build-setup.log
Loading