All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 2/2] tests/gem_exec_await: Add a memory pressure subtest
Date: Mon, 19 Nov 2018 15:22:29 +0000	[thread overview]
Message-ID: <20181119152229.8390-2-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20181119152229.8390-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Memory pressure subtest attempts to provoke system overload which can
cause GPU hangs, especially when combined with spin batches which do
not allow for some nop instructions to provide relief.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/i915/gem_exec_await.c | 107 ++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/tests/i915/gem_exec_await.c b/tests/i915/gem_exec_await.c
index 3ea5b5903c6b..ccb5159a6fe1 100644
--- a/tests/i915/gem_exec_await.c
+++ b/tests/i915/gem_exec_await.c
@@ -30,6 +30,11 @@
 
 #include <sys/ioctl.h>
 #include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <sched.h>
 
 #define LOCAL_I915_EXEC_NO_RELOC (1<<11)
 #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
@@ -227,6 +232,92 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags)
 	free(exec);
 }
 
+struct thread {
+	pthread_t thread;
+	volatile bool done;
+};
+
+static unsigned long get_meminfo(const char *info, const char *tag)
+{
+        const char *str;
+        unsigned long val;
+
+        str = strstr(info, tag);
+        if (str && sscanf(str + strlen(tag), " %lu", &val) == 1)
+                return val >> 10;
+
+        igt_warn("Unrecognised /proc/meminfo field: '%s'\n", tag);
+        return 0;
+}
+
+static unsigned long get_avail_ram_mb(void)
+{
+	int fd;
+	int ret;
+	char buf[4096];
+	unsigned long ram;
+
+	fd = open("/proc/meminfo", O_RDONLY);
+	igt_assert_fd(fd);
+
+	ret = read(fd, buf, sizeof(buf));
+	igt_assert(ret >= 0);
+
+	close(fd);
+
+	ram = get_meminfo(buf, "MemAvailable:");
+	ram += get_meminfo(buf, "Buffers:");
+	ram += get_meminfo(buf, "Cached:");
+	ram += get_meminfo(buf, "SwapCached:");
+
+	return ram;
+}
+
+#define PAGE_SIZE 4096
+static void *mempressure(void *arg)
+{
+	struct thread *thread = arg;
+	const unsigned int sz_mb = 2;
+	const unsigned int sz = sz_mb << 20;
+	unsigned int n = 0, max = 0;
+	unsigned int blocks;
+	void **ptr = NULL;
+
+	while (!thread->done) {
+		unsigned long ram_mb = get_avail_ram_mb();
+
+		if (!ptr) {
+			blocks = ram_mb / sz_mb;
+			ptr = calloc(blocks, sizeof(void *));
+			igt_assert(ptr);
+		} else if (ram_mb < 384) {
+			blocks = max + 1;
+		}
+
+		if (ptr[n])
+			munmap(ptr[n], sz);
+
+		ptr[n] = mmap(NULL, sz, PROT_WRITE,
+			      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		assert(ptr[n] != MAP_FAILED);
+
+		madvise(ptr[n], sz, MADV_HUGEPAGE);
+
+		for (size_t page = 0; page < sz; page += PAGE_SIZE)
+			*(volatile uint32_t *)((unsigned char *)ptr[n] + page) =
+				0;
+
+		if (n > max)
+			max = n;
+
+		n++;
+
+		if (n >= blocks)
+			n = 0;
+	}
+
+	return NULL;
+}
 igt_main
 {
 	int ring_size = 0;
@@ -255,6 +346,22 @@ igt_main
 		wide(device, ring_size, 20, CONTEXTS);
 	}
 
+	igt_subtest("wide-contexts-mempressure") {
+		struct thread thread = { };
+		int ret;
+
+		gem_require_contexts(device);
+
+		ret = pthread_create(&thread.thread, NULL, mempressure,
+				     &thread);
+		igt_assert_eq(ret, 0);
+
+		wide(device, ring_size, 20, CONTEXTS);
+
+		thread.done = true;
+		pthread_join(thread.thread, NULL);
+	}
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(device);
-- 
2.19.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t 2/2] tests/gem_exec_await: Add a memory pressure subtest
Date: Mon, 19 Nov 2018 15:22:29 +0000	[thread overview]
Message-ID: <20181119152229.8390-2-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20181119152229.8390-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Memory pressure subtest attempts to provoke system overload which can
cause GPU hangs, especially when combined with spin batches which do
not allow for some nop instructions to provide relief.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/i915/gem_exec_await.c | 107 ++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/tests/i915/gem_exec_await.c b/tests/i915/gem_exec_await.c
index 3ea5b5903c6b..ccb5159a6fe1 100644
--- a/tests/i915/gem_exec_await.c
+++ b/tests/i915/gem_exec_await.c
@@ -30,6 +30,11 @@
 
 #include <sys/ioctl.h>
 #include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <sched.h>
 
 #define LOCAL_I915_EXEC_NO_RELOC (1<<11)
 #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
