From patchwork Wed Mar 22 10:06:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9638399 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 2C559602CB for ; Wed, 22 Mar 2017 10:06:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F9D7275A2 for ; Wed, 22 Mar 2017 10:06:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 127612842B; Wed, 22 Mar 2017 10:06:57 +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 6D66F275A2 for ; Wed, 22 Mar 2017 10:06:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2D388986D; Wed, 22 Mar 2017 10:06:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 99F778986D; Wed, 22 Mar 2017 10:06:54 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id z133so8266697wmb.2; Wed, 22 Mar 2017 03:06: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=leh55W+2UHq5jb2wWcW1mO0lzA+GyB7KmfwGJNhxROA=; b=qYGquG5q0Q6rnF4W7A/xy/3RnBY6mGifdwjrJAV3NWhZHeUSPCBBQUO+GuCCfDGuPC nATA1qoP5HArvQfIq+4oCGE1yDFVugm+VgZMnjTCSJqVXxgkDdmiHTdDqQK0/dtuxFWs yDxygxiE0o3X+ryjnRVIS+71amGlOpv8aLcomSNPpIG/wJFZkUZxAAUFhH82wN8QRWfK yBz+d9qMZnv/xMwJNwRsiLUmQbKAsOICwy184Vuz+iSTJlGyw1Um2EArSkDp3eZGUTa1 cr8Da+eEVTEPPm7S+a18UHATk4lCKQb3yqiJ/kp+sA42DGdG1/To3NCQDqzKnCMgBwPg aATQ== 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=leh55W+2UHq5jb2wWcW1mO0lzA+GyB7KmfwGJNhxROA=; b=R21GGQ0u23qBW2/R9K4ccko5e5prdefXUw4dcaUpM5GcyP75WjALs6ZhSKu1VCVV5d G02tDV46GQ86IfzyUe8oENGY4gVnQBNXYJveZob1ZWR9NgLwXniwQZzsUPz6JlX2anvS bd3f8QK+ykvrQYEBqhAsL+jkc7q4h4EV95LOYUGd4i8kb7+hoRpq6HV+Lg++EWm5kQb/ fH7vwCKi4Fs+abcURdqQfMcfAIPQzYfeOEiKhtMv6dWodLrihVslVprCmgLwq61ABBMK pbtMTi0Vc2LHFItKV0dYNFSJIwDJ1R1r8uQ1BMUc1G/OJomHiR3oml7Q9waPucc26bA2 33IQ== X-Gm-Message-State: AFeK/H3anw+6ombPmkI7Zid62qdDTJwDqlYFALHVcwTJFinz3uOq/KbgoMSlRk/g0h32iA== X-Received: by 10.28.184.8 with SMTP id i8mr6466490wmf.26.1490177213237; Wed, 22 Mar 2017 03:06:53 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id x1sm1185600wrd.63.2017.03.22.03.06.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 03:06:52 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm: Refactor vblank sequence number comparison Date: Wed, 22 Mar 2017 10:06:50 +0000 Message-Id: <20170322100650.26082-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170317202030.24410-3-chris@chris-wilson.co.uk> References: <20170317202030.24410-3-chris@chris-wilson.co.uk> MIME-Version: 1.0 Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org, =?UTF-8?q?Michel=20D=C3=A4nzer?= 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 Move the repeated (a - b) <= (1 << 23) to its own function. v2: Catch the '1<<23' inside drm_handle_vblank() as well Signed-off-by: Chris Wilson Cc: Ville Syrjälä Cc: Daniel Vetter Cc: Michel Dänzer Reviewed-by: Michel Dänzer --- drivers/gpu/drm/drm_irq.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index a164cf51d093..9efe1eacabe7 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1492,6 +1492,11 @@ int drm_legacy_modeset_ctl(struct drm_device *dev, void *data, return 0; } +static inline bool vblank_passed(u32 seq, u32 ref) +{ + return (seq - ref) <= (1 << 23); +} + static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, union drm_wait_vblank *vblwait, struct drm_file *file_priv) @@ -1542,7 +1547,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, vblwait->request.sequence); e->event.sequence = vblwait->request.sequence; - if ((seq - vblwait->request.sequence) <= (1 << 23)) { + if (vblank_passed(seq, vblwait->request.sequence)) { drm_vblank_put(dev, pipe); send_vblank_event(dev, e, seq, &now); vblwait->reply.sequence = seq; @@ -1632,9 +1637,8 @@ int drm_wait_vblank(struct drm_device *dev, void *data, } if ((flags & _DRM_VBLANK_NEXTONMISS) && - (seq - vblwait->request.sequence) <= (1 << 23)) { + vblank_passed(seq, vblwait->request.sequence)) vblwait->request.sequence = seq + 1; - } if (flags & _DRM_VBLANK_EVENT) { /* must hold on to the vblank ref until the event fires @@ -1647,8 +1651,8 @@ int drm_wait_vblank(struct drm_device *dev, void *data, DRM_DEBUG("waiting on vblank count %u, crtc %u\n", vblwait->request.sequence, pipe); DRM_WAIT_ON(ret, vblank->queue, 3 * HZ, - (drm_vblank_count(dev, pipe) - - vblwait->request.sequence) <= (1 << 23) || + vblank_passed(drm_vblank_count(dev, pipe), + vblwait->request.sequence) || !READ_ONCE(vblank->enabled)); } @@ -1683,7 +1687,7 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe) list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { if (e->pipe != pipe) continue; - if ((seq - e->event.sequence) > (1<<23)) + if (!vblank_passed(seq, e->event.sequence)) continue; DRM_DEBUG("vblank event on %u, current %u\n",