From 1184e5778ac3ffd8caf3f4d5b9e2b30a736d64d7 Mon Sep 17 00:00:00 2001 From: Caz Yokoyama Date: Thu, 25 Apr 2019 10:23:13 -0700 Subject: 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 Cc: Petri Latvala Reviewed-by: Petri Latvala --- lib/igt_aux.c | 24 ++++++++++++++++++++++++ lib/igt_aux.h | 2 ++ lib/intel_os.c | 14 -------------- tests/i915/gem_exec_reuse.c | 14 +------------- 4 files changed, 27 insertions(+), 27 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; +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index dbd88b67..67e8fbf4 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -298,4 +298,6 @@ void igt_lsof(const char *dpath); #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +uint64_t vfs_file_max(void); + #endif /* IGT_AUX_H */ diff --git a/lib/intel_os.c b/lib/intel_os.c index dd93bea1..505831c0 100644 --- a/lib/intel_os.c +++ b/lib/intel_os.c @@ -279,20 +279,6 @@ void *intel_get_total_pinnable_mem(size_t *total) return can_mlock; } -static 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; -} - static unsigned max_open_files(void) { struct rlimit rlim; diff --git a/tests/i915/gem_exec_reuse.c b/tests/i915/gem_exec_reuse.c index 9cba1354..935bfa9a 100644 --- a/tests/i915/gem_exec_reuse.c +++ b/tests/i915/gem_exec_reuse.c @@ -25,6 +25,7 @@ #include #include "igt.h" +#include "igt_aux.h" IGT_TEST_DESCRIPTION("Inspect scaling with large number of reused objects"); @@ -56,19 +57,6 @@ static void noop(struct noop *n, gem_execbuf(n->fd, &execbuf); } -static uint64_t vfs_file_max(void) -{ - long long unsigned max = 80000; - FILE *file = fopen("/proc/sys/fs/file-max", "r"); - if (file) { - igt_assert(fscanf(file, "%llu", &max) == 1); - fclose(file); - } - - igt_info("System limit for open files is %llu\n", max); - return max; -} - static uint64_t max_open_files(void) { struct rlimit rlim; -- cgit v1.2.3