瀏覽代碼

do not change status on the 'waker' side, leave it to the worker to decide about its own status after wake-up requests

Olivier Aumage 8 年之前
父節點
當前提交
faab421955
共有 3 個文件被更改,包括 22 次插入27 次删除
  1. 1 1
      src/core/workers.c
  2. 3 17
      src/datawizard/copy_driver.c
  3. 18 9
      src/drivers/driver_common/driver_common.c

+ 1 - 1
src/core/workers.c

@@ -2114,7 +2114,7 @@ static int starpu_wakeup_worker_locked(int workerid, starpu_pthread_cond_t *sche
 	}
 	else if (_starpu_config.workers[workerid].status == STATUS_SLEEPING)
 	{
-		_starpu_config.workers[workerid].status = STATUS_WAKING_UP;
+		_starpu_config.workers[workerid].state_keep_awake = 1;
 		/* cond_broadcast is required over cond_signal since
 		 * the condition is share for multiple purpose */
 		STARPU_PTHREAD_COND_BROADCAST(sched_cond);

+ 3 - 17
src/datawizard/copy_driver.c

@@ -64,14 +64,7 @@ void _starpu_wake_all_blocked_workers_on_node(unsigned nodeid)
 		STARPU_PTHREAD_MUTEX_LOCK_SCHED(&condition->worker->sched_mutex);
 		if (condition->cond == &condition->worker->sched_cond)
 		{
-			if (condition->worker->status == STATUS_SCHEDULING)
-			{
-				condition->worker->state_keep_awake = 1;
-			}
-			else if (condition->worker->status == STATUS_SLEEPING)
-			{
-				condition->worker->status = STATUS_WAKING_UP;
-			} 
+			condition->worker->state_keep_awake = 1;
 		} 
 		STARPU_PTHREAD_COND_BROADCAST(condition->cond);
 		STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&condition->worker->sched_mutex);
@@ -110,15 +103,8 @@ void starpu_wake_all_blocked_workers(void)
 		STARPU_PTHREAD_MUTEX_LOCK_SCHED(&condition->worker->sched_mutex);
 		if (condition->cond == &condition->worker->sched_cond)
 		{
-			if (condition->worker->status == STATUS_SCHEDULING)
-			{
-				condition->worker->state_keep_awake = 1;
-			}
-			else if (condition->worker->status == STATUS_SLEEPING)
-			{
-				condition->worker->status = STATUS_WAKING_UP;
-			} 
-		} 
+			condition->worker->state_keep_awake = 1;
+		}
 		STARPU_PTHREAD_COND_BROADCAST(condition->cond);
 		STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&condition->worker->sched_mutex);
 	}

+ 18 - 9
src/drivers/driver_common/driver_common.c

@@ -387,21 +387,25 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *worker, int w
 		STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
 
 		if (_starpu_worker_can_block(memnode, worker)
-			&& !_starpu_sched_ctx_last_worker_awake(worker))
+			&& !_starpu_sched_ctx_last_worker_awake(worker)
+			&& !worker->state_block_in_parallel_req
+			&& !worker->state_unblock_in_parallel_req)
 		{
 			do
 			{
 				STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
 			}
-			while (worker->status == STATUS_SLEEPING);
+			/* do not check status != SLEEPING here since status is
+			 * not changed by other threads/workers */
+			while (!worker->state_keep_awake
+					&& !worker->state_block_in_parallel_req
+					&& !worker->state_unblock_in_parallel_req);
+			worker->state_keep_awake = 0;
 			STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
-		}
-		else
-		{
+		} else {
 			STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
 			if (_starpu_machine_is_running())
-				_starpu_exponential_backoff(worker);
-		}
+				_starpu_exponential_backoff(worker); }
 
 		return NULL;
 	}
@@ -557,13 +561,18 @@ int _starpu_get_multi_worker_task(struct _starpu_worker *workers, struct starpu_
 		_starpu_worker_leave_sched_op(worker);
 
 		if (_starpu_worker_can_block(memnode, worker)
-				&& !_starpu_sched_ctx_last_worker_awake(worker))
+				&& !_starpu_sched_ctx_last_worker_awake(worker)
+				&& !worker->state_block_in_parallel_req
+				&& !worker->state_unblock_in_parallel_req)
 		{
 			do
 			{
 				STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
 			}
-			while (worker->status == STATUS_SLEEPING);
+			while (!worker->state_keep_awake
+					&& !worker->state_block_in_parallel_req
+					&& !worker->state_unblock_in_parallel_req);
+			worker->state_keep_awake = 0;
 			STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
 		}
 		else