Skip to contentSkip to conversation

Added multiplier for APERF and MPERF counters

PATCH In review Lukasz Anaczkowski 2 participants 4 messages Sep 16, 2015 – Sep 18, 2015 Turbostat utility

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added multiplier for APERF and MPERF counters

From: Hubert Chrzaniuk <[email protected]>

Intel(R) Xeon Phi x200 (KNL) increments APERF/MPERF every 1024 clocks, which is different than other Intel architectures (incremented every single clock).
It results in understated values for %Busy and Avg_MHz values, thus multiplier for APERF/MPERF counters.

---
 tools/power/x86/turbostat/turbostat.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/power/x86/turbostat/turbostat.c +13 -0
index 9655cb4..1dda607 100644
@@ -71,6 +71,7 @@ unsigned int extra_msr_offset32;
 unsigned int extra_msr_offset64;
 unsigned int extra_delta_offset32;
 unsigned int extra_delta_offset64;
+unsigned int aperf_mperf_multiplier = 1;
 int do_smi;
 double bclk;
 unsigned int show_pkg;
@@ -984,6 +985,8 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 			return -3;
 		if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf))
 			return -4;
+		t->aperf = t->aperf * aperf_mperf_multiplier;
+		t->mperf = t->mperf * aperf_mperf_multiplier;
 	}
 
 	if (do_smi) {
@@ -2543,6 +2546,13 @@ int is_knl(unsigned int family, unsigned int model)
 	return 0;
 }
 
+unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model)
+{
+	if (is_knl(family, model))
+		return 1024;
+	return 1;
+}
+
 #define SLM_BCLK_FREQS 5
 double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0};
 
@@ -2744,6 +2754,9 @@ void process_cpuid()
 		}
 	}
 
+	if (has_aperf)
+		aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model);
+
 	do_nhm_platform_info = do_nhm_cstates = do_smi = probe_nhm_msrs(family, model);
 	do_snb_cstates = has_snb_msrs(family, model);
 	do_pc2 = do_snb_cstates && (pkg_cstate_limit >= PCL__2);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 10 lines · Lukasz Anaczkowski

From: Hubert Chrzaniuk <[email protected]>

Intel(R) Xeon Phi x200 (KNL) increments APERF/MPERF every 1024 clocks, which is different than other Intel architectures (incremented every single clock).
It results in understated values for %Busy and Avg_MHz values, thus multiplier for APERF/MPERF counters.

Please *always* send PM-related patches to [email protected] (CCed now).

Quoted 50 lines
---
 tools/power/x86/turbostat/turbostat.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/power/x86/turbostat/turbostat.c +13 -0
index 9655cb4..1dda607 100644
@@ -71,6 +71,7 @@ unsigned int extra_msr_offset32;
 unsigned int extra_msr_offset64;
 unsigned int extra_delta_offset32;
 unsigned int extra_delta_offset64;
+unsigned int aperf_mperf_multiplier = 1;
 int do_smi;
 double bclk;
 unsigned int show_pkg;
@@ -984,6 +985,8 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 			return -3;
 		if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf))
 			return -4;
+		t->aperf = t->aperf * aperf_mperf_multiplier;
+		t->mperf = t->mperf * aperf_mperf_multiplier;
 	}
 
 	if (do_smi) {
@@ -2543,6 +2546,13 @@ int is_knl(unsigned int family, unsigned int model)
 	return 0;
 }
 
+unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model)
+{
+	if (is_knl(family, model))
+		return 1024;
+	return 1;
+}
+
 #define SLM_BCLK_FREQS 5
 double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0};
 
@@ -2744,6 +2754,9 @@ void process_cpuid()
 		}
 	}
 
+	if (has_aperf)
+		aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model);
+
 	do_nhm_platform_info = do_nhm_cstates = do_smi = probe_nhm_msrs(family, model);
 	do_snb_cstates = has_snb_msrs(family, model);
 	do_pc2 = do_snb_cstates && (pkg_cstate_limit >= PCL__2);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw

From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, September 17, 2015 7:05 PM

Quoted 1 line

Please *always* send PM-related patches to [email protected] (CCed now).

Ok, thanks for noticing.
I've addressed my patch based on output of ./scripts/get_maintainer.pl and gave me output like this:

Len Brown <len.brown@xxx>
Dasaratharaman Chandramouli <dasaratharaman.chandramouli@xxx> [email protected]

Should it be fixed somehow?

Cheers,
Lukasz

#3 lore raw
Quoted 9 lines · Lukasz

From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, September 17, 2015 7:05 PM

Quoted 1 line

Please *always* send PM-related patches to [email protected] (CCed now).

Ok, thanks for noticing.
I've addressed my patch based on output of ./scripts/get_maintainer.pl and gave me output like this:

Quoted 5 lines

Len Brown <len.brown@xxx>
Dasaratharaman Chandramouli <dasaratharaman.chandramouli@xxx> [email protected]

Should it be fixed somehow?

Well, so to speak, the script is not an intelligent entity and while it can give you hints, it by no means is an ultimate source of information.

If you did "grep -r -I -l APERF *" in the kernel source tree, you'll immediately see that PM uses it.

And while at it, we really should only be using the APERF/MPERF ratio so I'm not sure why this patch actually matters?

Thanks,
Rafael