Parcourir la source

merge blocked and sleeping states which always were set conjointly

Olivier Aumage il y a 8 ans
Parent
commit
190ec21dcf
4 fichiers modifiés avec 14 ajouts et 21 suppressions
  1. 6 13
      src/core/sched_ctx.c
  2. 0 3
      src/core/sched_ctx.h
  3. 7 2
      src/core/workers.c
  4. 1 3
      src/core/workers.h

+ 6 - 13
src/core/sched_ctx.c

@@ -551,7 +551,6 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 		sem_init(&sched_ctx->wake_up_sem[w], 0, 0);
 
 		sched_ctx->parallel_sect[w] = 0;
-		sched_ctx->sleeping[w] = 0;
 	}
 
 	sched_ctx->parallel_view = 0;
@@ -2353,24 +2352,18 @@ static unsigned _worker_sleeping_in_other_ctx(unsigned sched_ctx_id, int workeri
 
 void _starpu_sched_ctx_signal_worker_blocked(unsigned sched_ctx_id, int workerid)
 {
-	struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
-	worker->blocked = 1;
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
-	sched_ctx->sleeping[workerid] = 1;
+	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]);
-
-	return;
 }
 
 void _starpu_sched_ctx_signal_worker_woke_up(unsigned sched_ctx_id, int workerid)
 {
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
-	sem_post(&sched_ctx->wake_up_sem[sched_ctx->main_master]);
-	sched_ctx->sleeping[workerid] = 0;
 	struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
-	worker->blocked = 0;
-
-	return;
+	sem_post(&sched_ctx->wake_up_sem[sched_ctx->main_master]);
+	worker->state_blocked_in_ctx = 0;
 }
 
 static void _starpu_sched_ctx_put_workers_to_sleep(unsigned sched_ctx_id, unsigned all)
@@ -2454,14 +2447,14 @@ static void _starpu_sched_ctx_wake_up_workers(unsigned sched_ctx_id, unsigned al
 		if(starpu_worker_get_type(workerid) == STARPU_CPU_WORKER
 			 && sched_ctx->parallel_sect[workerid] && (workerid != master || all))
 		{
-			if((current_worker_id == -1 || workerid != current_worker_id) && sched_ctx->sleeping[workerid])
+			struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
+			if((current_worker_id == -1 || workerid != current_worker_id) && worker->state_blocked_in_ctx)
 			{
 				/* 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);
 				if (worker->state_wait_ack__busy_in_parallel)

+ 0 - 3
src/core/sched_ctx.h

@@ -139,9 +139,6 @@ struct _starpu_sched_ctx
 	   all woke up and ready continue appl */
 	sem_t wake_up_sem[STARPU_NMAXWORKERS];
 
-	/* bool indicating if the workers is sleeping in this ctx */
-	unsigned sleeping[STARPU_NMAXWORKERS];
-
 	/* ctx nesting the current ctx */
 	unsigned nesting_sched_ctx;
 

+ 7 - 2
src/core/workers.c

@@ -577,9 +577,14 @@ static void _starpu_worker_init(struct _starpu_worker *workerarg, struct _starpu
 	workerarg->reverse_phase[1] = 0;
 	workerarg->pop_ctx_priority = 1;
 	workerarg->sched_mutex_depth = 0;
-	workerarg->blocked = 0;
 	workerarg->is_slave_somewhere = 0;
 
+	workerarg->state_sched_op_pending = 0;
+	workerarg->state_changing_ctx_waiting = 0;
+	workerarg->state_busy_in_parallel = 0;
+	workerarg->state_wait_ack__busy_in_parallel = 0;
+	workerarg->state_blocked_in_ctx = 0;
+
 	/* cpu_set/hwloc_cpu_set initialized in topology.c */
 }
 
@@ -1687,7 +1692,7 @@ unsigned starpu_worker_get_count(void)
 
 unsigned starpu_worker_is_blocked(int workerid)
 {
-	return _starpu_config.workers[workerid].blocked;
+	return _starpu_config.workers[workerid].state_blocked_in_ctx;
 }
 
 unsigned starpu_worker_is_slave_somewhere(int workerid)

+ 1 - 3
src/core/workers.h

@@ -86,6 +86,7 @@ LIST_TYPE(_starpu_worker,
 	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;
+	int state_blocked_in_ctx:1; /* worker is blocked in a ctx */
 	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 */
@@ -142,9 +143,6 @@ LIST_TYPE(_starpu_worker,
 	/* sched mutex local worker locking depth */
 	unsigned sched_mutex_depth;
 
-	/* bool to indicate if the worker is blocked in a ctx */
-	unsigned blocked;
-
 	/* bool to indicate if the worker is slave in a ctx */
 	unsigned is_slave_somewhere;