All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
@ 2012-12-24 10:30 Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2012-12-24 10:30 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 10276 bytes --]


Hello,

On (12/24/12 03:08), Ivan Shapovalov wrote:
> 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            | 11 ++-----
>  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(+), 206 deletions(-)
> 
> diff --git a/src/cpu/abstract_cpu.cpp b/src/cpu/abstract_cpu.cpp
> index 537f3cb..5618761 100644
> --- a/src/cpu/abstract_cpu.cpp
> +++ b/src/cpu/abstract_cpu.cpp
> @@ -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)
>  {
> diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
> index 2304cd5..8b9c9f9 100644
> --- a/src/cpu/cpu.h
> +++ b/src/cpu/cpu.h
> @@ -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,13 +160,6 @@ extern vector<class abstract_cpu *> all_cpus;
>  
>  class cpu_linux: public abstract_cpu
>  {
> -
> -	void	account_freq(uint64_t frequency, uint64_t duration);
> -	void 	parse_pstates_start(void);
> -	void 	parse_cstates_start(void);
> -	void 	parse_pstates_end(void);
> -	void 	parse_cstates_end(void);
> -

I see that you've dropped states start/end parsing, but I can't see where did you land them

	-ss


>  public:
>  	virtual void	measurement_start(void);
>  	virtual void	measurement_end(void);
> @@ -186,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);
> @@ -201,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);
> diff --git a/src/cpu/cpu_core.cpp b/src/cpu/cpu_core.cpp
> index 8aba60b..8249d83 100644
> --- a/src/cpu/cpu_core.cpp
> +++ b/src/cpu/cpu_core.cpp
> @@ -77,45 +77,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;
> diff --git a/src/cpu/cpu_linux.cpp b/src/cpu/cpu_linux.cpp
> index 034263b..41a2238 100644
> --- a/src/cpu/cpu_linux.cpp
> +++ b/src/cpu/cpu_linux.cpp
> @@ -350,45 +350,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;
> diff --git a/src/cpu/cpu_package.cpp b/src/cpu/cpu_package.cpp
> index 61ce050..6794a38 100644
> --- a/src/cpu/cpu_package.cpp
> +++ b/src/cpu/cpu_package.cpp
> @@ -102,46 +102,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;
> diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
> index 640a0d5..4d52206 100644
> --- a/src/cpu/intel_cpus.cpp
> +++ b/src/cpu/intel_cpus.cpp
> @@ -185,44 +185,6 @@ void nhm_core::measurement_end(void)
>  	total_stamp = 0;
>  }
>  
> -void nhm_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 nhm_core::calculate_freq(uint64_t time)
>  {
>  	uint64_t freq = 0;
> @@ -418,42 +380,6 @@ void nhm_package::measurement_end(void)
>  
>  }
>  
> -void nhm_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 nhm_package::calculate_freq(uint64_t time)
>  {
> diff --git a/src/cpu/intel_cpus.h b/src/cpu/intel_cpus.h
> index a8bb892..181ffc4 100644
> --- a/src/cpu/intel_cpus.h
> +++ b/src/cpu/intel_cpus.h
> @@ -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);
> -- 
> 1.8.0.2
> 
> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
@ 2012-12-24 14:39 Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2012-12-24 14:39 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

On (12/24/12 17:55), Ivan Shapovalov wrote:
> On 24 December 2012 17:50:06 Ivan Shapovalov wrote:
> > <...>
> > 
> > Argh. I've misrebased the patches; wrong are 01/10 and 03/10.
> > Will resend them as v3.
> 
> Mistake on mistake... I meant 02/10 and 03/10.
> 

no problem :-)

	-ss

> > 
> > <...>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
@ 2012-12-24 13:55 Ivan Shapovalov
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Shapovalov @ 2012-12-24 13:55 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

On 24 December 2012 17:50:06 Ivan Shapovalov wrote:
> <...>
> 
> Argh. I've misrebased the patches; wrong are 01/10 and 03/10.
> Will resend them as v3.

Mistake on mistake... I meant 02/10 and 03/10.

> 
> <...>

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
@ 2012-12-24 13:50 Ivan Shapovalov
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Shapovalov @ 2012-12-24 13:50 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 11261 bytes --]

