Skip to contentSkip to conversation

Separate average frequency from acpi-cpufreq and make it available via EXPORT_SYMBOL_GPL for others

PATCH New Thomas Renninger 1 participant 4 messages Apr 23, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Len,

if Venkatesh and others agree, can you push these into your test tree, please. The patches are based on your latest test tree.

These slightly conflict with a work_on_cpu vs smp_call_function_single patch which is AFAIK still under discussion. But it should be easy (just remove a hunk?) to resolve this.

Thanks,

Thomas

#1 lore raw

PATCH 1/3 acpi-cpufreq: Move average performance funtions into separate file and KConfig

exports:
EXPORT_SYMBOL_GPL(get_average_perf)
unsigned int get_average_perf(struct cpufreq_policy *policy, unsigned int cpu,

			      u64 *saved_aperf, u64 *saved_mperf)

This function will read the
APERF (0x000000E8) MSR:
Incremented by hardware at the P0 frequency

and
and MPERF (0x000000E7) MSR:
Incremented by hardware at the actual number of core clocks cycles

and will calculate the average frequency the CPU core has run, based on the saved_aperf/saved_mperf values from a previous call.

Example (untested, evaluates the average freq of the last ms on core 0):
===============
#ifdef(X86_AVERAGE_FREQUENCY) /* also make
u64 saved_aperf, saved_mperf;
struct cpufreq_policy;
struct cpuinfo_x86 *cpu = &cpu_data(cpu);
int cpu = 0;
unsigned int average_freq;

if (!cpu_has(cpu, X86_FEATURE_APERF_MPERF)) /* Introduced in next patch */

    return;

cpufreq_get_policy(policy, cpu);
get_average_perf(policy, cpu, &saved_aperf, &saved_mperf); msleep(1);
average_freq = get_average_perf(policy, cpu, &saved_aperf, &saved_mperf); #endif
===============

One could now easily add a debug monitor of the average freq of a process' life cycle, there are probably other use-cases, I could imagine sched_mc developers may find this interface convenient for debugging/optimizing.

Additional modification:
Use smp_call_function_single instead of work_on_cpu.
The latter was broken anyway: 0 was always returned as the called function read_measured_perf_ctrs always returns zero which work_on_cpu's return value was wrongly checked for:
if (!work_on_cpu(cpu, read_measured_perf_ctrs, &readin))

		return 0;
---
 arch/x86/kernel/cpu/cpufreq/Kconfig             |   15 +++
 arch/x86/kernel/cpu/cpufreq/Makefile            |    1 +
 arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c      |   94 +--------------
 arch/x86/kernel/cpu/cpufreq/average_frequency.c |  146 +++++++++++++++++++++++
 include/linux/cpufreq.h                         |   13 ++
 5 files changed, 178 insertions(+), 91 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/cpufreq/average_frequency.c
arch/x86/kernel/cpu/cpufreq/Kconfig +15 -0
index 52c8398..3ca1602 100644
@@ -26,6 +26,21 @@ config X86_ACPI_CPUFREQ
 
 	  If in doubt, say N.
 
+config X86_AVERAGE_FREQUENCY
+	bool "Calculate and consider average frequency over a time period"
+	depends on CPU_FREQ_TABLE
+	help
+	  Latest X86 Intel processors can overclock a single core
+	  behind the kernel's back (ida cpuinfo flag) if specific requirements
+	  are met.
+	  With this option, the kernel can evaluate the real frequency a core
+	  was running on over a time period and kernel parts, for example
+	  the cpufreq core and governor or later the scheduler can consider and
+	  optimize for the "boost" frequency on such processors.
+	  Currently the only driver which serves such processors is acpi-cpufreq.
+	  This option should be enabled for this driver at least
+	  on processors which show the "ida" flag in /proc/cpuinfo
+
 config ELAN_CPUFREQ
 	tristate "AMD Elan SC400 and SC410"
 	select CPU_FREQ_TABLE
arch/x86/kernel/cpu/cpufreq/Makefile +1 -0
index 509296d..3eb5a64 100644
@@ -2,6 +2,7 @@
 # K8 systems. ACPI is preferred to all other hardware-specific drivers.
 # speedstep-* is preferred over p4-clockmod.
 
