[patch 10/16] x86: generic aperf/mperf code.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move some of the aperf/mperf code out from the cpufreq driver thingy
so that other people can enjoy it too.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: H Peter Anvin <hpa@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Venkatesh Pallipadi <venkatesh.pallipadi@xxxxxxxxx>
Cc: Yanmin <yanmin_zhang@xxxxxxxxxxxxxxx>
Cc: Dave Jones <davej@xxxxxxxxxx>
Cc: Len Brown <len.brown@xxxxxxxxx>
Cc: Yinghai Lu <yhlu.kernel@xxxxxxxxx>
Cc: cpufreq@xxxxxxxxxxxxxxx

Backport to 2.6.31.4-rt14
Signed-off-by: Dinakar Guniguntala <dino@xxxxxxxxxx>

---
 arch/x86/include/asm/processor.h           |   12 ++++++++
 arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c |   41 +++++++++--------------------
 2 files changed, 26 insertions(+), 27 deletions(-)

Index: linux-2.6.31.4-rt14/arch/x86/include/asm/processor.h
===================================================================
--- linux-2.6.31.4-rt14.orig/arch/x86/include/asm/processor.h	2009-10-12 16:15:40.000000000 -0400
+++ linux-2.6.31.4-rt14/arch/x86/include/asm/processor.h	2009-10-16 09:15:40.000000000 -0400
@@ -1010,4 +1010,16 @@
 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);
+}
+
 #endif /* _ASM_X86_PROCESSOR_H */
Index: linux-2.6.31.4-rt14/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
===================================================================
--- linux-2.6.31.4-rt14.orig/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c	2009-10-16 09:15:39.000000000 -0400
+++ linux-2.6.31.4-rt14/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c	2009-10-16 09:15:40.000000000 -0400
@@ -243,23 +243,12 @@
 	return cmd.val;
 }
 
-struct perf_pair {
-	union {
-		struct {
-			u32 lo;
-			u32 hi;
-		} split;
-		u64 whole;
-	} aperf, mperf;
-};
-
 /* Called via smp_call_function_single(), on the target CPU */
 static void read_measured_perf_ctrs(void *_cur)
 {
-	struct perf_pair *cur = _cur;
+	struct aperfmperf *am = _cur;
 
-	rdmsr(MSR_IA32_APERF, cur->aperf.split.lo, cur->aperf.split.hi);
-	rdmsr(MSR_IA32_MPERF, cur->mperf.split.lo, cur->mperf.split.hi);
+	get_aperfmperf(am);
 }
 
 /*
@@ -278,19 +267,17 @@
 static unsigned int get_measured_perf(struct cpufreq_policy *policy,
 				      unsigned int cpu)
 {
-	struct perf_pair readin, cur;
+	struct aperfmperf readin, cur;
 	unsigned int perf_percent;
 	unsigned int retval;
 
 	if (smp_call_function_single(cpu, read_measured_perf_ctrs, &readin, 1))
 		return 0;
 
-	cur.aperf.whole = readin.aperf.whole -
-				per_cpu(msr_data, cpu).saved_aperf;
-	cur.mperf.whole = readin.mperf.whole -
-				per_cpu(msr_data, cpu).saved_mperf;
-	per_cpu(msr_data, cpu).saved_aperf = readin.aperf.whole;
-	per_cpu(msr_data, cpu).saved_mperf = readin.mperf.whole;
+	cur.aperf = readin.aperf - per_cpu(msr_data, cpu).saved_aperf;
+	cur.mperf = readin.mperf - per_cpu(msr_data, cpu).saved_mperf;
+	per_cpu(msr_data, cpu).saved_aperf = readin.aperf;
+	per_cpu(msr_data, cpu).saved_mperf = readin.mperf;
 
 #ifdef __i386__
 	/*
@@ -305,8 +292,8 @@
 		h = max_t(u32, cur.aperf.split.hi, cur.mperf.split.hi);
 		shift_count = fls(h);
 
-		cur.aperf.whole >>= shift_count;
-		cur.mperf.whole >>= shift_count;
+		cur.aperf >>= shift_count;
+		cur.mperf >>= shift_count;
 	}
 
 	if (((unsigned long)(-1) / 100) < cur.aperf.split.lo) {
@@ -321,14 +308,14 @@
 		perf_percent = 0;
 
 #else
-	if (unlikely(((unsigned long)(-1) / 100) < cur.aperf.whole)) {
+	if (unlikely(((unsigned long)(-1) / 100) < cur.aperf)) {
 		int shift_count = 7;
-		cur.aperf.whole >>= shift_count;
-		cur.mperf.whole >>= shift_count;
+		cur.aperf >>= shift_count;
+		cur.mperf >>= shift_count;
 	}
 
-	if (cur.aperf.whole && cur.mperf.whole)
-		perf_percent = (cur.aperf.whole * 100) / cur.mperf.whole;
+	if (cur.aperf && cur.mperf)
+		perf_percent = (cur.aperf * 100) / cur.mperf;
 	else
 		perf_percent = 0;
 

--
--
To unsubscribe from this list: send the line "unsubscribe cpufreq" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Devel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Forum]     [Linux SCSI]

  Powered by Linux