Andra Hugo 13 years ago
parent
commit
36c19ba6c3

+ 41 - 4
sched_ctx_hypervisor/src/hypervisor_policies/lp2_policy.c

@@ -403,9 +403,8 @@ static double _find_tmax(double t1, double t2)
 	return t1 + ((t2 - t1)/2);
 }
 
-static unsigned _compute_task_distribution_over_ctxs(int ns, int nw, int nt, double w_in_s[ns][nw], int *sched_ctxs, int *workers)
+static unsigned _compute_task_distribution_over_ctxs(int ns, int nw, int nt, double w_in_s[ns][nw], double tasks[nw][nt], int *sched_ctxs, int *workers)
 {	
-	double tasks[nw][nt];
 	double draft_tasks[nw][nt];
 	double draft_w_in_s[ns][nw];
 	
@@ -506,12 +505,50 @@ static void lp2_handle_poped_task(unsigned sched_ctx, int worker)
 				nt++;
 			
 			double w_in_s[ns][nw];
+			double tasks_per_worker[nw][nt];
 
-			unsigned found_sol = _compute_task_distribution_over_ctxs(ns, nw, nt, w_in_s, NULL, NULL);
+			unsigned found_sol = _compute_task_distribution_over_ctxs(ns, nw, nt, w_in_s, tasks_per_worker, NULL, NULL);
 			/* if we did find at least one solution redistribute the resources */
 			if(found_sol)
 			{
-				_redistribute_resources_in_ctxs(ns, nw, nt, w_in_s, 0, NULL, NULL);
+				int w, s;
+				double nworkers[ns][2];
+				int nworkers_rounded[ns][2];
+				for(s = 0; s < ns; s++)
+				{
+					nworkers[s][0] = 0.0;
+					nworkers[s][1] = 0.0;
+					nworkers_rounded[s][0] = 0;
+					nworkers_rounded[s][1] = 0;
+
+				}
+
+				for(s = 0; s < ns; s++)
+				{
+					for(w = 0; w < nw; w++)
+					{
+						enum starpu_perf_archtype arch = starpu_worker_get_type(w);
+						
+						if(arch == STARPU_CUDA_WORKER)
+						{
+							if(w_in_s[s][w] >= 0.3)
+							{
+								nworkers_rounded[s][0]++;
+								nworkers[s][0] += w_in_s[s][w];
+							}
+						}
+						else
+						{
+							if(w_in_s[s][w] > 0.5)
+							{
+								nworkers_rounded[s][1]++;
+								nworkers[s][1] += w_in_s[s][w];
+							}
+						}
+					}
+				}
+				_lp_redistribute_resources_in_ctxs(ns, 2, nworkers_rounded, nworkers);
+
 			}
 		}
 		pthread_mutex_unlock(&act_hypervisor_mutex);

+ 10 - 252
sched_ctx_hypervisor/src/hypervisor_policies/lp_policy.c

@@ -16,263 +16,21 @@
 
 #include "lp_tools.h"
 
