From patchwork Fri Mar 17 20:20:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9631553 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 9E6C760245 for ; Fri, 17 Mar 2017 20:20:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92B13285A1 for ; Fri, 17 Mar 2017 20:20:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 878D0285D4; Fri, 17 Mar 2017 20:20:45 +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 159EB285A1 for ; Fri, 17 Mar 2017 20:20:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 38A386EDAE; Fri, 17 Mar 2017 20:20:41 +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 36F506EDA9; Fri, 17 Mar 2017 20:20:38 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u132so4940812wmg.1; Fri, 17 Mar 2017 13:20:38 -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=K7rMD5Zj/O3o+n67CM/wh1G/C3K5L9ZTsuZ5f8g/AWo=; b=PN9BwbKUffN7JX5xrNL3A5EHqjEI/f7x0YRxWx7kRzLvW9prugN+HQ5VztjoxOfYcl mowUSo/NnC0WwxlSgnymnfTYzHRLJnCsq6iSbXfTx4zvVXw/xoOgl6ALB5JPU3tSyfjQ TYbH0tbMx9+PzO2RFqipWfwr/E5Uyfaj6gcRBRo406aINppfqRD+bT+WnlqNxlgc5a/n y8IfnSfybidseX21d88qZHMDPtUvMtjalHtsVSK0+c9Wozb210eGgqqrQlrcm2rJAYnZ rL8GPy9oXYr2L62pM56ER4HItHwW17enBbrGcGYcBcPtwNPXoBDgGW7zUPm/HLbbEjVJ mIYQ== 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=K7rMD5Zj/O3o+n67CM/wh1G/C3K5L9ZTsuZ5f8g/AWo=; b=SPrSR3DrYTzrT5a6U4T5WOnJoBai6gmQqvQCyQ+wVcbh9tE9Fjv7w6WdEln62RnQ0G xnlbBFyJvgePFeGIR5fe1Mj1nxrTzcdNPmn6ObSQ+LzyArRz2GBOtV+RcosIlFmybGfI UV6MAbO530IJtW4DBJiwqIOprQpe2kWdIEmBrGtSN3kR8uKZYPYW6fICZJ2iSV/OMJZa 7q6X5UTP0fJ0pfEU+d3otPxWk0AZPexqPCOYykAFkBydoH6hwXUpsBirqr0iNOysvCVp eKx78qOgOCBf9tsI/hG//mviVoxndZIrQlH5USN9bFxHg6/IGIAQxZoiW42mo1qjeJS5 bcYg== X-Gm-Message-State: AFeK/H2vC5SB+fSy474pA2zJjaDhqFzv9zJeqy9zR1H0e1/eUXXd+0FdIYsfburlcr2HSQ== X-Received: by 10.28.133.84 with SMTP id h81mr65885wmd.23.1489782036804; Fri, 17 Mar 2017 13:20:36 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id k139sm3829222wmg.11.2017.03.17.13.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 13:20:35 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/4] drm: Peek at the current counter/timestamp for vblank queries Date: Fri, 17 Mar 2017 20:20:30 +0000 Message-Id: <20170317202030.24410-4-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170317202030.24410-1-chris@chris-wilson.co.uk> References: <20170317202030.24410-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 253505da57bd..846401548ec9 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1569,6 +1569,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. * @@ -1618,6 +1629,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) && + READ_ONCE(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);