瀏覽代碼

plateform to create strategies for constructing ones own hypervisor(still slow)

Andra Hugo 13 年之前
父節點
當前提交
e6d0ef6c68

+ 17 - 11
include/starpu_scheduler.h

@@ -69,39 +69,39 @@ struct starpu_machine_topology_s {
  * field of the starpu_conf structure passed to the starpu_init function. */
 struct starpu_sched_policy_s {
 	/* Initialize the scheduling policy. */
-	void (*init_sched)(unsigned ctx_id);
+	void (*init_sched)(unsigned sched_ctx_id);
 
 	/* Cleanup the scheduling policy. */
-	void (*deinit_sched)(unsigned ctx_id);
+	void (*deinit_sched)(unsigned sched_ctx_id);
 
 	/* Insert a task into the scheduler. */
-        int (*push_task)(struct starpu_task *, unsigned ctx_id);
+        int (*push_task)(struct starpu_task *);
 	/* Notify the scheduler that a task was directly pushed to the worker
 	 * without going through the scheduler. This method is called when a
 	 * task is explicitely assigned to a worker. This method therefore
 	 * permits to keep the timing state of the scheduler coherent even
 	 * when StarPU bypasses the scheduling strategy. */
-	void (*push_task_notify)(struct starpu_task *, int workerid, unsigned ctx_id);
+	void (*push_task_notify)(struct starpu_task *, int workerid);
 
 
 	/* Get a task from the scheduler. The mutex associated to the worker is
 	 * already taken when this method is called. */
-	struct starpu_task *(*pop_task)(unsigned ctx_id);
+	struct starpu_task *(*pop_task)();
 
 	 /* Remove all available tasks from the scheduler (tasks are chained by
 	  * the means of the prev and next fields of the starpu_task
 	  * structure). The mutex associated to the worker is already taken
 	  * when this method is called. */
-	struct starpu_task *(*pop_every_task)(unsigned ctx_id);
+	struct starpu_task *(*pop_every_task)();
 
 	/* This method is called every time a task has been executed. (optionnal) */
-	void (*post_exec_hook)(struct starpu_task *, unsigned ctx_id);
+	void (*post_exec_hook)(struct starpu_task *);
 
 	/* Initialize the scheduling policy for added workers. */
-	void (*add_workers)(unsigned ctx_id, int *workerids, unsigned nworkers);
+	void (*add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
 
 	/* Deinitialize the scheduling policy for removed workers. */
-	void (*remove_workers)(unsigned ctx_id, int *workerids, unsigned nworkers);
+	void (*remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
 
 	/* Name of the policy (optionnal) */
 	const char *policy_name;
@@ -128,8 +128,8 @@ struct worker_collection {
 #define WORKER_LIST 0
 
 struct starpu_sched_ctx_hypervisor_criteria {
-	void (*update_current_idle_time)(unsigned sched_ctx, int worker, double idle_time, unsigned current_nprocs);
-	void (*update_current_working_time)(unsigned sched_ctx, int worker, double working_time, unsigned current_nprocs);
+	void (*idle_time_cb)(unsigned sched_ctx, int worker, double idle_time);
+	void (*working_time_cb)(unsigned sched_ctx, double working_time);
 };
 
 #ifdef STARPU_BUILD_SCHED_CTX_HYPERVISOR
@@ -162,6 +162,12 @@ struct worker_collection* starpu_get_worker_collection_of_sched_ctx(unsigned sch
 
 pthread_mutex_t* starpu_get_changing_ctx_mutex(unsigned sched_ctx_id);
 
+void starpu_set_sched_ctx(unsigned *sched_ctx);
+
+unsigned starpu_get_sched_ctx();
+
+unsigned starpu_get_nworkers_of_sched_ctx(unsigned sched_ctx);
+
 /* Check if the worker specified by workerid can execute the codelet. */
 int starpu_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
 

+ 0 - 4
include/starpu_task.h

@@ -272,10 +272,6 @@ void starpu_task_destroy(struct starpu_task *task);
 
 int starpu_task_submit(struct starpu_task *task);
 	
-void starpu_set_sched_ctx(unsigned *sched_ctx);
-
-unsigned starpu_get_sched_ctx();
-
 /* This function blocks until the task was executed. It is not possible to
  * synchronize with a task more than once. It is not possible to wait
  * synchronous or detached tasks.

+ 24 - 10
sched_ctx_hypervisor/include/sched_ctx_hypervisor.h

@@ -1,6 +1,15 @@
 #include <starpu.h>
+#include <../common/config.h>
 
-struct starpu_sched_ctx_hypervisor_criteria* sched_ctx_hypervisor_init(void);
+/* ioctl properties*/
+#define HYPERVISOR_MAX_IDLE 1
+#define HYPERVISOR_MIN_WORKING 2
+#define HYPERVISOR_PRIORITY 3
+#define HYPERVISOR_MIN_PROCS 4
+#define HYPERVISOR_MAX_PROCS 5
+#define HYPERVISOR_GRANULARITY 6
+
+struct starpu_sched_ctx_hypervisor_criteria* sched_ctx_hypervisor_init(int type);
 
 void sched_ctx_hypervisor_shutdown(void);
 
@@ -8,17 +17,22 @@ void sched_ctx_hypervisor_handle_ctx(unsigned sched_ctx);
 
 void sched_ctx_hypervisor_ignore_ctx(unsigned sched_ctx);
 
-void sched_ctx_hypervisor_set_resize_interval(unsigned sched_ctx, unsigned min_nprocs, unsigned max_nprocs);
-
-void sched_ctx_hypervisor_set_resize_granularity(unsigned sched_ctx, unsigned granluarity);
-
-void sched_ctx_hypervisor_set_idle_max_value(unsigned sched_ctx, int max_idle_value, int *workers, int nworkers);
+void sched_ctx_hypervisor_resize(unsigned sender_sched_ctx, unsigned receier_sched_ctx, int *workers_to_move, unsigned nworkers_to_movex);
 
-void sched_ctx_hypervisor_set_work_min_value(unsigned sched_ctx, int min_working_value, int *workers, int nworkers); 
+void sched_ctx_hypervisor_set_data(unsigned sched_ctx, void *data);
 
-void sched_ctx_hypervisor_increase_priority(unsigned sched_ctx, int priority_step, int *workers, int nworkers);
+void* sched_ctx_hypervisor_get_data(unsigned sched_ctx);
 
-void sched_ctx_hypervisor_update_current_idle_time(unsigned sched_ctx, int worker, double idle_time, unsigned current_nprocs);
+void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...);
 
-void sched_ctx_hypervisor_update_current_working_time(unsigned sched_ctx, int worker, double working_time, unsigned current_nprocs);
+/* hypervisor policies */
+#define SIMPLE_POLICY 1
 
+struct hypervisor_policy {
+	void (*init)(void);
+	void (*deinit)(void);
+	void (*add_sched_ctx)(unsigned sched_ctx);
+	void(*remove_sched_ctx)(unsigned sched_ctx);
+	void (*ioctl)(unsigned sched_ctx, va_list varg_list);
+	void (*manage_idle_time)(unsigned req_sched_ctx, int *sched_ctxs, unsigned nsched_ctxs, int worker, double idle_time);
+};

+ 3 - 1
sched_ctx_hypervisor/src/Makefile.am

@@ -25,4 +25,6 @@ lib_LTLIBRARIES = libsched_ctx_hypervisor.la
 
 libsched_ctx_hypervisor_la_LIBADD = $(top_builddir)/src/libstarpu.la
 
-libsched_ctx_hypervisor_la_SOURCES = sched_ctx_hypervisor.c
+libsched_ctx_hypervisor_la_SOURCES = 	\
+	sched_ctx_hypervisor.c		\
+	hypervisor_policies/simple_policy.c

+ 103 - 164
sched_ctx_hypervisor/src/sched_ctx_hypervisor.c

@@ -1,230 +1,169 @@
 #include <sched_ctx_hypervisor_intern.h>
-#include <sched_ctx_hypervisor.h>
-#include <common/utils.h>
-#include <pthread.h>
 
 struct starpu_sched_ctx_hypervisor_criteria* criteria = NULL;
-pthread_mutex_t resize_mutex;
 
-static void reset_ctx_wrapper_info(unsigned sched_ctx)
-{
-	hypervisor.resize_granularity = 1;
+extern struct hypervisor_policy simple_policy;
 
-	int i;
-	for(i = 0; i < STARPU_NMAXWORKERS; i++)
+static void idle_time_cb(unsigned sched_ctx, int worker, double idle_time);
+
+static void _load_hypervisor_policy(int type)
+{
+	switch(type)
 	{
-		hypervisor.sched_ctx_wrapper[sched_ctx].priority[i] = 0;
-	 	hypervisor.sched_ctx_wrapper[sched_ctx].current_idle_time[i] = 0.0;
-		hypervisor.sched_ctx_wrapper[sched_ctx].current_working_time[i] = 0.0;
+	case SIMPLE_POLICY:
+		hypervisor.policy.init = simple_policy.init;
+		hypervisor.policy.deinit = simple_policy.deinit;
+		hypervisor.policy.add_sched_ctx = simple_policy.add_sched_ctx;
+		hypervisor.policy.remove_sched_ctx = simple_policy.remove_sched_ctx;
+		hypervisor.policy.ioctl = simple_policy.ioctl;
+		hypervisor.policy.manage_idle_time = simple_policy.manage_idle_time;
+		break;
 	}
+		
 }
 
-struct starpu_sched_ctx_hypervisor_criteria* sched_ctx_hypervisor_init(void)
+struct starpu_sched_ctx_hypervisor_criteria* sched_ctx_hypervisor_init(int type)
 {
 	hypervisor.resize = 1;
-	hypervisor.num_ctxs = 0;
+	hypervisor.nsched_ctxs = 0;
+
 	int i;
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 	{
-		hypervisor.sched_ctx_wrapper[i].sched_ctx = STARPU_NMAX_SCHED_CTXS;
-		hypervisor.sched_ctx_wrapper[i].current_nprocs = 0;
-		hypervisor.sched_ctx_wrapper[i].min_nprocs = 0;
-		hypervisor.sched_ctx_wrapper[i].max_nprocs = 0;
-		hypervisor.sched_ctx_wrapper[i].current_nprocs = 0;
-		reset_ctx_wrapper_info(i);
+		hypervisor.sched_ctxs[i] = -1;
+		hypervisor.sched_ctx_w[i].sched_ctx = STARPU_NMAX_SCHED_CTXS;
+		hypervisor.sched_ctx_w[i].data = NULL;
 		int j;
 		for(j = 0; j < STARPU_NMAXWORKERS; j++)
-		{
-			hypervisor.sched_ctx_wrapper[i].max_idle_time[j] = MAX_IDLE_TIME;
-			hypervisor.sched_ctx_wrapper[i].min_working_time[j] = MIN_WORKING_TIME;
-	
-		}
+			hypervisor.sched_ctx_w[i].current_idle_time[j] = 0.0;
 	}
-	PTHREAD_MUTEX_INIT(&resize_mutex, NULL);
 
+
+	_load_hypervisor_policy(type);
+
+	hypervisor.policy.init();
 	criteria = (struct starpu_sched_ctx_hypervisor_criteria*)malloc(sizeof(struct starpu_sched_ctx_hypervisor_criteria));
-	criteria->update_current_idle_time =  sched_ctx_hypervisor_update_current_idle_time;
+	criteria->idle_time_cb = idle_time_cb;
 	return criteria;
 }
 
 void sched_ctx_hypervisor_shutdown(void)
 {
+	hypervisor.policy.deinit();
 	hypervisor.resize = 0;
-	PTHREAD_MUTEX_DESTROY(&resize_mutex);
 	free(criteria);
 }
 
 void sched_ctx_hypervisor_handle_ctx(unsigned sched_ctx)
-{
-	hypervisor.sched_ctx_wrapper[sched_ctx].sched_ctx = sched_ctx;
-	hypervisor.num_ctxs++;
+{	
+	hypervisor.policy.add_sched_ctx(sched_ctx);
+	hypervisor.sched_ctx_w[sched_ctx].sched_ctx = sched_ctx;
+	hypervisor.sched_ctxs[hypervisor.nsched_ctxs++] = sched_ctx;
 }
 
-void sched_ctx_hypervisor_ignore_ctx(unsigned sched_ctx)
+static int _get_first_free_sched_ctx(int *sched_ctxs, unsigned nsched_ctxs)
 {
-	hypervisor.sched_ctx_wrapper[sched_ctx].sched_ctx = STARPU_NMAX_SCHED_CTXS;
-	hypervisor.num_ctxs--;
-}
+        int i;
+        for(i = 0; i < nsched_ctxs; i++)
+                if(sched_ctxs[i] == -1)
+                        return i;
 
-void sched_ctx_hypervisor_set_resize_interval(unsigned sched_ctx, unsigned min_nprocs, unsigned max_nprocs)
-{
-	hypervisor.sched_ctx_wrapper[sched_ctx].min_nprocs = min_nprocs;
-	hypervisor.sched_ctx_wrapper[sched_ctx].max_nprocs = max_nprocs;
+        return -1;
 }
 
-void sched_ctx_hypervisor_set_resize_granularity(unsigned sched_ctx, unsigned granularity)
+/* rearange array of sched_ctxs in order not to have {-1, -1, 5, -1, 7}    
+   and have instead {5, 7, -1, -1, -1}                                    
+   it is easier afterwards to iterate the array                           
+*/
+static void _rearange_sched_ctxs(int *sched_ctxs, int old_nsched_ctxs)
 {
-	hypervisor.resize_granularity = granularity;
+        int first_free_id = -1;
+        int i;
+        for(i = 0; i < old_nsched_ctxs; i++)
+        {
+                if(sched_ctxs[i] != -1)
+                {
+                        first_free_id = _get_first_free_sched_ctx(sched_ctxs, old_nsched_ctxs);
+                        if(first_free_id != -1)
+			{
+                                sched_ctxs[first_free_id] = sched_ctxs[i];
+				sched_ctxs[i] = -1;
+			}
+                }
+	}
 }
 
-void sched_ctx_hypervisor_set_idle_max_value(unsigned sched_ctx, int max_idle_value, int *workers, int nworkers)
+void sched_ctx_hypervisor_ignore_ctx(unsigned sched_ctx)
 {
-	int i;
-	for(i = 0; i < nworkers; i++)
-		hypervisor.sched_ctx_wrapper[sched_ctx].max_idle_time[workers[i]] = max_idle_value;
+        unsigned i;
+        for(i = 0; i < hypervisor.nsched_ctxs; i++)
+        {
+                if(hypervisor.sched_ctxs[i] == sched_ctx)
+                {
+                        hypervisor.sched_ctxs[i] = -1;
+			break;
+                }
+        }
+
+        _rearange_sched_ctxs(hypervisor.sched_ctxs, hypervisor.nsched_ctxs);
+	hypervisor.nsched_ctxs--;
+	hypervisor.sched_ctx_w[sched_ctx].sched_ctx = STARPU_NMAX_SCHED_CTXS;
+	hypervisor.policy.remove_sched_ctx(sched_ctx);
 }
 
-void sched_ctx_hypervisor_set_work_min_value(unsigned sched_ctx, int min_working_value, int *workers, int nworkers)
+void sched_ctx_hypervisor_set_data(unsigned sched_ctx, void *data)
 {
-	int i;
-	for(i = 0; i < nworkers; i++)
-		hypervisor.sched_ctx_wrapper[sched_ctx].min_working_time[workers[i]] = min_working_value;
-
+	hypervisor.sched_ctx_w[sched_ctx].data = data;
+	return;
 }
 
-void sched_ctx_hypervisor_increase_priority(unsigned sched_ctx, int priority_step, int *workers, int nworkers)
+void* sched_ctx_hypervisor_get_data(unsigned sched_ctx)
 {
-	int i;
-	for(i = 0; i < nworkers; i++)
-		hypervisor.sched_ctx_wrapper[sched_ctx].priority[workers[i]] += priority_step;
-
+	return hypervisor.sched_ctx_w[sched_ctx].data;
 }
 
-static int compute_priority_per_sched_ctx(unsigned sched_ctx)
+void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...)
 {
-	struct sched_ctx_wrapper *sched_ctx_wrapper = &hypervisor.sched_ctx_wrapper[sched_ctx];
-	int total_priority = 0;
+	va_list varg_list;
+	va_start(varg_list, sched_ctx);
 
-	struct worker_collection *workers = starpu_get_worker_collection_of_sched_ctx(sched_ctx);
-	int worker;
-	workers->init_cursor(workers);
-	while(workers->has_next(workers))
-	{
-		worker = workers->get_next(workers);
-		total_priority += sched_ctx_wrapper->priority[worker] + sched_ctx_wrapper->current_idle_time[worker];
-	}
-	workers->init_cursor(workers);
-	return total_priority;
+	hypervisor.policy.ioctl(sched_ctx, varg_list);
+	return;
 }
 
-static struct sched_ctx_wrapper* find_highest_priority_sched_ctx(unsigned sched_ctx)
-{
-	int i;
-	int highest_priority = 0;
-	int current_priority = 0;
-	struct sched_ctx_wrapper *sched_ctx_wrapper = NULL;
-	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
-	{
-		if(hypervisor.sched_ctx_wrapper[i].sched_ctx != STARPU_NMAX_SCHED_CTXS && i != sched_ctx)
-		{
-			current_priority = compute_priority_per_sched_ctx(i);
-			if (highest_priority < current_priority)
-			{
-				highest_priority = current_priority;
-				sched_ctx_wrapper = &hypervisor.sched_ctx_wrapper[i];
-			}
-		}
-	}
+static void _sched_ctx_hypervisor_resize(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int* workers_to_move, unsigned nworkers_to_move)
+{	
+	starpu_remove_workers_from_sched_ctx(workers_to_move, nworkers_to_move, sender_sched_ctx);
+	starpu_add_workers_to_sched_ctx(workers_to_move, nworkers_to_move, receiver_sched_ctx);
 	
-	return sched_ctx_wrapper;
-}
-
-static int* get_first_workers_by_priority(unsigned sched_ctx, int req_worker, int nworkers)
-{
-	struct sched_ctx_wrapper *sched_ctx_wrapper = &hypervisor.sched_ctx_wrapper[sched_ctx];
-
-	int curr_workers[nworkers];
 	int i;
-	for(i = 0; i < nworkers; i++)
-		curr_workers[i] = -1;
-
-	struct worker_collection *workers = starpu_get_worker_collection_of_sched_ctx(sched_ctx);
-	int index;
-	int worker;
-	int considered = 0;
+	for(i = 0; i < nworkers_to_move; i++)
+		hypervisor.sched_ctx_w[sender_sched_ctx].current_idle_time[workers_to_move[i]] = 0.0;
 
-	workers->init_cursor(workers);
-	for(index = 0; index < nworkers; index++)
-	{
-		while(workers->has_next(workers))
-		{
-			worker = workers->get_next(workers);
-			for(i = 0; i < index; i++)
-			{
-				if(curr_workers[i] == worker)
-				{
-					considered = 1;
-					break;
-				}
-			}
-			
-			if(!considered && (curr_workers[index] < 0 || 
-					  sched_ctx_wrapper->priority[worker] >
-					  sched_ctx_wrapper->priority[curr_workers[index]]))
-				curr_workers[index] = worker;
-		}
-	}
-	workers->deinit_cursor(workers);
-	return curr_workers;
+	return;
 }
 
-static void resize_ctxs_if_possible(unsigned sched_ctx, int worker)
+void sched_ctx_hypervisor_resize(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int* workers_to_move, unsigned nworkers_to_move)
 {
-	struct sched_ctx_wrapper *highest_priority_sched_ctx = find_highest_priority_sched_ctx(sched_ctx);
-	struct sched_ctx_wrapper *current_sched_ctx = &hypervisor.sched_ctx_wrapper[sched_ctx];
-	if(highest_priority_sched_ctx != NULL && current_sched_ctx->sched_ctx != STARPU_NMAX_SCHED_CTXS)
-	{	
-		unsigned nworkers_to_be_moved = 0;
-		
-		unsigned potential_nprocs = highest_priority_sched_ctx->current_nprocs +
-			hypervisor.resize_granularity;
-		
-		if(potential_nprocs < highest_priority_sched_ctx->max_nprocs &&
-		   potential_nprocs > current_sched_ctx->min_nprocs)
-			nworkers_to_be_moved = hypervisor.resize_granularity;
-		
+	if(hypervisor.resize)
+		_sched_ctx_hypervisor_resize(sender_sched_ctx, receiver_sched_ctx, workers_to_move, nworkers_to_move);
 
-		if(nworkers_to_be_moved > 0)
-		{
-			int *workers_to_be_moved = get_first_workers_by_priority(sched_ctx, worker, nworkers_to_be_moved);
-						
-			starpu_remove_workers_from_sched_ctx(workers_to_be_moved, nworkers_to_be_moved, sched_ctx);
-			starpu_add_workers_to_sched_ctx(workers_to_be_moved, nworkers_to_be_moved, highest_priority_sched_ctx->sched_ctx);
-			reset_ctx_wrapper_info(sched_ctx);
-		}
-	}
+	return;
 }
 
-void sched_ctx_hypervisor_update_current_idle_time(unsigned sched_ctx, int worker, double idle_time, unsigned current_nprocs)
+static void idle_time_cb(unsigned sched_ctx, int worker, double idle_time)
 {
-	struct sched_ctx_wrapper *sched_ctx_wrapper = &hypervisor.sched_ctx_wrapper[sched_ctx];
-	sched_ctx_wrapper->current_idle_time[worker] += idle_time;
-	if(hypervisor.resize && hypervisor.num_ctxs > 1 &&
-	   sched_ctx_wrapper->current_idle_time[worker] > sched_ctx_wrapper->max_idle_time[worker])
-	{
-		int ret = pthread_mutex_trylock(&resize_mutex);
-		if(ret != EBUSY)
-		{
-			resize_ctxs_if_possible(sched_ctx, worker);
-			pthread_mutex_unlock(&resize_mutex);
-		}
-	}
+	hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker] += idle_time;
+
+	if(hypervisor.nsched_ctxs > 1 && hypervisor.policy.manage_idle_time)
+		hypervisor.policy.manage_idle_time(sched_ctx, hypervisor.sched_ctxs, hypervisor.nsched_ctxs, worker, hypervisor.sched_ctx_w[sched_ctx].current_idle_time[worker]);
+		
+
+	return;
 }
 
-void sched_ctx_hypervisor_update_current_working_time(unsigned sched_ctx, int worker, double working_time, unsigned current_nprocs)
+static void working_time_cb(unsigned sched_ctx, int worker, double working_time, unsigned current_nprocs)
 {
-	hypervisor.sched_ctx_wrapper[sched_ctx].current_working_time[worker] += working_time;
-	hypervisor.sched_ctx_wrapper[sched_ctx].current_nprocs = current_nprocs;
-	resize_ctxs_if_possible(sched_ctx, worker);
+	return;
 }
 

+ 6 - 33
sched_ctx_hypervisor/src/sched_ctx_hypervisor_intern.h

@@ -1,44 +1,17 @@
-#include <common/config.h>
-
-#define MAX_IDLE_TIME 5000
-#define MIN_WORKING_TIME 500
+#include <sched_ctx_hypervisor.h>
 
 struct sched_ctx_wrapper {
-	/* the sched_ctx it wrappes*/
 	unsigned sched_ctx;
-
-	/* underneath this limit we cannot resize */
-	unsigned min_nprocs;
-
-	/* above this limit we cannot resize */
-	unsigned max_nprocs;
-	
-	/* priority for a worker to stay in this context */
-	/* the smaller the priority the faster it will be moved */
-	/* to another context */
-	int priority[STARPU_NMAXWORKERS];
-
-	/* above this limit the priority of the worker is reduced */
-	double max_idle_time[STARPU_NMAXWORKERS];
-
-	/* underneath this limit the priority of the worker is reduced */
-	double min_working_time[STARPU_NMAXWORKERS];
-
-	/* counter for idle time of each worker in a ctx */
+	void *data;
 	double current_idle_time[STARPU_NMAXWORKERS];
-
-	/* counter for working time of each worker in a ctx */
-	double current_working_time[STARPU_NMAXWORKERS];
-
-	/* number of procs of the sched_ctx*/
-	unsigned current_nprocs;
 };
 
 struct sched_ctx_hypervisor {
-	struct sched_ctx_wrapper sched_ctx_wrapper[STARPU_NMAX_SCHED_CTXS];
-	int resize_granularity;
+	struct sched_ctx_wrapper sched_ctx_w[STARPU_NMAX_SCHED_CTXS];
+	int sched_ctxs[STARPU_NMAX_SCHED_CTXS];
+	unsigned nsched_ctxs;
 	unsigned resize;
-	unsigned num_ctxs;
+	struct hypervisor_policy policy;
 };
 
 struct sched_ctx_hypervisor hypervisor;

+ 14 - 2
src/core/sched_ctx.c

@@ -165,8 +165,13 @@ static void _starpu_add_workers_to_sched_ctx(struct starpu_sched_ctx *sched_ctx,
 			workers_to_add[i] = worker;
 		}
 	}
-	if(added_workers && *n_added_workers > 0)
-		sched_ctx->sched_policy->add_workers(sched_ctx->id, added_workers, *n_added_workers);	
+
+
+	if(added_workers)
+	{
+		if(*n_added_workers > 0)
+			sched_ctx->sched_policy->add_workers(sched_ctx->id, added_workers, *n_added_workers);	
+	}
 	else
 		sched_ctx->sched_policy->add_workers(sched_ctx->id, workers_to_add, nworkers_to_add);		
 	return;
@@ -623,3 +628,10 @@ pthread_mutex_t* starpu_get_changing_ctx_mutex(unsigned sched_ctx_id)
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 	return &sched_ctx->changing_ctx_mutex;
 }
+
+unsigned starpu_get_nworkers_of_sched_ctx(unsigned sched_ctx_id)
+{
+	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
+	return sched_ctx->workers->nworkers;
+
+}

+ 6 - 6
src/core/sched_policy.c

@@ -249,7 +249,7 @@ static int _starpu_push_task_on_specific_worker(struct starpu_task *task, int wo
 	{
 		sched_ctx = worker->sched_ctx[i];
 		if (sched_ctx != NULL && sched_ctx->sched_policy != NULL && sched_ctx->sched_policy->push_task_notify)
-			sched_ctx->sched_policy->push_task_notify(task, workerid, sched_ctx->id);
+			sched_ctx->sched_policy->push_task_notify(task, workerid);
 	}
 	
 	if (is_basic_worker)
@@ -313,7 +313,7 @@ int _starpu_push_task(starpu_job_t j, unsigned job_is_already_locked)
 		struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
 		STARPU_ASSERT(sched_ctx->sched_policy->push_task);
 
-		ret = sched_ctx->sched_policy->push_task(task, sched_ctx->id);
+		ret = sched_ctx->sched_policy->push_task(task);
 	}
 
 	_starpu_profiling_set_task_push_end_time(task);
@@ -358,7 +358,7 @@ struct starpu_task *_starpu_pop_task(struct starpu_worker_s *worker)
 					PTHREAD_MUTEX_LOCK(sched_ctx_mutex);
 					if (sched_ctx->sched_policy->pop_task)
 					{
-						task = sched_ctx->sched_policy->pop_task(sched_ctx->id);
+						task = sched_ctx->sched_policy->pop_task();
 						PTHREAD_MUTEX_UNLOCK(sched_ctx_mutex);
 						break;
 					}
@@ -401,7 +401,7 @@ struct starpu_task *_starpu_pop_task(struct starpu_worker_s *worker)
 			{
 				if(sched_ctx != NULL && sched_ctx->criteria != NULL)
 				{
-					sched_ctx->criteria->update_current_idle_time(sched_ctx->id, worker->workerid, 1.0, sched_ctx->workers->nworkers);
+					sched_ctx->criteria->idle_time_cb(sched_ctx->id, worker->workerid, 1.0);
 				}
 			}
 		}
@@ -416,14 +416,14 @@ struct starpu_task *_starpu_pop_every_task(struct starpu_sched_ctx *sched_ctx)
 	STARPU_ASSERT(sched_ctx->sched_policy->pop_every_task);
 
 	/* TODO set profiling info */
-	return sched_ctx->sched_policy->pop_every_task(sched_ctx->id);
+	return sched_ctx->sched_policy->pop_every_task();
 }
 
 void _starpu_sched_post_exec_hook(struct starpu_task *task)
 {
 	struct starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
 	if (sched_ctx->sched_policy->post_exec_hook)
-		sched_ctx->sched_policy->post_exec_hook(task, sched_ctx->id);
+		sched_ctx->sched_policy->post_exec_hook(task);
 }
 
 void _starpu_wait_on_sched_event(void)

+ 10 - 5
src/sched_policies/heft.c

@@ -125,8 +125,9 @@ static void heft_init(unsigned sched_ctx_id)
 	starputop_register_parameter_float("HEFT_IDLE_POWER", &hd->idle_power, idle_power_minimum,idle_power_maximum,param_modified);
 }
 
-static void heft_post_exec_hook(struct starpu_task *task, unsigned sched_ctx_id)
+static void heft_post_exec_hook(struct starpu_task *task)
 {
+	unsigned sched_ctx_id = task->sched_ctx;
 	int workerid = starpu_worker_get_id();
 	STARPU_ASSERT(workerid >= 0);
 
@@ -145,8 +146,9 @@ static void heft_post_exec_hook(struct starpu_task *task, unsigned sched_ctx_id)
 	PTHREAD_MUTEX_UNLOCK(sched_mutex);
 }
 
-static void heft_push_task_notify(struct starpu_task *task, int workerid, unsigned sched_ctx_id)
+static void heft_push_task_notify(struct starpu_task *task, int workerid)
 {
+	unsigned sched_ctx_id = task->sched_ctx;
 	/* Compute the expected penality */
 	enum starpu_perf_archtype perf_arch = starpu_worker_get_perf_archtype(workerid);
 
@@ -344,7 +346,8 @@ static int _heft_push_task(struct starpu_task *task, unsigned prio, unsigned sch
 
 	struct starpu_task_bundle *bundle = task->bundle;
 
-	workers->init_cursor(workers);
+	if(workers->init_cursor)
+		workers->init_cursor(workers);
 
 	compute_all_performance_predictions(task, local_task_length, exp_end,
 					    &max_exp_end, &best_exp_end,
@@ -427,14 +430,16 @@ static int _heft_push_task(struct starpu_task *task, unsigned prio, unsigned sch
 		model_best = local_task_length[best_id_ctx];
 	}
 
-	workers->deinit_cursor(workers);
+	if(workers->init_cursor)
+		workers->deinit_cursor(workers);
 
 	_starpu_increment_nsubmitted_tasks_of_worker(best);
 	return push_task_on_best_worker(task, best, model_best, prio, sched_ctx_id);
 }
 
-static int heft_push_task(struct starpu_task *task, unsigned sched_ctx_id)
+static int heft_push_task(struct starpu_task *task)
 {
+	unsigned sched_ctx_id = task->sched_ctx;;
 	pthread_mutex_t *changing_ctx_mutex = starpu_get_changing_ctx_mutex(sched_ctx_id);
 	int ret_val = -1;
 	if (task->priority > 0)

+ 5 - 2
src/worker_collection/worker_list.c

@@ -89,13 +89,15 @@ static int list_remove(struct worker_collection *workers, int worker)
 {
 	int *workerids = (int *)workers->workerids;
 	unsigned nworkers = workers->nworkers;
-
+	
+	int found_worker = -1;
 	unsigned i;
 	for(i = 0; i < nworkers; i++)
 	{
 		if(workerids[i] == worker)
 		{
 			workerids[i] = -1;
+			found_worker = worker;
 			break;
 		}
 	}
@@ -103,7 +105,7 @@ static int list_remove(struct worker_collection *workers, int worker)
 	_rearange_workerids(workerids, nworkers);
 	workers->nworkers--;
 
-	return;
+	return found_worker;
 }
 
 static void _init_workers(int *workerids)
@@ -140,6 +142,7 @@ static void list_init_cursor(struct worker_collection *workers)
 static void list_deinit_cursor(struct worker_collection *workers)
 {
 	int *cursor = (int*)pthread_getspecific(workers->cursor_key);
+	*cursor = 0;
 	free(cursor);
 }