Skip to contentSkip to conversation

Reduce the time for which 'struct_mutex' is held

PATCH New [email protected] 1 participant 4 messages Aug 27, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Reduce the time for which 'struct_mutex' is held

From: Ankitprasad Sharma <[email protected]>

We are trying to reduce the time for which the global 'struct_mutex' is locked. Execbuffer ioctl is one place where it is generally held for the longest time. And sometimes because of this occasional glitches/flickers are observed in 60 fps playback (due to miss of V-blank intervals) as page flip calls gets blocked/delayed because the 'struct_mutex' is already locked.

For this, we have exposed two new flags in GEM_CREATE ioctl, to pre-populate the object with system memory pages and also do an immediate clflush for the new pages.

The third patch too tries to reduce the 'struct_mutex' lock time by moving only those objects to CPU domain in put_pages(), that can either be used in the future or had a CPU mapping.

v2: Addressed comments from Chris/Arun. Fixed warnings in clflush of pre-populated pages.

This series is based on an earlier series of Stolen Memory patches, extending the GEM_CREATE ioctl further
http://lists.freedesktop.org/archives/intel-gfx/2015-July/072199.html

Ankitprasad Sharma (2):
drm/i915: Support for pre-populating the object with system pages drm/i915: Support for the clflush of pre-populated pages

Chris Wilson (1):
drm/i915: Only move to the CPU write domain if keeping the GTT pages

 drivers/gpu/drm/i915/i915_dma.c |   2 +-
 drivers/gpu/drm/i915/i915_drv.h |   5 ++
 drivers/gpu/drm/i915/i915_gem.c | 119 ++++++++++++++++++++++++++++++++--------
 include/uapi/drm/i915_drm.h     |  12 ++--
 4 files changed, 109 insertions(+), 29 deletions(-)
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v2 1/3 drm/i915: Support for pre-populating the object with system pages

From: Ankitprasad Sharma <[email protected]>

This patch provides support for the User to populate the object with system pages at its creation time. Since this can be safely performed without holding the 'struct_mutex', it would help to reduce the time 'struct_mutex' is kept locked especially during the exec-buffer path, where it is generally held for the longest time.

v2: Corrected error handling on pre-populate failure (Arun), wrap list_add_tail() in __i915_gem_object_get_pages__tail_locked(), moved error handling to the caller (Chris)

---
 drivers/gpu/drm/i915/i915_dma.c |  2 +-
 drivers/gpu/drm/i915/i915_gem.c | 50 +++++++++++++++++++++++++++++++++++------
 include/uapi/drm/i915_drm.h     | 11 +++++----
 3 files changed, 49 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -1
