From patchwork Thu Mar 16 23:47:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9629451 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 9BC3960132 for ; Thu, 16 Mar 2017 23:47:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D4F028665 for ; Thu, 16 Mar 2017 23:47:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 820372867F; Thu, 16 Mar 2017 23:47:59 +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 E93EA28665 for ; Thu, 16 Mar 2017 23:47:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15B196EC38; Thu, 16 Mar 2017 23:47:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 993826EC38; Thu, 16 Mar 2017 23:47:54 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id l37so7680705wrc.3; Thu, 16 Mar 2017 16:47:54 -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=L1fwqmUjlaXmqWqf6v5pnqfj+huzRCUe8Z+a+TDhVWM=; b=V3gTkeI7f27zftouh2sMnTO9BvzGfm2pKPLuKq82l5sslXtq+u7YuVSxwUjBZYyyWd 6dPsWkVc+JSKb4a/psfkoDhTRw3M7Il9ImvltciuqIexLHjFKTB3MJt0t0H4yUc83g8V zfjKRQ7PS4mYQrxwpjif8G91gv4EdTl3VFCH1oCpENb8K87/XYWzbhL3nD9m7cRhM5TB 1/eN/lLVzvvM25iHLsIOTBYmmVuAw4a+I0GHGMqSvd39Jhf/praLe6jBCzRzgP7F31jH riu6+fNMhB1IBXOZTPMcK4j7vHTBi+sPZtmswnasLQZDaUEVgd1Cy3bKuPobC/qQqN/t Nw3g== 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=L1fwqmUjlaXmqWqf6v5pnqfj+huzRCUe8Z+a+TDhVWM=; b=R+zfNz+c/JQoxJaRL6uCguHdG0HxH/6h4pH/YBWvGgVj31psq9xh6ZbJ4uEdyrlXKw Yc05JtbwwwNu6UaTm3ytmT6QXczoqnczl2UbkncsmCSBvftbTTF33MoNqRWf8vtLplVR 2SWiCohKnZm5DwLA/q/3NNxHSVkARvA+dXd3YOvFZNCAWVBuS13p2TmMRK2XKanc2SPT HsjiZLtKO3xIkQMY5ynqvPANeWZ0bg6OsNFQ/RsrNNfnsCYTv1LlbBzomYy2DiD2bxSG M+aoJG67OKQHGMM9xfY+VPMUjod6oD9BY+pyROgitgAt1DvXcIa8tYqdPtdPaq1ORq3A CaUw== X-Gm-Message-State: AFeK/H3eQTL+i6R8STNSd7+V76A/lBxr6+F2m4FClGuQKfgV/s/9w5Ia8T+99td4q0OZGw== X-Received: by 10.223.182.133 with SMTP id j5mr11513910wre.19.1489708073365; Thu, 16 Mar 2017 16:47:53 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id r2sm616684wmb.26.2017.03.16.16.47.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 16:47:52 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm: Peek at the current counter/timestamp for vblank queries Date: Thu, 16 Mar 2017 23:47:49 +0000 Message-Id: <20170316234749.1297-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170316234749.1297-1-chris@chris-wilson.co.uk> References: <20170316234749.1297-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 4cc9352ab6a8..b4bd361a2bcc 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1562,6 +1562,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. * @@ -1611,6 +1622,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);