From patchwork Wed Mar 27 23:03:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 2353651 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 7343F3FC8C for ; Wed, 27 Mar 2013 23:16:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 768FDE65C6 for ; Wed, 27 Mar 2013 16:16:23 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ea0-f175.google.com (mail-ea0-f175.google.com [209.85.215.175]) by gabe.freedesktop.org (Postfix) with ESMTP id 75AB9E5DCB for ; Wed, 27 Mar 2013 16:15:33 -0700 (PDT) Received: by mail-ea0-f175.google.com with SMTP id r16so966733ead.6 for ; Wed, 27 Mar 2013 16:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=DMuKzp6dQ8tIgYxgQGhIHy2Ex7YnFX9J8aT35tnnsjQ=; b=iDgJqj49447kEC02PJmsoIlzV0usZoiYIhK3qZj65NcrVNqMV/WnIZ/MQdN2Op98Gr kvCm/qHJpE0/7CKMkWraBb0CIdD1bskBl5j4xVOxLpfe00GTAruGU9YzDp9SsnhTgBcf JtDp+qoiU+5WJKNsSuCSOSoK/Tqzci5r1BSL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=DMuKzp6dQ8tIgYxgQGhIHy2Ex7YnFX9J8aT35tnnsjQ=; b=SG28Ae+LUkXYjWk7KfcxgMgQL3VFuHrlZk4MJs7Liepa5RrBCI3KITIUguDLpNZFS2 HWxp9POzr8E3afcMv8ks36vdA7V1OEo/ZESoXgCvOares621eE7m4G/KOqUvazDSw2/s Rck3Y+YpyeaL5dIT2VSP4nVIIZLxCKH5QNxQTfDj9yzqjl5a2Ba1yc+lT/Qzd9qKnARU ymUB427/BWBVMSB+JMwzmRhgWoHztFotPUev0OmdZyvw35P3gC1FI1/DF5wZZwIsug25 vfrG5IaMmyj2d+2V7j3bD7vw41CjJCDcTTYkBOUGV0kC6zJ5WDNtnmSOT29IXQfxgEfn UBgA== X-Received: by 10.15.35.193 with SMTP id g41mr49520765eev.45.1364426132545; Wed, 27 Mar 2013 16:15:32 -0700 (PDT) Received: from wespe.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id bc1sm22899963eeb.11.2013.03.27.16.15.30 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 27 Mar 2013 16:15:31 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Thu, 28 Mar 2013 00:03:25 +0100 Message-Id: <1364425405-1200-2-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1364425405-1200-1-git-send-email-daniel.vetter@ffwll.ch> References: <1364425405-1200-1-git-send-email-daniel.vetter@ffwll.ch> X-Gm-Message-State: ALoCoQlClWUuV5J2xmyQvk5ePEhh8OTAtsCjhsguL9WYGFFSQmjSx2b87hQYO8aTHzM5C0Moesx+ Cc: Daniel Vetter , Thomas Gleixner , Jack Winter Subject: [Intel-gfx] [PATCH 2/2] drm/i915: fix up _wait_for macro X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org As Thomas Gleixner spotted, it's rather horrible racy: - We can miss almost a full tick, so need to compensate by 1 jiffy. - We need to re-check the condition when having timed-out, since a the last check could have been before the timeout expired. E.g. when we've been preempted or a long irq happened. Cc: Thomas Gleixner Reported-by: Jack Winter Cc: Jack Winter Signed-off-by: Daniel Vetter Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/i915/intel_drv.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index c8c1979..9dcae4e 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -33,12 +33,21 @@ #include #include +/** + * _wait_for - 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 + * 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); \ + unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \ int ret__ = 0; \ while (!(COND)) { \ if (time_after(jiffies, timeout__)) { \ - ret__ = -ETIMEDOUT; \ + if (!(COND)) \ + ret__ = -ETIMEDOUT; \ break; \ } \ if (W && drm_can_sleep()) { \