From patchwork Tue Aug 2 23:18:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakash, Prashanth" X-Patchwork-Id: 9260485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A433E6077C for ; Tue, 2 Aug 2016 23:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 950D9284DD for ; Tue, 2 Aug 2016 23:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 887B3284FF; Tue, 2 Aug 2016 23:31:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB4E284DD for ; Tue, 2 Aug 2016 23:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754585AbcHBXbE (ORCPT ); Tue, 2 Aug 2016 19:31:04 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56647 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755060AbcHBXbD (ORCPT ); Tue, 2 Aug 2016 19:31:03 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E0E19605A4; Tue, 2 Aug 2016 23:21:19 +0000 (UTC) Received: from pprakash-lnx.qualcomm.com (unknown [129.46.15.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: pprakash@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8DD626029D; Tue, 2 Aug 2016 23:21:18 +0000 (UTC) From: Prashanth Prakash To: linux-pm@vger.kernel.org Cc: rjw@rjwysocki.net, viresh.kumar@linaro.org, alexey.klimov@arm.com, hotran@apm.com, cov@codeaurora.org, Prashanth Prakash Subject: [PATCH] cpufreq: cpufreq_stats in the absence of frequency table Date: Tue, 2 Aug 2016 17:18:57 -0600 Message-Id: <1470179937-14698-1-git-send-email-pprakash@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP cpufreq drivers such as CPPC works on contigious scale and does not have a static frequency table. This commit adds cpufreq_stats support for such drivers by creating a pseudo frequency table by discretizing the contigious scale. Signed-off-by: Prashanth Prakash --- drivers/cpufreq/cpufreq_stats.c | 63 ++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 06d3abd..4eb9c41 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -14,6 +14,9 @@ #include #include #include +#include + +#define CPUFREQ_PSEUDO_FREQ_TABLE_COUNT (16) static DEFINE_SPINLOCK(cpufreq_stats_lock); @@ -25,6 +28,7 @@ struct cpufreq_stats { unsigned int last_index; u64 *time_in_state; unsigned int *freq_table; + bool pseudo_freq_table; #ifdef CONFIG_CPU_FREQ_STAT_DETAILS unsigned int *trans_table; #endif @@ -130,9 +134,17 @@ static struct attribute_group stats_attr_group = { static int freq_table_get_index(struct cpufreq_stats *stats, unsigned int freq) { int index; - for (index = 0; index < stats->max_state; index++) - if (stats->freq_table[index] == freq) - return index; + + if (stats->pseudo_freq_table) { + for (index = 0; index < stats->max_state; index++) + if (stats->freq_table[index] >= freq) + return index; + } else { + for (index = 0; index < stats->max_state; index++) + if (stats->freq_table[index] == freq) + return index; + } + return -1; } @@ -154,14 +166,14 @@ void cpufreq_stats_free_table(struct cpufreq_policy *policy) void cpufreq_stats_create_table(struct cpufreq_policy *policy) { - unsigned int i = 0, count = 0, ret = -ENOMEM; + unsigned int i = 0, count = 0, ret = -ENOMEM, step_size; struct cpufreq_stats *stats; unsigned int alloc_size; struct cpufreq_frequency_table *pos, *table; - /* We need cpufreq table for creating stats table */ + /* We need cpufreq table or min < max for creating stats table */ table = policy->freq_table; - if (unlikely(!table)) + if (!table && !(policy->min < policy->max)) return; /* stats already initialized */ @@ -173,8 +185,20 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) return; /* Find total allocation size */ - cpufreq_for_each_valid_entry(pos, table) - count++; + if (table) { + cpufreq_for_each_valid_entry(pos, table) + count++; + } else { + stats->pseudo_freq_table = true; + count = CPUFREQ_PSEUDO_FREQ_TABLE_COUNT; + step_size = (policy->max - policy->min + 1) / count; + + /* count is larger than min-max range */ + if (!step_size) { + count = policy->max - policy->min + 1; + step_size = 1; + } + } alloc_size = count * sizeof(int) + count * sizeof(u64); @@ -195,10 +219,17 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) stats->max_state = count; - /* Find valid-unique entries */ - cpufreq_for_each_valid_entry(pos, table) - if (freq_table_get_index(stats, pos->frequency) == -1) - stats->freq_table[i++] = pos->frequency; + if (table) { + /* Find valid-unique entries */ + cpufreq_for_each_valid_entry(pos, table) + if (freq_table_get_index(stats, pos->frequency) == -1) + stats->freq_table[i++] = pos->frequency; + } else { + /* Create a pseudo frequency table */ + for (i = 0 ; i < count ; i++) + stats->freq_table[i] = policy->min + i * step_size; + stats->freq_table[count-1] = policy->max; + } stats->state_num = i; stats->last_time = get_jiffies_64(); @@ -231,9 +262,15 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, new_index = freq_table_get_index(stats, new_freq); /* We can't do stats->time_in_state[-1]= .. */ - if (old_index == -1 || new_index == -1 || old_index == new_index) + if (old_index == -1 || new_index == -1) return; + if (old_index == new_index) { + if (stats->pseudo_freq_table) + stats->total_trans++; + return; + } + cpufreq_stats_update(stats); stats->last_index = new_index;