-static void _round_double_to_int(int ns, int nw, double res[ns][nw], int res_rounded[ns][nw])
-{
-	int s, w;
-	double left_res[nw];
-	for(w = 0; w < nw; w++)
-		left_res[nw] = 0.0;
-	for(s = 0; s < ns; s++)
-	{
-		for(w = 0; w < nw; w++)
-		{
-			int x = floor(res[s][w]);
-			double x_double = (double)x;
-			double diff = res[s][w] - x_double;
-			
-			if(diff != 0.0)
-			{
-				if(diff > 0.5)
-				{
-					if(left_res[w] != 0.0)
-					{
-						if((diff + left_res[w]) > 0.5)
-						{
-							res_rounded[s][w] = x + 1;
-							left_res[w] = (-1.0) * (x_double + 1.0 - (res[s][w] + left_res[w]));
-						}
-						else
-						{
-							res_rounded[s][w] = x;
-							left_res[w] = (-1.0) * (diff + left_res[w]);
-						}
-					}
-					else
-					{
-						res_rounded[s][w] = x + 1;
-						left_res[w] = (-1.0) * (x_double + 1.0 - res[s][w]);
-					}
-
-				}
-				else
-				{
-					if((diff + left_res[w]) > 0.5)
-					{
-						res_rounded[s][w] = x + 1;
-						left_res[w] = (-1.0) * (x_double + 1.0 - (res[s][w] + left_res[w]));
-					}
-					else
-					{
-						res_rounded[s][w] = x;
-						left_res[w] = diff;
-					}
-				}
-			}
-		}
-	}		
-}
-
-static void _redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw])
-{
-	int *sched_ctxs = sched_ctx_hypervisor_get_sched_ctxs();
-	int s, s2, w;
-	for(s = 0; s < ns; s++)
-	{
-		for(w = 0; w < nw; w++)
-		{
-			enum starpu_archtype arch;
-			if(w == 0) arch = STARPU_CUDA_WORKER;
-			if(w == 1) arch = STARPU_CPU_WORKER;
-
-			if(w == 1)
-			{
-				unsigned nworkers_ctx = get_nworkers_ctx(sched_ctxs[s], arch);
-				if(nworkers_ctx > res_rounded[s][w])
-				{
-					int nworkers_to_move = nworkers_ctx - res_rounded[s][w];
-					int receiving_s = -1;
-					
-					for(s2 = 0; s2 < ns; s2++)
-					{
-						if(sched_ctxs[s2] != sched_ctxs[s])
-						{
-							int nworkers_ctx2 = get_nworkers_ctx(sched_ctxs[s2], arch);
-							if((res_rounded[s2][w] - nworkers_ctx2) >= nworkers_to_move)
-							{
-								receiving_s = sched_ctxs[s2];
-								break;
-							}
-						}
-					}
-					if(receiving_s != -1)
-					{
-						int *workers_to_move = _get_first_workers(sched_ctxs[s], &nworkers_to_move, arch);
-						sched_ctx_hypervisor_move_workers(sched_ctxs[s], receiving_s, workers_to_move, nworkers_to_move, 0);
-						struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
-						int i;
-						for(i = 0; i < nworkers_to_move; i++)
-							new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
-						
-						free(workers_to_move);
-					}
-				}
-			}
-			else
-			{
-				double nworkers_ctx = get_nworkers_ctx(sched_ctxs[s], arch) * 1.0;
-				if(nworkers_ctx > res[s][w])
-				{
-					double nworkers_to_move = nworkers_ctx - res[s][w];
-					int receiving_s = -1;
-					
-					for(s2 = 0; s2 < ns; s2++)
-					{
-						if(sched_ctxs[s2] != sched_ctxs[s])
-						{
-							double nworkers_ctx2 = get_nworkers_ctx(sched_ctxs[s2], arch) * 1.0;
-							if((res[s2][w] - nworkers_ctx2) >= nworkers_to_move)
-							{
-								receiving_s = sched_ctxs[s2];
-								break;
-							}
-						}
-					}
-					if(receiving_s != -1)
-					{
-						int x = floor(nworkers_to_move);
-						double x_double = (double)x;
-						double diff = nworkers_to_move - x_double;
-						if(diff == 0.0)
-						{
-							int *workers_to_move = _get_first_workers(sched_ctxs[s], &x, arch);
-							if(x > 0)
-							{
-								sched_ctx_hypervisor_move_workers(sched_ctxs[s], receiving_s, workers_to_move, x, 0);
-
-								struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
-								int i;
-								for(i = 0; i < x; i++)
-									new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
-							}
-							free(workers_to_move);
-						}
-						else
-						{
-							x+=1;
-							int *workers_to_move = _get_first_workers(sched_ctxs[s], &x, arch);
-							if(x > 0)
-							{
-								if(diff > 0.3)
-									sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_move, x, receiving_s);
-								else
-									sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_move, x-1, receiving_s);
-								
-								struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
-								int i;
-								for(i = 0; i < x-1; i++)
-									new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
-							}
-							free(workers_to_move);
-						}
-					}
-				}
-			}
-
-		}
-	}
-}
-
-static void _distribute_resources_in_ctxs(int* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers)
-{
-	int current_nworkers = workers == NULL ? starpu_worker_get_count() : nworkers;
-	int *current_sched_ctxs = sched_ctxs == NULL ? sched_ctx_hypervisor_get_sched_ctxs() : sched_ctxs;
-
-	int s, s2, w;
-	for(s = 0; s < ns; s++)
-	{
-		for(w = 0; w < nw; w++)
-		{
-			enum starpu_archtype arch;
-			if(w == 0) arch = STARPU_CUDA_WORKER;
-			if(w == 1) arch = STARPU_CPU_WORKER;
-
-			if(w == 1)
-			{
-				int nworkers_to_add = res_rounded[s][w];
-				int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &nworkers_to_add, arch);
-
-				if(nworkers_to_add > 0)
-				{
-					sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, nworkers_to_add, current_sched_ctxs[s]);
-					sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
-					struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
-					int i;
-					for(i = 0; i < nworkers_to_add; i++)
-						new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
-				}
-				free(workers_to_add);
-			}
-			else
-			{
-				double nworkers_to_add = res[s][w];
-				int x = floor(nworkers_to_add);
-				double x_double = (double)x;
-				double diff = nworkers_to_add - x_double;
-				if(diff == 0.0)
-				{
-					int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &x, arch);
-					if(x > 0)
-					{
-						sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x, current_sched_ctxs[s]);
-						sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
-						struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
-						int i;
-						for(i = 0; i < x; i++)
-							new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
-						
-					}
-					free(workers_to_add);
-				}
-				else
-				{
-					x+=1;
-					int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &x, arch);
-					if(x > 0)
-					{
-						if(diff >= 0.3)
-							sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x, current_sched_ctxs[s]);
-						else
-							sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x-1, current_sched_ctxs[s]);
-						sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
-						struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
-						int i;
-						for(i = 0; i < x-1; i++)
-							new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
-					}
-					free(workers_to_add);			
-				}
-			}
-			
-		}
-		sched_ctx_hypervisor_stop_resize(current_sched_ctxs[s]);
-	}
-}
 
 static void lp_handle_poped_task(unsigned sched_ctx, int worker)
 {
 	if(_velocity_gap_btw_ctxs())
 	{
 		int nsched_ctxs = sched_ctx_hypervisor_get_nsched_ctxs();
-//		int nsched_ctxs = 3;
 		
-		double res[nsched_ctxs][2];
+		double nworkers[nsched_ctxs][2];
 
 		int ret = pthread_mutex_trylock(&act_hypervisor_mutex);
 		if(ret != EBUSY)
 		{ 
 			int total_nw[2];
 			_get_total_nw(NULL, -1, 2, total_nw);
-			double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, res, total_nw);
+			double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, nworkers, total_nw);
 			if(vmax != 0.0)
 			{
 //				printf("********resize\n");
@@ -281,15 +39,15 @@ static void lp_handle_poped_task(unsigned sched_ctx, int worker)
 /* 				printf("ctx %d/worker type %d: n = %lf \n", i, 0, res[i][0]); */
 /* 				printf("ctx %d/worker type %d: n = %lf \n", i, 1, res[i][1]); */
 /* 			} */
-				int res_rounded[nsched_ctxs][2];
-				_round_double_to_int(nsched_ctxs, 2, res, res_rounded);
+				int nworkers_rounded[nsched_ctxs][2];
+				_lp_round_double_to_int(nsched_ctxs, 2, nworkers, nworkers_rounded);
   /*     		for( i = 0; i < nsched_ctxs; i++) */
 /* 			{ */
 /* 				printf("ctx %d/worker type %d: n = %d \n", i, 0, res_rounded[i][0]); */
 /* 				printf("ctx %d/worker type %d: n = %d \n", i, 1, res_rounded[i][1]); */
 /* 			} */
 				
-				_redistribute_resources_in_ctxs(nsched_ctxs, 2, res_rounded, res);
+				_lp_redistribute_resources_in_ctxs(nsched_ctxs, 2, nworkers_rounded, nworkers);
 			}
 			pthread_mutex_unlock(&act_hypervisor_mutex);
 		}
