Re: [PATCH] drm/vkms: Solve bug on kms_crc_cursor tests

From: Rodrigo Siqueira
Date: Mon Feb 25 2019 - 16:49:03 EST


Hi,

First of all, thanks for your patch!

I think you figured out the reason for the extra frame problems :)

The patch worked like a charm. Almost all of the tests in kms_flip are
passing, and the tests related to kms_cursor_crc are working again \o/

I just have some cosmetic comments inline.

On 02/25, Shayenne Moura wrote:
> vkms_crc_work_handle needs the value of the actual frame to
> schedule the workqueue that calls periodically the vblank
> handler and the destroy state functions. However, the frame
> value returned from vkms_vblank_simulate is updated and
> diminished in vblank_get_timestamp because it is not in a
> vblank interrupt, and return an inaccurate value.
>
> Solve this getting the actual vblank frame directly from the
> vblank->count inside the `struct drm_crtc`, instead of using
> the `drm_accurate_vblank_count` function.

AFAIU, I think the problem that you describe happens when
vkms_vblank_simulate() execute, because of the following steps:

1. Inside vkms_vblank_simulate() we call drm_crtc_accurate_vblank_count()
2. In its turn, drm_crtc_accurate_vblank_count() calls the function
drm_update_vblank_count(dev, pipe, false).
3. Finally, the âfalseâ used in drm_update_vblank_count(), will be
passed to vkms_get_vblank_timestamp() and the condition âif
(!in_vblank_irq)â will be executed multiple times (we donât want it).

Am I correct? If so, I recommend you to add this level of detail about
the problem and the solution. Finally, IMHO you could change the commit
message for something that describes the problem related to the extra
decrement made by drm_crtc_accurate_vblank_count() inside
vkms_vblank_simulate().

> Signed-off-by: Shayenne Moura <shayenneluzmoura@xxxxxxxxx>
> ---
> drivers/gpu/drm/vkms/vkms_crc.c | 4 +++-
> drivers/gpu/drm/vkms/vkms_crtc.c | 4 +++-
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c
> index d7b409a3c0f8..09a8b00ef1f1 100644
> --- a/drivers/gpu/drm/vkms/vkms_crc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crc.c
> @@ -161,6 +161,8 @@ void vkms_crc_work_handle(struct work_struct *work)
> struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
> struct vkms_device *vdev = container_of(out, struct vkms_device,
> output);
> + unsigned int pipe = drm_crtc_index(crtc);
> + struct drm_vblank_crtc *vblank = &crtc->dev->vblank[pipe];
> struct vkms_crc_data *primary_crc = NULL;
> struct vkms_crc_data *cursor_crc = NULL;
> struct drm_plane *plane;
> @@ -196,7 +198,7 @@ void vkms_crc_work_handle(struct work_struct *work)
> if (primary_crc)
> crc32 = _vkms_get_crc(primary_crc, cursor_crc);
>
> - frame_end = drm_crtc_accurate_vblank_count(crtc);
> + frame_end = vblank->count;
>
> /* queue_work can fail to schedule crc_work; add crc for
> * missing frames
> diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> index 8a9aeb0a9ea8..9bf3268e2e92 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -10,6 +10,8 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
> vblank_hrtimer);
> struct drm_crtc *crtc = &output->crtc;
> struct vkms_crtc_state *state = to_vkms_crtc_state(crtc->state);
> + unsigned int pipe = drm_crtc_index(crtc);
> + struct drm_vblank_crtc *vblank = &crtc->dev->vblank[pipe];

How about have have a function for this operation?

Perhaps, someone here or in the dri-devel channel knows any helper
already available to get this information, try to ask in the channel.

Thanks

> u64 ret_overrun;
> bool ret;
>
> @@ -20,7 +22,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
> DRM_ERROR("vkms failure on handling vblank");
>
> if (state && output->crc_enabled) {
> - u64 frame = drm_crtc_accurate_vblank_count(crtc);
> + u64 frame = vblank->count;
>
> /* update frame_start only if a queued vkms_crc_work_handle()
> * has read the data
> --
> 2.17.1
>

--
Rodrigo Siqueira
https://siqueira.tech
Graduate Student
Department of Computer Science
University of SÃo Paulo

Attachment: signature.asc
Description: PGP signature