1 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/init.h>
5 #include <linux/cpufreq.h>
6 #include <linux/slab.h>
10 static DEFINE_PER_CPU(struct aperfmperf
, acfreq_old_perf
);
12 /* Called via smp_call_function_single(), on the target CPU */
13 static void read_measured_perf_ctrs(void *_cur
)
15 struct aperfmperf
*am
= _cur
;
21 * Return the measured active (C0) frequency on this CPU since last call
24 * Return: Average CPU frequency in terms of max frequency (zero on error)
26 * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
27 * over a period of time, while CPU is in C0 state.
28 * IA32_MPERF counts at the rate of max advertised frequency
29 * IA32_APERF counts at the rate of actual CPU frequency
30 * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
31 * no meaning should be associated with absolute values of these MSRs.
33 unsigned int cpufreq_get_measured_perf(struct cpufreq_policy
*policy
,
36 struct aperfmperf perf
;
40 if (smp_call_function_single(cpu
, read_measured_perf_ctrs
, &perf
, 1))
43 ratio
= calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf
, cpu
), &perf
);
44 per_cpu(acfreq_old_perf
, cpu
) = perf
;
46 retval
= (policy
->cpuinfo
.max_freq
* ratio
) >> APERFMPERF_SHIFT
;
50 EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf
);
51 MODULE_LICENSE("GPL");