From patchwork Wed Sep 3 11:55:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 4834791 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E0779F314 for ; Wed, 3 Sep 2014 13:43:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F8FF2020E for ; Wed, 3 Sep 2014 13:43:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 93A3C201FB for ; Wed, 3 Sep 2014 13:43:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7D4EB6E570; Wed, 3 Sep 2014 06:43:11 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D5356E542 for ; Wed, 3 Sep 2014 04:55:36 -0700 (PDT) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s83BtaFq006002; Wed, 3 Sep 2014 06:55:36 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s83BtZe2010728; Wed, 3 Sep 2014 06:55:36 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 3 Sep 2014 06:55:35 -0500 Received: from deskari.lan (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s83BtNQH004347; Wed, 3 Sep 2014 06:55:34 -0500 From: Tomi Valkeinen To: Rob Clark , Subject: [PATCH 7/9] drm/omap: fix omap_crtc_flush() to handle the workqueue Date: Wed, 3 Sep 2014 14:55:08 +0300 Message-ID: <1409745310-19092-7-git-send-email-tomi.valkeinen@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409745310-19092-1-git-send-email-tomi.valkeinen@ti.com> References: <1409745310-19092-1-git-send-email-tomi.valkeinen@ti.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 03 Sep 2014 06:43:10 -0700 Cc: Tomi Valkeinen X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP omap_crtc_flush() is used to wait for scheduled work to be done for the give crtc. However, it's not quite right at the moment. omap_crtc_flush() does wait for work that is ran via vsync irq to be done. However, work is also queued to the driver's priv->wq workqueue, which is not handled by omap_crtc_flush(). Improve omap_crtc_flush() to flush the workqueue so that work there will be ran. This fixes a race issue on module unload, where an unpin work may be on the work queue, but does not get ran before drm core starts tearing the driver down, leading to a WARN. Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_crtc.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c index 3261fbf94957..506cf8bc804f 100644 --- a/drivers/gpu/drm/omapdrm/omap_crtc.c +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c @@ -655,21 +655,42 @@ static void omap_crtc_post_apply(struct omap_drm_apply *apply) /* nothing needed for post-apply */ } +static bool omap_crtc_work_pending(struct omap_crtc *omap_crtc) +{ + return !list_empty(&omap_crtc->pending_applies) || + !list_empty(&omap_crtc->queued_applies) || + omap_crtc->event || omap_crtc->old_fb; +} + +/* + * Wait for any work on the workqueue to be finished, and any work which will + * be run via vsync irq to be done. + * + * Note that work on workqueue could schedule new vsync work, and vice versa. + */ void omap_crtc_flush(struct drm_crtc *crtc) { struct omap_crtc *omap_crtc = to_omap_crtc(crtc); + struct omap_drm_private *priv = crtc->dev->dev_private; int loops = 0; - while (!list_empty(&omap_crtc->pending_applies) || - !list_empty(&omap_crtc->queued_applies) || - omap_crtc->event || omap_crtc->old_fb) { + while (true) { + /* first flush the wq, so that any scheduled work is done */ + flush_workqueue(priv->wq); + + /* if we have nothing queued for this crtc, we're done */ + if (!omap_crtc_work_pending(omap_crtc)) + break; if (++loops > 10) { - dev_err(crtc->dev->dev, - "omap_crtc_flush() timeout\n"); + dev_err(crtc->dev->dev, "omap_crtc_flush() timeout\n"); break; } + /* + * wait for a bit so that a vsync has (probably) happened, and + * that the crtc work is (probably) done. + */ schedule_timeout_uninterruptible(msecs_to_jiffies(20)); } }