From patchwork Thu Nov 21 07:09:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 21660 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8D6120E7C for ; Thu, 21 Nov 2013 07:09:13 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ld13sf1590865vcb.9 for ; Wed, 20 Nov 2013 23:09:12 -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=sZCDovBEJrLSfGnIvj/EqfdUr3w2YeXsRjSodMsnqzE=; b=KY8flIRSaxd0Gwn7cfZorSbyJKb/CgZiqBuXBuNyZ4qxJFceqAJ54jZJE9pQSRHRtP 7qWO5wWN6vvcwHwgONvb/wZyouk89VmX9RdRgKF+7wZCHXoTx6NdNj+Kh62T1b8rJzsF Tdx3FG9jkdXdAvC3ECc6Qapp7LC+H6xejhmD35imn0e+/EynYlVdxMOQgAy2Lel5J9KR VVtQaWk1v79wmMLJpWcbS/fzDRb0rgj9x4lWA+wcu07QjCVUY7NbaPATCwf9E7cD6OUd nzULVofAQ/2VSSf7blG+u196oYrqnrWdJwFFiwqGS/qKn3nGqyiKdZyOUwBeXIvs9JWI Bsfg== X-Gm-Message-State: ALoCoQmFPrqCS8gMjlH4YQzC6P0N/JzBUg3o9LLZSRECRiySof7HNeceaS6HVL4AgVfxxK3K83zN X-Received: by 10.52.31.69 with SMTP id y5mr1429323vdh.4.1385017752725; Wed, 20 Nov 2013 23:09:12 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.29.129 with SMTP id k1ls363713qeh.75.gmail; Wed, 20 Nov 2013 23:09:12 -0800 (PST) X-Received: by 10.58.233.98 with SMTP id tv2mr4466474vec.11.1385017752627; Wed, 20 Nov 2013 23:09:12 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id rw8si10540993vdc.57.2013.11.20.23.09.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Nov 2013 23:09:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 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.50; Received: by mail-vb0-f50.google.com with SMTP id 10so3661796vbe.37 for ; Wed, 20 Nov 2013 23:09:12 -0800 (PST) X-Received: by 10.52.98.194 with SMTP id ek2mr3679654vdb.11.1385017752495; Wed, 20 Nov 2013 23:09:12 -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 u4csp407468vcz; Wed, 20 Nov 2013 23:09:12 -0800 (PST) X-Received: by 10.49.1.230 with SMTP id 6mr8633104qep.48.1385017751894; Wed, 20 Nov 2013 23:09:11 -0800 (PST) Received: from mail-qe0-f46.google.com (mail-qe0-f46.google.com [209.85.128.46]) by mx.google.com with ESMTPS id kb1si6306223qeb.151.2013.11.20.23.09.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Nov 2013 23:09:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.46 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.128.46; Received: by mail-qe0-f46.google.com with SMTP id s14so7102759qeb.33 for ; Wed, 20 Nov 2013 23:09:11 -0800 (PST) X-Received: by 10.49.39.201 with SMTP id r9mr8650223qek.46.1385017751579; Wed, 20 Nov 2013 23:09:11 -0800 (PST) Received: from localhost (git.linaro.org. [54.235.93.228]) by mx.google.com with ESMTPSA id n7sm74546239qai.1.2013.11.20.23.09.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 20 Nov 2013 23:09:10 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net, nm@ti.com Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, shawn.guo@linaro.org, ceh@ti.com, Viresh Kumar Subject: [PATCH] cpufreq: Make sure CPU is running on a freq from freq-table Date: Thu, 21 Nov 2013 12:39:02 +0530 Message-Id: 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.50 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-by: Nishanth Menon Signed-off-by: Viresh Kumar --- After lots of discussion with Nishanth and others, I feel something like this.. @Nishanth: Please see if this works for you and I hope we don't need any of these patches anymore: - https://lkml.org/lkml/2013/11/15/569 : cpufreq: cpufreq-cpu0: Use a sane boot frequency when booting with a mismatched bootloader configuration - https://lkml.org/lkml/2013/11/15/503 : cpufreq: stats: Do not populate stats when policy->cur has no exact match - https://lkml.org/lkml/2013/11/19/16 : cpufreq/stats: Add "unknown" frequency field in stats tables drivers/cpufreq/cpufreq.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 02d534d..d55c843 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1038,6 +1038,32 @@ 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. + */ + if (has_target()) { + ret = __cpufreq_driver_target(policy, policy->cur, + CPUFREQ_RELATION_L); + if (ret) + pr_err("%s: Unable to set frequency from table: %d\n", + __func__, ret); + } + /* related cpus should atleast have policy->cpus */ cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);