Explorar el Código

src/core/perfmodel: store at the beginning of the application the names for the different perfmodel directories, there is no need to recalcute them at each function call

Nathalie Furmento hace 10 años
padre
commit
36fe1cbc6e

+ 39 - 26
src/core/perfmodel/perfmodel.c

@@ -427,42 +427,54 @@ double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundl
 }
 
 static int directory_existence_was_tested = 0;
+static char *_perf_model_dir = NULL;
+static char *_perf_model_dir_codelet = NULL;
+static char *_perf_model_dir_bus = NULL;
+static char *_perf_model_dir_debug = NULL;
+#define _PERF_MODEL_DIR_MAXLEN 256
 
-void _starpu_get_perf_model_dir(char *path, size_t maxlen)
+void _starpu_set_perf_model_dirs()
 {
+	_perf_model_dir = malloc(_PERF_MODEL_DIR_MAXLEN);
+	_perf_model_dir_codelet = malloc(_PERF_MODEL_DIR_MAXLEN);
+	_perf_model_dir_bus = malloc(_PERF_MODEL_DIR_MAXLEN);
+	_perf_model_dir_debug = malloc(_PERF_MODEL_DIR_MAXLEN);
+
 #ifdef STARPU_PERF_MODEL_DIR
 	/* use the directory specified at configure time */
-	snprintf(path, maxlen, "%s", STARPU_PERF_MODEL_DIR);
+	snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s", STARPU_PERF_MODEL_DIR);
 #else
-	snprintf(path, maxlen, "%s/.starpu/sampling/", _starpu_get_home_path());
+	snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s/.starpu/sampling/", _starpu_get_home_path());
 #endif
+
+	snprintf(_perf_model_dir_codelet, _PERF_MODEL_DIR_MAXLEN, "%s/codelets/%d/", _perf_model_dir, _STARPU_PERFMODEL_VERSION);
+	snprintf(_perf_model_dir_bus, _PERF_MODEL_DIR_MAXLEN, "%s/bus/", _perf_model_dir);
+	snprintf(_perf_model_dir_debug, _PERF_MODEL_DIR_MAXLEN, "%s/debug/", _perf_model_dir);
 }
 
-void _starpu_get_perf_model_dir_codelets(char *path, size_t maxlen)
+char *_starpu_get_perf_model_dir_codelet()
 {
-	char perf_model_path[256];
-	_starpu_get_perf_model_dir(perf_model_path, maxlen);
-	snprintf(path, maxlen, "%s/codelets/%d/", perf_model_path, _STARPU_PERFMODEL_VERSION);
+	_starpu_create_sampling_directory_if_needed();
+	return _perf_model_dir_codelet;
 }
 
-void _starpu_get_perf_model_dir_bus(char *path, size_t maxlen)
+char *_starpu_get_perf_model_dir_bus()
 {
-	_starpu_get_perf_model_dir(path, maxlen);
-	strncat(path, "/bus/", maxlen);
+	_starpu_create_sampling_directory_if_needed();
+	return _perf_model_dir_bus;
 }
 
-void _starpu_get_perf_model_dir_debug(char *path, size_t maxlen)
+char *_starpu_get_perf_model_dir_debug()
 {
-	_starpu_get_perf_model_dir(path, maxlen);
-	strncat(path, "/debug/", maxlen);
+	_starpu_create_sampling_directory_if_needed();
+	return _perf_model_dir_debug;
 }
 
 void _starpu_create_sampling_directory_if_needed(void)
 {
 	if (!directory_existence_was_tested)
 	{
-		char perf_model_dir[256];
-		_starpu_get_perf_model_dir(perf_model_dir, 256);
+		_starpu_set_perf_model_dirs();
 
 		/* The performance of the codelets are stored in
 		 * $STARPU_PERF_MODEL_DIR/codelets/ while those of the bus are stored in
@@ -472,24 +484,25 @@ void _starpu_create_sampling_directory_if_needed(void)
 		   may not be safe: it is possible that the permission are
 		   changed in between. Instead, we create it and check if
 		   it already existed before */
-		_starpu_mkpath_and_check(perf_model_dir, S_IRWXU);
-
+		_starpu_mkpath_and_check(_perf_model_dir, S_IRWXU);
 
 		/* Per-task performance models */
-		char perf_model_dir_codelets[256];
-		_starpu_get_perf_model_dir_codelets(perf_model_dir_codelets, 256);
-		_starpu_mkpath_and_check(perf_model_dir_codelets, S_IRWXU);
+		_starpu_mkpath_and_check(_perf_model_dir_codelet, S_IRWXU);
 
 		/* Performance of the memory subsystem */
-		char perf_model_dir_bus[256];
-		_starpu_get_perf_model_dir_bus(perf_model_dir_bus, 256);
-		_starpu_mkpath_and_check(perf_model_dir_bus, S_IRWXU);
+		_starpu_mkpath_and_check(_perf_model_dir_bus, S_IRWXU);
 
 		/* Performance debug measurements */
-		char perf_model_dir_debug[256];
-		_starpu_get_perf_model_dir_debug(perf_model_dir_debug, 256);
-		_starpu_mkpath_and_check(perf_model_dir_debug, S_IRWXU);
+		_starpu_mkpath_and_check(_perf_model_dir_debug, S_IRWXU);
 
 		directory_existence_was_tested = 1;
 	}
 }
