From patchwork Sat Nov 16 00:20:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 3191411 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6DFF29F3AE for ; Sat, 16 Nov 2013 00:21:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8491D20918 for ; Sat, 16 Nov 2013 00:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 865C320901 for ; Sat, 16 Nov 2013 00:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752672Ab3KPAVM (ORCPT ); Fri, 15 Nov 2013 19:21:12 -0500 Received: from arroyo.ext.ti.com ([192.94.94.40]:56302 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752487Ab3KPAVK (ORCPT ); Fri, 15 Nov 2013 19:21:10 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id rAG0KxMZ015713; Fri, 15 Nov 2013 18:20:59 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id rAG0KxHW020563; Fri, 15 Nov 2013 18:20:59 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Fri, 15 Nov 2013 18:20:59 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id rAG0Kw2g022922; Fri, 15 Nov 2013 18:20:59 -0600 From: Nishanth Menon To: "Rafael J. Wysocki" , Viresh Kumar CC: , , , , Nishanth Menon , Tobias Diedrich , Konrad Rzeszutek Wilk , Dave Jones Subject: [PATCH] cpufreq: stats: Do not populate stats when policy->cur has no exact match Date: Fri, 15 Nov 2013 18:20:43 -0600 Message-ID: <1384561243-30391-1-git-send-email-nm@ti.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP commit 46a310b ([CPUFREQ] Don't set stat->last_index to -1 if the pol->cur has incorrect value.) tries to handle case where policy->cur does not match any entry in freq_table. As indicated in the above commit, the exact match search of freq_table_get index will return a -1 which is stored in stat->last_index. However, as a result of the above commit, cpufreq_stat_notifier_trans which updates the statistics, fails to update any *further* valid transitions that take place as stat->last_index is -1 as the condition occurs at boot and never solved. So, instead of having a statistics information that never ever reflects valid data in the mentioned case and scratching our heads, we instead, refuse to populate any of the statistics entries and note in kernel log the error condition for developers to fix. The only useable information are the available frequencies which is already available in other cpufreq sysfs entries. Cc: Tobias Diedrich Cc: Konrad Rzeszutek Wilk Cc: Dave Jones Reported-by: Carlos Hernandez Signed-off-by: Nishanth Menon --- Patch based on v3.12 tag Reported by Carlos on TI vendor kernel (v3.12tag based): OMAP5uEVM: http://pastebin.mozilla.org/3612196 AM335x-evm: http://pastebin.mozilla.org/3612220 As can be seen, the translation table are present, however none of the transition information is ever updated. With the current patch, this becomes: http://pastebin.mozilla.org/3612256 Original commit thread seems to be: https://lkml.org/lkml/2011/6/16/760 but I dont see much information if this was discussed further. An alternate approach possible is to try and recover from this case by using an 'atmost' match to find a closest match and then giveup when we cant find one, but that does not really indicate a proper statistic (if freq1 < cur_freq < freq2, was the intent to be at freq1 or freq2? stats should not make that policy decision) http://pastebin.mozilla.org/3612179 (alternate approach 1) Yet another option might be to update last_index using the first transition into a valid index, but then, we wont have statistics information 100% correct as we did not store the very first frequency stat. http://pastebin.mozilla.org/3612241 (alternate approach 2) drivers/cpufreq/cpufreq_stats.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 4cf0d28..4c8a501 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -251,6 +251,14 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, stat->last_time = get_jiffies_64(); stat->last_index = freq_table_get_index(stat, policy->cur); spin_unlock(&cpufreq_stats_lock); + + if (stat->last_index == -1) { + pr_err("%s: No match for current freq %u in table. Disabled!\n", + __func__, policy->cur); + ret = -EINVAL; + goto error_out; + } + cpufreq_cpu_put(current_policy); return 0; error_out: