Browse Source

bug fixing

Andra Hugo 13 years ago
parent
commit
32d3916b5b

+ 1 - 1
include/starpu_scheduler.h

@@ -137,7 +137,7 @@ struct starpu_sched_ctx_hypervisor_criteria {
 };
 };
 
 
 #ifdef STARPU_BUILD_SCHED_CTX_HYPERVISOR
 #ifdef STARPU_BUILD_SCHED_CTX_HYPERVISOR
-unsigned starpu_create_sched_ctx_with_criteria(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_name, struct starpu_sched_ctx_hypervisor_criteria *criteria);
+unsigned starpu_create_sched_ctx_with_criteria(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_name, struct starpu_sched_ctx_hypervisor_criteria **criteria);
 void starpu_call_poped_task_cb(int workerid, unsigned sched_ctx_id);
 void starpu_call_poped_task_cb(int workerid, unsigned sched_ctx_id);
 void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
 void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
 #endif //STARPU_BUILD_SCHED_CTX_HYPERVISOR
 #endif //STARPU_BUILD_SCHED_CTX_HYPERVISOR

+ 4 - 7
sched_ctx_hypervisor/src/hypervisor_policies/simple_policy.c

@@ -300,9 +300,7 @@ static unsigned _simple_resize(unsigned sender_sched_ctx, unsigned receiver_sche
 	if(ret != EBUSY)
 	if(ret != EBUSY)
 	{					
 	{					
 		unsigned nworkers_to_move = _get_nworkers_to_move(sender_sched_ctx);
 		unsigned nworkers_to_move = _get_nworkers_to_move(sender_sched_ctx);
-		
-		if(sender_sched_ctx == 2)
-			printf("try to resize with nworkers = %d\n", nworkers_to_move);
+//		printf("nworkers = %d\n", nworkers_to_move);
 		if(nworkers_to_move > 0)
 		if(nworkers_to_move > 0)
 		{
 		{
 			unsigned poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
 			unsigned poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
@@ -313,6 +311,7 @@ static unsigned _simple_resize(unsigned sender_sched_ctx, unsigned receiver_sche
 				poor_sched_ctx = receiver_sched_ctx;
 				poor_sched_ctx = receiver_sched_ctx;
 				struct simple_policy_config *config = (struct simple_policy_config*)sched_ctx_hypervisor_get_config(poor_sched_ctx);
 				struct simple_policy_config *config = (struct simple_policy_config*)sched_ctx_hypervisor_get_config(poor_sched_ctx);
 				unsigned nworkers = starpu_get_nworkers_of_sched_ctx(poor_sched_ctx);
 				unsigned nworkers = starpu_get_nworkers_of_sched_ctx(poor_sched_ctx);
+      
 				if((nworkers+nworkers_to_move) > config->max_nworkers)
 				if((nworkers+nworkers_to_move) > config->max_nworkers)
 					nworkers_to_move = nworkers > config->max_nworkers ? 0 : (config->max_nworkers - nworkers);
 					nworkers_to_move = nworkers > config->max_nworkers ? 0 : (config->max_nworkers - nworkers);
 				if(nworkers_to_move == 0) poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
 				if(nworkers_to_move == 0) poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
@@ -365,7 +364,7 @@ static void simple_manage_task_flux(unsigned curr_sched_ctx)
 		{
 		{
 			double debit_fast = sched_ctx_hypervisor_get_debit(fast_sched_ctx);
 			double debit_fast = sched_ctx_hypervisor_get_debit(fast_sched_ctx);
 			/* only if there is a difference of 30 % */
 			/* only if there is a difference of 30 % */
-			if(debit_fast != 0.0 && debit_fast > (curr_debit + curr_debit * 0.1))
+			if(debit_fast != 0.0 && (debit_fast + debit_fast *0.2) > curr_debit)
 				_simple_resize(fast_sched_ctx, curr_sched_ctx);
 				_simple_resize(fast_sched_ctx, curr_sched_ctx);
 		}
 		}
 		
 		
@@ -373,7 +372,7 @@ static void simple_manage_task_flux(unsigned curr_sched_ctx)
 		{
 		{
 			double debit_slow = sched_ctx_hypervisor_get_debit(slow_sched_ctx);
 			double debit_slow = sched_ctx_hypervisor_get_debit(slow_sched_ctx);
 			/* only if there is a difference of 30 % */
 			/* only if there is a difference of 30 % */
-			if(curr_debit != 0.0 && (debit_slow + debit_slow *0.1) < curr_debit)
+			if(curr_debit != 0.0 && (debit_slow + debit_slow *0.2) < curr_debit)
 				_simple_resize(curr_sched_ctx, slow_sched_ctx);
 				_simple_resize(curr_sched_ctx, slow_sched_ctx);
 		}
 		}
 	}
 	}
@@ -403,7 +402,6 @@ static void* simple_ioctl(unsigned sched_ctx, va_list varg_list, unsigned later)
 			workerids = va_arg(varg_list, int*);
 			workerids = va_arg(varg_list, int*);
 			nworkers = va_arg(varg_list, int);
 			nworkers = va_arg(varg_list, int);
 			double max_idle = va_arg(varg_list, double);
 			double max_idle = va_arg(varg_list, double);
-			
 			for(i = 0; i < nworkers; i++)
 			for(i = 0; i < nworkers; i++)
 				config->max_idle[workerids[i]] = max_idle;
 				config->max_idle[workerids[i]] = max_idle;
 
 
@@ -445,7 +443,6 @@ static void* simple_ioctl(unsigned sched_ctx, va_list varg_list, unsigned later)
 		case HYPERVISOR_MAX_WORKERS:
 		case HYPERVISOR_MAX_WORKERS:
 			config->max_nworkers = va_arg(varg_list, unsigned);
 			config->max_nworkers = va_arg(varg_list, unsigned);
 			if(config->max_nworkers == 0)
 			if(config->max_nworkers == 0)
-			  printf("%d: max nworkers = 0\n", sched_ctx);
 			break;
 			break;
 
 
 		case HYPERVISOR_GRANULARITY:
 		case HYPERVISOR_GRANULARITY:

+ 21 - 19
sched_ctx_hypervisor/src/sched_ctx_hypervisor.c

@@ -29,7 +29,7 @@ static void _load_hypervisor_policy(int type)
 	}
 	}
 }
 }
 
 
