All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [igt-dev] [PATCH 3/4] lib: add igt_allow_unlimited_files()
Date: Thu,  4 Apr 2019 15:39:24 -0700	[thread overview]
Message-ID: <20190404223925.1102-3-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20190404223925.1102-1-lucas.demarchi@intel.com>

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>
---
 lib/igt_aux.c                   | 21 +++++++++++++++++++++
 lib/igt_aux.h                   |  2 ++
 tests/i915/gem_concurrent_all.c | 22 +---------------------
 tests/i915/gem_exec_reuse.c     | 25 +------------------------
 tests/i915/gem_fd_exhaustion.c  | 22 +---------------------
 5 files changed, 26 insertions(+), 66 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);
 
diff --git a/tests/i915/gem_concurrent_all.c b/tests/i915/gem_concurrent_all.c
index 6049372d..3ddaab82 100644
--- a/tests/i915/gem_concurrent_all.c
+++ b/tests/i915/gem_concurrent_all.c
@@ -1678,26 +1678,6 @@ num_buffers(uint64_t max,
 	return n;
 }
 
-static bool 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;
-}
-
 igt_main
 {
 	const struct access_mode modes[] = {
@@ -1821,7 +1801,7 @@ igt_main
 		all = true;
 
 	igt_fixture {
-		allow_unlimited_files();
+		igt_allow_unlimited_files();
 
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
diff --git a/tests/i915/gem_exec_reuse.c b/tests/i915/gem_exec_reuse.c
index 55904718..9cba1354 100644
--- a/tests/i915/gem_exec_reuse.c
+++ b/tests/i915/gem_exec_reuse.c
@@ -56,29 +56,6 @@ static void noop(struct noop *n,
 	gem_execbuf(n->fd, &execbuf);
 }
 
-static bool 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);
-		fclose(file);
-	}
-
-	if (getrlimit(RLIMIT_NOFILE, &rlim))
-		return false;
-
-	rlim.rlim_cur = rlim.rlim_max;
-	if (setrlimit(RLIMIT_NOFILE, &rlim))
-		return false;
-
-	rlim.rlim_cur = nofile_rlim;
-	rlim.rlim_max = nofile_rlim;
-	return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
-}
-
 static uint64_t vfs_file_max(void)
 {
 	long long unsigned max = 80000;
@@ -126,7 +103,7 @@ igt_main
 		uint32_t bbe = MI_BATCH_BUFFER_END;
 		unsigned engine;
 
-		allow_unlimited_files();
+		igt_allow_unlimited_files();
 
 		no.fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(no.fd);
diff --git a/tests/i915/gem_fd_exhaustion.c b/tests/i915/gem_fd_exhaustion.c
index 559590b1..9704fa02 100644
--- a/tests/i915/gem_fd_exhaustion.c
+++ b/tests/i915/gem_fd_exhaustion.c
@@ -60,26 +60,6 @@ static int write_sysctl(const char *path, unsigned int val)
 	return -errno;
 }
 
-static bool allow_unlimited_files(void)
-{
-	unsigned int nofile_rlim = 1024*1024;
-	struct rlimit rlim;
-	unsigned int buf;
-
-	buf = read_sysctl("/proc/sys/fs/file-max");
-	if (buf > 0)
-		nofile_rlim = buf;
-	original_nr_open = read_sysctl("/proc/sys/fs/nr_open");
-	igt_assert(write_sysctl("/proc/sys/fs/nr_open", nofile_rlim) == 0);
-
-	if (getrlimit(RLIMIT_NOFILE, &rlim))
-		return false;
-
-	rlim.rlim_cur = nofile_rlim;
-	rlim.rlim_max = nofile_rlim;
-	return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
-}
-
 static void restore_original_sysctl(int sig)
 {
 	if (original_nr_open > 0)
@@ -90,7 +70,7 @@ igt_simple_main
 {
 	int fd;
 
-	igt_require(allow_unlimited_files());
+	igt_require(igt_allow_unlimited_files());
 
 	fd = drm_open_driver(DRIVER_INTEL);
 
-- 
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-04-04 22:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-04 22:39 [igt-dev] [PATCH 1/4] lib/igt_kmod: simplify check for loaded module Lucas De Marchi
2019-04-04 22:39 ` [igt-dev] [PATCH 2/4] gem_exec_parallel: do not special case the default Lucas De Marchi
2019-04-04 22:57   ` Chris Wilson
2019-04-04 22:39 ` Lucas De Marchi [this message]
2019-04-04 23:00   ` [igt-dev] [PATCH 3/4] lib: add igt_allow_unlimited_files() Chris Wilson
2019-04-04 22:39 ` [igt-dev] [PATCH 4/4] gem_exec_parallel: allow unlimited open files Lucas De Marchi
2019-04-04 23:01   ` Chris Wilson
2019-04-04 23:19 ` [igt-dev] [PATCH 1/4] lib/igt_kmod: simplify check for loaded module Chris Wilson
2019-04-05 16:33   ` Lucas De Marchi
2019-04-04 23:39 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [1/4] " Patchwork
2019-04-05 19:29 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-04-08 11:56   ` Petri Latvala
2019-04-30 17:09     ` Lucas De Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190404223925.1102-3-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.