浏览代码

hypervisor: Use <common/uthash.h> for the `resize_requests' hash table.

Ludovic Courtès 12 年之前
父节点
当前提交
2f47e1f77d

+ 9 - 1
sched_ctx_hypervisor/include/sched_ctx_hypervisor.h

@@ -92,6 +92,10 @@ struct sched_ctx_wrapper {
 	pthread_mutex_t mutex;
 };
 
+/* Forward declaration of an internal data structure
+ * FIXME: Remove when no longer exposed.  */
+struct resize_request_entry;
+
 struct hypervisor_policy {
 	const char* name;
 	unsigned custom;
@@ -100,7 +104,11 @@ struct hypervisor_policy {
 	void (*handle_pushed_task)(unsigned sched_ctx, int worker);
 	void (*handle_poped_task)(unsigned sched_ctx, int worker);
 	void (*handle_idle_end)(unsigned sched_ctx, int worker);
-//	void (*handle_post_exec_hook)(unsigned sched_ctx, struct starpu_htbl32_node* resize_requests, int task_tag);
+
+	/* FIXME: The 'resize_requests' hash table is an implementation
+	 * detail that should be invisible to policies.  */
+	void (*handle_post_exec_hook)(unsigned sched_ctx, struct resize_request_entry* resize_requests, int task_tag);
+
 	void (*handle_submitted_job)(struct starpu_task *task, unsigned footprint);
 };
 

+ 14 - 10
sched_ctx_hypervisor/src/hypervisor_policies/app_driven_policy.c

@@ -16,16 +16,20 @@
 
 #include "policy_tools.h"
 
-/* void app_driven_handle_post_exec_hook(unsigned sched_ctx, struct starpu_htbl32_node_s* resize_requests, int task_tag) */
-/* { */
-/* 	void* sched_ctx_pt =  _starpu_htbl_search_32(resize_requests, (uint32_t)task_tag); */
-/* 	if(sched_ctx_pt && sched_ctx_pt != resize_requests) */
-/* 	{ */
-/* 		_resize_to_unknown_receiver(sched_ctx, 1); */
-/* 		_starpu_htbl_insert_32(&resize_requests, (uint32_t)task_tag, NULL); */
-/* 	} */
+void app_driven_handle_post_exec_hook(unsigned sched_ctx, struct resize_request_entry* resize_requests, int task_tag)
+{
+	struct resize_request_entry *entry;
 
-/* } */
+	/* Check whether 'task_tag' is in the 'resize_requests' set.  */
+	HASH_FIND_INT(resize_requests, task_tag, &entry);
+	if(entry != NULL)
+	{
+		_resize_to_unknown_receiver(sched_ctx, 1);
+		HASH_DEL(resize_requests, entry);
+		free(entry);
+	}
+
+}
 
 struct hypervisor_policy app_driven_policy = {
 	.size_ctxs = NULL,
@@ -33,7 +37,7 @@ struct hypervisor_policy app_driven_policy = {
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = NULL,
 	.handle_idle_end = NULL,
-//	.handle_post_exec_hook = app_driven_handle_post_exec_hook,
+	.handle_post_exec_hook = app_driven_handle_post_exec_hook,
 	.handle_submitted_job = NULL,
 	.custom = 0,
 	.name = "app_driven"

+ 1 - 1
sched_ctx_hypervisor/src/hypervisor_policies/gflops_rate_policy.c

@@ -300,7 +300,7 @@ struct hypervisor_policy gflops_rate_policy = {
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = NULL,
 	.handle_idle_end = NULL,
-//	.handle_post_exec_hook = NULL,
+	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.custom = 0,
 	.name = "gflops_rate"

+ 1 - 1
sched_ctx_hypervisor/src/hypervisor_policies/idle_policy.c

@@ -47,7 +47,7 @@ struct hypervisor_policy idle_policy = {
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = idle_handle_idle_cycle,
 	.handle_idle_end = NULL,
-//	.handle_post_exec_hook = NULL,
+	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.custom = 0,
 	.name = "idle"

+ 1 - 1
sched_ctx_hypervisor/src/hypervisor_policies/lp2_policy.c

@@ -586,7 +586,7 @@ struct hypervisor_policy lp2_policy = {
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = NULL,
 	.handle_idle_end = NULL,
-//	.handle_post_exec_hook = NULL,
+	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = lp2_handle_submitted_job,
 	.custom = 0,
 	.name = "lp2"

+ 1 - 1
sched_ctx_hypervisor/src/hypervisor_policies/lp_policy.c

@@ -106,7 +106,7 @@ struct hypervisor_policy lp_policy = {
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = NULL,
 	.handle_idle_end = NULL,
-//	.handle_post_exec_hook = NULL,
+	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.custom = 0,
 	.name = "lp"

+ 23 - 7
sched_ctx_hypervisor/src/sched_ctx_hypervisor.c

@@ -15,6 +15,7 @@
  */
 
 #include <sched_ctx_hypervisor_intern.h>
+#include <common/uthash.h>
 
 unsigned imposed_resize = 0;
 struct starpu_performance_counters* perf_counters = NULL;
@@ -34,6 +35,7 @@ extern struct hypervisor_policy lp_policy;
 extern struct hypervisor_policy lp2_policy;
 #endif
 
+
 static struct hypervisor_policy *predefined_policies[] = {
         &idle_policy,
 	&app_driven_policy,
@@ -60,7 +62,7 @@ static void _load_hypervisor_policy(struct hypervisor_policy *policy)
 	hypervisor.policy.handle_pushed_task = policy->handle_pushed_task;
 	hypervisor.policy.handle_idle_cycle = policy->handle_idle_cycle;
 	hypervisor.policy.handle_idle_end = policy->handle_idle_end;
-//	hypervisor.policy.handle_post_exec_hook = policy->handle_post_exec_hook;
+	hypervisor.policy.handle_post_exec_hook = policy->handle_post_exec_hook;
 	hypervisor.policy.handle_submitted_job = policy->handle_submitted_job;
 }
 
@@ -224,7 +226,7 @@ void sched_ctx_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
 {	
 	pthread_mutex_lock(&act_hypervisor_mutex);
 /* 	hypervisor.configurations[sched_ctx] = (struct starpu_htbl32_node*)malloc(sizeof(struct starpu_htbl32_node)); */
-/* 	hypervisor.resize_requests[sched_ctx] = (struct starpu_htbl32_node*)malloc(sizeof(struct starpu_htbl32_node)); */
+	hypervisor.resize_requests[sched_ctx] = NULL;
 	pthread_mutex_init(&hypervisor.conf_mut[sched_ctx], NULL);
 	pthread_mutex_init(&hypervisor.resize_mut[sched_ctx], NULL);
 
@@ -624,10 +626,20 @@ static unsigned _ack_resize_completed(unsigned sched_ctx, int worker)
 	return 0;
 }
 
+/* Enqueue a resize request for 'sched_ctx', to be executed when the
+ * 'task_tag' tasks of 'sched_ctx' complete.  */
 void sched_ctx_hypervisor_resize(unsigned sched_ctx, int task_tag)
 {
+	struct resize_request_entry *entry;
+
+	entry = malloc(sizeof *entry);
+	STARPU_ASSERT(entry != NULL);
+
+	entry->sched_ctx = sched_ctx;
+	entry->task_tag = task_tag;
+
 	pthread_mutex_lock(&hypervisor.resize_mut[sched_ctx]);
-//	_starpu_htbl_insert_32(&hypervisor.resize_requests[sched_ctx], (uint32_t)task_tag, (void*)sched_ctx);	
+	HASH_ADD_INT(hypervisor.resize_requests[sched_ctx], task_tag, entry);
 	pthread_mutex_unlock(&hypervisor.resize_mut[sched_ctx]);
 }
 
@@ -721,11 +733,15 @@ static void notify_post_exec_hook(unsigned sched_ctx, int task_tag)
 		
 	if(hypervisor.resize[sched_ctx])
 	{
+		struct resize_request_entry* resize_requests;
+
 		pthread_mutex_lock(&hypervisor.resize_mut[sched_ctx]);
-/* 		struct starpu_htbl32_node* resize_requests = hypervisor.resize_requests[sched_ctx]; */
-		
-/* 		if(hypervisor.policy.handle_post_exec_hook) */
-/* 			hypervisor.policy.handle_post_exec_hook(sched_ctx, resize_requests, task_tag); */
+		resize_requests = hypervisor.resize_requests[sched_ctx];
+
+		/* TODO: Move the lookup of 'task_tag' in 'resize_requests'
+		 * here, and remove + free the entry here.  */
+		if(hypervisor.policy.handle_post_exec_hook)
+			hypervisor.policy.handle_post_exec_hook(sched_ctx, resize_requests, task_tag);
 		pthread_mutex_unlock(&hypervisor.resize_mut[sched_ctx]);
 	}
 	return;

+ 19 - 5
sched_ctx_hypervisor/src/sched_ctx_hypervisor_intern.h

@@ -16,10 +16,6 @@
 
 #include <sched_ctx_hypervisor.h>
 #include <common/uthash.h>
-
-#define HASH_ADD_UINT32_T(head,field,add) HASH_ADD(hh,head,field,sizeof(uint32_t),add)
-#define HASH_FIND_UINT32_T(head,find,out) HASH_FIND(hh,head,find,sizeof(uint32_t),out)
-
 struct size_request {
 	int *workers;
 	int nworkers;
@@ -27,6 +23,21 @@ struct size_request {
 	int nsched_ctxs;
 };
 
+
+/* Entry in the resize request hash table.  */
+struct resize_request_entry {
+	/* Key: the tag of tasks concerned by this resize request.  */
+	uint32_t task_tag;
+
+	/* Value: identifier of the scheduling context needing to be resized.
+	 * The value doesn't matter since the hash table is used only to test
+	 * membership of a task tag.  */
+	unsigned sched_ctx;
+
+	/* Bookkeeping.  */
+	UT_hash_handle hh;
+};
+
 struct sched_ctx_hypervisor {
 	struct sched_ctx_wrapper sched_ctx_w[STARPU_NMAX_SCHED_CTXS];
 	int sched_ctxs[STARPU_NMAX_SCHED_CTXS];
@@ -35,7 +46,10 @@ struct sched_ctx_hypervisor {
 	int min_tasks;
 	struct hypervisor_policy policy;
 	struct starpu_htbl32_node *configurations[STARPU_NMAX_SCHED_CTXS];
-	struct starpu_htbl32_node *resize_requests[STARPU_NMAX_SCHED_CTXS];
+
+	/* Set of pending resize requests for any context/tag pair.  */
+	struct resize_request_entry *resize_requests[STARPU_NMAX_SCHED_CTXS];
+
 	pthread_mutex_t conf_mut[STARPU_NMAX_SCHED_CTXS];
 	pthread_mutex_t resize_mut[STARPU_NMAX_SCHED_CTXS];
 	struct size_request *sr;