瀏覽代碼

Use RW-locks instead of a lock to protect the history-based models. This has 2
advantages: this reduces contention in case everyone just consults the table,
and pthread_rwlock_t are available on MAC OS X (while pthread_spin_t are not).

Cédric Augonnet 16 年之前
父節點
當前提交
c071c55eb5
共有 2 個文件被更改,包括 10 次插入11 次删除
  1. 1 1
      include/starpu-perfmodel.h
  2. 9 10
      src/core/perfmodel/perfmodel_history.c

+ 1 - 1
include/starpu-perfmodel.h

@@ -93,7 +93,7 @@ struct starpu_perfmodel_t {
 	} is_loaded;
 	unsigned benchmarking;
 
-	pthread_spinlock_t model_mutex;
+	pthread_rwlock_t model_rwlock;
 };
 
 /* This function is intended to be used by external tools that should read the

+ 9 - 10
src/core/perfmodel/perfmodel_history.c

@@ -316,9 +316,8 @@ void load_history_based_model(struct starpu_perfmodel_t *model, unsigned scan_hi
 		return;
 	}
 	
-	//init_mutex(&model->model_mutex);
-	pthread_spin_init(&model->model_mutex, 0);
-	pthread_spin_lock(&model->model_mutex);
+	pthread_rwlock_init(&model->model_rwlock, NULL);
+	pthread_rwlock_wrlock(&model->model_rwlock);
 
 		/* make sure the performance model directory exists (or create it) */
 		if (!directory_existence_was_tested)
@@ -371,7 +370,7 @@ void load_history_based_model(struct starpu_perfmodel_t *model, unsigned scan_hi
 	
 		model->is_loaded = STARPU_PERFMODEL_LOADED;
 
-	pthread_spin_unlock(&model->model_mutex);
+	pthread_rwlock_unlock(&model->model_rwlock);
 }
 
 /* This function is intended to be used by external tools that should read the
@@ -466,9 +465,9 @@ double history_based_job_expected_length(struct starpu_perfmodel_t *model, enum
 	if (!history)
 		return -1.0;
 
-	pthread_spin_lock(&model->model_mutex);
+	pthread_rwlock_rdlock(&model->model_rwlock);
 	entry = htbl_search_32(history, key);
-	pthread_spin_unlock(&model->model_mutex);
+	pthread_rwlock_unlock(&model->model_rwlock);
 
 	exp = entry?entry->mean:-1.0;
 
@@ -500,7 +499,7 @@ void update_perfmodel_history(job_t j, enum starpu_perf_archtype arch, unsigned
 			reg_model = &per_arch_model->regression;
 			list = &per_arch_model->list;
 
-			pthread_spin_lock(&model->model_mutex);
+			pthread_rwlock_wrlock(&model->model_rwlock);
 	
 				entry = htbl_search_32(history, key);
 	
@@ -555,13 +554,13 @@ void update_perfmodel_history(job_t j, enum starpu_perf_archtype arch, unsigned
 			reg_model->beta = num/denom;
 			reg_model->alpha = expl((reg_model->sumlny - reg_model->beta*reg_model->sumlnx)/n);
 			
-			pthread_spin_unlock(&model->model_mutex);
+			pthread_rwlock_unlock(&model->model_rwlock);
 		}
 
 #ifdef MODEL_DEBUG
 		FILE * debug_file = per_arch_model->debug_file;
 
-		pthread_spin_lock(&model->model_mutex);
+		pthread_rwlock_wrlock(&model->model_rwlock);
 
 		STARPU_ASSERT(j->footprint_is_computed);
 
@@ -580,7 +579,7 @@ void update_perfmodel_history(job_t j, enum starpu_perf_archtype arch, unsigned
 		fprintf(debug_file, "\n");	
 
 
-		pthread_spin_unlock(&model->model_mutex);
+		pthread_rwlock_unlock(&model->model_rwlock);
 #endif
 	}
 }