Skip to content

Commit

Permalink
[mono] Set thread suspend default in mono.proj; default to hybrid (#4…
Browse files Browse the repository at this point in the history
…6873)

* [mono] Set thread suspend default in mono.proj; default to hybrid

Instead of detecting in cmake, make a decision in mono.proj

* [cmake] Pick a fallback suspend policy if GC_SUSPEND is default

* cleanup mono.proj

* default to "preemptive" on wasm

It isn't really preemptive, it just turns off safepoint code in the AOT
compiler.  This is fine for single threaded.
  • Loading branch information
lambdageek committed Jan 16, 2021
1 parent f76f1ef commit c31d8ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(ANDROID_UNIFIED_HEADERS 1)
set(ENABLE_MONODROID 1)
set(DISABLE_EXECUTABLES 1)
set(GC_SUSPEND "hybrid")
# Force some defines
set(HAVE_SCHED_GETAFFINITY 0)
set(HAVE_SCHED_SETAFFINITY 0)
Expand Down Expand Up @@ -264,9 +263,6 @@ if(TARGET_SYSTEM_NAME STREQUAL "Darwin")
set(TARGET_MACH 1)
set(TARGET_OSX 1)
set(TARGET_DARWIN 1)
if (GC_SUSPEND STREQUAL "default")
set(GC_SUSPEND "hybrid")
endif()
elseif(TARGET_SYSTEM_NAME STREQUAL "iOS" OR TARGET_SYSTEM_NAME STREQUAL "tvOS")
set(TARGET_MACH 1)
set(TARGET_IOS 1)
Expand Down Expand Up @@ -552,6 +548,20 @@ if (GC_SUSPEND STREQUAL "coop")
set(ENABLE_COOP_SUSPEND 1)
elseif(GC_SUSPEND STREQUAL "hybrid")
set(ENABLE_HYBRID_SUSPEND 1)
elseif(GC_SUSPEND STREQUAL "preemptive")
elseif(GC_SUSPEND STREQUAL "default")
# set some kind of fallback default
if(TARGET_SYSTEM_NAME STREQUAL "watchOS")
set(ENABLE_COOP_SUSPEND 1)
elseif(TARGET_SYSTEM_NAME STREQUAL "Windows")
# use preemptive
elseif(TARGET_SYSTEM_NAME STREQUAL "Emscripten")
# use preemptive
else()
set(ENABLE_HYBRID_SUSPEND 1)
endif()
else()
message(FATAL_ERROR "GC_SUSPEND (set to '${GC_SUSPEND}') must be one of coop, hybrid or preemptive")
endif()

######################################
Expand Down
16 changes: 15 additions & 1 deletion src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- MonoAOTLLVMDir - [optional] the directory where LLVM is located, for an AOT-only Mono
- MonoVerboseBuild - enable verbose build
- MonoMetadataUpdate - enable experimental method body replacement code
- MonoThreadSuspend - coop,hybrid,preemptive - default thread suspend mode
-->

<PropertyGroup>
Expand Down Expand Up @@ -49,6 +50,15 @@
<MonoCxxCompiler Condition="'$(MonoCCompiler)' == 'gcc'">g++</MonoCxxCompiler>
</PropertyGroup>

<!-- default thread suspend for specific platforms -->
<PropertyGroup>
<MonoThreadSuspend Condition="'$(TargetswatchOS)' == 'true' and '$(MonoThreadSuspend)' == ''">coop</MonoThreadSuspend>
<!-- wasm isn't really preemptive, but we don't want safepoints -->
<MonoThreadSuspend Condition="'$(TargetsBrowser)' == 'true' and '$(MonoThreadSuspend)' == ''">preemptive</MonoThreadSuspend>
<!-- all other platforms -->
<MonoThreadSuspend Condition="'$(MonoThreadSuspend)' == ''">hybrid</MonoThreadSuspend>
</PropertyGroup>

<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
<PackageReference Include="Microsoft.NETCore.Runtime.ICU.Transport" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
</ItemGroup>
Expand Down Expand Up @@ -126,6 +136,7 @@
<_MonoCMakeArgs Include="-DCMAKE_INSTALL_LIBDIR=lib"/>
<_MonoCMakeArgs Include="-DCMAKE_BUILD_TYPE=$(Configuration)"/>
<_MonoCMakeArgs Condition="'$(MonoEnableLLVM)' == 'true'" Include="-DLLVM_PREFIX=$(MonoLLVMDir)" />
<_MonoCMakeArgs Include="-DGC_SUSPEND=$(MonoThreadSuspend)" />
</ItemGroup>

<!-- We build LLVM bits for x64 Linux without C++11 ABI (CentOS 7 has libstdc++ < 5.1) -->
Expand Down Expand Up @@ -434,7 +445,10 @@
<!-- FIXME: Add sanity check that the interpreter is enabled -->
<MonoAOTCMakeArgs Condition="'$(MonoMetadataUpdate)' == 'true'" Include="-DENABLE_METADATA_UPDATE=1" />

<!-- Select generator platform for VS generator -->
<!-- thread suspend -->
<MonoAOTCMakeArgs Include="-DGC_SUSPEND=$(MonoThreadSuspend)" />

<!-- Select generator platform for VS generator -->
<MonoAOTCMakeArgs Condition="'$(OS)' == 'Windows_NT' and '$(_MonoUseNinja)' != 'true' and '$(Platform)' == 'x64'" Include="-A x64" />
<MonoAOTCMakeArgs Condition="'$(OS)' == 'Windows_NT' and '$(_MonoUseNinja)' != 'true' and '$(Platform)' == 'x86'" Include="-A Win32" />
<MonoAOTCMakeArgs Condition="'$(OS)' == 'Windows_NT' and '$(_MonoUseNinja)' != 'true' and '$(Platform)' == 'arm'" Include="-A ARM" />
Expand Down

0 comments on commit c31d8ae

Please sign in to comment.