From: Ville Syrjälä <[email protected]> Nonblocking commits that touch just CRTC-less planes and connectors use the fake commit. Unlike CRTC commits, which stall_checks() bounds to about triple buffering using crtc->commit_list, the fake commit is on no list, and the only thing that limits how far userspace can run ahead is the -EBUSY check on the previous fake commit's flip_done, which is completed from the commit tail.
That limit is about to go away when the flip_done gets completed earlier. Without any limit, and with drivers that call drm_atomic_helper_swap_state() with stall=false, the work items of all the queued commits start at once and each waits for the hw_done of its predecessor. These waits add up, and once the backlog takes longer than 10 s to drain the later work items hit the hw_done timeout in drm_atomic_helper_wait_for_dependencies(), which has no way to recover from it. So wait (interruptibly, with the usual 10 s timeout) for the previous fake commit's hw_done in drm_atomic_helper_setup_commit(). This limits the depth of fake commit only commits to one, without relying on -EBUSY. CRTC commits are left to stall_checks(). Do it in setup_commit() rather than swap_state() so that it does not depend on the driver's stall choice, and so that an interrupted wait is cheap to unwind. Cc: Maarten Lankhorst <[email protected]> Signed-off-by: Ville Syrjälä <[email protected]> --- drivers/gpu/drm/drm_atomic_helper.c | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index ccfe3840d505..3baca28b5cb8 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2428,6 +2428,34 @@ static int stall_checks(struct drm_crtc *crtc, bool nonblock) return ret < 0 ? ret : 0; } +/* + * Commits that only touch planes and connectors without a CRTC use the fake + * commit, which has no CRTC to hang off of, and so no commit_list for + * stall_checks() to look at. Their flip_done is completed already in + * drm_atomic_helper_setup_commit(), so the -EBUSY checks do not limit how far + * userspace can run ahead either. Without any limit the work items of the + * queued nonblocking commits would all wait for each other's hw_done, and + * the waits would add up and eventually time out. + * + * Wait for the previous fake commit to reach hw_done instead, which limits + * the depth to one commit. CRTC commits are limited by stall_checks(). + */ +static int stall_for_fake_commit(struct drm_device *dev, + struct drm_crtc_commit *commit) +{ + long ret; + + if (!commit || commit->crtc) + return 0; + + ret = wait_for_completion_interruptible_timeout(&commit->hw_done, + 10 * HZ); + if (ret == 0) + drm_err(dev, "fake commit hw_done timed out\n"); + + return ret < 0 ? ret : 0; +} + static void release_crtc_commit(struct completion *completion) { struct drm_crtc_commit *commit = container_of(completion, @@ -2590,6 +2618,10 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_commit *state, return -EBUSY; } + ret = stall_for_fake_commit(state->dev, old_conn_state->commit); + if (ret) + return ret; + /* Always track connectors explicitly for e.g. link retraining. */ commit = crtc_or_fake_commit(state, new_conn_state->crtc ?: old_conn_state->crtc); if (!commit) @@ -2612,6 +2644,10 @@ int drm_atomic_helper_setup_commit(struct drm_atomic_commit *state, return -EBUSY; } + ret = stall_for_fake_commit(state->dev, old_plane_state->commit); + if (ret) + return ret; + /* Always track planes explicitly for async pageflip support. */ commit = crtc_or_fake_commit(state, new_plane_state->crtc ?: old_plane_state->crtc); if (!commit) -- 2.56.0
