Kaynağa Gözat

Fix spurious direct use of pthread_* stuff. This fixes simgrid termination

Samuel Thibault 11 yıl önce
ebeveyn
işleme
50a6cfea59

+ 35 - 1
include/starpu_thread.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012-2013  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012-2014  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
@@ -23,6 +23,7 @@ extern "C"
 {
 #endif
 
+#include <starpu_config.h>
 #ifdef STARPU_SIMGRID
 #include <xbt/synchro_core.h>
 #include <msg/msg.h>
@@ -181,10 +182,43 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock);
 
 #endif /* STARPU_SIMGRID, _MSC_VER */
 
+/*
+ * Encapsulation of the pthread_barrier_* functions.
+ */
+
+#ifdef STARPU_SIMGRID
+
+typedef struct {
+	starpu_pthread_mutex_t mutex;
+	starpu_pthread_cond_t cond;
+	unsigned count;
+	unsigned done;
+} starpu_pthread_barrier_t;
+typedef int starpu_pthread_barrierattr_t;
+#define STARPU_PTHREAD_BARRIER_SERIAL_THREAD -1
+
+int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_pthread_barrierattr_t *attr, unsigned count);
+int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier);
+int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier);
+
+#elif !defined(_MSC_VER) /* STARPU_SIMGRID */
+
+typedef pthread_barrier_t starpu_pthread_barrier_t;
+typedef pthread_barrierattr_t starpu_pthread_barrierattr_t;
+
+#define starpu_pthread_barrier_init pthread_barrier_init
+#define starpu_pthread_barrier_destroy pthread_barrier_destroy
+
+int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier);
+#define STARPU_PTHREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD
+
+#endif /* STARPU_SIMGRID, _MSC_VER */
+
 #ifdef _MSC_VER
 typedef void* starpu_pthread_rwlock_t;
 typedef void* starpu_pthread_mutex_t;
 typedef void* starpu_pthread_cond_t;
+typedef void* starpu_pthread_barrier_t;
 #endif /* _MSC_VER */
 
 #ifdef __cplusplus

+ 8 - 8
include/starpu_thread_util.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012-2013  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012-2014  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
@@ -277,30 +277,30 @@ int _starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock, char *file
  */
 
 #define STARPU_PTHREAD_BARRIER_INIT(barrier, attr, count) do {                \
-	int p_ret = pthread_barrier_init((barrier), (attr), (count));          \
+	int p_ret = starpu_pthread_barrier_init((barrier), (attr), (count));          \
 	if (STARPU_UNLIKELY(p_ret)) {                                          \
 		fprintf(stderr,                                                \
-			"%s:%d pthread_barrier_init: %s\n",                    \
+			"%s:%d starpu_pthread_barrier_init: %s\n",                    \
 			__FILE__, __LINE__, strerror(p_ret));                  \
 		STARPU_ABORT();                                                \
 	}                                                                      \
 } while (0)
 
 #define STARPU_PTHREAD_BARRIER_DESTROY(barrier) do {                          \
-	int p_ret = pthread_barrier_destroy((barrier));                        \
+	int p_ret = starpu_pthread_barrier_destroy((barrier));                        \
 	if (STARPU_UNLIKELY(p_ret)) {                                          \
 		fprintf(stderr,                                                \
-			"%s:%d pthread_barrier_destroy: %s\n",                 \
+			"%s:%d starpu_pthread_barrier_destroy: %s\n",                 \
 			__FILE__, __LINE__, strerror(p_ret));                  \
 		STARPU_ABORT();                                                \
 	}                                                                      \
 } while (0)
 
 #define STARPU_PTHREAD_BARRIER_WAIT(barrier) do {                             	\
