summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2019-04-04 15:16:11 -0700
committerLucas De Marchi <lucas.demarchi@intel.com>2019-04-05 10:00:45 -0700
commit8bc80862603bd5d1b0dcb7a0472935215f167f09 (patch)
treef095731ce601ac3492add9a876cb5d108b22135e /lib
parent019f892e5d1a0a9643cb726c47ce2d99c14b444f (diff)
lib: add igt_allow_unlimited_files()
Share the implementation to tweak the maximum number of open files. The version in tests/i915/gem_exec_reuse.c was a little bit different, but I don't think it needs to be because it would still return a failure if any of the calls to setrlimit() fail. So I'm using the other one. Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_aux.c21
-rw-r--r--lib/igt_aux.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 6eaf546e..266aa832 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -42,6 +42,7 @@
#include <unistd.h>
#include <sys/poll.h>
#include <sys/wait.h>
+#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/syscall.h>
@@ -1588,3 +1589,23 @@ double igt_stop_siglatency(struct igt_mean *result)
return mean;
}
+
+bool igt_allow_unlimited_files(void)
+{
+ struct rlimit rlim;
+ unsigned nofile_rlim = 1024*1024;
+
+ FILE *file = fopen("/proc/sys/fs/file-max", "r");
+ if (file) {
+ igt_assert(fscanf(file, "%u", &nofile_rlim) == 1);
+ igt_info("System limit for open files is %u\n", nofile_rlim);
+ fclose(file);
+ }
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim))
+ return false;
+
+ rlim.rlim_cur = nofile_rlim;
+ rlim.rlim_max = nofile_rlim;
+ return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
+}
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 09b6246b..55392790 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -274,6 +274,8 @@ struct igt_mean;
void igt_start_siglatency(int sig); /* 0 => SIGRTMIN (default) */
double igt_stop_siglatency(struct igt_mean *result);
+bool igt_allow_unlimited_files(void);
+
void igt_set_module_param(const char *name, const char *val);
void igt_set_module_param_int(const char *name, int val);