From patchwork Thu Aug 17 03:42:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9904901 X-Patchwork-Delegate: rjw@sisk.pl 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 31AF5603B5 for ; Thu, 17 Aug 2017 03:43:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 288D728A9A for ; Thu, 17 Aug 2017 03:43:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D52628AA0; Thu, 17 Aug 2017 03:43:06 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 7E2E228A9A for ; Thu, 17 Aug 2017 03:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752491AbdHQDmh (ORCPT ); Wed, 16 Aug 2017 23:42:37 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:37349 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752471AbdHQDmf (ORCPT ); Wed, 16 Aug 2017 23:42:35 -0400 Received: by mail-pg0-f54.google.com with SMTP id y129so33871758pgy.4 for ; Wed, 16 Aug 2017 20:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=MmsIda3xYP0p9glFY/PA5+2g51Fv4FaPjQT13r5K9NE=; b=BC1+ZTiEi4QN3QnQUhV/SZUkVwZavSM38yT3FKJ5TtBHcW7vnxmYmLiAT6oeN8wmZ9 rPksWX9FwUpoK5YKAoLEYXmqjjrBIhnSSRrFfSP3TC2NvpXy7A+4Whvo1/ReOdyI76mH 99Zn9Led4AFBQXCaAObVZN8re/oX3ePn95+7E= 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; bh=MmsIda3xYP0p9glFY/PA5+2g51Fv4FaPjQT13r5K9NE=; b=HezChBuBTIuu4PQfpIwc2FXwzKyEVxh7v4GZFQcEKEj9Q+zqHTPvTbTPsPKtTJ3dxr S2Uvw/Wghcd+6qpbKg2thjsxlEmmxyVyStFk29X+D4RzGcDoOsrMo3kPzHHst60J+wdR KL1+MCzAngBn4sMQB+YfrYIf9/x28rkzDUzRt5PTI7egKvCUC5VoQACxefW1yMbUzjvp t0VX+RU9g0lRHFQR7i+HX4tItgHGydsqooO6zZ6ow1tAuJLbDzi75OKrvXun72J6QlYN lL26Sg3nkv0v4xPYvoBwIf1VleMhjzLnZk3uUFxyz+JR94fpfq9MuvOPZgYmNp9X1iXQ TwkA== X-Gm-Message-State: AHYfb5iJyyEXOsykXDdNQr8fQYVVL2EIZqVXojveIXBsGFzJ7C5NZCRe bEENWlI5OiCush4o X-Received: by 10.99.178.73 with SMTP id t9mr3473364pgo.34.1502941355108; Wed, 16 Aug 2017 20:42:35 -0700 (PDT) Received: from localhost ([122.172.110.130]) by smtp.gmail.com with ESMTPSA id m84sm4511145pfi.88.2017.08.16.20.42.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Aug 2017 20:42:34 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , leonard.crestez@nxp.com, kernel@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, linux-kernel@vger.kernel.org Subject: [PATCH V3 resend] cpufreq: Cap the default transition delay value to 10 ms Date: Thu, 17 Aug 2017 09:12:27 +0530 Message-Id: <00a3cebb2febc73dd275cbff2a24c73fb11ff255.1502941122.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1.202.g24db08a6e8fe Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If transition_delay_us isn't defined by the cpufreq driver, the default value of transition delay (time after which the cpufreq governor will try updating the frequency again) is currently calculated by multiplying transition_latency (nsec) with LATENCY_MULTIPLIER (1000) and then converting this time to usec. That gives the exact same value as transition_latency, just that the time unit is usec instead of nsec. With acpi-cpufreq for example, transition_latency is set to around 10 usec and we get transition delay as 10 ms. Which seems to be a reasonable amount of time to reevaluate the frequency again. But for platforms where frequency switching isn't that fast (like ARM), the transition_latency varies from 500 usec to 3 ms, and the transition delay becomes 500 ms to 3 seconds. Of course, that is a pretty bad default value to start with. We can try to come across a better formula (instead of multiplying with LATENCY_MULTIPLIER) to solve this problem, but will that be worth it ? This patch tries a simple approach and caps the maximum value of default transition delay to 10 ms. Of course, userspace can still come in and change this value anytime or individual drivers can rather provide transition_delay_us instead. Signed-off-by: Viresh Kumar --- One of the IMX shows odd behavior after this patch is applied and stays at max freq for little longer. More detailed debugging is required to be done by some IMX guys (who haven't replied for the last 3 weeks on that email thread, apart from Leonard). As per Leonard as well, we shouldn't stop this patch from getting merged and so sending it again. drivers/cpufreq/cpufreq.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b2cc98551fc3..c7ae67d6886d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -532,8 +532,19 @@ unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) return policy->transition_delay_us; latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; - if (latency) - return latency * LATENCY_MULTIPLIER; + if (latency) { + /* + * For platforms that can change the frequency very fast (< 10 + * us), the above formula gives a decent transition delay. But + * for platforms where transition_latency is in milliseconds, it + * ends up giving unrealistic values. + * + * Cap the default transition delay to 10 ms, which seems to be + * a reasonable amount of time after which we should reevaluate + * the frequency. + */ + return min(latency * LATENCY_MULTIPLIER, (unsigned int)10000); + } return LATENCY_MULTIPLIER; }