From patchwork Wed Mar 15 20:40:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9626643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BF17604A9 for ; Wed, 15 Mar 2017 20:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DCED22B27 for ; Wed, 15 Mar 2017 20:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6274128637; Wed, 15 Mar 2017 20:40:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1156C22B27 for ; Wed, 15 Mar 2017 20:40:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7DCA96E965; Wed, 15 Mar 2017 20:40:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id BDE8C6E962; Wed, 15 Mar 2017 20:40:34 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u132so6578371wmg.1; Wed, 15 Mar 2017 13:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RSZRMMiRdGoRHW6i98/p3+Tgg5WpXPQ5wuIgb4a5TQc=; b=viAHpdHlTGaqxKuhsGtrtXPYTwxXn/raQzn4pti7GY9ohslKXEc846mrCOiWPi5BBD +7X1I3qZLYrJ0yw56cnigyJlbF623Eesmnc8+6bej+hpJluBMhPbbLyHIGtFRKVMRiOK cSwIzPXs1Nl+XDGZlx2hOm22eWNntlknfZDyRPdi9Haqt+G7hceQYM/+fmnYFm2emy8+ DKDly1AjAmuY5jJZnGfYw4sCLmCoQT3vDuydo+b1yf1gZAcSRPMOK0v+3M8iCiLnQXHc 9SKySnnOjiFTP13PWbT4rASwkl+HgMuqg9qzISE8tVLdjzbygH9LxOpNRdHEtVieVmXr 2/EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RSZRMMiRdGoRHW6i98/p3+Tgg5WpXPQ5wuIgb4a5TQc=; b=ICG9cq1xw3jcJUEvhvgMg0zyT96Xr3HCWsi9JRztCRyD0yAI88cTOtDc1YLM2fi+dl cGd+b8lVGd7J/idzMDR3dTk6teo0llH+J4lCE6MEm4iCzy4uz8jr7mXmnQY9lrIizWpe cu0aFtcLV9c7v4Y2C8qgoy4CGSKc6d98sNAnVajYz+1tysbniGD3OtC99ASLG5dz1WIN 6+2WjTRKAuuTZz04FgrO+HMp3bYgNTqKf98frB2GQOIJEPSTxdL9dLguJYuG/BEbQheX vJi89fBsDqpdAfGeEqjxxIUQ4q09a6S8j4ophDCsR0wEKEjjba8g5zW9IGQLGzrbECsL apMw== X-Gm-Message-State: AFeK/H29nS0kX5cIDUmhq2rjED3jw8U00Sxv0PDIyuzmj/YQnp7lt50pO/stgIiVbg3tsg== X-Received: by 10.28.26.196 with SMTP id a187mr21070524wma.33.1489610433301; Wed, 15 Mar 2017 13:40:33 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id z88sm3643199wrb.26.2017.03.15.13.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 13:40:32 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm: Peek at the current counter/timestamp for vblank queries Date: Wed, 15 Mar 2017 20:40:27 +0000 Message-Id: <20170315204027.20160-3-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170315204027.20160-1-chris@chris-wilson.co.uk> References: <20170315204027.20160-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Cc: =?UTF-8?q?Michel=20D=C3=A4nzer?= , Laurent Pinchart , Dave Airlie , intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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-Virus-Scanned: ClamAV using ClamSMTP Bypass all the spinlocks and return the last timestamp and counter from the last vblank if the driver delcares that it is accurate (and stable across on/off), and the vblank is currently enabled. This is dependent upon the both the hardware and driver to provide the proper barriers to facilitate reading our bookkeeping outside of the vblank interrupt and outside of the explicit vblank locks. Signed-off-by: Chris Wilson Cc: Ville Syrjälä Cc: Daniel Vetter Cc: Michel Dänzer Cc: Laurent Pinchart Cc: Dave Airlie , Cc: Mario Kleiner --- drivers/gpu/drm/drm_irq.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 53a526c7b24d..c55abce152a2 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1559,6 +1559,17 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, return ret; } +static bool drm_wait_vblank_is_query(union drm_wait_vblank *vblwait) +{ + if (vblwait->request.sequence) + return false; + + return _DRM_VBLANK_RELATIVE == + (vblwait->request.type & (_DRM_VBLANK_TYPES_MASK | + _DRM_VBLANK_EVENT | + _DRM_VBLANK_NEXTONMISS)); +} + /* * Wait for VBLANK. * @@ -1608,6 +1619,21 @@ int drm_wait_vblank(struct drm_device *dev, void *data, vblank = &dev->vblank[pipe]; + /* If the counter is currently enabled and accurate, short-circuit queries + * to return the cached timestamp of the last vblank. + */ + if (dev->vblank_disable_immediate && + drm_wait_vblank_is_query(vblwait) && + vblank->enabled) { + struct timeval now; + + vblwait->reply.sequence = + drm_vblank_count_and_time(dev, pipe, &now); + vblwait->reply.tval_sec = now.tv_sec; + vblwait->reply.tval_usec = now.tv_usec; + return 0; + } + ret = drm_vblank_get(dev, pipe); if (ret) { DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret);