[PATCH i-g-t 11/15] lib/i915/intel_memory_region: Add new macros and support for igt_collection

Matthew Auld matthew.auld at intel.com
Tue May 11 09:26:53 UTC 2021


From: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

As with new memory region era we will have to cover different sets
of memory regions inside the tests this patch adds support for
generating subtest names according to passed memory region collection.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Signed-off-by: José Roberto de Souza <jose.souza at intel.com>
Cc: Vinay Belgaumkar <vinay.belgaumkar at intel.com>
Cc: Janusz Krzysztofik <janusz.krzysztofik at intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
 lib/i915/intel_memory_region.c | 26 ++++++++++++++++++--------
 lib/i915/intel_memory_region.h | 15 ++++++++++++++-
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 91d3ef18..983ac4df 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -80,9 +80,12 @@ const char *get_memory_region_name(uint32_t region)
 {
 	uint16_t class = MEMORY_TYPE_FROM_REGION(region);
 
-	if (class == I915_MEMORY_CLASS_SYSTEM)
+	switch (class) {
+	case I915_MEMORY_CLASS_SYSTEM:
 		return "smem";
-
+	case I915_MEMORY_CLASS_DEVICE:
+		return "lmem";
+	}
 	igt_assert_f(false, "Unknown memory region");
 }
 
@@ -169,11 +172,13 @@ int __gem_create_in_memory_region_list(int fd, uint32_t *handle, uint64_t size,
 				       struct drm_i915_gem_memory_class_instance *mem_regions,
 				       int num_regions)
 {
-	/* a temporary solution, to be removed when these arguments will be used */
-	(void) mem_regions;
-	(void) num_regions;
+	struct drm_i915_gem_create_ext_memory_regions ext_regions = {
+		.base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS },
+		.num_regions = num_regions,
+		.regions = to_user_pointer(mem_regions),
+	};
 
-	return __gem_create(fd, &size, handle);
+	return __gem_create_ext(fd, &size, handle, &ext_regions.base);
 }
 
 /* gem_create_in_memory_region_list:
@@ -264,8 +269,13 @@ char *memregion_dynamic_subtest_name(struct igt_collection *set)
 		int r;
 
 		region = data->value;
-
-		r = snprintf(p, len, "%s-", get_memory_region_name(region));
+		if (IS_DEVICE_MEMORY_REGION(region))
+			r = snprintf(p, len, "%s%d-",
+				     get_memory_region_name(region),
+				     MEMORY_INSTANCE_FROM_REGION(region));
+		else
+			r = snprintf(p, len, "%s-",
+				     get_memory_region_name(region));
 
 		igt_assert(r > 0);
 		p += r;
diff --git a/lib/i915/intel_memory_region.h b/lib/i915/intel_memory_region.h
index 3e53d8de..e9d1d66d 100644
--- a/lib/i915/intel_memory_region.h
+++ b/lib/i915/intel_memory_region.h
@@ -26,6 +26,9 @@
 #define INTEL_MEMORY_REGION_H
 
 #define I915_SYSTEM_MEMORY I915_MEMORY_CLASS_SYSTEM
+#define I915_DEVICE_MEMORY I915_MEMORY_CLASS_DEVICE
+#define I915_STOLEN_SYSTEM_MEMORY I915_MEMORY_CLASS_STOLEN_SYSTEM
+#define I915_STOLEN_DEVICE_MEMORY I915_MEMORY_CLASS_STOLEN_DEVICE
 
 #define INTEL_MEMORY_REGION_ID(type, instance) ((type) << 16u | (instance))
 #define MEMORY_TYPE_FROM_REGION(r) ((r) >> 16u)
@@ -34,10 +37,19 @@
 #define IS_MEMORY_REGION_TYPE(region, type) \
 	(MEMORY_TYPE_FROM_REGION(region) == type)
 
+#define IS_DEVICE_MEMORY_REGION(region) \
+	IS_MEMORY_REGION_TYPE(region, I915_MEMORY_CLASS_DEVICE)
 #define IS_SYSTEM_MEMORY_REGION(region) \
 	IS_MEMORY_REGION_TYPE(region, I915_MEMORY_CLASS_SYSTEM)
 
+#define IS_STOLEN_MEMORY_REGION(region) \
+	(IS_MEMORY_REGION_TYPE(region, I915_MEMORY_CLASS_STOLEN_SYSTEM) || \
+	 IS_MEMORY_REGION_TYPE(region, I915_MEMORY_CLASS_STOLEN_DEVICE))
+
 #define REGION_SMEM    INTEL_MEMORY_REGION_ID(I915_MEMORY_CLASS_SYSTEM, 0)
+#define REGION_LMEM(n) INTEL_MEMORY_REGION_ID(I915_MEMORY_CLASS_DEVICE, (n))
+#define REGION_STLN_SMEM(n) INTEL_MEMORY_REGION_ID(I915_MEMORY_CLASS_STOLEN_SYSTEM, (n))
+#define REGION_STLN_LMEM(n) INTEL_MEMORY_REGION_ID(I915_MEMORY_CLASS_STOLEN_DEVICE, (n))
 
 bool gem_has_query_support(int fd);
 
@@ -89,7 +101,8 @@ __get_memory_region_set(struct drm_i915_query_memory_regions *regions,
 
 /*
  * Helper macro to create igt_collection which contains all memory regions
- * which matches mem_region_types array.
+ * which matches mem_region_types array. Useful to filter out stolen memory
+ * from accessible memory regions.
  */
 #define get_memory_region_set(regions, mem_region_types...) ({ \
 	unsigned int arr__[] = { mem_region_types }; \
-- 
2.26.3



More information about the Intel-gfx-trybot mailing list