@@ -298,12 +56,12 @@ static void lp_handle_poped_task(unsigned sched_ctx, int worker)
 static void lp_size_ctxs(int *sched_ctxs, int ns, int *workers, int nworkers)
 {	
 	int nsched_ctxs = sched_ctxs == NULL ? sched_ctx_hypervisor_get_nsched_ctxs() : ns;
-	double res[nsched_ctxs][2];
+	double nworkers_per_type[nsched_ctxs][2];
 	int total_nw[2];
 	_get_total_nw(workers, nworkers, 2, total_nw);
 
 	pthread_mutex_lock(&act_hypervisor_mutex);
-	double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, res, total_nw);
+	double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, nworkers_per_type, total_nw);
 	if(vmax != 0.0)
 	{
 		int i;
@@ -313,15 +71,15 @@ static void lp_size_ctxs(int *sched_ctxs, int ns, int *workers, int nworkers)
 /* 			printf("ctx %d/worker type %d: n = %lf \n", i, 0, res[i][0]); */
 /* 			printf("ctx %d/worker type %d: n = %lf \n", i, 1, res[i][1]); */
 /* 		} */
-		int res_rounded[nsched_ctxs][2];
-		_round_double_to_int(nsched_ctxs, 2, res, res_rounded);
+		int nworkers_per_type_rounded[nsched_ctxs][2];
+		_lp_round_double_to_int(nsched_ctxs, 2, nworkers_per_type, nworkers_per_type_rounded);
 /*       		for( i = 0; i < nsched_ctxs; i++) */
 /* 		{ */
 /* 			printf("ctx %d/worker type %d: n = %d \n", i, 0, res_rounded[i][0]); */
 /* 			printf("ctx %d/worker type %d: n = %d \n", i, 1, res_rounded[i][1]); */
 /* 		} */
 		
-		_distribute_resources_in_ctxs(sched_ctxs, nsched_ctxs, 2, res_rounded, res, workers, nworkers);
+		_lp_distribute_resources_in_ctxs(sched_ctxs, nsched_ctxs, 2, nworkers_per_type_rounded, nworkers_per_type, workers, nworkers);
 	}
 	pthread_mutex_unlock(&act_hypervisor_mutex);
 }

