From: Mario Kleiner <mario.kleiner.de-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Thierry Reding
<thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
Cc: "Terje Bergström"
<tbergstrom-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
"linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
"Mario Kleiner"
<mario.kleiner-TdbV1Z3I5XE0NhjG498hmQ@public.gmane.org>
Subject: Re: [PATCH v2 5/5] drm/tegra: Implement page-flipping support
Date: Fri, 15 Feb 2013 23:34:26 +0100 [thread overview]
Message-ID: <511EB7F2.4070603@gmail.com> (raw)
In-Reply-To: <20130211090001.GA3423-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
On 02/11/2013 10:00 AM, Thierry Reding wrote:
> On Tue, Jan 22, 2013 at 06:27:24PM +0100, Mario Kleiner wrote:
>> On 22.01.13 09:31, Terje Bergström wrote:
>>> On 14.01.2013 18:06, Thierry Reding wrote:
>>>> +static int tegra_dc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
>>>> + struct drm_pending_vblank_event *event)
>>>> +{
>>>> + struct tegra_framebuffer *newfb = to_tegra_fb(fb);
>>>> + struct tegra_dc *dc = to_tegra_dc(crtc);
>>>> + struct drm_device *drm = crtc->dev;
>>>> + unsigned long flags;
>>>> +
>>>> + if (dc->event)
>>>> + return -EBUSY;
>> Hi
>>
>> I haven't read the Tegra programming manual or played with this, so
>> maybe i'm wrong for some reason, but i think there is a race here
>> between actual pageflip completion - latching newfb into the scanout
>> base register and the completion routine that gets called from the
>> vblank irq handler.
>>
>> If this code gets called close to vblank or inside vblank, couldn't
>> it happen that tegra_dc_set_base() programs a pageflip that gets
>> executed immediately - the new fb gets latched into the crtc, but
>> the corresponding vblank irq handler for the vblank of flip
>> completion runs before the "if (event)" block can set dc->event =
>> event;? Or vblank irq's are off because drm_vblank_get() is only
>> called at the end of the routine? In both cases the completion
>> routine would miss the correct vblank and only timestamp and emit
>> the completion event 1 vblank after actual flip completion.
>>
>> In that case it would be better to place tegra_dc_set_base() after
>> the "if (event)" block and have some check inside the flip
>> completion routine to make sure the pageflip completion event is
>> only emitted if the scanout is really already latched with the
>> newfb.
> An easier solution might be to expand the scope of the lock a bit to
> encompass the call to tegra_dc_set_base() and extend until the end of
> tegra_dc_page_flip(). That should properly keep the page-flip completion
> from interfering, right?
>
> spin_lock_irqsave(&drm->event_lock, flags);
>
> tegra_dc_set_base(dc, 0, 0, newfb);
>
> if (event) {
> event->pipe = dc->pipe;
> dc->event = event;
> drm_vblank_get(drm, dc->pipe);
> }
>
> spin_unlock_irqrestore(&drm->event_lock, flags);
>
> Thierry
Yes, that would avoid races between page flip ioctl and the irq handler.
But i think the tegra_dc_set_base() should go below the if (event) {}
block, before the spin_unlock_irqrestore() so you can be sure that
drm_vblank_get() has been called before tegra_dc_set_base() is executed.
Otherwise vblank irq's may be off during the vblank in which the
tegra_dc_set_base() takes effect and a flip complete would only get
reported one scanout cycle later at the next vblank -> You'd signal a
pageflip completion 1 frame too late.
You also still need to check in tegra_dc_finish_page_flip() if the new
scanout buffer has really been latched before emitting the flip complete
event. Otherwise it could happen that your execution of
tegra_dc_page_flip() intersects with the vblank interval and manages to
queue the event in time, so the finish_page_flip picks it up, but the
register programming in tegra_dc_set_base() happened a bit too late, so
it doesn't get latched in the same vblank but one vblank later --> You'd
signal pageflip completion 1 frame too early.
I've just downloaded the Tegra-3 TRM and had a quick look. Section
20.5.1 "Display shadow registers". As far as i understand, if dc->event
is pending in tegra_dc_finish_page_flip(), you could read back the
ACTIVE copy of DC_WINBUF_START_ADDR by setting READ_MUX properly in
DC_CMD_STATE_ACCESS_0, and compare its value against the ARM copy in
DC_WINBUF_A_START_ADDR_NS_0. If both values match, the pageflip has
happened and the dc->event can be dequeued and emitted.
That assumes that the ARM copy is latched into the ACTIVE copy only at
leading edge of vblank. Section 20.5.1 says "...latching happens on the
next frame boundary after (GENERAL/WIN_A/WIN_B/WIN_C)_ACT_REQ is
programmed..." - not totally clear to me if this is the same as start of
vblank?
-mario
prev parent reply other threads:[~2013-02-15 22:34 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-14 16:05 [PATCH v2 0/5] drm/tegra: Miscellaneous enhancements Thierry Reding
[not found] ` <1358179560-26799-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2013-01-14 16:05 ` [PATCH v2 1/5] drm: Allow vblank support without DRIVER_HAVE_IRQ Thierry Reding
2013-01-14 16:05 ` [PATCH v2 2/5] drm/tegra: Add plane support Thierry Reding
[not found] ` <1358179560-26799-3-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2013-01-14 17:03 ` Lucas Stach
2013-01-15 11:19 ` Thierry Reding
2013-01-15 9:53 ` Mark Zhang
[not found] ` <50F526FF.1010101-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-01-15 10:50 ` Lucas Stach
2013-01-18 3:59 ` Mark Zhang
2013-01-15 11:35 ` Ville Syrjälä
[not found] ` <20130115113532.GC3503-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-01-15 11:50 ` Thierry Reding
2013-01-14 16:05 ` [PATCH v2 3/5] drm/tegra: Implement .mode_set_base() Thierry Reding
[not found] ` <1358179560-26799-4-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2013-01-14 17:14 ` Lucas Stach
2013-01-17 6:10 ` Mark Zhang
2013-01-14 16:05 ` [PATCH v2 4/5] drm/tegra: Implement VBLANK support Thierry Reding
[not found] ` <1358179560-26799-5-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2013-01-22 17:37 ` Mario Kleiner
[not found] ` <50FECE63.7090009-TdbV1Z3I5XE0NhjG498hmQ@public.gmane.org>
2013-01-22 18:39 ` Lucas Stach
2013-01-22 18:49 ` Jon Mayo
[not found] ` <CADWT_cOjVg9-hB+jWuEUr+Ou-YECBN73WQXNy17qXf3TO1ZjpQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-01-22 19:59 ` Mario Kleiner
[not found] ` <50FEEF92.9060009-TdbV1Z3I5XE0NhjG498hmQ@public.gmane.org>
2013-01-23 8:02 ` Terje Bergström
[not found] ` <50FF990C.3040902-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-02-11 9:08 ` Thierry Reding
[not found] ` <20130211090840.GB3423-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
2013-02-11 15:43 ` Terje Bergström
2013-01-22 19:20 ` Mario Kleiner
[not found] ` <50FEE681.7020208-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-01-22 19:27 ` Jon Mayo
[not found] ` <CADWT_cOpSBR+DiKwQ4PvYk8-o88Wf5=Tz+ho_g4MdUVKMtc-dw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-01-22 20:08 ` Mario Kleiner
2013-02-11 9:13 ` Thierry Reding
2013-02-15 22:38 ` Mario Kleiner
2013-01-14 16:06 ` [PATCH v2 5/5] drm/tegra: Implement page-flipping support Thierry Reding
[not found] ` <1358179560-26799-6-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2013-01-16 11:10 ` Mark Zhang
[not found] ` <50F68AB2.4030408-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-01-16 11:53 ` Lucas Stach
2013-01-17 4:49 ` Mark Zhang
2013-01-17 6:33 ` Mark Zhang
2013-01-22 8:31 ` Terje Bergström
[not found] ` <50FE4E4F.6080506-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-22 8:57 ` Thierry Reding
[not found] ` <20130122085756.GA6315-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
2013-01-22 9:15 ` Lucas Stach
2013-01-22 9:31 ` Thierry Reding
[not found] ` <20130122093150.GA22264-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
2013-01-22 9:44 ` Terje Bergström
[not found] ` <50FE5F61.4080103-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-22 9:48 ` Lucas Stach
2013-01-22 10:39 ` Terje Bergström
2013-01-22 9:35 ` Terje Bergström
2013-01-22 17:27 ` Mario Kleiner
[not found] ` <50FECBFC.8080307-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-02-11 9:00 ` Thierry Reding
[not found] ` <20130211090001.GA3423-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
2013-02-15 22:34 ` Mario Kleiner [this message]
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=511EB7F2.4070603@gmail.com \
--to=mario.kleiner.de-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mario.kleiner-TdbV1Z3I5XE0NhjG498hmQ@public.gmane.org \
--cc=tbergstrom-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@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 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).