From patchwork Mon Feb 15 16:37:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Brodkin X-Patchwork-Id: 583033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 98F8014017E for ; Tue, 16 Feb 2016 03:38:22 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVMAG-0008UO-JZ; Mon, 15 Feb 2016 16:38:20 +0000 Received: from smtprelay.synopsys.com ([198.182.47.9]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVMAD-0008NZ-Je for linux-snps-arc@lists.infradead.org; Mon, 15 Feb 2016 16:38:18 +0000 Received: from us02secmta1.synopsys.com (us02secmta1.synopsys.com [10.12.235.96]) by smtprelay.synopsys.com (Postfix) with ESMTP id DE41C24E1508; Mon, 15 Feb 2016 08:37:55 -0800 (PST) Received: from us02secmta1.internal.synopsys.com (us02secmta1.internal.synopsys.com [127.0.0.1]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id D0B174E213; Mon, 15 Feb 2016 08:37:55 -0800 (PST) Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id ADC184E202; Mon, 15 Feb 2016 08:37:55 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 9BAD5DF6; Mon, 15 Feb 2016 08:37:55 -0800 (PST) Received: from abrodkin-e7440l.internal.synopsys.com (abrodkin-e7440l.internal.synopsys.com [10.121.3.53]) by mailhost.synopsys.com (Postfix) with ESMTP id 27881DF1; Mon, 15 Feb 2016 08:37:53 -0800 (PST) From: Alexey Brodkin To: linux-snps-arc@lists.infradead.org Subject: [PATCH] arc: make sure __delay() never gets executed with 0 loops Date: Mon, 15 Feb 2016 19:37:47 +0300 Message-Id: <1455554267-23886-1-git-send-email-abrodkin@synopsys.com> X-Mailer: git-send-email 2.4.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160215_083817_772272_B9407F29 X-CRM114-Status: UNSURE ( 8.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.47.9 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [198.182.47.9 listed in wl.mailspike.net] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vineet Gupta , Alexey Brodkin , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Current implementation of __delay() function uses so-called zero-delay loops. And the only condition to exit that loop is LP_COUNT (loop count register) = 1 (but not 0 as it might be easily imagined). So if our calculation of "loops" gives 0 (and that is pretty possible given result of multiplication being >> 32) then zero-delay loop mechanism starts with LP_COUNT=0 and it ends up decrementing LP_COUNT while staying in the loop effectively producing close to infinite delay instead of very short one. I bumped into it with AXS101 + external DDR controller and caches disabled. In that case I've got very small loops_per_jiffy=0xf00: ------------------------>8-------------------- Calibrating delay loop... 0.77 BogoMIPS (lpj=3862) ------------------------>8-------------------- And on console output delays were way too long. Signed-off-by: Alexey Brodkin Cc: Vineet Gupta Please enter the commit message for your changes. Lines starting --- arch/arc/include/asm/delay.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arc/include/asm/delay.h b/arch/arc/include/asm/delay.h index 08e7e2a..1a7a1dc 100644 --- a/arch/arc/include/asm/delay.h +++ b/arch/arc/include/asm/delay.h @@ -57,7 +57,8 @@ static inline void __udelay(unsigned long usecs) */ loops = ((u64) usecs * 4295 * HZ * loops_per_jiffy) >> 32; - __delay(loops); + if (loops) + __delay(loops); } #define udelay(n) (__builtin_constant_p(n) ? ((n) > 20000 ? __bad_udelay() \