Browse Source

Move task push end management just before releasing the mutex of the queue to which it was pushed
Otherwise the task might have already disappeared when we try to add information to it.

Samuel Thibault 12 years ago
parent
commit
15edf8fa61

+ 2 - 1
src/core/jobs.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2012  Université de Bordeaux 1
+ * Copyright (C) 2009-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Télécom-SudParis
  * Copyright (C) 2011  INRIA
@@ -420,6 +420,7 @@ int _starpu_push_local_task(struct _starpu_worker *worker, struct starpu_task *t
 		starpu_task_list_push_front(&worker->local_tasks, task);
 
 	_STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
+	_starpu_push_task_end(task);
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
 
 	return 0;

+ 16 - 5
src/core/sched_policy.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010-2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  INRIA
  *
@@ -276,6 +276,10 @@ static int _starpu_push_task_on_specific_worker(struct starpu_task *task, int wo
 		_STARPU_PTHREAD_BARRIER_INIT(&j->before_work_barrier, NULL, worker_size);
 		_STARPU_PTHREAD_BARRIER_INIT(&j->after_work_barrier, NULL, worker_size);
 
+		/* Note: we have to call that early, or else the task may have
+		 * disappeared already */
+		_starpu_push_task_end(task);
+
 		int i;
 		for (i = 0; i < worker_size; i++)
 		{
@@ -398,14 +402,21 @@ int _starpu_push_task_to_workers(struct starpu_task *task)
 			ret = _starpu_push_task_to_workers(task);
 		}
 	}
-
-	_starpu_profiling_set_task_push_end_time(task);
-
-	task->scheduled = 1;
+	/* Note: from here, the task might have been destroyed already! */
 	_STARPU_LOG_OUT();
 	return ret;
 
 } 
+
+/* This is called right after the scheduler has pushed a task to a queue
+ * but just before releasing mutexes: we need the task to still be alive!
+ */
+int _starpu_push_task_end(struct starpu_task *task)
+{
+	_starpu_profiling_set_task_push_end_time(task);
+	task->scheduled = 1;
+}
+
 /*
  * Given a handle that needs to be converted in order to be used on the given
  * node, returns a task that takes care of the conversion.

+ 4 - 1
src/core/sched_policy.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012-2013  Université de Bordeaux 1
  * Copyright (C) 2011  INRIA
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -36,6 +36,9 @@ int _starpu_push_task(struct _starpu_job *task);
 /* actually pushes the tasks to the specific worker or to the scheduler */
 int _starpu_push_task_to_workers(struct starpu_task *task);
 
+/* Called by scheduler to notify that the task has just been pushed */
+int _starpu_push_task_end(struct starpu_task *task);
+
 /* pop a task that can be executed on the worker */
 struct starpu_task *_starpu_pop_task(struct _starpu_worker *worker);
 /* pop every task that can be executed on the worker */

+ 2 - 0
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -338,6 +338,7 @@ static int push_task_on_best_worker(struct starpu_task *task, int best_workerid,
 		_STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
 		ret =_starpu_fifo_push_sorted_task(dt->queue_array[best_workerid], task);
 		_STARPU_PTHREAD_COND_SIGNAL(sched_cond);
+		_starpu_push_task_end(task);
 		_STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
 	}
 	else
@@ -345,6 +346,7 @@ static int push_task_on_best_worker(struct starpu_task *task, int best_workerid,
 		_STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
 		ret = _starpu_fifo_push_task(dt->queue_array[best_workerid], task);
 		_STARPU_PTHREAD_COND_SIGNAL(sched_cond);
+		_starpu_push_task_end(task);
 		_STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
 	}
 

+ 3 - 1
src/sched_policies/eager_central_policy.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010-2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  INRIA
  *
@@ -92,6 +92,8 @@ static int push_task_eager_policy(struct starpu_task *task)
 		
 	ret_val = _starpu_fifo_push_task(data->fifo, task);
 
+	_starpu_push_task_end(task);
+
 	while(workers->has_next(workers, &it))
 	{
 		worker = workers->get_next(workers, &it);

+ 2 - 1
src/sched_policies/eager_central_priority_policy.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  INRIA
  *
@@ -146,6 +146,7 @@ static int _starpu_priority_push_task(struct starpu_task *task)
 	starpu_task_list_push_back(&taskq->taskq[priolevel], task);
 	taskq->ntasks[priolevel]++;
 	taskq->total_ntasks++;
+	_starpu_push_task_end(task);
 
 	while(workers->has_next(workers, &it))
 	{

+ 2 - 1
src/sched_policies/parallel_eager.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2011-2012  Université de Bordeaux 1
+ * Copyright (C) 2011-2013  Université de Bordeaux 1
  * Copyright (C) 2011  Télécom-SudParis
  * Copyright (C) 2011  INRIA
  *
@@ -185,6 +185,7 @@ static int push_task_peager_policy(struct starpu_task *task)
 
 
 	ret_val = _starpu_fifo_push_task(data->fifo, task);
+	_starpu_push_task_end(task);
 
 	while(workers->has_next(workers, &it))
     {

+ 2 - 1
src/sched_policies/work_stealing_policy.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2013  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011, 2012  INRIA
  *
@@ -367,6 +367,7 @@ int ws_push_task(struct starpu_task *task)
 #endif
 	_starpu_job_list_push_back(deque_queue->jobq, j);
 	deque_queue->njobs++;
+	_starpu_push_task_end(task);
 
 	while(workers->has_next(workers, &it))
 	{