+
+void _starpu_free_sampling_directory(void)
+{
+	free(_perf_model_dir);
+	free(_perf_model_dir_codelet);
+	free(_perf_model_dir_bus);
+	directory_existence_was_tested = 0;
+}

+ 4 - 4
src/core/perfmodel/perfmodel.h

@@ -63,10 +63,9 @@ struct starpu_data_descr;
 struct _starpu_job;
 struct starpu_perfmodel_arch;
 
-void _starpu_get_perf_model_dir(char *path, size_t maxlen);
-void _starpu_get_perf_model_dir_codelets(char *path, size_t maxlen);
-void _starpu_get_perf_model_dir_bus(char *path, size_t maxlen);
-void _starpu_get_perf_model_dir_debug(char *path, size_t maxlen);
+char *_starpu_get_perf_model_dir_codelet();
+char *_starpu_get_perf_model_dir_bus();
+char *_starpu_get_perf_model_dir_debug();
 
 double _starpu_history_based_job_expected_perf(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, struct _starpu_job *j, unsigned nimpl);
 void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned scan_history);
@@ -84,6 +83,7 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 int _starpu_perfmodel_create_comb_if_needed(struct starpu_perfmodel_arch* arch);
 
 void _starpu_create_sampling_directory_if_needed(void);
+void _starpu_free_sampling_directory(void);
 
 void _starpu_load_bus_performance_files(void);
 

+ 3 - 3
src/core/perfmodel/perfmodel_bus.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2014  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014  Centre National de la Recherche Scientifique
  * Copyright (C) 2013 Corentin Salingue
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -752,9 +752,9 @@ static void benchmark_all_gpu_devices(void)
 
 static void get_bus_path(const char *type, char *path, size_t maxlen)
 {
-	_starpu_get_perf_model_dir_bus(path, maxlen);
-
 	char hostname[65];
+
+	snprintf(path, maxlen, "%s", _starpu_get_perf_model_dir_bus());
 	_starpu_gethostname(hostname, sizeof(hostname));
 	strncat(path, hostname, maxlen);
 	strncat(path, ".", maxlen);

+ 6 - 12
src/core/perfmodel/perfmodel_history.c

@@ -706,8 +706,7 @@ static void get_model_debug_path(struct starpu_perfmodel *model, const char *arc
 {
 	STARPU_ASSERT(path);
 
-	_starpu_get_perf_model_dir_debug(path, maxlen);
-	strncat(path, model->symbol, maxlen);
+	snprintf(path, maxlen, "%s/%s", _starpu_get_perf_model_dir_debug(), model->symbol);
 
 	char hostname[65];
 	_starpu_gethostname(hostname, sizeof(hostname));
@@ -720,8 +719,7 @@ static void get_model_debug_path(struct starpu_perfmodel *model, const char *arc
 
 static void get_model_path(struct starpu_perfmodel *model, char *path, size_t maxlen)
 {
-	_starpu_get_perf_model_dir_codelets(path, maxlen);
-	strncat(path, model->symbol, maxlen);
+	snprintf(path, maxlen, "%s/%s", _starpu_get_perf_model_dir_codelet(), model->symbol);
 
 	const char *dot = strrchr(model->symbol, '.');
 	if (dot == NULL)
@@ -903,6 +901,7 @@ void _starpu_deinitialize_registered_performance_models(void)
 	STARPU_PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
 	STARPU_PTHREAD_RWLOCK_DESTROY(&registered_models_rwlock);
 	_free_arch_combs();
+	_starpu_free_sampling_directory();
 }
 
 /* We first try to grab the global lock in read mode to check whether the model
@@ -967,9 +966,7 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 
 void starpu_perfmodel_directory(FILE *output)
 {
-	char perf_model_dir[256];
-	_starpu_get_perf_model_dir_codelets(perf_model_dir, 256);
-	fprintf(output, "directory: <%s>\n", perf_model_dir);
+	fprintf(output, "directory: <%s>\n", _starpu_get_perf_model_dir_codelet());
 }
 
 /* This function is intended to be used by external tools that should read
@@ -977,14 +974,11 @@ void starpu_perfmodel_directory(FILE *output)
 int starpu_perfmodel_list(FILE *output)
 {
 #if !defined(_WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
-        char path[256];
+        char *path;
         DIR *dp;
         struct dirent *ep;
 
-	char perf_model_dir_codelets[256];
-	_starpu_get_perf_model_dir_codelets(perf_model_dir_codelets, 256);
-
-        strncpy(path, perf_model_dir_codelets, 256);
+	path = _starpu_get_perf_model_dir_codelet();
         dp = opendir(path);
         if (dp != NULL)
 	{