+ 242 - 0
sched_ctx_hypervisor/src/hypervisor_policies/lp_tools.c

@@ -190,3 +190,245 @@ double _lp_get_tmax(int nw, int *workers)
 	double res[nsched_ctxs][ntypes_of_workers];
 	return _lp_get_nworkers_per_ctx(nsched_ctxs, ntypes_of_workers, res, total_nw) * 1000;
 }
+
+void _lp_round_double_to_int(int ns, int nw, double res[ns][nw], int res_rounded[ns][nw])
+{
+	int s, w;
+	double left_res[nw];
+	for(w = 0; w < nw; w++)
+		left_res[nw] = 0.0;
+	for(s = 0; s < ns; s++)
+	{
+		for(w = 0; w < nw; w++)
+		{
+			int x = floor(res[s][w]);
+			double x_double = (double)x;
+			double diff = res[s][w] - x_double;
+			
+			if(diff != 0.0)
+			{
+				if(diff > 0.5)
+				{
+					if(left_res[w] != 0.0)
+					{
+						if((diff + left_res[w]) > 0.5)
+						{
+							res_rounded[s][w] = x + 1;
+							left_res[w] = (-1.0) * (x_double + 1.0 - (res[s][w] + left_res[w]));
+						}
+						else
+						{
+							res_rounded[s][w] = x;
+							left_res[w] = (-1.0) * (diff + left_res[w]);
+						}
+					}
+					else
+					{
+						res_rounded[s][w] = x + 1;
+						left_res[w] = (-1.0) * (x_double + 1.0 - res[s][w]);
+					}
+
+				}
+				else
+				{
+					if((diff + left_res[w]) > 0.5)
+					{
+						res_rounded[s][w] = x + 1;
+						left_res[w] = (-1.0) * (x_double + 1.0 - (res[s][w] + left_res[w]));
+					}
+					else
+					{
+						res_rounded[s][w] = x;
+						left_res[w] = diff;
+					}
+				}
+			}
+		}
+	}		
+}
+
+void _lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw])
+{
+	int *sched_ctxs = sched_ctx_hypervisor_get_sched_ctxs();
+	int s, s2, w;
+	for(s = 0; s < ns; s++)
+	{
+		for(w = 0; w < nw; w++)
+		{
+			enum starpu_archtype arch;
+			if(w == 0) arch = STARPU_CUDA_WORKER;
+			if(w == 1) arch = STARPU_CPU_WORKER;
+
+			if(w == 1)
+			{
+				unsigned nworkers_ctx = get_nworkers_ctx(sched_ctxs[s], arch);
+				if(nworkers_ctx > res_rounded[s][w])
+				{
+					int nworkers_to_move = nworkers_ctx - res_rounded[s][w];
+					int receiving_s = -1;
+					
+					for(s2 = 0; s2 < ns; s2++)
+					{
+						if(sched_ctxs[s2] != sched_ctxs[s])
+						{
+							int nworkers_ctx2 = get_nworkers_ctx(sched_ctxs[s2], arch);
+							if((res_rounded[s2][w] - nworkers_ctx2) >= nworkers_to_move)
+							{
+								receiving_s = sched_ctxs[s2];
+								break;
+							}
+						}
+					}
+					if(receiving_s != -1)
+					{
+						int *workers_to_move = _get_first_workers(sched_ctxs[s], &nworkers_to_move, arch);
+						sched_ctx_hypervisor_move_workers(sched_ctxs[s], receiving_s, workers_to_move, nworkers_to_move, 0);
+						struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
+						int i;
+						for(i = 0; i < nworkers_to_move; i++)
+							new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
+						
+						free(workers_to_move);
+					}
+				}
+			}
+			else
+			{
+				double nworkers_ctx = get_nworkers_ctx(sched_ctxs[s], arch) * 1.0;
+				if(nworkers_ctx > res[s][w])
+				{
+					double nworkers_to_move = nworkers_ctx - res[s][w];
+					int receiving_s = -1;
+					
+					for(s2 = 0; s2 < ns; s2++)
+					{
+						if(sched_ctxs[s2] != sched_ctxs[s])
+						{
+							double nworkers_ctx2 = get_nworkers_ctx(sched_ctxs[s2], arch) * 1.0;
+							if((res[s2][w] - nworkers_ctx2) >= nworkers_to_move)
+							{
+								receiving_s = sched_ctxs[s2];
+								break;
+							}
+						}
+					}
+					if(receiving_s != -1)
+					{
+						int x = floor(nworkers_to_move);
+						double x_double = (double)x;
+						double diff = nworkers_to_move - x_double;
+						if(diff == 0.0)
+						{
+							int *workers_to_move = _get_first_workers(sched_ctxs[s], &x, arch);
+							if(x > 0)
+							{
+								sched_ctx_hypervisor_move_workers(sched_ctxs[s], receiving_s, workers_to_move, x, 0);
+
+								struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
+								int i;
+								for(i = 0; i < x; i++)
+									new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
+							}
+							free(workers_to_move);
+						}
+						else
+						{
+							x+=1;
+							int *workers_to_move = _get_first_workers(sched_ctxs[s], &x, arch);
+							if(x > 0)
+							{
+								if(diff > 0.3)
+									sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_move, x, receiving_s);
+								else
+									sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_move, x-1, receiving_s);
+								
+								struct policy_config *new_config = sched_ctx_hypervisor_get_config(receiving_s);
+								int i;
+								for(i = 0; i < x-1; i++)
+									new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] :  new_config->new_workers_max_idle;
+							}
+							free(workers_to_move);
+						}
+					}
+				}
+			}
+
+		}
+	}
+}
+
+void _lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers)
+{
+	int current_nworkers = workers == NULL ? starpu_worker_get_count() : nworkers;
+	int *current_sched_ctxs = sched_ctxs == NULL ? sched_ctx_hypervisor_get_sched_ctxs() : sched_ctxs;
+
+	int s, s2, w;
+	for(s = 0; s < ns; s++)
+	{
+		for(w = 0; w < nw; w++)
+		{
+			enum starpu_archtype arch;
+			if(w == 0) arch = STARPU_CUDA_WORKER;
+			if(w == 1) arch = STARPU_CPU_WORKER;
+
+			if(w == 1)
+			{
+				int nworkers_to_add = res_rounded[s][w];
+				int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &nworkers_to_add, arch);
+
+				if(nworkers_to_add > 0)
+				{
+					sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, nworkers_to_add, current_sched_ctxs[s]);
+					sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
+					struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
+					int i;
+					for(i = 0; i < nworkers_to_add; i++)
+						new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
+				}
+				free(workers_to_add);
+			}
+			else
+			{
+				double nworkers_to_add = res[s][w];
+				int x = floor(nworkers_to_add);
+				double x_double = (double)x;
+				double diff = nworkers_to_add - x_double;
+				if(diff == 0.0)
+				{
+					int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &x, arch);
+					if(x > 0)
+					{
+						sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x, current_sched_ctxs[s]);
+						sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
+						struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
+						int i;
+						for(i = 0; i < x; i++)
+							new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
+						
+					}
+					free(workers_to_add);
+				}
+				else
+				{
+					x+=1;
+					int *workers_to_add = _get_first_workers_in_list(workers, current_nworkers, &x, arch);
+					if(x > 0)
+					{
+						if(diff >= 0.3)
+							sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x, current_sched_ctxs[s]);
+						else
+							sched_ctx_hypervisor_add_workers_to_sched_ctx(workers_to_add, x-1, current_sched_ctxs[s]);
+						sched_ctx_hypervisor_start_resize(current_sched_ctxs[s]);
+						struct policy_config *new_config = sched_ctx_hypervisor_get_config(current_sched_ctxs[s]);
+						int i;
+						for(i = 0; i < x-1; i++)
+							new_config->max_idle[workers_to_add[i]] = new_config->max_idle[workers_to_add[i]] != MAX_IDLE_TIME ? new_config->max_idle[workers_to_add[i]] :  new_config->new_workers_max_idle;
+					}
+					free(workers_to_add);			
+				}
+			}
+			
+		}
+		sched_ctx_hypervisor_stop_resize(current_sched_ctxs[s]);
+	}
+}

+ 9 - 0
sched_ctx_hypervisor/src/hypervisor_policies/lp_tools.h

@@ -11,3 +11,12 @@ double _lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_workers, double r
 
 /* returns tmax of the system */
 double _lp_get_tmax(int nw, int *workers);
+
+/* the linear programme determins a rational number of ressources for each ctx, we round them depending on the type of ressource */
+void _lp_round_double_to_int(int ns, int nw, double res[ns][nw], int res_rounded[ns][nw]);
+
+/* redistribute the ressource in contexts by assigning the first x available ressources to each one */
+void _lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw]);
+
+/* make the first distribution of ressource in contexts by assigning the first x available ressources to each one */
+void _lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers);