Forráskód Böngészése

port r19135 from 1.2: Ignore ENOLCK errors (but emit a warning for the user)

Samuel Thibault 8 éve
szülő
commit
64866677c6

+ 23 - 0
src/common/utils.c

@@ -278,6 +278,17 @@ int _starpu_frdlock(FILE *file)
 	};
 	ret = fcntl(fileno(file), F_SETLKW, &lock);
 #endif
+#ifdef ENOLCK
+	if (ret != 0 && errno == ENOLCK)
+	{
+		static int warn;
+		if (!warn) {
+			warn = 1;
+			_STARPU_DISP("warning: Couldn't lock performance file, StarPU home is probably on NFS which does not support locking.\n");
+		}
+		return -1;
+	}
+#endif
 	STARPU_ASSERT(ret == 0);
 	return ret;
 }
@@ -327,6 +338,18 @@ int _starpu_fwrlock(FILE *file)
 	};
 	ret = fcntl(fileno(file), F_SETLKW, &lock);
 #endif
+
+#ifdef ENOLCK
+	if (ret != 0 && errno == ENOLCK)
+	{
+		static int warn;
+		if (!warn) {
+			warn = 1;
+			_STARPU_DISP("warning: Couldn't lock performance file, StarPU home is probably on NFS which does not support locking.\n");
+		}
+		return -1;
+	}
+#endif
 	STARPU_ASSERT(ret == 0);
 	return ret;
 }

+ 37 - 18
src/core/perfmodel/perfmodel_bus.c

@@ -787,6 +787,7 @@ static void load_bus_affinity_file_content(void)
 {
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
 	FILE *f;
+	int locked;
 
 	char path[256];
 	get_affinity_path(path, sizeof(path));
@@ -796,7 +797,7 @@ static void load_bus_affinity_file_content(void)
 	f = fopen(path, "r");
 	STARPU_ASSERT(f);
 
-	_starpu_frdlock(f);
+	locked = _starpu_frdlock(f) == 0;
 
 	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	ncpus = _starpu_topology_get_nhwcpu(config);
@@ -850,7 +851,8 @@ static void load_bus_affinity_file_content(void)
 		STARPU_ASSERT(ret == 0);
 	}
 #endif /* !STARPU_USE_OPENCL */
-	_starpu_frdunlock(f);
+	if (locked)
+		_starpu_frdunlock(f);
 
 	fclose(f);
 #endif /* !(STARPU_USE_CUDA_ || STARPU_USE_OPENCL */
@@ -865,6 +867,8 @@ static void write_bus_affinity_file_content(void)
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
 	FILE *f;
 	char path[256];
+	int locked;
+
 	get_affinity_path(path, sizeof(path));
 
 	_STARPU_DEBUG("writing affinities to %s\n", path);
@@ -878,7 +882,7 @@ static void write_bus_affinity_file_content(void)
 		STARPU_ABORT();
 	}
 
-	_starpu_frdlock(f);
+	locked = _starpu_frdlock(f) == 0;
 	unsigned cpu;
         unsigned gpu;
 
@@ -914,7 +918,8 @@ static void write_bus_affinity_file_content(void)
 	}
 #endif
 
-	_starpu_frdunlock(f);
+	if (locked)
+		_starpu_frdunlock(f);
 	fclose(f);
 #endif
 }
@@ -1010,6 +1015,7 @@ static int load_bus_latency_file_content(void)
 	unsigned src, dst;
 	FILE *f;
 	double latency;
+	int locked;
 
 	char path[256];
 	get_latency_path(path, sizeof(path));
@@ -1024,7 +1030,7 @@ static int load_bus_latency_file_content(void)
 		fflush(stderr);
 		STARPU_ABORT();
 	}
-	_starpu_frdlock(f);
+	locked = _starpu_frdlock(f) == 0;
 
 	for (src = 0; src < STARPU_MAXNODES; src++)
 	{
@@ -1092,7 +1098,8 @@ static int load_bus_latency_file_content(void)
 			break;
 		ungetc(n, f);
 	}
-	_starpu_frdunlock(f);
+	if (locked)
+		_starpu_frdunlock(f);
 	fclose(f);
 
 	/* No more values, take NAN */
