Prechádzať zdrojové kódy

port 11187 from 1.1: Fix livelock while running in valgrind: we really have to call sched_yield explicitly, rep nop is not enough

Samuel Thibault 11 rokov pred
rodič
commit
55124f1005
3 zmenil súbory, kde vykonal 18 pridanie a 8 odobranie
  1. 2 0
      configure.ac
  2. 0 8
      include/starpu_util.h
  3. 16 0
      src/common/utils.h

+ 2 - 0
configure.ac

@@ -258,6 +258,8 @@ AC_CHECK_HEADERS([malloc.h], [AC_DEFINE([STARPU_HAVE_MALLOC_H], [1], [Define to
 AC_CHECK_HEADERS([valgrind/valgrind.h], [AC_DEFINE([STARPU_HAVE_VALGRIND_H], [1], [Define to 1 if you have the <valgrind/valgrind.h> header file.])])
 AC_CHECK_HEADERS([valgrind/helgrind.h], [AC_DEFINE([STARPU_HAVE_HELGRIND_H], [1], [Define to 1 if you have the <valgrind/helgrind.h> header file.])])
 
+AC_CHECK_FUNC([sched_yield], [AC_DEFINE([STARPU_HAVE_SCHED_YIELD], [1], [Define to 1 if the function sched_yield is available.])])
+
 AC_CHECK_HEADERS([aio.h])
 
 # This defines HAVE_SYNC_VAL_COMPARE_AND_SWAP

+ 0 - 8
include/starpu_util.h

@@ -198,14 +198,6 @@ STARPU_ATOMIC_SOMETHING(or, old | value)
 #define STARPU_WMB() STARPU_SYNCHRONIZE()
 #endif
 
-/* This is needed in some places to make valgrind yield to another thread to be
- * able to progress.  */
-#if defined(__i386__) || defined(__x86_64__)
-#define STARPU_UYIELD() __asm__ __volatile("rep; nop")
-#else
-#define STARPU_UYIELD() ((void)0)
-#endif
-
 #ifdef __cplusplus
 }
 #endif

+ 16 - 0
src/common/utils.h

@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <math.h>
 #include <pthread.h>
+#ifdef STARPU_HAVE_SCHED_YIELD
+#include <sched.h>
+#endif
 
 #ifdef STARPU_HAVE_HELGRIND_H
 #include <valgrind/helgrind.h>
@@ -57,6 +60,19 @@
 #define STARPU_DEBUG_PREFIX "[starpu]"
 #endif
 
+/* This is needed in some places to make valgrind yield to another thread to be
+ * able to progress.  */
+#if defined(__i386__) || defined(__x86_64__)
+#define _STARPU_UYIELD() __asm__ __volatile("rep; nop")
+#else
+#define _STARPU_UYIELD() ((void)0)
+#endif
+#if defined(STARPU_HAVE_SCHED_YIELD) && defined(STARPU_HAVE_HELGRIND_H)
+#define STARPU_UYIELD() do { if (RUNNING_ON_VALGRIND) sched_yield(); else _STARPU_UYIELD(); } while (0)
+#else
+#define STARPU_UYIELD() _STARPU_UYIELD()
+#endif
+
 #ifdef STARPU_VERBOSE
 #  define _STARPU_DEBUG(fmt, ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
 #else