Bläddra i källkod

hyp only: optimise resize (use idle and speed for the triggering policy)

Andra Hugo 11 år sedan
förälder
incheckning
20906d8d77

+ 6 - 3
sc_hypervisor/src/hypervisor_policies/feft_lp_policy.c

@@ -28,6 +28,9 @@ static void _try_resizing(unsigned *sched_ctxs, int nsched_ctxs, int *workers, i
 	printf("resize_no = %d\n", resize_no);
 	starpu_trace_user_event(resize_no++);
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
+
+	if(ns <= 1) return;
+
 	unsigned *curr_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
 	unsigned curr_nworkers = nworkers == -1 ? starpu_worker_get_count() : (unsigned)nworkers;
 	
@@ -154,13 +157,13 @@ static void feft_lp_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *worker
 static void feft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 {
 	unsigned criteria = sc_hypervisor_get_resize_criteria();
-	if(criteria != SC_NOTHING && criteria == SC_IDLE)
+	if(criteria != SC_NOTHING)// && criteria == SC_IDLE)
 	{
 		int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 		if(ret != EBUSY)
 		{
-			if(sc_hypervisor_check_idle(sched_ctx, worker))
-				_try_resizing(NULL, -1, NULL, -1);
+			printf("trigger idle \n");
+			_try_resizing(NULL, -1, NULL, -1);
 			starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 		}
 	}

+ 7 - 3
sc_hypervisor/src/policies_utils/policy_tools.c

@@ -465,10 +465,14 @@ unsigned sc_hypervisor_check_idle(unsigned sched_ctx, int worker)
 	struct sc_hypervisor_policy_config *config = sc_w->config;
 	if(config != NULL)
 	{
-		printf("w%d/ctx%d: current idle %lf max_idle %lf\n", worker, sched_ctx, sc_w->idle_time[worker], config->max_idle[worker]);
-		if(sc_w->idle_time[worker] > config->max_idle[worker])
+		double end_time = starpu_timing_now();
+		double idle = (end_time - sc_w->idle_start_time[worker]) / 1000000.0; /* in seconds */ 
+		double idle_time = sc_w->idle_time[worker] + idle;
+
+
+		if(idle_time > config->max_idle[worker])
 		{
-//			sc_w->current_idle_time[worker] = 0.0;
+//			printf("w%d/ctx%d: current idle %lf all idle %lf max_idle %lf\n", worker, sched_ctx, idle, idle_time, config->max_idle[worker]);
 			return 1;
 		}
 	}

+ 15 - 11
sc_hypervisor/src/sc_hypervisor.c

@@ -960,10 +960,13 @@ static void notify_idle_cycle(unsigned sched_ctx, int worker, double idle_time)
 		{
 			double curr_time = starpu_timing_now();
 			double elapsed_time = (curr_time - sc_w->hyp_react_start_time) / 1000000.0; /* in seconds */
-			if(sc_w->sched_ctx != STARPU_NMAX_SCHED_CTXS && elapsed_time > sc_w->config->time_sample)
+			if(sc_w->sched_ctx != STARPU_NMAX_SCHED_CTXS && elapsed_time > sc_w->config->max_idle[worker])
 			{
+				if(sc_hypervisor_check_idle(sched_ctx, worker))
+				{
+					hypervisor.policy.handle_idle_cycle(sched_ctx, worker);
+				}
 				sc_w->hyp_react_start_time = starpu_timing_now();
-				hypervisor.policy.handle_idle_cycle(sched_ctx, worker);
 			}
 		}
 	}
@@ -1016,11 +1019,11 @@ static void notify_post_exec_task(struct starpu_task *task, size_t data_size, ui
 	hypervisor.sched_ctx_w[sched_ctx].elapsed_tasks[worker]++ ;
 	hypervisor.sched_ctx_w[sched_ctx].total_elapsed_flops[worker] += flops;
 
-	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
+	starpu_pthread_mutex_lock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 	hypervisor.sched_ctx_w[sched_ctx].remaining_flops -= flops;
 	if(_sc_hypervisor_use_lazy_resize())
 		_ack_resize_completed(sched_ctx, worker);
-	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
+	starpu_pthread_mutex_unlock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 
 	
 	if(hypervisor.resize[sched_ctx])
@@ -1093,9 +1096,10 @@ static void notify_post_exec_task(struct starpu_task *task, size_t data_size, ui
 
 static void notify_submitted_job(struct starpu_task *task, uint32_t footprint, size_t data_size)
 {
-	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
-	hypervisor.sched_ctx_w[task->sched_ctx].submitted_flops += task->flops;
-	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
+	unsigned sched_ctx = task->sched_ctx;
+	starpu_pthread_mutex_lock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
+	hypervisor.sched_ctx_w[sched_ctx].submitted_flops += task->flops;
+	starpu_pthread_mutex_unlock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 
 	if(hypervisor.policy.handle_submitted_job && !type_of_tasks_known)
 		hypervisor.policy.handle_submitted_job(task->cl, task->sched_ctx, footprint, data_size);
@@ -1226,10 +1230,10 @@ struct types_of_workers* sc_hypervisor_get_types_of_workers(int *workers, unsign
 
 void sc_hypervisor_update_diff_total_flops(unsigned sched_ctx, double diff_total_flops)
 {
-	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
+	starpu_pthread_mutex_lock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 	hypervisor.sched_ctx_w[sched_ctx].total_flops += diff_total_flops;
 	hypervisor.sched_ctx_w[sched_ctx].remaining_flops += diff_total_flops;	
-	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
+	starpu_pthread_mutex_unlock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 }
 
 void sc_hypervisor_update_diff_elapsed_flops(unsigned sched_ctx, double diff_elapsed_flops)
@@ -1237,9 +1241,9 @@ void sc_hypervisor_update_diff_elapsed_flops(unsigned sched_ctx, double diff_ela
 	int workerid = starpu_worker_get_id();
 	if(workerid != -1)
 	{
-		starpu_pthread_mutex_lock(&act_hypervisor_mutex);
+//		starpu_pthread_mutex_lock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 		hypervisor.sched_ctx_w[sched_ctx].elapsed_flops[workerid] += diff_elapsed_flops;
 		hypervisor.sched_ctx_w[sched_ctx].total_elapsed_flops[workerid] += diff_elapsed_flops;
-		starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
+//		starpu_pthread_mutex_unlock(&hypervisor.sched_ctx_w[sched_ctx].mutex);
 	}
 }