@@ -1108,6 +1115,7 @@ static void write_bus_latency_file_content(void)
 {
         unsigned src, dst, maxnode;
 	FILE *f;
+	int locked;
 
 	STARPU_ASSERT(was_benchmarked);
 
@@ -1124,7 +1132,7 @@ static void write_bus_latency_file_content(void)
 		fflush(stderr);
 		STARPU_ABORT();
 	}
-	_starpu_fwrlock(f);
+	locked = _starpu_fwrlock(f) == 0;
 	_starpu_fftruncate(f, 0);
 
 	fprintf(f, "# ");
@@ -1185,7 +1193,8 @@ static void write_bus_latency_file_content(void)
 
 		fprintf(f, "\n");
 	}
-	_starpu_fwrunlock(f);
+	if (locked)
+		_starpu_fwrunlock(f);
 
 	fclose(f);
 }
@@ -1232,6 +1241,7 @@ static int load_bus_bandwidth_file_content(void)
 	unsigned src, dst;
 	FILE *f;
 	double bandwidth;
+	int locked;
 
 	char path[256];
 	get_bandwidth_path(path, sizeof(path));
@@ -1246,7 +1256,7 @@ static int load_bus_bandwidth_file_content(void)
 		fflush(stderr);
 		STARPU_ABORT();
 	}
-	_starpu_frdlock(f);
+	locked = _starpu_frdlock(f) == 0;
 
 	for (src = 0; src < STARPU_MAXNODES; src++)
 	{
@@ -1314,7 +1324,8 @@ static int load_bus_bandwidth_file_content(void)
 			break;
 		ungetc(n, f);
 	}
-	_starpu_frdunlock(f);
+	if (locked)
+		_starpu_frdunlock(f);
 	fclose(f);
 
 	/* No more values, take NAN */
@@ -1330,6 +1341,7 @@ static void write_bus_bandwidth_file_content(void)
 {
 	unsigned src, dst, maxnode;
 	FILE *f;
+	int locked;
 
 	STARPU_ASSERT(was_benchmarked);
 
@@ -1341,7 +1353,7 @@ static void write_bus_bandwidth_file_content(void)
 	f = fopen(path, "w+");
 	STARPU_ASSERT(f);
 
-	_starpu_fwrlock(f);
+	locked = _starpu_fwrlock(f) == 0;
 	_starpu_fftruncate(f, 0);
 
 	fprintf(f, "# ");
@@ -1415,7 +1427,8 @@ static void write_bus_bandwidth_file_content(void)
 		fprintf(f, "\n");
 	}
 
-	_starpu_fwrunlock(f);
+	if (locked)
+		_starpu_fwrunlock(f);
 	fclose(f);
 }
 #endif /* STARPU_SIMGRID */
@@ -1591,11 +1604,12 @@ static void check_bus_config_file(void)
                 int ret;
 		unsigned read_cuda = -1, read_opencl = -1, read_mic = -1;
                 unsigned read_cpus = -1;
+		int locked;
 
                 // Loading configuration from file
                 f = fopen(path, "r");
                 STARPU_ASSERT(f);
-		_starpu_frdlock(f);
+		locked = _starpu_frdlock(f) == 0;
                 _starpu_drop_comments(f);
                 ret = fscanf(f, "%u\t", &read_cpus);
 		STARPU_ASSERT(ret == 1);
@@ -1610,7 +1624,8 @@ static void check_bus_config_file(void)
 		if (ret == 0)
 			read_mic = 0;
                 _starpu_drop_comments(f);
-		_starpu_frdunlock(f);
+		if (locked)
+			_starpu_frdunlock(f);
                 fclose(f);
 
                 // Loading current configuration
@@ -1657,6 +1672,7 @@ static void write_bus_config_file_content(void)
 {
 	FILE *f;
 	char path[256];
+	int locked;
 
 	STARPU_ASSERT(was_benchmarked);
         get_config_path(path, sizeof(path));
@@ -1665,7 +1681,7 @@ static void write_bus_config_file_content(void)
 
         f = fopen(path, "w+");
 	STARPU_ASSERT(f);
-	_starpu_fwrlock(f);
+	locked = _starpu_fwrlock(f) == 0;
 	_starpu_fftruncate(f, 0);
 
         fprintf(f, "# Current configuration\n");
@@ -1674,7 +1690,8 @@ static void write_bus_config_file_content(void)
         fprintf(f, "%d # Number of OpenCL devices\n", nopencl);
         fprintf(f, "%d # Number of MIC devices\n", nmic);
 
-	_starpu_fwrunlock(f);
+	if (locked)
+		_starpu_fwrunlock(f);
         fclose(f);
 }
 
