linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cpufreq: Add governor operation ongoing flag
@ 2013-08-13  7:09 Xiaoguang Chen
  2013-08-13  7:09 ` [PATCH 2/2] cpufreq: Only do governor start after successful stop Xiaoguang Chen
  2013-08-14  5:21 ` [PATCH 1/2] cpufreq: Add governor operation ongoing flag Viresh Kumar
  0 siblings, 2 replies; 11+ messages in thread
From: Xiaoguang Chen @ 2013-08-13  7:09 UTC (permalink / raw)
  To: cpufreq, linux-pm, linux-kernel; +Cc: viresh.kumar, rjw, chenxg.marvell, chenxg

__cpufreq_governor operation needs to be executed one by one.
If one operation is ongoing, the other operation can't be executed.
If the order is not guaranteed, there may be unexpected behavior.

 For example, governor is in enable state, and one process
tries to stop the goveror, but it is scheduled out before policy->
governor->governor() is executed, but the governor enable flag is
set to false already. Then one other process tries to start governor,
It finds enable flag is false, and it can process down to do governor
start operation, So the governor is started twice.

Add the governor_ops_ongoing flag to check whether there is governor
operation ongoing, if so, return -EAGAIN.

Signed-off-by: Xiaoguang Chen <chenxg@marvell.com>
---
 drivers/cpufreq/cpufreq.c | 9 +++++++++
 include/linux/cpufreq.h   | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f0a5e2b..dfe0b86 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1652,6 +1652,11 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
 		mutex_unlock(&cpufreq_governor_lock);
 		return -EBUSY;
 	}
+	if (policy->governor_ops_ongoing) {
+		mutex_unlock(&cpufreq_governor_lock);
+		return -EAGAIN;
+	}
+	policy->governor_ops_ongoing = true;
 
 	if (event == CPUFREQ_GOV_STOP)
 		policy->governor_enabled = false;
@@ -1684,6 +1689,10 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
 	if ((event == CPUFREQ_GOV_STOP) && !ret)
 		module_put(policy->governor->owner);
 
+	mutex_lock(&cpufreq_governor_lock);
+	policy->governor_ops_ongoing = false;
+	mutex_unlock(&cpufreq_governor_lock);
+
 	return ret;
 }
 
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 90d5a15..8d3eac2 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -111,6 +111,7 @@ struct cpufreq_policy {
 	struct cpufreq_governor	*governor; /* see below */
 	void			*governor_data;
 	bool			governor_enabled; /* governor start/stop flag */
+	bool			governor_ops_ongoing;
 
 	struct work_struct	update; /* if update_policy() needs to be
 					 * called, but you're in IRQ context */
-- 
1.8.0


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

end of thread, other threads:[~2013-08-14  8:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-13  7:09 [PATCH 1/2] cpufreq: Add governor operation ongoing flag Xiaoguang Chen
2013-08-13  7:09 ` [PATCH 2/2] cpufreq: Only do governor start after successful stop Xiaoguang Chen
2013-08-14  5:23   ` Viresh Kumar
2013-08-14  7:38     ` Xiaoguang Chen
2013-08-14  5:21 ` [PATCH 1/2] cpufreq: Add governor operation ongoing flag Viresh Kumar
2013-08-14  7:36   ` Xiaoguang Chen
2013-08-14  7:48     ` Viresh Kumar
2013-08-14  8:19       ` Xiaoguang Chen
2013-08-14  8:22         ` Viresh Kumar
2013-08-14  8:50           ` Xiaoguang Chen
2013-08-14  8:54             ` Viresh Kumar

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