+obj-$(CONFIG_X86_AVERAGE_FREQUENCY)     += average_frequency.o
 obj-$(CONFIG_X86_POWERNOW_K8)		+= powernow-k8.o
 obj-$(CONFIG_X86_ACPI_CPUFREQ)		+= acpi-cpufreq.o
 obj-$(CONFIG_X86_POWERNOW_K6)		+= powernow-k6.o
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +3 -91

103 lines not on this page · raw message

arch/x86/kernel/cpu/cpufreq/average_frequency.c new file +146 -0

146 lines not on this page · raw message

include/linux/cpufreq.h +13 -0
index 1610427..0ab8bf7 100644
@@ -362,6 +362,19 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
 
 void cpufreq_frequency_table_put_attr(unsigned int cpu);
 
+/*
+ * Get the average frequency since the last call of this function if the
+ * needed MSRs are supported by the CPU
+*/
+#ifdef CONFIG_X86_AVERAGE_FREQUENCY
+unsigned int get_average_perf(struct cpufreq_policy *policy, unsigned int cpu,
+			      u64 *saved_aperf, u64 *saved_mperf);
+#else
+unsigned int get_average_perf(struct cpufreq_policy *policy, unsigned int cpu,
+			      u64 *saved_aperf, u64 *saved_mperf)
+{ return 0; }
+#endif
+
 
 /*********************************************************************
  *                     UNIFIED DEBUG HELPERS                         *
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/3 X86: Introduce mperf_aperf X86_FEATURE

In reply to Thomas Renninger

Users of the newly introduced:
EXPORT_SYMBOL_GPL(get_average_perf);
function must check for this feature to make sure it can be used.

---
 arch/x86/include/asm/cpufeature.h          |    1 +
 arch/x86/kernel/cpu/addon_cpuid_features.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 arch/x86/kernel/cpu/mkcapflags.pl
arch/x86/include/asm/cpufeature.h +1 -0
index bb83b1c..b1c4bd8 100644
@@ -155,6 +155,7 @@
  */
 #define X86_FEATURE_IDA		(7*32+ 0) /* Intel Dynamic Acceleration */
 #define X86_FEATURE_ARAT	(7*32+ 1) /* Always Running APIC Timer */
+#define X86_FEATURE_APERF_MPERF	(7*32+ 3) /* APERF/MPERF average freq MSRs */
 
 /* Virtualization flags: Linux defined */
 #define X86_FEATURE_TPR_SHADOW  (8*32+ 0) /* Intel TPR Shadow */
arch/x86/kernel/cpu/addon_cpuid_features.c +1 -0
index c965e52..e91c357 100644
@@ -32,6 +32,7 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
 	static const struct cpuid_bit __cpuinitconst cpuid_bits[] = {
 		{ X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 },
 		{ X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 },
+		{ X86_FEATURE_APERF_MPERF, CR_ECX, 0, 0x00000006 },
 		{ 0, 0, 0, 0 }
 	};
 
arch/x86/kernel/cpu/mkcapflags.pl +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/3 acpi-cpufreq: Use X86_FEATURE_APERF_MPERF to check for average freq capability

In reply to Thomas Renninger
---
 arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +2 -6
index bf9b6b1..b75ca28 100644
@@ -647,12 +647,8 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 	acpi_processor_notify_smm(THIS_MODULE);
 
 	/* Check for APERF/MPERF support in hardware */
-	if (c->x86_vendor == X86_VENDOR_INTEL && c->cpuid_level >= 6) {
-		unsigned int ecx;
-		ecx = cpuid_ecx(6);
-		if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)
-			acpi_cpufreq_driver.getavg = get_measured_perf;
-	}
+	if (cpu_has(c, X86_FEATURE_APERF_MPERF))
+		acpi_cpufreq_driver.getavg = get_measured_perf;
 
 	dprintk("CPU%u - ACPI performance management activated.\n", cpu);
 	for (i = 0; i < perf->state_count; i++)
Signature · 1 line
1.6.0.2