-
Notifications
You must be signed in to change notification settings - Fork 188
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
Prejit support on FunctionsNetHost #2711
Open
kshyju
wants to merge
24
commits into
main
Choose a base branch
from
shkr/2637_fnh_prejit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
91db9cc
FNH-WIP for prejit support
kshyju 60f949a
Install net9 rc1
kshyju 45c6701
Switching back to .NET9 preview 6
kshyju f66827e
fix YAML to install preview6
kshyju 129ad4a
Changed a trace level log to Info level.
kshyju 40ecea7
Updating build YAML file to include the pre-jit artifacts in the nuge…
kshyju c246745
PR review fixes
kshyju 972c875
Replaced "AZURE_FUNCTIONS_FUNCTIONSNETHOST" prefix with "AZURE_FUNCTI…
kshyju 0f224fc
Switching to named pipes for communication between FNH and StartupHoo…
kshyju 5fe75d2
Added linux.coldstart jittrace and removed removed R2R from placehold…
kshyju 220777e
Fixed incorrect output path for prelaunch apps
kshyju 0f59756
Using native method to get environment variable.
kshyju e4f8415
Revert "Using native method to get environment variable."
kshyju 526d6d0
Switching to native interop using DllImport for signaling specializat…
kshyju 4310a3d
Minor cleanup. Upgraded dependencies to GA versions.
kshyju bd92bc6
Cleanup
kshyju cf9d6fa
Updated sdk version in global json to net9. Removed duplicate global.…
kshyju 3330553
Minor cleanup
kshyju 21739aa
Install net8 explicitly.
kshyju b5a5424
Variable rename in YML file based on PR comments.
kshyju 4402eca
Change YAML variable to "tfm"
kshyju 6ad089e
Remove workingdir
kshyju 7bc6174
Minor folder restructuring
kshyju 6478abd
fix project path based on latest folder reorg
kshyju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
eng/ci/templates/official/jobs/build-host-prejit-artifacts.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
jobs: | ||
|
||
- job: BuildPreJitApp | ||
displayName: Build Pre-jit placeholder app artifacts | ||
|
||
templateContext: | ||
outputParentDirectory: $(Build.ArtifactStagingDirectory) | ||
outputs: | ||
- output: pipelineArtifact | ||
displayName: Publish Pre-jit placeholder app artifacts | ||
path: $(Build.ArtifactStagingDirectory)/_preJitAppPackages | ||
artifact: _preJitAppPackages | ||
|
||
variables: | ||
targetFrameworks: 'net8.0,net9.0' | ||
|
||
steps: | ||
- template: /eng/ci/templates/steps/install-dotnet.yml@self | ||
|
||
- ${{ each tfm in split(variables.targetFrameworks, ',') }}: | ||
- task: DotNetCoreCLI@2 | ||
displayName: ${{ tfm }} publish of pre-jit app | ||
inputs: | ||
command: publish | ||
publishWebProjects: false | ||
zipAfterPublish: false | ||
modifyOutputPath: false | ||
arguments: -c Release -o $(Build.ArtifactStagingDirectory)/_preJitAppPackages/${{ replace(tfm, 'net', '') }} -f ${{ tfm }} -p:UseAppHost=false | ||
projects: host/src/FunctionsNetHost.PlaceholderApp/FunctionsNetHost.PlaceholderApp.csproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,13 @@ jobs: | |
displayName: Download prelaunch artifacts | ||
inputs: | ||
artifactName: _preLaunchAppPackages | ||
path: $(Build.SourcesDirectory)/host/dist/portable | ||
path: $(Build.SourcesDirectory)/host/dist/portable/prelaunchapps | ||
|
||
- task: DownloadPipelineArtifact@2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we supposed to use |
||
displayName: Download pre-jit artifacts | ||
inputs: | ||
artifactName: _preJitAppPackages | ||
path: $(Build.SourcesDirectory)/host/dist/portable/prejit-placeholder-app | ||
|
||
- task: DownloadPipelineArtifact@2 | ||
displayName: Download host artifacts - linux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
host/src/FunctionsNetHost.PlaceholderApp/FunctionsNetHost.PlaceholderApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
<AssemblyName>Microsoft.Azure.Functions.NetHost.Placeholder</AssemblyName> | ||
<Version>1.0.0</Version> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/../../../key.snk</AssemblyOriginatorKeyFile> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<TieredCompilation>false</TieredCompilation> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\FunctionsNetHost.Shared\FunctionsNetHost.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="JitTrace\linux.coldstart.jittrace"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="JitTrace\coldstart.jittrace"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
31 changes: 31 additions & 0 deletions
31
host/src/FunctionsNetHost.PlaceholderApp/FunctionsNetHost.PlaceholderApp.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.12.35209.166 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionsNetHost.PlaceholderApp", "FunctionsNetHost.PlaceholderApp.csproj", "{A102AA50-8331-4E2E-B926-F37BA4CA4F83}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionsNetHost.Shared", "..\FunctionsNetHost.Shared\FunctionsNetHost.Shared.csproj", "{298B4E58-F398-4943-9F68-9B9F0DCE0B84}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A102AA50-8331-4E2E-B926-F37BA4CA4F83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A102AA50-8331-4E2E-B926-F37BA4CA4F83}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A102AA50-8331-4E2E-B926-F37BA4CA4F83}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A102AA50-8331-4E2E-B926-F37BA4CA4F83}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{298B4E58-F398-4943-9F68-9B9F0DCE0B84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{298B4E58-F398-4943-9F68-9B9F0DCE0B84}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{298B4E58-F398-4943-9F68-9B9F0DCE0B84}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{298B4E58-F398-4943-9F68-9B9F0DCE0B84}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {93CA0BCF-0402-4BDF-86B8-2600B81AFFEB} | ||
EndGlobalSection | ||
EndGlobal |
74 changes: 74 additions & 0 deletions
74
host/src/FunctionsNetHost.PlaceholderApp/Interop/NativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using FunctionsNetHost.Shared.Interop; | ||
|
||
namespace FunctionsNetHost.PlaceholderApp.Interop | ||
{ | ||
internal static unsafe class NativeMethods | ||
{ | ||
private const string NativeWorkerDll = "FunctionsNetHost.exe"; | ||
private static readonly ManualResetEventSlim SpecializationWaitHandle = new(false); | ||
private static SpecializeMessage _specializationMessage; | ||
|
||
static NativeMethods() | ||
{ | ||
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, ImportResolver); | ||
} | ||
|
||
internal static unsafe void RegisterForStartupHookCallback() | ||
{ | ||
RegisterStartupHookMessageHandlingCallback(&StartupHookCallbackHandler, nint.Zero); | ||
} | ||
|
||
/// <summary> | ||
/// Waits for the specialization message from the native code. | ||
/// This method blocks until the specialization event occurs and the message is received. | ||
/// Once the message is received, it returns the content of the specialization message. | ||
/// </summary> | ||
internal static SpecializeMessage WaitForSpecializationMessage() | ||
{ | ||
SpecializationWaitHandle.Wait(); | ||
|
||
// Don't need _specializationWaitHandle anymore. Dispose it. | ||
SpecializationWaitHandle.Dispose(); | ||
|
||
return _specializationMessage; | ||
} | ||
|
||
private static void RegisterStartupHookMessageHandlingCallback(delegate* unmanaged<byte**, int, nint, nint> requestCallback, nint grpcHandler) | ||
{ | ||
_ = register_startuphook_callback(nint.Zero, requestCallback, grpcHandler); | ||
} | ||
|
||
[DllImport(NativeWorkerDll)] | ||
private static extern unsafe int register_startuphook_callback(nint pInProcessApplication, delegate* unmanaged<byte**, int, nint, nint> requestCallback, nint grpcHandler); | ||
|
||
[UnmanagedCallersOnly] | ||
private static unsafe nint StartupHookCallbackHandler(byte** nativeMessage, int nativeMessageSize, nint grpcHandler) | ||
{ | ||
_specializationMessage = SpecializeMessage.FromByteArray(new Span<byte>(*nativeMessage, nativeMessageSize).ToArray()); | ||
SpecializationWaitHandle.Set(); | ||
|
||
return nint.Zero; | ||
} | ||
|
||
/// <summary> | ||
/// Custom import resolve callback. | ||
/// When trying to resolve "FunctionsNetHost", we return the handle using GetMainProgramHandle API in this callback. | ||
/// </summary> | ||
private static nint ImportResolver(string libraryName, System.Reflection.Assembly assembly, DllImportSearchPath? searchPath) | ||
{ | ||
if (libraryName == NativeWorkerDll) | ||
{ | ||
return NativeLibrary.GetMainProgramHandle(); | ||
} | ||
|
||
// Return 0 so that built-in resolving code will be executed. | ||
return nint.Zero; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider making this a variable