From patchwork Mon Nov 25 04:23:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 21732 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A451E23FCB for ; Mon, 25 Nov 2013 04:24:07 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id i4sf13279357oah.6 for ; Sun, 24 Nov 2013 20:24:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=PX1XXY7nAzL4L/zgZcQFv3sQGFI+FPxF3n4ZMAGahkM=; b=IbyoRoPd8xIbl3j+zJGNTj8RdT/6eekf/qSnDd46gZEUqnSttOnnYF6zgnWbZHBaec Y/Jfcv1OcgDjmfDBYdyjnNghK5xL8dN+gBnhXBQWVr1r7VMMS0yPCx2S2CWlFHXcJzfG t9aW8bEqwDBQtX9pvxKLKowago7uVC6SRGYlT8bIO5CInDLY+UlMCAszXqBBbyX2rLLw ET4U9mxvv5xQTxtGsvsuprq13NFtaWMuvti9u5pbskBSzO3WHfNlhTCxK/KQ+ohmpZAA fdlY6MUsGWdDg0/lX0DCpkRRlbAl9dIIv8MjhHV2NkXI5bKNtvaCHREQMcoJ99j+DG4R FwgQ== X-Gm-Message-State: ALoCoQk4Z0YbJktgdmebzEYnAFCk3alccy93APEPPqN0fV1tpn8Sn29myVko5bEXxPUztQe9YPvW X-Received: by 10.182.230.168 with SMTP id sz8mr8516738obc.9.1385353446617; Sun, 24 Nov 2013 20:24:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.128.41 with SMTP id nl9ls1982296qeb.56.gmail; Sun, 24 Nov 2013 20:24:06 -0800 (PST) X-Received: by 10.58.210.66 with SMTP id ms2mr24832249vec.10.1385353446454; Sun, 24 Nov 2013 20:24:06 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id gu4si5449445vdc.46.2013.11.24.20.24.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 24 Nov 2013 20:24:06 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id p6so2510797vbe.27 for ; Sun, 24 Nov 2013 20:24:06 -0800 (PST) X-Received: by 10.220.192.198 with SMTP id dr6mr4183278vcb.19.1385353446367; Sun, 24 Nov 2013 20:24:06 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp106531vcz; Sun, 24 Nov 2013 20:24:06 -0800 (PST) X-Received: by 10.224.147.75 with SMTP id k11mr41873252qav.22.1385353445794; Sun, 24 Nov 2013 20:24:05 -0800 (PST) Received: from mail-qa0-f54.google.com (mail-qa0-f54.google.com [209.85.216.54]) by mx.google.com with ESMTPS id i9si13509068qce.46.2013.11.24.20.24.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 24 Nov 2013 20:24:05 -0800 (PST) Received-SPF: neutral (google.com: 209.85.216.54 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.216.54; Received: by mail-qa0-f54.google.com with SMTP id f11so7131667qae.20 for ; Sun, 24 Nov 2013 20:24:05 -0800 (PST) X-Received: by 10.224.37.72 with SMTP id w8mr41798858qad.33.1385353445311; Sun, 24 Nov 2013 20:24:05 -0800 (PST) Received: from localhost (git.linaro.org. [54.235.93.228]) by mx.google.com with ESMTPSA id a5sm6083765qae.2.2013.11.24.20.24.03 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 24 Nov 2013 20:24:04 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, nm@ti.com, ceh@ti.com, Viresh Kumar Subject: [PATCH V2] cpufreq: Make sure CPU is running on a freq from freq-table Date: Mon, 25 Nov 2013 09:53:59 +0530 Message-Id: <046513da96dfec919a1a41d270c167147d4a9c8d.1385353358.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Sometimes boot loaders set CPU frequency to a value outside of frequency table present with cpufreq core. In such cases CPU might be unstable if it has to run on that frequency for long duration of time and so its better to set it to a frequency which is specified in freq-table. This also makes cpufreq stats inconsistent as cpufreq-stats would fail to register because current frequency of CPU isn't found in freq-table. Because we don't want this change to effect boot process badly, we go for the next freq which is >= policy->cur ('cur' must be set by now, otherwise we will end up setting freq to lowest of the table as 'cur' is initialized to zero). In case where CPU is already running on one of the frequencies present in freq-table, this would turn into a dummy call as __cpufreq_driver_target() would return early. Reported-by: Carlos Hernandez Reported-and-tested-by: Nishanth Menon Signed-off-by: Viresh Kumar --- V1->V2 - Set to (policy->cur - 1) instead of policy->cur. - return early in case __cpufreq_driver_target() fails. drivers/cpufreq/cpufreq.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 02d534d..7be996c 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1038,6 +1038,38 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, } } + /* + * Sometimes boot loaders set CPU frequency to a value outside of + * frequency table present with cpufreq core. In such cases CPU might be + * unstable if it has to run on that frequency for long duration of time + * and so its better to set it to a frequency which is specified in + * freq-table. This also makes cpufreq stats inconsistent as + * cpufreq-stats would fail to register because current frequency of CPU + * isn't found in freq-table. + * + * Because we don't want this change to effect boot process badly, we go + * for the next freq which is >= policy->cur ('cur' must be set by now, + * otherwise we will end up setting freq to lowest of the table as 'cur' + * is initialized to zero). + * + * In case where CPU is already running on one of the frequencies + * present in freq-table, this would turn into a dummy call as + * __cpufreq_driver_target() would return early. + * + * We are passing target-freq as "policy->cur - 1" otherwise + * __cpufreq_driver_target() would simply fail, as policy->cur will be + * equal to target-freq. + */ + if (has_target()) { + ret = __cpufreq_driver_target(policy, policy->cur - 1, + CPUFREQ_RELATION_L); + if (ret) { + pr_err("%s: Unable to set frequency from table: %d\n", + __func__, ret); + goto err_out_unregister; + } + } + /* related cpus should atleast have policy->cpus */ cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);