Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4881539ybv; Mon, 17 Feb 2020 07:43:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxfbl4NvPb3XDX7XndDn1W7Az1CZJibR0qX4D5EpfXHoo4d1GMt4f5GBsq7HIAshUW9fT7z X-Received: by 2002:a9d:4110:: with SMTP id o16mr12728059ote.101.1581954187475; Mon, 17 Feb 2020 07:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581954187; cv=none; d=google.com; s=arc-20160816; b=q1Z4eMXqq+GQhHuxW216oDRZ9rakbiLz/62NWYh/tWkEILjMgQp3EGDoMZXZvQOjO+ OugHwqDCjAwGfVoMKz7kpKxDVkgXUjqVFCSn40VV9GyUi7QxtVr7WCCSP3jiqP4yatS2 KObnPZkaRK/XxhLskEI/AHDViKI03Iau3gUq63gsvv995RwXOGe66RH2dZVsy79DwSCZ EXZ6SRsoMvLD3iQYmOzaHTTKM4OGn38fMnDf1dbzRuQuBNVTxYDEs1Nt7BDuwLhcu9kF 2uzPWvT4uuaPcnN15JKCF9FPFfKc9ulJfUY2YrcOmFQmCCkylh+8tNgWzyJuupeVeHzJ HWTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=556jZPK8Ln3qyMHoFnra5q+K0qfU/YwU5Nw6Aae+qSY=; b=mccpnfO+fM7tquuBSpr/yDn38bgVFmm5ymu/ZFnqMikOw44ak6OVk2iMI8Owr5TEGl kliK1v9Q1tVXX24QgWCdm9o9SKvPyQy6sGOATGrDBzBpYZDbEZ5gQLvWIuYmTb2ySl8K fx0xEy3OOsJf4NK5gHUKk7vPkhxZWd8CPKUje0I7o7UOOV7goAOdUrRAk4Ulp6urh2Ck i3psNe4ZLCiP7eTbP6Ae3Z1RzqvjZXiOCkN6k8LgZhGo4NBeYtGJM+2s6KUUI2IT1wJw jQ5l+MJQDgIcSposZk32TyX3EN5xO1oVRkgGa0Xpffja9w8QnSJ2AB6GLOdoncj/rnv6 tzyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=ebSOobPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si6535382oik.46.2020.02.17.07.42.54; Mon, 17 Feb 2020 07:43:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=ebSOobPA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=raspberrypi.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729301AbgBQPlS (ORCPT + 99 others); Mon, 17 Feb 2020 10:41:18 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33681 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728000AbgBQPlS (ORCPT ); Mon, 17 Feb 2020 10:41:18 -0500 Received: by mail-wm1-f66.google.com with SMTP id m10so176780wmc.0 for ; Mon, 17 Feb 2020 07:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id; bh=556jZPK8Ln3qyMHoFnra5q+K0qfU/YwU5Nw6Aae+qSY=; b=ebSOobPAYTfm2SFuYNP5SBLHSOZxKMF0XUXrOnV6s6UX7fzQNW7s1ZFIPs/qhlDMKA aPLGSHIUH0720Ztqotj6iPs6Yme49UDIXnaup04lUoweD4a24uE2garU5w5KE1CS1DA4 MZxD3AjAENeWCdA9LtpaNTtSrkwHpNspFMPQdEfZolIw6WD8MvM5qMltMrTFg4CwTAAa aP4JZjwnJqu0hFALewUWR2bCfDoGr69gP4UYaLe80B5CYgLcNxb0acndzHMcMm6phCSZ gBVWlzhHWdoH3FFmhmPXqzG/25RPG3awBC7oyA7Ga66em9xIsonwI5MfVZo86I70CnGd anAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=556jZPK8Ln3qyMHoFnra5q+K0qfU/YwU5Nw6Aae+qSY=; b=ucUgBDFBwKHVU3R1Bg5ymRhg1+KUBK4rYhtLhZY36cBGfKDrjD3eT3O1JnFDob52y4 VL0ynGTrbPTbJH4LsZ/JFMNePqwMiQmh8QDLykrHeOQHa9xWGsCc9jsMN4x+M/vU9rVy ahHWSb1sQ+BmHT1KDFN0BvwnF2P22eEoNaL9UErnAOE3ZU6h7JBTOqRQERrfHl8z8LYh oH/1T7EFQ2I2k2vzmjYs7DFQbv6A2WoZGK/k550z/+ptT27XIvfNWwSN92oKf2wlxW/T Zz1ZabgfHiFZ/rQrkZRrqBHxHHOgK+bYbKEBo93LyOJ+yM5Q4qUSa1DuQNposBPCjDC2 kpQA== X-Gm-Message-State: APjAAAVv67S6w11uduZejpfeKQFSKQ/Y/KX5Fskaru4qZkAhx6mGaLf0 GsEtRdaqaXrXKYuRbhShYHQ/Cw== X-Received: by 2002:a7b:c5cd:: with SMTP id n13mr22849920wmk.172.1581954074099; Mon, 17 Feb 2020 07:41:14 -0800 (PST) Received: from jamesh-VirtualBox.pitowers.org ([2a00:1098:3142:14:9260:684f:13fd:35ee]) by smtp.gmail.com with ESMTPSA id h2sm1546370wrt.45.2020.02.17.07.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 07:41:13 -0800 (PST) From: James Hughes To: eric@anholt.net, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: James Hughes Subject: [PATCH] GPU: DRM: VC4/V3D Replace wait_for macros in to remove use of msleep Date: Mon, 17 Feb 2020 15:31:45 +0000 Message-Id: <20200217153145.13780-1-james.hughes@raspberrypi.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The wait_for macro's for Broadcom VC4 and V3D drivers used msleep which is inappropriate due to its inaccuracy at low values (minimum wait time is about 30ms on the Raspberry Pi). This patch replaces the macro with the one from the Intel i915 version which uses usleep_range to provide more accurate waits. Signed-off-by: James Hughes --- drivers/gpu/drm/v3d/v3d_drv.h | 41 ++++++++++++++++++++++----------- drivers/gpu/drm/vc4/vc4_drv.h | 43 +++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h index 7b4f3b5a086e..069fefe16d28 100644 --- a/drivers/gpu/drm/v3d/v3d_drv.h +++ b/drivers/gpu/drm/v3d/v3d_drv.h @@ -267,27 +267,42 @@ struct v3d_csd_job { }; /** - * _wait_for - magic (register) wait macro + * __wait_for - magic 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. + * Macro to help avoid open coding check/wait/timeout patterns. 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) ({ \ - unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \ - int ret__ = 0; \ - while (!(COND)) { \ - if (time_after(jiffies, timeout__)) { \ - if (!(COND)) \ - ret__ = -ETIMEDOUT; \ +#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \ + const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \ + long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \ + int ret__; \ + might_sleep(); \ + for (;;) { \ + const bool expired__ = ktime_after(ktime_get_raw(), end__); \ + OP; \ + /* Guarantee COND check prior to timeout */ \ + barrier(); \ + if (COND) { \ + ret__ = 0; \ break; \ } \ - msleep(1); \ + if (expired__) { \ + ret__ = -ETIMEDOUT; \ + break; \ + } \ + usleep_range(wait__, wait__ * 2); \ + if (wait__ < (Wmax)) \ + wait__ <<= 1; \ } \ ret__; \ }) +#define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \ + (Wmax)) +#define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000) + static inline unsigned long nsecs_to_jiffies_timeout(const u64 n) { /* nsecs_to_jiffies64() does not guard against overflow */ diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h index 7956f6ed9b6a..c59be5e1d52b 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.h +++ b/drivers/gpu/drm/vc4/vc4_drv.h @@ -629,32 +629,41 @@ struct vc4_validated_shader_info { }; /** - * _wait_for - magic (register) wait macro + * __wait_for - magic 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. + * Macro to help avoid open coding check/wait/timeout patterns. 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) + 1; \ - int ret__ = 0; \ - while (!(COND)) { \ - if (time_after(jiffies, timeout__)) { \ - if (!(COND)) \ - ret__ = -ETIMEDOUT; \ +#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \ + const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \ + long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \ + int ret__; \ + might_sleep(); \ + for (;;) { \ + const bool expired__ = ktime_after(ktime_get_raw(), end__); \ + OP; \ + /* Guarantee COND check prior to timeout */ \ + barrier(); \ + if (COND) { \ + ret__ = 0; \ break; \ } \ - if (W && drm_can_sleep()) { \ - msleep(W); \ - } else { \ - cpu_relax(); \ + if (expired__) { \ + ret__ = -ETIMEDOUT; \ + break; \ } \ + usleep_range(wait__, wait__ * 2); \ + if (wait__ < (Wmax)) \ + wait__ <<= 1; \ } \ ret__; \ }) -#define wait_for(COND, MS) _wait_for(COND, MS, 1) +#define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \ + (Wmax)) +#define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000) /* vc4_bo.c */ struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size); -- 2.17.1