diff options
author | Steve Muckle <steve.muckle@linaro.org> | 2016-07-13 16:25:25 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-07-21 08:46:08 -0400 |
commit | e3c06236087051d5c62d60d0668588c370fda887 (patch) | |
tree | 87bf8e5a9b77cb24d416851136451aaf43f27fd1 | |
parent | da7de91c3e237f3ace1aa29b82c69702dc0176c5 (diff) |
cpufreq: add cpufreq_driver_resolve_freq()
Cpufreq governors may need to know what a particular target frequency
maps to in the driver without necessarily wanting to set the frequency.
Support this operation via a new cpufreq API,
cpufreq_driver_resolve_freq(). This API returns the lowest driver
frequency equal or greater than the target frequency
(CPUFREQ_RELATION_L), subject to any policy (min/max) or driver
limitations. The mapping is also cached in the policy so that a
subsequent fast_switch operation can avoid repeating the same lookup.
The API will call a new cpufreq driver callback, resolve_freq(), if it
has been registered by the driver. Otherwise the frequency is resolved
via cpufreq_frequency_table_target(). Rather than require ->target()
style drivers to provide a resolve_freq() callback it is left to the
caller to ensure that the driver implements this callback if necessary
to use cpufreq_driver_resolve_freq().
Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Steve Muckle <smuckle@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 25 | ||||
-rw-r--r-- | include/linux/cpufreq.h | 16 |
2 files changed, 41 insertions, 0 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 118b4f30a406..b696baeb249d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -492,6 +492,29 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy) | |||
492 | } | 492 | } |
493 | EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch); | 493 | EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch); |
494 | 494 | ||
495 | /** | ||
496 | * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported | ||
497 | * one. | ||
498 | * @target_freq: target frequency to resolve. | ||
499 | * | ||
500 | * The target to driver frequency mapping is cached in the policy. | ||
501 | * | ||
502 | * Return: Lowest driver-supported frequency greater than or equal to the | ||
503 | * given target_freq, subject to policy (min/max) and driver limitations. | ||
504 | */ | ||
505 | unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, | ||
506 | unsigned int target_freq) | ||
507 | { | ||
508 | target_freq = clamp_val(target_freq, policy->min, policy->max); | ||
509 | policy->cached_target_freq = target_freq; | ||
510 | if (cpufreq_driver->resolve_freq) | ||
511 | return cpufreq_driver->resolve_freq(policy, target_freq); | ||
512 | policy->cached_resolved_idx = | ||
513 | cpufreq_frequency_table_target(policy, target_freq, | ||
514 | CPUFREQ_RELATION_L); | ||
515 | return policy->freq_table[policy->cached_resolved_idx].frequency; | ||
516 | } | ||
517 | |||
495 | /********************************************************************* | 518 | /********************************************************************* |
496 | * SYSFS INTERFACE * | 519 | * SYSFS INTERFACE * |
497 | *********************************************************************/ | 520 | *********************************************************************/ |
@@ -2199,6 +2222,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, | |||
2199 | policy->min = new_policy->min; | 2222 | policy->min = new_policy->min; |
2200 | policy->max = new_policy->max; | 2223 | policy->max = new_policy->max; |
2201 | 2224 | ||
2225 | policy->cached_target_freq = UINT_MAX; | ||
2226 | |||
2202 | pr_debug("new min and max freqs are %u - %u kHz\n", | 2227 | pr_debug("new min and max freqs are %u - %u kHz\n", |
2203 | policy->min, policy->max); | 2228 | policy->min, policy->max); |
2204 | 2229 | ||
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index c6410b1b2490..631ba33bbe9f 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h | |||
@@ -120,6 +120,10 @@ struct cpufreq_policy { | |||
120 | bool fast_switch_possible; | 120 | bool fast_switch_possible; |
121 | bool fast_switch_enabled; | 121 | bool fast_switch_enabled; |
122 | 122 | ||
123 | /* Cached frequency lookup from cpufreq_driver_resolve_freq. */ | ||
124 | unsigned int cached_target_freq; | ||
125 | int cached_resolved_idx; | ||
126 | |||
123 | /* Synchronization for frequency transitions */ | 127 | /* Synchronization for frequency transitions */ |
124 | bool transition_ongoing; /* Tracks transition status */ | 128 | bool transition_ongoing; /* Tracks transition status */ |
125 | spinlock_t transition_lock; | 129 | spinlock_t transition_lock; |
@@ -270,6 +274,16 @@ struct cpufreq_driver { | |||
270 | unsigned int index); | 274 | unsigned int index); |
271 | unsigned int (*fast_switch)(struct cpufreq_policy *policy, | 275 | unsigned int (*fast_switch)(struct cpufreq_policy *policy, |
272 | unsigned int target_freq); | 276 | unsigned int target_freq); |
277 | |||
278 | /* | ||
279 | * Caches and returns the lowest driver-supported frequency greater than | ||
280 | * or equal to the target frequency, subject to any driver limitations. | ||
281 | * Does not set the frequency. Only to be implemented for drivers with | ||
282 | * target(). | ||
283 | */ | ||
284 | unsigned int (*resolve_freq)(struct cpufreq_policy *policy, | ||
285 | unsigned int target_freq); | ||
286 | |||
273 | /* | 287 | /* |
274 | * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION | 288 | * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION |
275 | * unset. | 289 | * unset. |
@@ -501,6 +515,8 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, | |||
501 | int __cpufreq_driver_target(struct cpufreq_policy *policy, | 515 | int __cpufreq_driver_target(struct cpufreq_policy *policy, |
502 | unsigned int target_freq, | 516 | unsigned int target_freq, |
503 | unsigned int relation); | 517 | unsigned int relation); |
518 | unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, | ||
519 | unsigned int target_freq); | ||
504 | int cpufreq_register_governor(struct cpufreq_governor *governor); | 520 | int cpufreq_register_governor(struct cpufreq_governor *governor); |
505 | void cpufreq_unregister_governor(struct cpufreq_governor *governor); | 521 | void cpufreq_unregister_governor(struct cpufreq_governor *governor); |
506 | 522 | ||