[PATCH 1/2] cpufreq: governor: Move requested_freq to policy_dbs_info

Lifeng Zheng posted 2 patches 1 month, 3 weeks ago
[PATCH 1/2] cpufreq: governor: Move requested_freq to policy_dbs_info
Posted by Lifeng Zheng 1 month, 3 weeks ago
Conservative governor uses requested_freq to store the last target freq
requested by the governor. This member variable can also be useful for the
ondemand governor. So move it to struct policy_dbs_info and update it each
time request a frequency.

Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
 drivers/cpufreq/cpufreq_conservative.c | 14 ++++----------
 drivers/cpufreq/cpufreq_governor.c     |  1 +
 drivers/cpufreq/cpufreq_governor.h     | 12 ++++++++++++
 drivers/cpufreq/cpufreq_ondemand.c     | 10 +++++-----
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index cce6a8d113e1..2980ca19c580 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -14,7 +14,6 @@
 struct cs_policy_dbs_info {
 	struct policy_dbs_info policy_dbs;
 	unsigned int down_skip;
-	unsigned int requested_freq;
 };
 
 static inline struct cs_policy_dbs_info *to_dbs_info(struct policy_dbs_info *policy_dbs)
@@ -59,7 +58,7 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
 {
 	struct policy_dbs_info *policy_dbs = policy->governor_data;
 	struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
-	unsigned int requested_freq = dbs_info->requested_freq;
+	unsigned int requested_freq = policy_dbs->requested_freq;
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	unsigned int load = dbs_update(policy);
@@ -79,7 +78,7 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
 	 */
 	if (requested_freq > policy->max || requested_freq < policy->min) {
 		requested_freq = policy->cur;
-		dbs_info->requested_freq = requested_freq;
+		policy_dbs->requested_freq = requested_freq;
 	}
 
 	freq_step = get_freq_step(cs_tuners, policy);
@@ -111,9 +110,7 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
 		if (requested_freq > policy->max)
 			requested_freq = policy->max;
 
-		__cpufreq_driver_target(policy, requested_freq,
-					CPUFREQ_RELATION_HE);
-		dbs_info->requested_freq = requested_freq;
+		gov_freq_request(policy, requested_freq, CPUFREQ_RELATION_HE);
 		goto out;
 	}
 
@@ -135,9 +132,7 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
 		else
 			requested_freq = policy->min;
 
-		__cpufreq_driver_target(policy, requested_freq,
-					CPUFREQ_RELATION_LE);
-		dbs_info->requested_freq = requested_freq;
+		gov_freq_request(policy, requested_freq, CPUFREQ_RELATION_LE);
 	}
 
  out:
@@ -310,7 +305,6 @@ static void cs_start(struct cpufreq_policy *policy)
 	struct cs_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
 
 	dbs_info->down_skip = 0;
-	dbs_info->requested_freq = policy->cur;
 }
 
 static struct dbs_governor cs_governor = {
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 1a7fcaf39cc9..7ec38407230f 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -524,6 +524,7 @@ int cpufreq_dbs_governor_start(struct cpufreq_policy *policy)
 
 	policy_dbs->is_shared = policy_is_shared(policy);
 	policy_dbs->rate_mult = 1;
+	policy_dbs->requested_freq = policy->cur;
 
 	sampling_rate = dbs_data->sampling_rate;
 	ignore_nice = dbs_data->ignore_nice_load;
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index 168c23fd7fca..51db1abced93 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -97,6 +97,8 @@ struct policy_dbs_info {
 	/* Status indicators */
 	bool is_shared;		/* This object is used by multiple CPUs */
 	bool work_in_progress;	/* Work is being queued up or in progress */
+
+	unsigned int requested_freq;	/* Last frequency requested by the governor */
 };
 
 static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
@@ -105,6 +107,16 @@ static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
 	policy_dbs->sample_delay_ns = delay_us * NSEC_PER_USEC;
 }
 
+static inline void gov_freq_request(struct cpufreq_policy *policy,
+				    unsigned int requested_freq,
+				    unsigned int relation)
+{
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+
+	__cpufreq_driver_target(policy, requested_freq, relation);
+	policy_dbs->requested_freq = requested_freq;
+}
+
 /* Per cpu structures */
 struct cpu_dbs_info {
 	u64 prev_cpu_idle;
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index a6ecc203f7b7..fb6d4183d589 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -101,8 +101,8 @@ static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
 	else if (policy->cur == policy->max)
 		return;
 
-	__cpufreq_driver_target(policy, freq, od_tuners->powersave_bias ?
-			CPUFREQ_RELATION_LE : CPUFREQ_RELATION_HE);
+	gov_freq_request(policy, freq, od_tuners->powersave_bias ?
+			 CPUFREQ_RELATION_LE : CPUFREQ_RELATION_HE);
 }
 
 /*
@@ -142,7 +142,7 @@ static void od_update(struct cpufreq_policy *policy)
 								 freq_next,
 								 CPUFREQ_RELATION_LE);
 
-		__cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_CE);
+		gov_freq_request(policy, freq_next, CPUFREQ_RELATION_CE);
 	}
 }
 
@@ -160,8 +160,8 @@ static unsigned int od_dbs_update(struct cpufreq_policy *policy)
 	 * it then.
 	 */
 	if (sample_type == OD_SUB_SAMPLE && policy_dbs->sample_delay_ns > 0) {
-		__cpufreq_driver_target(policy, dbs_info->freq_lo,
-					CPUFREQ_RELATION_HE);
+		gov_freq_request(policy, dbs_info->freq_lo,
+				 CPUFREQ_RELATION_HE);
 		return dbs_info->freq_lo_delay_us;
 	}
 
-- 
2.33.0