@@ -2124,6 +2141,7 @@ static void write_bus_platform_file_content(int version)
 	unsigned i;
 	const char *speed, *flops, *Bps, *s;
 	char dash;
+	int locked;
 
 	if (version == 3)
 	{
@@ -2156,7 +2174,7 @@ static void write_bus_platform_file_content(int version)
 		fflush(stderr);
 		STARPU_ABORT();
 	}
-	_starpu_fwrlock(f);
+	locked = _starpu_fwrlock(f) == 0;
 	_starpu_fftruncate(f, 0);
 
 	fprintf(f,
@@ -2399,7 +2417,8 @@ flat_cuda:
 " </platform>\n"
 		);
 
-	_starpu_fwrunlock(f);
+	if (locked)
+		_starpu_fwrunlock(f);
 	fclose(f);
 }
 

+ 16 - 8
src/core/perfmodel/perfmodel_history.c

@@ -848,6 +848,7 @@ static void save_history_based_model(struct starpu_perfmodel *model)
 {
 	STARPU_ASSERT(model);
 	STARPU_ASSERT(model->symbol);
+	int locked;
 
 	/* TODO checks */
 
@@ -862,10 +863,11 @@ static void save_history_based_model(struct starpu_perfmodel *model)
 	f = fopen(path, "w+");
 	STARPU_ASSERT_MSG(f, "Could not save performance model %s\n", path);
 
-	_starpu_fwrlock(f);
+	locked = _starpu_fwrlock(f) == 0;
 	_starpu_fftruncate(f, 0);
 	dump_model_file(f, model);
-	_starpu_fwrunlock(f);
+	if (locked)
+		_starpu_fwrunlock(f);
 
 	fclose(f);
 }
@@ -1056,9 +1058,11 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 			f = fopen(path, "r");
 			if (f)
 			{
-				_starpu_frdlock(f);
+				int locked;
+				locked = _starpu_frdlock(f) == 0;
 				parse_model_file(f, model, scan_history);
-				_starpu_frdunlock(f);
+				if (locked)
+					_starpu_frdunlock(f);
 				fclose(f);
 				_STARPU_DEBUG("Performance model file %s for model %s is loaded\n", path, model->symbol);
 			}
@@ -1149,14 +1153,16 @@ int starpu_perfmodel_load_file(const char *filename, struct starpu_perfmodel *mo
 {
 	int res;
 	FILE *f = fopen(filename, "r");
+	int locked;
 
 	STARPU_ASSERT(f);
 
 	starpu_perfmodel_init(model);
 
-	_starpu_frdlock(f);
+	locked = _starpu_frdlock(f) == 0;
 	parse_model_file(f, model, 1);
-	_starpu_frdunlock(f);
+	if (locked)
+		_starpu_frdunlock(f);
 
 	res = fclose(f);
 	STARPU_ASSERT(res == 0);
@@ -1632,13 +1638,14 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 		struct starpu_task *task = j->task;
 		starpu_perfmodel_debugfilepath(model, arch_combs[comb], per_arch_model->debug_path, 256, impl);
 		FILE *f = fopen(per_arch_model->debug_path, "a+");
+		int locked;
 		if (f == NULL)
 		{
 			_STARPU_DISP("Error <%s> when opening file <%s>\n", strerror(errno), per_arch_model->debug_path);
 			STARPU_PTHREAD_RWLOCK_UNLOCK(&model->state->model_rwlock);
 			return;
 		}
-		_starpu_fwrlock(f);
+		locked = _starpu_fwrlock(f) == 0;
 
 		if (!j->footprint_is_computed)
 			(void) _starpu_compute_buffers_footprint(model, arch, impl, j);
@@ -1658,7 +1665,8 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 			handle->ops->display(handle, f);
 		}
 		fprintf(f, "\n");
-		_starpu_fwrunlock(f);
+		if (locked)
+			_starpu_fwrunlock(f);
 		fclose(f);
 #endif
 		STARPU_PTHREAD_RWLOCK_UNLOCK(&model->state->model_rwlock);