From patchwork Sun Sep 24 20:00:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 114149 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1854496qgf; Sun, 24 Sep 2017 13:01:25 -0700 (PDT) X-Received: by 10.98.237.18 with SMTP id u18mr5339194pfh.251.1506283285626; Sun, 24 Sep 2017 13:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506283285; cv=none; d=google.com; s=arc-20160816; b=pzKPDXE56/UqtVwKVO7smhgtgRia9+mxROMG/QEReABPKGdek7pJK/FvgQCkoCH/F4 ekDnp5tcOVKRIVVRXbVFcHnpZki8ZT1EXz7ty8VURefFenvDIjzD/0Z/pGOVs34eG44+ Kc8k9gR59q/SBnX+pr2f86jOQceMpSHA6NhkLzFQcP/K9EYoysgT3/LTuV9XUxbmlCkc m1P5fEJdC/thj/fuTa2U0MlzJJdtM9/XKQ9rrJ0Cer8aJAVJPTQie2N91bb0JLg5llKx BlbiPWLdMPLQ66cVybs7gy5RepPV3Xi10wujp+265CKTbra0RcKq78+5HjRaqtHdV9Xb pyaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=uxOweclbuLLqbp0HFPbl5f1EXAAK0QnMtIdo4TQivl8JGgoQ9Kyr4BDg4RFhLRx3f0 QYIGfBB8UCU+7HPk1kLbMZoA8wSz+C5kAjphZNZI281eSQv1KnGUbR9TuewpkMk2VV9q rWX7mvH6hxKxId0YVb+kf49/Vb0BH9350x72ajW3UqD+bDdKMKqYtQhPFzoa6EpZ79WP rnRkFMsAQX5inBlw8rESgHjK3lZ51D0zHi2HCOpGKawTdt/Js39vZW9oMv3UY8ANAQMi 1FATFisbDbvYWVvkgwGvxfNTy0ISxbl8jjmeOMHc36UqaC1EETru1PDcrAR3y9t5OWr6 oPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JaXr+rVf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si3054647plm.785.2017.09.24.13.01.25; Sun, 24 Sep 2017 13:01:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JaXr+rVf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752945AbdIXUAs (ORCPT + 26 others); Sun, 24 Sep 2017 16:00:48 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:48614 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbdIXUAn (ORCPT ); Sun, 24 Sep 2017 16:00:43 -0400 Received: by mail-wm0-f45.google.com with SMTP id m127so14363975wmm.3 for ; Sun, 24 Sep 2017 13:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=JaXr+rVf8MLFfrqncoxU7+JvYAaGZZjIlLyHZzefeZo4z+84psFX2ZzC6XXZuZkUk5 H+TlAMs7GTigMK4C5C2P07gZz7uqrS47EvcD5MgYDhETQRuvLozUzvmtzNFPBTB1KN90 636q287vX4M0XzdJE0u5iHRtLVfsbt5WZLxLfTCLbf97qFOTbJtKnvRFeg7SKwHGxFnQ tC/1k341/m9+Joz4EHveOzl2jutu4MnH4lqSFL80sy4OvHN8y5ohduHfGIwNeazHsLQA Ym2r1yv5ltTHhjtxDIlAK+EJxRuOgP2eq9T5y3/HbR2RSGRfMu2/c7G3q5sM109+hno2 NtmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1XJ5txoH3FfDeXms2SPHVoUXCF7dKj5iGGdchcRZZH0=; b=MKd3KtKV8vJj7TmVplQfkfX4iJdrttgASe3sdHEsSvFpaZbYwXdEcIBo5B4kVp2JbF x3qKVMHaitk3TYIZDTXDO9HDc/o7DhMmf4kqSXeRr5WZ/fEFdkPEBrE6zWtrl6hQKliX 3nLcLyi/6sB5mLbPA2LWt1hzlZeiGdsAEwyWUmi8AMN7aimfxZRJLFlkH1e3Q1pWmcqP 9xe5o2l4YmowUMeO0Yy0fAfWKZhxckO4WTWGUTwQf5idcOhnaGnMY6bMMbWT5nGx1LvR P66mjt3P0U/StgfdY1jrTrleSojHKFWV9U3iGt9Z4NTnbNsulQyWHleBeP5U7mN6mq5v 8/Kw== X-Gm-Message-State: AHPjjUg/73ZjjI2QZ2s1qgaJhkQt6ZiWLM02bNjzY5bF75KCSyeQEob7 XQiA3WAHG5X0oyt18A4zAXik1w== X-Google-Smtp-Source: AOwi7QB1pUc4od7iGlxfjb3oV8YVk6pKCmtnxD+y5u/Qc89fnu/1YNKVqPlG87H6kO4H+7y2OZ7ysw== X-Received: by 10.28.18.210 with SMTP id 201mr7656430wms.135.1506283242513; Sun, 24 Sep 2017 13:00:42 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id j5sm6786144wmg.8.2017.09.24.13.00.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 13:00:42 -0700 (PDT) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman Subject: [PATCH v4 05/10] clk: use round rate to bail out early in set_rate Date: Sun, 24 Sep 2017 22:00:25 +0200 Message-Id: <20170924200030.6227-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924200030.6227-1-jbrunet@baylibre.com> References: <20170924200030.6227-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of clk_core_set_rate_nolock() bails out early if the requested rate is exactly the same as the one set. It should bail out if the request would not result in a rate a change. This is important when the rate is not exactly what is requested, which is fairly common with PLLs. Ex: provider able to give any rate with steps of 100Hz - 1st consumer request 48000Hz and gets it. - 2nd consumer request 48010Hz as well. If we were to perform the usual mechanism, we would get 48000Hz as well. The clock would not change so there is no point performing any checks to make sure the clock can change, we know it won't. This is important to prepare the addition of the clock protection mechanism Acked-by: Linus Walleij Tested-by: Quentin Schulz Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.13.5 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 0905139a1893..44022299741a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1582,15 +1582,36 @@ static void clk_change_rate(struct clk_core *core) clk_change_rate(core->new_child); } +static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, + unsigned long req_rate) +{ + int ret; + struct clk_rate_request req; + + lockdep_assert_held(&prepare_lock); + + if (!core) + return 0; + + clk_core_get_boundaries(core, &req.min_rate, &req.max_rate); + req.rate = req_rate; + + ret = clk_core_round_rate_nolock(core, &req); + + return ret ? 0 : req.rate; +} + static int clk_core_set_rate_nolock(struct clk_core *core, unsigned long req_rate) { struct clk_core *top, *fail_clk; - unsigned long rate = req_rate; + unsigned long rate; if (!core) return 0; + rate = clk_core_req_round_rate_nolock(core, req_rate); + /* bail early if nothing to do */ if (rate == clk_core_get_rate_nolock(core)) return 0; @@ -1599,7 +1620,7 @@ static int clk_core_set_rate_nolock(struct clk_core *core, return -EBUSY; /* calculate new rates and get the topmost changed clock */ - top = clk_calc_new_rates(core, rate); + top = clk_calc_new_rates(core, req_rate); if (!top) return -EINVAL;