Bladeren bron

liberate the resources used by the greedy scheduling policy

Cédric Augonnet 15 jaren geleden
bovenliggende
commit
2b6536a9e8

+ 17 - 0
src/core/mechanisms/fifo_queues.c

@@ -61,6 +61,23 @@ struct starpu_jobq_s *_starpu_create_fifo(void)
 	return jobq;
 }
 
+void _starpu_destroy_fifo(struct starpu_jobq_s *jobq)
+{
+	STARPU_ASSERT(jobq);
+
+	/* We first liberate the FIFO-specific data structure */
+	struct starpu_fifo_jobq_s *fifo = jobq->queue;
+
+	starpu_job_list_delete(fifo->jobq);
+	free(fifo);
+
+	/* Then we liberate the generic resources associated to a jobq */
+	pthread_mutex_destroy(&jobq->activity_mutex);
+	pthread_cond_destroy(&jobq->activity_cond);
+
+	free(jobq);
+}
+
 int _starpu_fifo_push_prio_task(struct starpu_jobq_s *q, starpu_job_t task)
 {
 #ifndef STARPU_NO_PRIO

+ 1 - 0
src/core/mechanisms/fifo_queues.h

@@ -36,6 +36,7 @@ struct starpu_fifo_jobq_s {
 };
 
 struct starpu_jobq_s *_starpu_create_fifo(void);
+void _starpu_destroy_fifo(struct starpu_jobq_s *jobq);
 
 int _starpu_fifo_push_task(struct starpu_jobq_s *q, starpu_job_t task);
 int _starpu_fifo_push_prio_task(struct starpu_jobq_s *q, starpu_job_t task);

+ 24 - 2
src/core/mechanisms/queues.c

@@ -29,16 +29,38 @@ void _starpu_setup_queues(void (*init_queue_design)(void),
 {
 	unsigned worker;
 
-	init_queue_design();
+	if (init_queue_design)
+		init_queue_design();
 
 	for (worker = 0; worker < config->nworkers; worker++)
 	{
 		struct  starpu_worker_s *workerarg = &config->workers[worker];
 		
-		workerarg->jobq = func_init_queue();
+		if (func_init_queue)
+			workerarg->jobq = func_init_queue();
 	}
 }
 
+void _starpu_deinit_queues(void (*deinit_queue_design)(void),
+		  void (*func_deinit_queue)(struct starpu_jobq_s *q), 
+		  struct starpu_machine_config_s *config)
+{
+	unsigned worker;
+
+	for (worker = 0; worker < config->nworkers; worker++)
+	{
+		struct  starpu_worker_s *workerarg = &config->workers[worker];
+		
+		if (func_deinit_queue)
+			func_deinit_queue(workerarg->jobq);
+	}
+
+	if (deinit_queue_design)
+		deinit_queue_design();
+}
+
+
+
 /* this may return NULL for an "anonymous thread" */
 struct starpu_jobq_s *_starpu_get_local_queue(void)
 {

+ 4 - 0
src/core/mechanisms/queues.h

@@ -66,6 +66,10 @@ struct starpu_machine_config_s;
 void _starpu_setup_queues(void (*init_queue_design)(void),
                   struct starpu_jobq_s *(*func_init_queue)(void),
                   struct starpu_machine_config_s *config);
+void _starpu_deinit_queues(void (*deinit_queue_design)(void),
+		  void (*func_deinit_queue)(struct starpu_jobq_s *q), 
+		  struct starpu_machine_config_s *config);
+
 
 struct starpu_jobq_s *_starpu_get_local_queue(void);
 void _starpu_set_local_queue(struct starpu_jobq_s *jobq);

+ 15 - 1
src/core/policies/eager-central-policy.c

@@ -38,6 +38,14 @@ static void init_central_queue_design(void)
 	jobq->_starpu_pop_every_task = _starpu_fifo_pop_every_task;
 }
 
+static void deinit_central_queue_design(void)
+{
+	/* TODO check that there is no task left in the queue */
+
+	/* deallocate the job queue */
+	_starpu_destroy_fifo(jobq);
+}
+
 static struct starpu_jobq_s *func_init_central_queue(void)
 {
 	/* once again, this is trivial */
@@ -50,6 +58,12 @@ static void initialize_eager_center_policy(struct starpu_machine_config_s *confi
 	_starpu_setup_queues(init_central_queue_design, func_init_central_queue, config);
 }
 
+static void deinitialize_eager_center_policy(struct starpu_machine_config_s *config, 
+		   __attribute__ ((unused)) struct starpu_sched_policy_s *_policy) 
+{
+	_starpu_deinit_queues(deinit_central_queue_design, NULL, config);
+}
+
 static struct starpu_jobq_s *get_local_queue_eager(struct starpu_sched_policy_s *policy 
 						__attribute__ ((unused)))
 {
@@ -59,7 +73,7 @@ static struct starpu_jobq_s *get_local_queue_eager(struct starpu_sched_policy_s
 
 struct starpu_sched_policy_s sched_eager_policy = {
 	.init_sched = initialize_eager_center_policy,
-	.deinit_sched = NULL,
+	.deinit_sched = deinitialize_eager_center_policy,
 	._starpu_get_local_queue = get_local_queue_eager,
 	.policy_name = "eager",
 	.policy_description = "greedy policy"