Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1407409

Re: [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback

From Viresh Kumar <viresh.kumar@linaro.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback
Date 2016-05-26 08:50 +0200
Message-ID <rCXhf-2WS-5@gated-at.bofh.it> (permalink)
References <rCTGF-Bd-1@gated-at.bofh.it> <rCTGF-Bd-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 25-05-16, 19:53, Steve Muckle wrote:
> Support the new resolve_freq cpufreq callback which resolves a target
> frequency to a driver-supported frequency without actually setting it.

And here is the first abuser of this API as I was talking about in the
earlier patch :)

But, I know why you are doing it and I think we can do it differently.

So, lets assume that the ->resolve_freq() callback will ONLY be
provided by the drivers which also provide a ->target() callback.

i.e. not by acpi-cpufreq at least.

> The target frequency and resolved frequency table entry are cached so
> that a subsequent fast_switch operation may avoid the frequency table
> walk assuming the requested target frequency is the same.
> 
> Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Signed-off-by: Steve Muckle <smuckle@linaro.org>
> ---
>  drivers/cpufreq/acpi-cpufreq.c | 56 ++++++++++++++++++++++++++++++++----------
>  1 file changed, 43 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
> index 7f38fb55f223..d87962eda1ed 100644
> --- a/drivers/cpufreq/acpi-cpufreq.c
> +++ b/drivers/cpufreq/acpi-cpufreq.c
> @@ -66,6 +66,8 @@ enum {
>  
>  struct acpi_cpufreq_data {
>  	struct cpufreq_frequency_table *freq_table;
> +	unsigned int cached_lookup_freq;
> +	struct cpufreq_frequency_table *cached_lookup_entry;

This could have been an integer value 'Index', which could have been
used together with the freq-table to get the freq we wanted.

And, then we can move these two fields into the cpufreq_policy
structure and make them part of the first patch itself.

>  	unsigned int resume;
>  	unsigned int cpu_feature;
>  	unsigned int acpi_perf_cpu;
> @@ -458,26 +460,53 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
>  	return result;
>  }
>  
> -unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy,
> -				      unsigned int target_freq)
> +/*
> + * Find the closest frequency above target_freq.
> + *
> + * The table is sorted in the reverse order with respect to the
> + * frequency and all of the entries are valid (see the initialization).
> + */
> +static inline struct cpufreq_frequency_table
> +*lookup_freq(struct cpufreq_frequency_table *table, unsigned int target_freq)
>  {
> -	struct acpi_cpufreq_data *data = policy->driver_data;
> -	struct acpi_processor_performance *perf;
> -	struct cpufreq_frequency_table *entry;
> -	unsigned int next_perf_state, next_freq, freq;
> +	struct cpufreq_frequency_table *entry = table;
> +	unsigned int freq;
>  
> -	/*
> -	 * Find the closest frequency above target_freq.
> -	 *
> -	 * The table is sorted in the reverse order with respect to the
> -	 * frequency and all of the entries are valid (see the initialization).
> -	 */
> -	entry = data->freq_table;
>  	do {
>  		entry++;
>  		freq = entry->frequency;
>  	} while (freq >= target_freq && freq != CPUFREQ_TABLE_END);
>  	entry--;
> +
> +	return entry;
> +}
> +
> +unsigned int acpi_cpufreq_resolve_freq(struct cpufreq_policy *policy,
> +				       unsigned int target_freq)
> +{
> +	struct acpi_cpufreq_data *data = policy->driver_data;
> +	struct cpufreq_frequency_table *entry;
> +
> +	data->cached_lookup_freq = target_freq;
> +	entry = lookup_freq(data->freq_table, target_freq);
> +	data->cached_lookup_entry = entry;
> +
> +	return entry->frequency;
> +}
> +

And then we could remove this callback from acpi-cpufreq.

> +unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy,
> +				      unsigned int target_freq)
> +{
> +	struct acpi_cpufreq_data *data = policy->driver_data;
> +	struct acpi_processor_performance *perf;
> +	struct cpufreq_frequency_table *entry;
> +	unsigned int next_perf_state, next_freq;
> +
> +	if (data->cached_lookup_entry &&
> +	    data->cached_lookup_freq == target_freq)
> +		entry = data->cached_lookup_entry;
> +	else
> +		entry = lookup_freq(data->freq_table, target_freq);

And a static inline callback in cpufreq.h to get this entry.

>  	next_freq = entry->frequency;
>  	next_perf_state = entry->driver_data;
>  
> @@ -918,6 +947,7 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
>  	.verify		= cpufreq_generic_frequency_table_verify,
>  	.target_index	= acpi_cpufreq_target,
>  	.fast_switch	= acpi_cpufreq_fast_switch,
> +	.resolve_freq	= acpi_cpufreq_resolve_freq,
>  	.bios_limit	= acpi_processor_get_bios_limit,
>  	.init		= acpi_cpufreq_cpu_init,
>  	.exit		= acpi_cpufreq_cpu_exit,

Sounds reasonable ?

-- 
viresh

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/3] cpufreq: avoid redundant driver calls in schedutil Steve Muckle <steve.muckle@linaro.org> - 2016-05-26 05:00 +0200
  [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Steve Muckle <steve.muckle@linaro.org> - 2016-05-26 05:00 +0200
    Re: [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-26 08:30 +0200
      Re: [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Steve Muckle <steve.muckle@linaro.org> - 2016-05-30 17:40 +0200
        Re: [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-31 07:40 +0200
  [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback Steve Muckle <steve.muckle@linaro.org> - 2016-05-26 05:00 +0200
    Re: [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-26 08:50 +0200
      Re: [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback Steve Muckle <steve.muckle@linaro.org> - 2016-05-30 18:30 +0200
  [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to driver frequency Steve Muckle <steve.muckle@linaro.org> - 2016-05-26 05:00 +0200
    Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-26 09:20 +0200
      Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency "Rafael J. Wysocki" <rafael@kernel.org> - 2016-05-29 02:50 +0200
        Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-30 12:20 +0200
          Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency "Rafael J. Wysocki" <rafael@kernel.org> - 2016-05-30 16:30 +0200
            Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Viresh Kumar <viresh.kumar@linaro.org> - 2016-05-30 17:40 +0200
              Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency "Rafael J. Wysocki" <rafael@kernel.org> - 2016-05-30 21:10 +0200
            Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Wanpeng Li <kernellwp@gmail.com> - 2016-05-31 03:50 +0200
      Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Steve Muckle <steve.muckle@linaro.org> - 2016-05-30 18:40 +0200
    Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Wanpeng Li <kernellwp@gmail.com> - 2016-05-27 07:50 +0200
      Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to  driver frequency Steve Muckle <steve.muckle@linaro.org> - 2016-05-30 18:50 +0200

csiph-web