Преглед изворни кода

move task_pool out of the policies

Andra Hugo пре 12 година
родитељ
комит
05d10ea37d

+ 10 - 0
sc_hypervisor/include/sc_hypervisor_policy.h

@@ -28,6 +28,7 @@ extern "C"
 #define HYPERVISOR_REDIM_SAMPLE 0.02
 #define HYPERVISOR_START_REDIM_SAMPLE 0.1
 
+/* task wrapper linked list */
 struct sc_hypervisor_policy_task_pool
 {
 	/* Which codelet has been executed */
@@ -42,6 +43,15 @@ struct sc_hypervisor_policy_task_pool
 	struct sc_hypervisor_policy_task_pool *next;
 };
 
+/* add task information to a task wrapper linked list */
+void sc_hypervisor_policy_add_task_to_pool(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, struct sc_hypervisor_policy_task_pool *task_pools);
+
+/* remove task information from a task wrapper linked list */
+void sc_hypervisor_policy_remove_task_from_pool(struct starpu_task *task, uint32_t footprint, struct sc_hypervisor_policy_task_pool *task_pools);
+
+/* clone a task wrapper linked list */
+struct sc_hypervisor_policy_task_pool* sc_hypervisor_policy_clone_task_pool(struct sc_hypervisor_policy_task_pool *tp);
+
 /* find the context with the lowest priority in order to move some workers */
 unsigned sc_hypervisor_find_lowest_prio_sched_ctx(unsigned req_sched_ctx, int nworkers_to_move);
 

+ 1 - 0
sc_hypervisor/src/Makefile.am

@@ -25,6 +25,7 @@ libsc_hypervisor_la_SOURCES = 				\
 	sc_hypervisor.c					\
 	sc_config.c					\
 	policies_utils/policy_tools.c			\
+	policies_utils/task_pool.c			\
 	policies_utils/lp_tools.c			\
 	hypervisor_policies/idle_policy.c		\
 	hypervisor_policies/app_driven_policy.c		\

+ 3 - 79
sc_hypervisor/src/hypervisor_policies/teft_lp_policy.c

@@ -170,88 +170,12 @@ static void teft_lp_handle_submitted_job(struct starpu_codelet *cl, unsigned sch
 {
 	/* count the tasks of the same type */
 	starpu_pthread_mutex_lock(&mutex);
-	struct sc_hypervisor_policy_task_pool *tp = NULL;
-
-	for (tp = task_pools; tp; tp = tp->next)
-	{
-		if (tp && tp->cl == cl && tp->footprint == footprint && tp->sched_ctx_id == sched_ctx)
-			break;
-	}
-
-	if (!tp)
-	{
-		tp = (struct sc_hypervisor_policy_task_pool *) malloc(sizeof(struct sc_hypervisor_policy_task_pool));
-		tp->cl = cl;
-		tp->footprint = footprint;
-		tp->sched_ctx_id = sched_ctx;
-		tp->n = 0;
-		tp->next = task_pools;
-		task_pools = tp;
-	}
-
-	/* One more task of this kind */
-	tp->n++;
+	sc_hypervisor_policy_add_task_to_pool(cl, sched_ctx, footprint, task_pools);
 	starpu_pthread_mutex_unlock(&mutex);
 
 	size_if_required();
 }
 
-static void _remove_task_from_pool(struct starpu_task *task, uint32_t footprint)
-{
-	/* count the tasks of the same type */
-	struct sc_hypervisor_policy_task_pool *tp = NULL;
-
-	for (tp = task_pools; tp; tp = tp->next)
-	{
-		if (tp && tp->cl == task->cl && tp->footprint == footprint && tp->sched_ctx_id == task->sched_ctx)
-			break;
-	}
-
-	if (tp)
-	{
-		if(tp->n > 1)
-			tp->n--;
-		else
-		{
-			if(tp == task_pools)
-			{
-				struct sc_hypervisor_policy_task_pool *next_tp = NULL;
-				if(task_pools->next)
-					next_tp = task_pools->next;
-
-				free(tp);
-				tp = NULL;
-				
-				if(next_tp)
-					task_pools = next_tp;
-				
-			}
-			else
-			{
-				struct sc_hypervisor_policy_task_pool *prev_tp = NULL;
-				for (prev_tp = task_pools; prev_tp; prev_tp = prev_tp->next)
-				{
-					if (prev_tp->next == tp)
-						prev_tp->next = tp->next;
-				}
-				
-				free(tp);
-				tp = NULL;
-			}
-		}
-	}
-}
-
-static struct sc_hypervisor_policy_task_pool* _clone_linked_list(struct sc_hypervisor_policy_task_pool *tp)
-{
-	if(tp == NULL) return NULL;
-
-	struct sc_hypervisor_policy_task_pool *tmp_tp = (struct sc_hypervisor_policy_task_pool*)malloc(sizeof(struct sc_hypervisor_policy_task_pool));
-	memcpy(tmp_tp, tp, sizeof(struct sc_hypervisor_policy_task_pool));
-	tmp_tp->next = _clone_linked_list(tp->next);
-	return tmp_tp;
-}
-
 static void _get_tasks_times(int nw, int nt, double times[nw][nt], int *workers, unsigned size_ctxs)
 {
         struct sc_hypervisor_policy_task_pool *tp;
@@ -554,7 +478,7 @@ static void teft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct sta
 			   submitted task will change during the exec */
 
 			struct sc_hypervisor_policy_task_pool *tp = NULL;
-			struct sc_hypervisor_policy_task_pool *tmp_task_pools = _clone_linked_list(task_pools);
+			struct sc_hypervisor_policy_task_pool *tmp_task_pools = sc_hypervisor_policy_clone_task_pool(task_pools);
 
 			for (tp = task_pools; tp; tp = tp->next)
 				nt++;
@@ -586,7 +510,7 @@ static void teft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct sta
 	}
 	/* too expensive to take this mutex and correct value of the number of tasks is not compulsory */
 //	starpu_pthread_mutex_lock(&mutex);
-	_remove_task_from_pool(task, footprint);
+	sc_hypervisor_policy_remove_task_from_pool(task, footprint, task_pools);
 //	starpu_pthread_mutex_unlock(&mutex);
 
 }

