All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [igt PATCH 0/1] lib: igt@i915_suspend@shrink faster
@ 2019-02-20  1:13 Caz Yokoyama
  2019-02-19 19:05 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Caz Yokoyama @ 2019-02-20  1:13 UTC (permalink / raw)
  To: igt-dev

igt@i915_suspend@shrink runs 25 sec instead of 90 sec on my NUC which has
2GB of memory. The child process which is created by igt_fork() updates
pinnable memory size, (*can_mlock). Parent process mlocks at the end of
"for loop" when the child process finds pinnable memory size in 4kb
boundary. This patch also reduces the chance of dying entire test process
because the parent process mclocks the memory where we already know it is
pinnable.

Incrementary mlocking small memory in addition to 3/4 of available memory
by the child process does not work because kernel finds the parent
process mlocks more memory than the child process and kills the parent
process.

Another big time consumer is igt_system_suspend_autoresume(). 15 sec of
delay is hard coded. It is too danger to reduce 15 sec because some of
test machines may fail by reducing delay time.

"gem_userptr_blits@mlocked-*" test also calls
intel_get_total_pinnable_mem(). I do not test them because they do not
finish within 30 min on my NUC without this patch.

Caz Yokoyama (1):
  igt@i915_suspend@shrink faster

 lib/intel_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.17.1

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

^ permalink raw reply	[flat|nested] 23+ messages in thread
* [igt-dev] [PATCH i-g-t] lib: Incrementally mlock()
@ 2019-02-27 16:29 Chris Wilson
  2019-02-27 17:34 ` Caz Yokoyama
  2019-02-28 18:56 ` Caz Yokoyama
  0 siblings, 2 replies; 23+ messages in thread
From: Chris Wilson @ 2019-02-27 16:29 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

As we already have the previous portion of the mmap mlocked, we only
need to mlock() the fresh portion for testing available memory.

v2: Fixup the uint64_t pointer arithmetric and only use a single mmap to
avoid subsequent mlock fail (for reasons unknown, but bet on mm/).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Caz Yokoyama <Caz.Yokoyama@intel.com>
---
 lib/igt_aux.h             |  2 +-
 lib/intel_os.c            | 40 +++++++++++++++++++++------------------
 tests/eviction_common.c   | 17 +++++++++--------
 tests/i915/i915_suspend.c | 17 +++--------------
 4 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index fb02c026a..09b6246bf 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -194,7 +194,7 @@ void intel_purge_vm_caches(int fd);
 uint64_t intel_get_avail_ram_mb(void);
 uint64_t intel_get_total_ram_mb(void);
 uint64_t intel_get_total_swap_mb(void);
-size_t intel_get_total_pinnable_mem(void);
+void *intel_get_total_pinnable_mem(size_t *pinned);
 
 int __intel_check_memory(uint64_t count, uint64_t size, unsigned mode,
 			 uint64_t *out_required, uint64_t *out_total);
diff --git a/lib/intel_os.c b/lib/intel_os.c
index e1e31e230..dd93bea1a 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -227,11 +227,9 @@ intel_get_total_swap_mb(void)
  *
  * Returns: Amount of memory that can be safely pinned, in bytes.
  */
-size_t
-intel_get_total_pinnable_mem(void)
+void *intel_get_total_pinnable_mem(size_t *total)
 {
 	uint64_t *can_mlock, pin, avail;
-	size_t ret;
 
 	pin = (intel_get_total_ram_mb() + 1) << 20;
 	avail = (intel_get_avail_ram_mb() + 1) << 20;
@@ -245,34 +243,40 @@ intel_get_total_pinnable_mem(void)
 	 */
 	*can_mlock = (avail >> 1) + (avail >> 2);
 	if (mlock(can_mlock, *can_mlock)) {
-		*can_mlock = 0;
-		goto out;
+		munmap(can_mlock, pin);
+		return MAP_FAILED;
 	}
 
 	for (uint64_t inc = 1024 << 20; inc >= 4 << 10; inc >>= 2) {
-		igt_debug("Testing mlock %'"PRIu64" B (%'"PRIu64" MiB)\n",
-			  *can_mlock, *can_mlock >> 20);
+		uint64_t locked = *can_mlock;
+
+		igt_debug("Testing mlock %'"PRIu64"B (%'"PRIu64"MiB) + %'"PRIu64"B\n",
+			  locked, locked >> 20, inc);
 
 		igt_fork(child, 1) {
-			for (uint64_t bytes = *can_mlock;
-			     bytes <= pin;
-			     bytes += inc) {
-				if (mlock(can_mlock, bytes))
+			uint64_t bytes = *can_mlock;
+
+			while (bytes <= pin) {
+				if (mlock((void *)can_mlock + bytes, inc))
 					break;
 
-				*can_mlock = bytes;
+				*can_mlock = bytes += inc;
 				__sync_synchronize();
 			}
 		}
 		__igt_waitchildren();
-		igt_assert(!mlock(can_mlock, *can_mlock));
-	}
 
-out:
-	ret = *can_mlock;
-	munmap(can_mlock, pin);
+		if (*can_mlock > locked + inc) { /* Weird bit of mm/ lore */
+			*can_mlock -= inc;
+			igt_debug("Claiming mlock %'"PRIu64"B (%'"PRIu64"MiB)\n",
+				  *can_mlock, *can_mlock >> 20);
+			igt_assert(!mlock((void *)can_mlock + locked,
+					  *can_mlock - locked));
+		}
+	}
 
-	return ret;
+	*total = pin;
+	return can_mlock;
 }
 
 static uint64_t vfs_file_max(void)
