瀏覽代碼

Free performance models data

Samuel Thibault 13 年之前
父節點
當前提交
7ac870d6fc
共有 3 個文件被更改,包括 70 次插入6 次删除
  1. 27 3
      src/common/htable32.c
  2. 4 1
      src/common/htable32.h
  3. 39 2
      src/core/perfmodel/perfmodel_history.c

+ 27 - 3
src/common/htable32.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -24,7 +24,7 @@
 void *_starpu_htbl_search_32(struct starpu_htbl32_node *htbl, uint32_t key)
 {
 	unsigned currentbit;
-	unsigned keysize = 32;
+	unsigned keysize = sizeof(uint32_t)*8;
 
 	struct starpu_htbl32_node *current_htbl = htbl;
 
@@ -62,7 +62,7 @@ void *_starpu_htbl_search_32(struct starpu_htbl32_node *htbl, uint32_t key)
 void *_starpu_htbl_insert_32(struct starpu_htbl32_node **htbl, uint32_t key, void *entry)
 {
 	unsigned currentbit;
-	unsigned keysize = 32;
+	unsigned keysize = sizeof(uint32_t)*8;
 
 	struct starpu_htbl32_node **current_htbl_ptr = htbl;
 
@@ -102,3 +102,27 @@ void *_starpu_htbl_insert_32(struct starpu_htbl32_node **htbl, uint32_t key, voi
 
 	return old_entry;
 }
+
+static void _starpu_htbl_destroy_32_bit(struct starpu_htbl32_node *htbl, unsigned bit, void (*remove)(void*))
+{
+	unsigned keysize = sizeof(uint32_t)*8;
+	int i;
+
+	if (!htbl)
+		return;
+
+	if (bit >= keysize) {
+		/* entry, delete it */
+		if (remove)
+			remove(htbl);
+		return;
+	}
+
+	for (i = 0; i < 1<<_STARPU_HTBL32_NODE_SIZE; i++) {
+		_starpu_htbl_destroy_32_bit(htbl->children[i], bit+_STARPU_HTBL32_NODE_SIZE, remove);
+	}
+}
+void _starpu_htbl_destroy_32(struct starpu_htbl32_node *htbl, void (*remove)(void*))
+{
+	_starpu_htbl_destroy_32_bit(htbl, 0, remove);
+}

+ 4 - 1
src/common/htable32.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -41,4 +41,7 @@ void *_starpu_htbl_search_32(struct starpu_htbl32_node *htbl, uint32_t key);
  * otherwise. */
 void *_starpu_htbl_insert_32(struct starpu_htbl32_node **htbl, uint32_t key, void *entry);
 
+/* Delete the content of the table, `remove' being called on each element */
+void _starpu_htbl_destroy_32(struct starpu_htbl32_node *htbl, void (*remove)(void*));
+
 #endif // __GENERIC_HTABLE_H__

+ 39 - 2
src/core/perfmodel/perfmodel_history.c

@@ -662,8 +662,6 @@ static void _starpu_dump_registered_models(void)
 	{
 		save_history_based_model(node->model);
 		node = node->next;
-
-		/* XXX free node */
 	}
 
 	_STARPU_PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
@@ -681,6 +679,45 @@ void _starpu_deinitialize_registered_performance_models(void)
 	if (_starpu_get_calibrate_flag())
 		_starpu_dump_registered_models();
 
+	_STARPU_PTHREAD_RWLOCK_WRLOCK(&registered_models_rwlock);
+
+	struct starpu_model_list *node, *pnode;
+	node = registered_models;
+
+	_STARPU_DEBUG("FREE MODELS !\n");
+
+	while (node)
+	{
+		struct starpu_perfmodel *model = node->model;
+		unsigned arch;
+		unsigned nimpl;
+
+		_STARPU_PTHREAD_RWLOCK_WRLOCK(&model->model_rwlock);
+		for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
+		{
+			for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
+			{
+				struct starpu_per_arch_perfmodel *archmodel = &model->per_arch[arch][nimpl];
+				struct starpu_history_list *list, *plist;
+				_starpu_htbl_destroy_32(archmodel->history, NULL);
+				list = archmodel->list;
+				while (list) {
+					free(list->entry);
+					plist = list;
+					list = list->next;
+					free(plist);
+				}
+			}
+		}
+
+		model->is_loaded = 0;
+		_STARPU_PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);
+
+		pnode = node;
+		node = node->next;
+		free(pnode);
+	}
+
 	_STARPU_PTHREAD_RWLOCK_DESTROY(&registered_models_rwlock);
 }