From patchwork Tue May 17 15:43:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 9113921 Return-Path: X-Original-To: patchwork-intel-gfx@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 318729F30C for ; Tue, 17 May 2016 15:43:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55BBC20268 for ; Tue, 17 May 2016 15:43:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C5F86201FE for ; Tue, 17 May 2016 15:43:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19A016E60F; Tue, 17 May 2016 15:43:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 5AF2D6E68E for ; Tue, 17 May 2016 15:43:31 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 17 May 2016 08:43:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,324,1459839600"; d="scan'208";a="956447395" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.90]) by orsmga001.jf.intel.com with ESMTP; 17 May 2016 08:43:30 -0700 Received: by rosetta (Postfix, from userid 1000) id 47F3881944; Tue, 17 May 2016 18:43:29 +0300 (EEST) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Tue, 17 May 2016 18:43:24 +0300 Message-Id: <1463499808-3335-4-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463499808-3335-1-git-send-email-mika.kuoppala@intel.com> References: <1463499808-3335-1-git-send-email-mika.kuoppala@intel.com> Subject: [Intel-gfx] [PATCH 3/7] drm/i915: Spin opportunistically in wait_for X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 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=-5.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 Usually the condition we are after appears within very short time. Spin few times before going into sleep. With this approximately half of the wait_for in init path will take the fast path without sleeping. Signed-off-by: Mika Kuoppala Reviewed-by: Daniel Vetter --- drivers/gpu/drm/i915/intel_drv.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index 488141929a7a..c225605c727c 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -39,7 +39,7 @@ #include /** - * _wait_for_ms - magic (register) wait macro + * __wait_for_ms - magic (register) wait macro * * Does the right thing for modeset paths when run under kdgb or similar atomic * contexts. Note that it's important that we check the condition again after @@ -50,17 +50,22 @@ * drm_can_sleep() can be removed and in_atomic()/!in_atomic() asserts * added. */ -#define _wait_for_ms(COND, TIMEOUT_MS, SLEEP_US) ({ \ +#define __wait_for_ms(COND, TIMEOUT_MS, SLEEP_US, SPIN_COUNT) ({ \ const unsigned long timeout__ = \ jiffies + msecs_to_jiffies(TIMEOUT_MS) + 1; \ + unsigned int c__ = 0; \ int ret__ = 0; \ + \ while (!(COND)) { \ if (time_after(jiffies, timeout__)) { \ if (!(COND)) \ ret__ = -ETIMEDOUT; \ break; \ } \ - if ((SLEEP_US) && drm_can_sleep()) { \ + \ + if (++c__ > (SPIN_COUNT) && \ + (SLEEP_US) && \ + drm_can_sleep()) { \ usleep_range((SLEEP_US), (SLEEP_US) * 2); \ } else { \ cpu_relax(); \ @@ -69,7 +74,8 @@ ret__; \ }) -#define wait_for(COND, MS) _wait_for_ms((COND), (MS), 1 * USEC_PER_MSEC) +#define wait_for(COND, MS) __wait_for_ms((COND), (MS), 1 * USEC_PER_MSEC, 5) +#define _wait_for_ms(COND, MS, US) __wait_for_ms((COND), (MS), (US), 5) /* If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false. */ #if defined(CONFIG_DRM_I915_DEBUG) && defined(CONFIG_PREEMPT_COUNT)