linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target()
@ 2021-06-29  6:27 Viresh Kumar
  2021-06-29  6:27 ` [PATCH 2/2] cpufreq: Remove ->resolve_freq() Viresh Kumar
  2021-06-30 17:47 ` [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Viresh Kumar @ 2021-06-29  6:27 UTC (permalink / raw)
  To: Rafael Wysocki, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, TungChen Shih, linux-kernel

__cpufreq_driver_target() open codes cpufreq_driver_resolve_freq(), lets
make the former reuse the later.

Separate out __resolve_freq() to accept relation as well as an argument
and use it at both the locations.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 42 ++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 802abc925b2a..d691c6c97c79 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -524,19 +524,8 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
 }
 EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
 
-/**
- * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
- * one.
- * @policy: associated policy to interrogate
- * @target_freq: target frequency to resolve.
- *
- * The target to driver frequency mapping is cached in the policy.
- *
- * Return: Lowest driver-supported frequency greater than or equal to the
- * given target_freq, subject to policy (min/max) and driver limitations.
- */
-unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
-					 unsigned int target_freq)
+static unsigned int __resolve_freq(struct cpufreq_policy *policy,
+		unsigned int target_freq, unsigned int relation)
 {
 	target_freq = clamp_val(target_freq, policy->min, policy->max);
 	policy->cached_target_freq = target_freq;
@@ -545,7 +534,7 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
 		unsigned int idx;
 
 		idx = cpufreq_frequency_table_target(policy, target_freq,
-						     CPUFREQ_RELATION_L);
+						     relation);
 		policy->cached_resolved_idx = idx;
 		return policy->freq_table[idx].frequency;
 	}
@@ -555,6 +544,23 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
 
 	return target_freq;
 }
+
+/**
+ * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
+ * one.
+ * @policy: associated policy to interrogate
+ * @target_freq: target frequency to resolve.
+ *
+ * The target to driver frequency mapping is cached in the policy.
+ *
+ * Return: Lowest driver-supported frequency greater than or equal to the
+ * given target_freq, subject to policy (min/max) and driver limitations.
+ */
+unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
+					 unsigned int target_freq)
+{
+	return __resolve_freq(policy, target_freq, CPUFREQ_RELATION_L);
+}
 EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq);
 
 unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)
@@ -2225,13 +2231,11 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
 			    unsigned int relation)
 {
 	unsigned int old_target_freq = target_freq;
-	int index;
 
 	if (cpufreq_disabled())
 		return -ENODEV;
 
-	/* Make sure that target_freq is within supported range */
-	target_freq = clamp_val(target_freq, policy->min, policy->max);
+	target_freq = __resolve_freq(policy, target_freq, relation);
 
 	pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
 		 policy->cpu, target_freq, relation, old_target_freq);
@@ -2252,9 +2256,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
 	if (!cpufreq_driver->target_index)
 		return -EINVAL;
 
