linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states.
@ 2013-12-17 17:42 dirk.brandewie
  2013-12-17 17:42 ` [PATCH 2/2] intel_pstate: Remove periodic P state boost dirk.brandewie
  2013-12-18 12:37 ` [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states Bartlomiej Zolnierkiewicz
  0 siblings, 2 replies; 4+ messages in thread
From: dirk.brandewie @ 2013-12-17 17:42 UTC (permalink / raw)
  To: linux-pm; +Cc: rjw, Dirk Brandewie

From: Dirk Brandewie <dirk.j.brandewie@intel.com>

Baytrail requires setting P state and voltage pairs when adjusting the
requested P state.  Add function for retrieving the valid voltage
values and modify *_set_pstate() functions to caluclate the
appropriate voltage for the requested P state.

Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
---
 drivers/cpufreq/intel_pstate.c | 58 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 5f1cbae..4cc4534 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -35,6 +35,7 @@
 #define SAMPLE_COUNT		3
 
 #define BYT_RATIOS	0x66a
+#define BYT_VIDS        0x66b
 
 #define FRAC_BITS 8
 #define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
@@ -64,6 +65,12 @@ struct pstate_data {
 	int	turbo_pstate;
 };
 
+struct vid_data {
+	int32_t min;
+	int32_t max;
+	int32_t ratio;
+};
+
 struct _pid {
 	int setpoint;
 	int32_t integral;
@@ -82,6 +89,7 @@ struct cpudata {
 	struct timer_list timer;
 
 	struct pstate_data pstate;
+	struct vid_data vid;
 	struct _pid pid;
 
 	int min_pstate_count;
@@ -106,7 +114,8 @@ struct pstate_funcs {
 	int (*get_max)(void);
 	int (*get_min)(void);
 	int (*get_turbo)(void);
-	void (*set)(int pstate);
+	void (*set)(struct cpudata*, int pstate);
+	void (*get_vid)(struct cpudata *);
 };
 
 struct cpu_defaults {
@@ -358,6 +367,41 @@ static int byt_get_max_pstate(void)
 	return (value >> 16) & 0xFF;
 }
 
+static void byt_set_pstate(struct cpudata *cpudata, int pstate)
+{
+	u64 val;
+	int32_t vid_fp;
+	u32 vid;
+
+	val = pstate << 8;
+	if (limits.no_turbo)
+		val |= (u64)1 << 32;
+
+	vid_fp = mul_fp(cpudata->vid.min +
+			int_tofp(pstate - cpudata->pstate.min_pstate),
+			cpudata->vid.ratio);
+
+	vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max);
+	vid = fp_toint(vid_fp);
+
+	val |= vid;
+
+	wrmsrl(MSR_IA32_PERF_CTL, val);
+}
+
+static void byt_get_vid(struct cpudata *cpudata)
+{
+	u64 value;
+	rdmsrl(BYT_VIDS, value);
+	cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
+	cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
+	cpudata->vid.ratio = div_fp(
+		cpudata->vid.max - cpudata->vid.min,
+		int_tofp(cpudata->pstate.max_pstate - 
+			cpudata->pstate.min_pstate));
+}
+
+
 static int core_get_min_pstate(void)
 {
 	u64 value;
@@ -365,6 +409,7 @@ static int core_get_min_pstate(void)
 	return (value >> 40) & 0xFF;
 }
 
+
 static int core_get_max_pstate(void)
 {
 	u64 value;
@@ -384,7 +429,7 @@ static int core_get_turbo_pstate(void)
 	return ret;
 }
 
-static void core_set_pstate(int pstate)
+static void core_set_pstate(struct cpudata *cpudata, int pstate)
 {
 	u64 val;
 
@@ -425,7 +470,8 @@ static struct cpu_defaults byt_params = {
 		.get_max = byt_get_max_pstate,
 		.get_min = byt_get_min_pstate,
 		.get_turbo = byt_get_max_pstate,
-		.set = core_set_pstate,
+		.set = byt_set_pstate,
+		.get_vid = byt_get_vid,
 	},
 };
 
@@ -462,7 +508,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
 
 	cpu->pstate.current_pstate = pstate;
 
-	pstate_funcs.set(pstate);
+	pstate_funcs.set(cpu, pstate);
 }
 
 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
@@ -488,6 +534,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
 	cpu->pstate.max_pstate = pstate_funcs.get_max();
 	cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
 
+	if (pstate_funcs.get_vid)
+		pstate_funcs.get_vid(cpu);
+
 	/*
 	 * goto max pstate so we don't slow up boot if we are built-in if we are
 	 * a module we will take care of it during normal operation
@@ -776,6 +825,7 @@ static void copy_cpu_funcs(struct pstate_funcs *funcs)
 	pstate_funcs.get_min   = funcs->get_min;
 	pstate_funcs.get_turbo = funcs->get_turbo;
 	pstate_funcs.set       = funcs->set;
+	pstate_funcs.get_vid   = funcs->get_vid;
 }
 
 #if IS_ENABLED(CONFIG_ACPI)
-- 
1.8.3.1


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

* [PATCH 2/2] intel_pstate: Remove periodic P state boost
  2013-12-17 17:42 [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states dirk.brandewie
@ 2013-12-17 17:42 ` dirk.brandewie
  2013-12-18 12:37 ` [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states Bartlomiej Zolnierkiewicz
  1 sibling, 0 replies; 4+ messages in thread
From: dirk.brandewie @ 2013-12-17 17:42 UTC (permalink / raw)
  To: linux-pm; +Cc: rjw, Dirk Brandewie

From: Dirk Brandewie <dirk.j.brandewie@intel.com>

Remove the periodic P state boost.  This code required for some corner
case benchmark tests.  The calculation of the required P state was
incorrect/inaccurate and would not allow P state increase.

This was fixed by a combination of commits:
  2134ed4 cpufreq / intel_pstate: Change to scale off of max P-state
  d253d2a intel_pstate: Improve accuracy by not truncating until final result

Fixes Bug:
  https://bugzilla.kernel.org/show_bug.cgi?id=64271

Reported-by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
---
 drivers/cpufreq/intel_pstate.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 4cc4534..5bafccc 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -92,8 +92,6 @@ struct cpudata {
 	struct vid_data vid;
 	struct _pid pid;
 
-	int min_pstate_count;
-
 	u64	prev_aperf;
 	u64	prev_mperf;
 	int	sample_ptr;
@@ -617,15 +615,6 @@ static void intel_pstate_timer_func(unsigned long __data)
 
 	intel_pstate_sample(cpu);
 	intel_pstate_adjust_busy_pstate(cpu);
-
-	if (cpu->pstate.current_pstate == cpu->pstate.min_pstate) {
-		cpu->min_pstate_count++;
-		if (!(cpu->min_pstate_count % 5)) {
-			intel_pstate_set_pstate(cpu, cpu->pstate.max_pstate);
-		}
-	} else
-		cpu->min_pstate_count = 0;
-
 	intel_pstate_set_sample_time(cpu);
 }
 
-- 
1.8.3.1


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

* Re: [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states.
  2013-12-17 17:42 [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states dirk.brandewie
  2013-12-17 17:42 ` [PATCH 2/2] intel_pstate: Remove periodic P state boost dirk.brandewie
@ 2013-12-18 12:37 ` Bartlomiej Zolnierkiewicz
  2013-12-19  0:03   ` Dirk Brandewie
  1 sibling, 1 reply; 4+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2013-12-18 12:37 UTC (permalink / raw)
  To: dirk.brandewie; +Cc: linux-pm, rjw, Dirk Brandewie


Hi,

On Tuesday, December 17, 2013 09:42:06 AM dirk.brandewie@gmail.com wrote:
> From: Dirk Brandewie <dirk.j.brandewie@intel.com>
> 
> Baytrail requires setting P state and voltage pairs when adjusting the
> requested P state.  Add function for retrieving the valid voltage
> values and modify *_set_pstate() functions to caluclate the
> appropriate voltage for the requested P state.
> 
> Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
> ---
>  drivers/cpufreq/intel_pstate.c | 58 +++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 54 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index 5f1cbae..4cc4534 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -35,6 +35,7 @@
>  #define SAMPLE_COUNT		3
>  
>  #define BYT_RATIOS	0x66a
> +#define BYT_VIDS        0x66b
>  
>  #define FRAC_BITS 8
>  #define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
> @@ -64,6 +65,12 @@ struct pstate_data {
>  	int	turbo_pstate;
>  };
>  
> +struct vid_data {
> +	int32_t min;
> +	int32_t max;
> +	int32_t ratio;
> +};
> +
>  struct _pid {
>  	int setpoint;
>  	int32_t integral;
> @@ -82,6 +89,7 @@ struct cpudata {
>  	struct timer_list timer;
>  
>  	struct pstate_data pstate;
> +	struct vid_data vid;
>  	struct _pid pid;
>  
>  	int min_pstate_count;
> @@ -106,7 +114,8 @@ struct pstate_funcs {
>  	int (*get_max)(void);
>  	int (*get_min)(void);
>  	int (*get_turbo)(void);
> -	void (*set)(int pstate);
> +	void (*set)(struct cpudata*, int pstate);
> +	void (*get_vid)(struct cpudata *);
>  };
>  
>  struct cpu_defaults {
> @@ -358,6 +367,41 @@ static int byt_get_max_pstate(void)
>  	return (value >> 16) & 0xFF;
>  }
>  
> +static void byt_set_pstate(struct cpudata *cpudata, int pstate)
> +{
> +	u64 val;
> +	int32_t vid_fp;
> +	u32 vid;
> +
> +	val = pstate << 8;
> +	if (limits.no_turbo)
> +		val |= (u64)1 << 32;
> +
> +	vid_fp = mul_fp(cpudata->vid.min +
> +			int_tofp(pstate - cpudata->pstate.min_pstate),
> +			cpudata->vid.ratio);

Shouldn't this be:

+	vid_fp = cpudata->vid.min + mul_fp(
+			int_tofp(pstate - cpudata->pstate.min_pstate),
+			cpudata->vid.ratio);

?

> +	vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max);
> +	vid = fp_toint(vid_fp);
> +
> +	val |= vid;
> +
> +	wrmsrl(MSR_IA32_PERF_CTL, val);
> +}
> +
> +static void byt_get_vid(struct cpudata *cpudata)
> +{
> +	u64 value;

please add a newline here

> +	rdmsrl(BYT_VIDS, value);
> +	cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
> +	cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
> +	cpudata->vid.ratio = div_fp(
> +		cpudata->vid.max - cpudata->vid.min,
> +		int_tofp(cpudata->pstate.max_pstate - 
> +			cpudata->pstate.min_pstate));
> +}
> +
> +
>  static int core_get_min_pstate(void)
>  {
>  	u64 value;
> @@ -365,6 +409,7 @@ static int core_get_min_pstate(void)
>  	return (value >> 40) & 0xFF;
>  }
>  
> +

superfluous newline

>  static int core_get_max_pstate(void)
>  {
>  	u64 value;
> @@ -384,7 +429,7 @@ static int core_get_turbo_pstate(void)
>  	return ret;
>  }
>  
> -static void core_set_pstate(int pstate)
> +static void core_set_pstate(struct cpudata *cpudata, int pstate)
>  {
>  	u64 val;
>  
> @@ -425,7 +470,8 @@ static struct cpu_defaults byt_params = {
>  		.get_max = byt_get_max_pstate,
>  		.get_min = byt_get_min_pstate,
>  		.get_turbo = byt_get_max_pstate,
> -		.set = core_set_pstate,
> +		.set = byt_set_pstate,
> +		.get_vid = byt_get_vid,
>  	},
>  };
>  
> @@ -462,7 +508,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
>  
>  	cpu->pstate.current_pstate = pstate;
>  
> -	pstate_funcs.set(pstate);
> +	pstate_funcs.set(cpu, pstate);
>  }
>  
>  static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
> @@ -488,6 +534,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
>  	cpu->pstate.max_pstate = pstate_funcs.get_max();
>  	cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
>  
> +	if (pstate_funcs.get_vid)
> +		pstate_funcs.get_vid(cpu);
> +
>  	/*
>  	 * goto max pstate so we don't slow up boot if we are built-in if we are
>  	 * a module we will take care of it during normal operation
> @@ -776,6 +825,7 @@ static void copy_cpu_funcs(struct pstate_funcs *funcs)
>  	pstate_funcs.get_min   = funcs->get_min;
>  	pstate_funcs.get_turbo = funcs->get_turbo;
>  	pstate_funcs.set       = funcs->set;
> +	pstate_funcs.get_vid   = funcs->get_vid;
>  }
>  
>  #if IS_ENABLED(CONFIG_ACPI)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics


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

* Re: [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states.
  2013-12-18 12:37 ` [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states Bartlomiej Zolnierkiewicz
@ 2013-12-19  0:03   ` Dirk Brandewie
  0 siblings, 0 replies; 4+ messages in thread
From: Dirk Brandewie @ 2013-12-19  0:03 UTC (permalink / raw)
  To: Bartlomiej Zolnierkiewicz; +Cc: linux-pm, rjw, Dirk Brandewie

On 12/18/2013 04:37 AM, Bartlomiej Zolnierkiewicz wrote:
		val |= (u64)1 << 32;
>> +
>> +	vid_fp = mul_fp(cpudata->vid.min +
>> +			int_tofp(pstate - cpudata->pstate.min_pstate),
>> +			cpudata->vid.ratio);
>
> Shouldn't this be:
>
> +	vid_fp = cpudata->vid.min + mul_fp(
> +			int_tofp(pstate - cpudata->pstate.min_pstate),
> +			cpudata->vid.ratio);
>

Yes thx

> ?
>


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

end of thread, other threads:[~2013-12-19  0:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-17 17:42 [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states dirk.brandewie
2013-12-17 17:42 ` [PATCH 2/2] intel_pstate: Remove periodic P state boost dirk.brandewie
2013-12-18 12:37 ` [PATCH 1/2] intel_pstate: Add setting voltage value for baytrail P states Bartlomiej Zolnierkiewicz
2013-12-19  0:03   ` Dirk Brandewie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).