summaryrefslogtreecommitdiff
path: root/lib/igt_aux.c
diff options
context:
space:
mode:
authorCaz Yokoyama <caz.yokoyama@intel.com>2019-04-25 10:23:13 -0700
committerPetri Latvala <petri.latvala@intel.com>2019-04-26 12:41:26 +0300
commit1184e5778ac3ffd8caf3f4d5b9e2b30a736d64d7 (patch)
tree46b4323819cec3baafcd79d9242067404f3daeac /lib/igt_aux.c
parent2fc51d5528eda79fe1856e0b85e6b71e3fb79c47 (diff)
lib: consolidate duplicated define of vfs_file_max(void)
Remove it from intel_os.c and gem_exec_reuse.c and globally define in igt_aux.c. v3: update comment in the code and commit message. Signed-off-by: Caz Yokoyama <caz.yokoyama@intel.com> Cc: Petri Latvala <petri.latvala@intel.com> Reviewed-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/igt_aux.c')
-rw-r--r--lib/igt_aux.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 3dd68d95..1a70edcc 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1646,3 +1646,27 @@ bool igt_allow_unlimited_files(void)
rlim.rlim_max = nofile_rlim;
return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
}
+
+/**
+ * vfs_file_max: report maximum number of files
+ *
+ * Get the global system-wide maximum of open files the kernel allows,
+ * by reading /proc/sys/fs/file-max. Fails the current subtest if
+ * reading the file fails, and returns a suitable best guess if it
+ * cannot be opened.
+ *
+ * Returns: System-wide maximum of open files, or a best effort guess.
+ */
+uint64_t vfs_file_max(void)
+{
+ static long long unsigned max;
+ if (max == 0) {
+ FILE *file = fopen("/proc/sys/fs/file-max", "r");
+ max = 80000;
+ if (file) {
+ igt_assert(fscanf(file, "%llu", &max) == 1);
+ fclose(file);
+ }
+ }
+ return max;
+}