From 42967b645c5887284b0ba1fab5facc63c543d37b Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Thu, 24 Nov 2022 14:01:54 +0100 Subject: [PATCH 1/5] Adds a workaround for the dotnet runtime issue 77973 --- .../Datadog.Tracer.Native/cor_profiler.cpp | 33 +++++++++++++++++-- .../environment_variables.h | 3 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp index 3f54f17c9270..29945f99169b 100644 --- a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp +++ b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp @@ -215,6 +215,29 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un return E_FAIL; } + WSTRING runtimeType = runtime_information_.is_core() ? (runtime_information_.major_version > 4 ? WStr(".NET") : WStr(".NET Core")) : WStr(".NET Framework"); + Logger::Info("Runtime Information: ", runtimeType, " ", runtime_information_.major_version, ".", runtime_information_.minor_version, ".", runtime_information_.build_version); + + // Check if we have to disable tiered compilation (due to https://github.com/dotnet/runtime/issues/77973) + bool disableTieredCompilation = false; + bool internal_workaround_77973_enabled = true; + shared::TryParseBooleanEnvironmentValue(shared::GetEnvironmentValue(environment::internal_workaround_77973_enabled), internal_workaround_77973_enabled); + if (internal_workaround_77973_enabled) + { + if (runtime_information_.major_version == 5 || + (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 11) || + (runtime_information_.major_version == 7 && runtime_information_.minor_version == 0 && runtime_information_.build_version == 0)) + { + Logger::Warn("Tiered Compilation was disabled due to https://github.com/dotnet/runtime/issues/77973. This action can be disabled by setting the environment variable DD_INTERNAL_WORKAROUND_77973_ENABLED=false"); + disableTieredCompilation = true; + } + } + + if (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 11) + { + disableTieredCompilation = true; + } + auto pInfo = info10 != nullptr ? info10 : this->info_; auto work_offloader = std::make_shared(pInfo); @@ -255,8 +278,14 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un event_mask |= COR_PRF_DISABLE_ALL_NGEN_IMAGES; } - // set event mask to subscribe to events and disable NGEN images - hr = this->info_->SetEventMask2(event_mask, COR_PRF_HIGH_ADD_ASSEMBLY_REFERENCES); + DWORD high_event_mask = COR_PRF_HIGH_ADD_ASSEMBLY_REFERENCES; + if (disableTieredCompilation) + { + high_event_mask |= COR_PRF_HIGH_DISABLE_TIERED_COMPILATION; + } + + // set event mask to subscribe to events + hr = this->info_->SetEventMask2(event_mask, high_event_mask); if (FAILED(hr)) { Logger::Warn("DATADOG TRACER DIAGNOSTICS - Failed to attach profiler: unable to set event mask."); diff --git a/tracer/src/Datadog.Tracer.Native/environment_variables.h b/tracer/src/Datadog.Tracer.Native/environment_variables.h index 030500859cf7..3f110bcbfa2c 100644 --- a/tracer/src/Datadog.Tracer.Native/environment_variables.h +++ b/tracer/src/Datadog.Tracer.Native/environment_variables.h @@ -115,6 +115,9 @@ namespace environment // Sets whether the current process must run in CI Visibility mode or not. const shared::WSTRING ci_visibility_enabled = WStr("DD_CIVISIBILITY_ENABLED"); + // Enables the workaround for dotnet issue 77973 (https://github.com/dotnet/runtime/issues/77973) + const shared::WSTRING internal_workaround_77973_enabled = WStr("DD_INTERNAL_WORKAROUND_77973_ENABLED"); + } // namespace environment } // namespace trace From 7893b4038f1bd9784703d18623e87bec851210fc Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Thu, 24 Nov 2022 14:08:46 +0100 Subject: [PATCH 2/5] clean up --- tracer/src/Datadog.Tracer.Native/cor_profiler.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp index 29945f99169b..56f71f8bf870 100644 --- a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp +++ b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp @@ -233,11 +233,6 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un } } - if (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 11) - { - disableTieredCompilation = true; - } - auto pInfo = info10 != nullptr ? info10 : this->info_; auto work_offloader = std::make_shared(pInfo); From fc7bd6d10d5cf8f32ee5bbc736dc24f4c83af661 Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Thu, 24 Nov 2022 14:17:45 +0100 Subject: [PATCH 3/5] Remove previous workaround. --- tracer/build/_build/docker/smoke.dockerfile | 3 --- tracer/build/_build/docker/smoke.dotnet-tool.dockerfile | 3 --- tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile | 3 --- .../_build/docker/smoke.dotnet-tool.self-instrument.dockerfile | 3 --- tracer/build/_build/docker/smoke.windows.dockerfile | 3 --- .../build/_build/docker/smoke.windows.dotnet-tool.dockerfile | 3 --- tracer/build/_build/docker/smoke.windows.nuget.dockerfile | 3 --- .../build/_build/docker/smoke.windows.tracer-home.dockerfile | 3 --- tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs | 1 - 9 files changed, 25 deletions(-) diff --git a/tracer/build/_build/docker/smoke.dockerfile b/tracer/build/_build/docker/smoke.dockerfile index b5162d5dc505..89352309d8b5 100644 --- a/tracer/build/_build/docker/smoke.dockerfile +++ b/tracer/build/_build/docker/smoke.dockerfile @@ -38,9 +38,6 @@ ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet ENV ASPNETCORE_URLS=http://localhost:5000 -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile index 58c422f69173..37c5d0255928 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile @@ -32,9 +32,6 @@ ENV DD_TRACE_DEBUG=1 ENV ASPNETCORE_URLS=http://localhost:5000 ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile index 631c6bb5b1d6..bfb6b78b5cd5 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile @@ -32,9 +32,6 @@ ENV DD_TRACE_DEBUG=1 ENV ASPNETCORE_URLS=http://localhost:5000 ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile index 8f9afcdc6c8c..70e10f0b3469 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile @@ -41,9 +41,6 @@ ENV DD_TRACE_DEBUG=1 ENV ASPNETCORE_URLS=http://localhost:5000 ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.windows.dockerfile b/tracer/build/_build/docker/smoke.windows.dockerfile index 7ba449fe8a8d..d4f73c8a83c5 100644 --- a/tracer/build/_build/docker/smoke.windows.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.dockerfile @@ -43,9 +43,6 @@ ENV DD_PROFILING_ENABLED=1 \ DD_PROFILING_LOG_DIR="C:\logs" \ ASPNETCORE_URLS=http://localhost:5000 -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile b/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile index 7a2674291ce2..3a76ff82444f 100644 --- a/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile @@ -43,9 +43,6 @@ ENV DD_PROFILING_ENABLED=1 \ DD_PROFILING_LOG_DIR="C:\logs" \ ASPNETCORE_URLS=http://localhost:5000 -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.windows.nuget.dockerfile b/tracer/build/_build/docker/smoke.windows.nuget.dockerfile index 74a3b6d5c107..1beff6f20bef 100644 --- a/tracer/build/_build/docker/smoke.windows.nuget.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.nuget.dockerfile @@ -46,9 +46,6 @@ ENV CORECLR_ENABLE_PROFILING=1 \ DD_PROFILING_ENABLED=1 \ ASPNETCORE_URLS=http://localhost:5000 -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile b/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile index 7f8e02171112..113a0472208b 100644 --- a/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile @@ -50,9 +50,6 @@ ENV DD_PROFILING_ENABLED=1 \ DD_PROFILING_LOG_DIR="C:\logs" \ ASPNETCORE_URLS=http://localhost:5000 -# see https://github.com/dotnet/runtime/issues/77973 -ENV COMPlus_TieredCompilation=0 - # Copy the app across COPY --from=builder /src/publish /app/. diff --git a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs index 2e3a6906a244..1b57f96a4cb2 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs @@ -189,7 +189,6 @@ public void SetEnvironmentVariables( { string profilerEnabled = AutomaticInstrumentationEnabled ? "1" : "0"; environmentVariables["DD_DOTNET_TRACER_HOME"] = MonitoringHome; - environmentVariables["COMPlus_TieredCompilation"] = "0"; // Everything should be using the native loader now var nativeLoaderPath = GetNativeLoaderPath(); From bc4ca02b6048bdd69a8496da329339987da0a49b Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Mon, 12 Dec 2022 16:47:36 +0100 Subject: [PATCH 4/5] Changing the runtime versions according to the merged .NET runtime PRs --- tracer/src/Datadog.Tracer.Native/cor_profiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp index 56f71f8bf870..438391a31254 100644 --- a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp +++ b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp @@ -225,8 +225,8 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un if (internal_workaround_77973_enabled) { if (runtime_information_.major_version == 5 || - (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 11) || - (runtime_information_.major_version == 7 && runtime_information_.minor_version == 0 && runtime_information_.build_version == 0)) + (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 12) || + (runtime_information_.major_version == 7 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 1)) { Logger::Warn("Tiered Compilation was disabled due to https://github.com/dotnet/runtime/issues/77973. This action can be disabled by setting the environment variable DD_INTERNAL_WORKAROUND_77973_ENABLED=false"); disableTieredCompilation = true; From 874d40bbfac259c48bca37edf7dfca2f881a69d4 Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Mon, 12 Dec 2022 18:16:57 +0100 Subject: [PATCH 5/5] Change warning to info --- tracer/src/Datadog.Tracer.Native/cor_profiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp index 438391a31254..12960d26eab7 100644 --- a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp +++ b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp @@ -228,7 +228,7 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un (runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 12) || (runtime_information_.major_version == 7 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 1)) { - Logger::Warn("Tiered Compilation was disabled due to https://github.com/dotnet/runtime/issues/77973. This action can be disabled by setting the environment variable DD_INTERNAL_WORKAROUND_77973_ENABLED=false"); + Logger::Info("Tiered Compilation was disabled due to https://github.com/dotnet/runtime/issues/77973. This action can be disabled by setting the environment variable DD_INTERNAL_WORKAROUND_77973_ENABLED=false"); disableTieredCompilation = true; } }