-	index = cpufreq_frequency_table_target(policy, target_freq, relation);
-
-	return __target_index(policy, index);
+	return __target_index(policy, policy->cached_resolved_idx);
 }
 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
 
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] cpufreq: Remove ->resolve_freq()
  2021-06-29  6:27 [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Viresh Kumar
@ 2021-06-29  6:27 ` Viresh Kumar
  2021-06-30 17:47 ` [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2021-06-29  6:27 UTC (permalink / raw)
  To: Rafael Wysocki, Viresh Kumar, Jonathan Corbet, Alex Shi
  Cc: linux-pm, Vincent Guittot, TungChen Shih, linux-doc, linux-kernel

commit e3c062360870 ("cpufreq: add cpufreq_driver_resolve_freq()")
introduced this callback, back in 2016, for drivers that provide the
->target() callback.

The kernel haven't seen a single user of the same in the past 5 years
and there is little hope that it will be used anytime soon.

Lets remove it for now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 Documentation/cpu-freq/cpu-drivers.rst        |  3 ---
 .../zh_CN/cpu-freq/cpu-drivers.rst            |  2 --
 drivers/cpufreq/cpufreq.c                     | 21 +++++++------------
 include/linux/cpufreq.h                       |  9 --------
 4 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/Documentation/cpu-freq/cpu-drivers.rst b/Documentation/cpu-freq/cpu-drivers.rst
index a697278ce190..5ee49820d48a 100644
--- a/Documentation/cpu-freq/cpu-drivers.rst
+++ b/Documentation/cpu-freq/cpu-drivers.rst
@@ -58,9 +58,6 @@ And optionally
 
  .driver_data - cpufreq driver specific data.
 
- .resolve_freq - Returns the most appropriate frequency for a target
- frequency. Doesn't change the frequency though.
-
  .get_intermediate and target_intermediate - Used to switch to stable
  frequency while changing CPU frequency.
 
diff --git a/Documentation/translations/zh_CN/cpu-freq/cpu-drivers.rst b/Documentation/translations/zh_CN/cpu-freq/cpu-drivers.rst
index 0ca2cb646666..f906a4e5a3ac 100644
--- a/Documentation/translations/zh_CN/cpu-freq/cpu-drivers.rst
+++ b/Documentation/translations/zh_CN/cpu-freq/cpu-drivers.rst
@@ -64,8 +64,6 @@ 并且可选择
 
  .driver_data - cpufreq驱动程序的特定数据。
 
- .resolve_freq - 返回最适合目标频率的频率。不过并不能改变频率。
-
  .get_intermediate 和 target_intermediate - 用于在改变CPU频率时切换到稳定
  的频率。
 
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d691c6c97c79..b106191d84b1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -527,22 +527,17 @@ EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
 static unsigned int __resolve_freq(struct cpufreq_policy *policy,
 		unsigned int target_freq, unsigned int relation)
 {
-	target_freq = clamp_val(target_freq, policy->min, policy->max);
-	policy->cached_target_freq = target_freq;
+	unsigned int idx;
 
-	if (cpufreq_driver->target_index) {
-		unsigned int idx;
-
-		idx = cpufreq_frequency_table_target(policy, target_freq,
-						     relation);
-		policy->cached_resolved_idx = idx;
-		return policy->freq_table[idx].frequency;
-	}
+	target_freq = clamp_val(target_freq, policy->min, policy->max);
 
-	if (cpufreq_driver->resolve_freq)
-		return cpufreq_driver->resolve_freq(policy, target_freq);
+	if (!cpufreq_driver->target_index)
+		return target_freq;
 
-	return target_freq;
+	idx = cpufreq_frequency_table_target(policy, target_freq, relation);
+	policy->cached_resolved_idx = idx;
+	policy->cached_target_freq = target_freq;
+	return policy->freq_table[idx].frequency;
 }
 
 /**
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 353969c7acd3..18f0ddf7347a 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -330,15 +330,6 @@ struct cpufreq_driver {
 				       unsigned long target_perf,
 				       unsigned long capacity);
 
-	/*
-	 * Caches and returns the lowest driver-supported frequency greater than
-	 * or equal to the target frequency, subject to any driver limitations.
-	 * Does not set the frequency. Only to be implemented for drivers with
-	 * target().
-	 */
-	unsigned int	(*resolve_freq)(struct cpufreq_policy *policy,
-					unsigned int target_freq);
-
 	/*
 	 * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION
 	 * unset.
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target()
  2021-06-29  6:27 [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Viresh Kumar
  2021-06-29  6:27 ` [PATCH 2/2] cpufreq: Remove ->resolve_freq() Viresh Kumar
@ 2021-06-30 17:47 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2021-06-30 17:47 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Linux PM, Vincent Guittot, TungChen Shih,
	Linux Kernel Mailing List

On Tue, Jun 29, 2021 at 8:27 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> __cpufreq_driver_target() open codes cpufreq_driver_resolve_freq(), lets
> make the former reuse the later.
>
> Separate out __resolve_freq() to accept relation as well as an argument
> and use it at both the locations.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/cpufreq/cpufreq.c | 42 ++++++++++++++++++++-------------------
>  1 file changed, 22 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 802abc925b2a..d691c6c97c79 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -524,19 +524,8 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
>  }
>  EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
>
> -/**
> - * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
> - * one.
> - * @policy: associated policy to interrogate
> - * @target_freq: target frequency to resolve.
> - *
> - * The target to driver frequency mapping is cached in the policy.
> - *
> - * Return: Lowest driver-supported frequency greater than or equal to the
> - * given target_freq, subject to policy (min/max) and driver limitations.
> - */
> -unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
> -                                        unsigned int target_freq)
> +static unsigned int __resolve_freq(struct cpufreq_policy *policy,
> +               unsigned int target_freq, unsigned int relation)
>  {
>         target_freq = clamp_val(target_freq, policy->min, policy->max);
>         policy->cached_target_freq = target_freq;
> @@ -545,7 +534,7 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
>                 unsigned int idx;
>
>                 idx = cpufreq_frequency_table_target(policy, target_freq,
> -                                                    CPUFREQ_RELATION_L);
> +                                                    relation);
>                 policy->cached_resolved_idx = idx;
>                 return policy->freq_table[idx].frequency;
>         }
> @@ -555,6 +544,23 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
>
>         return target_freq;
>  }
> +
> +/**
> + * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
> + * one.
> + * @policy: associated policy to interrogate
> + * @target_freq: target frequency to resolve.
> + *
> + * The target to driver frequency mapping is cached in the policy.
> + *
> + * Return: Lowest driver-supported frequency greater than or equal to the
> + * given target_freq, subject to policy (min/max) and driver limitations.
> + */
> +unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
> +                                        unsigned int target_freq)
> +{
> +       return __resolve_freq(policy, target_freq, CPUFREQ_RELATION_L);
> +}
>  EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq);
>
>  unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)
> @@ -2225,13 +2231,11 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
>                             unsigned int relation)
>  {
>         unsigned int old_target_freq = target_freq;
> -       int index;
>
>         if (cpufreq_disabled())
>                 return -ENODEV;
>
> -       /* Make sure that target_freq is within supported range */
> -       target_freq = clamp_val(target_freq, policy->min, policy->max);
> +       target_freq = __resolve_freq(policy, target_freq, relation);
>
>         pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
>                  policy->cpu, target_freq, relation, old_target_freq);
> @@ -2252,9 +2256,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
>         if (!cpufreq_driver->target_index)
>                 return -EINVAL;
>
> -       index = cpufreq_frequency_table_target(policy, target_freq, relation);
> -
> -       return __target_index(policy, index);
> +       return __target_index(policy, policy->cached_resolved_idx);
>  }
>  EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
>
> --

Applied as 5.14-rc1 material along with the [2/2], thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-30 17:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29  6:27 [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Viresh Kumar
2021-06-29  6:27 ` [PATCH 2/2] cpufreq: Remove ->resolve_freq() Viresh Kumar
2021-06-30 17:47 ` [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).