瀏覽代碼

factorize worker thread initialization, fix threaded profiling by setting up the prof timer

Samuel Thibault 13 年之前
父節點
當前提交
f5789e5edc
共有 5 個文件被更改,包括 46 次插入41 次删除
  1. 40 0
      src/core/workers.c
  2. 3 0
      src/core/workers.h
  3. 1 17
      src/drivers/cpu/driver_cpu.c
  4. 1 12
      src/drivers/cuda/driver_cuda.c
  5. 1 12
      src/drivers/opencl/driver_opencl.c

+ 40 - 0
src/core/workers.c

@@ -254,6 +254,40 @@ static unsigned _starpu_may_launch_driver(struct starpu_conf *conf,
 	return 1;
 }
 
+#ifdef STARPU_PERF_DEBUG
+struct itimerval prof_itimer;
+#endif
+
+void _starpu_worker_init(struct _starpu_worker *worker, unsigned fut_key)
+{
+	(void) fut_key;
+	int devid = worker->devid;
+	(void) devid;
+
+#ifdef STARPU_PERF_DEBUG
+	setitimer(ITIMER_PROF, &prof_itimer, NULL);
+#endif
+
+#ifdef STARPU_USE_FXT
+	_starpu_fxt_register_thread(worker->bindid);
+
+	unsigned memnode = worker->memory_node;
+	_STARPU_TRACE_WORKER_INIT_START(fut_key, devid, memnode);
+#endif
+
+	_starpu_bind_thread_on_cpu(worker->config, worker->bindid);
+
+        _STARPU_DEBUG("worker %d is ready on logical cpu %d\n", devid, worker->bindid);
+#ifdef STARPU_HAVE_HWLOC
+	_STARPU_DEBUG("worker %d cpuset start at %d\n", devid, hwloc_bitmap_first(worker->initial_hwloc_cpu_set));
+#endif
+
+	_starpu_set_local_memory_node_key(&worker->memory_node);
+
+	_starpu_set_local_worker_key(worker);
+
+}
+
 static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 {
 	config->running = 1;
@@ -266,6 +300,12 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 	/* Launch workers asynchronously (except for SPUs) */
 	unsigned cpu = 0, cuda = 0;
 	unsigned worker;
+
+#ifdef STARPU_PERF_DEBUG
+	/* Get itimer of the main thread, to set it for the worker threads */
+	getitimer(ITIMER_PROF, &prof_itimer);
+#endif
+
 	for (worker = 0; worker < nworkers; worker++)
 	{
 		struct _starpu_worker *workerarg = &config->workers[worker];

+ 3 - 0
src/core/workers.h

@@ -195,6 +195,9 @@ void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *m
  * */
 void _starpu_set_local_worker_key(struct _starpu_worker *worker);
 
+/* This function initializes the current thread for the given worker */
+void _starpu_worker_init(struct _starpu_worker *worker, unsigned fut_key);
+
 /* Returns the _starpu_worker structure that describes the state of the
  * current worker. */
 struct _starpu_worker *_starpu_get_local_worker_key(void);

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

@@ -115,23 +115,7 @@ int _starpu_cpu_driver_init(struct starpu_driver *d)
 
 	int devid = cpu_worker->devid;
 
-#ifdef STARPU_USE_FXT
-	_starpu_fxt_register_thread(cpu_worker->bindid);
-
-	unsigned memnode = cpu_worker->memory_node;
-	_STARPU_TRACE_WORKER_INIT_START(_STARPU_FUT_CPU_KEY, devid, memnode);
-#endif
-
-	_starpu_bind_thread_on_cpu(cpu_worker->config, cpu_worker->bindid);
-
-        _STARPU_DEBUG("cpu worker %d is ready on logical cpu %d\n", devid, cpu_worker->bindid);
-#ifdef STARPU_HAVE_HWLOC
-	_STARPU_DEBUG("cpu worker %d cpuset start at %d\n", devid, hwloc_bitmap_first(cpu_worker->initial_hwloc_cpu_set));
-#endif
-
-	_starpu_set_local_memory_node_key(&cpu_worker->memory_node);
-
-	_starpu_set_local_worker_key(cpu_worker);
+	_starpu_worker_init(cpu_worker, _STARPU_FUT_CPU_KEY);
 
 	snprintf(cpu_worker->name, sizeof(cpu_worker->name), "CPU %d", devid);
 	snprintf(cpu_worker->short_name, sizeof(cpu_worker->short_name), "CPU %d", devid);

+ 1 - 12
src/drivers/cuda/driver_cuda.c

@@ -332,18 +332,7 @@ int _starpu_cuda_driver_init(struct starpu_driver *d)
 
 	int devid = args->devid;
 
-#ifdef STARPU_USE_FXT
-	_starpu_fxt_register_thread(args->bindid);
-
-	unsigned memnode = args->memory_node;
-	_STARPU_TRACE_WORKER_INIT_START(_STARPU_FUT_CUDA_KEY, devid, memnode);
-#endif
-
-	_starpu_bind_thread_on_cpu(args->config, args->bindid);
-
-	_starpu_set_local_memory_node_key(&args->memory_node);
-
-	_starpu_set_local_worker_key(args);
+	_starpu_worker_init(args, _STARPU_FUT_CUDA_KEY);
 
 	init_context(devid);
 

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

@@ -436,18 +436,7 @@ int _starpu_opencl_driver_init(struct starpu_driver *d)
 
 	int devid = args->devid;
 
-#ifdef USE_FXT
-	fxt_register_thread(args->bindid);
-
-	unsigned memnode = args->memory_node;
-	_STARPU_TRACE_WORKER_INIT_START(_STARPU_FUT_OPENCL_KEY, devid, memnode);
-#endif
-
-	_starpu_bind_thread_on_cpu(args->config, args->bindid);
-
-	_starpu_set_local_memory_node_key(&args->memory_node);
-
-	_starpu_set_local_worker_key(args);
+	_starpu_worker_init(args, _STARPU_FUT_OPENCL_KEY);
 
 	_starpu_opencl_init_context(devid);