linux/drivers/gpu/drm/vkms
Daniel Vetter 88ad7f3a56 drm/vkms: Reduce critical section in vblank_simulate
We can reduce the critical section in vkms_vblank_simulate under
output->lock quite a lot:

- hrtimer_forward_now just needs to be ordered correctly wrt
  drm_crtc_handle_vblank. We already access the hrtimer timestamp
  without locks. While auditing that I noticed that we don't correctly
  annotate the read there, so sprinkle a READ_ONCE to make sure the
  compiler doesn't do anything foolish.

- drm_crtc_handle_vblank must stay under the lock to avoid races with
  drm_crtc_arm_vblank_event.

- The access to vkms_ouptut->crc_state also must stay under the lock.

- next problem is making sure the output->state structure doesn't get
  freed too early. First we rely on a given hrtimer being serialized:
  If we call drm_crtc_handle_vblank, then we are guaranteed that the
  previous call to vkms_vblank_simulate has completed. The other side
  of the coin is that the atomic updates waits for the vblank to
  happen before it releases the old state. Both taken together means
  that by the time the atomic update releases the old state, the
  hrtimer won't access it anymore (it might be accessing the new state
  at the same time, but that's ok).

- state is invariant, except the few fields separate protected by
  state->crc_lock. So no need to hold the lock for that.

- finally the queue_work. We need to make sure there's no races with
  the flush_work, i.e. when we call flush_work we need to guarantee
  that the hrtimer can't requeue the work again. This is guaranteed by
  the same vblank/hrtimer ordering guarantees like the reasoning above
  why state won't be freed too early: flush_work on the old state is
  called after wait_for_flip_done in the atomic commit code.

Therefore we can also move everything after the output->crc_state out
of the critical section.

Motivated by suggestions from Rodrigo.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190719152314.7706-3-daniel.vetter@ffwll.ch
2019-09-03 17:16:53 +02:00
..
Makefile drm/vkms: Rename vkms_crc.c into vkms_composer.c 2019-07-12 00:46:02 -03:00
vkms_composer.c drm/vkms: drop use of drmP.h 2019-07-15 18:11:30 +02:00
vkms_crtc.c drm/vkms: Reduce critical section in vblank_simulate 2019-09-03 17:16:53 +02:00
vkms_drv.c drm/vkms: Use wait_for_flip_done 2019-09-03 17:16:53 +02:00
vkms_drv.h drm/vkms: drop use of drmP.h 2019-07-15 18:11:30 +02:00
vkms_gem.c drm/vkms: drop use of drmP.h 2019-07-15 18:11:30 +02:00
vkms_output.c drm/vkms: Avoid assigning 0 for possible_crtc 2019-07-12 00:45:49 -03:00
vkms_plane.c drm/vkms: drop use of drmP.h 2019-07-15 18:11:30 +02:00