index 8319e07..955aa16 100644
@@ -171,7 +171,7 @@ static int i915_getparam(struct drm_device *dev, void *data,
 		value = HAS_RESOURCE_STREAMER(dev);
 		break;
 	case I915_PARAM_CREATE_VERSION:
-		value = 2;
+		value = 3;
 		break;
 	default:
 		DRM_DEBUG("Unknown parameter %d\n", param->param);
drivers/gpu/drm/i915/i915_gem.c +43 -7

83 lines not on this page · raw message

include/uapi/drm/i915_drm.h +5 -6
index f71f75c..26ea715 100644
@@ -457,20 +457,19 @@ struct drm_i915_gem_create {
 	__u32 handle;
 	__u32 pad;
 	/**
-	 * Requested flags (currently used for placement
-	 * (which memory domain))
+	 * Requested flags
 	 *
 	 * You can request that the object be created from special memory
 	 * rather than regular system pages using this parameter. Such
 	 * irregular objects may have certain restrictions (such as CPU
 	 * access to a stolen object is verboten).
-	 *
-	 * This can be used in the future for other purposes too
-	 * e.g. specifying tiling/caching/madvise
+	 * Also using this parameter object can be pre-populated with system
+	 * pages.
 	 */
 	__u32 flags;
 #define I915_CREATE_PLACEMENT_STOLEN 	(1<<0) /* Cannot use CPU mmaps */
-#define __I915_CREATE_UNKNOWN_FLAGS	-(I915_CREATE_PLACEMENT_STOLEN << 1)
+#define I915_CREATE_POPULATE		(1<<1) /* Pre-populate object pages */
+#define __I915_CREATE_UNKNOWN_FLAGS	-(I915_CREATE_POPULATE << 1)
 };
 
 struct drm_i915_gem_pread {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v2 2/3 drm/i915: Support for the clflush of pre-populated pages

In reply to [email protected]

From: Ankitprasad Sharma <[email protected]>

This patch provides a support for the User to immediately flush out the cachelines for the pre-populated pages of an object, at the time of its creation. This will not lead to any redundancy and would further reduce the time for which the 'struct_mutex' is kept locked in execbuffer path, as cache flush of the newly allocated pages is anyways done when the object is submitted to GPU.

v2: flush_cpu_write_domain expects the struct mutex to be locked which was triggerring WARN_ONs, hence doing the required changes in an inline manner (Ankit)

---
 drivers/gpu/drm/i915/i915_dma.c | 2 +-
 drivers/gpu/drm/i915/i915_gem.c | 7 +++++++
 include/uapi/drm/i915_drm.h     | 3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +1 -1
index 955aa16..eb0b31d 100644
@@ -171,7 +171,7 @@ static int i915_getparam(struct drm_device *dev, void *data,
 		value = HAS_RESOURCE_STREAMER(dev);
 		break;
 	case I915_PARAM_CREATE_VERSION:
-		value = 3;
+		value = 4;
 		break;
 	default:
 		DRM_DEBUG("Unknown parameter %d\n", param->param);
drivers/gpu/drm/i915/i915_gem.c +7 -0
index 4430128..fa4cfb0 100644
@@ -426,6 +426,13 @@ i915_gem_create(struct drm_file *file,
 			return ret;
 		}
 
+		if (flags & I915_CREATE_FLUSH) {
+			if (i915_gem_clflush_object(obj, false))
+				i915_gem_chipset_flush(obj->base.dev);
+
+			obj->base.write_domain = 0;
+		}
+
 		mutex_lock(&dev->struct_mutex);
 		__i915_gem_object_get_pages__tail_locked(obj);
 		mutex_unlock(&dev->struct_mutex);
include/uapi/drm/i915_drm.h +2 -1
index 26ea715..547305a 100644
@@ -469,7 +469,8 @@ struct drm_i915_gem_create {
 	__u32 flags;
 #define I915_CREATE_PLACEMENT_STOLEN 	(1<<0) /* Cannot use CPU mmaps */
 #define I915_CREATE_POPULATE		(1<<1) /* Pre-populate object pages */
-#define __I915_CREATE_UNKNOWN_FLAGS	-(I915_CREATE_POPULATE << 1)
+#define I915_CREATE_FLUSH		(1<<2) /* Clflush prepopulated pages */
+#define __I915_CREATE_UNKNOWN_FLAGS	-(I915_CREATE_FLUSH << 1)
 };
 
 struct drm_i915_gem_pread {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH v2 3/3 drm/i915: Only move to the CPU write domain if keeping the GTT pages

In reply to [email protected]

From: Chris Wilson <[email protected]>

We have for a long time been ultra-paranoid about the situation whereby we hand back pages to the system that have been written to by the GPU and potentially simultaneously by the user through a CPU mmapping. We can relax this restriction when we know that the cache domain tracking is true and there can be no stale cacheline invalidatations. This is true if the object has never been CPU mmaped as all internal accesses (i.e. kmap/iomap) are carefully flushed. For a CPU mmaping, one would expect that the invalid cache lines are resolved on PTE/TLB shootdown during munmap(), so the only situation we need to be paranoid about is when such a CPU mmaping exists at the time of put_pages. Given that we need to treat put_pages carefully as we may return live data to the system that we want to use again in the future (i.e. I915_MADV_WILLNEED pages) we can simply treat a live CPU mmaping as a special case of WILLNEED (which it is!). Any I915_MADV_DONTNEED pages and their mmapings are shot down immediately following put_pages.

v2: Add a new flag to check if ever a cached CPU mapping was created for the object. This is needed as we have verified that the CPU cachelines are not invalidated upon munmap(). So to ensure correctness, object still needs to be moved to CPU write domain in put_pages(), even if there are no live CPU mappings for I915_MADV_DONTNEED pages.

v3: Formatted comments, removed redundant braces (Chris)

---
 drivers/gpu/drm/i915/i915_drv.h |  5 ++++
 drivers/gpu/drm/i915/i915_gem.c | 62 +++++++++++++++++++++++++++++++----------
 2 files changed, 52 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +5 -0
index 8db905a..bb85401 100644
@@ -2096,6 +2096,11 @@ struct drm_i915_gem_object {
 
 	unsigned int frontbuffer_bits:INTEL_FRONTBUFFER_BITS;
 
+	/*
+	 * Whether the object was ever mapped with cached CPU mapping
+	 */
+	unsigned int has_stale_cachelines:1;
+
 	unsigned int pin_display;
 
 	struct sg_table *pages;
drivers/gpu/drm/i915/i915_gem.c +47 -15

78 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx