Explorar el Código

Add a _STARPU_PTHREAD_CREATE macro and use it.

Also update the use_starpu_pthread_macros.cocci script.

[Coccinelle] use_starpu_pthread_macros.cocci.
Cyril Roelandt hace 12 años
padre
commit
2fcf7e6af2

+ 2 - 1
mpi/src/starpu_mpi.c

@@ -795,7 +795,8 @@ int _starpu_mpi_initialize(int initialize_mpi, int *rank, int *world_size)
 
         _STARPU_PTHREAD_MUTEX_INIT(&mutex_posted_requests, NULL);
 
-	pthread_create(&progress_thread, NULL, progress_thread_func, (void *)&initialize_mpi);
+	_STARPU_PTHREAD_CREATE(&progress_thread, NULL,
+			       progress_thread_func, (void *)&initialize_mpi);
 
 	_STARPU_PTHREAD_MUTEX_LOCK(&mutex);
 	while (!running)

+ 9 - 0
src/common/utils.h

@@ -61,6 +61,15 @@ char *_starpu_get_home_path(void);
 /* If FILE is currently on a comment line, eat it.  */
 void _starpu_drop_comments(FILE *f);
 
+#define _STARPU_PTHREAD_CREATE(thread, attr, routine, arg) do {                \
+	int p_ret = pthread_create((thread), (attr), (routine), (arg));	       \
+	if (STARPU_UNLIKELY(p_ret != 0)) {                                     \
+		fprintf(stderr,                                                \
+			"%s:%d pthread_create: %s\n",                          \
+			__FILE__, __LINE__, strerror(p_ret));                  \
+	}                                                                      \
+} while (0)
+
 #define _STARPU_PTHREAD_MUTEX_INIT(mutex, attr) {                              \
 	int p_ret = pthread_mutex_init((mutex), (attr));                       \
 	if (STARPU_UNLIKELY(p_ret)) {                                          \

+ 20 - 9
src/core/workers.c

@@ -383,8 +383,11 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 				driver.id.cpu_id = cpu;
 				if (_starpu_may_launch_driver(config->conf, &driver))
 				{
-					pthread_create(&workerarg->worker_thread,
-							NULL, _starpu_cpu_worker, workerarg);
+					_STARPU_PTHREAD_CREATE(
+						&workerarg->worker_thread,
+						NULL,
+						_starpu_cpu_worker,
+						workerarg);
 				}
 				else
 				{
@@ -400,8 +403,11 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 				driver.id.cuda_id = cuda;
 				if (_starpu_may_launch_driver(config->conf, &driver))
 				{
-					pthread_create(&workerarg->worker_thread,
-						       NULL, _starpu_cuda_worker, workerarg);
+					_STARPU_PTHREAD_CREATE(
+						&workerarg->worker_thread,
+						NULL,
+						_starpu_cuda_worker,
+						workerarg);
 				}
 				else
 				{
@@ -420,9 +426,11 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 				}
 				workerarg->set = NULL;
 				workerarg->worker_is_initialized = 0;
-				pthread_create(&workerarg->worker_thread,
-						NULL, _starpu_opencl_worker, workerarg);
-
+				_STARPU_PTHREAD_CREATE(
+					&workerarg->worker_thread,
+					NULL,
+					_starpu_opencl_worker,
+					workerarg);
 				break;
 #endif
 #ifdef STARPU_USE_GORDON
@@ -436,8 +444,11 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 
 					gordon_worker_set.set_is_initialized = 0;
 
-					pthread_create(&gordon_worker_set.worker_thread, NULL,
-							_starpu_gordon_worker, &gordon_worker_set);
+					_STARPU_PTHREAD_CREATE(
+						&gordon_worker_set.worker_thread,
+						NULL,
+						_starpu_gordon_worker,
+						&gordon_worker_set);
 
 					_STARPU_PTHREAD_MUTEX_LOCK(&gordon_worker_set.mutex);
 					while (!gordon_worker_set.set_is_initialized)

+ 2 - 1
src/drivers/gordon/driver_gordon.c

@@ -464,7 +464,8 @@ void *_starpu_gordon_worker(void *arg)
 	_STARPU_PTHREAD_MUTEX_INIT(&progress_mutex, NULL);
 	_STARPU_PTHREAD_COND_INIT(&progress_cond, NULL);
 
-	pthread_create(&progress_thread, NULL, gordon_worker_progress, gordon_set_arg);
+	_STARPU_PTHREAD_CREATE(&progress_thread, NULL,
+			       gordon_worker_progress, gordon_set_arg);
 
 	/* wait for the progression thread to be ready */
 	_STARPU_PTHREAD_MUTEX_LOCK(&progress_mutex);

+ 3 - 2
src/top/starpu_top_connection.c

@@ -31,6 +31,7 @@
 #include <top/starpu_top_connection.h>
 #include <top/starpu_top_message_queue.h>
 #include <starpu_top.h>
+#include <common/utils.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <string.h>
@@ -161,7 +162,7 @@ void _starpu_top_communications_threads_launcher(void)
 	pthread_attr_init(&threads_attr);
 	pthread_attr_setdetachstate(&threads_attr, PTHREAD_CREATE_DETACHED);
 
-	pthread_create(&from_ui, &threads_attr, message_from_ui, NULL);
-	pthread_create(&to_ui, &threads_attr, message_to_ui, NULL);
+	_STARPU_PTHREAD_CREATE(&from_ui, &threads_attr, message_from_ui, NULL);
+	_STARPU_PTHREAD_CREATE(&to_ui, &threads_attr, message_to_ui, NULL);
 }
 

+ 7 - 0
tools/dev/experimental/use_starpu_pthread_macros.cocci

@@ -21,6 +21,7 @@ virtual report
 
 @initialize:python depends on report || org@
 d = {
+'pthread_create'          : '_STARPU_PTHREAD_CREATE',
 'pthread_mutex_init'      : '_STARPU_PTHREAD_MUTEX_INIT',
 'pthread_mutex_lock'      : '_STARPU_PTHREAD_MUTEX_LOCK',
 'pthread_mutex_unlock'    : '_STARPU_PTHREAD_MUTEX_UNLOCK',
@@ -76,6 +77,12 @@ else:
 //
 // Patch mode.
 //
+@pthread_ depends on patch@
+expression E1, E2, E3, E4;
+@@
+- pthread_create(E1, E2, E3, E4);
++ _STARPU_PTHREAD_CREATE(E1, E2, E3, E4);
+
 @pthread_mutex_ depends on patch@
 expression E1, E2;
 @@

+ 2 - 0
tools/dev/experimental/use_starpu_pthread_macros_test.c

@@ -1,6 +1,8 @@
 static void
 foo(void)
 {
+	pthread_create(&th, NULL, f, &arg);
+
 	pthread_mutex_init(&mutex, NULL);
 	pthread_mutex_lock(&mutex);
 	pthread_mutex_unlock(&mutex);