Przeglądaj źródła

Move tag re-locking within _starpu_tag_set_ready

We were already unlocking just after calling it anyway, and this
avoids re-locking the tag after releasing its children, which
can raise deadlocks when running a cycle tag graph, e.g. with
tests/main/subgraph_repeat_regenerate_tag_cycle
Samuel Thibault 4 lat temu
rodzic
commit
d4517037a0

+ 3 - 2
src/core/dependencies/cg.c

@@ -219,9 +219,10 @@ void _starpu_notify_cg(void *pred STARPU_ATTRIBUTE_UNUSED, struct _starpu_cg *cg
 				{
 					/* reset the counter so that we can reuse the completion group */
 					tag_successors->ndeps_completed = 0;
+					/* This releases the lock */
 					_starpu_tag_set_ready(tag);
-				}
-				_starpu_spin_unlock(&tag->lock);
+				} else
+					_starpu_spin_unlock(&tag->lock);
 				break;
 			}
 

+ 5 - 6
src/core/dependencies/tags.c

@@ -221,7 +221,7 @@ static struct _starpu_tag *gettag_struct(starpu_tag_t id)
 	return tag;
 }
 
-/* lock should be taken */
+/* lock should be taken, and this releases it */
 void _starpu_tag_set_ready(struct _starpu_tag *tag)
 {
 	/* mark this tag as ready to run */
@@ -229,6 +229,10 @@ void _starpu_tag_set_ready(struct _starpu_tag *tag)
 	/* declare it to the scheduler ! */
 	struct _starpu_job *j = tag->job;
 
+	STARPU_ASSERT(!STARPU_AYU_EVENT || tag->id < STARPU_AYUDAME_OFFSET);
+	STARPU_AYU_PRERUNTASK(tag->id + STARPU_AYUDAME_OFFSET, -1);
+	STARPU_AYU_POSTRUNTASK(tag->id + STARPU_AYUDAME_OFFSET);
+
 	/* In case the task job is going to be scheduled immediately, and if
 	 * the task is "empty", calling _starpu_push_task would directly try to enforce
 	 * the dependencies of the task, and therefore it would try to grab the
@@ -238,11 +242,6 @@ void _starpu_tag_set_ready(struct _starpu_tag *tag)
 	/* enforce data dependencies */
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	_starpu_enforce_deps_starting_from_task(j);
-
-	_starpu_spin_lock(&tag->lock);
-	STARPU_ASSERT(!STARPU_AYU_EVENT || tag->id < STARPU_AYUDAME_OFFSET);
-	STARPU_AYU_PRERUNTASK(tag->id + STARPU_AYUDAME_OFFSET, -1);
-	STARPU_AYU_POSTRUNTASK(tag->id + STARPU_AYUDAME_OFFSET);
 }
 
 /* the lock of the tag must already be taken ! */

+ 2 - 0
src/core/dependencies/tags.h

@@ -68,6 +68,8 @@ void _starpu_notify_tag_dependencies(struct _starpu_tag *tag);
 void _starpu_notify_job_start_tag_dependencies(struct _starpu_tag *tag, _starpu_notify_job_start_data *data);
 
 void _starpu_tag_declare(starpu_tag_t id, struct _starpu_job *job);
+
+/* lock should be taken, and this releases it */
 void _starpu_tag_set_ready(struct _starpu_tag *tag);
 
 unsigned _starpu_submit_job_enforce_task_deps(struct _starpu_job *j);