From patchwork Tue Nov 19 05:40:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 21591 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f72.google.com (mail-qe0-f72.google.com [209.85.128.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A503E20972 for ; Tue, 19 Nov 2013 05:40:38 +0000 (UTC) Received: by mail-qe0-f72.google.com with SMTP id 5sf186563qeb.7 for ; Mon, 18 Nov 2013 21:40:38 -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=+ziPliX1r8VRxNb1w58uPhHilDciB8/RXWTyzIfPbqs=; b=QHG++YL0YTndxlAsJM3GoyINwY/ChcuLJc1creJ40qAgozER0al/WTbe+VDeqyLtyq EY/ODzTkgJMl0P3klu8HcCgQga4m/i4eWmnylZGsxLBG0D+oFnG1mLbqps+coxgAxsut zAHosw1k4zyVpD3ndvEJ3YlVdqhkKExGfpe/MUt/W7q1hY16Z+eGRkNrJ5mRpgaidYxp /fNsNyHr/j2E/xxOsn4cZb3T/cAyl08iEzUVf9eWlwjkPpnqT1OHGZja56hoxwrNCK9M sRADdeeYkbNIhRQ0sUeP5ro+f9QMQvB9VKAbJHGbakd3CNnWE3aJIudVvlgod7b01t55 ktqQ== X-Gm-Message-State: ALoCoQnFdFkAeSPu9l29zQEAgpjVQ9x9IGUC5ffjR6YkwBBVSn4u5uoPvkKZUh2Ubv4x4daMzyQs X-Received: by 10.58.188.113 with SMTP id fz17mr9543678vec.26.1384839637845; Mon, 18 Nov 2013 21:40:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.48.11 with SMTP id h11ls3053337qen.65.gmail; Mon, 18 Nov 2013 21:40:37 -0800 (PST) X-Received: by 10.220.74.69 with SMTP id t5mr19527686vcj.18.1384839637719; Mon, 18 Nov 2013 21:40:37 -0800 (PST) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id th8si814661vdc.76.2013.11.18.21.40.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Nov 2013 21:40:37 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.179 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.179; Received: by mail-vc0-f179.google.com with SMTP id hz11so4470583vcb.10 for ; Mon, 18 Nov 2013 21:40:37 -0800 (PST) X-Received: by 10.52.65.136 with SMTP id x8mr16479555vds.23.1384839637620; Mon, 18 Nov 2013 21:40:37 -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 u4csp253752vcz; Mon, 18 Nov 2013 21:40:36 -0800 (PST) X-Received: by 10.66.149.73 with SMTP id ty9mr24439259pab.36.1384839636380; Mon, 18 Nov 2013 21:40:36 -0800 (PST) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by mx.google.com with ESMTPS id ot3si874290pac.137.2013.11.18.21.40.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Nov 2013 21:40:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.49 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.220.49; Received: by mail-pa0-f49.google.com with SMTP id kx10so1425308pab.36 for ; Mon, 18 Nov 2013 21:40:35 -0800 (PST) X-Received: by 10.66.161.38 with SMTP id xp6mr6148959pab.145.1384839635711; Mon, 18 Nov 2013 21:40:35 -0800 (PST) Received: from localhost ([122.167.133.207]) by mx.google.com with ESMTPSA id g8sm14338333pbe.37.2013.11.18.21.40.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 18 Nov 2013 21:40:35 -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, shawn.guo@linaro.org, ceh@ti.com, Viresh Kumar Subject: [PATCH] cpufreq/stats: Add "unknown" frequency field in stats tables Date: Tue, 19 Nov 2013 11:10:26 +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.220.179 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: , 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. To fix this issue, lets create another entry for time_in_state and trans_table that will tell the user that CPU was running on unknown frequency for some time. This is how the output looks like on my thinkpad (Removed some entries to keep it simple): $ cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state 2800000 46 2600000 138 1200000 65 1000000 152 800000 34803 unknown 0 $ cat /sys/devices/system/cpu/cpu0/cpufreq/stats/trans_table From : To : 2801000 2800000 2600000 2400000 2200000 2000000 unknown 2801000: 0 15 20 9 13 17 0 2800000: 13 0 4 1 0 1 0 2600000: 26 1 0 5 1 1 0 2400000: 11 0 6 0 1 1 0 2200000: 8 1 5 3 0 0 0 2000000: 11 1 2 1 2 0 0 unknown: 0 0 0 0 0 0 0 Reported-by: Carlos Hernandez Reported-and-tested-by: Nishanth Menon Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 45 ++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 4cf0d28..ebb21cd 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -72,9 +72,13 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) return 0; cpufreq_stats_update(stat->cpu); for (i = 0; i < stat->state_num; i++) { - len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], - (unsigned long long) - jiffies_64_to_clock_t(stat->time_in_state[i])); + if (stat->freq_table[i] == -1) + return sprintf(buf + len, "unknown"); + else + return sprintf(buf + len, "%u", stat->freq_table[i]); + + len += sprintf(buf + len, " %llu\n", (unsigned long long) + jiffies_64_to_clock_t(stat->time_in_state[i])); } return len; } @@ -94,8 +98,12 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) for (i = 0; i < stat->state_num; i++) { if (len >= PAGE_SIZE) break; - len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", - stat->freq_table[i]); + if (stat->freq_table[i] == -1) + len += snprintf(buf + len, PAGE_SIZE - len, "%9s ", + "unknown"); + else + len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", + stat->freq_table[i]); } if (len >= PAGE_SIZE) return PAGE_SIZE; @@ -106,8 +114,12 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) if (len >= PAGE_SIZE) break; - len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", - stat->freq_table[i]); + if (stat->freq_table[i] == -1) + len += snprintf(buf + len, PAGE_SIZE - len, "%9s: ", + "unknown"); + else + len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", + stat->freq_table[i]); for (j = 0; j < stat->state_num; j++) { if (len >= PAGE_SIZE) @@ -145,10 +157,12 @@ static struct attribute_group stats_attr_group = { static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) { int index; - for (index = 0; index < stat->max_state; index++) + for (index = 0; index < stat->max_state - 1; index++) if (stat->freq_table[index] == freq) return index; - return -1; + + /* Last state is INVALID, to mark out of table frequency */ + return stat->max_state - 1; } /* should be called late in the CPU removal sequence so that the stats @@ -222,6 +236,9 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, count++; } + /* An extra entry for Invalid frequencies */ + count++; + alloc_size = count * sizeof(int) + count * sizeof(u64); #ifdef CONFIG_CPU_FREQ_STAT_DETAILS @@ -243,9 +260,13 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, unsigned int freq = table[i].frequency; if (freq == CPUFREQ_ENTRY_INVALID) continue; - if (freq_table_get_index(stat, freq) == -1) + if (freq_table_get_index(stat, freq) == stat->max_state - 1) stat->freq_table[j++] = freq; } + + /* Mark Invalid freq as max value to indicate Invalid freq */ + stat->freq_table[j++] = -1; + stat->state_num = j; spin_lock(&cpufreq_stats_lock); stat->last_time = get_jiffies_64(); @@ -315,10 +336,6 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb, old_index = stat->last_index; new_index = freq_table_get_index(stat, freq->new); - /* We can't do stat->time_in_state[-1]= .. */ - if (old_index == -1 || new_index == -1) - return 0; - cpufreq_stats_update(freq->cpu); if (old_index == new_index)