a2fed573f0
Starting with model 10 of Family 0x10, AMD processors may have support for APERF/MPERF. Add support for identifying it and using it within cpufreq. Move the APERF/MPERF functions out of the acpi-cpufreq code and into their own file so they can easily be shared. Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com> LKML-Reference: <20100401141956.GA1930@aftab> Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> Reviewed-by: Thomas Renninger <trenn@suse.de> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
52 lines
1.5 KiB
C
52 lines
1.5 KiB
C
#include <linux/kernel.h>
|
|
#include <linux/smp.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/cpufreq.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include "mperf.h"
|
|
|
|
static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf);
|
|
|
|
/* Called via smp_call_function_single(), on the target CPU */
|
|
static void read_measured_perf_ctrs(void *_cur)
|
|
{
|
|
struct aperfmperf *am = _cur;
|
|
|
|
get_aperfmperf(am);
|
|
}
|
|
|
|
/*
|
|
* Return the measured active (C0) frequency on this CPU since last call
|
|
* to this function.
|
|
* Input: cpu number
|
|
* Return: Average CPU frequency in terms of max frequency (zero on error)
|
|
*
|
|
* We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
|
|
* over a period of time, while CPU is in C0 state.
|
|
* IA32_MPERF counts at the rate of max advertised frequency
|
|
* IA32_APERF counts at the rate of actual CPU frequency
|
|
* Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
|
|
* no meaning should be associated with absolute values of these MSRs.
|
|
*/
|
|
unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
|
|
unsigned int cpu)
|
|
{
|
|
struct aperfmperf perf;
|
|
unsigned long ratio;
|
|
unsigned int retval;
|
|
|
|
if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1))
|
|
return 0;
|
|
|
|
ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf);
|
|
per_cpu(acfreq_old_perf, cpu) = perf;
|
|
|
|
retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT;
|
|
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf);
|
|
MODULE_LICENSE("GPL");
|