소스 검색

Use pthread_setname_np when available

Samuel Thibault 8 년 전
부모
커밋
7339c8f5fe

+ 5 - 0
configure.ac

@@ -258,6 +258,11 @@ fi
 # yes, that's non portable, but it's still better than sched_setaffinity
 AC_CHECK_FUNCS(pthread_setaffinity_np)
 
+AC_CHECK_FUNC([pthread_setname_np], have_pthread_setname_np=yes, have_pthread_setname_np=no)
+if test x$have_pthread_setname_np = xyes; then
+	AC_DEFINE(STARPU_HAVE_PTHREAD_SETNAME_NP,[1],[pthread_setname_np is available])
+fi
+
 # There is no posix_memalign on Mac OS X, only memalign
 AC_CHECK_FUNCS([posix_memalign], [AC_DEFINE([STARPU_HAVE_POSIX_MEMALIGN], [1], [Define to 1 if you have the `posix_memalign' function.])])
 AC_CHECK_FUNCS([memalign], [AC_DEFINE([STARPU_HAVE_MEMALIGN], [1], [Define to 1 if you have the `memalign' function.])])

+ 1 - 0
include/starpu_config.h.in

@@ -134,6 +134,7 @@ typedef ssize_t starpu_ssize_t;
 #undef STARPU_HAVE_HWLOC
 #undef STARPU_HAVE_PTHREAD_SPIN_LOCK
 #undef STARPU_HAVE_PTHREAD_BARRIER
+#undef STARPU_HAVE_PTHREAD_SETNAME_NP
 #undef STARPU_HAVE_STRUCT_TIMESPEC
 
 /* This is only for building examples */

+ 6 - 0
include/starpu_thread.h

@@ -47,6 +47,7 @@ typedef msg_process_t starpu_pthread_t;
 typedef int starpu_pthread_attr_t;
 
 int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, msg_host_t host);
+#define starpu_pthread_setname(thread, name)
 int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
 int starpu_pthread_join(starpu_pthread_t thread, void **retval);
 int starpu_pthread_exit(void *retval) STARPU_ATTRIBUTE_NORETURN;
@@ -61,6 +62,11 @@ typedef pthread_attr_t starpu_pthread_attr_t;
 
 #define starpu_pthread_create pthread_create
 #define starpu_pthread_create_on(name, thread, attr, routine, arg, where) starpu_pthread_create(thread, attr, routine, arg)
+#ifdef STARPU_HAVE_PTHREAD_SETNAME_NP
+#define starpu_pthread_setname(thread, name) pthread_setname_np(thread, name)
+#else
+#define starpu_pthread_setname(thread, name)
+#endif
 #define starpu_pthread_join pthread_join
 #define starpu_pthread_exit pthread_exit
 #define starpu_pthread_attr_init pthread_attr_init

+ 2 - 0
mpi/src/starpu_mpi.c

@@ -1280,6 +1280,8 @@ static void *_starpu_mpi_progress_thread_func(void *arg)
 	struct _starpu_mpi_argc_argv *argc_argv = (struct _starpu_mpi_argc_argv *) arg;
 	int rank, worldsize;
 
+	starpu_pthread_setname(pthread_self(), "MPI");
+
 #ifndef STARPU_SIMGRID
 	_starpu_mpi_do_initialize(argc_argv);
 #endif

+ 1 - 0
src/core/task.c

@@ -1191,6 +1191,7 @@ static void *watchdog_func(void *arg)
 	timeout = ((float) atoll(timeout_env)) / 1000000;
 #endif
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
+	starpu_pthread_setname(pthread_self(), "watchdog");
 
 	STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
 	while (_starpu_machine_is_running())

+ 1 - 0
src/drivers/cpu/driver_cpu.c

@@ -217,6 +217,7 @@ int _starpu_cpu_driver_init(struct _starpu_worker *cpu_worker)
 
 	snprintf(cpu_worker->name, sizeof(cpu_worker->name), "CPU %d", devid);
 	snprintf(cpu_worker->short_name, sizeof(cpu_worker->short_name), "CPU %d", devid);
+	starpu_pthread_setname(pthread_self(), cpu_worker->short_name);
 
 	_STARPU_TRACE_WORKER_INIT_END(cpu_worker->workerid);
 

+ 5 - 0
src/drivers/cuda/driver_cuda.c

@@ -658,6 +658,11 @@ int _starpu_cuda_driver_init(struct _starpu_worker_set *worker_set)
 
 		_STARPU_TRACE_WORKER_INIT_END(workerid);
 	}
+	{
+		char thread_name[16];
+		snprintf(thread_name, sizeof(thread_name), "CUDA %u", worker0->devid);
+		starpu_pthread_setname(pthread_self(), thread_name);
+	}
 
 	/* tell the main thread that this one is ready */
 	STARPU_PTHREAD_MUTEX_LOCK(&worker0->mutex);

+ 6 - 0
src/drivers/mic/driver_mic_source.c

@@ -535,6 +535,12 @@ void *_starpu_mic_src_worker(void *arg)
 	{
 		struct _starpu_worker *worker = &config->workers[baseworkerid+i];
 		snprintf(worker->name, sizeof(worker->name), "MIC %d core %u", devid, i);
+		snprintf(worker->short_name, sizeof(worker->short_name), "MIC %d.%u", devid, i);
+	}
+	{
+		char thread_name[16];
+		snprintf(thread_name, sizeof(thread_name), "MIC %d", devid);
+		starpu_pthread_setname(pthread_self(), thread_name);
 	}
 
 	for (i = 0; i < worker_set->nworkers; i++)

+ 1 - 0
src/drivers/opencl/driver_opencl.c

@@ -640,6 +640,7 @@ int _starpu_opencl_driver_init(struct _starpu_worker *worker)
 #endif
 	snprintf(worker->name, sizeof(worker->name), "OpenCL %u (%s %.1f GiB)", devid, devname, size);
 	snprintf(worker->short_name, sizeof(worker->short_name), "OpenCL %u", devid);
+	starpu_pthread_setname(pthread_self(), worker->short_name);
 
 	worker->pipeline_length = starpu_get_env_number_default("STARPU_OPENCL_PIPELINE", 2);
 	if (worker->pipeline_length > STARPU_MAX_PIPELINE)

+ 7 - 1
src/drivers/scc/driver_scc_source.c

@@ -298,7 +298,13 @@ void *_starpu_scc_src_worker(void *arg)
 	for (i = 0; i < config->topology.nmiccores[devid]; i++)
 	{
 		struct _starpu_worker *worker = &config->workers[baseworkerid+i];
-		snprintf(worker->name, sizeof(worker->name), "MIC %d core %u", devid, i);
+		snprintf(worker->name, sizeof(worker->name), "SCC %d core %u", devid, i);
+		snprintf(worker->short_name, sizeof(worker->short_name), "SCC %d core %u", devid, i);
+	}
+	{
+		char thread_name[16];
+		snprintf(thread_name, sizeof(thread_name), "SCC %d", devid);
+		starpu_pthread_setname(pthread_self(), thread_name);
 	}
 
 	_STARPU_TRACE_WORKER_INIT_END(workerid);

+ 2 - 0
src/top/starpu_top_connection.c

@@ -60,6 +60,7 @@ void * message_from_ui(void * p)
 {
 	(void) p;
 	char str[STARPU_TOP_BUFFER_SIZE];
+	starpu_pthread_setname(pthread_self(), "starpu_top_message_from_ui");
 	while(1)
 	{
 		char * check=fgets (str, STARPU_TOP_BUFFER_SIZE, starpu_top_socket_fd_read);
@@ -85,6 +86,7 @@ static
 void * message_to_ui(void * p)
 {
 	(void) p;
+	starpu_pthread_setname(pthread_self(), "starpu_top_message_to_ui");
 	while(1)
 	{
 		char* message = _starpu_top_message_remove(_starpu_top_mt);