From patchwork Mon Dec 12 07:40:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 9470159 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8110E60476 for ; Mon, 12 Dec 2016 08:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 723D628414 for ; Mon, 12 Dec 2016 08:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 667232845D; Mon, 12 Dec 2016 08:29:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F237A28414 for ; Mon, 12 Dec 2016 08:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750712AbcLLI3F (ORCPT ); Mon, 12 Dec 2016 03:29:05 -0500 Received: from www.osadl.org ([62.245.132.105]:33938 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991AbcLLI3F (ORCPT ); Mon, 12 Dec 2016 03:29:05 -0500 X-Greylist: delayed 3030 seconds by postgrey-1.27 at vger.kernel.org; Mon, 12 Dec 2016 03:29:04 EST Received: from debian01.hofrr.at (92-243-34-74.adsl.nanet.at [92.243.34.74] (may be forged)) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id uBC7cK37015993; Mon, 12 Dec 2016 08:38:20 +0100 From: Nicholas Mc Guire To: Michael Turquette , Mark Brown Cc: Stephen Boyd , patches@opensource.wolfsonmicro.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH RFC] clk: wm831x: fix usleep_range with bad range Date: Mon, 12 Dec 2016 08:40:09 +0100 Message-Id: <1481528409-5182-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The delay here is not in atomic context and does not seem critical with respect to precision, but usleep_range(min,max) with min==max results in giving the timer subsystem no room to optimize uncritical delays. Fix this by setting the range to 2000,3000 us. Fixes: commit f05259a6ffa4 ("clk: wm831x: Add initial WM831x clock driver") Signed-off-by: Nicholas Mc Guire Acked-by: Charles Keepax --- problem was located by coccinelle spatch The problem is that usleep_range is calculating the delay by exp = ktime_add_us(ktime_get(), min) delta = (u64)(max - min) * NSEC_PER_USEC so delta is set to 0 and then calls schedule_hrtimeout_range(exp, 0,...) effectively this means that the clock subsystem has no room to optimize and the behavior is no better than using usleep(). As this is not a critical delay it is set to a range of 2 to 3 milliseconds - this change needs a review by someone that knows the details of the device though. Q:It might actually be possible to just use msleep(2) here rather than using a hrtimer, at least I do not see what a hrtimer would be needed here for - a longer delay e.g. on a HZ100 box should not hurt ? Patch was only compile tested with: i386_defconfig + CONFIG_X86_INTEL_QUARK=y CONFIG_MFD_WM831X_I2C=y, COMMON_CLK=y, CONFIG_COMMON_CLK_WM831X=m Patch is against: 4.9.0-rc8 (localversion-next is -next-20161209) drivers/clk/clk-wm831x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-wm831x.c b/drivers/clk/clk-wm831x.c index f4fdac5..fe42d46 100644 --- a/drivers/clk/clk-wm831x.c +++ b/drivers/clk/clk-wm831x.c @@ -97,7 +97,8 @@ static int wm831x_fll_prepare(struct clk_hw *hw) if (ret != 0) dev_crit(wm831x->dev, "Failed to enable FLL: %d\n", ret); - usleep_range(2000, 2000); + /* wait 2-3 ms for new frequency taking effect */ + usleep_range(2000, 3000); return ret; }