Andra Hugo 14 éve
szülő
commit
3f57f348c3
4 módosított fájl, 45 hozzáadás és 18 törlés
  1. 2 0
      include/starpu_scheduler.h
  2. 38 12
      src/core/sched_policy.c
  3. 2 2
      src/core/sched_policy.h
  4. 3 4
      src/core/workers.c

+ 2 - 0
include/starpu_scheduler.h

@@ -104,8 +104,10 @@ struct starpu_sched_ctx {
 	struct starpu_sched_policy_s *sched_policy;
 	int workerid[STARPU_NMAXWORKERS];
 	int nworkers_in_ctx;
+	unsigned is_init_sched; /*we keep an init sched which we never delete*/
 };
 
+void starpu_delete_sched_ctx(struct starpu_sched_ctx *sched_ctx);
 
 /* When there is no available task for a worker, StarPU blocks this worker on a
 condition variable. This function specifies which condition variable (and the

+ 38 - 12
src/core/sched_policy.c

@@ -422,10 +422,11 @@ static int starpu_get_ctx_id(struct starpu_sched_ctx *sched_ctx, struct starpu_w
 	return -1;
 }
 
-void _starpu_create_sched_ctx(struct starpu_sched_ctx *sched_ctx, const char *policy_name, int *workerids_in_ctx, int nworkerids_in_ctx)
+void _starpu_create_sched_ctx(struct starpu_sched_ctx *sched_ctx, const char *policy_name, int *workerids_in_ctx, int nworkerids_in_ctx, unsigned is_init_sched)
 {
 	sched_ctx->nworkers_in_ctx = nworkerids_in_ctx;
 	sched_ctx->sched_policy = malloc(sizeof(struct starpu_sched_policy_s));
+	sched_ctx->is_init_sched = is_init_sched;
 
 
 	struct starpu_machine_config_s *config = _starpu_get_machine_config();
@@ -535,31 +536,56 @@ void starpu_create_sched_ctx(struct starpu_sched_ctx *sched_ctx, const char *pol
     	  if(!starpu_task_wait_for_all()){
 		/*block the workers until the contex is switched*/
 		set_changing_ctx_flag(STATUS_CHANGING_CTX, nworkerids_in_ctx, workerids_in_ctx);
-		_starpu_create_sched_ctx(sched_ctx, policy_name, workerids_in_ctx, nworkerids_in_ctx);
+		_starpu_create_sched_ctx(sched_ctx, policy_name, workerids_in_ctx, nworkerids_in_ctx, 0);
 		set_changing_ctx_flag(STATUS_UNKNOWN, nworkerids_in_ctx, workerids_in_ctx);
 	  }
 	  return;
 }
 
-void _starpu_delete_sched_ctx(struct starpu_sched_ctx *sched_ctx)
+int worker_belongs_to_ctx(struct starpu_worker_s *workerarg, struct starpu_sched_ctx *sched_ctx){
+	unsigned i;
+	for(i = 0; i < workerarg->nctxs; i++)
+		if(sched_ctx != NULL && workerarg->sched_ctx[i] == sched_ctx 
+		   && workerarg->status != STATUS_JOINED)
+		  return 1;
+	return 0;
+
+}
+void starpu_delete_sched_ctx(struct starpu_sched_ctx *sched_ctx)
 {
 	struct starpu_machine_config_s *config = _starpu_get_machine_config();
 	int nworkers = config->topology.nworkers;
        
-	unsigned used_sched_ctx = 0;
 	int i;
 	int workerid = -1;
 	for(i = 0; i < nworkers; i++){
 		struct starpu_worker_s *workerarg = &config->workers[i];
-		workerid = starpu_get_ctx_id(sched_ctx, workerarg);
-		
-		if(sched_ctx != NULL && workerid != -1 && workerarg->status != STATUS_JOINED)
-			used_sched_ctx++;
+		if(worker_belongs_to_ctx(workerarg, sched_ctx))
+			workerarg->nctxs--;
+
 	}
 
-	if(used_sched_ctx < 2  && sched_ctx != NULL){
-		free(sched_ctx->sched_policy);
-		sched_ctx->sched_policy = NULL;
-		sched_ctx = NULL;
+	free(sched_ctx->sched_policy);
+	sched_ctx->sched_policy = NULL;
+	sched_ctx = NULL;
+}
+
+void _starpu_delete_all_sched_ctxs(){
+  	struct starpu_machine_config_s *config = _starpu_get_machine_config();
+	int nworkers = config->topology.nworkers;
+
+	unsigned i, j;
+	struct starpu_sched_ctx *sched_ctx = NULL;
+	struct starpu_worker_s *workerarg = NULL;
+	for(i = 0; i < nworkers; i++){
+		workerarg = &config->workers[i];
+		for(j = 0; j < workerarg->nctxs; j++){
+			sched_ctx = workerarg->sched_ctx[j];
+			if(sched_ctx != NULL && !sched_ctx->is_init_sched){
+				free(sched_ctx->sched_policy);
+				sched_ctx->sched_policy = NULL;
+				sched_ctx = NULL;
+			}
+		}
 	}
 }

+ 2 - 2
src/core/sched_policy.h

@@ -37,9 +37,9 @@ void _starpu_sched_post_exec_hook(struct starpu_task *task);
 
 void _starpu_wait_on_sched_event(void);
 
-void _starpu_create_sched_ctx(struct starpu_sched_ctx *sched_ctx, const char *policy_name, int *workerid, int nworkerids);
+void _starpu_create_sched_ctx(struct starpu_sched_ctx *sched_ctx, const char *policy_name, int *workerid, int nworkerids, unsigned is_init_sched);
 
-void _starpu_delete_sched_ctx(struct starpu_sched_ctx *sched_ctx);
+void _starpu_delete_all_sched_ctxs();
 
 void _starpu_increment_nblocked_ths(int nworkers);
 

+ 3 - 4
src/core/workers.c

@@ -351,9 +351,9 @@ int starpu_init(struct starpu_conf *user_conf)
 	/* initialize the scheduling policy */
 
 	if(user_conf == NULL)
-	  _starpu_create_sched_ctx(&sched_ctx, NULL, NULL, -1);
+	  _starpu_create_sched_ctx(&sched_ctx, NULL, NULL, -1, 1);
 	else
-	  _starpu_create_sched_ctx(&sched_ctx, user_conf->sched_policy_name, NULL, -1);
+	  _starpu_create_sched_ctx(&sched_ctx, user_conf->sched_policy_name, NULL, -1, 1);
 
 	//_starpu_init_sched_policy(&config, &sched_ctx);
 
@@ -487,8 +487,7 @@ void starpu_shutdown(void)
 	/* wait for their termination */
 	_starpu_terminate_workers(&config);
 
-	//	_starpu_deinit_sched_policy(&config);
-	
+	_starpu_delete_all_sched_ctxs();
 
 	_starpu_destroy_topology(&config);