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: 3240611 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C166AC045B for ; Tue, 26 Nov 2013 18:38:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B214E20451 for ; Tue, 26 Nov 2013 18:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 859D720454 for ; Tue, 26 Nov 2013 18:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752003Ab3KZSi3 (ORCPT ); Tue, 26 Nov 2013 13:38:29 -0500 Received: from mail-pd0-f202.google.com ([209.85.192.202]:46548 "EHLO mail-pd0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750879Ab3KZSi2 (ORCPT ); Tue, 26 Nov 2013 13:38:28 -0500 X-Greylist: delayed 458 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Nov 2013 13:38:28 EST Received: by mail-pd0-f202.google.com with SMTP id g10so857688pdj.1 for ; Tue, 26 Nov 2013 10:38:27 -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=jVooL3zf3BlfC+k9b4mUcfn+9VBHMKsogjcsH660n9JEfq78OPkjP/UR/zLYTfHO4I 8OBqGQhlBUBSzaYRTDF2OKy7/dsLdNFdWVcI8uplYko7EQ1/WuBuW4MgtEG1RNTxz2uj fhCUsCZ1VT4kg//rU+GOY7eeuLS07AecY0fyoQOVDOeU3cFhoR866je17hRl4Jd+8QLr KA9q14uNDOZmBh7E6kKG8iBo+2ij4eWRsFtxkiha53o9nQ3TadR6XPZThFvtfboXc+2i Z1tkDudsrMVQNIdxnC6MAKiXoU1ZwurbYBAb9QiBmxVMhloBfu6grFqGpOwYGr+CoaZW QmYA== X-Gm-Message-State: ALoCoQnw0cBbYe2a9B8dehnRpAM4vBxMd1+P+h1NPIIoXA4W/WblxWIALiY5vubZSSm2f5I7dXikNWclGMfhYZXzyzagIpgquUN5dG0oBOabMfYBDoXm8Z2GyokGbD/7SvIFnh0YyDvMW9lwVMVV+kJHpy5myq9egH+Oy4m8i4zCzSSnJHqrbaoxUrxWU15Qo80+656+8CZo3hWJmC78/zQ77nSlw4Sk7w== 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 Cc: Leela Krishna Amudala , Olof Johansson , Tomasz Figa , Kukjin Kim , Doug Anderson , Ben Dooks , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org 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 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 */