From patchwork Wed Sep 11 10:13:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 19957 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A1959248D9 for ; Wed, 11 Sep 2013 10:17:01 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hf12sf10128636vcb.7 for ; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=a4XGnR8JgCf7H69MfjdhBt7lcV0nOd3EQkhX5iMt+go=; b=agSSrq37ZMnu+hLflFl7W1DBNdkaVOK911oCYwapKc02gra8wqUkHyv9lCDQKw+weh F7pLnY2O6E6PbRqZkvFgyBPZB/rARlGuRvBiLPYRBCsKNZjrKXe5dvS8/bkgYHLzQGeU AhWV63sUEWmB0G9qLjZk+/g0j1gl8urvUQg8g6f32quSUvcx0Z0Zqd5I+uMbvZWhElkb OpyQSGuWZdfmUXJT9ldENEb0GThQLuv9IsLKicuQAUFb9Ce8HzM3+zle0czFpG+xfoWT mxy2BH40knt5Dnjno2iQlA10B+60UG5TTvo3LKqbZMJ1GzojFjWiwbaNnlx1J20ErWNk IwUA== X-Received: by 10.236.90.67 with SMTP id d43mr349778yhf.36.1378894621478; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.107.136 with SMTP id hc8ls181152qeb.55.gmail; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) X-Received: by 10.52.229.73 with SMTP id so9mr432402vdc.27.1378894621219; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id ti4si5777042vec.99.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:17:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 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.173; Received: by mail-vc0-f173.google.com with SMTP id id13so6065714vcb.32 for ; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) X-Gm-Message-State: ALoCoQnCyAVaQVdfmON2flRo+0a6SfdDLoxts6vkbvIOp2HkW51aQBYfmItIjV++W9prR/5bMJvb X-Received: by 10.220.16.73 with SMTP id n9mr530669vca.24.1378894621126; Wed, 11 Sep 2013 03:17:01 -0700 (PDT) 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 u4csp47837vcz; Wed, 11 Sep 2013 03:17:00 -0700 (PDT) X-Received: by 10.68.202.6 with SMTP id ke6mr763234pbc.173.1378894620214; Wed, 11 Sep 2013 03:17:00 -0700 (PDT) Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com [209.85.160.46]) by mx.google.com with ESMTPS id iv2si1757247pac.3.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:17:00 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.46 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.46; Received: by mail-pb0-f46.google.com with SMTP id rq2so8929497pbb.33 for ; Wed, 11 Sep 2013 03:16:59 -0700 (PDT) X-Received: by 10.68.175.33 with SMTP id bx1mr846539pbc.21.1378894619720; Wed, 11 Sep 2013 03:16:59 -0700 (PDT) Received: from localhost ([27.57.128.127]) by mx.google.com with ESMTPSA id qp10sm2544858pab.13.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:16:59 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 1/5] cpufreq: Optimize cpufreq_frequency_table_verify() Date: Wed, 11 Sep 2013 15:43:07 +0530 Message-Id: X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: 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.173 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: , cpufreq_frequency_table_verify() is a bit rewritten here to make it more logical and optimal. - merge multiple lines for variable declarations together. - quit early if any frequency between min/max is found. - don't call cpufreq_verify_within_limits() in case any valid freq is found as it is of no use. - count renamed as found and made a boolean. Signed-off-by: Viresh Kumar --- drivers/cpufreq/freq_table.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index f111454a..53a2f1a 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c @@ -54,9 +54,8 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_cpuinfo); int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table) { - unsigned int next_larger = ~0; - unsigned int i; - unsigned int count = 0; + unsigned int next_larger = ~0, freq, i = 0; + bool found = false; pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", policy->min, policy->max, policy->cpu); @@ -64,21 +63,23 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq); - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { - unsigned int freq = table[i].frequency; + for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) { if (freq == CPUFREQ_ENTRY_INVALID) continue; - if ((freq >= policy->min) && (freq <= policy->max)) - count++; - else if ((next_larger > freq) && (freq > policy->max)) + if ((freq >= policy->min) && (freq <= policy->max)) { + found = true; + break; + } + + if ((next_larger > freq) && (freq > policy->max)) next_larger = freq; } - if (!count) + if (!found) { policy->max = next_larger; - - cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, - policy->cpuinfo.max_freq); + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, + policy->cpuinfo.max_freq); + } pr_debug("verification lead to (%u - %u kHz) for cpu %u\n", policy->min, policy->max, policy->cpu);