Skip to contentSkip to conversation

drm/atomic: Interruptible locks for everyone!

PATCH Superseded Maarten Lankhorst 1 participant 8 messages Sep 12, 2017

Subsystems (2)
lore
Share & tools
lore

Maarten Lankhorst

author maintainer
#0 lore raw

v2 cover drm/atomic: Interruptible locks for everyone!

drm_atomic_commit could previous have always failed when waits failed, but locking was always done uninterruptibly. Add infrastructure to make it possible for callers to choose interruptible locking, and convert the 5 most common ioctl's to use it.

All other atomic helpers can be converted when additional tests are added to kms_atomic_interruptible.

Changes since last version:
- Small fixes to the preparation patch
- Convert setcrtc as well.

Maarten Lankhorst (6):
drm/atomic: Prepare drm_modeset_lock infrastructure for interruptible
waiting, v2.
drm/atomic: Convert atomic ioctl locking to interruptible. drm/legacy: Convert cursor ioctl locking to interruptible. drm/legacy: Convert setplane ioctl locking to interruptible. drm/atomic: Convert pageflip ioctl locking to interruptible. drm/crtc: Convert setcrtc ioctl locking to interruptible.

 drivers/gpu/drm/drm_atomic.c       |  7 +--
 drivers/gpu/drm/drm_crtc.c         |  7 +--
 drivers/gpu/drm/drm_debugfs_crc.c  |  2 +-
 drivers/gpu/drm/drm_modeset_lock.c | 96 +++++++++++++++++++-------------------
 drivers/gpu/drm/drm_plane.c        | 21 +++++----
 include/drm/drm_modeset_lock.h     | 12 +++--
 6 files changed, 77 insertions(+), 68 deletions(-)
Signature · 6 lines
2.14.1

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

PATCH v2 1/6 drm/atomic: Prepare drm_modeset_lock infrastructure for interruptible waiting, v2.

When we want to make drm_atomic_commit interruptible, there are a lot of places that call the lock function, which we don't have control over.

Rather than trying to convert every single one, it's easier to toggle interruptible waiting per acquire_ctx. If drm_modeset_acquire_init is called with DRM_MODESET_ACQUIRE_INTERRUPTIBLE, then we will perform interruptible waits in drm_modeset_lock and drm_modeset_backoff.

Changes since v1:
- Fix locking example in drm_modeset_lock.c to be compatible with interruptible waiting (xexaxo) and make it default. Uninterruptible waiting shouldn't happen except in corner cases, but the example will still apply if the flag is removed.
- Add drm_modeset_lock_single_interruptible() to documentation.
- Fix dead link to removed drm_modeset_lock_interruptible() in drm_modeset_lock().

---
 drivers/gpu/drm/drm_debugfs_crc.c  |  2 +-
 drivers/gpu/drm/drm_modeset_lock.c | 96 +++++++++++++++++++-------------------
 include/drm/drm_modeset_lock.h     | 12 +++--
 3 files changed, 57 insertions(+), 53 deletions(-)
