public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Antonio Argenziano <antonio.argenziano@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Matthew Auld <matthew.auld@intel.com>
Subject: [igt-dev] [RFT v4 6/6] igt/lib: If mappable aperture is missing return 0 size
Date: Mon, 25 Mar 2019 16:20:43 -0700	[thread overview]
Message-ID: <20190325232043.7953-6-antonio.argenziano@intel.com> (raw)
In-Reply-To: <20190325232043.7953-1-antonio.argenziano@intel.com>

So far the aperture size has been read directly from the bar,
in this patch we return zero if the mappable aperture is not available
as the value stored in the bar is not accurate. The patch also adds a
'require' when a call to gem_mappable_aperture_size() is made so that
the aperture is guaranteed to exist before checking the size.

Cc: Katarzyna Dec <katarzyna.dec@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
---
 lib/ioctl_wrappers.c       | 26 ++++++++++++++++++--------
 lib/ioctl_wrappers.h       |  1 +
 tests/i915/gem_cpu_reloc.c | 14 ++++++++++----
 tests/prime_mmap.c         |  7 +++++--
 4 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index a66eb4bc..c903d05c 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1089,6 +1089,22 @@ uint64_t gem_aperture_size(int fd)
 	return aperture_size;
 }
 
+static uint64_t __gem_mappable_aperture_size(int fd)
+{
+	struct pci_device *pci_dev = igt_device_get_pci_device(fd);
+	int bar;
+
+	if (!gem_mmap__has_gtt(fd))
+		return 0; /* Aperture not available */
+
+	if (intel_gen(pci_dev->device_id) < 3)
+		bar = 0;
+	else
+		bar = 2;
+
+	return pci_dev->regions[bar].size;
+}
+
 /**
  * gem_mappable_aperture_size:
  *
@@ -1099,15 +1115,9 @@ uint64_t gem_aperture_size(int fd)
  */
 uint64_t gem_mappable_aperture_size(int fd)
 {
-	struct pci_device *pci_dev = igt_device_get_pci_device(fd);
-	int bar;
-
-	if (intel_gen(pci_dev->device_id) < 3)
-		bar = 0;
-	else
-		bar = 2;
+	gem_require_mmap_gtt(fd);
 
-	return pci_dev->regions[bar].size;
+	return __gem_mappable_aperture_size(fd);
 }
 
 /**
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index ad93daff..b3b0313e 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -38,6 +38,7 @@
 
 #include "i915/gem_context.h"
 #include "i915/gem_scheduler.h"
+#include "i915/gem_mman.h"
 
 /**
  * igt_ioctl:
diff --git a/tests/i915/gem_cpu_reloc.c b/tests/i915/gem_cpu_reloc.c
index 17c2fe11..58fd4470 100644
--- a/tests/i915/gem_cpu_reloc.c
+++ b/tests/i915/gem_cpu_reloc.c
@@ -283,8 +283,11 @@ igt_main
 		run_test(i915, 1);
 
 	igt_subtest("full") {
-		uint64_t aper_size = gem_mappable_aperture_size(i915);
-		unsigned long count = aper_size / 4096 + 1;
+		uint64_t aper_size;
+		unsigned long count;
+
+		aper_size = gem_mappable_aperture_size(i915);
+		count = aper_size / 4096 + 1;
 
 		intel_require_memory(count, 4096, CHECK_RAM);
 
@@ -292,10 +295,13 @@ igt_main
 	}
 
 	igt_subtest("forked") {
-		uint64_t aper_size = gem_mappable_aperture_size(i915);
-		unsigned long count = aper_size / 4096 + 1;
+		uint64_t aper_size;
+		unsigned long count;
 		int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 
+		aper_size = gem_mappable_aperture_size(i915);
+		count = aper_size / 4096 + 1;
+
 		intel_require_memory(count, 4096, CHECK_RAM);
 
 		igt_fork(child, ncpus)
diff --git a/tests/prime_mmap.c b/tests/prime_mmap.c
index f28985da..c844effc 100644
--- a/tests/prime_mmap.c
+++ b/tests/prime_mmap.c
@@ -480,8 +480,11 @@ test_aperture_limit(void)
 	char *ptr1, *ptr2;
 	uint32_t handle1, handle2;
 	/* Two buffers the sum of which > mappable aperture */
-	uint64_t size1 = (gem_mappable_aperture_size(fd) * 7) / 8;
-	uint64_t size2 = (gem_mappable_aperture_size(fd) * 3) / 8;
+	uint64_t size1;
+	uint64_t size2;
+
+	size1 = (gem_mappable_aperture_size(fd) * 7) / 8;
+	size2 = (gem_mappable_aperture_size(fd) * 3) / 8;
 
 	handle1 = gem_create(fd, size1);
 	fill_bo(handle1, BO_SIZE);
-- 
2.20.1

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

  parent reply	other threads:[~2019-03-25 23:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 23:20 [igt-dev] [RFT v4 1/6] lib/i915/gem_mman: Remove static variables Antonio Argenziano
2019-03-25 23:20 ` [igt-dev] [RFT v4 2/6] lib/i915: Add mmap_offset support Antonio Argenziano
2019-03-25 23:20 ` [igt-dev] [RFT v4 3/6] igt/lib: Add wrapper to check if gtt mapping is available Antonio Argenziano
2019-04-16 13:25   ` Katarzyna Dec
2019-04-16 13:28     ` Chris Wilson
2019-04-16 16:43       ` Antonio Argenziano
2019-03-25 23:20 ` [igt-dev] [RFT v4 4/6] igt/i915: Require GTT mapping to be available when needed Antonio Argenziano
2019-03-25 23:36   ` Chris Wilson
2019-03-27 21:05     ` Antonio Argenziano
2019-03-27 21:19       ` Chris Wilson
2019-04-11 18:13         ` Antonio Argenziano
2019-04-11 20:07           ` Chris Wilson
2019-04-11 21:27             ` Antonio Argenziano
2019-03-27 21:24       ` Chris Wilson
2019-04-05 18:00         ` Antonio Argenziano
2019-04-05 18:04           ` Chris Wilson
2019-04-11 18:13       ` Antonio Argenziano
2019-04-11 20:08         ` Chris Wilson
2019-04-16 14:38   ` Katarzyna Dec
2019-03-25 23:20 ` [igt-dev] [RFT v4 5/6] Coherency tests that need to be using WC + sync Antonio Argenziano
2019-04-16 14:43   ` Katarzyna Dec
2019-03-25 23:20 ` Antonio Argenziano [this message]
2019-04-17  9:55   ` [igt-dev] [RFT v4 6/6] igt/lib: If mappable aperture is missing return 0 size Katarzyna Dec
2019-03-26  9:39 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [RFT,v4,1/6] lib/i915/gem_mman: Remove static variables Patchwork
2019-04-16 13:27 ` [igt-dev] [RFT v4 1/6] " Katarzyna Dec
2019-04-16 15:29   ` Antonio Argenziano

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=20190325232043.7953-6-antonio.argenziano@intel.com \
    --to=antonio.argenziano@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    /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