浏览代码

Benefit from simgrid's xbt_cond_timedwait

Samuel Thibault 7 年之前
父节点
当前提交
b0aa2b839f
共有 3 个文件被更改,包括 14 次插入21 次删除
  1. 0 10
      include/starpu_thread_util.h
  2. 5 3
      src/common/thread.c
  3. 9 8
      src/drivers/cpu/driver_cpu.c

+ 0 - 10
include/starpu_thread_util.h

@@ -347,16 +347,6 @@ int _starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_m
 }
 #endif
 
-#define STARPU_PTHREAD_COND_TIMED_WAIT(cond, mutex, abstime) do {              \
-	int p_ret = starpu_pthread_cond_timedwait((cond), (mutex), (abstime)); \
-	if (STARPU_UNLIKELY(p_ret && p_ret != ETIMEDOUT)) {                    \
-		fprintf(stderr,                                                \
-			"%s:%d starpu_pthread_cond_timedwait: %s\n",           \
-			__FILE__, __LINE__, strerror(p_ret));                  \
-		STARPU_ABORT();                                                \
-	}                                                                      \
-} while (0)
-
 /*
  * Encapsulation of the starpu_pthread_barrier_* functions.
  */

+ 5 - 3
src/common/thread.c

@@ -345,6 +345,7 @@ int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mu
 {
 	struct timespec now, delta;
 	double delay;
+	int ret = 0;
 	_starpu_clock_gettime(&now);
 	delta.tv_sec = abstime->tv_sec - now.tv_sec;
 	delta.tv_nsec = abstime->tv_nsec - now.tv_nsec;
@@ -353,12 +354,13 @@ int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mu
 	_STARPU_TRACE_COND_WAIT_BEGIN();
 
 	_starpu_pthread_cond_auto_init(cond);
-	xbt_cond_timedwait(*cond, *mutex, delay);
-	STARPU_ASSERT_MSG(0, "FIXME: we don't have a return value for ETIMEOUT");
+#if SIMGRID_VERSION_MAJOR > 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR >= 18)
+	ret = xbt_cond_timedwait(*cond, *mutex, delay) ? -ETIMEDOUT : 0;
+#endif
 
 	_STARPU_TRACE_COND_WAIT_END();
 
-	return 0;
+	return ret;
 }
 
 int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)

+ 9 - 8
src/drivers/cpu/driver_cpu.c

@@ -344,23 +344,24 @@ int _starpu_cpu_driver_run_once(struct _starpu_worker *cpu_worker)
 		task = _starpu_get_worker_task(cpu_worker, workerid, memnode);
 
 #ifdef STARPU_SIMGRID
- #ifdef WHEN_starpu_pthread_wait_timedwait_IS_FIXED_WITH_SIMGRID
+ #ifndef STARPU_OPENMP
+	if (!res && !task)
+		/* No progress, wait */
+		starpu_pthread_wait_wait(&cpu_worker->wait);
+ #else
+  #if SIMGRID_VERSION_MAJOR > 3 || (SIMGRID_VERSION_MAJOR == 3 && SIMGRID_VERSION_MINOR >= 18)
 	if (!res && !task)
 	{
 		/* No progress, wait (but at most 1s for OpenMP support) */
+		/* TODO: ideally, make OpenMP wake worker when run_once should return */
 		struct timespec abstime;
 		_starpu_clock_gettime(&abstime);
 		abstime.tv_sec++;
 		starpu_pthread_wait_timedwait(&cpu_worker->wait, &abstime);
 	}
- #else
-  #ifdef STARPU_OPENMP
-	/* FIXME: properly test termination for caller */
-	MSG_process_sleep(0.001);
   #else
-	if (!res && !task)
-		/* No progress, wait */
-		starpu_pthread_wait_wait(&cpu_worker->wait);
+	/* Previous simgrid versions don't really permit to use wait_timedwait in C */
+	MSG_process_sleep(0.001);
   #endif
  #endif
 #endif