瀏覽代碼

add binary exponential backoof when spinning for task

Pierre-André Wacrenier 12 年之前
父節點
當前提交
b2a51a010a
共有 3 個文件被更改,包括 10 次插入3 次删除
  1. 1 1
      src/core/workers.c
  2. 4 1
      src/core/workers.h
  3. 5 1
      src/drivers/driver_common/driver_common.c

+ 1 - 1
src/core/workers.c

@@ -415,7 +415,7 @@ void _starpu_worker_init(struct _starpu_worker *worker, unsigned fut_key)
 	worker->worker_is_running = 1;
 	STARPU_PTHREAD_COND_SIGNAL(&worker->started_cond);
 	STARPU_PTHREAD_MUTEX_UNLOCK(&worker->mutex);
-
+	worker->spinning_backoff = 1;
 }
 
 static void _starpu_launch_drivers(struct _starpu_machine_config *pconfig)

+ 4 - 1
src/core/workers.h

@@ -87,11 +87,13 @@ struct _starpu_worker
 	struct _starpu_sched_ctx_list *sched_ctx_list;
 	unsigned nsched_ctxs; /* the no of contexts a worker belongs to*/
 	struct _starpu_barrier_counter tasks_barrier; /* wait for the tasks submitted */
-       
+
 	unsigned has_prev_init; /* had already been inited in another ctx */
 
 	unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS];
 
+	unsigned spinning_backoff ; /* number of cycles to pause when spinning  */
+
 	/* conditions variables used when parallel sections are executed in contexts */
 	starpu_pthread_cond_t parallel_sect_cond;
 	starpu_pthread_mutex_t parallel_sect_mutex;
@@ -103,6 +105,7 @@ struct _starpu_worker
 	/* indicate whether the workers shares tasks lists with other workers*/
 	/* in this case when removing him from a context it disapears instantly */
 	unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS];
+
 #ifdef __GLIBC__
 	cpu_set_t cpu_set;
 #endif /* __GLIBC__ */

+ 5 - 1
src/drivers/driver_common/driver_common.c

@@ -206,7 +206,10 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *args, int wor
 		{
 			if (_starpu_machine_is_running())
 			{
-				STARPU_UYIELD();
+				int delay = args->spinning_backoff;
+				args->spinning_backoff<<=1; /* TODO : check if a max is needed */ 
+				while(delay--)
+					STARPU_UYIELD();
 #ifdef STARPU_SIMGRID
 				static int warned;
 				if (!warned)
@@ -249,6 +252,7 @@ struct starpu_task *_starpu_get_worker_task(struct _starpu_worker *args, int wor
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
 	struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
 
+	args->spinning_backoff = 1;
 	if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_idle_end)
 		perf_counters->notify_idle_end(task->sched_ctx, args->workerid);
 #endif //STARPU_USE_SC_HYPERVISOR