+ 1 - 1
sc_hypervisor/src/policies_utils/policy_tools.c

@@ -39,7 +39,7 @@ static int _compute_priority(unsigned sched_ctx)
 	return total_priority;
 }
 
-/* find the context with the slowest priority */
+/* find the context with the lowest priority */
 unsigned sc_hypervisor_find_lowest_prio_sched_ctx(unsigned req_sched_ctx, int nworkers_to_move)
 {
 	int i;

+ 99 - 0
sc_hypervisor/src/policies_utils/task_pool.c

@@ -0,0 +1,99 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010-2013  INRIA
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+
+#include "sc_hypervisor_policy.h"
+
+void sc_hypervisor_policy_add_task_to_pool(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, struct sc_hypervisor_policy_task_pool *task_pools)
+{
+	struct sc_hypervisor_policy_task_pool *tp = NULL;
+
+	for (tp = task_pools; tp; tp = tp->next)
+	{
+		if (tp && tp->cl == cl && tp->footprint == footprint && tp->sched_ctx_id == sched_ctx)
+			break;
+	}
+
+	if (!tp)
+	{
+		tp = (struct sc_hypervisor_policy_task_pool *) malloc(sizeof(struct sc_hypervisor_policy_task_pool));
+		tp->cl = cl;
+		tp->footprint = footprint;
+		tp->sched_ctx_id = sched_ctx;
+		tp->n = 0;
+		tp->next = task_pools;
+		task_pools = tp;
+	}
+
+	/* One more task of this kind */
+	tp->n++;
+}
+
+void sc_hypervisor_policy_remove_task_from_pool(struct starpu_task *task, uint32_t footprint, struct sc_hypervisor_policy_task_pool *task_pools)
+{
+	/* count the tasks of the same type */
+	struct sc_hypervisor_policy_task_pool *tp = NULL;
+
+	for (tp = task_pools; tp; tp = tp->next)
+	{
+		if (tp && tp->cl == task->cl && tp->footprint == footprint && tp->sched_ctx_id == task->sched_ctx)
+			break;
+	}
+
+	if (tp)
+	{
+		if(tp->n > 1)
+			tp->n--;
+		else
+		{
+			if(tp == task_pools)
+			{
+				struct sc_hypervisor_policy_task_pool *next_tp = NULL;
+				if(task_pools->next)
+					next_tp = task_pools->next;
+
+				free(tp);
+				tp = NULL;
+				
+				if(next_tp)
+					task_pools = next_tp;
+				
+			}
+			else
+			{
+				struct sc_hypervisor_policy_task_pool *prev_tp = NULL;
+				for (prev_tp = task_pools; prev_tp; prev_tp = prev_tp->next)
+				{
+					if (prev_tp->next == tp)
+						prev_tp->next = tp->next;
+				}
+				
+				free(tp);
+				tp = NULL;
+			}
+		}
+	}
+}
+
+struct sc_hypervisor_policy_task_pool* sc_hypervisor_policy_clone_task_pool(struct sc_hypervisor_policy_task_pool *tp)
+{
+	if(tp == NULL) return NULL;
+
+	struct sc_hypervisor_policy_task_pool *tmp_tp = (struct sc_hypervisor_policy_task_pool*)malloc(sizeof(struct sc_hypervisor_policy_task_pool));
+	memcpy(tmp_tp, tp, sizeof(struct sc_hypervisor_policy_task_pool));
+	tmp_tp->next = sc_hypervisor_policy_clone_task_pool(tp->next);
+	return tmp_tp;
+}