Mono EventPipe fixes. (#52437)
authorJohan Lorensson <lateralusx.github@gmail.com>
Mon, 10 May 2021 06:43:23 +0000 (08:43 +0200)
committerGitHub <noreply@github.com>
Mon, 10 May 2021 06:43:23 +0000 (08:43 +0200)
Correct conversion of COMPlus_EventPipeCircularMB value.

CoreClr detach/shutdown is flagged much later than Mono, meaning
Mono won't run function in ep_shutdown. Since EventPipe won't
out live runtime and already runs and shutdown as integrated part
of Mono shutdown, this will always be FALSE on Mono.

Thread sleep needs to enter/exit GC safe or it will block STW, delaying
operations like sample profiler and GC.

src/mono/mono/eventpipe/ep-rt-mono.h

index 5d82475..47e8693 100644 (file)
@@ -872,7 +872,7 @@ ep_rt_config_value_get_circular_mb (void)
        uint32_t circular_mb = 0;
        gchar *value = g_getenv ("COMPlus_EventPipeCircularMB");
        if (value)
-               circular_mb = strtoul (value, NULL, 9);
+               circular_mb = strtoul (value, NULL, 10);
        g_free (value);
        return circular_mb;
 }
@@ -1097,7 +1097,9 @@ inline
 bool
 ep_rt_process_detach (void)
 {
-       return (mono_runtime_is_shutting_down () == TRUE) ? true : false;
+       // This is set to early in Mono compared to coreclr and only represent runtime
+       // shutting down. EventPipe won't be shutdown to late on Mono, so always return FALSE.
+       return FALSE;
 }
 
 static
@@ -1247,7 +1249,14 @@ inline
 void
 ep_rt_thread_sleep (uint64_t ns)
 {
-       g_usleep (ns / 1000);
+       MONO_REQ_GC_UNSAFE_MODE;
+       if (ns == 0) {
+               mono_thread_info_yield ();
+       } else {
+               MONO_ENTER_GC_SAFE;
+               g_usleep (ns / 1000);
+               MONO_EXIT_GC_SAFE;
+       }
 }
 
 static