All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region
@ 2015-08-12  3:49 Chen Yu
  2015-09-07 21:47 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Yu @ 2015-08-12  3:49 UTC (permalink / raw)
  To: kristen, rjw, viresh.kumar
  Cc: linux-pm, linux-kernel, rui.zhang, lenb, Chen Yu

In current code, if system is using performance policy, user can
modify the max_perf_pct to any values lower than 100:

$ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
/sys/devices/system/cpu/intel_pstate/max_perf_pct:100
/sys/devices/system/cpu/intel_pstate/min_perf_pct:100

$ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct

$ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
/sys/devices/system/cpu/intel_pstate/max_perf_pct:80
/sys/devices/system/cpu/intel_pstate/min_perf_pct:100

the max_perf_pct above is lower than min_perf_pct, which
is not reasonable.

This patch solves this problem by clamping min_perf_pct and max_perf_pct
to be strictly inside [min_policy_pct,max_policy_pct].

Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
 drivers/cpufreq/intel_pstate.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index fcb929e..3702c5a 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -423,6 +423,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
 
 	limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
 	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
+	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
 	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
 
 	if (hwp_active)
@@ -442,6 +443,7 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
 
 	limits.min_sysfs_pct = clamp_t(int, input, 0 , 100);
 	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
+	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
 	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
 
 	if (hwp_active)
@@ -985,12 +987,14 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 
 	limits.min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
 	limits.min_policy_pct = clamp_t(int, limits.min_policy_pct, 0 , 100);
-	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
-	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
-
 	limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
 	limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
+
+	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
+	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
+	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
 	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
+	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
 	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
 
 	if (hwp_active)
-- 
1.8.3.1


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

* Re: [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region
  2015-08-12  3:49 [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region Chen Yu
@ 2015-09-07 21:47 ` Rafael J. Wysocki
  2015-09-09  2:15     ` Chen, Yu C
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2015-09-07 21:47 UTC (permalink / raw)
  To: Chen Yu, kristen; +Cc: viresh.kumar, linux-pm, linux-kernel, rui.zhang, lenb

On Wednesday, August 12, 2015 11:49:19 AM Chen Yu wrote:
> In current code, if system is using performance policy, user can
> modify the max_perf_pct to any values lower than 100:
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:100
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> $ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:80
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> the max_perf_pct above is lower than min_perf_pct, which
> is not reasonable.
> 
> This patch solves this problem by clamping min_perf_pct and max_perf_pct
> to be strictly inside [min_policy_pct,max_policy_pct].
> 
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>

Looks reasonable to me.

Kristen, any objections?


> ---
>  drivers/cpufreq/intel_pstate.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index fcb929e..3702c5a 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -423,6 +423,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -442,6 +443,7 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.min_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
>  	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -985,12 +987,14 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
>  
>  	limits.min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
>  	limits.min_policy_pct = clamp_t(int, limits.min_policy_pct, 0 , 100);
> -	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> -	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
> -
>  	limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
>  	limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
> +
> +	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
> +	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* RE: [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region
  2015-09-07 21:47 ` Rafael J. Wysocki
@ 2015-09-09  2:15     ` Chen, Yu C
  0 siblings, 0 replies; 4+ messages in thread
From: Chen, Yu C @ 2015-09-09  2:15 UTC (permalink / raw)
  To: Rafael J. Wysocki, kristen
  Cc: viresh.kumar, linux-pm, linux-kernel, Zhang, Rui, lenb, Seiichi Ikarashi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1653 bytes --]

Hi ,Rafael

> -----Original Message-----
> From: Rafael J. Wysocki [mailto:rjw@rjwysocki.net]
> Sent: Tuesday, September 08, 2015 5:47 AM
> To: Chen, Yu C; kristen@linux.intel.com
> Cc: viresh.kumar@linaro.org; linux-pm@vger.kernel.org; linux-
> kernel@vger.kernel.org; Zhang, Rui; lenb@kernel.org
> Subject: Re: [PATCH][rfc] intel_pstate: Fix user input of min/max to legal
> policy region
> 
> On Wednesday, August 12, 2015 11:49:19 AM Chen Yu wrote:
> > In current code, if system is using performance policy, user can
> > modify the max_perf_pct to any values lower than 100:
> >
> > $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> > /sys/devices/system/cpu/intel_pstate/max_perf_pct:100
> > /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> >
> > $ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
> >
> > $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> > /sys/devices/system/cpu/intel_pstate/max_perf_pct:80
> > /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> >
> > the max_perf_pct above is lower than min_perf_pct, which is not
> > reasonable.
> >
> > This patch solves this problem by clamping min_perf_pct and
> > max_perf_pct to be strictly inside [min_policy_pct,max_policy_pct].
> >
> > Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> 
> Looks reasonable to me.
> 
> Kristen, any objections?
> 
Thanks for your reply! 
According to suggestion from  Seiichi, will re-send a V2 version patch,
to make some update.

Best Regards,
Yu 

ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* RE: [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region
@ 2015-09-09  2:15     ` Chen, Yu C
  0 siblings, 0 replies; 4+ messages in thread
From: Chen, Yu C @ 2015-09-09  2:15 UTC (permalink / raw)
  To: Rafael J. Wysocki, kristen
  Cc: viresh.kumar, linux-pm, linux-kernel, Zhang, Rui, lenb, Seiichi Ikarashi

Hi ,Rafael

> -----Original Message-----
> From: Rafael J. Wysocki [mailto:rjw@rjwysocki.net]
> Sent: Tuesday, September 08, 2015 5:47 AM
> To: Chen, Yu C; kristen@linux.intel.com
> Cc: viresh.kumar@linaro.org; linux-pm@vger.kernel.org; linux-
> kernel@vger.kernel.org; Zhang, Rui; lenb@kernel.org
> Subject: Re: [PATCH][rfc] intel_pstate: Fix user input of min/max to legal
> policy region
> 
> On Wednesday, August 12, 2015 11:49:19 AM Chen Yu wrote:
> > In current code, if system is using performance policy, user can
> > modify the max_perf_pct to any values lower than 100:
> >
> > $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> > /sys/devices/system/cpu/intel_pstate/max_perf_pct:100
> > /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> >
> > $ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
> >
> > $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> > /sys/devices/system/cpu/intel_pstate/max_perf_pct:80
> > /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> >
> > the max_perf_pct above is lower than min_perf_pct, which is not
> > reasonable.
> >
> > This patch solves this problem by clamping min_perf_pct and
> > max_perf_pct to be strictly inside [min_policy_pct,max_policy_pct].
> >
> > Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> 
> Looks reasonable to me.
> 
> Kristen, any objections?
> 
Thanks for your reply! 
According to suggestion from  Seiichi, will re-send a V2 version patch,
to make some update.

Best Regards,
Yu 


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

end of thread, other threads:[~2015-09-09  2:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-12  3:49 [PATCH][rfc] intel_pstate: Fix user input of min/max to legal policy region Chen Yu
2015-09-07 21:47 ` Rafael J. Wysocki
2015-09-09  2:15   ` Chen, Yu C
2015-09-09  2:15     ` Chen, Yu C

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.