x86: Add generic aperf/mperf code
Commit-ID: 5cbc19a983141729d716be17197028434127b376 Gitweb: http://git.kernel.org/tip/5cbc19a983141729d716be17197028434127b376 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 2 Sep 2009 11:49:52 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 15 Sep 2009 16:51:26 +0200
x86: Add generic aperf/mperf code
Move some of the aperf/mperf code out from the cpufreq driver thingy so that other people can enjoy it too.
Cc H. Peter Anvin <[email protected]>
Cc Venkatesh Pallipadi <[email protected]>
Cc Yanmin <[email protected]>
Cc Dave Jones <[email protected]>
Cc Len Brown <[email protected]>
Cc Yinghai Lu <[email protected]>
Signed-off-by Peter Zijlstra <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>
--- arch/x86/include/asm/processor.h | 30 +++++++++++ arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c | 79 +++------------------------ 2 files changed, 39 insertions(+), 70 deletions(-)
arch/x86/include/asm/processor.h +30 -0
@@ -27,6 +27,7 @@ struct mm_struct;#include <linux/cpumask.h> #include <linux/cache.h> #include <linux/threads.h> +#include <linux/math64.h> #include <linux/init.h> /*
@@ -1020,4 +1021,33 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,extern int get_tsc_mode (unsigned long adr);extern int set_tsc_mode (unsigned int val); +struct aperfmperf { +u64 aperf, mperf; +}; + +static inline void get_aperfmperf (struct aperfmperf *am) +{ +WARN_ON_ONCE (!boot_cpu_has (X86_FEATURE_APERFMPERF )); + +rdmsrl (MSR_IA32_APERF , am->aperf); +rdmsrl (MSR_IA32_MPERF , am->mperf); +} + +#define APERFMPERF_SHIFT 10 + +static inline +unsigned long calc_aperfmperf_ratio (struct aperfmperf *old, +struct aperfmperf *new) +{ +u64 aperf = new->aperf - old->aperf; +u64 mperf = new->mperf - old->mperf; +unsigned long ratio = aperf; + + mperf >>=APERFMPERF_SHIFT ; +if (mperf) + ratio =div64_u64 (aperf, mperf); + +return ratio; +} +#endif /* _ASM_X86_PROCESSOR_H */
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +9 -70
106 lines not on this page · raw message