Code deduplication and a single i965 P-states accounting bugfix in cpu/*
Ivan Shapovalov
cover Code deduplication and a single i965 P-states accounting bugfix in cpu/*
This is a series of refactor (well, mainly deduplication) of cpu/* code followed with a single bugfix patch.
The bugfix itself may be applied even without applying refactoring, but then the same change shall be applied to all copies of calculate_freq().
So the whole purpose of the series is to
1) mercilessly purge those method overrides which are identical to the methods in base classes, and
2) prefer defining a helper function and overriding it rather than copy-pasting the whole big function whose behavior needs to be altered and changing one-two lines in it.
Ivan Shapovalov (11):
Fix includes: do not include intel_cpus.h inside cpu.h
Deduplication: move is_turbo() function to lib
Deduplication: move all instances of account_freq() to
abstract_cpu::account_freq()
Deduplication: remove nhm_cpu::account_freq() almost identical to
abstract_cpu::account_freq()
Deduplication: remove
nhm_{cpu,core,package}::change_effective_frequency() identical to cpu_{linux,core,package}::change_effective_frequency()
Deduplication: merge
cpu_{core,linux,package}::change_effective_frequency() into abstract_cpu::change_effective_frequency()
Deduplication: remove {cpu,nhm}_core::calculate_freq() identical to
abstract_cpu::calculate_freq()
Deduplication: remove nhm_package::calculate_freq() identical to
cpu_package::calculate_freq()
Deduplication: properly merge cpu_package::calculate_freq() into
abstract_cpu::calculate_freq()
Deduplication: merge go_idle()/go_unidle()/change_freq() overrides
into abstract_cpu() class
Ignore non-P-state-enabled CPUs when calculating frequency.
src/cpu/abstract_cpu.cpp | 69 ++++++++++-- src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 29 ++---- src/cpu/cpu_core.cpp | 97 ----------------- src/cpu/cpu_linux.cpp | 98 ------------------ src/cpu/cpu_package.cpp | 102 ++---------------- src/cpu/intel_cpus.cpp | 265 +---------------------------------------------- src/cpu/intel_cpus.h | 23 +--- src/cpu/intel_gpu.cpp | 2 +- src/lib.cpp | 9 ++ src/lib.h | 1 + 11 files changed, 94 insertions(+), 602 deletions(-)
--
1.8.0
Ivan Shapovalov
RFC PATCH 1/11 Fix includes: do not include intel_cpus.h inside cpu.h
The file "cpu.h" is generic (unlike "intel_cpus.h"), so the existing order seems illogical. Also it broke KDevelop's code completion.
--- src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 2 -- src/cpu/intel_cpus.cpp | 2 +- src/cpu/intel_cpus.h | 2 ++ src/cpu/intel_gpu.cpp | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-)
src/cpu/cpu.cpp +1 -0
@@ -31,6 +31,7 @@ #include <unistd.h> #include "cpu.h" #include "cpudevice.h" +#include "intel_cpus.h" #include "../parameters/parameters.h" #include "../perf/perf_bundle.h"
src/cpu/cpu.h +0 -2
@@ -210,8 +210,6 @@ public: }; -#include "intel_cpus.h" -extern void enumerate_cpus (void );extern void report_display_cpu_pstates (void );
src/cpu/intel_cpus.cpp +1 -1
@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h" #include <iostream> #include <fstream> #include <stdlib.h>
src/cpu/intel_cpus.h +2 -0
@@ -25,6 +25,8 @@#include <stdint.h> #include <sys/time.h> +#include "cpu.h" +#define MSR_TSC 0x10#define MSR_NEHALEM_PLATFORM_INFO 0xCE
src/cpu/intel_gpu.cpp +1 -1
@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h" #include <iostream> #include <fstream> #include <stdlib.h>
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 2/11 Deduplication: move is_turbo() function to lib
In reply to Ivan ShapovalovTrivial: remove 4 identical static definitions of is_turbo().
--- src/cpu/cpu_core.cpp | 9 --------- src/cpu/cpu_linux.cpp | 9 --------- src/cpu/cpu_package.cpp | 10 ---------- src/cpu/intel_cpus.cpp | 8 -------- src/lib.cpp | 9 +++++++++ src/lib.h | 1 + 6 files changed, 10 insertions(+), 36 deletions(-)
src/cpu/cpu_core.cpp +0 -9
@@ -28,15 +28,6 @@ #include "../parameters/parameters.h" -static int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo) -{ - if (freq != max) - return 0; - if (maxmo + 1000 != max) - return 0; - return 1; -} - char * cpu_core::fill_cstate_line(int line_nr, char *buffer, const char *separator) { unsigned int i;
src/cpu/cpu_linux.cpp +0 -9
@@ -38,15 +38,6 @@ #include <sys/stat.h> #include <dirent.h> -static int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo) -{ - if (freq != max) - return 0; - if (maxmo + 1000 != max) - return 0; - return 1; -} - void cpu_linux::measurement_start(void) { ifstream file;
src/cpu/cpu_package.cpp +0 -10
@@ -27,16 +27,6 @@ #include "../lib.h" #include "../parameters/parameters.h" -static int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo) -{ - if (freq != max) - return 0; - if (maxmo + 1000 != max) - return 0; - return 1; -} - - char * cpu_package::fill_cstate_line(int line_nr, char *buffer, const char *separator) { unsigned int i;
src/cpu/intel_cpus.cpp +0 -8
@@ -40,14 +40,6 @@ #include "../parameters/parameters.h" #include "../display.h" -static int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo) -{ - if (freq != max) - return 0; - if (maxmo + 1000 != max) - return 0; - return 1; -} int has_c2c7_res;
src/lib.cpp +9 -0
@@ -59,6 +59,15 @@ extern "C" { static int kallsyms_read = 0; +int is_turbo(uint64_t freq, uint64_t max, uint64_t maxmo) +{ + if (freq != max) + return 0; + if (maxmo + 1000 != max) + return 0; + return 1; +} + double percentage(double F) { F = F * 100.0;
src/lib.h +1 -0
@@ -38,6 +38,7 @@#define POWERTOP_VERSION "v2.1"#define POWERTOP_SHORT_VERSION "2.1" +extern int is_turbo (uint64_t freq,uint64_t max,uint64_t maxmo);extern int get_max_cpu (void );extern void set_max_cpu (int cpu);
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 3/11 Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
In reply to Ivan ShapovalovTrivial: unify identical in-class private definitions in the common base class.
The only override left is nhm_cpu::account_freq() which is almost identical but ignores the "Turbo Mode" state.
Seems like a hidden bug to me, but will remove it in a separate commit so one can revert it easily in case something goes wrong.
--- src/cpu/abstract_cpu.cpp | 39 +++++++++++++++++++++++++ src/cpu/cpu.h | 6 ++-- src/cpu/cpu_core.cpp | 39 ------------------------- src/cpu/cpu_linux.cpp | 39 ------------------------- src/cpu/cpu_package.cpp | 40 -------------------------- src/cpu/intel_cpus.cpp | 74 ------------------------------------------------ src/cpu/intel_cpus.h | 5 ---- 7 files changed, 41 insertions(+), 201 deletions(-)
src/cpu/abstract_cpu.cpp +39 -0
@@ -28,7 +28,46 @@ #include <stdio.h> #include <stdlib.h> #include "cpu.h" +#include "../lib.h" +void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) +{ + struct frequency *state = NULL; + unsigned int i; + + for (i = 0; i < pstates.size(); i++) { + if (freq == pstates[i]->freq) { + state = pstates[i]; + break; + } + } + + + if (!state) { + state = new(std::nothrow) struct frequency; + + if (!state) + return; + + memset(state, 0, sizeof(*state)); + + pstates.push_back(state); + + state->freq = freq; + hz_to_human(freq, state->human_name); + if (freq == 0) + strcpy(state->human_name, _("Idle")); + if (is_turbo(freq, max_frequency, max_minus_one_frequency)) + sprintf(state->human_name, _("Turbo Mode")); + + state->after_count = 1; + } + + + state->time_after += duration; + + +} void abstract_cpu::measurement_start(void) {
src/cpu/cpu.h +2 -4
@@ -83,6 +83,8 @@ protected:double time_factor;uint64_t max_frequency;uint64_t max_minus_one_frequency; + + virtual void account_freq(uint64_t frequency, uint64_t duration); public:uint64_t last_stamp;uint64_t total_stamp;
@@ -158,8 +160,6 @@ extern vector<class abstract_cpu *> all_cpus; class cpu_linux: public abstract_cpu { - -void account_freq (uint64_t frequency,uint64_t duration); public: virtual void measurement_start(void); virtual void measurement_end(void);
@@ -181,7 +181,6 @@ public: class cpu_core: public abstract_cpu { -void account_freq (uint64_t frequency,uint64_t duration); public: virtual char * fill_cstate_line(int line_nr, char *buffer, const char *separator=""); virtual char * fill_cstate_name(int line_nr, char *buffer);
@@ -196,7 +195,6 @@ public: class cpu_package: public abstract_cpu { -void account_freq (uint64_t frequency,uint64_t duration); public: virtual char * fill_cstate_line(int line_nr, char *buffer, const char *separator=""); virtual char * fill_cstate_name(int line_nr, char *buffer);
src/cpu/cpu_core.cpp +0 -39
@@ -72,45 +72,6 @@ char * cpu_core::fill_pstate_name(int line_nr, char *buffer) return buffer; } - -void cpu_core::account_freq(uint64_t freq, uint64_t duration) -{ - struct frequency *state = NULL; - unsigned int i; - - for (i = 0; i < pstates.size(); i++) { - if (freq == pstates[i]->freq) { - state = pstates[i]; - break; - } - } - - - if (!state) { - state = new(std::nothrow) struct frequency; - - if (!state) - return; - - memset(state, 0, sizeof(*state)); - - pstates.push_back(state); - - state->freq = freq; - hz_to_human(freq, state->human_name); - if (freq == 0) - strcpy(state->human_name, _("Idle")); - if (is_turbo(freq, max_frequency, max_minus_one_frequency)) - sprintf(state->human_name, _("Turbo Mode")); - - state->after_count = 1; - } - - - state->time_after += duration; -} - - void cpu_core::calculate_freq(uint64_t time) { uint64_t freq = 0;
src/cpu/cpu_linux.cpp +0 -39
@@ -322,45 +322,6 @@ char * cpu_linux::fill_pstate_line(int line_nr, char *buffer) -void cpu_linux::account_freq(uint64_t freq, uint64_t duration) -{ - struct frequency *state = NULL; - unsigned int i; - - - for (i = 0; i < pstates.size(); i++) { - if (freq == pstates[i]->freq) { - state = pstates[i]; - break; - } - } - - if (!state) { - state = new(std::nothrow) struct frequency; - - if (!state) - return; - - memset(state, 0, sizeof(*state)); - - pstates.push_back(state); - - state->freq = freq; - hz_to_human(freq, state->human_name); - if (freq == 0) - strcpy(state->human_name, _("Idle")); - if (is_turbo(freq, max_frequency, max_minus_one_frequency)) - sprintf(state->human_name, _("Turbo Mode")); - - state->after_count = 1; - } - - - state->time_after += duration; - - -} - void cpu_linux::change_freq(uint64_t time, int frequency) { current_frequency = frequency;
src/cpu/cpu_package.cpp +0 -40
@@ -91,46 +91,6 @@ char * cpu_package::fill_pstate_line(int line_nr, char *buffer) return buffer; } - - - -void cpu_package::account_freq(uint64_t freq, uint64_t duration) -{ - struct frequency *state = NULL; - unsigned int i; - - for (i = 0; i < pstates.size(); i++) { - if (freq == pstates[i]->freq) { - state = pstates[i]; - break; - } - } - - - if (!state) { - state = new(std::nothrow) struct frequency; - - if (!state) - return; - - memset(state, 0, sizeof(*state)); - - pstates.push_back(state); - - state->freq = freq; - hz_to_human(freq, state->human_name); - if (freq == 0) - strcpy(state->human_name, _("Idle")); - if (is_turbo(freq, max_frequency, max_minus_one_frequency)) - sprintf(state->human_name, _("Turbo Mode")); - state->after_count = 1; - } - - state->time_after += duration; - -} - - void cpu_package::calculate_freq(uint64_t time) { uint64_t freq = 0;
src/cpu/intel_cpus.cpp +0 -74
86 lines not on this page · raw message
src/cpu/intel_cpus.h +0 -5
@@ -53,9 +53,6 @@ private:uint64_t last_stamp;uint64_t total_stamp; - -void account_freq (uint64_t frequency,uint64_t duration); - public: virtual void measurement_start(void); virtual void measurement_end(void);
@@ -78,8 +75,6 @@ private:uint64_t last_stamp;uint64_t total_stamp; - -void account_freq (uint64_t frequency,uint64_t duration); public: virtual void measurement_start(void); virtual void measurement_end(void);
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 4/11 Deduplication: remove nhm_cpu::account_freq() almost identical to abstract_cpu::account_freq()
In reply to Ivan ShapovalovSee previous commit for explanation.
--- src/cpu/intel_cpus.cpp | 36 ------------------------------------ src/cpu/intel_cpus.h | 2 -- 2 files changed, 38 deletions(-)
src/cpu/intel_cpus.cpp +0 -36
@@ -528,42 +528,6 @@ int nhm_cpu::has_pstate_level(int level) return cpu_linux::has_pstate_level(level); } -void nhm_cpu::account_freq(uint64_t freq, uint64_t duration) -{ - struct frequency *state = NULL; - unsigned int i; - - - for (i = 0; i < pstates.size(); i++) { - if (freq == pstates[i]->freq) { - state = pstates[i]; - break; - } - } - - if (!state) { - state = new(std::nothrow) struct frequency; - - if (!state) - return; - - memset(state, 0, sizeof(*state)); - - pstates.push_back(state); - - state->freq = freq; - hz_to_human(freq, state->human_name); - if (freq == 0) - strcpy(state->human_name, _("Idle")); - state->after_count = 1; - } - - - state->time_after += duration; - - -} - void nhm_cpu::change_freq(uint64_t time, int frequency) { current_frequency = frequency;
src/cpu/intel_cpus.h +0 -2
@@ -98,8 +98,6 @@ private:uint64_t last_stamp;uint64_t total_stamp; - -void account_freq (uint64_t frequency,uint64_t duration); public: virtual void measurement_start(void); virtual void measurement_end(void);
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 5/11 Deduplication: remove nhm_{cpu, core, package}::change_effective_frequency() identical to cpu_{linux, core, package}::change_effective_frequency()
In reply to Ivan ShapovalovTrivial: remove identical overrides wrt. direct base classes.
--- src/cpu/intel_cpus.cpp | 64 -------------------------------------------------- src/cpu/intel_cpus.h | 4 ---- 2 files changed, 68 deletions(-)
src/cpu/intel_cpus.cpp +0 -64
@@ -211,29 +211,6 @@ void nhm_core::calculate_freq(uint64_t time) old_idle = idle; } -void nhm_core::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t freq = 0; - uint64_t time_delta, fr; - - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = freq; - last_stamp = time; - abstract_cpu::change_effective_frequency(time, frequency); -} - char * nhm_core::fill_pstate_line(int line_nr, char *buffer) { buffer[0] = 0;
@@ -396,28 +373,6 @@ void nhm_package::calculate_freq(uint64_t time) old_idle = idle; } -void nhm_package::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t time_delta, fr; - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = frequency; - last_stamp = time; - - abstract_cpu::change_effective_frequency(time, frequency); -} - - void nhm_cpu::measurement_start(void) { ifstream file;
@@ -537,25 +492,6 @@ void nhm_cpu::change_freq(uint64_t time, int frequency) old_idle = idle; } -void nhm_cpu::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t time_delta, fr; - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = frequency; - last_stamp = time; -} - void nhm_cpu::go_idle(uint64_t time) {
src/cpu/intel_cpus.h +0 -4
@@ -61,7 +61,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual void calculate_freq(uint64_t time); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); };
@@ -83,8 +82,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual void calculate_freq(uint64_t time); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); - }; class nhm_cpu: public cpu_linux
@@ -108,7 +105,6 @@ public: virtual int has_pstate_level(int level); virtual void change_freq(uint64_t time, int freq); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); virtual void go_idle(uint64_t time); virtual void go_unidle(uint64_t time);
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 6/11 Deduplication: merge cpu_{core, linux, package}::change_effective_frequency() into abstract_cpu::change_effective_frequency()
In reply to Ivan ShapovalovThe mentioned overrides differ only in assigning 0 to effective_frequency prior to calling abstract_cpu::change_effective_frequency(), which reassigns real frequency to the same field.
Moreover, the field value is never used between assignments.
So it shall be safe to merge these overrides into the base definition as shown:
* immediately assign real frequency to field effective_frequency;
* remove post-assignment to the same field.
--- src/cpu/abstract_cpu.cpp | 17 +++++++++++++++-- src/cpu/cpu.h | 4 ---- src/cpu/cpu_core.cpp | 23 ----------------------- src/cpu/cpu_linux.cpp | 19 ------------------- src/cpu/cpu_package.cpp | 20 -------------------- 5 files changed, 15 insertions(+), 68 deletions(-)
src/cpu/abstract_cpu.cpp +15 -2
@@ -393,14 +393,27 @@ void abstract_cpu::calculate_freq(uint64_t time) void abstract_cpu::change_effective_frequency(uint64_t time, uint64_t frequency) { unsigned int i; + uint64_t time_delta, fr; + + if (last_stamp) + time_delta = time - last_stamp; + else + time_delta = 1; + + fr = effective_frequency; + if (old_idle) + fr = 0; + + account_freq(fr, time_delta); + + effective_frequency = frequency; + last_stamp = time; /* propagate to all children */ for (i = 0; i < children.size(); i++) if (children[i]) { children[i]->change_effective_frequency(time, frequency); } - - effective_frequency = frequency; }
src/cpu/cpu.h +0 -4
@@ -173,7 +173,6 @@ public: virtual char * fill_pstate_name(int line_nr, char *buffer); virtual void change_freq(uint64_t time, int freq); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); virtual void go_idle(uint64_t time); virtual void go_unidle(uint64_t time);
@@ -190,7 +189,6 @@ public: virtual int can_collapse(void) { return childcount == 1;}; virtual void calculate_freq(uint64_t time); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); }; class cpu_package: public abstract_cpu
@@ -204,8 +202,6 @@ public: virtual int can_collapse(void) { return childcount == 1;}; virtual void calculate_freq(uint64_t time); - virtual void change_effective_frequency(uint64_t time, uint64_t freq); - };extern void enumerate_cpus (void );
src/cpu/cpu_core.cpp +0 -23
@@ -98,29 +98,6 @@ void cpu_core::calculate_freq(uint64_t time) old_idle = idle; } -void cpu_core::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t freq = 0; - uint64_t time_delta, fr; - - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = freq; - last_stamp = time; - abstract_cpu::change_effective_frequency(time, frequency); -} - char * cpu_core::fill_pstate_line(int line_nr, char *buffer) { buffer[0] = 0;
src/cpu/cpu_linux.cpp +0 -19
@@ -331,25 +331,6 @@ void cpu_linux::change_freq(uint64_t time, int frequency) old_idle = idle; } -void cpu_linux::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t time_delta, fr; - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = frequency; - last_stamp = time; -} - void cpu_linux::go_idle(uint64_t time) {
src/cpu/cpu_package.cpp +0 -20
@@ -117,23 +117,3 @@ void cpu_package::calculate_freq(uint64_t time) old_idle = idle; } -void cpu_package::change_effective_frequency(uint64_t time, uint64_t frequency) -{ - uint64_t time_delta, fr; - - if (last_stamp) - time_delta = time - last_stamp; - else - time_delta = 1; - - fr = effective_frequency; - if (old_idle) - fr = 0; - - account_freq(fr, time_delta); - - effective_frequency = frequency; - last_stamp = time; - - abstract_cpu::change_effective_frequency(time, frequency); -}
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 7/11 Deduplication: remove {cpu, nhm}_core::calculate_freq() identical to abstract_cpu::calculate_freq()
In reply to Ivan ShapovalovTrivial: remove identical overrides wrt. direct base class.
--- src/cpu/cpu.h | 1 - src/cpu/cpu_core.cpp | 26 -------------------------- src/cpu/intel_cpus.cpp | 26 -------------------------- src/cpu/intel_cpus.h | 2 -- 4 files changed, 55 deletions(-)
src/cpu/cpu.h +0 -1
@@ -188,7 +188,6 @@ public: virtual char * fill_pstate_name(int line_nr, char *buffer); virtual int can_collapse(void) { return childcount == 1;}; - virtual void calculate_freq(uint64_t time); }; class cpu_package: public abstract_cpu
src/cpu/cpu_core.cpp +0 -26
@@ -72,32 +72,6 @@ char * cpu_core::fill_pstate_name(int line_nr, char *buffer) return buffer; } -void cpu_core::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - char * cpu_core::fill_pstate_line(int line_nr, char *buffer) { buffer[0] = 0;
src/cpu/intel_cpus.cpp +0 -26
@@ -185,32 +185,6 @@ void nhm_core::measurement_end(void) total_stamp = 0; } -void nhm_core::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - char * nhm_core::fill_pstate_line(int line_nr, char *buffer) { buffer[0] = 0;
src/cpu/intel_cpus.h +0 -2
@@ -80,8 +80,6 @@ public: virtual int can_collapse(void) { return 0;}; virtual char * fill_pstate_line(int line_nr, char *buffer); - - virtual void calculate_freq(uint64_t time); }; class nhm_cpu: public cpu_linux
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 8/11 Deduplication: remove nhm_package::calculate_freq() identical to cpu_package::calculate_freq()
In reply to Ivan ShapovalovTrivial - remove an identical override wrt. direct base class.
--- src/cpu/intel_cpus.cpp | 27 --------------------------- src/cpu/intel_cpus.h | 3 --- 2 files changed, 30 deletions(-)
src/cpu/intel_cpus.cpp +0 -27
@@ -320,33 +320,6 @@ void nhm_package::measurement_end(void) } - -void nhm_package::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - change_effective_frequency(time, current_frequency); - old_idle = idle; -} - void nhm_cpu::measurement_start(void) { ifstream file;
src/cpu/intel_cpus.h +0 -3
@@ -59,9 +59,6 @@ public: virtual int can_collapse(void) { return 0;}; virtual char * fill_pstate_line(int line_nr, char *buffer); - - virtual void calculate_freq(uint64_t time); - }; class nhm_core: public cpu_core
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 9/11 Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()
In reply to Ivan ShapovalovThe overridden method "cpu_package::calculate_freq()" differs from a generic implementation in that it propagates the package's frequency to all in-package cores by
calling change_effective_frequency().
Instead of duplicating the code, introduce a small virtual function freq_updated() which normally propagates frequency changes upwards and override it for cpu_package, retaining the correct behavior. Then remove the override of calculate_freq().
--- src/cpu/abstract_cpu.cpp | 11 ++++++++--- src/cpu/cpu.h | 5 +++-- src/cpu/cpu_package.cpp | 38 +++++++++++--------------------------- 3 files changed, 22 insertions(+), 32 deletions(-)
src/cpu/abstract_cpu.cpp +8 -3
@@ -69,6 +69,13 @@ void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) } +void abstract_cpu::freq_updated(uint64_t time) +{ + if(parent) + parent->calculate_freq(time); + old_idle = idle; +} + void abstract_cpu::measurement_start(void) { unsigned int i;
@@ -385,9 +392,7 @@ void abstract_cpu::calculate_freq(uint64_t time) current_frequency = freq; idle = is_idle; - if (parent) - parent->calculate_freq(time); - old_idle = idle; + freq_updated(time); } void abstract_cpu::change_effective_frequency(uint64_t time, uint64_t frequency)
src/cpu/cpu.h +3 -2
@@ -85,6 +85,7 @@ protected:uint64_t max_minus_one_frequency; virtual void account_freq(uint64_t frequency, uint64_t duration); + virtual void freq_updated(uint64_t time); public:uint64_t last_stamp;uint64_t total_stamp;
@@ -192,6 +193,8 @@ public: class cpu_package: public abstract_cpu { +protected: + virtual void freq_updated(uint64_t time); public: virtual char * fill_cstate_line(int line_nr, char *buffer, const char *separator=""); virtual char * fill_cstate_name(int line_nr, char *buffer);
@@ -199,8 +202,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual char * fill_pstate_name(int line_nr, char *buffer); virtual int can_collapse(void) { return childcount == 1;}; - - virtual void calculate_freq(uint64_t time); };extern void enumerate_cpus (void );
src/cpu/cpu_package.cpp +11 -27
@@ -27,6 +27,17 @@ #include "../lib.h" #include "../parameters/parameters.h" +void cpu_package::freq_updated(uint64_t time) +{ + if (parent) + parent->calculate_freq(time); + /* + * Make the frequency changes to propagate to all cores in a package. + */ + change_effective_frequency(time, current_frequency); + old_idle = idle; +} + char * cpu_package::fill_cstate_line(int line_nr, char *buffer, const char *separator) { unsigned int i;
@@ -90,30 +101,3 @@ char * cpu_package::fill_pstate_line(int line_nr, char *buffer) sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); return buffer; } - -void cpu_package::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - change_effective_frequency(time, current_frequency); - old_idle = idle; -} -
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 10/11 Deduplication: merge go_idle()/go_unidle()/change_freq() overrides into abstract_cpu() class
In reply to Ivan ShapovalovWhen merging, also (while at it) use the new freq_updated() method in these functions.
--- src/cpu/cpu.h | 11 +++-------- src/cpu/cpu_linux.cpp | 31 ------------------------------- src/cpu/intel_cpus.cpp | 28 ---------------------------- src/cpu/intel_cpus.h | 5 ----- 4 files changed, 3 insertions(+), 72 deletions(-)
src/cpu/cpu.h +3 -8
@@ -143,9 +143,9 @@ public:/* Frequency micro accounting methods */ virtual void calculate_freq(uint64_t time); - virtual void go_idle(uint64_t time) { idle = true; if (parent) parent->calculate_freq(time);}; - virtual void go_unidle(uint64_t time) { idle = false; if (parent) parent->calculate_freq(time);};; - virtual void change_freq(uint64_t time, int freq) { current_frequency = freq; if (parent) parent->calculate_freq(time);}; + virtual void go_idle(uint64_t time) { idle = true; freq_updated(time); } + virtual void go_unidle(uint64_t time) { idle = false; freq_updated(time); } + virtual void change_freq(uint64_t time, int freq) { current_frequency = freq; freq_updated(time); } virtual void change_effective_frequency(uint64_t time, uint64_t freq);
@@ -172,11 +172,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual char * fill_pstate_name(int line_nr, char *buffer); - - virtual void change_freq(uint64_t time, int freq); - virtual void go_idle(uint64_t time); - virtual void go_unidle(uint64_t time); - }; class cpu_core: public abstract_cpu
src/cpu/cpu_linux.cpp +0 -31
@@ -318,34 +318,3 @@ char * cpu_linux::fill_pstate_line(int line_nr, char *buffer) sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); return buffer; } - - - - -void cpu_linux::change_freq(uint64_t time, int frequency) -{ - current_frequency = frequency; - - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - -void cpu_linux::go_idle(uint64_t time) -{ - - idle = true; - - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - - -void cpu_linux::go_unidle(uint64_t time) -{ - idle = false; - if (parent) - parent->calculate_freq(time); - old_idle = idle; -}
src/cpu/intel_cpus.cpp +0 -28
@@ -429,31 +429,3 @@ int nhm_cpu::has_pstate_level(int level) return 1; return cpu_linux::has_pstate_level(level); } - -void nhm_cpu::change_freq(uint64_t time, int frequency) -{ - current_frequency = frequency; - - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - -void nhm_cpu::go_idle(uint64_t time) -{ - - idle = true; - - if (parent) - parent->calculate_freq(time); - old_idle = idle; -} - - -void nhm_cpu::go_unidle(uint64_t time) -{ - idle = false; - if (parent) - parent->calculate_freq(time); - old_idle = idle; -}
src/cpu/intel_cpus.h +0 -5
@@ -98,11 +98,6 @@ public: virtual char * fill_pstate_name(int line_nr, char *buffer); virtual char * fill_pstate_line(int line_nr, char *buffer); virtual int has_pstate_level(int level); - - virtual void change_freq(uint64_t time, int freq); - virtual void go_idle(uint64_t time); - virtual void go_unidle(uint64_t time); - }; class atom_package: public cpu_package
Signature · 1 line
1.8.0
Ivan Shapovalov
RFC PATCH 11/11 Ignore non-P-state-enabled CPUs when calculating frequency.
In reply to Ivan ShapovalovThis fixes bogus reported CPU frequencies (actually, uninitialized values from i965_core) when i965 monitoring is used.
--- src/cpu/abstract_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/cpu/abstract_cpu.cpp +1 -1
@@ -380,7 +380,7 @@ void abstract_cpu::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;
Signature · 1 line
1.8.0
Sergey Senozhatsky
Re: [Powertop] [RFC] [PATCH 01/11] Fix includes: do not include intel_cpus.h inside cpu.h
In reply to Ivan ShapovalovQuoted 7 lines · Ivan Shapovalov
The file "
cpu.h" is generic (unlike "intel_cpus.h"), so the existing order seems illogical.Also it broke KDevelop's code completion.
just a side note. no offense, but are you gonna fix every product kdevelop fails to parse instead of fixing just kdevelop?
-ss
Quoted 81 lines
Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>--- src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 2 -- src/cpu/intel_cpus.cpp | 2 +- src/cpu/intel_cpus.h | 2 ++ src/cpu/intel_gpu.cpp | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-)src/cpu/cpu.cpp +1
-0@@ -31,6 +31,7 @@ #include <unistd.h> #include "cpu.h" #include "cpudevice.h" +#include "intel_cpus.h" #include "../parameters/parameters.h" #include "../perf/perf_bundle.h"src/cpu/cpu.h +0
-2@@ -210,8 +210,6 @@ public: }; -#include "intel_cpus.h" -extern void enumerate_cpus (void );extern void report_display_cpu_pstates (void );src/cpu/intel_cpus.cpp +1
-1@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h" #include <iostream> #include <fstream> #include <stdlib.h>src/cpu/intel_cpus.h +2
-0@@ -25,6 +25,8 @@#include <stdint.h> #include <sys/time.h> +#include "cpu.h" +#define MSR_TSC 0x10#define MSR_NEHALEM_PLATFORM_INFO 0xCEsrc/cpu/intel_gpu.cpp +1
-1@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h" #include <iostream> #include <fstream> #include <stdlib.h>Signature · 6 lines
1.8.0 _______________________________________________ PowerTop mailing list PowerTop(a)lists.01.org https://lists.01.org/mailman/listinfo/powertop
Ivan Shapovalov
Re: [Powertop] [RFC] [PATCH 01/11] Fix includes: do not include intel_cpus.h inside cpu.h
Quoted 8 lines · On 05 Nov 2012 14:16:25 Sergey Senozhatsky wrote:
Quoted 4 lines · Ivan Shapovalov
The file "
cpu.h" is generic (unlike "intel_cpus.h"), so the existing order seems illogical.Also it broke KDevelop's code completion.
just a side note. no offense, but are you gonna fix every product kdevelop fails to parse instead of fixing just kdevelop?
It's a big architectural WIP there (on kdevelop).
- Ivan
Quoted 93 lines
-ssQuoted 89 lines
Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>---
src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 2 -- src/cpu/intel_cpus.cpp | 2 +- src/cpu/intel_cpus.h | 2 ++ src/cpu/intel_gpu.cpp | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-)src/cpu/cpu.cpp +1
-0@@ -31,6 +31,7 @@ #include <unistd.h> #include "cpu.h" #include "cpudevice.h" +#include "intel_cpus.h"#include "
../parameters/parameters.h"#include "
../perf/perf_bundle.h"src/cpu/cpu.h +0
-2@@ -210,8 +210,6 @@ public: }; -#include "intel_cpus.h" -extern void enumerate_cpus (void );extern void report_display_cpu_pstates (void );src/cpu/intel_cpus.cpp +1
-1@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h"#include <iostream>
#include <fstream>
#include <stdlib.h>src/cpu/intel_cpus.h +2
-0@@ -25,6 +25,8 @@#include <stdint.h> #include <sys/time.h> +#include "cpu.h" +#define MSR_TSC 0x10#define
MSR_NEHALEM_PLATFORM_INFO0xCEsrc/cpu/intel_gpu.cpp +1
-1@@ -22,7 +22,7 @@ * Authors: * Arjan van de Ven <arjan(a)linux.intel.com> */ -#include "cpu.h" +#include "intel_cpus.h"#include <iostream>
#include <fstream>
#include <stdlib.h>
Sergey Senozhatsky
Quoted 3 lines · Ivan Shapovalov
This is a series of refactor (well, mainly deduplication) of cpu/* code followed with a single bugfix patch.
thanks for patches, we'll review. code is frozen for a release, so it'll take some time.
-ss
Quoted 53 lines
The bugfix itself may be applied even without applying refactoring, but then the same change shall be applied to all copies of
calculate_freq().So the whole purpose of the series is to
1) mercilessly purge those method overrides which are identical to the methods in base classes, and
2) prefer defining a helper function and overriding it rather than copy-pasting the whole big function whose behavior needs to be altered and changing one-two lines in it.Ivan Shapovalov (11):
Fix includes: do not includeintel_cpus.hinsidecpu.h
Deduplication: moveis_turbo()function to lib
Deduplication: move all instances ofaccount_freq()to
abstract_cpu::account_freq()
Deduplication: removenhm_cpu::account_freq()almost identical to
abstract_cpu::account_freq()
Deduplication: remove
nhm_{cpu,core,package}::change_effective_frequency() identical to cpu_{linux,core,package}::change_effective_frequency()
Deduplication: merge
cpu_{core,linux,package}::change_effective_frequency() intoabstract_cpu::change_effective_frequency()
Deduplication: remove {cpu,nhm}_core::calculate_freq() identical to
abstract_cpu::calculate_freq()
Deduplication: removenhm_package::calculate_freq()identical to
cpu_package::calculate_freq()
Deduplication: properly mergecpu_package::calculate_freq()into
abstract_cpu::calculate_freq()
Deduplication: merge go_idle()/go_unidle()/change_freq() overrides
intoabstract_cpu()class
Ignore non-P-state-enabled CPUs when calculating frequency.src/cpu/abstract_cpu.cpp | 69 ++++++++++-- src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 29 ++---- src/cpu/cpu_core.cpp | 97 ----------------- src/cpu/cpu_linux.cpp | 98 ------------------ src/cpu/cpu_package.cpp | 102 ++---------------- src/cpu/intel_cpus.cpp | 265 +---------------------------------------------- src/cpu/intel_cpus.h | 23 +--- src/cpu/intel_gpu.cpp | 2 +- src/lib.cpp | 9 ++ src/lib.h | 1 + 11 files changed, 94 insertions(+), 602 deletions(-)--
1.8.0_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
Ivan Shapovalov
Quoted 6 lines · On 05 ноября 2012 14:30:37 Sergey Senozhatsky wrote:
Quoted 2 lines · Ivan Shapovalov
This is a series of refactor (well, mainly deduplication) of cpu/* code followed with a single bugfix patch.
thanks for patches, we'll review. code is frozen for a release, so it'll take some time.
Ok, thanks.
FYI: the last patch in series is a bugfix, so it probably shall go into the upcoming release independently of refactoring..
- Ivan
Quoted 76 lines
-ssQuoted 73 lines
The bugfix itself may be applied even without applying refactoring, but then the same change shall be applied to all copies of
calculate_freq().So the whole purpose of the series is to
1) mercilessly purge those method overrides which are identical to the methods in base>
classes, and2) prefer defining a helper function and overriding it rather than copy-pasting>
the whole big function whose behavior needs to be altered and changing one-two lines in it.>
Ivan Shapovalov (11):
Fix includes: do not includeintel_cpus.hinsidecpu.h
Deduplication: moveis_turbo()function to lib
Deduplication: move all instances ofaccount_freq()to
abstract_cpu::account_freq()Deduplication: remove
nhm_cpu::account_freq()almost identical to
abstract_cpu::account_freq()Deduplication: remove
nhm_{cpu,core,package}::change_effective_frequency() identical to cpu_{linux,core,package}::change_effective_frequency()
Deduplication: merge
cpu_{core,linux,package}::change_effective_frequency() into
abstract_cpu::change_effective_frequency()Deduplication: remove {cpu,nhm}_core::calculate_freq() identical to
abstract_cpu::calculate_freq()Deduplication: remove
nhm_package::calculate_freq()identical to
cpu_package::calculate_freq()Deduplication: properly merge
cpu_package::calculate_freq()into
abstract_cpu::calculate_freq()Deduplication: merge go_idle()/go_unidle()/change_freq() overrides
into
abstract_cpu()classIgnore non-P-state-enabled CPUs when calculating frequency.
src/cpu/abstract_cpu.cpp | 69 ++++++++++-- src/cpu/cpu.cpp | 1 + src/cpu/cpu.h | 29 ++---- src/cpu/cpu_core.cpp | 97 ----------------- src/cpu/cpu_linux.cpp | 98 ------------------ src/cpu/cpu_package.cpp | 102 ++---------------- src/cpu/intel_cpus.cpp | 265 +---------------------------------------------- src/cpu/intel_cpus.h | 23 +--- src/cpu/intel_gpu.cpp | 2 +- src/lib.cpp | 9 ++ src/lib.h | 1 + 11 files changed, 94 insertions(+), 602 deletions(-)--
1.8.0_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
Signature · 2 lines
С уважением, Шаповалов Иван.
Sergey Senozhatsky
Re: [Powertop] [RFC] [PATCH 09/11] Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()
In reply to Ivan ShapovalovQuoted 22 lines · Ivan Shapovalov
The overridden method "
cpu_package::calculate_freq()" differs from a generic implementation in that it propagates the package's frequency to all in-package cores by
callingchange_effective_frequency().Instead of duplicating the code, introduce a small virtual function
freq_updated()which normally propagates frequency changes upwards and override it forcpu_package, retaining the correct behavior. Then remove the override ofcalculate_freq().Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>--- src/cpu/abstract_cpu.cpp | 11 ++++++++--- src/cpu/cpu.h | 5 +++-- src/cpu/cpu_package.cpp | 38 +++++++++++--------------------------- 3 files changed, 22 insertions(+), 32 deletions(-)src/cpu/abstract_cpu.cpp +0
-0
src/cpu/abstract_cpu.cpp void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) · line 78
Quoted 10 lines
src/cpu/abstract_cpu.cpp +7
-0@@ -69,6 +69,13 @@ void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) } +void abstract_cpu::freq_updated(uint64_t time) +{ + if(parent) + parent->calculate_freq(time); + old_idle = idle; +} +
why is this function called something_updatED?
-ss
Quoted 105 lines
src/cpu/abstract_cpu.cpp +1
-3void abstract_cpu::measurement_start(void) { unsigned int i;@@ -385,9 +392,7 @@ void abstract_cpu::calculate_freq(uint64_t time) current_frequency = freq; idle = is_idle; - if (parent) - parent->calculate_freq(time); - old_idle = idle; + freq_updated(time); } void abstract_cpu::change_effective_frequency(uint64_t time, uint64_t frequency)src/cpu/cpu.h +3
-2@@ -85,6 +85,7 @@ protected:uint64_t max_minus_one_frequency; virtual void account_freq(uint64_t frequency, uint64_t duration); + virtual void freq_updated(uint64_t time); public:uint64_t last_stamp;uint64_t total_stamp;@@ -192,6 +193,8 @@ public: class cpu_package: public abstract_cpu { +protected: + virtual void freq_updated(uint64_t time); public: virtual char * fill_cstate_line(int line_nr, char *buffer, const char *separator=""); virtual char * fill_cstate_name(int line_nr, char *buffer);@@ -199,8 +202,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual char * fill_pstate_name(int line_nr, char *buffer); virtual int can_collapse(void) { return childcount == 1;}; - - virtual void calculate_freq(uint64_t time); };extern void enumerate_cpus (void );src/cpu/cpu_package.cpp +11
-27@@ -27,6 +27,17 @@ #include "../lib.h" #include "../parameters/parameters.h" +void cpu_package::freq_updated(uint64_t time) +{ + if (parent) + parent->calculate_freq(time); + /* + * Make the frequency changes to propagate to all cores in a package. + */ + change_effective_frequency(time, current_frequency); + old_idle = idle; +} + char * cpu_package::fill_cstate_line(int line_nr, char *buffer, const char *separator) { unsigned int i;@@ -90,30 +101,3 @@ char * cpu_package::fill_pstate_line(int line_nr, char *buffer) sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); return buffer; } - -void cpu_package::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - change_effective_frequency(time, current_frequency); - old_idle = idle; -} -Signature · 6 lines
1.8.0 _______________________________________________ PowerTop mailing list PowerTop(a)lists.01.org https://lists.01.org/mailman/listinfo/powertop
Ivan Shapovalov
Re: [Powertop] [RFC] [PATCH 09/11] Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()
Quoted 26 lines · On 06 November 2012 23:30:19 Sergey Senozhatsky wrote:
Quoted 25 lines · Ivan Shapovalov
The overridden method "
cpu_package::calculate_freq()" differs from a generic implementation in that it propagates the package's frequency to all in-package cores by callingchange_effective_frequency().Instead of duplicating the code, introduce a small virtual function
freq_updated()which normally propagates frequency changes upwards and override it forcpu_package, retaining the correct behavior. Then remove the override ofcalculate_freq().Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>---
src/cpu/abstract_cpu.cpp | 11 ++++++++--- src/cpu/cpu.h | 5 +++-- src/cpu/cpu_package.cpp | 38 +++++++++++--------------------------- 3 files changed, 22 insertions(+), 32 deletions(-)src/cpu/abstract_cpu.cpp +0
-0@@ -69,6 +69,13 @@ void abstract_cpu::account_freq(uint64_t freq, uint64_tduration)>
}
Quoted 9 lines
src/cpu/abstract_cpu.cpp void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) · line 78
Quoted 7 lines
src/cpu/abstract_cpu.cpp +7
-0+void abstract_cpu::freq_updated(uint64_t time) +{ + if(parent) + parent->calculate_freq(time); + old_idle = idle; +} +why is this function called
something_updatED?
Because it is called after field "current_frequency" and/or field "idle" are updated by someone. The intent of the function is to propagate the local changes to the cpu node hierarchy.
- Ivan
Quoted 123 lines
-ssQuoted 119 lines
void
abstract_cpu::measurement_start(void)
{src/cpu/abstract_cpu.cpp +1
-3unsigned int i;@@ -385,9 +392,7 @@ void abstract_cpu::calculate_freq(uint64_t time) current_frequency = freq; idle = is_idle; - if (parent) - parent->calculate_freq(time); - old_idle = idle; + freq_updated(time); }void
abstract_cpu::change_effective_frequency(uint64_t time, uint64_t frequency)>src/cpu/cpu.h +1
-0@@ -85,6 +85,7 @@ protected:uint64_t max_minus_one_frequency; virtual void account_freq(uint64_t frequency, uint64_t duration); + virtual void freq_updated(uint64_t time); public:src/cpu/cpu.h +2
-0uint64_t last_stamp;uint64_t total_stamp;@@ -192,6 +193,8 @@ public: class cpu_package: public abstract_cpu { +protected: + virtual void freq_updated(uint64_t time); public: virtual char * fill_cstate_line(int line_nr, char *buffer, const charsrc/cpu/cpu.h +0
-2*separator=""); virtual char * fill_cstate_name(int line_nr, char *buffer);@@ -199,8 +202,6 @@ public: virtual char * fill_pstate_line(int line_nr, char *buffer); virtual char * fill_pstate_name(int line_nr, char *buffer); virtual int can_collapse(void) { return childcount == 1;}; - - virtual void calculate_freq(uint64_t time); };extern void
enumerate_cpus(void);src/cpu/cpu_package.cpp +11
-0@@ -27,6 +27,17 @@ #include "../lib.h" #include "../parameters/parameters.h" +void cpu_package::freq_updated(uint64_t time) +{ + if (parent) + parent->calculate_freq(time); + /* + * Make the frequency changes to propagate to all cores in a package. + */ + change_effective_frequency(time, current_frequency); + old_idle = idle; +} + char * cpu_package::fill_cstate_line(int line_nr, char *buffer, constchar *separator) {
src/cpu/cpu_package.cpp +0
-27unsigned int i;@@ -90,30 +101,3 @@ char * cpu_package::fill_pstate_line(int line_nr, char *buffer)> sprintf(buffer," %5.1f%% ", percentage(1.0* (pstates[line_nr]->time_after) / total_stamp)); return buffer; } - -void cpu_package::calculate_freq(uint64_t time) -{ - uint64_t freq = 0; - bool is_idle = true; - unsigned int i; - - /* calculate the maximum frequency of all children */ - for (i = 0; i < children.size(); i++) - if (children[i]) { - uint64_t f = 0; - if (!children[i]->idle) { - f = children[i]->current_frequency; - is_idle = false; - } - if (f > freq) - freq = f; - } - - current_frequency = freq; - idle = is_idle; - if (parent) - parent->calculate_freq(time); - change_effective_frequency(time, current_frequency); - old_idle = idle; -} -
Chris Ferron
Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.
In reply to Ivan ShapovalovQuoted 13 lines · Ivan Shapovalov
This fixes bogus reported CPU frequencies (actually, uninitialized values from
i965_core) when i965 monitoring is used.Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>--- src/cpu/abstract_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/cpu/abstract_cpu.cpp +0
-0
src/cpu/abstract_cpu.cpp void abstract_cpu::calculate_freq(uint64_t time) · line 386
Quoted 8 lines
src/cpu/abstract_cpu.cpp +1
-1@@ -380,7 +380,7 @@ void abstract_cpu::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;
This patch for the bug fix has been merged.
Thanks,
Chris
Sergey Senozhatsky
Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.
Quoted 9 lines · Chris Ferron
Quoted 8 lines · Ivan Shapovalov
This fixes bogus reported CPU frequencies (actually, uninitialized values from
i965_core) when i965 monitoring is used.Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>--- src/cpu/abstract_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
src/cpu/abstract_cpu.cpp void abstract_cpu::calculate_freq(uint64_t time) · line 385
Quoted 12 lines
src/cpu/abstract_cpu.cpp +1
-1@@ -380,7 +380,7 @@ void abstract_cpu::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;This patch for the bug fix has been merged.
Thanks,
Chris
thanks, Chris!
sorry, my bad, I somehow forgot to ask to merge this one.
the whole patch series looks interesting and I'd like to revisit it after release. thanks Ivan.
-ss
Ivan Shapovalov
Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.
In reply to Chris FerronQuoted 22 lines · On 13 November 2012 11:14:52 Chris Ferron wrote:
Quoted 21 lines · Ivan Shapovalov
This fixes bogus reported CPU frequencies (actually, uninitialized values from
i965_core) when i965 monitoring is used.Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>---
src/cpu/abstract_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/cpu/abstract_cpu.cpp +1
-1@@ -380,7 +380,7 @@ void abstract_cpu::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) {
Quoted 6 lines
Quoted 4 lines
src/cpu/abstract_cpu.cpp +0
-0uint64_t f = 0;if (!children[i]->idle) { f = children[i]->current_frequency;This patch for the bug fix has been merged.
Ugh, I forgot to notify - to make it work without previous patches, one shall rather modify {cpu,nhm}_package::calculate_freq(), so merging this patch alone and as-is doesn't do anything...
Please, consider this one for the release:
---
src/cpu/cpu_package.cpp +1 -1
@@ -149,7 +149,7 @@ void cpu_package::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;
src/cpu/intel_cpus.cpp +1 -1
@@ -460,7 +460,7 @@ void nhm_package::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;
---
Chris Ferron
Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.
Quoted 53 lines · Ivan Shapovalov
Quoted 19 lines · On 13 November 2012 11:14:52 Chris Ferron wrote:
Quoted 18 lines · Ivan Shapovalov
This fixes bogus reported CPU frequencies (actually, uninitialized values from
i965_core) when i965 monitoring is used.Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>---
src/cpu/abstract_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/cpu/abstract_cpu.cpp +0
-0@@ -380,7 +380,7 @@ void abstract_cpu::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++)Quoted 8 lines
Quoted 7 lines
src/cpu/abstract_cpu.cpp +1
-1- if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0;if (!children[i]->idle) { f = children[i]->current_frequency;This patch for the bug fix has been merged.
Ugh, I forgot to notify - to make it work without previous patches, one shall rather modify {cpu,nhm}_package::calculate_freq(), so merging this patch alone and as-is doesn't do anything...
Please, consider this one for the release:
---
src/cpu/cpu_package.cpp +1
-1@@ -149,7 +149,7 @@ void cpu_package::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency;src/cpu/intel_cpus.cpp +0
-0
src/cpu/intel_cpus.cpp void nhm_package::calculate_freq(uint64_t time)
Quoted 9 lines
src/cpu/intel_cpus.cpp +1
-2@@ -460,7 +460,7 @@ void nhm_package::calculate_freq(uint64_t time) /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) - if (children[i]) { + if (children[i] && children[i]->has_pstates()) { uint64_t f = 0; if (!children[i]->idle) { f = children[i]->current_frequency; ---
Yep, I already caught that. Thanks for the follow up.