From a6e85ec08d51d8680e63677c6cede7b23e789469 Mon Sep 17 00:00:00 2001 From: Johan Lorensson Date: Thu, 7 Jan 2021 09:05:28 +0100 Subject: [PATCH] Backport changes affecting EventPipe from PR 38225 into C library. (#46219) * Backport changes affecting EventPipe from PR 38225 into C library. * Mono only supports portable thread pool. --- src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 10 ++++++++++ src/mono/mono/eventpipe/ep-rt-mono.h | 9 +++++++++ src/native/eventpipe/ep-config.c | 12 ++++++++++-- src/native/eventpipe/ep-rt.h | 4 ++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 91a359db0e8b7..8bed6e1f86131 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -11,6 +11,7 @@ #include "ep-session-provider.h" #include "fstream.h" #include "typestring.h" +#include "win32threadpool.h" #undef EP_ARRAY_SIZE #define EP_ARRAY_SIZE(expr) (sizeof(expr) / sizeof ((expr) [0])) @@ -1524,6 +1525,15 @@ ep_rt_config_value_get_circular_mb (void) return CLRConfig::GetConfigValue (CLRConfig::INTERNAL_EventPipeCircularMB); } +static +inline +bool +ep_rt_config_value_get_use_portable_thread_pool (void) +{ + STATIC_CONTRACT_NOTHROW; + return ThreadpoolMgr::UsePortableThreadPool (); +} + /* * EventPipeSampleProfiler. */ diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 2c7807b7e904d..6031050236bb3 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -980,6 +980,15 @@ ep_rt_config_value_get_circular_mb (void) return circular_mb; } +static +inline +bool +ep_rt_config_value_get_use_portable_thread_pool (void) +{ + // Only supports portable thread pool. + return true; +} + /* * EventPipeSampleProfiler. */ diff --git a/src/native/eventpipe/ep-config.c b/src/native/eventpipe/ep-config.c index 65dd0d72c38f8..0b1b8397f113b 100644 --- a/src/native/eventpipe/ep-config.c +++ b/src/native/eventpipe/ep-config.c @@ -95,8 +95,16 @@ config_register_provider ( ep_requires_lock_held (); - // See if we've already registered this provider. - EventPipeProvider *existing_provider = config_get_provider (config, ep_provider_get_provider_name (provider)); + // See if we've already registered this provider. When the portable thread pool is being used, allow there to be multiple + // DotNETRuntime providers, as the portable thread pool temporarily uses an event source on the managed side with the same + // provider name. + // TODO: This change to allow multiple DotNETRuntime providers is temporary to get EventPipe working for + // PortableThreadPoolEventSource. Once a long-term solution is figured out, this change should be reverted. See + // https://github.com/dotnet/runtime/issues/38763 for more information. + EventPipeProvider *existing_provider = NULL; + if (!ep_rt_config_value_get_use_portable_thread_pool () || ep_rt_utf8_string_compare (ep_config_get_public_provider_name_utf8 (), ep_provider_get_provider_name (provider)) != 0) + existing_provider = config_get_provider (config, ep_provider_get_provider_name (provider)); + if (existing_provider) return false; diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index e9c837ecf7a71..6c31a237f4d0f 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -294,6 +294,10 @@ static uint32_t ep_rt_config_value_get_circular_mb (void); +static +bool +ep_rt_config_value_get_use_portable_thread_pool (void); + /* * EventPipeSampleProfiler. */