[igt-dev] [PATCH i-g-t 5/5] lib/i915/intel_memory_region: wrappers for memory regions ops

Ramalingam C ramalingam.c at intel.com
Mon Jan 27 17:02:05 UTC 2020


For the IGT tests concerned on memory regions we need a means of
identifying the local memory availability.

Eventually these data will be provided through IOCTLs. But till then
to stabilize the local memory support by testing difference features on
local memory we have exposed these details through a debugfs called
"i915_gem_objects"

At this patch we are creating the wrappers for the detection of the
local memory. These wrappers will enable us to migrate to IOCTLs
with less or no impact to the IGT tests using this wrappers.

Signed-off-by: Ramalingam C <ramalingam.c at intel.com>
cc: Zbigniew Kempczy_ski <zbigniew.kempczynski at intel.com>
cc: Vinay Belgaumkar <vinay.belgaumkar at intel.com>
cc: Matthew Auld <matthew.auld at intel.com>
cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/Makefile.sources           |  2 +
 lib/i915/intel_memory_region.c | 72 ++++++++++++++++++++++++++++++++++
 lib/i915/intel_memory_region.h | 29 ++++++++++++++
 lib/meson.build                |  1 +
 4 files changed, 104 insertions(+)
 create mode 100644 lib/i915/intel_memory_region.c
 create mode 100644 lib/i915/intel_memory_region.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 631d6714e5ce..32832d22a84a 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -17,6 +17,8 @@ lib_source_list =	 	\
 	i915/gem_mman.h	\
 	i915/gem_vm.c	\
 	i915/gem_vm.h	\
+	i915/intel_memory_region.c \
+	i915/intel_memory_region.h \
 	i915_3d.h		\
 	i915_reg.h		\
 	i915_pciids.h		\
diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
new file mode 100644
index 000000000000..c0f06b1cd26d
--- /dev/null
+++ b/lib/i915/intel_memory_region.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+#include "intel_reg.h"
+#include "drmtest.h"
+#include "ioctl_wrappers.h"
+#include "igt_dummyload.h"
+#include "igt_gt.h"
+#include "intel_chipset.h"
+
+#include "i915/intel_memory_region.h"
+
+#define MAX_I915_GEM_OBJ_BUF_LEN	1000
+
+static int get_i915_gem_objects_str(int drm_fd, char *buf)
+{
+	int fd, len;
+
+	fd = igt_debugfs_dir(drm_fd);
+	if (fd < 0)
+		return -ENODEV;
+
+	len = igt_debugfs_simple_read(fd, "i915_gem_objects", buf,
+				      MAX_I915_GEM_OBJ_BUF_LEN - 1);
+	close(fd);
+	if (len < 0)
+		return len;
+
+	return 0;
+}
+
+/**
+ * gem_has_lmem:
+ * @fd: open i915 drm file descriptor
+ *
+ * Helper function to check if lmem is available on device.
+ *
+ * Returns: True if at least one lmem region was found.
+ */
+bool gem_has_lmem(int fd)
+{
+	char buf[MAX_I915_GEM_OBJ_BUF_LEN];
+
+	if (get_i915_gem_objects_str(fd, buf) < 0)
+		return false;
+
+	return strstr(buf, "local");
+}
diff --git a/lib/i915/intel_memory_region.h b/lib/i915/intel_memory_region.h
new file mode 100644
index 000000000000..233a6c62e925
--- /dev/null
+++ b/lib/i915/intel_memory_region.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef INTEL_MEMORY_REGION_H
+#define INTEL_MEMORY_REGION_H
+
+bool gem_has_lmem(int fd);
+
+#endif /* INTEL_MEMORY_REGION_H */
diff --git a/lib/meson.build b/lib/meson.build
index d87546185ade..0eb3e7238228 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -7,6 +7,7 @@ lib_sources = [
 	'i915/gem_ring.c',
 	'i915/gem_mman.c',
 	'i915/gem_vm.c',
+	'i915/intel_memory_region.c',
 	'igt_collection.c',
 	'igt_color_encoding.c',
 	'igt_debugfs.c',
-- 
2.20.1



More information about the igt-dev mailing list