More nuclear pageflip
Subsystems (2)
cover More nuclear pageflip
The first two patches here were already posted earlier this week; they allow our legacy plane updates to make use of the main atomic helpers rather than the transitional atomic helpers. This shouldn't have any functional change, but it will cause us to exercise the full atomic pipeline rather than just the plane subset of it.
The third patch is the interesting one; it allows us to handle nuclear pageflip requests in a non-blocking manner and deliver a uevent upon completion. This is important functionality for compositors since it allows them to request that the kernel perform a flip, then continue on doing other work while they wait for the flip to actually happen.
The final patch here switches our legacy pageflip ioctl to use the atomic helper (thus exercising the new asynchronous support added in patch #3). Removing the i915-specific pageflip handling should allow us to drop a bunch of our display code; I've been somewhat conservative in my code removal for now (just enough to get rid of the 'function unused' compiler warnings); we can do further cleanup of code that relates to the legacy pageflip pipeline in a future patchset.
Matt Roper (4):
drm/i915: Keep plane->state updated on pageflip drm/i915: Switch planes from transitional helpers to full atomic
helpers
drm/i915: Enable asynchronous nuclear flips
drm/i915: Use atomic helper for pageflips
drivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_params.c | 5 - drivers/gpu/drm/i915/intel_atomic.c | 162 ++++++-- drivers/gpu/drm/i915/intel_display.c | 716 +---------------------------------- drivers/gpu/drm/i915/intel_drv.h | 8 + drivers/gpu/drm/i915/intel_lrc.c | 3 +- 6 files changed, 155 insertions(+), 748 deletions(-)
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/4 drm/i915: Keep plane->state updated on pageflip
Until all drivers have transitioned to atomic, the framebuffer associated with a plane is tracked in both plane->fb (for legacy) and plane->state->fb (for all the new atomic codeflow). All of our modeset and plane updates use drm_plane->update_plane(), so in theory plane->fb and plane->state->fb should always stay in sync and point at the same thing for i915. However we forgot about the pageflip ioctl case, which currently only updates plane->fb and leaves plane->state->fb at a stale value.
Surprisingly, this doesn't cause any real problems at the moment since internally we use the plane->fb pointer in most of the places that matter, and on the next .update_plane() call, we use plane->fb to figure out which framebuffer to cleanup. However when we switch to the full atomic helpers for update_plane()/disable_plane(), those helpers use plane->state->fb to figure out which framebuffer to cleanup, so not having updated the plane->state->fb pointer causes things to blow up following a pageflip ioctl.
The fix here is to just make sure we update plane->state->fb at the same time we update plane->fb in the pageflip ioctl.
--- drivers/gpu/drm/i915/intel_display.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/intel_display.c +7 -0
@@ -9801,6 +9801,13 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, crtc->primary->fb = fb; +/* Keep state structure in sync */ +if (crtc->primary->state->fb) +drm_framebuffer_unreference (crtc->primary->state->fb); + crtc->primary->state->fb = fb; +if (crtc->primary->state->fb) +drm_framebuffer_reference (crtc->primary->state->fb); + work->pending_flip_obj = obj;atomic_inc (&intel_crtc->unpin_work_count);
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 1/4] drm/i915: Keep plane->state updated on pageflip
Quoted 31 lines · Matt Roper
Until all drivers have transitioned to atomic, the framebuffer associated with a plane is tracked in both
plane->fb(for legacy) andplane->state->fb(for all the new atomic codeflow). All of our modeset and plane updates usedrm_plane->update_plane(), so in theoryplane->fbandplane->state->fbshould always stay in sync and point at the same thing for i915. However we forgot about the pageflip ioctl case, which currently only updatesplane->fband leavesplane->state->fbat a stale value.Surprisingly, this doesn't cause any real problems at the moment since internally we use the
plane->fbpointer in most of the places that matter, and on the next .update_plane() call, we useplane->fbto figure out which framebuffer to cleanup. However when we switch to the full atomic helpers for update_plane()/disable_plane(), those helpers useplane->state->fbto figure out which framebuffer to cleanup, so not having updated theplane->state->fbpointer causes things to blow up following a pageflip ioctl.The fix here is to just make sure we update
plane->state->fbat the same time we updateplane->fbin the pageflip ioctl.Signed-off-by Matt Roper <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/i915/intel_display.c +0
-0
drivers/gpu/drm/i915/intel_display.c static int intel_crtc_page_flip(struct drm_crtc *crtc, · line 9809
Quoted 9 lines
drivers/gpu/drm/i915/intel_display.c +6
-0@@ -9801,6 +9801,13 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, crtc->primary->fb = fb; +/* Keep state structure in sync */ +if (crtc->primary->state->fb) +drm_framebuffer_unreference (crtc->primary->state->fb); + crtc->primary->state->fb = fb; +if (crtc->primary->state->fb) +drm_framebuffer_reference (crtc->primary->state->fb);
Yeah, I had the same fixup in my own testconversion. So merged this and the 2nd patch to dinq (for 3.21).
Thanks, Daniel
Quoted 11 lines
drivers/gpu/drm/i915/intel_display.c +1
-0+ work->pending_flip_obj = obj;atomic_inc (&intel_crtc->unpin_work_count);Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/4 drm/i915: Switch planes from transitional helpers to full atomic helpers
In reply to Matt RoperThere are two sets of helper functions provided by the DRM core that can implement the .update_plane() and .disable_plane() hooks in terms of a driver's atomic entrypoints. The transitional helpers (which we have been using so far) create a plane state and then use the plane's atomic entrypoints to perform the atomic begin/check/prepare/commit/finish sequence on that single plane only. The full atomic helpers create a top-level atomic state (which is capable of holding multiple object states for planes, crtc's, and/or connectors) and then passes the top-level atomic state through the full "atomic modeset" pipeline.
Switching from the transitional to full helpers here shouldn't result in any functional change, but will enable us to exercise/test more of the internal atomic pipeline with the legacy API's used by existing applications.
--- drivers/gpu/drm/i915/intel_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -2
@@ -12076,8 +12076,8 @@ void intel_plane_destroy(struct drm_plane *plane) }const struct drm_plane_funcs intel_plane_funcs = { - .update_plane = drm_plane_helper_update, - .disable_plane = drm_plane_helper_disable, + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, .destroy = intel_plane_destroy, .set_property = drm_atomic_helper_plane_set_property, .atomic_get_property = intel_plane_atomic_get_property,
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/4 drm/i915: Enable asynchronous nuclear flips
In reply to Matt RoperThe initial i915 nuclear pageflip support rejected asynchronous updates. Allow all work after we swap in the new state structures to run asynchronously. We also need to start sending completion events to userspace if they were requested.
--- drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/intel_atomic.c | 162 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_drv.h | 8 ++ 3 files changed, 150 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -1777,6 +1777,9 @@ struct drm_i915_private {struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES ];wait_queue_head_t pending_flip_queue; +/* CRTC mask of pending atomic flips */ +uint32_t pending_atomic; +#ifdef CONFIG_DEBUG_FS struct intel_pipe_crc pipe_crc[I915_MAX_PIPES ];#endif
drivers/gpu/drm/i915/intel_atomic.c +139 -23
195 lines not on this page · raw message
drivers/gpu/drm/i915/intel_drv.h +8 -0
@@ -391,6 +391,14 @@ struct intel_crtc_state {int pbn; }; +/* In-flight atomic operation */ +struct intel_pending_atomic { +struct work_struct work; +struct drm_device *dev; +struct drm_atomic_state *state; +uint32_t crtc_mask; +}; +struct intel_pipe_wm {struct intel_wm_level wm[5 ];uint32_t linetime;
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/4] drm/i915: Enable asynchronous nuclear flips
Quoted 205 lines · Matt Roper
The initial i915 nuclear pageflip support rejected asynchronous updates. Allow all work after we swap in the new state structures to run asynchronously. We also need to start sending completion events to userspace if they were requested.
Signed-off-by Matt Roper <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/intel_atomic.c | 162 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_drv.h | 8 ++ 3 files changed, 150 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/i915_drv.h +3
-0@@ -1777,6 +1777,9 @@ struct drm_i915_private {struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES ];wait_queue_head_t pending_flip_queue; +/* CRTC mask of pending atomic flips */ +uint32_t pending_atomic; +#ifdef CONFIG_DEBUG_FS struct intel_pipe_crc pipe_crc[I915_MAX_PIPES ];#endif drivers/gpu/drm/i915/intel_atomic.c +118
-23@@ -76,6 +76,8 @@ int intel_atomic_check(struct drm_device *dev, state->allow_modeset = false;for (i =0 ; i < ncrtcs; i++) {struct intel_crtc *crtc =to_intel_crtc (state->crtcs[i]); +if (crtc) + state->crtc_states[i]->enable = crtc->active;if (crtc && crtc->pipe != nuclear_pipe) not_nuclear = true; }@@ -96,6 +98,87 @@ int intel_atomic_check(struct drm_device *dev, } +/* +* Wait until CRTC's have no pending flip, then atomically mark those CRTC's +* as busy. +*/ +static int wait_for_pending_flip (uint32_t crtc_mask, +struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; +int ret; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + ret =wait_event_interruptible_locked (dev_priv->pending_flip_queue, + !(dev_priv->pending_atomic & crtc_mask)); +if (ret ==0 ) + dev_priv->pending_atomic |= crtc_mask; +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); + +return ret; +} + +/* Finish pending flip operation on specified CRTC's */ +static void flip_completion (struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + dev_priv->pending_atomic &= ~commit->crtc_mask; +wake_up_all_locked (&dev_priv->pending_flip_queue); +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); +} + +/* +* Finish an atomic commit. The work here can be performed asynchronously +* if desired. The new state has already been applied to the DRM objects +* and no modeset locks are needed. +*/ +static void finish_atomic_commit (struct work_struct *work) +{ +struct intel_pending_atomic *commit = + container_of(work, struct intel_pending_atomic, work); +struct drm_device *dev = commit->dev; +struct drm_crtc *crtc; +struct drm_atomic_state *state = commit->state; +int i; + +/* +* FIXME: The proper sequence here will eventually be: +* +* drm_atomic_helper_commit_pre_planes(dev, state); +* drm_atomic_helper_commit_planes(dev, state); +* drm_atomic_helper_commit_post_planes(dev, state); +* drm_atomic_helper_wait_for_vblanks(dev, state); +* drm_atomic_helper_cleanup_planes(dev, state); +* drm_atomic_state_free(state); +* +* once we have full atomic modeset. For now, just manually update +* plane states to avoid clobbering good states with dummy states +* while nuclear pageflipping. +*/ +drm_atomic_helper_commit_planes (dev, state); +drm_atomic_helper_wait_for_vblanks (dev, state); + +/* Send CRTC completion events. */ +for (i =0 ; i < dev->mode_config.num_crtc; i++) { + crtc = state->crtcs[i]; +if (crtc && crtc->state->event) { +spin_lock_irq (&dev->event_lock); +drm_send_vblank_event (dev,to_intel_crtc (crtc)->pipe, + crtc->state->event); +spin_unlock_irq (&dev->event_lock); + crtc->state->event =NULL ; + } + } + +drm_atomic_helper_cleanup_planes (dev, state); +drm_atomic_state_free (state); + +flip_completion (commit); +kfree (commit); +} +/** * intel_atomic_commit - commit validated state object * @dev: DRM device @@ -116,34 +199,48 @@ int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, bool async) { +struct intel_pending_atomic *commit;int ret;int i; -if (async) { -DRM_DEBUG_KMS ("i915 does not yet support async commit\n" ); -return -EINVAL ; - } - ret =drm_atomic_helper_prepare_planes (dev, state);if (ret)return ret; -/* Point of no return */ + commit =kzalloc (sizeof (*commit),GFP_KERNEL ); +if (!commit) +return -ENOMEM ; + + commit->dev = dev; + commit->state = state; + +for (i =0 ; i < dev->mode_config.num_crtc; i++) +if (state->crtcs[i]) + commit->crtc_mask |= + (1 <<drm_crtc_index (state->crtcs[i]));/* -* FIXME: The proper sequence here will eventually be: -* -* drm_atomic_helper_swap_state(dev, state) -* drm_atomic_helper_commit_pre_planes(dev, state); -* drm_atomic_helper_commit_planes(dev, state); -* drm_atomic_helper_commit_post_planes(dev, state); -* drm_atomic_helper_wait_for_vblanks(dev, state); -* drm_atomic_helper_cleanup_planes(dev, state); -* drm_atomic_state_free(state); -* -* once we have full atomic modeset. For now, just manually update -* plane states to avoid clobbering good states with dummy states -* while nuclear pageflipping. +* If there's already a flip pending, we won't schedule another one +* until it completes. We may relax this in the future, but for now +* this matches the legacy pageflip behavior. +*/ + ret =wait_for_pending_flip (commit->crtc_mask, commit); +if (ret) { +kfree (commit); +return ret; + } + +/* +* Point of no return; everything from here on can't fail, so swap +* the new state into the DRM objects. +*/ + +/* +* FIXME: Should eventually use drm_atomic_helper_swap_state(). +* However since we only handle planes at the moment, we don't +* want to clobber our good crtc state with something bogus, +* so just manually swap the plane states and copy over any completion +* events for CRTC's. */ for (i =0 ; i < dev->mode_config.num_total_plane; i++) {struct drm_plane *plane = state->planes[i];@@ -155,10 +252,29 @@ int intel_atomic_commit(struct drm_device *dev,swap (state->plane_states[i], plane->state); plane->state->state =NULL ; } -drm_atomic_helper_commit_planes (dev, state); -drm_atomic_helper_wait_for_vblanks (dev, state); -drm_atomic_helper_cleanup_planes (dev, state); -drm_atomic_state_free (state); + +for (i =0 ; i < dev->mode_config.num_crtc; i++) {
drivers/gpu/drm/i915/intel_atomic.c int intel_atomic_commit(struct drm_device *dev, · line 266
Quoted 10 lines
drivers/gpu/drm/i915/intel_atomic.c +10
-0+struct drm_crtc *crtc = state->crtcs[i]; +struct drm_crtc_state *crtc_state = state->crtc_states[i]; + +if (!crtc || !crtc_state) +continue ; + +/* n.b., we only copy the event and enabled flag for now */ +swap (crtc->state->event, crtc_state->event); +swap (crtc->state->enable, crtc_state->enable); + }
Before we can swap in the new state we need to stall for any oustanding async flip to complete. At least until we have a full-blown flip queue.
drivers/gpu/drm/i915/intel_atomic.c int intel_atomic_commit(struct drm_device *dev, · line 276
Quoted 10 lines
drivers/gpu/drm/i915/intel_atomic.c +10
-0+ +/* +* From here on, we can do everything asynchronously without any +* modeset locks. +*/ +if (async) { +INIT_WORK (&commit->work, finish_atomic_commit); +schedule_work (&commit->work); + }else { +finish_atomic_commit (&commit->work);
That also solves the problem of stalling for any oustanding async commit when we process a synchronous one. With just legacy pageflips we do that in the crtc shutdown funcs, but long-term I think it'll be much more robust to do this in the top-level commit code (and rip out all the pageflip waits deep down in the low-level functions). -Daniel
Quoted 30 lines
drivers/gpu/drm/i915/intel_atomic.c +1
-0+ }return 0 ; }drivers/gpu/drm/i915/intel_drv.h +8
-0@@ -391,6 +391,14 @@ struct intel_crtc_state {int pbn; }; +/* In-flight atomic operation */ +struct intel_pending_atomic { +struct work_struct work; +struct drm_device *dev; +struct drm_atomic_state *state; +uint32_t crtc_mask; +}; +struct intel_pipe_wm {struct intel_wm_level wm[5 ];uint32_t linetime;Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/4] drm/i915: Enable asynchronous nuclear flips
Quoted 211 lines · Daniel Vetter
Quoted 210 lines · Matt Roper
The initial i915 nuclear pageflip support rejected asynchronous updates. Allow all work after we swap in the new state structures to run asynchronously. We also need to start sending completion events to userspace if they were requested.
Signed-off-by Matt Roper <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/intel_atomic.c | 162 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_drv.h | 8 ++ 3 files changed, 150 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/i915_drv.h +3
-0@@ -1777,6 +1777,9 @@ struct drm_i915_private {struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES ];wait_queue_head_t pending_flip_queue; +/* CRTC mask of pending atomic flips */ +uint32_t pending_atomic; +#ifdef CONFIG_DEBUG_FS struct intel_pipe_crc pipe_crc[I915_MAX_PIPES ];#endif drivers/gpu/drm/i915/intel_atomic.c +123
-23@@ -76,6 +76,8 @@ int intel_atomic_check(struct drm_device *dev, state->allow_modeset = false;for (i =0 ; i < ncrtcs; i++) {struct intel_crtc *crtc =to_intel_crtc (state->crtcs[i]); +if (crtc) + state->crtc_states[i]->enable = crtc->active;if (crtc && crtc->pipe != nuclear_pipe) not_nuclear = true; }@@ -96,6 +98,87 @@ int intel_atomic_check(struct drm_device *dev, } +/* +* Wait until CRTC's have no pending flip, then atomically mark those CRTC's +* as busy. +*/ +static int wait_for_pending_flip (uint32_t crtc_mask, +struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; +int ret; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + ret =wait_event_interruptible_locked (dev_priv->pending_flip_queue, + !(dev_priv->pending_atomic & crtc_mask)); +if (ret ==0 ) + dev_priv->pending_atomic |= crtc_mask; +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); + +return ret; +} + +/* Finish pending flip operation on specified CRTC's */ +static void flip_completion (struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + dev_priv->pending_atomic &= ~commit->crtc_mask; +wake_up_all_locked (&dev_priv->pending_flip_queue); +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); +} + +/* +* Finish an atomic commit. The work here can be performed asynchronously +* if desired. The new state has already been applied to the DRM objects +* and no modeset locks are needed. +*/ +static void finish_atomic_commit (struct work_struct *work) +{ +struct intel_pending_atomic *commit = + container_of(work, struct intel_pending_atomic, work); +struct drm_device *dev = commit->dev; +struct drm_crtc *crtc; +struct drm_atomic_state *state = commit->state; +int i; + +/* +* FIXME: The proper sequence here will eventually be: +* +* drm_atomic_helper_commit_pre_planes(dev, state); +* drm_atomic_helper_commit_planes(dev, state); +* drm_atomic_helper_commit_post_planes(dev, state); +* drm_atomic_helper_wait_for_vblanks(dev, state); +* drm_atomic_helper_cleanup_planes(dev, state); +* drm_atomic_state_free(state); +* +* once we have full atomic modeset. For now, just manually update +* plane states to avoid clobbering good states with dummy states +* while nuclear pageflipping. +*/ +drm_atomic_helper_commit_planes (dev, state); +drm_atomic_helper_wait_for_vblanks (dev, state); + +/* Send CRTC completion events. */ +for (i =0 ; i < dev->mode_config.num_crtc; i++) { + crtc = state->crtcs[i]; +if (crtc && crtc->state->event) { +spin_lock_irq (&dev->event_lock); +drm_send_vblank_event (dev,to_intel_crtc (crtc)->pipe, + crtc->state->event); +spin_unlock_irq (&dev->event_lock); + crtc->state->event =NULL ; + } + } + +drm_atomic_helper_cleanup_planes (dev, state); +drm_atomic_state_free (state); + +flip_completion (commit); +kfree (commit); +} +/** * intel_atomic_commit - commit validated state object * @dev: DRM device @@ -116,34 +199,48 @@ int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, bool async) { +struct intel_pending_atomic *commit;int ret;int i; -if (async) { -DRM_DEBUG_KMS ("i915 does not yet support async commit\n" ); -return -EINVAL ; - } - ret =drm_atomic_helper_prepare_planes (dev, state);if (ret)return ret; -/* Point of no return */ + commit =kzalloc (sizeof (*commit),GFP_KERNEL ); +if (!commit) +return -ENOMEM ; + + commit->dev = dev; + commit->state = state; + +for (i =0 ; i < dev->mode_config.num_crtc; i++) +if (state->crtcs[i]) + commit->crtc_mask |= + (1 <<drm_crtc_index (state->crtcs[i]));/* -* FIXME: The proper sequence here will eventually be: -* -* drm_atomic_helper_swap_state(dev, state) -* drm_atomic_helper_commit_pre_planes(dev, state); -* drm_atomic_helper_commit_planes(dev, state); -* drm_atomic_helper_commit_post_planes(dev, state); -* drm_atomic_helper_wait_for_vblanks(dev, state); -* drm_atomic_helper_cleanup_planes(dev, state); -* drm_atomic_state_free(state); -* -* once we have full atomic modeset. For now, just manually update -* plane states to avoid clobbering good states with dummy states -* while nuclear pageflipping. +* If there's already a flip pending, we won't schedule another one +* until it completes. We may relax this in the future, but for now +* this matches the legacy pageflip behavior. +*/ + ret =wait_for_pending_flip (commit->crtc_mask, commit); +if (ret) { +kfree (commit); +return ret; + } + +/* +* Point of no return; everything from here on can't fail, so swap +* the new state into the DRM objects. +*/ + +/* +* FIXME: Should eventually use drm_atomic_helper_swap_state(). +* However since we only handle planes at the moment, we don't +* want to clobber our good crtc state with something bogus, +* so just manually swap the plane states and copy over any completion +* events for CRTC's. */ for (i =0 ; i < dev->mode_config.num_total_plane; i++) {struct drm_plane *plane = state->planes[i];@@ -155,10 +252,29 @@ int intel_atomic_commit(struct drm_device *dev,swap (state->plane_states[i], plane->state); plane->state->state =NULL ; } -drm_atomic_helper_commit_planes (dev, state); -drm_atomic_helper_wait_for_vblanks (dev, state); -drm_atomic_helper_cleanup_planes (dev, state); -drm_atomic_state_free (state); + +for (i =0 ; i < dev->mode_config.num_crtc; i++) { +struct drm_crtc *crtc = state->crtcs[i]; +struct drm_crtc_state *crtc_state = state->crtc_states[i]; + +if (!crtc || !crtc_state) +continue ;
Quoted 8 lines
drivers/gpu/drm/i915/intel_atomic.c int intel_atomic_commit(struct drm_device *dev, · line 266
Quoted 5 lines
drivers/gpu/drm/i915/intel_atomic.c +5
-0+ +/* n.b., we only copy the event and enabled flag for now */ +swap (crtc->state->event, crtc_state->event); +swap (crtc->state->enable, crtc_state->enable); + }Before we can swap in the new state we need to stall for any oustanding async flip to complete. At least until we have a full-blown flip queue.
I think the wait_for_pending_flip() call above the two comment blocks before the loop should take care of that --- it waits until all the CRTC's in commit->crtc_mask have no pending flip, then atomically marks them as busy before proceeding.
Matt
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/4] drm/i915: Enable asynchronous nuclear flips
Quoted 221 lines · Matt Roper
Quoted 211 lines · Daniel Vetter
Quoted 210 lines · Matt Roper
The initial i915 nuclear pageflip support rejected asynchronous updates. Allow all work after we swap in the new state structures to run asynchronously. We also need to start sending completion events to userspace if they were requested.
Signed-off-by Matt Roper <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/intel_atomic.c | 162 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/intel_drv.h | 8 ++ 3 files changed, 150 insertions(+), 23 deletions(-)drivers/gpu/drm/i915/i915_drv.h +3
-0@@ -1777,6 +1777,9 @@ struct drm_i915_private {struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES ];wait_queue_head_t pending_flip_queue; +/* CRTC mask of pending atomic flips */ +uint32_t pending_atomic; +#ifdef CONFIG_DEBUG_FS struct intel_pipe_crc pipe_crc[I915_MAX_PIPES ];#endif drivers/gpu/drm/i915/intel_atomic.c +123
-23@@ -76,6 +76,8 @@ int intel_atomic_check(struct drm_device *dev, state->allow_modeset = false;for (i =0 ; i < ncrtcs; i++) {struct intel_crtc *crtc =to_intel_crtc (state->crtcs[i]); +if (crtc) + state->crtc_states[i]->enable = crtc->active;if (crtc && crtc->pipe != nuclear_pipe) not_nuclear = true; }@@ -96,6 +98,87 @@ int intel_atomic_check(struct drm_device *dev, } +/* +* Wait until CRTC's have no pending flip, then atomically mark those CRTC's +* as busy. +*/ +static int wait_for_pending_flip (uint32_t crtc_mask, +struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; +int ret; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + ret =wait_event_interruptible_locked (dev_priv->pending_flip_queue, + !(dev_priv->pending_atomic & crtc_mask)); +if (ret ==0 ) + dev_priv->pending_atomic |= crtc_mask; +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); + +return ret; +} + +/* Finish pending flip operation on specified CRTC's */ +static void flip_completion (struct intel_pending_atomic *commit) +{ +struct drm_i915_private *dev_priv = commit->dev->dev_private; + +spin_lock_irq (&dev_priv->pending_flip_queue.lock); + dev_priv->pending_atomic &= ~commit->crtc_mask; +wake_up_all_locked (&dev_priv->pending_flip_queue); +spin_unlock_irq (&dev_priv->pending_flip_queue.lock); +} + +/* +* Finish an atomic commit. The work here can be performed asynchronously +* if desired. The new state has already been applied to the DRM objects +* and no modeset locks are needed. +*/ +static void finish_atomic_commit (struct work_struct *work) +{ +struct intel_pending_atomic *commit = + container_of(work, struct intel_pending_atomic, work); +struct drm_device *dev = commit->dev; +struct drm_crtc *crtc; +struct drm_atomic_state *state = commit->state; +int i; + +/* +* FIXME: The proper sequence here will eventually be: +* +* drm_atomic_helper_commit_pre_planes(dev, state); +* drm_atomic_helper_commit_planes(dev, state); +* drm_atomic_helper_commit_post_planes(dev, state); +* drm_atomic_helper_wait_for_vblanks(dev, state); +* drm_atomic_helper_cleanup_planes(dev, state); +* drm_atomic_state_free(state); +* +* once we have full atomic modeset. For now, just manually update +* plane states to avoid clobbering good states with dummy states +* while nuclear pageflipping. +*/ +drm_atomic_helper_commit_planes (dev, state); +drm_atomic_helper_wait_for_vblanks (dev, state); + +/* Send CRTC completion events. */ +for (i =0 ; i < dev->mode_config.num_crtc; i++) { + crtc = state->crtcs[i]; +if (crtc && crtc->state->event) { +spin_lock_irq (&dev->event_lock); +drm_send_vblank_event (dev,to_intel_crtc (crtc)->pipe, + crtc->state->event); +spin_unlock_irq (&dev->event_lock); + crtc->state->event =NULL ; + } + } + +drm_atomic_helper_cleanup_planes (dev, state); +drm_atomic_state_free (state); + +flip_completion (commit); +kfree (commit); +} +/** * intel_atomic_commit - commit validated state object * @dev: DRM device @@ -116,34 +199,48 @@ int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, bool async) { +struct intel_pending_atomic *commit;int ret;int i; -if (async) { -DRM_DEBUG_KMS ("i915 does not yet support async commit\n" ); -return -EINVAL ; - } - ret =drm_atomic_helper_prepare_planes (dev, state);if (ret)return ret; -/* Point of no return */ + commit =kzalloc (sizeof (*commit),GFP_KERNEL ); +if (!commit) +return -ENOMEM ; + + commit->dev = dev; + commit->state = state; + +for (i =0 ; i < dev->mode_config.num_crtc; i++) +if (state->crtcs[i]) + commit->crtc_mask |= + (1 <<drm_crtc_index (state->crtcs[i]));/* -* FIXME: The proper sequence here will eventually be: -* -* drm_atomic_helper_swap_state(dev, state) -* drm_atomic_helper_commit_pre_planes(dev, state); -* drm_atomic_helper_commit_planes(dev, state); -* drm_atomic_helper_commit_post_planes(dev, state); -* drm_atomic_helper_wait_for_vblanks(dev, state); -* drm_atomic_helper_cleanup_planes(dev, state); -* drm_atomic_state_free(state); -* -* once we have full atomic modeset. For now, just manually update -* plane states to avoid clobbering good states with dummy states -* while nuclear pageflipping. +* If there's already a flip pending, we won't schedule another one +* until it completes. We may relax this in the future, but for now +* this matches the legacy pageflip behavior. +*/ + ret =wait_for_pending_flip (commit->crtc_mask, commit); +if (ret) { +kfree (commit); +return ret; + } + +/* +* Point of no return; everything from here on can't fail, so swap +* the new state into the DRM objects. +*/ + +/* +* FIXME: Should eventually use drm_atomic_helper_swap_state(). +* However since we only handle planes at the moment, we don't +* want to clobber our good crtc state with something bogus, +* so just manually swap the plane states and copy over any completion +* events for CRTC's. */ for (i =0 ; i < dev->mode_config.num_total_plane; i++) {struct drm_plane *plane = state->planes[i];@@ -155,10 +252,29 @@ int intel_atomic_commit(struct drm_device *dev,swap (state->plane_states[i], plane->state); plane->state->state =NULL ; } -drm_atomic_helper_commit_planes (dev, state); -drm_atomic_helper_wait_for_vblanks (dev, state); -drm_atomic_helper_cleanup_planes (dev, state); -drm_atomic_state_free (state); + +for (i =0 ; i < dev->mode_config.num_crtc; i++) { +struct drm_crtc *crtc = state->crtcs[i]; +struct drm_crtc_state *crtc_state = state->crtc_states[i]; + +if (!crtc || !crtc_state) +continue ;Quoted 8 lines
drivers/gpu/drm/i915/intel_atomic.c int intel_atomic_commit(struct drm_device *dev, · line 266
Quoted 5 lines
drivers/gpu/drm/i915/intel_atomic.c +5
-0+ +/* n.b., we only copy the event and enabled flag for now */ +swap (crtc->state->event, crtc_state->event); +swap (crtc->state->enable, crtc_state->enable); + }Before we can swap in the new state we need to stall for any oustanding async flip to complete. At least until we have a full-blown flip queue.
Quoted 4 lines
I think the
wait_for_pending_flip()call above the two comment blocks before the loop should take care of that --- it waits until all the CRTC's incommit->crtc_maskhave no pending flip, then atomically marks them as busy before proceeding.
Right, completely missed that one, must have been blind. Looks sensible.
Another lesson learned from the old pageflip code to consider is that free-standing flip/unpin works which only communicate their completion status to the core of the driver through some bitmasks are a pain to integrate into the shrinker. And even more so with atomic flips we must be able to stall for the unpin to complete on any outstanding flips if we run out of ggtt space.
Currently that's handled by restarting the entire ioctl from the eviction code (see the EAGAIN in i915_gem_evict.c), which isn't terrible pretty. Imo some explicit queue which the shrinker could stall on directly (and maybe even process synchronously if needed) would be much better. With atomic it should be possible since the async worker doesn't need any modeset locks, only the dev->struct_mutex to unpin objects.
Anyway something to keep in mind, but maybe only once we have the full flip queue in place. For now the important part is not to break things, but I think we should have full coverage for everything in igt (but maybe not in the limited prts subset).
Another thing I might or might not have missed is the async waiting. Currently prepare_plane_fb does a synchronous stall for rendering, which needs to be split like with the mmio_flip code which has an explicit wait_request in the work function. Long-term I'd like to use the plane_state->fence pointer, but unfortunately i915 reqeusts haven't been subclassed properly yet. So we'd need our own request pointer for now - at least those are refcounted already.
And one more wishlist: Would it be feasible to build up the atomic async stuff from the mmio_flip code? Just for additional continuity and testing
...
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/4 drm/i915: Use atomic helper for pageflips
In reply to Matt RoperNow that we have asynchronous nuclear pageflip, we should be able to push our legacy pageflip ioctl through the atomic helper and rip out a bunch of i915-specific pageflip code.
This patch is actually pretty conservative; I think there's a lot more flip-related infrastructure that should be ripped out now that we're never doing command streamer flips and always letting the DRM core handle the flip logic.
--- drivers/gpu/drm/i915/i915_drv.h | 6 - drivers/gpu/drm/i915/i915_params.c | 5 - drivers/gpu/drm/i915/intel_display.c | 719 +---------------------------------- drivers/gpu/drm/i915/intel_lrc.c | 3 +- 4 files changed, 3 insertions(+), 730 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -6
@@ -556,11 +556,6 @@ struct drm_i915_display_funcs {void (*audio_codec_disable)(struct intel_encoder *encoder);void (*fdi_link_train)(struct drm_crtc *crtc);void (*init_clock_gating)(struct drm_device *dev); -int (*queue_flip)(struct drm_device *dev,struct drm_crtc *crtc, -struct drm_framebuffer *fb, -struct drm_i915_gem_object *obj, -struct intel_engine_cs *ring, -uint32_t flags);void (*update_primary_plane)(struct drm_crtc *crtc,struct drm_framebuffer *fb,int x,int y);
@@ -2526,7 +2521,6 @@ struct i915_params {bool reset;bool disable_display;bool disable_vtd_wa; -int use_mmio_flip;bool mmio_debug;bool verbose_state_checks;bool nuclear_pageflip;
drivers/gpu/drm/i915/i915_params.c +0 -5
@@ -49,7 +49,6 @@ struct i915_params i915 __read_mostly = { .disable_display = 0, .enable_cmd_parser = 1, .disable_vtd_wa = 0, - .use_mmio_flip = 0, .mmio_debug = 0, .verbose_state_checks = 1, .nuclear_pageflip = 0,
@@ -167,10 +166,6 @@ module_param_named(enable_cmd_parser, i915.enable_cmd_parser, int, 0600);MODULE_PARM_DESC (enable_cmd_parser,"Enable command parsing (1=enabled [default], 0=disabled)" ); -module_param_named (use_mmio_flip, i915.use_mmio_flip, int,0600 ); -MODULE_PARM_DESC (use_mmio_flip, -"use MMIO flips (-1=never, 0=driver discretion [default], 1=always)" ); -module_param_named (mmio_debug, i915.mmio_debug, bool,0600 );MODULE_PARM_DESC (mmio_debug, "Enable the MMIO debug code (default: false). This may negatively "
drivers/gpu/drm/i915/intel_display.c +2 -717
766 lines not on this page · raw message
drivers/gpu/drm/i915/intel_lrc.c +1 -2
@@ -226,8 +226,7 @@ int intel_sanitize_enable_execlists(struct drm_device *dev, int enable_execlistsif (enable_execlists ==0 )return 0 ; -if (HAS_LOGICAL_RING_CONTEXTS (dev) &&USES_PPGTT (dev) && - i915.use_mmio_flip >=0 ) +if (HAS_LOGICAL_RING_CONTEXTS (dev) &&USES_PPGTT (dev))return 1 ;return 0 ;
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 12 lines · Matt Roper
The first two patches here were already posted earlier this week; they allow our legacy plane updates to make use of the main atomic helpers rather than the transitional atomic helpers. This shouldn't have any functional change, but it will cause us to exercise the full atomic pipeline rather than just the plane subset of it.
The third patch is the interesting one; it allows us to handle nuclear pageflip requests in a non-blocking manner and deliver a uevent upon completion. This is important functionality for compositors since it allows them to request that the kernel perform a flip, then continue on doing other work while they wait for the flip to actually happen.
Quoted 7 lines
The final patch here switches our legacy pageflip ioctl to use the atomic helper (thus exercising the new asynchronous support added in patch #3). Removing the i915-specific pageflip handling should allow us to drop a bunch of our display code; I've been somewhat conservative in my code removal for now (just enough to get rid of the 'function unused' compiler warnings); we can do further cleanup of code that relates to the legacy pageflip pipeline in a future patchset.
Our current mmio flip doesn't work on gen4 and earlier because the flip completion event generation only works with MI_ flips. So I think we need to (at least for now) keep the legacy flip code around and wired up for those platforms.
But we need to redo the flip completion anyway (and probably just key off the next vblank interrupt) since if you'd do an atomic flip with just sprites the event stuff wont work on any platform. Once we have that we can then also roll out the legacy-pageflip-on-atomic for older platforms. -Daniel
Quoted 23 lines
Matt Roper (4):
drm/i915: Keepplane->stateupdated on pageflip drm/i915: Switch planes from transitional helpers to full atomic
helpers
drm/i915: Enable asynchronous nuclear flips
drm/i915: Use atomic helper for pageflipsdrivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_params.c | 5 - drivers/gpu/drm/i915/intel_atomic.c | 162 ++++++-- drivers/gpu/drm/i915/intel_display.c | 716 +---------------------------------- drivers/gpu/drm/i915/intel_drv.h | 8 + drivers/gpu/drm/i915/intel_lrc.c | 3 +- 6 files changed, 155 insertions(+), 748 deletions(-)Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 26 lines · Daniel Vetter
Quoted 12 lines · Matt Roper
The first two patches here were already posted earlier this week; they allow our legacy plane updates to make use of the main atomic helpers rather than the transitional atomic helpers. This shouldn't have any functional change, but it will cause us to exercise the full atomic pipeline rather than just the plane subset of it.
The third patch is the interesting one; it allows us to handle nuclear pageflip requests in a non-blocking manner and deliver a uevent upon completion. This is important functionality for compositors since it allows them to request that the kernel perform a flip, then continue on doing other work while they wait for the flip to actually happen.
Quoted 7 lines
The final patch here switches our legacy pageflip ioctl to use the atomic helper (thus exercising the new asynchronous support added in patch #3). Removing the i915-specific pageflip handling should allow us to drop a bunch of our display code; I've been somewhat conservative in my code removal for now (just enough to get rid of the 'function unused' compiler warnings); we can do further cleanup of code that relates to the legacy pageflip pipeline in a future patchset.
Our current mmio flip doesn't work on gen4 and earlier because the flip completion event generation only works with
MI_flips. So I think we need to (at least for now) keep the legacy flip code around and wired up for those platforms.
Quoted 5 lines
But we need to redo the flip completion anyway (and probably just key off the next vblank interrupt) since if you'd do an atomic flip with just sprites the event stuff wont work on any platform. Once we have that we can then also roll out the legacy-pageflip-on-atomic for older platforms. -Daniel
Hmm, my code at the moment sends the completion event to userspace and marks the CRTC as no longer having a flip pending after drm_atomic_helper_wait_for_vblanks(dev, state) call, which probably works when we're actually updating the framebuffer, but I guess that will send the uevent too early in cases where the fb doesn't change (since we already made a point of optimizing out that unnecessary vblank wait).
So maybe I should just get the "schedule stuff for future vblank" mechanism done that I already had on my plate for the watermark stuff, and then use that to send the uevent once the next vblank following the commit happens.
It occurs to me that I probably need to take a look at all the i915 hangcheck/recovery stuff too; I haven't paid much attention to how that works, but I'm guessing it probably needs to be updated a bit now as well.
Matt
Quoted 17 lines
Quoted 17 lines
Matt Roper (4):
drm/i915: Keepplane->stateupdated on pageflip drm/i915: Switch planes from transitional helpers to full atomic
helpers
drm/i915: Enable asynchronous nuclear flips
drm/i915: Use atomic helper for pageflipsdrivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_params.c | 5 - drivers/gpu/drm/i915/intel_atomic.c | 162 ++++++-- drivers/gpu/drm/i915/intel_display.c | 716 +---------------------------------- drivers/gpu/drm/i915/intel_drv.h | 8 + drivers/gpu/drm/i915/intel_lrc.c | 3 +- 6 files changed, 155 insertions(+), 748 deletions(-)
Quoted 16 lines
Quoted 7 lines
Signature · 6 lines
1.8.5.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfxSignature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx