Skip to content

Commit f6ce410

Browse files
Gustavo Padovanatseanpaul
authored andcommitted
drm/fence: allow fence waiting to be interrupted by userspace
If userspace is running an synchronously atomic commit and interrupts the atomic operation during fence_wait() it will hang until the timer expires, so here we change the wait to be interruptible so it stop immediately when userspace wants to quit. Also adds the necessary error checking for fence_wait(). v2: Comment by Daniel Vetter - Add error checking for fence_wait() v3: Rebase on top of new atomic noblocking support v4: Comment by Maarten Lankhorst - remove 'swapped' bitfield as it was duplicating information v5: Comments by Maarten Lankhorst - assign plane->state to plane_state if !intr - squash previous patch into this one v6: Comment by Sean Paul - rename intr to pre_swap Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk> Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> [seanpaul fixed a couple checkpatch warnings and moved the preswap comment] Signed-off-by: Sean Paul <seanpaul@chromium.org> Link: http://patchwork.freedesktop.org/patch/msgid/1473707291-14781-1-git-send-email-gustavo@padovan.org
1 parent f92f053 commit f6ce410

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎drivers/gpu/drm/drm_atomic_helper.c‎

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,29 +1009,46 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables);
10091009
* drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state
10101010
* @dev: DRM device
10111011
* @state: atomic state object with old state structures
1012+
* @pre_swap: if true, do an interruptible wait
10121013
*
10131014
* For implicit sync, driver should fish the exclusive fence out from the
10141015
* incoming fb's and stash it in the drm_plane_state. This is called after
10151016
* drm_atomic_helper_swap_state() so it uses the current plane state (and
10161017
* just uses the atomic state to find the changed planes)
1018+
*
1019+
* Returns zero if success or < 0 if fence_wait() fails.
10171020
*/
1018-
void drm_atomic_helper_wait_for_fences(struct drm_device *dev,
1019-
struct drm_atomic_state *state)
1021+
int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
1022+
struct drm_atomic_state *state,
1023+
bool pre_swap)
10201024
{
10211025
struct drm_plane *plane;
10221026
struct drm_plane_state *plane_state;
1023-
int i;
1027+
int i, ret;
10241028

10251029
for_each_plane_in_state(state, plane, plane_state, i) {
1026-
if (!plane->state->fence)
1030+
if (!pre_swap)
1031+
plane_state = plane->state;
1032+
1033+
if (!plane_state->fence)
10271034
continue;
10281035

1029-
WARN_ON(!plane->state->fb);
1036+
WARN_ON(!plane_state->fb);
1037+
1038+
/*
1039+
* If waiting for fences pre-swap (ie: nonblock), userspace can
1040+
* still interrupt the operation. Instead of blocking until the
1041+
* timer expires, make the wait interruptible.
1042+
*/
1043+
ret = fence_wait(plane_state->fence, pre_swap);
1044+
if (ret)
1045+
return ret;
10301046

1031-
fence_wait(plane->state->fence, false);
1032-
fence_put(plane->state->fence);
1033-
plane->state->fence = NULL;
1047+
fence_put(plane_state->fence);
1048+
plane_state->fence = NULL;
10341049
}
1050+
1051+
return 0;
10351052
}
10361053
EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences);
10371054

@@ -1179,7 +1196,7 @@ static void commit_tail(struct drm_atomic_state *state)
11791196

11801197
funcs = dev->mode_config.helper_private;
11811198

1182-
drm_atomic_helper_wait_for_fences(dev, state);
1199+
drm_atomic_helper_wait_for_fences(dev, state, false);
11831200

11841201
drm_atomic_helper_wait_for_dependencies(state);
11851202

@@ -1238,6 +1255,12 @@ int drm_atomic_helper_commit(struct drm_device *dev,
12381255
if (ret)
12391256
return ret;
12401257

1258+
if (!nonblock) {
1259+
ret = drm_atomic_helper_wait_for_fences(dev, state, true);
1260+
if (ret)
1261+
return ret;
1262+
}
1263+
12411264
/*
12421265
* This is the point of no return - everything below never fails except
12431266
* when the hw goes bonghits. Which means we can commit the new state on

‎drivers/gpu/drm/msm/msm_atomic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void complete_commit(struct msm_commit *c, bool async)
112112
struct msm_drm_private *priv = dev->dev_private;
113113
struct msm_kms *kms = priv->kms;
114114

115-
drm_atomic_helper_wait_for_fences(dev, state);
115+
drm_atomic_helper_wait_for_fences(dev, state, false);
116116

117117
kms->funcs->prepare_commit(kms, state);
118118

‎include/drm/drm_atomic_helper.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ int drm_atomic_helper_commit(struct drm_device *dev,
4545
struct drm_atomic_state *state,
4646
bool nonblock);
4747

48-
void drm_atomic_helper_wait_for_fences(struct drm_device *dev,
49-
struct drm_atomic_state *state);
48+
int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
49+
struct drm_atomic_state *state,
50+
bool pre_swap);
5051
bool drm_atomic_helper_framebuffer_changed(struct drm_device *dev,
5152
struct drm_atomic_state *old_state,
5253
struct drm_crtc *crtc);

0 commit comments

Comments
 (0)