From patchwork Tue Sep 17 11:26:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 2901931 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CDD059F1E3 for ; Tue, 17 Sep 2013 11:27:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29A83202D1 for ; Tue, 17 Sep 2013 11:27:51 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 714B7202DD for ; Tue, 17 Sep 2013 11:27:46 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VLtRX-0003JI-H3; Tue, 17 Sep 2013 11:27:43 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VLtRV-0002XH-9Z; Tue, 17 Sep 2013 11:27:41 +0000 Received: from galois.linutronix.de ([2001:470:1f0b:db:abcd:42:0:1]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VLtRS-0002WR-70 for linux-arm-kernel@lists.infradead.org; Tue, 17 Sep 2013 11:27:39 +0000 Received: from localhost ([127.0.0.1]) by Galois.linutronix.de with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1VLtQn-0007YK-P3; Tue, 17 Sep 2013 13:26:57 +0200 Date: Tue, 17 Sep 2013 13:26:56 +0200 (CEST) From: Thomas Gleixner To: Russell King - ARM Linux Subject: Re: [PATCH] [PATCH] clocksource: tcb: fix min_delta calculation In-Reply-To: <20130917100417.GQ12758@n2100.arm.linux.org.uk> Message-ID: References: <1379077365-18458-1-git-send-email-mkl@pengutronix.de> <20130917095600.GJ26819@ludovic.desroches@atmel.com> <20130917100417.GQ12758@n2100.arm.linux.org.uk> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130917_072738_521334_36D385E2 X-CRM114-Status: GOOD ( 20.25 ) X-Spam-Score: -2.6 (--) Cc: nicolas.ferre@atmel.com, linux-kernel@vger.kernel.org, Marc Pignat , Ludovic Desroches , john.stultz@linaro.org, kernel@pengutronix.de, Marc Kleine-Budde , Ronald Wahl , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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.9 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 On Tue, 17 Sep 2013, Russell King - ARM Linux wrote: > On Tue, Sep 17, 2013 at 11:56:00AM +0200, Ludovic Desroches wrote: > > Any reason to not do this: > > > > --- a/drivers/clocksource/tcb_clksrc.c > > +++ b/drivers/clocksource/tcb_clksrc.c > > @@ -144,6 +144,9 @@ static void tc_mode(enum clock_event_mode m, struct > > clock_event_device *d) > > > > static int tc_next_event(unsigned long delta, struct clock_event_device > > *d) > > { > > + if (delta < d->min_delta_ticks) > > + delta = d->min_delta_ticks; > > + > > __raw_writel(delta, tcaddr + ATMEL_TC_REG(2, RC)); > > > > /* go go gadget! */ > > > > Then we can keep the same min_delta. > > You really should not play such games in your set_next_event() code - if > the interval is not supported, you should return -ETIME so that the core > code knows about it and can adjust things to suit. If you're getting > deltas which are too small for the hardware, that'll either be because > the bounds are wrong, or there's a bug in the core code. The core code does: int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, bool force) { .... delta = min(delta, (int64_t) dev->max_delta_ns); delta = max(delta, (int64_t) dev->min_delta_ns); clc = ((unsigned long long) delta * dev->mult) >> dev->shift; rc = dev->set_next_event((unsigned long) clc, dev); } So, the min_delta in timer ticks is set to 1 and converted by the core to nsecs for various reasons. This is where the rounding problem comes into play. The patch below should fix that. Thanks, tglx ---- diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 38959c8..41b7a30 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -42,7 +42,7 @@ struct ce_unbind { */ u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt) { - u64 clc = (u64) latch << evt->shift; + u64 tmp, clc = (u64) latch << evt->shift; if (unlikely(!evt->mult)) { evt->mult = 1; @@ -52,6 +52,14 @@ u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt) do_div(clc, evt->mult); if (clc < 1000) clc = 1000; + + /* Avoid rounding artifacts */ + tmp = (clc * dev->mult) >> dev->shift; + while (tmp < (u64) dev->min_delta_ticks) { + clc += 1000; + tmp = (clc * dev->mult) >> dev->shift; + } + if (clc > KTIME_MAX) clc = KTIME_MAX;