-struct starpu_sched_ctx_hypervisor_criteria* sched_ctx_hypervisor_init(int type)
+struct starpu_sched_ctx_hypervisor_criteria** sched_ctx_hypervisor_init(int type)
 {
 {
 	hypervisor.min_tasks = 0;
 	hypervisor.min_tasks = 0;
 	hypervisor.nsched_ctxs = 0;
 	hypervisor.nsched_ctxs = 0;
@@ -80,6 +80,7 @@ void sched_ctx_hypervisor_start_resize(unsigned sched_ctx)
 
 
 void sched_ctx_hypervisor_shutdown(void)
 void sched_ctx_hypervisor_shutdown(void)
 {
 {
+	printf("shutdown\n");
 	int i;
 	int i;
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 	{
 	{
@@ -89,6 +90,12 @@ void sched_ctx_hypervisor_shutdown(void)
 			sched_ctx_hypervisor_ignore_ctx(hypervisor.sched_ctxs[i]);
 			sched_ctx_hypervisor_ignore_ctx(hypervisor.sched_ctxs[i]);
 		}
 		}
 	}
 	}
+	criteria->idle_time_cb = NULL;
+	criteria->pushed_task_cb = NULL;
+	criteria->poped_task_cb = NULL;
+	criteria->post_exec_hook_cb = NULL;
+	criteria->reset_idle_time_cb = NULL;
+
 	free(criteria);
 	free(criteria);
 	criteria = NULL;
 	criteria = NULL;
 
 
@@ -352,23 +359,17 @@ void sched_ctx_hypervisor_steal_workers(unsigned sched_ctx, int *workerids, int
 
 
 static void reset_idle_time_cb(unsigned sched_ctx, int worker)
 static void reset_idle_time_cb(unsigned sched_ctx, int worker)
 {
 {
-	if(criteria != NULL)
-	{
-		if(hypervisor.resize[sched_ctx])
-			hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker] = 0.0;
-	}
+	if(hypervisor.resize[sched_ctx])
+		hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker] = 0.0;
 }
 }
 
 
 static void idle_time_cb(unsigned sched_ctx, int worker, double idle_time)
 static void idle_time_cb(unsigned sched_ctx, int worker, double idle_time)
 {
 {
-	if(criteria != NULL)
+	if(hypervisor.resize[sched_ctx] && hypervisor.nsched_ctxs > 1 && hypervisor.policy.manage_idle_time)
 	{
 	{
-		if(hypervisor.resize[sched_ctx] && hypervisor.nsched_ctxs > 1 && hypervisor.policy.manage_idle_time)
-		{
-			hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker] += idle_time;
-			hypervisor.policy.manage_idle_time(sched_ctx, worker, hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker]);
-			
-		}
+		hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker] += idle_time;
+		hypervisor.policy.manage_idle_time(sched_ctx, worker, hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker]);
+		
 	}
 	}
 	return;
 	return;
 }
 }
