Skip to contentSkip to conversation

drm/radeon: add error handling to fence_wait_empty_locked

PATCH In review Christian König 3 participants 4 messages Jul 4, 2012

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

PATCH 1/2 drm/radeon: add error handling to fence_wait_empty_locked

Instead of returning the error handle it directly and while at it fix the comments about the ring lock.

---
 drivers/gpu/drm/radeon/radeon.h       |    2 +-
 drivers/gpu/drm/radeon/radeon_fence.c |   33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -1
index 77b4519b..5861ec8 100644
@@ -239,7 +239,7 @@ void radeon_fence_process(struct radeon_device *rdev, int ring);
 bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
 int radeon_fence_wait_any(struct radeon_device *rdev,
 			  struct radeon_fence **fences,
 			  bool intr);
drivers/gpu/drm/radeon/radeon_fence.c +21 -12
index 7b55625..be4e4f3 100644
@@ -440,14 +440,11 @@ int radeon_fence_wait_any(struct radeon_device *rdev,
 	return 0;
 }
 
+/* caller must hold ring lock */
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
 {
 	uint64_t seq;
 
-	/* We are not protected by ring lock when reading current seq but
-	 * it's ok as worst case is we return to early while we could have
-	 * wait.
-	 */
 	seq = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
 	if (seq >= rdev->fence_drv[ring].sync_seq[ring]) {
 		/* nothing to wait for, last_seq is
@@ -457,15 +454,27 @@ int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
 	return radeon_fence_wait_seq(rdev, seq, ring, false, false);
 }
 
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
+/* caller must hold ring lock */
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
 {
-	/* We are not protected by ring lock when reading current seq
-	 * but it's ok as wait empty is call from place where no more
-	 * activity can be scheduled so there won't be concurrent access
-	 * to seq value.
-	 */
-	return radeon_fence_wait_seq(rdev, rdev->fence_drv[ring].sync_seq[ring],
-				     ring, false, false);
+	uint64_t seq = rdev->fence_drv[ring].sync_seq[ring];
+
+	while(1) {
+		int r;
+		r = radeon_fence_wait_seq(rdev, seq, ring, false, false);
+		if (r == -EDEADLK) {
+			mutex_unlock(&rdev->ring_lock);
+			r = radeon_gpu_reset(rdev);
+			mutex_lock(&rdev->ring_lock);
+			if (!r)
+				continue;
+		}
+		if (r) {
+			dev_err(rdev->dev, "error waiting for ring to become"
+				" idle (%d)\n", r);
+		}
+		return;
+	}
 }
 
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
Signature · 6 lines
1.7.9.5

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

PATCH 2/2 drm/radeon: add error handling to radeon_vm_unbind_locked

Waiting for a fence can fail for different reasons, the most common is a deadlock.

---
 drivers/gpu/drm/radeon/radeon_gart.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_gart.c +14 -3
index 2b34c1a..ee11c50 100644
@@ -316,10 +316,21 @@ static void radeon_vm_unbind_locked(struct radeon_device *rdev,
 	}
 
 	/* wait for vm use to end */
-	if (vm->fence) {
-		radeon_fence_wait(vm->fence, false);
-		radeon_fence_unref(&vm->fence);
+	while (vm->fence) {
+		int r;
+		r = radeon_fence_wait(vm->fence, false);
+		if (r)
+			DRM_ERROR("error while waiting for fence: %d\n", r);
+		if (r == -EDEADLK) {
+			mutex_unlock(&rdev->vm_manager.lock);
+			r = radeon_gpu_reset(rdev);
+			mutex_lock(&rdev->vm_manager.lock);
+			if (!r)
+				continue;
+		}
+		break;
 	}
+	radeon_fence_unref(&vm->fence);
 
 	/* hw unbind */
 	rdev->vm_manager.funcs->unbind(rdev, vm);
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#2 lore raw
In reply to Christian König
Quoted 5 lines · Christian König

Instead of returning the error handle it directly and while at it fix the comments about the ring lock.

For the series:

Quoted 81 lines
---
 drivers/gpu/drm/radeon/radeon.h       |    2 +-
 drivers/gpu/drm/radeon/radeon_fence.c |   33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -1
index 77b4519b..5861ec8 100644
@@ -239,7 +239,7 @@ void radeon_fence_process(struct radeon_device *rdev, int ring);
 bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
 int radeon_fence_wait_any(struct radeon_device *rdev,
                          struct radeon_fence **fences,
                          bool intr);
drivers/gpu/drm/radeon/radeon_fence.c +21 -13
index 7b55625..be4e4f3 100644
@@ -440,14 +440,11 @@ int radeon_fence_wait_any(struct radeon_device *rdev,
        return 0;
 }
 
+/* caller must hold ring lock */
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
 {
        uint64_t seq;
 
-       /* We are not protected by ring lock when reading current seq but
-        * it's ok as worst case is we return to early while we could have
-        * wait.
-        */
        seq = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
        if (seq >= rdev->fence_drv[ring].sync_seq[ring]) {
                /* nothing to wait for, last_seq is
@@ -457,15 +454,27 @@ int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
        return radeon_fence_wait_seq(rdev, seq, ring, false, false);
 }
 
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
+/* caller must hold ring lock */
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
 {
-       /* We are not protected by ring lock when reading current seq
-        * but it's ok as wait empty is call from place where no more
-        * activity can be scheduled so there won't be concurrent access
-        * to seq value.
-        */
-       return radeon_fence_wait_seq(rdev, rdev->fence_drv[ring].sync_seq[ring],
-                                    ring, false, false);
+       uint64_t seq = rdev->fence_drv[ring].sync_seq[ring];
+
+       while(1) {
+               int r;
+               r = radeon_fence_wait_seq(rdev, seq, ring, false, false);
+               if (r == -EDEADLK) {
+                       mutex_unlock(&rdev->ring_lock);
+                       r = radeon_gpu_reset(rdev);
+                       mutex_lock(&rdev->ring_lock);
+                       if (!r)
+                               continue;
+               }
+               if (r) {
+                       dev_err(rdev->dev, "error waiting for ring to become"
+                               " idle (%d)\n", r);
+               }
+               return;
+       }
 }
 
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
--

1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#3 lore raw
Quoted 10 lines · Alex Deucher
Quoted 5 lines · Christian König

Instead of returning the error handle it directly and while at it fix the comments about the ring lock.

For the series:

Quoted 85 lines
Quoted 77 lines
---
 drivers/gpu/drm/radeon/radeon.h       |    2 +-
 drivers/gpu/drm/radeon/radeon_fence.c |   33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -1
index 77b4519b..5861ec8 100644
@@ -239,7 +239,7 @@ void radeon_fence_process(struct radeon_device *rdev, int ring);
 bool radeon_fence_signaled(struct radeon_fence *fence);
 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
 int radeon_fence_wait_any(struct radeon_device *rdev,
                          struct radeon_fence **fences,
                          bool intr);
drivers/gpu/drm/radeon/radeon_fence.c +21 -13
index 7b55625..be4e4f3 100644
@@ -440,14 +440,11 @@ int radeon_fence_wait_any(struct radeon_device *rdev,
        return 0;
 }
 
+/* caller must hold ring lock */
 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
 {
        uint64_t seq;
 
-       /* We are not protected by ring lock when reading current seq but
-        * it's ok as worst case is we return to early while we could have
-        * wait.
-        */
        seq = atomic64_read(&rdev->fence_drv[ring].last_seq) + 1ULL;
        if (seq >= rdev->fence_drv[ring].sync_seq[ring]) {
                /* nothing to wait for, last_seq is
@@ -457,15 +454,27 @@ int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring)
        return radeon_fence_wait_seq(rdev, seq, ring, false, false);
 }
 
-int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
+/* caller must hold ring lock */
+void radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring)
 {
-       /* We are not protected by ring lock when reading current seq
-        * but it's ok as wait empty is call from place where no more
-        * activity can be scheduled so there won't be concurrent access
-        * to seq value.
-        */
-       return radeon_fence_wait_seq(rdev, rdev->fence_drv[ring].sync_seq[ring],
-                                    ring, false, false);
+       uint64_t seq = rdev->fence_drv[ring].sync_seq[ring];
+
+       while(1) {
+               int r;
+               r = radeon_fence_wait_seq(rdev, seq, ring, false, false);
+               if (r == -EDEADLK) {
+                       mutex_unlock(&rdev->ring_lock);
+                       r = radeon_gpu_reset(rdev);
+                       mutex_lock(&rdev->ring_lock);
+                       if (!r)
+                               continue;
+               }
+               if (r) {
+                       dev_err(rdev->dev, "error waiting for ring to become"
+                               " idle (%d)\n", r);
+               }
+               return;
+       }
 }
 
 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence)
--

1.7.9.5

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel