From patchwork Thu Jan 31 17:28:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 2074661 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A49E83FCDE for ; Thu, 31 Jan 2013 17:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752923Ab3AaR2Y (ORCPT ); Thu, 31 Jan 2013 12:28:24 -0500 Received: from mail-da0-f49.google.com ([209.85.210.49]:43087 "EHLO mail-da0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755984Ab3AaR2W (ORCPT ); Thu, 31 Jan 2013 12:28:22 -0500 Received: by mail-da0-f49.google.com with SMTP id v40so1370807dad.8 for ; Thu, 31 Jan 2013 09:28:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=yA/N1oRAppLQj85eSewDfu5mDJs4bXr2Qq04WplkZQ8=; b=G7o1mmZzXqsxAlqFbi4aLIvy1B68iSLWjTv8UGsCJs0t1rr7tbnNSB7PWjNKxfzUbb HKnoW8OpygTwDD+hv9Ha55BzBZDn9VU3rsm+t/zJ4T2HygW9rdKloXe3eh2AYcK5j22I HbVrz2XHAig4C6uqf4OtcKM4iktf+qHKBV4cALLaMgHZBE6hZrNxxRoKOPajd/82fy0S +KoQEN0O/aFcUB3Qh+qU98JkeyyUZ4FD+5dD+pgqmi4u/aSGJuQ6daDeCipGecMU06L7 I/CTE5mgBm8ZMaomC7rIDyWavEeF1reNncVjlf8oD97VUZdbcVH9+6ZSVt/BRvZPgl5U LDLA== X-Received: by 10.68.217.104 with SMTP id ox8mr23924563pbc.105.1359653299727; Thu, 31 Jan 2013 09:28:19 -0800 (PST) Received: from localhost ([122.172.196.215]) by mx.google.com with ESMTPS id kl3sm5576636pbc.15.2013.01.31.09.28.15 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 31 Jan 2013 09:28:19 -0800 (PST) From: Viresh Kumar To: rjw@sisk.pl, fabio.baltieri@linaro.org Cc: cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, robin.randhawa@arm.com, Steve.Bannister@arm.com, Liviu.Dudau@arm.com, Viresh Kumar Subject: [PATCH 2/2] cpufreq: governors: Remove code redundancy between governors Date: Thu, 31 Jan 2013 22:58:02 +0530 Message-Id: <118c59263751862b1750ed9f96639a4e70069e66.1359653181.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <09a94ff044ff6a6f7a5d953c3b1f3102c1dc50cf.1359653181.git.viresh.kumar@linaro.org> References: <09a94ff044ff6a6f7a5d953c3b1f3102c1dc50cf.1359653181.git.viresh.kumar@linaro.org> In-Reply-To: <09a94ff044ff6a6f7a5d953c3b1f3102c1dc50cf.1359653181.git.viresh.kumar@linaro.org> References: <09a94ff044ff6a6f7a5d953c3b1f3102c1dc50cf.1359653181.git.viresh.kumar@linaro.org> X-Gm-Message-State: ALoCoQlWqX5XJyQPihLj5RdaqVVmfDzCV6fDnNDIOb0eSGzXfaJqUR51kvUtBlaIlwvVFzrpz+F3 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org With the inclusion of following patches: 9f4eb10 cpufreq: conservative: call dbs_check_cpu only when necessary 772b4b1 cpufreq: ondemand: call dbs_check_cpu only when necessary code redundancy is introduced again. Get rid of it. Signed-off-by: Viresh Kumar Tested-by: Fabio Baltieri --- drivers/cpufreq/cpufreq_conservative.c | 52 ++++------------------- drivers/cpufreq/cpufreq_governor.c | 18 ++++++++ drivers/cpufreq/cpufreq_governor.h | 2 + drivers/cpufreq/cpufreq_ondemand.c | 77 ++++++++++------------------------ 4 files changed, 52 insertions(+), 97 deletions(-) diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index c18a304..e8bb915 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c @@ -111,58 +111,24 @@ static void cs_check_cpu(int cpu, unsigned int load) } } -static void cs_timer_update(struct cs_cpu_dbs_info_s *dbs_info, bool sample, - struct delayed_work *dw) +static void cs_dbs_timer(struct work_struct *work) { + struct delayed_work *dw = to_delayed_work(work); + struct cs_cpu_dbs_info_s *dbs_info = container_of(work, + struct cs_cpu_dbs_info_s, cdbs.work.work); unsigned int cpu = dbs_info->cdbs.cur_policy->cpu; + struct cs_cpu_dbs_info_s *core_dbs_info = &per_cpu(cs_cpu_dbs_info, + cpu); int delay = delay_for_sampling_rate(cs_tuners.sampling_rate); - if (sample) + mutex_lock(&core_dbs_info->cdbs.timer_mutex); + if (need_load_eval(&core_dbs_info->cdbs, cs_tuners.sampling_rate)) dbs_check_cpu(&cs_dbs_data, cpu); schedule_delayed_work_on(smp_processor_id(), dw, delay); + mutex_unlock(&core_dbs_info->cdbs.timer_mutex); } -static void cs_timer_coordinated(struct cs_cpu_dbs_info_s *dbs_info_local, - struct delayed_work *dw) -{ - struct cs_cpu_dbs_info_s *dbs_info; - ktime_t time_now; - s64 delta_us; - bool sample = true; - - /* use leader CPU's dbs_info */ - dbs_info = &per_cpu(cs_cpu_dbs_info, - dbs_info_local->cdbs.cur_policy->cpu); - mutex_lock(&dbs_info->cdbs.timer_mutex); - - time_now = ktime_get(); - delta_us = ktime_us_delta(time_now, dbs_info->cdbs.time_stamp); - - /* Do nothing if we recently have sampled */ - if (delta_us < (s64)(cs_tuners.sampling_rate / 2)) - sample = false; - else - dbs_info->cdbs.time_stamp = time_now; - - cs_timer_update(dbs_info, sample, dw); - mutex_unlock(&dbs_info->cdbs.timer_mutex); -} - -static void cs_dbs_timer(struct work_struct *work) -{ - struct delayed_work *dw = to_delayed_work(work); - struct cs_cpu_dbs_info_s *dbs_info = container_of(work, - struct cs_cpu_dbs_info_s, cdbs.work.work); - - if (policy_is_shared(dbs_info->cdbs.cur_policy)) { - cs_timer_coordinated(dbs_info, dw); - } else { - mutex_lock(&dbs_info->cdbs.timer_mutex); - cs_timer_update(dbs_info, true, dw); - mutex_unlock(&dbs_info->cdbs.timer_mutex); - } -} static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data) { diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c index 29d6a59..dc99472 100644 --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -177,6 +177,24 @@ static inline void dbs_timer_exit(struct dbs_data *dbs_data, int cpu) cancel_delayed_work_sync(&cdbs->work); } +/* Will return if we need to evaluate cpu load again or not */ +bool need_load_eval(struct cpu_dbs_common_info *cdbs, + unsigned int sampling_rate) +{ + if (policy_is_shared(cdbs->cur_policy)) { + ktime_t time_now = ktime_get(); + s64 delta_us = ktime_us_delta(time_now, cdbs->time_stamp); + + /* Do nothing if we recently have sampled */ + if (delta_us < (s64)(sampling_rate / 2)) + return false; + else + cdbs->time_stamp = time_now; + } + + return true; +} + int cpufreq_governor_dbs(struct dbs_data *dbs_data, struct cpufreq_policy *policy, unsigned int event) { diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h index c19a16c..16314b6 100644 --- a/drivers/cpufreq/cpufreq_governor.h +++ b/drivers/cpufreq/cpufreq_governor.h @@ -171,6 +171,8 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate) u64 get_cpu_idle_time(unsigned int cpu, u64 *wall); void dbs_check_cpu(struct dbs_data *dbs_data, int cpu); +bool need_load_eval(struct cpu_dbs_common_info *cdbs, + unsigned int sampling_rate); int cpufreq_governor_dbs(struct dbs_data *dbs_data, struct cpufreq_policy *policy, unsigned int event); #endif /* _CPUFREQ_GOVERNER_H */ diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 75efd5e..f38b8da 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c @@ -216,75 +216,44 @@ static void od_check_cpu(int cpu, unsigned int load_freq) } } -static void od_timer_update(struct od_cpu_dbs_info_s *dbs_info, bool sample, - struct delayed_work *dw) +static void od_dbs_timer(struct work_struct *work) { + struct delayed_work *dw = to_delayed_work(work); + struct od_cpu_dbs_info_s *dbs_info = + container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work); unsigned int cpu = dbs_info->cdbs.cur_policy->cpu; - int delay, sample_type = dbs_info->sample_type; + struct od_cpu_dbs_info_s *core_dbs_info = &per_cpu(od_cpu_dbs_info, + cpu); + int delay, sample_type = core_dbs_info->sample_type; + bool eval_load; + + mutex_lock(&core_dbs_info->cdbs.timer_mutex); + eval_load = need_load_eval(&core_dbs_info->cdbs, + od_tuners.sampling_rate); /* Common NORMAL_SAMPLE setup */ - dbs_info->sample_type = OD_NORMAL_SAMPLE; + core_dbs_info->sample_type = OD_NORMAL_SAMPLE; if (sample_type == OD_SUB_SAMPLE) { - delay = dbs_info->freq_lo_jiffies; - if (sample) - __cpufreq_driver_target(dbs_info->cdbs.cur_policy, - dbs_info->freq_lo, + delay = core_dbs_info->freq_lo_jiffies; + if (eval_load) + __cpufreq_driver_target(core_dbs_info->cdbs.cur_policy, + core_dbs_info->freq_lo, CPUFREQ_RELATION_H); } else { - if (sample) + if (eval_load) dbs_check_cpu(&od_dbs_data, cpu); - if (dbs_info->freq_lo) { + if (core_dbs_info->freq_lo) { /* Setup timer for SUB_SAMPLE */ - dbs_info->sample_type = OD_SUB_SAMPLE; - delay = dbs_info->freq_hi_jiffies; + core_dbs_info->sample_type = OD_SUB_SAMPLE; + delay = core_dbs_info->freq_hi_jiffies; } else { delay = delay_for_sampling_rate(od_tuners.sampling_rate - * dbs_info->rate_mult); + * core_dbs_info->rate_mult); } } schedule_delayed_work_on(smp_processor_id(), dw, delay); -} - -static void od_timer_coordinated(struct od_cpu_dbs_info_s *dbs_info_local, - struct delayed_work *dw) -{ - struct od_cpu_dbs_info_s *dbs_info; - ktime_t time_now; - s64 delta_us; - bool sample = true; - - /* use leader CPU's dbs_info */ - dbs_info = &per_cpu(od_cpu_dbs_info, - dbs_info_local->cdbs.cur_policy->cpu); - mutex_lock(&dbs_info->cdbs.timer_mutex); - - time_now = ktime_get(); - delta_us = ktime_us_delta(time_now, dbs_info->cdbs.time_stamp); - - /* Do nothing if we recently have sampled */ - if (delta_us < (s64)(od_tuners.sampling_rate / 2)) - sample = false; - else - dbs_info->cdbs.time_stamp = time_now; - - od_timer_update(dbs_info, sample, dw); - mutex_unlock(&dbs_info->cdbs.timer_mutex); -} - -static void od_dbs_timer(struct work_struct *work) -{ - struct delayed_work *dw = to_delayed_work(work); - struct od_cpu_dbs_info_s *dbs_info = - container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work); - - if (policy_is_shared(dbs_info->cdbs.cur_policy)) { - od_timer_coordinated(dbs_info, dw); - } else { - mutex_lock(&dbs_info->cdbs.timer_mutex); - od_timer_update(dbs_info, true, dw); - mutex_unlock(&dbs_info->cdbs.timer_mutex); - } + mutex_unlock(&core_dbs_info->cdbs.timer_mutex); } /************************** sysfs interface ************************/