Kaynağa Gözat

adding starpu_wakeup_worker() in the aim to wake up a single worker (not wake everyone) when submitting a single task

Pierre-André Wacrenier 11 yıl önce
ebeveyn
işleme
147e0b91c4
3 değiştirilmiş dosya ile 22 ekleme ve 1 silme
  1. 4 0
      include/starpu_scheduler.h
  2. 3 1
      src/core/errorcheck.h
  3. 15 0
      src/core/workers.c

+ 4 - 0
include/starpu_scheduler.h

@@ -51,6 +51,10 @@ struct starpu_sched_policy **starpu_sched_get_predefined_policies();
 
 void starpu_worker_get_sched_condition(int workerid, starpu_pthread_mutex_t **sched_mutex, starpu_pthread_cond_t **sched_cond);
 
+/* This function must be called to wake up a worker that is sleeping on the cond. 
+ * It returns 0 whenever the worker is not in a sleeping state */
+int starpu_wakeup_worker(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex);
+
 int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
 
 int starpu_push_local_task(int workerid, struct starpu_task *task, int back);

+ 3 - 1
src/core/errorcheck.h

@@ -35,7 +35,9 @@ enum _starpu_worker_status
 	/* during the execution of the callback */
 	STATUS_CALLBACK,
 	/* while sleeping because there is nothing to do */
-	STATUS_SLEEPING
+	STATUS_SLEEPING,
+	/* while a sleeping worker is about to wake up (to avoid waking twice for the same worker) */
+	STATUS_WAKING_UP
 };
 
 /* Specify what the local worker is currently doing (eg. executing a callback).

+ 15 - 0
src/core/workers.c

@@ -1523,6 +1523,21 @@ void starpu_worker_get_sched_condition(int workerid, starpu_pthread_mutex_t **sc
 	*sched_mutex = &config.workers[workerid].sched_mutex;
 }
 
+int starpu_wakeup_worker(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
+{
+	int success = 0;
+	STARPU_PTHREAD_MUTEX_LOCK(mutex);
+	if (config.workers[workerid].status == STATUS_SLEEPING)
+	{
+		config.workers[workerid].status = STATUS_WAKING_UP;
+		STARPU_PTHREAD_COND_SIGNAL(cond);
+		success = 1;
+	}
+	STARPU_PTHREAD_MUTEX_UNLOCK(mutex);
+	return success;
+}
+
+
 int starpu_worker_get_nids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize)
 {
 	unsigned nworkers = starpu_worker_get_count();