On 24 December 2012 13:30:52 Sergey Senozhatsky wrote:
> Hello,
> 
> On (12/24/12 03:08), Ivan Shapovalov wrote:
> > 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            | 11 ++-----
> >  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(+), 206 deletions(-)
> > 
> > diff --git a/src/cpu/abstract_cpu.cpp b/src/cpu/abstract_cpu.cpp
> > index 537f3cb..5618761 100644
> > --- a/src/cpu/abstract_cpu.cpp
> > +++ b/src/cpu/abstract_cpu.cpp
> > @@ -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)
> >  {
> > 
> > diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
> > index 2304cd5..8b9c9f9 100644
> > --- a/src/cpu/cpu.h
> > +++ b/src/cpu/cpu.h
> > 
> > @@ -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,13 +160,6 @@ extern vector<class abstract_cpu *> all_cpus;
> > 
> >  class cpu_linux: public abstract_cpu
> >  {
> > 
> > -
> > -	void	account_freq(uint64_t frequency, uint64_t duration);
> > -	void 	parse_pstates_start(void);
> > -	void 	parse_cstates_start(void);
> > -	void 	parse_pstates_end(void);
> > -	void 	parse_cstates_end(void);
> > -
> 
> I see that you've dropped states start/end parsing, but I can't see where
> did you land them
> 
> 	-ss

Argh. I've misrebased the patches; wrong are 01/10 and 03/10.
Will resend them as v3.

> 
> >  public:
> >  	virtual void	measurement_start(void);
> >  	virtual void	measurement_end(void);
> > 
> > @@ -186,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);
> > 
> > @@ -201,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);
> > 
> > diff --git a/src/cpu/cpu_core.cpp b/src/cpu/cpu_core.cpp
> > index 8aba60b..8249d83 100644
> > --- a/src/cpu/cpu_core.cpp
> > +++ b/src/cpu/cpu_core.cpp
> > @@ -77,45 +77,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;
> > 
> > diff --git a/src/cpu/cpu_linux.cpp b/src/cpu/cpu_linux.cpp
> > index 034263b..41a2238 100644
> > --- a/src/cpu/cpu_linux.cpp
> > +++ b/src/cpu/cpu_linux.cpp
> > @@ -350,45 +350,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;
> > 
> > diff --git a/src/cpu/cpu_package.cpp b/src/cpu/cpu_package.cpp
> > index 61ce050..6794a38 100644
> > --- a/src/cpu/cpu_package.cpp
> > +++ b/src/cpu/cpu_package.cpp
> > @@ -102,46 +102,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;
> > 
> > diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
> > index 640a0d5..4d52206 100644
> > --- a/src/cpu/intel_cpus.cpp
> > +++ b/src/cpu/intel_cpus.cpp
> > @@ -185,44 +185,6 @@ void nhm_core::measurement_end(void)
> > 
> >  	total_stamp = 0;
> >  
> >  }
> > 
> > -void nhm_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 nhm_core::calculate_freq(uint64_t time)
> >  {
> >  
> >  	uint64_t freq = 0;
> > 
> > @@ -418,42 +380,6 @@ void nhm_package::measurement_end(void)
> > 
> >  }
> > 
> > -void nhm_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 nhm_package::calculate_freq(uint64_t time)
> >  {
> > 
> > diff --git a/src/cpu/intel_cpus.h b/src/cpu/intel_cpus.h
> > index a8bb892..181ffc4 100644
> > --- a/src/cpu/intel_cpus.h
> > +++ b/src/cpu/intel_cpus.h
> > 
> > @@ -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);

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq()
@ 2012-12-23 23:08 Ivan Shapovalov
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Shapovalov @ 2012-12-23 23:08 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 9193 bytes --]

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            | 11 ++-----
 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(+), 206 deletions(-)

diff --git a/src/cpu/abstract_cpu.cpp b/src/cpu/abstract_cpu.cpp
index 537f3cb..5618761 100644
--- a/src/cpu/abstract_cpu.cpp
+++ b/src/cpu/abstract_cpu.cpp
@@ -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)
 {
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 2304cd5..8b9c9f9 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -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,13 +160,6 @@ extern vector<class abstract_cpu *> all_cpus;
 
 class cpu_linux: public abstract_cpu
 {
-
-	void	account_freq(uint64_t frequency, uint64_t duration);
-	void 	parse_pstates_start(void);
-	void 	parse_cstates_start(void);
-	void 	parse_pstates_end(void);
-	void 	parse_cstates_end(void);
-
 public:
 	virtual void	measurement_start(void);
 	virtual void	measurement_end(void);
@@ -186,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);
@@ -201,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);
diff --git a/src/cpu/cpu_core.cpp b/src/cpu/cpu_core.cpp
index 8aba60b..8249d83 100644
--- a/src/cpu/cpu_core.cpp
+++ b/src/cpu/cpu_core.cpp
@@ -77,45 +77,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;
diff --git a/src/cpu/cpu_linux.cpp b/src/cpu/cpu_linux.cpp
index 034263b..41a2238 100644
--- a/src/cpu/cpu_linux.cpp
+++ b/src/cpu/cpu_linux.cpp
@@ -350,45 +350,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;
diff --git a/src/cpu/cpu_package.cpp b/src/cpu/cpu_package.cpp
index 61ce050..6794a38 100644
--- a/src/cpu/cpu_package.cpp
+++ b/src/cpu/cpu_package.cpp
@@ -102,46 +102,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;
diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
index 640a0d5..4d52206 100644
--- a/src/cpu/intel_cpus.cpp
+++ b/src/cpu/intel_cpus.cpp
@@ -185,44 +185,6 @@ void nhm_core::measurement_end(void)
 	total_stamp = 0;
 }
 
-void nhm_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 nhm_core::calculate_freq(uint64_t time)
 {
 	uint64_t freq = 0;
@@ -418,42 +380,6 @@ void nhm_package::measurement_end(void)
 
 }
 
-void nhm_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 nhm_package::calculate_freq(uint64_t time)
 {
diff --git a/src/cpu/intel_cpus.h b/src/cpu/intel_cpus.h
index a8bb892..181ffc4 100644
--- a/src/cpu/intel_cpus.h
+++ b/src/cpu/intel_cpus.h
@@ -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);
-- 
1.8.0.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-12-24 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-24 10:30 [Powertop] [RFC] [PATCHv2 03/10] Deduplication: move all instances of account_freq() to abstract_cpu::account_freq() Sergey Senozhatsky
  -- strict thread matches above, loose matches on Subject: below --
2012-12-24 14:39 Sergey Senozhatsky
2012-12-24 13:55 Ivan Shapovalov
2012-12-24 13:50 Ivan Shapovalov
2012-12-23 23:08 Ivan Shapovalov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.