@@ -424,13 +425,14 @@ static void poped_task_cb(unsigned sched_ctx, int worker)
 	{
 	{
 		int npushed_tasks = get_ntasks(hypervisor.sched_ctx_w[sched_ctx].pushed_tasks);
 		int npushed_tasks = get_ntasks(hypervisor.sched_ctx_w[sched_ctx].pushed_tasks);
 		int npoped_tasks = get_ntasks(hypervisor.sched_ctx_w[sched_ctx].poped_tasks);
 		int npoped_tasks = get_ntasks(hypervisor.sched_ctx_w[sched_ctx].poped_tasks);
-		if(hypervisor.sched_ctx_w[sched_ctx].temp_npushed_tasks != npushed_tasks &&
-		   hypervisor.sched_ctx_w[sched_ctx].temp_npoped_tasks != npoped_tasks)
-		{
+		int old_npushed_tasks = hypervisor.sched_ctx_w[sched_ctx].temp_npushed_tasks;
+		int old_npoped_tasks = hypervisor.sched_ctx_w[sched_ctx].temp_npoped_tasks;
+		if((old_npushed_tasks + old_npushed_tasks * 0.2) < npushed_tasks ||
+		    (old_npoped_tasks + old_npoped_tasks * 0.2) < npoped_tasks)
 			hypervisor.policy.manage_task_flux(sched_ctx);
 			hypervisor.policy.manage_task_flux(sched_ctx);
-			hypervisor.sched_ctx_w[sched_ctx].temp_npushed_tasks = npushed_tasks;
-			hypervisor.sched_ctx_w[sched_ctx].temp_npoped_tasks = npoped_tasks;
-		}
+
+		hypervisor.sched_ctx_w[sched_ctx].temp_npushed_tasks = npushed_tasks;
+		hypervisor.sched_ctx_w[sched_ctx].temp_npoped_tasks = npoped_tasks;			
 	}
 	}
 }
 }
 
 

+ 7 - 8
src/core/sched_ctx.c

@@ -229,7 +229,7 @@ unsigned starpu_create_sched_ctx(const char *policy_name, int *workerids,
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 unsigned starpu_create_sched_ctx_with_criteria(const char *policy_name, int *workerids, 
 unsigned starpu_create_sched_ctx_with_criteria(const char *policy_name, int *workerids, 
 				 int nworkers_ctx, const char *sched_name,
 				 int nworkers_ctx, const char *sched_name,
-				 struct starpu_sched_ctx_hypervisor_criteria *criteria)
+				 struct starpu_sched_ctx_hypervisor_criteria **criteria)
 {
 {
 	unsigned sched_ctx_id = starpu_create_sched_ctx(policy_name, workerids, nworkers_ctx, sched_name);
 	unsigned sched_ctx_id = starpu_create_sched_ctx(policy_name, workerids, nworkers_ctx, sched_name);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
@@ -301,8 +301,7 @@ void _starpu_delete_all_sched_ctxs()
 		{
 		{
 			_starpu_deinit_sched_policy(sched_ctx);		
 			_starpu_deinit_sched_policy(sched_ctx);		
 			_starpu_barrier_counter_destroy(&sched_ctx->tasks_barrier);
 			_starpu_barrier_counter_destroy(&sched_ctx->tasks_barrier);
-			if(sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
-				free_sched_ctx_mem(sched_ctx);
+			free_sched_ctx_mem(sched_ctx);
 		}
 		}
 	}
 	}
 	return;
 	return;
@@ -644,10 +643,9 @@ void starpu_call_poped_task_cb(int workerid, unsigned sched_ctx_id)
 {
 {
 	struct starpu_worker_s *worker =  _starpu_get_worker_struct(workerid);
 	struct starpu_worker_s *worker =  _starpu_get_worker_struct(workerid);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
-	
 	if(sched_ctx != NULL && sched_ctx_id != 0 && sched_ctx_id != STARPU_NMAX_SCHED_CTXS
 	if(sched_ctx != NULL && sched_ctx_id != 0 && sched_ctx_id != STARPU_NMAX_SCHED_CTXS
-		   && sched_ctx->criteria != NULL)
-		sched_ctx->criteria->poped_task_cb(sched_ctx_id, worker->workerid);
+		   && *sched_ctx->criteria != NULL)
+		(*sched_ctx->criteria)->poped_task_cb(sched_ctx_id, worker->workerid);
 }
 }
 
 
 void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id)
 void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id)