-	int p_ret = pthread_barrier_wait((barrier));				\
-	if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == PTHREAD_BARRIER_SERIAL_THREAD)))) { \
+	int p_ret = starpu_pthread_barrier_wait((barrier));				\
+	if (STARPU_UNLIKELY(!((p_ret == 0) || (p_ret == STARPU_PTHREAD_BARRIER_SERIAL_THREAD)))) { \
 		fprintf(stderr,                                                \
-			"%s:%d pthread_barrier_wait: %s\n",                    \
+			"%s:%d starpu_pthread_barrier_wait: %s\n",                    \
 			__FILE__, __LINE__, strerror(p_ret));                  \
 			STARPU_ABORT();                                        \
 	}                                                                      \

+ 1 - 1
src/common/barrier.c

@@ -74,7 +74,7 @@ int _starpu_barrier_wait(struct _starpu_barrier *barrier)
 	{
 		barrier->reached_start = 0;
 		STARPU_PTHREAD_COND_BROADCAST(&barrier->cond);
-		ret = PTHREAD_BARRIER_SERIAL_THREAD;
+		ret = STARPU_PTHREAD_BARRIER_SERIAL_THREAD;
 	}
 	else
 	{

+ 0 - 13
src/common/barrier.h

@@ -17,11 +17,6 @@
 #ifndef __COMMON_BARRIER_H__
 #define __COMMON_BARRIER_H__
 
-#ifdef STARPU_SIMGRID
-/* Force using our implementation of barriers, so it can be simgridish */
-#undef PTHREAD_BARRIER_SERIAL_THREAD
-#endif
-
 #include <starpu_thread.h>
 
 struct _starpu_barrier
@@ -41,12 +36,4 @@ int _starpu_barrier_destroy(struct _starpu_barrier *barrier);
 
 int _starpu_barrier_wait(struct _starpu_barrier *barrier);
 
-#if !defined(PTHREAD_BARRIER_SERIAL_THREAD)
-#  define PTHREAD_BARRIER_SERIAL_THREAD -1
-#  define pthread_barrier_t struct _starpu_barrier
-#  define pthread_barrier_init(b,a,c) _starpu_barrier_init(b, c)
-#  define pthread_barrier_destroy(b) _starpu_barrier_destroy(b)
-#  define pthread_barrier_wait(b) _starpu_barrier_wait(b)
-#endif /* !PTHREAD_BARRIER_SERIAL_THREAD */
-
 #endif // __COMMON_BARRIER_H__

+ 20 - 1
src/common/fxt.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2013  Université de Bordeaux 1
+ * Copyright (C) 2009-2014  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
@@ -149,6 +149,9 @@
 #define	_STARPU_FUT_HYPERVISOR_BEGIN    0x5160
 #define	_STARPU_FUT_HYPERVISOR_END	0x5161
 
+#define _STARPU_FUT_BARRIER_WAIT_BEGIN		0x5162
+#define _STARPU_FUT_BARRIER_WAIT_END		0x5163
+
 #ifdef STARPU_USE_FXT
 #include <fxt/fxt.h>
 #include <fxt/fut.h>
@@ -584,6 +587,18 @@ do {										\
 	_STARPU_FUT_DO_PROBE2STR(_STARPU_FUT_COND_WAIT_END,__LINE__,_starpu_gettid(),file); \
 } while(0)
 
+#define _STARPU_TRACE_BARRIER_WAIT_BEGIN()	do { \
+	const char *file; \
+	file = strrchr(__FILE__,'/') + 1; \
+	_STARPU_FUT_DO_PROBE2STR(_STARPU_FUT_BARRIER_WAIT_BEGIN,__LINE__,_starpu_gettid(),file); \
+} while(0)
+
+#define _STARPU_TRACE_BARRIER_WAIT_END()	do { \
+	const char *file; \
+	file = strrchr(__FILE__,'/') + 1; \
+	_STARPU_FUT_DO_PROBE2STR(_STARPU_FUT_BARRIER_WAIT_END,__LINE__,_starpu_gettid(),file); \
+} while(0)
+
 #else // !STARPU_FXT_LOCK_TRACES
 
 #define _STARPU_TRACE_LOCKING_MUTEX()			do {} while(0)
