All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kazlauskas, Nicholas" <Nicholas.Kazlauskas-5C7GfCeVMHo@public.gmane.org>
To: "Michel Dänzer" <michel-otUistvHUpPR7s880joybQ@public.gmane.org>,
	"Ville Syrjälä"
	<ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: "daniel.vetter-/w4YWyX8dFk@public.gmane.org"
	<daniel.vetter-/w4YWyX8dFk@public.gmane.org>,
	"Olsak, Marek" <Marek.Olsak-5C7GfCeVMHo@public.gmane.org>,
	"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
	<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
	"manasi.d.navare-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org"
	<manasi.d.navare-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	"dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
	<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
	"Deucher,
	Alexander" <Alexander.Deucher-5C7GfCeVMHo@public.gmane.org>,
	"Wentland, Harry" <Harry.Wentland-5C7GfCeVMHo@public.gmane.org>
Subject: Re: [PATCH v4 3/4] drm: Document variable refresh properties
Date: Wed, 31 Oct 2018 13:38:24 +0000	[thread overview]
Message-ID: <311638a8-eb8a-cb8d-3f7a-109aaa4b046b@amd.com> (raw)
In-Reply-To: <1c1c0f6f-ccbd-bfc2-f249-a01f6fc997ec-5C7GfCeVMHo@public.gmane.org>

On 10/30/18 11:34 AM, Kazlauskas, Nicholas wrote:
> On 10/30/18 5:29 AM, Michel Dänzer wrote:
>> On 2018-10-29 7:03 p.m., Ville Syrjälä wrote:
>>> On Mon, Oct 29, 2018 at 05:37:49PM +0100, Michel Dänzer wrote:
>>>> On 2018-10-26 7:59 p.m., Ville Syrjälä wrote:
>>>>> On Fri, Oct 26, 2018 at 05:34:15PM +0000, Kazlauskas, Nicholas wrote:
>>>>>> On 10/26/18 10:53 AM, Ville Syrjälä wrote:
>>>>>>>
>>>>>>> Speaking of timestamps. What is the expected behaviour of vblank
>>>>>>> timestamps when vrr is enabled?
>>>>>>
>>>>>> When vrr is enabled the duration of the vertical front porch will be
>>>>>> extended until flip or timeout occurs. The vblank timestamp will vary
>>>>>> based on duration of the vertical front porch. The min/max duration for
>>>>>> the front porch can be specified by the driver via the min/max range.
>>>>>>
>>>>>> No changes to vblank timestamping handling should be necessary to
>>>>>> accommodate variable refresh rate.
>>>>>
>>>>> The problem is that the timestamp is supposed to correspond to the first
>>>>> active pixel. And since we don't know how long the front porch will be
>>>>> we can't realistically report the true value. So I guess just assuming
>>>>> min front porch length is as good as anything else?
>>>>
>>>> That (and documenting that the timestamp corresponds to the earliest
>>>> possible first active pixel, not necessarily the actual one, with VRR)
>>>> might be good enough for the actual vblank event timestamps.
>>>>
>>>>
>>>> However, I'm not so sure about the timestamps of page flip completion
>>>> events. Those could be very misleading if the flip completes towards the
>>>> timeout, which could result in bad behaviour of applications which use
>>>> them for animation timing.
>>>>
>>>> Maybe the timestamp could be updated appropriately (yes, I'm hand-waving
>>>> :) in drm_crtc_send_vblank_event?
>>>
>>> Hmm. Updated how? Whether it's a page flip event or vblank even we won't
>>> know when the first active pixel will come. Although I suppose if
>>> there is some kind of vrr slew rate limit we could at least account
>>> for that to report a more correct "this is the earliest you migth be
>>> able to see your frame" timestamp.
>>>
>>> Oh, or are you actually saying that shceduling a new flip before the
>>> timeout is actually going to latch that flip immediately? I figured
>>> that the flip would get latched on the next start of vblank regardless,
>>> and the act of scheduling a flip will just kick the hardware to start
>>> scanning the previously latched frame earlier.
>>>
>>> scanout A | ... vblank | scanout A | ... vblank | scanout B | ... vblank
>>>                     ^                ^        ^               ^
>>>                     |                |        flip C          latch C
>>>                     flip B           latch B
>>
>> This would kind of defeat the point of VRR, wouldn't it? If a flip was
>> scheduled after the start of vblank, the vblank would always time out,
>> resulting in the minimum refresh rate.
>>
>>
>>> scanout A | ... vblank | scanout B | ... vblank | scanout C | ... vblank
>>>                     ^ ^                      ^ ^
>>>                     | latch B                | latch C
>>>                     flip B                   flip C
>>
>> So this is what happens.
>>
>> Regardless, when the flip is latched, AMD hardware generates a "pflip"
>> interrupt, and its handler calls drm_crtc_send_vblank_event (and in the
>> case of DC drm_crtc_accurate_vblank_count before that). So the time when
>> drm_crtc_send_vblank_event is called might be a good approximation of
>> when scanout of the next frame starts.
>>
>> Another possibility might be to wait for the hardware vline counter to
>> wrap around to 0 before calling drm_crtc_accurate_vblank_count, then the
>> calculations should be based on 0 instead of crtc_vtotal.
>>
>>
> 
> 
> I understand the issue you're describing now. The timestamp is supposed
> to signify the end of the current vblank. The call to get scanout
> position is supposed to return the number of lines until scanout (a
> negative value) or the number of lines since the next scanout began (a
> positive value).
> 
> The amdgpu driver calculates the number of lines based on a hardware
> register status position which returns an increasing value from 0 that
> indicates the current vpos/hpos for the display.
> 
> For any vpos below vbl_start we know the value is correct since the next
> vblank hasn't begun yet. But for anythign about vbl_start it's probably
> wrong since it applies a corrective offset based on the fixed value of
> crtc_vtotal. It's even worse when the value is above crtc_vtotal since
> it'll be calculating the number of lines since the last scanout since
> it'll be a positive value.
> 
> So the issue becomes determining when the vfront porch will end.
> 
> When the flip address gets written the vfront porch will end at the
> start of the next line leaving only the back porch plus part of the
> line. But we don't know when the flip will occur, if at all. It hasn't
> occurred yet in this case.
> 
> Waiting for the wrap around to 0 might be the best choice here since
> there's no guarantee the flip will occur.
> 
> Nicholas Kazlauskas
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