@@ -655,8 +653,9 @@ void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id)
 	struct starpu_worker_s *worker =  _starpu_get_worker_struct(workerid);
 	struct starpu_worker_s *worker =  _starpu_get_worker_struct(workerid);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 
 
-	if(sched_ctx != NULL && sched_ctx_id != 0  && sched_ctx->criteria != NULL)
-			sched_ctx->criteria->pushed_task_cb(sched_ctx_id, workerid);
+	if(sched_ctx != NULL && sched_ctx_id != 0  && *sched_ctx->criteria != NULL)
+		(*sched_ctx->criteria)->pushed_task_cb(sched_ctx_id, workerid);
 
 
 }
 }
+
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR

+ 1 - 1
src/core/sched_ctx.h

@@ -71,7 +71,7 @@ struct starpu_sched_ctx {
 
 
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 	/* a structure containing a series of criteria determining the resize procedure */
 	/* a structure containing a series of criteria determining the resize procedure */
-	struct starpu_sched_ctx_hypervisor_criteria *criteria;
+	struct starpu_sched_ctx_hypervisor_criteria **criteria;
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 };
 };
 
 

+ 13 - 8
src/core/sched_policy.c

@@ -443,16 +443,21 @@ struct starpu_task *_starpu_pop_task(struct starpu_worker_s *worker)
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 	unsigned i;
 	unsigned i;
 	struct starpu_sched_ctx *sched_ctx = NULL;
 	struct starpu_sched_ctx *sched_ctx = NULL;
+	struct starpu_sched_ctx_hypervisor_criteria **criteria = NULL;
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 	{
 	{
 		sched_ctx = worker->sched_ctx[i];
 		sched_ctx = worker->sched_ctx[i];
-		if(sched_ctx != NULL && sched_ctx->id != 0 && sched_ctx->criteria != NULL 
-		   && sched_ctx->criteria->idle_time_cb && sched_ctx->criteria->reset_idle_time_cb)
+		if(sched_ctx != NULL && sched_ctx->id != 0)
 		{
 		{
-			if(!task)
-				sched_ctx->criteria->idle_time_cb(sched_ctx->id, worker->workerid, 1.0);
-			else
-				sched_ctx->criteria->reset_idle_time_cb(sched_ctx->id, worker->workerid);
+			criteria = sched_ctx->criteria;
+			if(criteria != NULL && *criteria != NULL && 
+			   (*criteria)->idle_time_cb && (*criteria)->reset_idle_time_cb)
+			{
+				if(!task)
+					(*criteria)->idle_time_cb(sched_ctx->id, worker->workerid, 1.0);
+				else
+					(*criteria)->reset_idle_time_cb(sched_ctx->id, worker->workerid);
+			}
 		}
 		}
 	}
 	}
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
@@ -474,8 +479,8 @@ void _starpu_sched_post_exec_hook(struct starpu_task *task)
 
 
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
 	if(task->hypervisor_tag > 0 && sched_ctx != NULL && 
 	if(task->hypervisor_tag > 0 && sched_ctx != NULL && 
-	   sched_ctx->id != 0 && sched_ctx->criteria != NULL)
-		sched_ctx->criteria->post_exec_hook_cb(sched_ctx->id, task->hypervisor_tag);
+	   sched_ctx->id != 0 && *sched_ctx->criteria != NULL)
+		(*sched_ctx->criteria)->post_exec_hook_cb(sched_ctx->id, task->hypervisor_tag);
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
 
 
 	if (sched_ctx->sched_policy->post_exec_hook)
 	if (sched_ctx->sched_policy->post_exec_hook)