drivers/gpu/drm/drm_debugfs_crc.c +1 -1
index f9e26dda56d6..9dd879589a2c 100644
@@ -155,7 +155,7 @@ static int crtc_crc_open(struct inode *inode, struct file *filep)
 	int ret = 0;
 
 	if (drm_drv_uses_atomic_modeset(crtc->dev)) {
-		ret = drm_modeset_lock_interruptible(&crtc->mutex, NULL);
+		ret = drm_modeset_lock_single_interruptible(&crtc->mutex);
 		if (ret)
 			return ret;
 
drivers/gpu/drm/drm_modeset_lock.c +48 -48

162 lines not on this page · raw message

include/drm/drm_modeset_lock.h +8 -4
index 4b27c2bb955c..a685d1bb21f2 100644
@@ -34,6 +34,7 @@ struct drm_modeset_lock;
  * @contended: used internally for -EDEADLK handling
  * @locked: list of held locks
  * @trylock_only: trylock mode used in atomic contexts/panic notifiers
+ * @interruptible: whether interruptible locking should be used.
  *
  * Each thread competing for a set of locks must use one acquire
  * ctx.  And if any lock fxn returns -EDEADLK, it must backoff and
@@ -59,6 +60,9 @@ struct drm_modeset_acquire_ctx {
 	 * Trylock mode, use only for panic handlers!
 	 */
 	bool trylock_only;
+
+	/* Perform interruptible waits on this context. */
+	bool interruptible;
 };
 
 /**
@@ -82,12 +86,13 @@ struct drm_modeset_lock {
 	struct list_head head;
 };
 
+#define DRM_MODESET_ACQUIRE_INTERRUPTIBLE BIT(0)
+
 void drm_modeset_acquire_init(struct drm_modeset_acquire_ctx *ctx,
 		uint32_t flags);
 void drm_modeset_acquire_fini(struct drm_modeset_acquire_ctx *ctx);
 void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx);
-void drm_modeset_backoff(struct drm_modeset_acquire_ctx *ctx);
-int drm_modeset_backoff_interruptible(struct drm_modeset_acquire_ctx *ctx);
+int drm_modeset_backoff(struct drm_modeset_acquire_ctx *ctx);
 
 void drm_modeset_lock_init(struct drm_modeset_lock *lock);
 
@@ -111,8 +116,7 @@ static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)
 
 int drm_modeset_lock(struct drm_modeset_lock *lock,
 		struct drm_modeset_acquire_ctx *ctx);
-int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
-		struct drm_modeset_acquire_ctx *ctx);
+int __must_check drm_modeset_lock_single_interruptible(struct drm_modeset_lock *lock);
 void drm_modeset_unlock(struct drm_modeset_lock *lock);
 
 struct drm_device;
Signature · 6 lines
2.14.1

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

PATCH v2 2/6 drm/atomic: Convert atomic ioctl locking to interruptible.

In reply to Maarten Lankhorst

Pass DRM_MODESET_ACQUIRE_INTERRUPTIBLE to acquire_init, and handle drm_modeset_backoff which can now fail by returning the error.

---
 drivers/gpu/drm/drm_atomic.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic.c +4 -3
index 75f5f74de9bf..366c56fe5f58 100644
@@ -2234,7 +2234,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 			(arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
 		return -EINVAL;
 
-	drm_modeset_acquire_init(&ctx, 0);
+	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 
 	state = drm_atomic_state_alloc(dev);
 	if (!state)
@@ -2347,8 +2347,9 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 
 	if (ret == -EDEADLK) {
 		drm_atomic_state_clear(state);
-		drm_modeset_backoff(&ctx);
-		goto retry;
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry;
 	}
 
 	drm_atomic_state_put(state);
Signature · 6 lines
2.14.1

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

PATCH v2 3/6 drm/legacy: Convert cursor ioctl locking to interruptible.

In reply to Maarten Lankhorst

Pass DRM_MODESET_ACQUIRE_INTERRUPTIBLE to acquire_init, and handle drm_modeset_backoff which can now fail by returning the error.

---
 drivers/gpu/drm/drm_plane.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_plane.c +4 -3
index 7a00351d5b5d..eef58595101c 100644
@@ -834,7 +834,7 @@ static int drm_mode_cursor_common(struct drm_device *dev,
 		return -ENOENT;
 	}
 
-	drm_modeset_acquire_init(&ctx, 0);
+	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 retry:
 	ret = drm_modeset_lock(&crtc->mutex, &ctx);
 	if (ret)
@@ -876,8 +876,9 @@ static int drm_mode_cursor_common(struct drm_device *dev,
 	}
 out:
 	if (ret == -EDEADLK) {
-		drm_modeset_backoff(&ctx);
-		goto retry;
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry;
 	}
 
 	drm_modeset_drop_locks(&ctx);
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#4 lore raw

PATCH v2 4/6 drm/legacy: Convert setplane ioctl locking to interruptible.

In reply to Maarten Lankhorst

Pass DRM_MODESET_ACQUIRE_INTERRUPTIBLE to acquire_init, and handle drm_modeset_backoff which can now fail by returning the error.

---
 drivers/gpu/drm/drm_plane.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_plane.c +4 -3
index eef58595101c..803d67c22da2 100644
@@ -667,7 +667,7 @@ static int setplane_internal(struct drm_plane *plane,
 	struct drm_modeset_acquire_ctx ctx;
 	int ret;
 
-	drm_modeset_acquire_init(&ctx, 0);
+	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 retry:
 	ret = drm_modeset_lock_all_ctx(plane->dev, &ctx);
 	if (ret)
@@ -678,8 +678,9 @@ static int setplane_internal(struct drm_plane *plane,
 
 fail:
 	if (ret == -EDEADLK) {
-		drm_modeset_backoff(&ctx);
-		goto retry;
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry;
 	}
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#5 lore raw

PATCH v2 5/6 drm/atomic: Convert pageflip ioctl locking to interruptible.

In reply to Maarten Lankhorst

Pass DRM_MODESET_ACQUIRE_INTERRUPTIBLE to acquire_init, and handle drm_modeset_backoff which can now fail by returning the error.

---
 drivers/gpu/drm/drm_plane.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_plane.c +4 -3
index 803d67c22da2..72cba9805edc 100644
@@ -987,7 +987,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 		return -EINVAL;
 	}
 
-	drm_modeset_acquire_init(&ctx, 0);
+	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 retry:
 	ret = drm_modeset_lock(&crtc->mutex, &ctx);
 	if (ret)
@@ -1076,8 +1076,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
 	crtc->primary->old_fb = NULL;
 
 	if (ret == -EDEADLK) {
-		drm_modeset_backoff(&ctx);
-		goto retry;
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry;
 	}
 
 	drm_modeset_drop_locks(&ctx);
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#6 lore raw

PATCH v2 6/6 drm/crtc: Convert setcrtc ioctl locking to interruptible.

In reply to Maarten Lankhorst

Pass DRM_MODESET_ACQUIRE_INTERRUPTIBLE to acquire_init, and handle drm_modeset_backoff which can now fail by returning the error.

---
 drivers/gpu/drm/drm_crtc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_crtc.c +4 -3
index 5af25ce5bf7c..68b4e976d5e0 100644
@@ -577,7 +577,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 	DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
 
 	mutex_lock(&crtc->dev->mode_config.mutex);
-	drm_modeset_acquire_init(&ctx, 0);
+	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
 retry:
 	ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx);
 	if (ret)
@@ -717,8 +717,9 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 	kfree(connector_set);
 	drm_mode_destroy(dev, mode);
 	if (ret == -EDEADLK) {
-		drm_modeset_backoff(&ctx);
-		goto retry;
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry;
 	}
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
Signature · 6 lines
2.14.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#7 lore raw
In reply to Maarten Lankhorst

Op 12-09-17 om 14:41 schreef Maarten Lankhorst:

Quoted 21 lines

drm_atomic_commit could previous have always failed when waits failed, but locking was always done uninterruptibly. Add infrastructure to make it possible for callers to choose interruptible locking, and convert the 5 most common ioctl's to use it.

All other atomic helpers can be converted when additional tests are added to kms_atomic_interruptible.

Changes since last version:
- Small fixes to the preparation patch
- Convert setcrtc as well.

Maarten Lankhorst (6):
drm/atomic: Prepare drm_modeset_lock infrastructure for interruptible
waiting, v2.
drm/atomic: Convert atomic ioctl locking to interruptible. drm/legacy: Convert cursor ioctl locking to interruptible. drm/legacy: Convert setplane ioctl locking to interruptible. drm/atomic: Convert pageflip ioctl locking to interruptible. drm/crtc: Convert setcrtc ioctl locking to interruptible.

Quoted 8 lines
 drivers/gpu/drm/drm_atomic.c       |  7 +--
 drivers/gpu/drm/drm_crtc.c         |  7 +--
 drivers/gpu/drm/drm_debugfs_crc.c  |  2 +-
 drivers/gpu/drm/drm_modeset_lock.c | 96 +++++++++++++++++++-------------------
 drivers/gpu/drm/drm_plane.c        | 21 +++++----
 include/drm/drm_modeset_lock.h     | 12 +++--
 6 files changed, 77 insertions(+), 68 deletions(-)

Please ignore this series, should have been sent to dri-devel with intel-gfx to cc. I'm resending.

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