Skip to content

Commit bbce8ea

Browse files
ionela-voinescuctmarinas
authored andcommitted
cpufreq: add function to get the hardware max frequency
Add weak function to return the hardware maximum frequency of a CPU, with the default implementation returning cpuinfo.max_freq, which is the best information we can generically get from the cpufreq framework. The default can be overwritten by a strong function in platforms that want to provide an alternative implementation, with more accurate information, obtained either from hardware or firmware. Signed-off-by: Ionela Voinescu <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Acked-by: Viresh Kumar <[email protected]> Cc: Viresh Kumar <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 6abde90 commit bbce8ea

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,26 @@ unsigned int cpufreq_quick_get_max(unsigned int cpu)
17251725
}
17261726
EXPORT_SYMBOL(cpufreq_quick_get_max);
17271727

1728+
/**
1729+
* cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1730+
* @cpu: CPU number
1731+
*
1732+
* The default return value is the max_freq field of cpuinfo.
1733+
*/
1734+
__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
1735+
{
1736+
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1737+
unsigned int ret_freq = 0;
1738+
1739+
if (policy) {
1740+
ret_freq = policy->cpuinfo.max_freq;
1741+
cpufreq_cpu_put(policy);
1742+
}
1743+
1744+
return ret_freq;
1745+
}
1746+
EXPORT_SYMBOL(cpufreq_get_hw_max_freq);
1747+
17281748
static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
17291749
{
17301750
if (unlikely(policy_is_inactive(policy)))

include/linux/cpufreq.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static inline bool policy_is_shared(struct cpufreq_policy *policy)
205205
unsigned int cpufreq_get(unsigned int cpu);
206206
unsigned int cpufreq_quick_get(unsigned int cpu);
207207
unsigned int cpufreq_quick_get_max(unsigned int cpu);
208+
unsigned int cpufreq_get_hw_max_freq(unsigned int cpu);
208209
void disable_cpufreq(void);
209210

210211
u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
@@ -232,6 +233,10 @@ static inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
232233
{
233234
return 0;
234235
}
236+
static inline unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
237+
{
238+
return 0;
239+
}
235240
static inline void disable_cpufreq(void) { }
236241
#endif
237242

0 commit comments

Comments
 (0)