intel_cpus: average cpu frequency, dnd some idle data
Joe Konno
cover intel_cpus: average cpu frequency, dnd some idle data
From: Joe Konno <joe.konno(a)intel.com>
The first patch in this series makes a cosmetic change to the Frequency Stats tab for Intel end-users. "Actual" cpu frequency will be changed to "Average", which is a more accurate representation of that data (since it displays the average cpu frequency for the sampling period). The underlying algorithms which generate this data remain unchanged.
The second patch will add a condition to the Frequency Stats tab "Idle" display, which will _not_ display "Idle" data if the intel_pstate kernel driver (not cpufreq) is loaded. Only the average frequency of each logical core for the sample period will be displayed (if intel_pstate is loaded).
With intel_pstate, Idle data for the Frequency Stats tab is inferred from cpu_frequency PM trace events. There have been particular workloads where PowerTOP may display 100% idle (in Frequency Stats) for the sampling period despite logical cores doing work. Further, Frequency Stats' 'idle' data may not match idle data presented in the Idle Stats tab. This is a bug, and is the justification for patch 2 in this series.
After this patch series is committed, end-users who load the intel_pstate driver are directed to perform idle analysis on data gathered from the Idle Stats tab, as the Frequency Stats tab will only provide average logical core frequency for the sampling period. It may be possible to bring idle statistics back to the Frequency Stats tab for intel_pstate in the future, but only after careful re-examination of Frequency Stats' idle calculations.
Joe Konno (2):
intel_cpus: frequency: clarify average clock speed
intel_cpus: no pstate Idle pct with intel_pstate
src/cpu/intel_cpus.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++-------- src/cpu/intel_cpus.h | 2 ++ 2 files changed, 46 insertions(+), 8 deletions(-)
Signature · 1 line
2.8.3
Joe Konno
PATCH 1/2 intel_cpus: frequency: clarify average clock speed
From: Joe Konno <joe.konno(a)intel.com>
Depending on the sample time (-t sample_time_in_secs), on Intel CPUs the average frequency is computed for the sample time. Therefore, let's change the label to "Average" so as not to confuse the end-user.
Previously, the UI and report printed the "actual" frequency-- at least, that's how it was labeled. This is not strictly true, as the actual cpu frequency of the platform may change at any point during the sample time for a variety of reasons.
--- src/cpu/intel_cpus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/cpu/intel_cpus.cpp +1 -1
@@ -573,7 +573,7 @@ void nhm_cpu::measurement_end(void) char * nhm_cpu::fill_pstate_name(int line_nr, char *buffer) { if (line_nr == LEVEL_C0) { - sprintf(buffer, _("Actual")); + sprintf(buffer, _("Average")); return buffer; } return cpu_linux::fill_pstate_name(line_nr, buffer);
Signature · 1 line
2.8.3
Joe Konno
PATCH 2/2 intel_cpus: no pstate Idle pct with intel_pstate
In reply to Joe KonnoFrom: Joe Konno <joe.konno(a)intel.com>
Do not display "percent Idle" in the Frequency Stats tab when the intel_pstate kernel driver is loaded. This is because Idle time is inferred through kernel PM trace events, which may be insufficient for proper computation in certain scenarios. Therefore, best to display no data than potentially inaccurate data.
End-users are encouraged to use the Idle Stats tab in the UI or report to analyze their system's idle time. When the intel_pstate kernel driver is loaded, the Frequency Stats tab will only present the end-user with the average frequency of each logical core.
--- src/cpu/intel_cpus.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- src/cpu/intel_cpus.h | 2 ++ 2 files changed, 45 insertions(+), 7 deletions(-)
src/cpu/intel_cpus.cpp +43 -7
@@ -70,6 +70,8 @@ static int intel_cpu_models[] = { 0 /* last entry must be zero */ }; +static int intel_pstate_driver_loaded = -1; + int is_supported_intel_cpu(int model) { int i;
@@ -81,6 +83,34 @@ int is_supported_intel_cpu(int model) return 0; } +int is_intel_pstate_driver_loaded() +{ + const string filename("/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"); + const string intel_pstate("intel_pstate"); + char line[32] = { '\0' }; + ifstream file; + + if (intel_pstate_driver_loaded > -1) + return intel_pstate_driver_loaded; + + file.open(filename, ios::in); + + if (!file) + return -1; + + file.getline(line, sizeof(line)-1); + file.close(); + + const string scaling_driver(line); + if (scaling_driver == intel_pstate) { + intel_pstate_driver_loaded = 1; + } else { + intel_pstate_driver_loaded = 0; + } + + return intel_pstate_driver_loaded; +} + static uint64_t get_msr(int cpu, uint64_t offset) { ssize_t retval;
@@ -267,10 +297,11 @@ void nhm_core::measurement_end(void) char * nhm_core::fill_pstate_line(int line_nr, char *buffer) { + const int intel_pstate = is_intel_pstate_driver_loaded(); buffer[0] = 0; unsigned int i; - if (total_stamp ==0) { + if (!intel_pstate && total_stamp ==0) { for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after; if (total_stamp == 0)
@@ -282,10 +313,11 @@ char * nhm_core::fill_pstate_line(int line_nr, char *buffer) return buffer; } - if (line_nr >= (int)pstates.size() || line_nr < 0) + if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0) return buffer; sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); + return buffer; }
@@ -342,10 +374,11 @@ nhm_package::nhm_package(int model) char * nhm_package::fill_pstate_line(int line_nr, char *buffer) { + const int intel_pstate = is_intel_pstate_driver_loaded(); buffer[0] = 0; unsigned int i; - if (total_stamp ==0) { + if (!intel_pstate && total_stamp ==0) { for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after; if (total_stamp == 0)
@@ -358,10 +391,11 @@ char * nhm_package::fill_pstate_line(int line_nr, char *buffer) return buffer; } - if (line_nr >= (int)pstates.size() || line_nr < 0) + if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0) return buffer; sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); + return buffer; }
@@ -581,7 +615,9 @@ char * nhm_cpu::fill_pstate_name(int line_nr, char *buffer) char * nhm_cpu::fill_pstate_line(int line_nr, char *buffer) { - if (total_stamp ==0) { + const int intel_pstate = is_intel_pstate_driver_loaded(); + + if (!intel_pstate && total_stamp ==0) { unsigned int i; for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after;
@@ -600,12 +636,12 @@ char * nhm_cpu::fill_pstate_line(int line_nr, char *buffer) hz_to_human(F, buffer, 1); return buffer; } - if (line_nr >= (int)pstates.size() || line_nr < 0) + if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0) return buffer; sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); - return buffer; + return buffer; }
src/cpu/intel_cpus.h +2 -0
@@ -175,4 +175,6 @@ public:int is_supported_intel_cpu (int model);int byt_has_ahci (); +int is_intel_pstate_driver_loaded (); +#endif
Signature · 1 line
2.8.3
Wang
Re: [Powertop] [PATCH 2/2] intel_cpus: no pstate Idle pct with intel_pstate
Hi Joe,
I just realized a further scenario that would be problematic with your current patch:
once I'd read from Len Brown's post to Red Hat, that enabling HWP in intel_pstate driver is considered a mistake, because enabling HWP only need to write a few msr bits, based on a few simple policies,
there's no need to load a whole intel_pstate driver to do that.
so future upstream kernel would remove that part, and HWP enabling will be put to some CPPC driver, and on HWP reinforced platform, intel_pstate driver will not be loaded at all.
So, if that happen, the is_intel_pstate_driver_loaded() will return false, and code will go to the old path, but the frequency statistics still not exist, then we got nothing.
mmm... maybe you could use 'cpufreq statistics exists or not' to branch your code,
if exist, use it; if not, calculate average freq from msrs.
there should have been such a function to check that condition.
-Wang, Xiaolong
-----Original Message-----
From: PowerTop [mailto:powertop-bounces(a)lists.01.org] On Behalf Of Joe Konno
Sent: Tuesday, June 14, 2016 12:01 AM
To: powertop(a)lists.01.org
Subject: [Powertop] [PATCH 2/2] intel_cpus: no pstate Idle pct with intel_pstate
From: Joe Konno <joe.konno(a)intel.com>
Do not display "percent Idle" in the Frequency Stats tab when the intel_pstate kernel driver is loaded. This is because Idle time is inferred through kernel PM trace events, which may be insufficient for proper computation in certain scenarios. Therefore, best to display no data than potentially inaccurate data.
End-users are encouraged to use the Idle Stats tab in the UI or report to analyze their system's idle time. When the intel_pstate kernel driver is loaded, the Frequency Stats tab will only present the end-user with the average frequency of each logical core.
--- src/cpu/intel_cpus.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- src/cpu/intel_cpus.h | 2 ++ 2 files changed, 45 insertions(+), 7 deletions(-)
src/cpu/intel_cpus.cpp +41 -5
@@ -70,6 +70,8 @@ static int intel_cpu_models[] = { 0 /* last entry must be zero */ }; +static int intel_pstate_driver_loaded = -1; + int is_supported_intel_cpu(int model) { int i;
@@ -81,6 +83,34 @@ int is_supported_intel_cpu(int model) return 0; } +int is_intel_pstate_driver_loaded() +{ + const string filename("/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"); + const string intel_pstate("intel_pstate"); + char line[32] = { '\0' }; + ifstream file; + + if (intel_pstate_driver_loaded > -1) + return intel_pstate_driver_loaded; + + file.open(filename, ios::in); + + if (!file) + return -1; + + file.getline(line, sizeof(line)-1); + file.close(); + + const string scaling_driver(line); + if (scaling_driver == intel_pstate) { + intel_pstate_driver_loaded = 1; + } else { + intel_pstate_driver_loaded = 0; + } + + return intel_pstate_driver_loaded; +} + static uint64_t get_msr(int cpu, uint64_t offset) { ssize_t retval;
@@ -267,10 +297,11 @@ void nhm_core::measurement_end(void) char * nhm_core::fill_pstate_line(int line_nr, char *buffer) { + const int intel_pstate = is_intel_pstate_driver_loaded(); buffer[0] = 0; unsigned int i; - if (total_stamp ==0) { + if (!intel_pstate && total_stamp ==0) { for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after; if (total_stamp == 0)
@@ -282,10 +313,11 @@ char * nhm_core::fill_pstate_line(int line_nr, char *buffer) return buffer; } - if (line_nr >= (int)pstates.size() || line_nr < 0) + if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0) return buffer; sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); + return buffer; }
@@ -342,10 +374,11 @@ nhm_package::nhm_package(int model) char * nhm_package::fill_pstate_line(int line_nr, char *buffer) { + const int intel_pstate = is_intel_pstate_driver_loaded(); buffer[0] = 0; unsigned int i; - if (total_stamp ==0) { + if (!intel_pstate && total_stamp ==0) { for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after; if (total_stamp == 0)
@@ -358,10 +391,11 @@ char * nhm_package::fill_pstate_line(int line_nr, char *buffer) return buffer; } - if (line_nr >= (int)pstates.size() || line_nr < 0) + if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0) return buffer; sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); + return buffer; }
@@ -581,7 +615,9 @@ char * nhm_cpu::fill_pstate_name(int line_nr, char *buffer) char * nhm_cpu::fill_pstate_line(int line_nr, char *buffer) { - if (total_stamp ==0) { + const int intel_pstate = is_intel_pstate_driver_loaded(); + + if (!intel_pstate && total_stamp ==0) { unsigned int i; for (i = 0; i < pstates.size(); i++) total_stamp += pstates[i]->time_after; @@ -600,12 +636,12 @@ char * nhm_cpu::fill_pstate_line(int line_nr, char *buffer) hz_to_human(F, buffer, 1);
return buffer;
}
- if (line_nr >= (int)pstates.size() || line_nr < 0)
+ if (intel_pstate > 0 || line_nr >= (int)pstates.size() || line_nr < 0)
return buffer;
sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp));
- return buffer;
+ return buffer;
}
src/cpu/intel_cpus.h +2 -0
@@ -175,4 +175,6 @@ public:int is_supported_intel_cpu (int model);int byt_has_ahci (); +int is_intel_pstate_driver_loaded (); +#endif
--
2.8.3
_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
Joe Konno
Re: [Powertop] [PATCH 2/2] intel_cpus: no pstate Idle pct with intel_pstate
Quoted 10 lines · Xiaolong
Hi Joe,
I just realized a further scenario that would be problematic with your current patch:
once I'd read from Len Brown's post to Red Hat, that enabling HWP inintel_pstatedriver is considered a mistake, because enabling HWP only need to write a few msr bits, based on a few simple policies,
there's no need to load a wholeintel_pstatedriver to do that.
so future upstream kernel would remove that part, and HWP enabling will be put to some CPPC driver, and on HWP reinforced platform,intel_pstatedriver will not be loaded at all.So, if that happen, the
is_intel_pstate_driver_loaded()will return false, and code will go to the old path, but the frequency statistics still not exist, then we got nothing.
Good catch, thanks!
Quoted 3 lines
mmm... maybe you could use 'cpufreq statistics exists or not' to branch your code,
if exist, use it; if not, calculate average freq from msrs.
there should have been such a function to check that condition.
My thoughts exactly. I'll see about submitting a new revision of this series.
Joe Konno
Re: [Powertop] [PATCH 2/2] intel_cpus: no pstate Idle pct with intel_pstate
Quoted 9 lines · Joe Konno
Quoted 8 lines · Xiaolong
Hi Joe,
I just realized a further scenario that would be problematic with your current patch:
once I'd read from Len Brown's post to Red Hat, that enabling HWP inintel_pstatedriver is considered a mistake, because enabling HWP only need to write a few msr bits, based on a few simple policies,
there's no need to load a wholeintel_pstatedriver to do that.
so future upstream kernel would remove that part, and HWP enabling will be put to some CPPC driver, and on HWP reinforced platform,intel_pstatedriver will not be loaded at all.
Quoted 8 lines
Quoted 2 lines
So, if that happen, the
is_intel_pstate_driver_loaded()will return false, and code will go to the old path, but the frequency statistics still not exist, then we got nothing.Good catch, thanks!
Quoted 3 lines
mmm... maybe you could use 'cpufreq statistics exists or not' to branch your code,
if exist, use it; if not, calculate average freq from msrs.
there should have been such a function to check that condition.
The check is duplicated in no less than four places-- there is no standalone utility function to perform the check. I'll address that duplication in my next revision by re-factoring the check into a proper function to ease re-use and maintenance.
Quoted 3 lines
My thoughts exactly. I'll see about submitting a new revision of this series.