Преглед на файлове

Make valgrind yield to other threads when busy-looping, otherwise we may get stuck

Samuel Thibault преди 12 години
родител
ревизия
d3065fdc1b
променени са 4 файла, в които са добавени 18 реда и са изтрити 4 реда
  1. 9 1
      include/starpu_util.h
  2. 3 0
      src/common/starpu_spinlock.c
  3. 3 1
      src/datawizard/datawizard.c
  4. 3 2
      src/drivers/driver_common/driver_common.c

+ 9 - 1
include/starpu_util.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -186,6 +186,14 @@ 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

+ 3 - 0
src/common/starpu_spinlock.c

@@ -82,6 +82,7 @@ int _starpu_spin_lock(struct _starpu_spinlock *lock)
 		/* Give hand to another thread, hopefully the one which has the
 		 * spinlock and probably just has also a short-lived mutex. */
 		MSG_process_sleep(0.000001);
+		STARPU_UYIELD();
 	}
 #elif defined(STARPU_SPINLOCK_CHECK)
 	int ret = pthread_mutex_lock(&lock->errcheck_lock);
@@ -96,6 +97,8 @@ int _starpu_spin_lock(struct _starpu_spinlock *lock)
 	do
 	{
 		prev = STARPU_TEST_AND_SET(&lock->taken, 1);
+		if (prev)
+			STARPU_UYIELD();
 	}
 	while (prev);
 	return 0;

+ 3 - 1
src/datawizard/datawizard.c

@@ -26,12 +26,14 @@
 
 void _starpu_datawizard_progress(unsigned memory_node, unsigned may_alloc)
 {
-#ifdef STARPU_SIMGRID
 #if STARPU_DEVEL
 #warning FIXME
 #endif
+#ifdef STARPU_SIMGRID
 	MSG_process_sleep(0.000010);
 #endif
+	STARPU_UYIELD();
+
 	/* in case some other driver requested data */
 	_starpu_handle_pending_node_data_requests(memory_node);
 	_starpu_handle_node_data_requests(memory_node, may_alloc);

+ 3 - 2
src/drivers/driver_common/driver_common.c

@@ -174,11 +174,12 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *args, int wor
 
 		if (_starpu_worker_can_block(memnode))
 			_STARPU_PTHREAD_COND_WAIT(&args->sched_cond, &args->sched_mutex);
-#ifdef STARPU_SIMGRID
 		else
 		{
 			if (_starpu_machine_is_running())
 			{
+				STARPU_UYIELD();
+#ifdef STARPU_SIMGRID
 				static int warned;
 				if (!warned)
 				{
@@ -186,9 +187,9 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *args, int wor
 					_STARPU_DISP("Has to make simgrid spin for progression hooks\n");
 				}
 				MSG_process_sleep(0.000010);
+#endif
 			}
 		}
-#endif
 
 		_STARPU_PTHREAD_MUTEX_UNLOCK(&args->sched_mutex);