Browse Source

drop parallel_sect_cond

Olivier Aumage 8 years ago
parent
commit
c7826aeffc
4 changed files with 25 additions and 5 deletions
  1. 12 2
      src/core/sched_ctx.c
  2. 0 1
      src/core/sched_ctx.h
  3. 1 0
      src/core/workers.h
  4. 12 2
      src/drivers/driver_common/driver_common.c

+ 12 - 2
src/core/sched_ctx.c

@@ -550,7 +550,6 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 		sem_init(&sched_ctx->fall_asleep_sem[w], 0, 0);
 		sem_init(&sched_ctx->wake_up_sem[w], 0, 0);
 
-		STARPU_PTHREAD_COND_INIT(&sched_ctx->parallel_sect_cond[w], NULL);
 		STARPU_PTHREAD_COND_INIT(&sched_ctx->parallel_sect_cond_busy[w], NULL);
 
 		sched_ctx->parallel_sect[w] = 0;
@@ -2459,10 +2458,21 @@ static void _starpu_sched_ctx_wake_up_workers(unsigned sched_ctx_id, unsigned al
 		{
 			if((current_worker_id == -1 || workerid != current_worker_id) && sched_ctx->sleeping[workerid])
 			{
+				/* TODO: this section seems suspicious since
+				 * busy_in_parallel state may change after
+				 * unlock and before sem_wait, sem should be
+				 * reimplemented using sched_mutex + a
+				 * condition */
 				struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
 				if (!workers_locked)
 					STARPU_PTHREAD_MUTEX_LOCK(&worker->sched_mutex);
-				STARPU_PTHREAD_COND_SIGNAL(&sched_ctx->parallel_sect_cond[workerid]);
+				if (worker->state_wait_ack__busy_in_parallel)
+				{
+					STARPU_ASSERT(worker->state_busy_in_parallel == 1);
+					worker->state_wait_ack__busy_in_parallel = 0;
+				}
+				/* broadcast is required because sched_cond is shared for multiple purpose */
+				STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
 				if (!workers_locked)
 					STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
 				sem_wait(&sched_ctx->wake_up_sem[master]);

+ 0 - 1
src/core/sched_ctx.h

@@ -128,7 +128,6 @@ struct _starpu_sched_ctx
 	int main_master;
 
 	/* conditions variables used when parallel sections are executed in contexts */
-	starpu_pthread_cond_t parallel_sect_cond[STARPU_NMAXWORKERS];
 	starpu_pthread_cond_t parallel_sect_cond_busy[STARPU_NMAXWORKERS];
 
 	/* boolean indicating that workers should block in order to allow

+ 1 - 0
src/core/workers.h

@@ -85,6 +85,7 @@ LIST_TYPE(_starpu_worker,
 	int state_sched_op_pending:1; /* a task pop is ongoing even though sched_mutex may temporarily be unlocked */
 	int state_changing_ctx_waiting:1; /* a thread is waiting for transient operations such as pop to complete before acquiring sched_mutex and modifying the worker ctx*/
 	int state_busy_in_parallel:1;
+	int state_wait_ack__busy_in_parallel:1;
 	struct starpu_task_list local_tasks; /* this queue contains tasks that have been explicitely submitted to that queue */
 	struct starpu_task **local_ordered_tasks; /* this queue contains tasks that have been explicitely submitted to that queue with an explicit order */
 	unsigned local_ordered_tasks_size; /* this records the size of local_ordered_tasks */

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

@@ -369,7 +369,12 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *worker, int w
 					needed = 0;
 					_starpu_sched_ctx_signal_worker_blocked(sched_ctx->id, workerid);
 					worker->state_busy_in_parallel = 1;
-					STARPU_PTHREAD_COND_WAIT(&sched_ctx->parallel_sect_cond[workerid], &worker->sched_mutex);
+					worker->state_wait_ack__busy_in_parallel = 1;
+					do
+					{
+						STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
+					}
+					while (worker->state_wait_ack__busy_in_parallel);
 					worker->state_busy_in_parallel = 0;
 					STARPU_PTHREAD_COND_SIGNAL(&sched_ctx->parallel_sect_cond_busy[workerid]);
 					_starpu_sched_ctx_signal_worker_woke_up(sched_ctx->id, workerid);
@@ -388,7 +393,12 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *worker, int w
 //				needed = 0;
 				_starpu_sched_ctx_signal_worker_blocked(sched_ctx->id, workerid);
 				worker->state_busy_in_parallel = 1;
-				STARPU_PTHREAD_COND_WAIT(&sched_ctx->parallel_sect_cond[workerid], &worker->sched_mutex);
+				worker->state_wait_ack__busy_in_parallel = 1;
+				do
+				{
+					STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
+				}
+				while (worker->state_wait_ack__busy_in_parallel);
 				worker->state_busy_in_parallel = 0;
 				STARPU_PTHREAD_COND_SIGNAL(&sched_ctx->parallel_sect_cond_busy[workerid]);
 				_starpu_sched_ctx_signal_worker_woke_up(sched_ctx->id, workerid);