From patchwork Wed Nov 7 18:32:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Langsdorf X-Patchwork-Id: 1711951 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 27384E003B for ; Wed, 7 Nov 2012 18:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754346Ab2KGSef (ORCPT ); Wed, 7 Nov 2012 13:34:35 -0500 Received: from smtp167.dfw.emailsrvr.com ([67.192.241.167]:35460 "EHLO smtp167.dfw.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753608Ab2KGScw (ORCPT ); Wed, 7 Nov 2012 13:32:52 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp6.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id D7855270C3F; Wed, 7 Nov 2012 13:32:51 -0500 (EST) X-Virus-Scanned: OK Received: by smtp6.relay.dfw1a.emailsrvr.com (Authenticated sender: mark.langsdorf-AT-calxeda.com) with ESMTPSA id 7B258270C24; Wed, 7 Nov 2012 13:32:51 -0500 (EST) From: Mark Langsdorf To: linux-kernel@vger.kernel.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org Cc: Mark Langsdorf , MyungJoo Ham Subject: [PATCH 3/6 v4] cpufreq: tolerate inexact values when collecting stats Date: Wed, 7 Nov 2012 12:32:43 -0600 Message-Id: <1352313166-28980-4-git-send-email-mark.langsdorf@calxeda.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352313166-28980-1-git-send-email-mark.langsdorf@calxeda.com> References: <1351631056-25938-1-git-send-email-mark.langsdorf@calxeda.com> <1352313166-28980-1-git-send-email-mark.langsdorf@calxeda.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When collecting stats, if a frequency doesn't match the table, go through the table again with both the search frequency and table values shifted left by 10 bits. Signed-off-by: Mark Langsdorf Cc: MyungJoo Ham --- Changes from v3, v2 None Changes from v1: Implemented a simple round-up algorithm instead of the over/under method that could cause errors on Intel processors with boost mode. drivers/cpufreq/cpufreq_stats.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 3998316..30aee36 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -161,6 +161,9 @@ static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) for (index = 0; index < stat->max_state; index++) if (stat->freq_table[index] == freq) return index; + for (index = 0; index < stat->max_state; index++) + if ((stat->freq_table[index] >> 10) == (freq >> 10)) + return index; return -1; } @@ -251,6 +254,8 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, spin_lock(&cpufreq_stats_lock); stat->last_time = get_jiffies_64(); stat->last_index = freq_table_get_index(stat, policy->cur); + if (stat->last_index > stat->max_state) + stat->last_index = stat->max_state - 1; spin_unlock(&cpufreq_stats_lock); cpufreq_cpu_put(data); return 0;