Przeglądaj źródła

Protect status update while executing task

Samuel Thibault 11 lat temu
rodzic
commit
e508f0cc26

+ 11 - 8
src/core/errorcheck.c

@@ -18,6 +18,16 @@
 #include <core/errorcheck.h>
 #include <core/workers.h>
 
+void _starpu_set_worker_status(struct _starpu_worker *worker, enum _starpu_worker_status st)
+{
+	starpu_pthread_mutex_t *sched_mutex;
+	starpu_pthread_cond_t *sched_cond;
+	starpu_worker_get_sched_condition(worker->workerid, &sched_mutex, &sched_cond);
+	STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
+	worker->status = st;
+	STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
+}
+
 void _starpu_set_local_worker_status(enum _starpu_worker_status st)
 {
 	struct _starpu_worker *worker = _starpu_get_local_worker_key();
@@ -26,14 +36,7 @@ void _starpu_set_local_worker_status(enum _starpu_worker_status st)
 	 * thereforce outside a worker), for instance if we are executing the
 	 * callback function of a task with a "NULL" codelet. */
 	if (worker)
-	{
-		starpu_pthread_mutex_t *sched_mutex;
-		starpu_pthread_cond_t *sched_cond;
-		starpu_worker_get_sched_condition(worker->workerid, &sched_mutex, &sched_cond);
-		STARPU_PTHREAD_MUTEX_LOCK(mutex);
-		worker->status = st;
-		STARPU_PTHREAD_MUTEX_UNLOCK(mutex);
-	}
+		_starpu_set_worker_status(worker, st);
 }
 
 enum _starpu_worker_status _starpu_get_local_worker_status(void)

+ 2 - 0
src/core/errorcheck.h

@@ -42,9 +42,11 @@ enum _starpu_worker_status
 	STATUS_WAKING_UP
 };
 
+struct _starpu_worker;
 /* Specify what the local worker is currently doing (eg. executing a callback).
  * This permits to detect if this is legal to do a blocking call for instance.
  * */
+void _starpu_set_worker_status(struct _starpu_worker *worker, enum _starpu_worker_status st);
 void _starpu_set_local_worker_status(enum _starpu_worker_status st);
 
 /* Indicate what type of operation the worker is currently doing. */

+ 2 - 2
src/drivers/driver_common/driver_common.c

@@ -51,7 +51,7 @@ void _starpu_driver_start_job(struct _starpu_worker *worker, struct _starpu_job
 	if (j->task_size == 1)
 		_starpu_sched_pre_exec_hook(task);
 
-	worker->status = STATUS_EXECUTING;
+	_starpu_set_worker_status(worker, STATUS_EXECUTING);
 	task->status = STARPU_TASK_RUNNING;
 
 	if (rank == 0)
@@ -102,7 +102,7 @@ void _starpu_driver_end_job(struct _starpu_worker *worker, struct _starpu_job *j
 	if (starpu_top)
 		_starpu_top_task_ended(task,workerid,codelet_end);
 
-	worker->status = STATUS_UNKNOWN;
+	_starpu_set_worker_status(worker, STATUS_UNKNOWN);
 }
 void _starpu_driver_update_job_feedback(struct _starpu_job *j, struct _starpu_worker *worker,
 					struct starpu_perfmodel_arch* perf_arch,