From patchwork Thu Apr 2 09:31:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mason X-Patchwork-Id: 6145941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 40D1CBF4A6 for ; Thu, 2 Apr 2015 09:45:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7158520263 for ; Thu, 2 Apr 2015 09:45:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C647201C8 for ; Thu, 2 Apr 2015 09:45:33 +0000 (UTC) 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 1Ydbdz-00073P-PZ; Thu, 02 Apr 2015 09:42:35 +0000 Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YdbTe-00061d-6o for linux-arm-kernel@lists.infradead.org; Thu, 02 Apr 2015 09:31:55 +0000 Received: from [172.27.0.114] (unknown [83.142.147.193]) (Authenticated sender: shill) by smtp2-g21.free.fr (Postfix) with ESMTPSA id 7D6AF4B010F for ; Thu, 2 Apr 2015 11:29:32 +0200 (CEST) Message-ID: <551D0C71.8050707@free.fr> Date: Thu, 02 Apr 2015 11:31:29 +0200 From: Mason User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0 SeaMonkey/2.32.1 MIME-Version: 1.0 To: Linux ARM Subject: __timer_udelay(1) may return immediately X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150402_023154_467136_9AB90300 X-CRM114-Status: UNSURE ( 8.36 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_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 Hello everyone, I'm using timer-based delays from arch/arm/lib/delay.c Consider the following configuration: HZ=100 timer->freq = 1000000 Thus UDELAY_MULT = 107374 ticks_per_jiffy = 10000 Thus __timer_udelay(1) => __timer_const_udelay(107374) => __timer_delay(0) => calls get_cycles() twice then returns prematurely The issue comes from a tiny rounding error as 107374 * ticks_per_jiffy >> UDELAY_SHIFT = 0,9999983 which is rounded down to 0. The root of the issue is that mathematically, UDELAY_MULT = 2199023 * HZ / 2048 = 107374,169921875 which is rounded down to 107374. It seems to me that a simple solution would be to round UDELAY_MULT up instead of down. Thus UDELAY_MULT = 107375 107375 * ticks_per_jiffy >> UDELAY_SHIFT = 1,0000076 We might end up sleeping one cycle more than necessary, but I don't think spinning a bit longer would be a problem? Patch provided for illustration purposes. What do you think? Regards. diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h index dff714d..873a43e 100644 --- a/arch/arm/include/asm/delay.h +++ b/arch/arm/include/asm/delay.h @@ -10,7 +10,7 @@ #include /* HZ */ #define MAX_UDELAY_MS 2 -#define UDELAY_MULT ((UL(2199023) * HZ) >> 11) +#define UDELAY_MULT (((UL(2199023) * HZ) >> 11) + 1) #define UDELAY_SHIFT 30 #ifndef __ASSEMBLY__