Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4997,6 +4997,31 @@ AC_ARG_WITH(lazy_gc_thread_creation, [ --with-lazy-gc-thread-creation=yes|no
fi
], [with_lazy_gc_thread_creation=no])

dnl *****************************
dnl *** Thread suspend policy ***
dnl *****************************

dnl Set a default hybrid or cooperative suspend on some platforms

dnl Coop default is set by the bitcode preset.

dnl If coop isn't on by default, maybe hybrid should be?
if test x$enable_cooperative_suspend_default != xyes; then
case $HOST in
X86 | AMD64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure processor is relevant..but I guess ok, it disambiguates darwin, and we don't have Windows/arm support. What about Linux/arm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME? add host_macos, host_ios, and either remove host_darwin or make it clear host_darwin is maco | ios? And never say "osx"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does coop work w/o coop handles finished? We just treat transition from jit=>native differently based on if it is a handles() transition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The processor check is specifically because we only want to turn this on on Intel for now - it feels like there are more deadlocks to chase down on linux on ARM.

The coop handles (plus precise managed stack scanning) would allow us to skip the "copy stackdata" step when a thread self-suspends and to stop scanning the native stack conservatively. So not having them doesn't preclude using hybrid suspend today.

dnl Some host/target confusion, there's no host_osx (and
dnl host_darwin would be true on iOS not just macOS).
if test x$target_osx = xyes; then
enable_hybrid_suspend_default=yes
elif test x$host_linux = xyes -o x$host_win32 = xyes; then
enable_hybrid_suspend_default=yes
fi
;;
esac
fi

dnl Now check if there were flags overriding the defaults

AC_ARG_WITH(cooperative_gc, [ --with-cooperative-gc=yes|no Enable cooperative stop-the-world garbage collection (sgen only) (defaults to no)], [AC_MSG_WARN([--with-cooperative-gc is deprecated, use --enable-cooperative-suspend instead])], [with_cooperative_gc=default])
AC_ARG_ENABLE(cooperative_suspend, [ --enable-cooperative-suspend Enable cooperative stop-the-world garbage collection (sgen only) (defaults to no)], [], [enable_cooperative_suspend=default])

Expand Down Expand Up @@ -5030,6 +5055,12 @@ fi

AM_CONDITIONAL([ENABLE_HYBRID_SUSPEND], [test x$enable_hybrid_suspend != xno])

dnl End of thread suspend policy

dnl **********************
dnl *** checked builds ***
dnl **********************

AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable checked build (expensive asserts), configure with a comma-separated LIST of checked build modules and then include that same list in the environment variable MONO_CHECK_MODE at runtime. Recognized checked build modules: all, gc, metadata, thread, private_types],[

if test x$enable_checked_build != x ; then
Expand Down Expand Up @@ -5063,6 +5094,8 @@ AC_ARG_ENABLE(checked_build, [ --enable-checked-build=LIST To enable check
fi
], [])

dnl End of checked builds

AC_CHECK_HEADER([malloc.h],
[AC_DEFINE([HAVE_USR_INCLUDE_MALLOC_H], [1],
[Define to 1 if you have /usr/include/malloc.h.])],,)
Expand Down Expand Up @@ -5687,9 +5720,9 @@ fi

thread_suspend_msg=
if test x$buildsgen = xyes; then
if test x$enable_cooperative_suspend = xyes; then
if test x$enable_cooperative_suspend != xno; then
thread_suspend_msg="Suspend: Cooperative"
elif test x$enable_hybrid_suspend = xyes; then
elif test x$enable_hybrid_suspend != xno; then
thread_suspend_msg="Suspend: Hybrid"
else
thread_suspend_msg="Suspend: Preemptive"
Expand Down
2 changes: 2 additions & 0 deletions mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2311,9 +2311,11 @@ mono_gc_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void
{
int res;

MONO_ENTER_GC_SAFE;
mono_threads_join_lock ();
res = pthread_create (new_thread, attr, start_routine, arg);
mono_threads_join_unlock ();
MONO_EXIT_GC_SAFE;

return res;
}
Expand Down
3 changes: 2 additions & 1 deletion mono/mini/Makefile.am.in
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,9 @@ gsharedvtcheck:
hybridcheck:
$(MAKE) fullaotcheck HYBRID=1

# FIXME: force preemptive suspend while interpreter doesn't support coop/hybird suspend
fullaotmixedcheck:
$(MAKE) fullaotcheck MIXED=1
$(MAKE) fullaotcheck MIXED=1 MONO_THREADS_SUSPEND=preemptive

fullaot_regtests = $(regtests)
fullaot_testing_deps = generics-variant-types.dll TestDriver.dll MemoryIntrinsics.dll
Expand Down
15 changes: 15 additions & 0 deletions mono/mini/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static FILE *mini_stats_fd;
static void mini_usage (void);
static void mono_runtime_set_execution_mode (MonoEEMode mode);
static int mono_jit_exec_internal (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
static void mono_interp_threads_suspend_check (void);

#ifdef HOST_WIN32
/* Need this to determine whether to detach console */
Expand Down Expand Up @@ -1810,6 +1811,7 @@ mono_enable_interp (const char *opts)
#ifndef MONO_ARCH_INTERPRETER_SUPPORTED
g_error ("--interpreter not supported on this architecture.\n");
#endif

}

/**
Expand Down Expand Up @@ -2664,6 +2666,9 @@ mono_runtime_set_execution_mode (MonoEEMode mode)
default:
g_error ("Unknown execution-mode %d", mode);
}

if (mono_use_interpreter)
mono_interp_threads_suspend_check ();
}

/**
Expand Down Expand Up @@ -2704,6 +2709,16 @@ mono_jit_set_trace_options (const char* options)
return TRUE;
}

static void
mono_interp_threads_suspend_check (void)
{
// FIXME: Add safepoint support and GC thread state transitions to the interpreter
if (mono_threads_are_safepoints_enabled ()) {
g_warning ("Interpreter does not support safepoints. Cannot use %s suspend with the interpreter.", mono_threads_suspend_policy_name ());
mono_threads_suspend_override_policy (MONO_THREADS_SUSPEND_FULL_PREEMPTIVE);
}
}

/**
* mono_set_signal_chaining:
*
Expand Down
29 changes: 18 additions & 11 deletions mono/utils/mono-threads-coop.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,6 @@ mono_threads_assert_gc_unsafe_region (void)
MONO_REQ_GC_UNSAFE_MODE;
}

/* -1 and 0 also used:
* -1 means uninitialized
* 0 means unset
*/
typedef enum {
MONO_THREADS_SUSPEND_FULL_PREEMPTIVE = 1,
MONO_THREADS_SUSPEND_FULL_COOP,
MONO_THREADS_SUSPEND_HYBRID
} MonoThreadsSuspendPolicy;

static MonoThreadsSuspendPolicy
threads_suspend_policy_default (void)
{
Expand Down Expand Up @@ -584,10 +574,12 @@ threads_suspend_policy_getenv (void)
return policy;
}

static MonoThreadsSuspendPolicy threads_suspend_policy = -1;

static MonoThreadsSuspendPolicy
mono_threads_suspend_policy (void)
{
static MonoThreadsSuspendPolicy policy = -1;
MonoThreadsSuspendPolicy policy = threads_suspend_policy;
if (G_UNLIKELY (policy == -1)) {
// thread suspend policy:
// if the MONO_THREADS_SUSPEND env is set, use it.
Expand All @@ -607,10 +599,25 @@ mono_threads_suspend_policy (void)
policy = MONO_THREADS_SUSPEND_FULL_PREEMPTIVE;

g_assert (policy > 0);
threads_suspend_policy = policy;
}
return policy;
}

/**
* mono_threads_suspend_override_policy:
*
* Don't use this. Provides a last resort escape hatch to override configure
* and environment settings and use the given thread suspend policy.
*
*/
void
mono_threads_suspend_override_policy (MonoThreadsSuspendPolicy new_policy)
{
threads_suspend_policy = new_policy;
g_warning ("Overriding suspend policy. Using %s suspend.", mono_threads_suspend_policy_name ());
}

const char*
mono_threads_suspend_policy_name (void)
{
Expand Down
14 changes: 14 additions & 0 deletions mono/utils/mono-threads-coop.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ mono_threads_safepoint (void)
mono_threads_state_poll ();
}

/* -1 and 0 also used:
* -1 means uninitialized
* 0 means unset
*/
typedef enum {
MONO_THREADS_SUSPEND_FULL_PREEMPTIVE = 1,
MONO_THREADS_SUSPEND_FULL_COOP,
MONO_THREADS_SUSPEND_HYBRID
} MonoThreadsSuspendPolicy;

/* Don't use this. */
void mono_threads_suspend_override_policy (MonoThreadsSuspendPolicy new_policy);


/*
* The following are used when detaching a thread. We need to pass the MonoThreadInfo*
* as a paramater as the thread info TLS key is being destructed, meaning that
Expand Down
4 changes: 3 additions & 1 deletion sdks/builds/android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ _android-$(1)_CONFIGURE_FLAGS= \
--with-btls-android-ndk=$$(ANDROID_TOOLCHAIN_DIR)/ndk \
--with-sigaltstack=yes \
--with-tls=pthread \
--without-ikvm-native
--without-ikvm-native \
--disable-cooperative-suspend \
--disable-hybrid-suspend

.stamp-android-$(1)-toolchain: | $$(if $$(IGNORE_PROVISION_ANDROID),,provision-android)
python "$$(ANDROID_TOOLCHAIN_DIR)/ndk/build/tools/make_standalone_toolchain.py" --verbose --force --api=$$(ANDROID_SDK_VERSION_$(1)) --arch=$(2) --install-dir=$$(ANDROID_TOOLCHAIN_PREFIX)/$(1)-clang
Expand Down
4 changes: 4 additions & 0 deletions sdks/builds/ios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ _ios-$(1)_CONFIGURE_FLAGS = \
--with-tls=pthread \
--without-ikvm-native \
--without-sigaltstack \
--disable-cooperative-suspend \
--disable-hybird-suspend \
$$(ios-$(1)_CONFIGURE_FLAGS)

.stamp-ios-$(1)-toolchain:
Expand Down Expand Up @@ -249,6 +251,8 @@ _ios-$(1)_CONFIGURE_FLAGS= \
--enable-monotouch \
--with-tls=pthread \
--without-ikvm-native \
--disable-cooperative-suspend \
--disable-hybrid-suspend \
$$(ios-$(1)_CONFIGURE_FLAGS)

# _ios-$(1)_CONFIGURE_FLAGS += --enable-extension-module=xamarin
Expand Down