I put some more thought into this and I don't think this is as bad as I 
had originally thought.

I think the vblank timestamp is supposed to be for the first active 
pixel of the next scanout. The usage of which is for clients to time 
their content/animation/etc.

The client likely doesn't care when they issue their flip, just that 
their content is matched for that vblank timestamp. The fixed refresh 
model works really well for that kind of application.

Utilizing variable refresh rate would be a mistake in that case since 
the client would then have to time based on when they flip which is a 
lot harder to "predict" precisely.

I did some more investigation into when amdgpu gets the scanout position 
and what values we get back out of it. The timestamp is updated shortly 
after the crtc irq vblank which is typically within a few lines of 
vbl_start. This makes sense, since we can provide the prediction 
timestamp early. Waiting for the vblank to wrap around to 0 doesn't 
really make sense here since that would mean we already hit timeout or 
the flip occurred - making the timestamp useless and probably burning a 
ton of CPU to do it.

What this means is that we're going to have to make some sort of 
prediction based on a fixed duration to have a reasonable result. I 
think assuming the min front porch duration (max refresh) is the logical 
approach here - in most cases this will be crtc_vtotal since it's the 
monitor's fastest refresh. For clients that flip early this will end up 
being the correct timestamp. No need to explicitly check for variable 
refresh enabled in the get scanout pos handler either.

There is one little caveat with get scanout pos with that approach, 
however. For usages other than the timestamp the number of lines until 
scanout will still be incorrect when going above crtc_vtotal. We can 
either assume the worst in this case (the max front porch duration, the 
min refresh/timeout) or clamp and just return the size of the back porch 
instead The vpos will look stalled, but the flip will likely happen 
sooner than the timeout in most cases so this will likely work out better.

Nicholas Kazlauskas
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-10-31 13:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11 16:39 [PATCH v4 0/4] A DRM API for adaptive sync and variable refresh rate support Nicholas Kazlauskas
2018-10-11 16:39 ` [PATCH v4 2/4] drm: Add vrr_enabled property to drm CRTC Nicholas Kazlauskas
2018-10-11 16:39 ` [PATCH v4 3/4] drm: Document variable refresh properties Nicholas Kazlauskas
     [not found]   ` <20181011163942.28267-4-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org>
2018-10-26 11:37     ` Pekka Paalanen
2018-10-26 14:49       ` Kazlauskas, Nicholas
     [not found]         ` <bdda3a3b-c912-98bf-8dbd-29a5b58086df-5C7GfCeVMHo@public.gmane.org>
