Skip to content

Commit

Permalink
Add Crossgen2 support (#11)
Browse files Browse the repository at this point in the history
* IBC tuning scripts allow generating .tibc files to get precise generics and partial IBC ready-to-run images
* Add linker root for IL stub generation code getting linked away
* Pin link-a-thon to netcoreapp3.0 for asp.net core
* Controllable with /p:UseCrossgen2=true when publishing ApiTemplate
* Prepare crossgen2 for run by running ./run_tuning.sh, which will build ApiTemplate with tuning enabled, run it to get a trace, then re-build it with the training data. The single exe binary is placed at /publish
* Use ./send-to-perflab.sh crossgen2 to submit a crossgen2 run
  • Loading branch information
nattress authored and sbomer committed Oct 3, 2019
1 parent 58aa423 commit 9aeb7e1
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,10 @@ ASALocalRun/
.mfractor/

.linker.txt
coreclrbin
coreclrbin

.vscode/
tibcdata/
rawibcdata/
src/ApiTemplate/tibcdata
published/
2 changes: 2 additions & 0 deletions build-coreclr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ cp "$coreclrbuilddir/Microsoft.NET.HostModel.dll" "$coreclrbinariesdir"
cp "$coreclrbuilddir/corebundle" "$coreclrbinariesdir"
cp "$coreclrbuilddir/System.Private.CoreLib.dll" "$coreclrbinariesdir"
cp "$coreclrbuilddir/crossgen" "$coreclrbinariesdir"
cp -r "$coreclrbuilddir/crossgen2" "$coreclrbinariesdir/crossgen2"
cp -r "$coreclrbuilddir/tibcmgr" "$coreclrbinariesdir/tibcmgr"
28 changes: 28 additions & 0 deletions produce_tibc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

scriptroot="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

referencescommandline=

for dll in $scriptroot/src/ApiTemplate/obj/Release/netcoreapp3.0/linux-x64/multifile-publish/*.dll
do
referencescommandline="$referencescommandline -r:$dll"
done

rm -r -f $scriptroot/tibcdata
mkdir -p $scriptroot/tibcdata

for dll in $scriptroot/src/ApiTemplate/obj/Release/netcoreapp3.0/linux-x64/multifile-publish/*.dll
do
assemfullname=$(basename $dll)
assemname="${assemfullname%.*}"
ibcfile=$scriptroot/rawibcdata/$assemname.ibc
tibcfile=$scriptroot/tibcdata/$assemname.tibc
if [ -f $ibcfile ]
then
tibc_command="$scriptroot/src/coreclrbin/tibcmgr/tibcmgr convert $referencescommandline $ibcfile $dll $tibcfile"
echo $tibc_command
$tibc_command
fi
done

10 changes: 10 additions & 0 deletions produce_tunedimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

scriptroot="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"


rm -r -f $scriptroot/src/ApiTemplate/tibcdata
mkdir -p $scriptroot/src/ApiTemplate/tibcdata
cp $scriptroot/tibcdata/* $scriptroot/src/ApiTemplate/tibcdata

dotnet publish -c Release src/ApiTemplate/ApiTemplate.csproj -o publish -p:SelfContained=true -p:UseStaticHost=true -p:UsePublishFilterList=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -p:UseTibcData=true -p:UseCrossgen2=true $1
49 changes: 49 additions & 0 deletions run_tuning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

scriptroot="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

dotnet publish -c Release src/ApiTemplate/ApiTemplate.csproj -o publish -p:UseStaticHost=true -p:UsePublishFilterList=true -p:LinkAggressively=true -p:PublishTrimmed=true -p:SelfContained=true -p:ProduceTuningImage=true -p:UseCrossgen2=true -r linux-x64 -p:PublishReadyToRun=true

rm -r -f $scriptroot/rawibcdata
mkdir -p $scriptroot/rawibcdata

export COMPlus_ZapBBInstr=*
export COMPlus_ZapBBInstrDir=$scriptroot/rawibcdata
export COMPlus_ZapBBInstrR2RGenerics=2

$scriptroot/publish/ApiTemplate & PROC_ID=$!
echo $PROC_ID

sleep 1
curl http://localhost:5000/WeatherForecast > /dev/null
while [ $? -ne 0 ]
do
sleep 1
curl http://localhost:5000/WeatherForecast > /dev/null
done

echo Service Live!

counter=1
while [ $counter -le 10 ]
do
echo $counter
curl http://localhost:5000/WeatherForecast > /dev/null
counter=$(($counter+1))
sleep 1
done

echo Telling the service to quit
kill -s SIGTERM $PROC_ID

sleep 1
while kill -0 "$PROC_ID" >/dev/null 2>&1; do
echo "PROCESS IS STILL RUNNING"
sleep 1
done

echo "PROCESS TERMINATED"

$scriptroot/produce_tibc.sh
$scriptroot/produce_tunedimage.sh

11 changes: 10 additions & 1 deletion send-to-perflab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ if [[ -z "$client" ]] || [[ -z "$server" ]]; then
exit 1
fi

crossgen2Arguments=
if [ "$1" == "crossgen2" ]; then
echo "Using crossgen2"
crossgen2Arguments="--build-arg /p:UseCrossgen2=true --build-arg /p:UseTibcData=true"
fi

# clone benchmarks repo
if [[ ! -e "$driverproject" ]]; then
git clone https://github.com/aspnet/benchmarks
Expand All @@ -24,6 +30,8 @@ dotnet run -p "$driverproject" -- \
--self-contained \
--sdk 3.0.100-rc1-014176 \
--path weatherforecast \
--aspnetcoreversion 3.0 \
--runtimeversion 3.0 \
--warmup 1 \
--duration 2 \
--build-arg "/p:SelfContained=true" \
Expand All @@ -35,7 +43,8 @@ dotnet run -p "$driverproject" -- \
--display-output \
--iterations 1 \
--collect-counters \
--env "COMPlus_gcServer=1"
--env "COMPlus_gcServer=1" \
$crossgen2Arguments

# --fetch \
# --collect-startup \
Expand Down
1 change: 1 addition & 0 deletions src/ApiTemplate/Linker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<linker>
<assembly fullname="System.Private.CoreLib">
<type fullname="System.Object" />
<type fullname="System.Runtime.CompilerServices.RuntimeHelpers" />
</assembly>

<assembly fullname="ApiTemplate">
Expand Down
44 changes: 40 additions & 4 deletions src/CustomR2RLogic.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<Project>
<PropertyGroup>
<TibcDir>$(MSBuildProjectDirectory)/tibcdata/</TibcDir>
</PropertyGroup>

<!-- These targets will use the locally-built crossgen, which doesn't take /JITPath -->
<Target Name="UseLocalCrossgen"
AfterTargets="_PrepareForReadyToRunCompilation">
<ItemGroup>
<_CrossgenTool Remove="@(_CrossgenTool)" />
<_CrossgenTool Include="$(CoreClrBinariesDir)crossgen" />
<_CrossgenTool Include="$(CoreClrBinariesDir)crossgen" Condition="'$(UseCrossgen2)' != 'true'" />
<_CrossgenTool Include="$(CoreClrBinariesDir)crossgen2/crossgen2" Condition="'$(UseCrossgen2)' == 'true'" />
</ItemGroup>
<Error Condition="!Exists('@(_CrossgenTool)')"
Text="crossgen not found in $(CoreClrBinariesDir)" />
Expand All @@ -18,18 +22,50 @@
<!-- Work around non-assemblies in the input that are normally filtered out by the ReadyToRun task -->
<ItemGroup>
<_ReadyToRunImplementationAssemblies Remove="@(_ReadyToRunImplementationAssemblies)"
Condition=" '%(Extension)' != '.dll' " />
Condition=" '%(Extension)' != '.dll'" />
<_TibcFiles Include="$(TibcDir)*.tibc" Condition="'$(UseCrossgen2)' == 'true'" />
</ItemGroup>

<!-- Necessary when sending to perflab - the permissions are not preserved when zipping/unzipping. -->
<Exec Command="chmod +x @(_CrossgenTool)" />
<PropertyGroup>

<!--
Arguments and commands for old Crossgen
-->
<PropertyGroup Condition="'$(UseCrossgen2)' != 'true'">
<CrossgenCommand>@(_CrossgenTool) /nologo /MissingDependenciesOK</CrossgenCommand>
<!-- crossgen fails if System.Private.CoreLib isn't a fully-qualified path -->
<CrossgenCommand>$(CrossgenCommand) /r @(_ReadyToRunImplementationAssemblies->'%(FullPath)', ' /r ')</CrossgenCommand>
</PropertyGroup>
<ItemGroup>

<ItemGroup Condition="'$(UseCrossgen2)' != 'true'">
<CrossgenCommands Include="$(CrossgenCommand) /out %(_ReadyToRunCompileList.OutputR2RImage) %(_ReadyToRunCompileList.Identity)" />
</ItemGroup>

<!--
Arguments and commands for Crossgen2 wow so shiny
-->
<PropertyGroup Condition="'$(UseCrossgen2)' == 'true'">
<CrossgenCommand>@(_CrossgenTool)</CrossgenCommand>

<CrossgenCommand>$(CrossgenCommand) --resilient</CrossgenCommand>
<CrossgenCommand Condition="'$(ProduceTuningImage)'=='true'">$(CrossgenCommand) --tuning </CrossgenCommand>
<CrossgenCommand Condition="'$(ProduceTuningImage)'!='true'">$(CrossgenCommand) --Ot </CrossgenCommand>
<CrossgenCommand Condition="'$(UseTibcData)'=='true'">$(CrossgenCommand) --inputbubble --partial -t:@(_TibcFiles->'%(FullPath)', ' -t:')</CrossgenCommand>
<!-- crossgen fails if System.Private.CoreLib isn't a fully-qualified path -->
<CrossgenCommand>$(CrossgenCommand) -r:@(_ReadyToRunImplementationAssemblies->'%(FullPath)', ' -r:')</CrossgenCommand>
</PropertyGroup>

<ItemGroup Condition="'$(UseCrossgen2)' == 'true'">
<CrossgenCommands Condition="'%(_ReadyToRunCompileList.Filename)' != '$(AssemblyName)' Or '$(UseTibcData)'!='true'" Include="$(CrossgenCommand) -o:%(_ReadyToRunCompileList.OutputR2RImage) %(_ReadyToRunCompileList.Identity)" />
<CrossgenCommands Condition="'%(_ReadyToRunCompileList.Filename)' == '$(AssemblyName)' And '$(UseTibcData)'=='true'" Include="$(CrossgenCommand) --compilebubblegenerics --nonlocalgenerics_fromprofiledata -o:%(_ReadyToRunCompileList.OutputR2RImage) %(_ReadyToRunCompileList.Identity)" />
</ItemGroup>
<Message Importance="High" Text="Crossgen2 %(CrossgenCommands.Identity)" />

<Exec Command="%(CrossgenCommands.Identity)" />
</Target>

Expand Down

0 comments on commit 9aeb7e1

Please sign in to comment.