All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: governor: Ensure sufficiently large sampling intervals
@ 2018-01-29  7:21 Viresh Kumar
  2018-01-31  9:27 ` Rafael J. Wysocki
  0 siblings, 1 reply; 29+ messages in thread
From: Viresh Kumar @ 2018-01-29  7:21 UTC (permalink / raw)
  To: stable; +Cc: Viresh Kumar, Rafael Wysocki, linux-pm

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

[ Upstream commit 56026645e2b6f11ede34a5e6ab69d3eb56f9c8fc ]

After commit aa7519af450d (cpufreq: Use transition_delay_us for legacy
governors as well) the sampling_rate field of struct dbs_data may be
less than the tick period which causes dbs_update() to produce
incorrect results, so make the code ensure that the value of that
field will always be sufficiently large.

Cc: 4.14 <stable@vger.kernel.org> # 4.14
Fixes: aa7519af450d (cpufreq: Use transition_delay_us for legacy governors as well)
Reported-by: Andy Tang <andy.tang@nxp.com>
Reported-by: Doug Smythies <dsmythies@telus.net>
Tested-by: Andy Tang <andy.tang@nxp.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq_governor.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 58d4f4e1ad6a..ca38229b045a 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -22,6 +22,8 @@
 
 #include "cpufreq_governor.h"
 
+#define CPUFREQ_DBS_MIN_SAMPLING_INTERVAL	(2 * TICK_NSEC / NSEC_PER_USEC)
+
 static DEFINE_PER_CPU(struct cpu_dbs_info, cpu_dbs);
 
 static DEFINE_MUTEX(gov_dbs_data_mutex);
@@ -47,11 +49,15 @@ ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf,
 {
 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
 	struct policy_dbs_info *policy_dbs;
+	unsigned int sampling_interval;
 	int ret;
-	ret = sscanf(buf, "%u", &dbs_data->sampling_rate);
-	if (ret != 1)
+
+	ret = sscanf(buf, "%u", &sampling_interval);
+	if (ret != 1 || sampling_interval < CPUFREQ_DBS_MIN_SAMPLING_INTERVAL)
 		return -EINVAL;
 
+	dbs_data->sampling_rate = sampling_interval;
+
 	/*
 	 * We are operating under dbs_data->mutex and so the list and its
 	 * entries can't be freed concurrently.
@@ -430,7 +436,14 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
 	if (ret)
 		goto free_policy_dbs_info;
 
-	dbs_data->sampling_rate = cpufreq_policy_transition_delay_us(policy);
+	/*
+	 * The sampling interval should not be less than the transition latency
+	 * of the CPU and it also cannot be too small for dbs_update() to work
+	 * correctly.
+	 */
+	dbs_data->sampling_rate = max_t(unsigned int,
+					CPUFREQ_DBS_MIN_SAMPLING_INTERVAL,
+					cpufreq_policy_transition_delay_us(policy));
 
 	if (!have_governor_per_policy())
 		gov->gdbs_data = dbs_data;
-- 
2.15.0.194.g9af6a3dea062

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

end of thread, other threads:[~2018-01-31  9:29 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <HE1PR0402MB282866171A847AE244A9F76CF3340@HE1PR0402MB2828.eurprd04.prod.outlook.com>
2017-12-12  7:30 ` Ask for help on governor Viresh Kumar
2017-12-12 16:18 ` Doug Smythies
2017-12-12 16:51   ` Rafael J. Wysocki
2017-12-13  3:10   ` Doug Smythies
2017-12-13  6:17     ` Viresh Kumar
2017-12-13  6:22       ` Andy Tang
2017-12-13  6:55         ` Viresh Kumar
2017-12-13 16:13       ` Doug Smythies
2017-12-14  1:21       ` Doug Smythies
2017-12-14  2:42         ` Andy Tang
2017-12-14 18:25           ` Stratos Karafotis
2017-12-15  1:29           ` Doug Smythies
2017-12-15  1:30         ` Doug Smythies
2017-12-15  1:56           ` Andy Tang
2017-12-15  7:37           ` Doug Smythies
2017-12-15  9:00             ` Andy Tang
2017-12-15 14:26               ` Rafael J. Wysocki
2017-12-15 15:53             ` Rafael J. Wysocki
2017-12-15 18:27             ` Doug Smythies
2017-12-15 23:53               ` Rafael J. Wysocki
2017-12-18  1:15               ` [PATCH] cpufreq: governor: Ensure sufficiently large sampling intervals Rafael J. Wysocki
2017-12-18  2:59                 ` Andy Tang
2017-12-18  4:38                 ` Viresh Kumar
2017-12-18 16:11               ` Doug Smythies
2017-12-18 17:42                 ` Rafael J. Wysocki
2017-12-13 16:13     ` Ask for help on governor Doug Smythies
2017-12-13 16:49     ` Doug Smythies
2018-01-29  7:21 [PATCH] cpufreq: governor: Ensure sufficiently large sampling intervals Viresh Kumar
2018-01-31  9:27 ` Rafael J. Wysocki

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.