@@ -227,6 +232,92 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags)
 	free(exec);
 }
 
+struct thread {
+	pthread_t thread;
+	volatile bool done;
+};
+
+static unsigned long get_meminfo(const char *info, const char *tag)
+{
+        const char *str;
+        unsigned long val;
+
+        str = strstr(info, tag);
+        if (str && sscanf(str + strlen(tag), " %lu", &val) == 1)
+                return val >> 10;
+
+        igt_warn("Unrecognised /proc/meminfo field: '%s'\n", tag);
+        return 0;
+}
+
+static unsigned long get_avail_ram_mb(void)
+{
+	int fd;
+	int ret;
+	char buf[4096];
+	unsigned long ram;
+
+	fd = open("/proc/meminfo", O_RDONLY);
+	igt_assert_fd(fd);
+
+	ret = read(fd, buf, sizeof(buf));
+	igt_assert(ret >= 0);
+
+	close(fd);
+
+	ram = get_meminfo(buf, "MemAvailable:");
+	ram += get_meminfo(buf, "Buffers:");
+	ram += get_meminfo(buf, "Cached:");
+	ram += get_meminfo(buf, "SwapCached:");
+
+	return ram;
+}
+
+#define PAGE_SIZE 4096
+static void *mempressure(void *arg)
+{
+	struct thread *thread = arg;
+	const unsigned int sz_mb = 2;
+	const unsigned int sz = sz_mb << 20;
+	unsigned int n = 0, max = 0;
+	unsigned int blocks;
+	void **ptr = NULL;
+
+	while (!thread->done) {
+		unsigned long ram_mb = get_avail_ram_mb();
+
+		if (!ptr) {
+			blocks = ram_mb / sz_mb;
+			ptr = calloc(blocks, sizeof(void *));
+			igt_assert(ptr);
+		} else if (ram_mb < 384) {
+			blocks = max + 1;
+		}
+
+		if (ptr[n])
+			munmap(ptr[n], sz);
+
+		ptr[n] = mmap(NULL, sz, PROT_WRITE,
+			      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		assert(ptr[n] != MAP_FAILED);
+
+		madvise(ptr[n], sz, MADV_HUGEPAGE);
+
+		for (size_t page = 0; page < sz; page += PAGE_SIZE)
+			*(volatile uint32_t *)((unsigned char *)ptr[n] + page) =
+				0;
+
+		if (n > max)
+			max = n;
+
+		n++;
+
+		if (n >= blocks)
+			n = 0;
+	}
+
+	return NULL;
+}
 igt_main
 {
 	int ring_size = 0;
@@ -255,6 +346,22 @@ igt_main
 		wide(device, ring_size, 20, CONTEXTS);
 	}
 
+	igt_subtest("wide-contexts-mempressure") {
+		struct thread thread = { };
+		int ret;
+
+		gem_require_contexts(device);
+
+		ret = pthread_create(&thread.thread, NULL, mempressure,
+				     &thread);
+		igt_assert_eq(ret, 0);
+
+		wide(device, ring_size, 20, CONTEXTS);
+
+		thread.done = true;
+		pthread_join(thread.thread, NULL);
+	}
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(device);
-- 
2.19.1

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

  reply	other threads:[~2018-11-19 15:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 15:22 [PATCH i-g-t 1/2] tests/gem_exec_await: Relax the busy spinner Tvrtko Ursulin
2018-11-19 15:22 ` [igt-dev] " Tvrtko Ursulin
2018-11-19 15:22 ` Tvrtko Ursulin [this message]
2018-11-19 15:22   ` [igt-dev] [PATCH i-g-t 2/2] tests/gem_exec_await: Add a memory pressure subtest Tvrtko Ursulin
2018-11-19 15:36   ` Chris Wilson
2018-11-19 15:36     ` Chris Wilson
2018-11-19 15:54     ` Tvrtko Ursulin
2018-11-19 15:54       ` Tvrtko Ursulin
2018-11-19 17:07       ` Chris Wilson
2018-11-19 17:07         ` [Intel-gfx] " Chris Wilson
2018-11-19 15:28 ` [igt-dev] [PATCH i-g-t 1/2] tests/gem_exec_await: Relax the busy spinner Chris Wilson
2018-11-19 15:28   ` Chris Wilson
2018-11-19 15:33   ` Tvrtko Ursulin
2018-11-19 15:33     ` Tvrtko Ursulin
2018-11-19 16:18     ` Chris Wilson
2018-11-19 16:18       ` Chris Wilson
2018-11-19 19:18       ` Tvrtko Ursulin
2018-11-19 19:18         ` Tvrtko Ursulin
2018-11-19 19:34         ` Chris Wilson
2018-11-19 19:34           ` Chris Wilson
2018-11-19 16:44 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] " Patchwork
2018-11-19 21:52 ` [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=20181119152229.8390-2-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --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.