Skip to contentSkip to conversation

Code deduplication and a single i965 P-states accounting bugfix in cpu/*

RFC PATCH Superseded Ivan Shapovalov 3 participants 22 messages Nov 5, 2012 – Nov 14, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ivan Shapovalov

author
#0 lore raw

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

author
#1 lore raw

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.

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
index 7f3af69..3314e82 100644
@@ -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
index 4480b11..a9f258a 100644
@@ -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
index 24465a0..a5684aa 100644
@@ -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
index 1949af1..a8bb892 100644
@@ -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
index 57474f1..e0f4ac2 100644
@@ -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
#2 lore raw

Re: [Powertop] [RFC] [PATCH 01/11] Fix includes: do not include intel_cpus.h inside cpu.h

Quoted 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
index 7f3af69..3314e82 100644
@@ -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
index 4480b11..a9f258a 100644
@@ -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
index 24465a0..a5684aa 100644
@@ -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
index 1949af1..a8bb892 100644
@@ -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
index 57474f1..e0f4ac2 100644
@@ -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
author
#3 lore raw

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

	-ss
Quoted 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
index 7f3af69..3314e82 100644
@@ -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
index 4480b11..a9f258a 100644
@@ -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
index 24465a0..a5684aa 100644
@@ -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
index 1949af1..a8bb892 100644
@@ -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
index 57474f1..e0f4ac2 100644
@@ -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>

author
#4 lore raw

RFC PATCH 2/11 Deduplication: move is_turbo() function to lib

In reply to Ivan Shapovalov

Trivial: remove 4 identical static definitions of is_turbo().

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 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
index 593d5f6..f56394f 100644
@@ -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
index f5e269e..56b895c 100644
@@ -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
index 2e2e8a3..7cdbf5d 100644
@@ -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
index a5684aa..24d0398 100644
@@ -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
index 9838c0b..723517a 100644
@@ -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
index 8cf4632..9b44450 100644
@@ -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
author
#5 lore raw

RFC PATCH 3/11 Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()

In reply to Ivan Shapovalov

Trivial: 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.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 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
index c4c1e93..894a7b8 100644
@@ -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
index a9f258a..8b9c9f9 100644
@@ -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
index f56394f..93740b7 100644
@@ -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
index 56b895c..c820238 100644
@@ -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
index 7cdbf5d..d154b90 100644
@@ -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
index a8bb892..181ffc4 100644
@@ -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
author
#6 lore raw

RFC PATCH 4/11 Deduplication: remove nhm_cpu::account_freq() almost identical to abstract_cpu::account_freq()

In reply to Ivan Shapovalov

See previous commit for explanation.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 src/cpu/intel_cpus.cpp | 36 ------------------------------------
 src/cpu/intel_cpus.h   |  2 --
 2 files changed, 38 deletions(-)
src/cpu/intel_cpus.cpp +0 -36
index 2a0a874..eeeb8c9 100644
@@ -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
index 181ffc4..cfa46ec 100644
@@ -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
author
#7 lore raw

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 Shapovalov

Trivial: remove identical overrides wrt. direct base classes.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 src/cpu/intel_cpus.cpp | 64 --------------------------------------------------
 src/cpu/intel_cpus.h   |  4 ----
 2 files changed, 68 deletions(-)
src/cpu/intel_cpus.cpp +0 -64
index eeeb8c9..30f2d38 100644
@@ -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
index cfa46ec..53cadab 100644
@@ -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
author
#8 lore raw

RFC PATCH 6/11 Deduplication: merge cpu_{core, linux, package}::change_effective_frequency() into abstract_cpu::change_effective_frequency()

In reply to Ivan Shapovalov

The 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.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 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
index 894a7b8..083a1e0 100644
@@ -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
index 8b9c9f9..c99d4ea 100644
@@ -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
index 93740b7..b19ca2c 100644
@@ -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
index c820238..24fbcb3 100644
@@ -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
index d154b90..0ad5bdd 100644
@@ -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
author
#9 lore raw

RFC PATCH 7/11 Deduplication: remove {cpu, nhm}_core::calculate_freq() identical to abstract_cpu::calculate_freq()

In reply to Ivan Shapovalov

Trivial: remove identical overrides wrt. direct base class.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 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
index c99d4ea..1e9d771 100644
@@ -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
index b19ca2c..03acdb1 100644
@@ -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
index 30f2d38..688e95b 100644
@@ -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
index 53cadab..f41d589 100644
@@ -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
author
#10 lore raw

RFC PATCH 8/11 Deduplication: remove nhm_package::calculate_freq() identical to cpu_package::calculate_freq()

In reply to Ivan Shapovalov

Trivial - remove an identical override wrt. direct base class.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 src/cpu/intel_cpus.cpp | 27 ---------------------------
 src/cpu/intel_cpus.h   |  3 ---
 2 files changed, 30 deletions(-)
src/cpu/intel_cpus.cpp +0 -27
index 688e95b..89eefee 100644
@@ -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
index f41d589..a4c0852 100644
@@ -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
author
#11 lore raw

RFC PATCH 9/11 Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()

In reply to 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
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().

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 +8 -3
index 083a1e0..d64cb24 100644
@@ -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
index 1e9d771..498447b 100644
@@ -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
index 0ad5bdd..277b55f 100644
@@ -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
#12 lore raw

Re: [Powertop] [RFC] [PATCH 09/11] Deduplication: properly merge cpu_package::calculate_freq() into abstract_cpu::calculate_freq()

Quoted 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
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().

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
index 083a1e0..d64cb24 100644

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 -3
 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
index 1e9d771..498447b 100644
@@ -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
index 0ad5bdd..277b55f 100644
@@ -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
author
#13 lore raw

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 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().

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
index 083a1e0..d64cb24 100644
@@ -69,6 +69,13 @@ void abstract_cpu::account_freq(uint64_t freq, uint64_t

duration)>
}

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

	-ss
Quoted 119 lines

void abstract_cpu::measurement_start(void)
{

src/cpu/abstract_cpu.cpp +1 -3
 	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 +1 -0
index 1e9d771..498447b 100644
@@ -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 -0
 	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
src/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
index 0ad5bdd..277b55f 100644
@@ -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) {

src/cpu/cpu_package.cpp +0 -27
 	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;
-}
-
author
#14 lore raw

RFC PATCH 10/11 Deduplication: merge go_idle()/go_unidle()/change_freq() overrides into abstract_cpu() class

In reply to Ivan Shapovalov

When merging, also (while at it) use the new freq_updated() method in these functions.

Signed-off-by Ivan Shapovalov <intelfx100(a)gmail.com>
---
 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
index 498447b..9c61641 100644
@@ -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
index 24fbcb3..4025880 100644
@@ -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
index 89eefee..c49102b 100644
@@ -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
index a4c0852..a125540 100644
@@ -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
author
#15 lore raw

RFC PATCH 11/11 Ignore non-P-state-enabled CPUs when calculating frequency.

In reply to 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
index d64cb24..fea377b 100644
@@ -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
#16 lore raw

Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.

Quoted 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
index d64cb24..fea377b 100644

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

#17 lore raw

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
index d64cb24..fea377b 100644
@@ -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
author
#18 lore raw

Re: [Powertop] [RFC] [PATCH 11/11] Ignore non-P-state-enabled CPUs when calculating frequency.

In reply to Chris Ferron
Quoted 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
index d64cb24..fea377b 100644
@@ -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 -0
  			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
index 2e2e8a3..4675167 100644
@@ -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
index 24465a0..a4ed86d 100644
@@ -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;

---

#19 lore raw

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
index d64cb24..fea377b 100644
@@ -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
index 2e2e8a3..4675167 100644
@@ -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
index 24465a0..a4ed86d 100644

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.

#20 lore raw
In reply to Ivan Shapovalov
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 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

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop

author
#21 lore raw
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
	-ss
Quoted 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, 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

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop

Signature · 2 lines
С уважением,
Шаповалов Иван.