From patchwork Tue Mar 5 22:06:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stratos Karafotis X-Patchwork-Id: 2222211 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 48F43DFF33 for ; Tue, 5 Mar 2013 22:07:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755052Ab3CEWGw (ORCPT ); Tue, 5 Mar 2013 17:06:52 -0500 Received: from sema.semaphore.gr ([78.46.194.137]:53825 "EHLO sema.semaphore.gr" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755022Ab3CEWGu (ORCPT ); Tue, 5 Mar 2013 17:06:50 -0500 Received: from albert.lan (unknown [91.140.112.22]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: stratosk) by sema.semaphore.gr (Postfix) with ESMTPSA id CBBE882906; Tue, 5 Mar 2013 23:06:48 +0100 (CET) Message-ID: <51366C77.3080309@semaphore.gr> Date: Wed, 06 Mar 2013 00:06:47 +0200 From: Stratos Karafotis User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3 MIME-Version: 1.0 To: "Rafael J. Wysocki" CC: Viresh Kumar , cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use an inline function to evaluate freq_target to avoid duplicate code. Also, define a macro for the default frequency step and fix the calculation of freq_target when the max freq is less that 100. Signed-off-by: Stratos Karafotis --- drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index 08be431..029de49 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c @@ -28,6 +28,7 @@ /* Conservative governor macros */ #define DEF_FREQUENCY_UP_THRESHOLD (80) #define DEF_FREQUENCY_DOWN_THRESHOLD (20) +#define DEF_FREQUENCY_STEP (5) #define DEF_SAMPLING_DOWN_FACTOR (1) #define MAX_SAMPLING_DOWN_FACTOR (10) @@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = { .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, .ignore_nice = 0, - .freq_step = 5, + .freq_step = DEF_FREQUENCY_STEP, }; +static inline unsigned int get_freq_target(struct cpufreq_policy *policy) +{ + unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100; + + /* max freq cannot be less than 100. But who knows... */ + if (unlikely(freq_target == 0)) + freq_target = DEF_FREQUENCY_STEP * 1000; /* frequency in KHz */ + + return freq_target; +} + /* * Every sampling_rate, we check, if current idle time is less than 20% * (default), then we try to increase frequency. Every sampling_rate * @@ -55,7 +67,6 @@ static void cs_check_cpu(int cpu, unsigned int load) { struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu); struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; - unsigned int freq_target; /* * break out if we 'cannot' reduce the speed as the user might @@ -72,13 +83,7 @@ static void cs_check_cpu(int cpu, unsigned int load) if (dbs_info->requested_freq == policy->max) return; - freq_target = (cs_tuners.freq_step * policy->max) / 100; - - /* max freq cannot be less than 100. But who knows.... */ - if (unlikely(freq_target == 0)) - freq_target = 5; - - dbs_info->requested_freq += freq_target; + dbs_info->requested_freq += get_freq_target(policy); if (dbs_info->requested_freq > policy->max) dbs_info->requested_freq = policy->max; @@ -94,9 +99,7 @@ static void cs_check_cpu(int cpu, unsigned int load) /* Check for frequency decrease */ if (load < cs_tuners.down_threshold) { - freq_target = (cs_tuners.freq_step * policy->max) / 100; - - dbs_info->requested_freq -= freq_target; + dbs_info->requested_freq -= get_freq_target(policy); if (dbs_info->requested_freq < policy->min) dbs_info->requested_freq = policy->min;