Procházet zdrojové kódy

Fix a bug that caused _starpu_register_model() to be called too many times.

Cyril Roelandt před 13 roky
rodič
revize
d0dd081e85

+ 21 - 2
src/core/perfmodel/perfmodel.c

@@ -127,11 +127,31 @@ static double common_task_expected_perf(struct starpu_perfmodel_t *model, enum s
 	return -1.0;
 }
 
+extern pthread_rwlock_t registered_models_rwlock;
+
 void _starpu_load_perfmodel(struct starpu_perfmodel_t *model)
 {
-	if (!model || model->is_loaded)
+	if (!model)
 		return;
 
+	/* If the model has already been loaded, there is nothing to do */
+	PTHREAD_RWLOCK_RDLOCK(&registered_models_rwlock);
+	if (model->is_loaded) {
+		PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
+		return;
+	}
+	PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
+
+	/* We have to make sure the model has not been loaded since the
+         * last time we took the lock */
+	PTHREAD_RWLOCK_WRLOCK(&registered_models_rwlock);
+	if (model->is_loaded) {
+		PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
+		return;
+	}
+	_starpu_register_model(model);
+	PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
+
 	switch (model->type) {
 		case STARPU_PER_ARCH:
 		case STARPU_COMMON:
@@ -150,7 +170,6 @@ void _starpu_load_perfmodel(struct starpu_perfmodel_t *model)
 			STARPU_ABORT();
 	}
 
-	_starpu_register_model(model);
 	model->is_loaded = 1;
 }
 

+ 1 - 7
src/core/perfmodel/perfmodel_history.c

@@ -34,7 +34,7 @@
 #include <windows.h>
 #endif
 		
-static pthread_rwlock_t registered_models_rwlock;
+pthread_rwlock_t registered_models_rwlock;
 static struct starpu_model_list_t *registered_models = NULL;
 
 /*
@@ -658,12 +658,6 @@ void _starpu_load_history_based_model(struct starpu_perfmodel_t *model, unsigned
 	/* make sure the performance model directory exists (or create it) */
 	_starpu_create_sampling_directory_if_needed();
 
-	/*
-	 * We need to keep track of all the model that were opened so that we can 
-	 * possibly update them at runtime termination ...
-	 */
-	_starpu_register_model(model);
-
 	char path[256];
 	get_model_path(model, path, 256);