From patchwork Wed Jan 6 11:09:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 7967461 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 317509F1C0 for ; Wed, 6 Jan 2016 11:10:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B6C420122 for ; Wed, 6 Jan 2016 11:10:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7030F201BC for ; Wed, 6 Jan 2016 11:10:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 149CB6E592; Wed, 6 Jan 2016 03:10:12 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C3626E58F; Wed, 6 Jan 2016 03:10:10 -0800 (PST) Received: by mail-wm0-f53.google.com with SMTP id f206so55463657wmf.0; Wed, 06 Jan 2016 03:10:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=HzMVshuO+aUqEglNdpsCEE0YY8T6ZHy6qCXvlFdRT+g=; b=tJckhLqDZ6VQr1PmiIkX2Is+V08Az2H4oOapiV1l/GCMWvU7S7y3fdfKRCNam6EiIH BRcosGzBRyjeX3H5VoM3gu/HVMq8+IytMWwaTFbRnbv9WCLCYTgqnxvfRzi+iX3+F1l8 w+vP0UKie5XD0l5I8uD5zJ03MzrCQjuCrDtIaCwViC8rxsOIk9pJ3f/mZWN9YUuGUp+B zdKBlIOguoXp3Q0HwttGY+lMcZLn52gsXG+qRnsC/AkQmS7oEVjfex0JtLXbSE22fve6 HRkFpLmqd2MbQpsDZQLUy3CQY00QWz5EhSStTirdZfs55jPuAUeC+4Fwy5yeqwBRPKND 3a3w== X-Received: by 10.194.235.137 with SMTP id um9mr44474379wjc.146.1452078608618; Wed, 06 Jan 2016 03:10:08 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id n129sm8171364wmb.1.2016.01.06.03.10.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jan 2016 03:10:07 -0800 (PST) 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, 6 Jan 2016 11:09:55 +0000 Message-Id: <1452078595-2840-3-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1452078595-2840-1-git-send-email-chris@chris-wilson.co.uk> References: <1452078595-2840-1-git-send-email-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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 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 866cf58a36c5..00298b39e7fc 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1659,6 +1659,17 @@ err_put: 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. * @@ -1708,6 +1719,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);