浏览代码

drop fall_asleep_sem in favor of sched_cond

Olivier Aumage 8 年之前
父节点
当前提交
1bf1776396
共有 3 个文件被更改,包括 6 次插入24 次删除
  1. 2 12
      src/core/sched_ctx.c
  2. 0 10
      src/core/sched_ctx.h
  3. 4 2
      src/drivers/driver_common/driver_common.c

+ 2 - 12
src/core/sched_ctx.c

@@ -547,7 +547,6 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
-		sem_init(&sched_ctx->fall_asleep_sem[w], 0, 0);
 		sched_ctx->parallel_sect[w] = 0;
 	}
 
@@ -2348,14 +2347,6 @@ static unsigned _worker_blocked_in_other_ctx(unsigned sched_ctx_id, int workerid
 
 }
 
-void _starpu_sched_ctx_signal_worker_blocked(unsigned sched_ctx_id, int workerid)
-{
-	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
-	struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
-	worker->state_blocked_in_ctx = 1;
-	sem_post(&sched_ctx->fall_asleep_sem[sched_ctx->main_master]);
-}
-
 static void _starpu_sched_ctx_put_workers_to_sleep(unsigned sched_ctx_id, unsigned all)
 {
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
@@ -2403,9 +2394,8 @@ static void _starpu_sched_ctx_put_workers_to_sleep(unsigned sched_ctx_id, unsign
 		{
 			/* TODO: replace fall_asleep_sem by a condition, in order to be able to avoid unlocking sched_mutex */
 			struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
-			STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
-			sem_wait(&sched_ctx->fall_asleep_sem[master]);
-			STARPU_PTHREAD_MUTEX_LOCK(&worker->sched_mutex);
+			while (!worker->state_blocked_in_ctx)
+				STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
 		}
 		workers_count++;
 	}

+ 0 - 10
src/core/sched_ctx.h

@@ -131,10 +131,6 @@ struct _starpu_sched_ctx
 	   parallel sections to be executed on their allocated resources */
 	unsigned parallel_sect[STARPU_NMAXWORKERS];
 
-	/* semaphore that block appl thread until starpu threads are
-	   all blocked and ready to exec the parallel code */
-	sem_t fall_asleep_sem[STARPU_NMAXWORKERS];
-
 	/* ctx nesting the current ctx */
 	unsigned nesting_sched_ctx;
 
@@ -220,12 +216,6 @@ unsigned _starpu_worker_belongs_to_a_sched_ctx(int workerid, unsigned sched_ctx_
    (if it is the last one awake in a context he should better keep awake) */
 unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker);
 
-/* let the appl know that the worker blocked to execute parallel code */
-void _starpu_sched_ctx_signal_worker_blocked(unsigned sched_ctx_id, int workerid);
-
-/* let the appl know that the worker woke up */
-void _starpu_sched_ctx_signal_worker_woke_up(unsigned sched_ctx_id, int workerid);
-
 /* If starpu_sched_ctx_set_context() has been called, returns the context
  * id set by its last call, or the id of the initial context */
 unsigned _starpu_sched_ctx_get_current_context();

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

@@ -367,7 +367,8 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *worker, int w
 					/* we need it until here bc of the list of ctxs of the workers
 					   that can change in another thread */
 					needed = 0;
-					_starpu_sched_ctx_signal_worker_blocked(sched_ctx->id, workerid);
+					worker->state_blocked_in_ctx = 1;
+					STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
 					worker->state_busy_in_parallel = 1;
 					worker->state_wait_ack__busy_in_parallel = 1;
 					do
@@ -395,7 +396,8 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *worker, int w
 			if(sched_ctx->parallel_sect[workerid])
 			{
 //				needed = 0;
-				_starpu_sched_ctx_signal_worker_blocked(sched_ctx->id, workerid);
+				worker->state_blocked_in_ctx = 1;
+				STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
 				worker->state_busy_in_parallel = 1;
 				worker->state_wait_ack__busy_in_parallel = 1;
 				do