2018-10-26 14:53           ` Ville Syrjälä
     [not found]             ` <20181026145321.GV9144-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-10-26 17:34               ` Kazlauskas, Nicholas
     [not found]                 ` <f21251f7-10e2-e0f7-702d-bd3868ac8edc-5C7GfCeVMHo@public.gmane.org>
2018-10-26 17:59                   ` Ville Syrjälä
2018-10-29 16:37                     ` Michel Dänzer
     [not found]                       ` <481ae686-adda-5857-5538-2b0af2e25427-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-10-29 18:03                         ` Ville Syrjälä
     [not found]                           ` <20181029180341.GN9144-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-10-29 19:11                             ` Kazlauskas, Nicholas
     [not found]                               ` <3b03a13a-5418-b4fc-137f-2f917b3947d3-5C7GfCeVMHo@public.gmane.org>
2018-10-30  9:07                                 ` Michel Dänzer
2018-10-30  9:29                             ` Michel Dänzer
2018-10-30 15:34                               ` Kazlauskas, Nicholas
     [not found]                                 ` <1c1c0f6f-ccbd-bfc2-f249-a01f6fc997ec-5C7GfCeVMHo@public.gmane.org>
2018-10-31 13:38                                   ` Kazlauskas, Nicholas [this message]
     [not found]                                     ` <311638a8-eb8a-cb8d-3f7a-109aaa4b046b-5C7GfCeVMHo@public.gmane.org>
2018-10-31 14:12                                       ` Michel Dänzer
2018-10-31 14:41                                         ` Kazlauskas, Nicholas
2018-10-31 16:20                                           ` Michel Dänzer
2018-10-31 17:54                                             ` Kazlauskas, Nicholas
2018-11-01  8:37                                               ` Pekka Paalanen
     [not found]                                               ` <87bcab42-e377-259c-13ea-0cfe9c675cf9-5C7GfCeVMHo@public.gmane.org>
2018-11-01 10:58                                                 ` Michel Dänzer
     [not found]                                                   ` <99214cf0-9717-3c23-9457-791288d4d252-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-11-01 14:58                                                     ` Kazlauskas, Nicholas
2018-11-01 17:05                                                       ` Michel Dänzer
     [not found]                                                         ` <8617ac72-ec32-8146-cead-e28e78067ec0-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-11-01 17:19                                                           ` Kazlauskas, Nicholas
2018-10-26 19:13                   ` Manasi Navare
2018-10-26 20:06                     ` Kazlauskas, Nicholas
2018-10-26 20:58                       ` Manasi Navare
2018-10-29  8:36                   ` Pekka Paalanen
2018-10-29 14:31                     ` Kazlauskas, Nicholas
     [not found] ` <20181011163942.28267-1-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org>
2018-10-11 16:39   ` [PATCH v4 1/4] drm: Add vrr_capable property to the drm connector Nicholas Kazlauskas
2018-10-11 16:39   ` [PATCH v4 4/4] drm/amd/display: Set FreeSync state using drm VRR properties Nicholas Kazlauskas
     [not found]     ` <20181011163942.28267-5-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org>
2018-10-11 20:39       ` Harry Wentland
     [not found]         ` <42b237df-9c30-4cd0-0891-d0b05b54533e-5C7GfCeVMHo@public.gmane.org>
2018-10-11 20:56           ` Kazlauskas, Nicholas
2018-10-11 21:24             ` Harry Wentland

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=311638a8-eb8a-cb8d-3f7a-109aaa4b046b@amd.com \
    --to=nicholas.kazlauskas-5c7gfcevmho@public.gmane.org \
    --cc=Alexander.Deucher-5C7GfCeVMHo@public.gmane.org \
    --cc=Harry.Wentland-5C7GfCeVMHo@public.gmane.org \
    --cc=Marek.Olsak-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=daniel.vetter-/w4YWyX8dFk@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=manasi.d.navare-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=michel-otUistvHUpPR7s880joybQ@public.gmane.org \
    --cc=ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.