public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ramalingam C <ramalingam.c@intel.com>
To: igt-dev <igt-dev@lists.freedesktop.org>
Subject: [igt-dev] [PATCH i-g-t 3/5] tests/dumb_buffer: Try to compute the largest possible dumb buffer
Date: Mon, 27 Jan 2020 22:32:03 +0530	[thread overview]
Message-ID: <20200127170205.7195-3-ramalingam.c@intel.com> (raw)
In-Reply-To: <20200127170205.7195-1-ramalingam.c@intel.com>

From: Chris Wilson <chris@chris-wilson.co.uk>

For our threaded clear test, we want to create as many buffers as can
fit into the available memory. However, since we don't know the size of
that available memory, it can be easy to create too large or too many
buffers, and waste our time testing the unobtainable. Instead, try
probing the available space by trying to create the largest dumb buffer
we possibly can, and assume that is the equivalent to the available
space.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ramalingam C <ramalingam.c@intel.com>
Reviewed-by: Ramalingam C <ramalingam.c@intel.com>
---
 tests/dumb_buffer.c | 68 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 9 deletions(-)

diff --git a/tests/dumb_buffer.c b/tests/dumb_buffer.c
index b6fe6f5dc6ec..ad854c0696e7 100644
--- a/tests/dumb_buffer.c
+++ b/tests/dumb_buffer.c
@@ -31,18 +31,18 @@
  * combinations are rejected.
  */
 
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <string.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <getopt.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdatomic.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
 
 #include <drm.h>
 
@@ -279,12 +279,62 @@ static void *thread_clear(void *data)
 	return (void *)(uintptr_t)checked;
 }
 
+static jmp_buf sigjmp;
+
+static void sigprobe(int sig)
+{
+	longjmp(sigjmp, sig);
+}
+
+static uint64_t estimate_largest_dumb_buffer(int fd)
+{
+	sighandler_t old_sigbus = signal(SIGBUS, sigprobe);
+	sighandler_t old_sigsegv = signal(SIGSEGV, sigprobe);
+	struct drm_mode_create_dumb create = {
+		.bpp = 32,
+		.width = 1 << 20, /* in pixels */
+		.height = 1, /* in rows */
+	};
+	volatile uint64_t largest = 0;
+	char * volatile ptr = NULL;
+
+	if (setjmp(sigjmp)) {
+		if (ptr)
+			munmap(ptr, create.size);
+
+		signal(SIGBUS, old_sigbus);
+		signal(SIGSEGV, old_sigsegv);
+
+		igt_info("Largest dumb buffer sucessfully created: %'"PRIu64" bytes\n",
+			 largest);
+		return largest / PAGE_SIZE;
+	}
+
+	for (create.height = 1; create.height; create.height *= 2) {
+		if (__dumb_create(fd, &create))
+			longjmp(sigjmp, SIGABRT);
+
+		ptr = __dumb_map(fd, create.handle, create.size, PROT_READ);
+		dumb_destroy(fd, create.handle);
+		if (!ptr)
+			longjmp(sigjmp, SIGABRT);
+
+		if (!*ptr)
+			largest = create.size;
+
+		munmap(ptr, create.size);
+		ptr = NULL;
+	}
+
+	longjmp(sigjmp, SIGABRT);
+}
+
 static void always_clear(int fd, int timeout)
 {
 	struct thread_clear arg = {
 		.fd = fd,
 		.timeout = timeout,
-		.max = intel_get_avail_ram_mb() << (20 - 12), /* in pages */
+		.max = estimate_largest_dumb_buffer(fd), /* in pages */
 	};
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	unsigned long checked;
-- 
2.20.1

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

  parent reply	other threads:[~2020-01-27 17:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-27 17:02 [igt-dev] [PATCH i-g-t 1/5] tests/dumb_buffer: Remove page nonaligned buffer tests Ramalingam C
2020-01-27 17:02 ` [igt-dev] [PATCH i-g-t 2/5] tests/i915/gem_create: Modify the page nonaligned tests Ramalingam C
2020-01-27 17:02 ` Ramalingam C [this message]
2020-01-27 17:02 ` [igt-dev] [PATCH i-g-t 4/5] tests/dumb_duffer: extending for lmem coverage Ramalingam C
2020-01-27 17:13   ` Chris Wilson
2020-01-27 17:02 ` [igt-dev] [PATCH i-g-t 5/5] lib/i915/intel_memory_region: wrappers for memory regions ops Ramalingam C
2020-01-27 19:41 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/5] tests/dumb_buffer: Remove page nonaligned buffer tests Patchwork
2020-01-28 13:57 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=20200127170205.7195-3-ramalingam.c@intel.com \
    --to=ramalingam.c@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox