From patchwork Tue Mar 25 05:59:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun R Murthy X-Patchwork-Id: 3885351 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D3E10BF540 for ; Tue, 25 Mar 2014 05:59:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B2B520136 for ; Tue, 25 Mar 2014 05:59:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2E54320109 for ; Tue, 25 Mar 2014 05:59:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE7AD6E03F; Mon, 24 Mar 2014 22:59:19 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 654336E03C for ; Mon, 24 Mar 2014 22:59:18 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 24 Mar 2014 22:59:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,726,1389772800"; d="scan'208";a="479326754" Received: from armurthy-desktop.iind.intel.com ([10.223.25.113]) by orsmga001.jf.intel.com with ESMTP; 24 Mar 2014 22:59:15 -0700 From: Arun R Murthy To: daniel.vetter@ffwll.ch, jani.nikula@linux.intel.com, intel-gfx@lists.freedesktop.org, airlied@linux.ie, chris@chris-wilson.co.uk Date: Tue, 25 Mar 2014 11:29:02 +0530 Message-Id: <1395727142-5423-1-git-send-email-arun.r.murthy@intel.com> X-Mailer: git-send-email 1.7.9.5 Cc: Arun R Murthy Subject: [Intel-gfx] [PATCH v3] drm/i915: use hrtimer in wait for vblank X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 In wait for vblank use usleep_range, which will use hrtimers instead of msleep. Using msleep(1~20) there are more chances of sleeping for 20ms. Using usleep_range uses hrtimers and hence are precise, worst case will trigger an interrupt at the higher/max timeout. Change-log: On replacing msleep(1) with usleep_range(1000, 2000) we have noticed the time consumed by wait for vblank is ~4ms to ~17ms. Change-Id: I6672e5697b01987a6d069ab06e76d97287b1f7ae Signed-off-by: Arun R Murthy --- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_dp.c | 4 ++-- drivers/gpu/drm/i915/intel_drv.h | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 4d4a0d9..9de2678 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -761,7 +761,7 @@ static void g4x_wait_for_vblank(struct drm_device *dev, int pipe) frame = I915_READ(frame_reg); - if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50)) + if (wait_for_us(I915_READ_NOTRACE(frame_reg) != frame, 50, 1000)) DRM_DEBUG_KMS("vblank wait timed out\n"); } diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c index f1ef3d4..14927e5 100644 --- a/drivers/gpu/drm/i915/intel_dp.c +++ b/drivers/gpu/drm/i915/intel_dp.c @@ -1074,7 +1074,7 @@ static void wait_panel_status(struct intel_dp *intel_dp, I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); - if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) { + if (wait_for_ms((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) { DRM_ERROR("Panel status timeout: status %08x control %08x\n", I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg)); @@ -1808,7 +1808,7 @@ void intel_edp_psr_disable(struct intel_dp *intel_dp) I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE); /* Wait till PSR is idle */ - if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) & + if (wait_for_ms((I915_READ(EDP_PSR_STATUS_CTL(dev)) & EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10)) DRM_ERROR("Timed out waiting for PSR Idle State\n"); } diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index 44067bc..bbda97e 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -42,8 +42,8 @@ * having timed out, since the timeout could be due to preemption or similar and * we've never had a chance to check the condition before the timeout. */ -#define _wait_for(COND, MS, W) ({ \ - unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \ +#define _wait_for(COND, TIMEOUT, MS, US) ({ \ + unsigned long timeout__ = jiffies + msecs_to_jiffies(TIMEOUT) + 1;\ int ret__ = 0; \ while (!(COND)) { \ if (time_after(jiffies, timeout__)) { \ @@ -51,8 +51,11 @@ ret__ = -ETIMEDOUT; \ break; \ } \ - if (W && drm_can_sleep()) { \ - msleep(W); \ + if ((MS | US) && drm_can_sleep()) { \ + if (MS) \ + msleep(MS); \ + else \ + usleep_range(US, US * 2); \ } else { \ cpu_relax(); \ } \ @@ -60,10 +63,12 @@ ret__; \ }) -#define wait_for(COND, MS) _wait_for(COND, MS, 1) -#define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0) +#define wait_for(COND, TIMEOUT) _wait_for(COND, TIMEOUT, 1, 0) +#define wait_for_ms(COND, TIMEOUT, MS) _wait_for(COND, TIMEOUT, MS, 0) +#define wait_for_us(COND, TIMEOUT, US) _wait_for(COND, TIMEOUT, 0, US) +#define wait_for_atomic(COND, TIMEOUT) _wait_for(COND, TIMEOUT, 0, 0) #define wait_for_atomic_us(COND, US) _wait_for((COND), \ - DIV_ROUND_UP((US), 1000), 0) + DIV_ROUND_UP((US), 1000), 0, 0) #define KHz(x) (1000 * (x)) #define MHz(x) KHz(1000 * (x))