@@ -604,6 +619,8 @@ do {										\
 #define _STARPU_TRACE_TRYLOCK_SPINLOCK()		do {} while(0)
 #define _STARPU_TRACE_COND_WAIT_BEGIN()		do {} while(0)
 #define _STARPU_TRACE_COND_WAIT_END()			do {} while(0)
+#define _STARPU_TRACE_BARRIER_WAIT_BEGIN()		do {} while(0)
+#define _STARPU_TRACE_BARRIER_WAIT_END()			do {} while(0)
 
 #endif // STARPU_FXT_LOCK_TRACES
 
@@ -684,6 +701,8 @@ do {										\
 #define _STARPU_TRACE_TRYLOCK_SPINLOCK()		do {} while(0)
 #define _STARPU_TRACE_COND_WAIT_BEGIN()		do {} while(0)
 #define _STARPU_TRACE_COND_WAIT_END()			do {} while(0)
+#define _STARPU_TRACE_BARRIER_WAIT_BEGIN()		do {} while(0)
+#define _STARPU_TRACE_BARRIER_WAIT_END()			do {} while(0)
 #define _STARPU_TRACE_MEMORY_FULL(size)				do {} while(0)
 #define _STARPU_TRACE_START_UNPARTITION(handle, memnode)	do {} while(0)
 #define _STARPU_TRACE_END_UNPARTITION(handle, memnode)		do {} while(0)

+ 55 - 2
src/common/thread.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012-2013  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012-2014  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
@@ -198,7 +198,7 @@ int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)
 
 int starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *restrict rwlock, const starpu_pthread_rwlockattr_t *restrict attr)
 {
-	return starpu_pthread_mutex_init(rwlock, attr);
+	return starpu_pthread_mutex_init(rwlock, NULL);
 }
 
 int starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)
@@ -260,6 +260,47 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
 	return p_ret;
 }
 
+int starpu_pthread_barrier_init(starpu_pthread_barrier_t *restrict barrier, const starpu_pthread_barrierattr_t *restrict attr, unsigned count)
+{
+	int ret = starpu_pthread_mutex_init(&barrier->mutex, NULL);
+	if (!ret)
+		ret = starpu_pthread_cond_init(&barrier->cond, NULL);
+	barrier->count = count;
+	barrier->done = 0;
+	return ret;
+}
+
+int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier)
+{
+	int ret = starpu_pthread_mutex_destroy(&barrier->mutex);
+	if (!ret)
+		ret = starpu_pthread_cond_destroy(&barrier->cond);
+	return ret;
+}
+
+int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
+{
+	int ret = 0;
+	_STARPU_TRACE_BARRIER_WAIT_BEGIN();
+
+	starpu_pthread_mutex_lock(&barrier->mutex);
+	barrier->done++;
+	if (barrier->done == barrier->count)
+	{
+		barrier->done = 0;
+		starpu_pthread_cond_broadcast(&barrier->cond);
+		ret = STARPU_PTHREAD_BARRIER_SERIAL_THREAD;
+	} else {
+		starpu_pthread_cond_wait(&barrier->cond, &barrier->mutex);
+	}
+
+	starpu_pthread_mutex_unlock(&barrier->mutex);
+
+	_STARPU_TRACE_BARRIER_WAIT_END();
+
+	return ret;
+}
+
 #elif !defined(_MSC_VER) /* !STARPU_SIMGRID */
 
 int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
@@ -377,4 +418,16 @@ int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
 	return p_ret;
 }
 
+int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
+{
+	int ret;
+	_STARPU_TRACE_BARRIER_WAIT_BEGIN();
+
+	ret = pthread_barrier_wait(barrier);
+
+	_STARPU_TRACE_BARRIER_WAIT_END();
+
+	return ret;
+}
+
 #endif /* STARPU_SIMGRID, _MSC_VER */

+ 2 - 4
src/common/thread.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012-2013  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012-2014  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
@@ -8,7 +8,7 @@
  * the Free Software Foundation; either version 2.1 of the License, or (at
  * your option) any later version.
  *
- * StarPU is distributed in the hope that it will be useful, but
+ * StarPr is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
@@ -21,8 +21,6 @@
 #include <starpu.h>
 #include <common/fxt.h>
 
-#define _starpu_pthread_barrier_t pthread_barrier_t
-
 #ifdef HAVE_PTHREAD_SPIN_LOCK
 typedef pthread_spinlock_t _starpu_pthread_spinlock_t;
 #endif

+ 2 - 2
src/core/combined_workers.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2013  Université de Bordeaux 1
+ * Copyright (C) 2010-2014  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -108,7 +108,7 @@ int starpu_combined_worker_assign_workerid(int nworkers, int workerid_array[])
 	
 #ifdef STARPU_USE_MP
 	combined_worker->count = nworkers -1;
-	pthread_mutex_init(&combined_worker->count_mutex,NULL);
+	STARPU_PTHREAD_MUTEX_INIT(&combined_worker->count_mutex,NULL);
 #endif
 
 	/* We assume that the memory node should either be that of the first

+ 3 - 3
src/core/jobs.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2013  Université de Bordeaux 1
+ * Copyright (C) 2009-2014  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2013  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Télécom-SudParis
  *
@@ -136,8 +136,8 @@ LIST_TYPE(_starpu_job,
 	int active_task_alias_count;
 
 	/* Parallel workers may have to synchronize before/after the execution of a parallel task. */
-	_starpu_pthread_barrier_t before_work_barrier;
-	_starpu_pthread_barrier_t after_work_barrier;
+	starpu_pthread_barrier_t before_work_barrier;
+	starpu_pthread_barrier_t after_work_barrier;
 )
 
 /* Create an internal struct _starpu_job *structure to encapsulate the task. */

+ 7 - 1
src/debug/traces/starpu_fxt.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2013  Université de Bordeaux 1
+ * Copyright (C) 2009-2014  Université de Bordeaux 1
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -1692,6 +1692,12 @@ void starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *opt
 			case _STARPU_FUT_COND_WAIT_END:
 				break;
 
+			case _STARPU_FUT_BARRIER_WAIT_BEGIN:
+				break;
+
+			case _STARPU_FUT_BARRIER_WAIT_END:
+				break;
+
 			case _STARPU_FUT_MEMORY_FULL:
 				break;
 

+ 2 - 2
src/drivers/mic/driver_mic_source.c

@@ -51,12 +51,12 @@ struct _starpu_mic_kernel
 
 /* Mutex for concurrent access to the table.
  */
-starpu_pthread_mutex_t htbl_mutex = PTHREAD_MUTEX_INITIALIZER;
+starpu_pthread_mutex_t htbl_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 
 /* Number of MIC worker initialized.
  */
 unsigned int nb_mic_worker_init = 0;
-starpu_pthread_mutex_t nb_mic_worker_init_mutex = PTHREAD_MUTEX_INITIALIZER;
+starpu_pthread_mutex_t nb_mic_worker_init_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 
 /* Returns the ID of the MIC device controlled by the caller.
  * if the worker doesn't control a MIC device -ENODEV is returned

+ 3 - 3
src/drivers/mp_common/mp_common.h

@@ -102,8 +102,8 @@ struct _starpu_mp_transfer_command_to_device
 
 LIST_TYPE(mp_barrier,
 		int id;
-		_starpu_pthread_barrier_t before_work_barrier;
-		_starpu_pthread_barrier_t after_work_barrier;
+		starpu_pthread_barrier_t before_work_barrier;
+		starpu_pthread_barrier_t after_work_barrier;
 	 );
 
 LIST_TYPE(mp_message,
@@ -178,7 +178,7 @@ struct _starpu_mp_node
 	union _starpu_mp_connection *sink_sink_dt_connections;
 
 	/* */
-	_starpu_pthread_barrier_t init_completed_barrier; 
+	starpu_pthread_barrier_t init_completed_barrier; 
 	
 	/* table to store pointer of the thread workers*/
 	void* thread_table;