diff --git a/tests/eviction_common.c b/tests/eviction_common.c
index 321772ba7..a3b9e4167 100644
--- a/tests/eviction_common.c
+++ b/tests/eviction_common.c
@@ -133,23 +133,24 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops,
 			      uint64_t surface_size,
 			      uint64_t surface_count)
 {
+	uint64_t sz, pin, total;
 	void *mem;
-	uint64_t sz, pin_total;
 
 	intel_require_memory(surface_count, surface_size, CHECK_RAM);
 
-	sz = surface_size*surface_count;
-	pin_total = intel_get_total_pinnable_mem();
-	igt_require(pin_total > sz);
-
-	mem = mmap(NULL, pin_total, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
+	mem = intel_get_total_pinnable_mem(&total);
 	igt_assert(mem != MAP_FAILED);
+	pin = *(uint64_t *)mem;
+	igt_assert(!munlock(mem, pin));
+
+	sz = surface_size * surface_count;
+	igt_require(pin > sz);
 
 	igt_fork(child, 1) {
 		uint32_t *bo;
 		uint64_t n;
 		int ret;
-		size_t lock = pin_total - sz;
+		size_t lock = pin - sz;
 
 		bo = malloc(surface_count * sizeof(*bo));
 		igt_assert(bo);
@@ -186,7 +187,7 @@ static void mlocked_evictions(int fd, struct igt_eviction_test_ops *ops,
 	}
 	igt_waitchildren();
 
-	munmap(mem, pin_total);
+	munmap(mem, total);
 }
 
 static int swapping_evictions(int fd, struct igt_eviction_test_ops *ops,
diff --git a/tests/i915/i915_suspend.c b/tests/i915/i915_suspend.c
index 84cb3b490..cd7cf9675 100644
--- a/tests/i915/i915_suspend.c
+++ b/tests/i915/i915_suspend.c
@@ -163,25 +163,14 @@ test_sysfs_reader(bool hibernate)
 static void
 test_shrink(int fd, unsigned int mode)
 {
-	void *mem;
 	size_t size;
+	void *mem;
 
 	gem_quiescent_gpu(fd);
 	intel_purge_vm_caches(fd);
 
-	size = intel_get_total_pinnable_mem();
-	igt_require(size > 64 << 20);
-	size -= 64 << 20;
-
-	mem = mmap(NULL, size, PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);
-
-	intel_purge_vm_caches(fd);
-
-	igt_debug("Locking %'zu B (%'zu MiB)\n",
-		  size, size >> 20);
-	igt_assert(!mlock(mem, size));
-	igt_info("Locked %'zu B (%'zu MiB)\n",
-		 size, size >> 20);
+	mem = intel_get_total_pinnable_mem(&size);
+	igt_assert(mem != MAP_FAILED);
 
 	intel_purge_vm_caches(fd);
 	igt_system_suspend_autoresume(mode, SUSPEND_TEST_NONE);
-- 
2.20.1

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2019-02-28 18:56 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20  1:13 [igt-dev] [igt PATCH 0/1] lib: igt@i915_suspend@shrink faster Caz Yokoyama
2019-02-19 19:05 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-02-19 22:37 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-02-19 22:49 ` [igt-dev] ✓ Fi.CI.BAT: success for lib: igt@i915_suspend@shrink faster (rev2) Patchwork
2019-02-20  0:53 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-02-20  1:13 ` [igt-dev] [igt PATCH 1/1] igt@i915_suspend@shrink faster Caz Yokoyama
2019-02-19 22:21   ` [igt-dev] [PATCH i-g-t] lib: Incrementally mlock() Chris Wilson
2019-02-20  5:26     ` Ashutosh Dixit
2019-02-20  5:39     ` Ashutosh Dixit
2019-02-20 22:28       ` Caz Yokoyama
2019-02-20 12:01     ` [PATCH i-g-t v2] " Chris Wilson
2019-02-26 17:42     ` [igt-dev] FW: [PATCH i-g-t] " Yokoyama, Caz
2019-02-26 17:42       ` Chris Wilson
2019-02-26 20:34         ` Caz Yokoyama
2019-02-26 21:31           ` Chris Wilson
2019-02-27  0:40             ` Caz Yokoyama
2019-02-27  8:13               ` Chris Wilson
2019-02-20  3:14   ` [igt-dev] [igt PATCH 1/1] igt@i915_suspend@shrink faster Ashutosh Dixit
2019-02-26 17:56 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib: igt@i915_suspend@shrink faster (rev3) Patchwork
2019-02-27 16:29 [igt-dev] [PATCH i-g-t] lib: Incrementally mlock() Chris Wilson
2019-02-27 17:34 ` Caz Yokoyama
2019-02-27 21:15   ` Chris Wilson
2019-02-28 18:56 ` Caz Yokoyama

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.