From: Thierry Reding Subject: Re: [PATCH v4 6/9] drm/tegra: Implement page-flipping support Date: Mon, 25 Feb 2013 08:06:57 +0100 Message-ID: <20130225070657.GB18053@avionic-0098.mockup.avionic-design.de> References: <1361457361-13838-1-git-send-email-thierry.reding@avionic-design.de> <1361457361-13838-7-git-send-email-thierry.reding@avionic-design.de> <5127993B.3020100@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0033904597==" Return-path: Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by gabe.freedesktop.org (Postfix) with ESMTP id 387C0E5C55 for ; Sun, 24 Feb 2013 23:07:04 -0800 (PST) In-Reply-To: <5127993B.3020100@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: Mario Kleiner Cc: Mario Kleiner , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0033904597== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MW5yreqqjyrRcusr" Content-Disposition: inline --MW5yreqqjyrRcusr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 22, 2013 at 05:13:47PM +0100, Mario Kleiner wrote: > On 02/21/2013 03:35 PM, Thierry Reding wrote: > >All the necessary support bits like .mode_set_base() and VBLANK are now > >available, so page-flipping case easily be implemented on top. > > > >Signed-off-by: Thierry Reding > >--- > >Changes in v3: > >- use drm_send_vblank_event() > >- set crtc->fb field > > > >Changes in v4: > >- fix a potential race by checking that a framebuffer base has been > > latched when completing a page-flip > > > > drivers/gpu/drm/tegra/dc.c | 66 +++++++++++++++++++++++++++++++++++++= ++++++++ > > drivers/gpu/drm/tegra/dc.h | 2 ++ > > drivers/gpu/drm/tegra/drm.c | 9 +++++++ > > drivers/gpu/drm/tegra/drm.h | 5 ++++ > > 4 files changed, 82 insertions(+) > > > >diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c > >index 5f55a25..c5d825f 100644 > >--- a/drivers/gpu/drm/tegra/dc.c > >+++ b/drivers/gpu/drm/tegra/dc.c > >@@ -183,7 +183,72 @@ void tegra_dc_disable_vblank(struct tegra_dc *dc) > > spin_unlock_irqrestore(&dc->lock, flags); > > } > >+static void tegra_dc_finish_page_flip(struct tegra_dc *dc) > >+{ > >+ struct drm_device *drm =3D dc->base.dev; > >+ struct drm_crtc *crtc =3D &dc->base; > >+ struct drm_gem_cma_object *gem; > >+ unsigned long flags, base; > >+ >=20 > The checks for properly latched scanout look good to me and should > fix the race between software and hardware. But shouldn't you > already spin_lock_irqsave() here, before checking dc->event and > performing write access on the DC_CMD_STATE_ACCESS registers? And > lock around most of the tegra_dc_page_flip() code below, like in > your previous iteration of the patch, to prevent a race between > pageflip ioctl and the vblank irq handler? Currently there's nothing else that touches the DC_CMD_STATE_ACCESS register, so that part should be safe. As to the locking that I removed since the previous patch, I looked at it more closely and didn't think it was necessary. Also nothing in my tests seemed to point to any race here, though I probably didn't cover everything. > >+ if (!dc->event) >=20 > -> !dc->event may exit prematurely because the irq handler on one > core doesn't notice the new setup of dc->event by > tegra_dc_page_flip() on a different core? Don't know if that can > happen, don't know the memory ordering of arm, but could imagine > that this or the compiler reordering instructions could cause > trouble without lock protection. I'm not sure I follow here. If the handler sees a NULL here, why would it want to continue? It can safely assume that the page flip wasn't setup for this interval, can't it? If indeed the VBLANK interrupt happens exactly around the assignment to dc->event, then we'll just schedule the page-flip for the next VBLANK. > >+ return; > >+ > >+ gem =3D drm_fb_cma_get_gem_obj(crtc->fb, 0); > -> crtc->fb gets updated in tegra_dc_page_flip() after > tegra_dc_set_base() without lock -> possibly stale fb here? Good point. That may indeed require a lock. I'll need to look more closely. > >+ /* check if new start address has been latched */ > >+ tegra_dc_writel(dc, READ_MUX, DC_CMD_STATE_ACCESS); > >+ base =3D tegra_dc_readl(dc, DC_WINBUF_START_ADDR); > >+ tegra_dc_writel(dc, 0, DC_CMD_STATE_ACCESS); > >+ >=20 > -> Can other code in the driver write to DC_CMD_STATE_ACCESS, > simultaneously to tegra_dc_page_flip writing->reading->writing and > cause trouble? This is the only location where the DC_CMD_STATE_ACCESS register is actually used in the driver so we should be safe for now. > >+static int tegra_dc_page_flip(struct drm_crtc *crtc, struct drm_framebu= ffer *fb, > >+ struct drm_pending_vblank_event *event) > >+{ > >+ struct tegra_dc *dc =3D to_tegra_dc(crtc); > >+ struct drm_device *drm =3D crtc->dev; > >+ > >+ if (dc->event) > >+ return -EBUSY; > >+ >=20 > -> Lock already here? >=20 > >+ if (event) { > >+ event->pipe =3D dc->pipe; > >+ dc->event =3D event; > >+ drm_vblank_get(drm, dc->pipe); > >+ } > >+ > >+ tegra_dc_set_base(dc, 0, 0, fb); > >+ crtc->fb =3D fb; > >+ >=20 > -> Unlock here? I tried to expand the lock after we discussed this previously but it caused the code to deadlock. While in the process of tracking it down I decided that the lock wasn't actually required at all. But I hadn't thought about the stale FB issue, so I'll check again. I notice that Dave has already merged this series, so if nobody objects I'll fix it up in a follow-up patch. Thierry --MW5yreqqjyrRcusr Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAEBAgAGBQJRKw2RAAoJEN0jrNd/PrOhzN8QALK5V9p9uuIWW00xVAuyQ4RW K+4h4qPgtOFalxFOwztvNGeldP5e81jSfBpsUxKlE9r4B9ZCm/WiyAMSNpVRk7d+ KyK03BxJBXlEY0WvcF+0JhYtCF+duRb09GrJScf2EEjDNxAj/sjyhKFaZuVJKDWf gPvZab7IpqfPorJZg/u84j70MomVPQlVCKuYl/Fm860tat7AJowEjk1pvdgESpYP 4oNDuG1Sjrdrxu+u+aTaLPDQUoouBkBOcNwlnjCXwvj7D0YaPdtywEcEdRHLjtYQ Xa16QY8yfZS1oCh4LwHNbNzPWrA6NETJcaratGmJpF+txd6kyTkYDnSfsU03+Csf bIl3E+PmmRVOebEFgNOGBAL4vha3o5NlTrf07QUolhMlbz7AThznFRJb3Wm64uDM pA5kTmHW16jvxSlJdzM7h4Xp+cX8Np1vhm3hHymyiyBe19+peSZ39KK7+jGknc8K BqJaua5Gfj8YSHOU++hA1Icq+zwNGn0NAL6Pg/0Ci5s+g8/26ObS/X0LJsl8aDLp W3YprRzCOCqiX8SNiZZ5LKNmXm837VXwqDvDNjZ7HKEQcTrD+ABOxjs/neicA57o oKENZYILvkilFUoffwZoBFViZSAQh7RJHnMGSwja5GysBJItumDQJG6Jzeusg0qm aGXs/F6wnG4x6i6aXu9f =eAe2 -----END PGP SIGNATURE----- --MW5yreqqjyrRcusr-- --===============0033904597== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel --===============0033904597==--