From patchwork Tue Nov 26 18:30:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 3240591 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 07E8F9F3AE for ; Tue, 26 Nov 2013 18:32:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E18792044C for ; Tue, 26 Nov 2013 18:32:38 +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 7D6C92043C for ; Tue, 26 Nov 2013 18:32:37 +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 1VlNQK-0001bp-Ne; Tue, 26 Nov 2013 18:31:48 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlNQ7-0003hG-On; Tue, 26 Nov 2013 18:31:35 +0000 Received: from mail-pd0-f202.google.com ([209.85.192.202]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlNPr-0003dc-C5 for linux-arm-kernel@lists.infradead.org; Tue, 26 Nov 2013 18:31:20 +0000 Received: by mail-pd0-f202.google.com with SMTP id g10so857467pdj.3 for ; Tue, 26 Nov 2013 10:30:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=19x6gPkAOZfcIzK144sn6NFn3dL+p6zKk38+Fn5b3cc=; b=YrnXOOtmltoTdtbcTFITyKqEqLK4BGCWrgEGX2uS2ZBu8yr7A+TxUnIdTtupr8oi4p dgp3It/i3vGBehNup2uIGJVGralh3z2u9f2Xk4ekKIJtEFJ/rL7KtQA/Xvi07TDTV0cV pywLXN6Z8mYocTbdgENVI/xneArYC4LYi67ymwX8BdrtNhf1QQqXmjOVvyDwcmUzNt3U tctZ+EFVCMj6EYUWiBCGI3GIYrPe+cVPddakKEUqXm7Ki1YJcnzZdlyekMUJEldjrpsD HdwRHkulkP0HnF5DMBr5e5cXUMgVNRWPJE7xPXTOiaM8dtSBhvBrbKhw3hoMNwRJxJvP IYhw== X-Gm-Message-State: ALoCoQlIbE0im+ydryvTkbWQ0h9077RUJgwIrzAVvqEOKsBHgeN0IVXwB0dbo1+ne5b0sInGC133wCLuNGr1lxYwgiroUN09m5dylcG5ZKeklwa7mdnb1WdbJ6klLl5bRo9T9nRckF8++eWDQmwmyiMh995xp1zI23MX9CDBAoO/oBhaYnVIJ7N/je53sHSlfjPmnS9/O0b9lPXUxVNmVtLUAZDRNyNI5A== X-Received: by 10.68.91.226 with SMTP id ch2mr304241pbb.1.1385490650563; Tue, 26 Nov 2013 10:30:50 -0800 (PST) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id m48si11091371yho.6.2013.11.26.10.30.50 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Nov 2013 10:30:50 -0800 (PST) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.72.141]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 507325A410D; Tue, 26 Nov 2013 10:30:50 -0800 (PST) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id D4D1380810; Tue, 26 Nov 2013 10:30:49 -0800 (PST) From: Doug Anderson To: Wim Van Sebroeck , Guenter Roeck Subject: [PATCH] watchdog: s3c2410_wdt: Handle rounding a little better for timeout Date: Tue, 26 Nov 2013 10:30:37 -0800 Message-Id: <1385490637-10306-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.8.4.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131126_133119_546503_CC2B7561 X-CRM114-Status: GOOD ( 11.89 ) X-Spam-Score: -1.9 (-) Cc: Kukjin Kim , linux-watchdog@vger.kernel.org, Leela Krishna Amudala , linux-kernel@vger.kernel.org, Tomasz Figa , Doug Anderson , linux-samsung-soc@vger.kernel.org, Ben Dooks , Olof Johansson , 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: , MIME-Version: 1.0 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, 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 The existing watchdog timeout worked OK but didn't deal with rounding in an ideal way when dividing out all of its clocks. Specifically if you had a timeout of 32 seconds and an input clock of 66666666, you'd end up setting a timeout of 31.9998 seconds and reporting a timeout of 31 seconds. Specifically DBG printouts showed: s3c2410wdt_set_heartbeat: count=16666656, timeout=32, freq=520833 s3c2410wdt_set_heartbeat: timeout=32, divisor=255, count=16666656 (0000ff4f) and the final timeout reported to the user was: ((count / divisor) * divisor) / freq (0xff4f * 255) / 520833 = 31 (truncated from 31.9998) the technically "correct" value is: (0xff4f * 255) / (66666666.0 / 128) = 31.9998 By using "DIV_ROUND_UP" we can be a little more correct. s3c2410wdt_set_heartbeat: count=16666688, timeout=32, freq=520834 s3c2410wdt_set_heartbeat: timeout=32, divisor=255, count=16666688 (0000ff50) and the final timeout reported to the user: (0xff50 * 255) / 520834 = 32 the technically "correct" value is: (0xff50 * 255) / (66666666.0 / 128) = 32.0003 We'll use a DIV_ROUND_UP to solve this, generally erroring on the side of reporting shorter values to the user and setting the watchdog to slightly longer than requested: * Round input frequency up to assume watchdog is counting faster. * Round divisions by divisor up to give us extra time. Signed-off-by: Doug Anderson Reviewed-by: Guenter Roeck --- drivers/watchdog/s3c2410_wdt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c index 7d8fd04..fe2322b 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -188,7 +188,7 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeou if (timeout < 1) return -EINVAL; - freq /= 128; + freq = DIV_ROUND_UP(freq, 128); count = timeout * freq; DBG("%s: count=%d, timeout=%d, freq=%lu\n", @@ -201,20 +201,20 @@ static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeou if (count >= 0x10000) { for (divisor = 1; divisor <= 0x100; divisor++) { - if ((count / divisor) < 0x10000) + if (DIV_ROUND_UP(count, divisor) < 0x10000) break; } - if ((count / divisor) >= 0x10000) { + if (divisor > 0x100) { dev_err(wdt->dev, "timeout %d too big\n", timeout); return -EINVAL; } } DBG("%s: timeout=%d, divisor=%d, count=%d (%08x)\n", - __func__, timeout, divisor, count, count/divisor); + __func__, timeout, divisor, count, DIV_ROUND_UP(count, divisor)); - count /= divisor; + count = DIV_ROUND_UP(count, divisor); wdt->count = count; /* update the pre-scaler */