dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Shayenne Moura <shayenneluzmoura@gmail.com>,
	Haneen Mohammed <hamohammed.sa@gmail.com>,
	David Airlie <airlied@linux.ie>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/vkms: Solve bug on kms_crc_cursor tests
Date: Mon, 11 Mar 2019 16:27:10 +0200	[thread overview]
Message-ID: <20190311142710.GY3888@intel.com> (raw)
In-Reply-To: <20190310203505.2needmil76a4rc74@smtp.gmail.com>

On Sun, Mar 10, 2019 at 05:35:05PM -0300, Rodrigo Siqueira wrote:
> On 03/01, Ville Syrjälä wrote:
> > On Fri, Mar 01, 2019 at 03:35:35PM -0300, Shayenne Moura wrote:
> > > Em sex, 1 de mar de 2019 às 12:26, Ville Syrjälä
> > > <ville.syrjala@linux.intel.com> escreveu:
> > > >
> > > > On Fri, Mar 01, 2019 at 11:55:11AM -0300, Shayenne Moura wrote:
> > > > > Em qui, 28 de fev de 2019 às 11:03, Ville Syrjälä
> > > > > <ville.syrjala@linux.intel.com> escreveu:
> > > > > >
> > > > > > On Thu, Feb 28, 2019 at 11:11:07AM +0100, Daniel Vetter wrote:
> > > > > > > On Mon, Feb 25, 2019 at 11:26:06AM -0300, 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.
> > > > > > > >
> > > > > > > > Signed-off-by: Shayenne Moura <shayenneluzmoura@gmail.com>
> > > > > > >
> > > > > > > Sorry for the delay, I'm a bit swamped right now :-/
> > > > > > >
> > > > > > > Debug work you're doing here is really impressive! But I have no idea
> > > > > > > what's going on. It doesn't look like it's just papering over a bug (like
> > > > > > > the in_vblank_irq check we've discussed on irc), but I also have no idea
> > > > > > > why it works.
> > > > > > >
> > > > > > > I'll pull in Ville, he understands this better than me.
> > > > > >
> > > > > > It's not entirely clear what we're trying to fix. From what I can see
> > > > > > the crc work seems to be in no way synchronized with page flips, so
> > > > > > I'm not sure how all this is really supposed to work.
> > > > > >
> > > > >
> > > > > Hi, Ville!
> > > > >
> > > > > Thank you for the review! :)
> > > > >
> > > > > I do not understand well what crc code is doing, but the issue that I found
> > > > > is related to the vblank timestamp and frame count.
> > > > >
> > > > > When vkms handles the crc_cursor it uses the start frame and end frame
> > > > > values to verify if it needs to call the function 'drm_crtc_add_crc_entry()'
> > > > > for each frame.
> > > > >
> > > > > However, when getting the frame count, the code is calling the function
> > > > > drm_update_vblank_count(dev, pipe, false) and, because of the 'false',
> > > > > subtracting the actual vblank timestamp (consequently, the frame count
> > > > > value), causing conflicts.
> > > >
> > > > The in_vblank_irq behavour looks sane to me. What are these conflicts?
> > > >
> > > 
> > > The entire history was:
> > >  - I sent the patch with bugfix for vblank extra frame. The patch changed
> > >    our function vkms_get_vblank_timestamp() to look like this:
> > > 
> > > bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
> > >                    int *max_error, ktime_t *vblank_time,
> > >                    bool in_vblank_irq)
> > > {
> > >     struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
> > >     struct vkms_output *output = &vkmsdev->output;
> > > 
> > >     *vblank_time = output->vblank_hrtimer.node.expires;
> > > 
> > > +   if (!in_vblank_irq)
> > > +        *vblank_time -= output->period_ns;
> > > 
> > >     return true;
> > > }
> > > 
> > >  - This patch solve the issue that I was looking for (extra vblank
> > > frames on kms_flip).
> > > 
> > >  - However, kms_cursor_crc tests, which passed before my patch, started to fail.
> > > 
> > >  - Debugging them, I found that the problem was inside of function
> > > `vkms_vblank_simulate()`
> > > when it was handling the crc_enabled (inside  if (state && output->crc_enabled))
> > > and inside the function vkms_crc_work_handle() too.
> > > 
> > >  - Following the 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).  /* This false is default */
> > > 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).
> > > 
> > >  - Inside vkms_crc, the issue is that the returned frame value change for
> > > every call of drm_crtc_accurate_vblank_count() because
> > > in_vblank_irq == false.
> 
> Hi Ville,
>  
> > OK. So why is it changing? AFAICS it should not change unless the
> > timer was moved forward in between the calls.
> 
> Yes Ville, you’re right. We have to update it only when the function
> vkms_vblank_simulate() is invoked (timer move forward), and FWIU we do
> it when we call drm_crtc_handle_vblank(). However, the current
> implementation of vkms, has a call to drm_crtc_accurate_vblank_count()
> inside the vkms_vblank_simulate() which is a problem because it also
> update the vblank value. FWIU, this patch fixes this issue by taking the
> count value in the data struct instead of call
> drm_crtc_accurate_vblank_count() which will avoid the extra update.

But why does that extra update change the vblank count?

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2019-03-11 14:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 14:26 [PATCH] drm/vkms: Solve bug on kms_crc_cursor tests Shayenne Moura
2019-02-25 21:48 ` Rodrigo Siqueira
2019-02-28 10:11 ` Daniel Vetter
2019-02-28 10:14   ` Daniel Vetter
2019-02-28 14:03   ` Ville Syrjälä
2019-03-01 14:55     ` Shayenne Moura
2019-03-01 15:25       ` Ville Syrjälä
2019-03-01 18:35         ` Shayenne Moura
2019-03-01 18:41           ` Ville Syrjälä
2019-03-10 20:35             ` Rodrigo Siqueira
2019-03-11 14:27               ` Ville Syrjälä [this message]
2019-03-15 11:51                 ` Rodrigo Siqueira
2019-03-15 13:48                   ` Ville Syrjälä
2019-03-18 19:36                     ` Rodrigo Siqueira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190311142710.GY3888@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hamohammed.sa@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigosiqueiramelo@gmail.com \
    --cc=shayenneluzmoura@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).