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: 110294 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1633939qge; Wed, 16 Aug 2017 20:42:39 -0700 (PDT) X-Received: by 10.99.173.6 with SMTP id g6mr3683522pgf.1.1502941359205; Wed, 16 Aug 2017 20:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502941359; cv=none; d=google.com; s=arc-20160816; b=R3Dc9We8oDYEyaHPl/o2+pdLGd7XxY0BGJtPmF/oljf/rAGj5fOa2gFpZXIaFjk4sT JQazrhfwFm0+YZ4LdL5OgPZQ490vKp+mVVlJ0Nl08rKSRR9xmB5QE1kiDKyIA/dlIAJh c9Z5EvROkG5REC2JvGzg1CFkKM7hRwERn5dokey1gX0eJd2ujenw5ujOsQKN/rxZie3J fxIEJRO5XteSx6cFpOnbPMU1bPHptC3QZFIVEILuBPmibOODTWmKMMzcQ2jQ/AKNTkXD pEfI2AuWzjl2W5kpUtpeHN+pa/zHsSkHE1Gqjwa2uHDScMnyDGcvAHSkSVM/7rBdDRUL zNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=MmsIda3xYP0p9glFY/PA5+2g51Fv4FaPjQT13r5K9NE=; b=LqeKs3e9gP6zVHqpZq78uExh7O4+mxwe3+fifnhB8oQYqH002++h7DAmu1NY30BVSP X08O5ECU3RKSU4XsUzdIsXQNyHpmdI4tzkcPx49bvF6/d9APRuN5vzU10pk8nzcf6XVq QTNvGku8SkX2DLUafGilUzg7h8srSkz0j2kdCCYzoHiJgfngOJbhnQGhWQHiHfOfT33z 2c0l0esN8qgQZTNJskOY3bwfNncQzQOzkjiGnhzrgItsiiWOOeqEGgAt6PnUCqYhqYv6 EaHQOQEXOS1rrac9yomoqG76YEE4Ko4JKi8GLpeHixBLvnFf81Qgma5vz75PQwAwElSw 0wbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BC1+ZTiE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si1626785plm.344.2017.08.16.20.42.38; Wed, 16 Aug 2017 20:42:39 -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=@linaro.org header.s=google header.b=BC1+ZTiE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752607AbdHQDmh (ORCPT + 26 others); Wed, 16 Aug 2017 23:42:37 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:37350 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752467AbdHQDmf (ORCPT ); Wed, 16 Aug 2017 23:42:35 -0400 Received: by mail-pg0-f41.google.com with SMTP id y129so33871756pgy.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=ft9tYZ2dlqljbE7UzbhyA3fwldbvKFCzevdyCxIzsR0IjK9os+MPdEczPyPD4+6QOb s2BNBtFG6ciRbmwjfGYcpsqDmHFWNBnJYfisxRBFVPGfM8J+nAxJSGBRnA4mhh6lLXwE mOXZrLf87mVnyKYc6coDOndFW7pCo/cv2QjOYj7lnXDyOmye8NHf0NbR4hMFw9udgjFs oD4ZI6sLoxuQJme/pz2os14iBjjBBiRXIb6Aeu0nLI38CWjyzur8PM8Nk8a4z9PtpiKL M8FDBrpW+uNPf7Du2nWmHGe9VqhpNWISDF6BOsq3XxzpVSLmdtFa9OeHwqIE0xZziCmG yd7Q== X-Gm-Message-State: AHYfb5j8L2uDzkdbh2CyApObSIYxhkPJxrcLA3KCnKsDwXruzaYr2az8 lIXcFlACGZ067ynv 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.14.1.202.g24db08a6e8fe 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; }