From patchwork Tue Nov 26 06:14:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 21764 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6AFE823FDB for ; Tue, 26 Nov 2013 06:14:54 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id uo5sf13433774pbc.10 for ; Mon, 25 Nov 2013 22:14:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=PmjARxQYFBrV9jBKBPw0J0UxNPZunqHotk8tG2IOWWw=; b=i4dpzvgrqTzjU+u0gJ6qDYCStIY3LkyEOrW57MrXnjcNPW6O6795Zlt1UwTc56YvzS xcuzJzNzmqE/EbZ+SXQbgn1l6ExuNyiOfjWOBCMkEmeaKPAQ9u2pqEnY9sZ2+gqjvlqq 6X3prNvtyMGK2O0Yg+8A7fImM64VNGvtJ05wfwVIcz0nOvAc3/7gKtM9yDixZziMobkv 9rJLMR1NrQlIrdWT8/oaj1uOCHplGN+6I7UAot8YlY4xGZ5zwhpzPBU69tWDvrXv/9Uk r7dIxPqQwsk18MnbOu69+azFBvzjSLpnfusMj/arqVToeY/U04pWfu7qRZKnmA3UD4HU /H/Q== X-Gm-Message-State: ALoCoQnpBQh2PSf/zRUMMpi/AeKhrJqpxxaAekuI242DyT1X4zYkZ4Vm67JnRJYCMnwVFQPn5cI1 X-Received: by 10.67.3.34 with SMTP id bt2mr113069pad.41.1385446493208; Mon, 25 Nov 2013 22:14:53 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.65 with SMTP id i1ls1893751qei.72.gmail; Mon, 25 Nov 2013 22:14:53 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr28770928vcx.1.1385446493063; Mon, 25 Nov 2013 22:14:53 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id lw10si18996066vec.119.2013.11.25.22.14.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 22:14:52 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id lf12so3440951vcb.7 for ; Mon, 25 Nov 2013 22:14:52 -0800 (PST) X-Received: by 10.58.133.77 with SMTP id pa13mr5862098veb.21.1385446492670; Mon, 25 Nov 2013 22:14:52 -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 u4csp188291vcz; Mon, 25 Nov 2013 22:14:52 -0800 (PST) X-Received: by 10.224.124.134 with SMTP id u6mr52016612qar.79.1385446491953; Mon, 25 Nov 2013 22:14:51 -0800 (PST) Received: from mail-qe0-f44.google.com (mail-qe0-f44.google.com [209.85.128.44]) by mx.google.com with ESMTPS id m8si15086812qcs.103.2013.11.25.22.14.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 22:14:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.44 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.128.44; Received: by mail-qe0-f44.google.com with SMTP id nd7so4621479qeb.31 for ; Mon, 25 Nov 2013 22:14:51 -0800 (PST) X-Received: by 10.49.17.232 with SMTP id r8mr53045227qed.74.1385446491357; Mon, 25 Nov 2013 22:14:51 -0800 (PST) Received: from [127.0.0.1] (git.linaro.org. [54.235.93.228]) by mx.google.com with ESMTPSA id f10sm79800561qej.1.2013.11.25.22.14.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 22:14:50 -0800 (PST) Message-ID: <52943C55.5010503@linaro.org> Date: Tue, 26 Nov 2013 11:44:45 +0530 From: viresh kumar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: "Rafael J. Wysocki" CC: Dirk Brandewie , Lists linaro-kernel , Patch Tracking , "cpufreq@vger.kernel.org" , "linux-pm@vger.kernel.org" , Linux Kernel Mailing List , Nishanth Menon , Carlos Hernandez Subject: Re: [PATCH V2] cpufreq: Make sure CPU is running on a freq from freq-table References: <046513da96dfec919a1a41d270c167147d4a9c8d.1385353358.git.viresh.kumar@linaro.org> <52938C5F.7000307@gmail.com> <2997050.eogEtPXZyL@vostro.rjw.lan> In-Reply-To: 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.220.176 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: , On Tuesday 26 November 2013 07:31 AM, Viresh Kumar wrote: > Probably just throw an print message that CPU found to be running on > out of table frequency, and that got fixed.. And here is the patch to test: From: Viresh Kumar Date: Mon, 18 Nov 2013 10:15:50 +0530 Subject: [PATCH] cpufreq: Make sure CPU is running on a freq from freq-table 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 current frequency doesn't match any frequency from freq-table, we throw warnings to user, so that user can get this fixed in their bootloaders or freq-tables. Reported-by: Carlos Hernandez Reported-and-tested-by: Nishanth Menon Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/cpufreq/freq_table.c | 24 ++++++++++++++++++++++++ include/linux/cpufreq.h | 2 ++ 3 files changed, 63 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 02d534d..5beb16d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1038,6 +1038,43 @@ 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). + * + * 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()) { + /* Are we running at unknown frequency ? */ + ret = cpufreq_frequency_table_get_index(policy, policy->cur); + if (ret == -EINVAL) { + /* Warn user and fix it */ + pr_warn("%s: CPU%d: running at invalid freq: %u KHz\n", + __func__, policy->cpu, policy->cur); + 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; + } + pr_warn("%s: CPU%d: frequency changed to: %u KHz\n", + __func__, policy->cpu, policy->cur); + } + } + /* related cpus should atleast have policy->cpus */ cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 3458d27..0d6cc0e 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c @@ -178,7 +178,31 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, } EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); +int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, + unsigned int freq) +{ + struct cpufreq_frequency_table *table; + int index = -EINVAL, i = 0; + + table = cpufreq_frequency_get_table(policy->cpu); + if (unlikely(!table)) { + pr_debug("%s: Unable to find freq_table\n", __func__); + return -ENOENT; + } + + for (; table[i].frequency != CPUFREQ_TABLE_END; i++) { + if (table[i].frequency == freq) { + index = i; + break; + } + } + + return index; +} +EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index); + static DEFINE_PER_CPU(struct cpufreq_frequency_table *, cpufreq_show_table); + /** * show_available_freqs - show available frequencies for the specified CPU */ diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index dc196bb..71646ce 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -439,6 +439,8 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation, unsigned int *index); +int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, + unsigned int freq); void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy); ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);