All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework
@ 2016-02-03 23:12 Rafael J. Wysocki
  2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
                   ` (12 more replies)
  0 siblings, 13 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:12 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

Hi,

A few days ago I looked at the common code used by the ondemand and conservative
governors because of the deadlock issue that Viresh has addressed recently
(http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me
that the whole thing was really too tangled and might be made easier to follow
at least.  I started to work on this and ended up with the following series.

I'm not really going to stop here, but first, I'd like to let everybody know
that this is happening and second, I'll need to rebase these patches on the
ones from Viresh (in the series linked above), but that may take some time
and I don't want to sit on them for all that long.

Overall, I'd like the governor code to be cleaner and easier to follow, so we can
move at least some parts of governor work to utilization update callbacks (invoked
by the scheduler) or to at least to irq_work so as to reduce the usage of process
context in cpufreq to absolute minimum.  That's the plan for the future, but for
now this is just a major cleanup.

[1/11] Clean up the way in which the default and fallback governors are set up.
[2/11] Use a common global mutex for dbs_data protection.
[3/11] Use common global pointer to dbs_data for system-wide governors.
[4/11] Avoid passing dbs_data pointers to functions that can get them by themselves.
[5/11] Make struct governor be a member of struct common_dbs_data.
[6/11] Rename struct common_dbs_data to struct dbs_governor.
[7/11] Rework cpufreq_governor_dbs() so it can be used as a governor callback directly.
[8/11] Drop the dbs_governor (former cdata) pointer from struct dbs_data.
[9/11] Rename struct cpu_common_dbs_info to struct policy_dbs_info.
[10/11] Rearrange data structures so policy->governor_data points to struct policy_dbs_info.
[11/11] Drop the second argument of dbs_check_cpu().

The patches are on top of 4.5-rc2 with my earlier series replacing timers with
utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
applied.

Thanks,
Rafael

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

* [PATCH 1/11] cpufreq: Clean up default and fallback governor setup
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
@ 2016-02-03 23:14 ` Rafael J. Wysocki
  2016-02-04  0:55   ` Saravana Kannan
  2016-02-04  5:03   ` Viresh Kumar
  2016-02-03 23:16 ` [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
                   ` (11 subsequent siblings)
  12 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:14 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The preprocessor magic used for setting the default cpufreq governor
(and for using the performance governor as a fallback one for that
matter) is really nasty, so replace it with __weak functions and
overrides.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq.c              |   37 ++++++++++++++++++---------------
 drivers/cpufreq/cpufreq_conservative.c |   10 +++++---
 drivers/cpufreq/cpufreq_ondemand.c     |   34 ++++++++++++++++--------------
 drivers/cpufreq/cpufreq_performance.c  |   18 ++++++++++++----
 drivers/cpufreq/cpufreq_powersave.c    |   10 +++++---
 drivers/cpufreq/cpufreq_userspace.c    |   10 +++++---
 include/linux/cpufreq.h                |   25 +---------------------
 7 files changed, 73 insertions(+), 71 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(str
 	return cpufreq_add_dev_symlink(policy);
 }
 
+__weak struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return NULL;
+}
+
 static int cpufreq_init_policy(struct cpufreq_policy *policy)
 {
 	struct cpufreq_governor *gov = NULL;
@@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp
 
 	/* Update governor of new_policy to the governor used before hotplug */
 	gov = find_governor(policy->last_governor);
-	if (gov)
+	if (gov) {
 		pr_debug("Restoring governor %s for cpu %d\n",
 				policy->governor->name, policy->cpu);
-	else
-		gov = CPUFREQ_DEFAULT_GOVERNOR;
+	} else {
+		gov = cpufreq_default_governor();
+		if (!gov)
+			return -ENODATA;
+	}
 
 	new_policy.governor = gov;
 
@@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq
 }
 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
 
+__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
+{
+	return NULL;
+}
+
 static int __cpufreq_governor(struct cpufreq_policy *policy,
 					unsigned int event)
 {
 	int ret;
 
-	/* Only must be defined when default governor is known to have latency
-	   restrictions, like e.g. conservative or ondemand.
-	   That this is the case is already ensured in Kconfig
-	*/
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
-	struct cpufreq_governor *gov = &cpufreq_gov_performance;
-#else
-	struct cpufreq_governor *gov = NULL;
-#endif
-
 	/* Don't start any governor operations if we are entering suspend */
 	if (cpufreq_suspended)
 		return 0;
@@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpu
 	if (policy->governor->max_transition_latency &&
 	    policy->cpuinfo.transition_latency >
 	    policy->governor->max_transition_latency) {
-		if (!gov)
-			return -EINVAL;
-		else {
+		struct cpufreq_governor *gov = cpufreq_fallback_governor();
+
+		if (gov) {
 			pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
 				policy->governor->name, gov->name);
 			policy->governor = gov;
+		} else {
+			return -EINVAL;
 		}
 	}
 
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_conservative = {
+static struct cpufreq_governor cpufreq_gov_conservative = {
 	.name			= "conservative",
 	.governor		= cs_cpufreq_governor_dbs,
 	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
@@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativ
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_conservative;
+}
+
 fs_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
Index: linux-pm/include/linux/cpufreq.h
===================================================================
--- linux-pm.orig/include/linux/cpufreq.h
+++ linux-pm/include/linux/cpufreq.h
@@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufr
 int cpufreq_register_governor(struct cpufreq_governor *governor);
 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
 
-/* CPUFREQ DEFAULT GOVERNOR */
-/*
- * Performance governor is fallback governor if any other gov failed to auto
- * load due latency restrictions
- */
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
-extern struct cpufreq_governor cpufreq_gov_performance;
-#endif
-#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
-extern struct cpufreq_governor cpufreq_gov_powersave;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_powersave)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
-extern struct cpufreq_governor cpufreq_gov_userspace;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_userspace)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
-extern struct cpufreq_governor cpufreq_gov_ondemand;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_ondemand)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
-extern struct cpufreq_governor cpufreq_gov_conservative;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_conservative)
-#endif
+struct cpufreq_governor *cpufreq_default_governor(void);
+struct cpufreq_governor *cpufreq_fallback_governor(void);
 
 /*********************************************************************
  *                     FREQUENCY TABLE HELPERS                       *
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -553,6 +553,19 @@ static struct common_dbs_data od_dbs_cda
 	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
 };
 
+static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+		unsigned int event)
+{
+	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
+}
+
+static struct cpufreq_governor cpufreq_gov_ondemand = {
+	.name			= "ondemand",
+	.governor		= od_cpufreq_governor_dbs,
+	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
+};
+
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;
@@ -604,22 +617,6 @@ void od_unregister_powersave_bias_handle
 }
 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
-}
-
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
-static
-#endif
-struct cpufreq_governor cpufreq_gov_ondemand = {
-	.name			= "ondemand",
-	.governor		= od_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static int __init cpufreq_gov_dbs_init(void)
 {
 	return cpufreq_register_governor(&cpufreq_gov_ondemand);
@@ -637,6 +634,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_ondemand;
+}
+
 fs_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
+++ linux-pm/drivers/cpufreq/cpufreq_performance.c
@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
 	return 0;
 }
 
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_performance = {
+static struct cpufreq_governor cpufreq_gov_performance = {
 	.name		= "performance",
 	.governor	= cpufreq_governor_performance,
 	.owner		= THIS_MODULE,
@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
 	cpufreq_unregister_governor(&cpufreq_gov_performance);
 }
 
+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_performance;
+}
+#endif
+#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
+struct cpufreq_governor *cpufreq_fallback_governor(void)
+{
+	return &cpufreq_gov_performance;
+}
+#endif
+
 MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
 MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
 MODULE_LICENSE("GPL");
Index: linux-pm/drivers/cpufreq/cpufreq_powersave.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_powersave.c
+++ linux-pm/drivers/cpufreq/cpufreq_powersave.c
@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(st
 	return 0;
 }
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_powersave = {
+static struct cpufreq_governor cpufreq_gov_powersave = {
 	.name		= "powersave",
 	.governor	= cpufreq_governor_powersave,
 	.owner		= THIS_MODULE,
@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_powersave;
+}
+
 fs_initcall(cpufreq_gov_powersave_init);
 #else
 module_init(cpufreq_gov_powersave_init);
Index: linux-pm/drivers/cpufreq/cpufreq_userspace.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_userspace.c
+++ linux-pm/drivers/cpufreq/cpufreq_userspace.c
@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(st
 	return rc;
 }
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_userspace = {
+static struct cpufreq_governor cpufreq_gov_userspace = {
 	.name		= "userspace",
 	.governor	= cpufreq_governor_userspace,
 	.store_setspeed	= cpufreq_set,
@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_userspace;
+}
+
 fs_initcall(cpufreq_gov_userspace_init);
 #else
 module_init(cpufreq_gov_userspace_init);

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

* [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
  2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
@ 2016-02-03 23:16 ` Rafael J. Wysocki
  2016-02-04  0:59   ` Saravana Kannan
  2016-02-04  5:09   ` Viresh Kumar
  2016-02-03 23:22 ` [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer Rafael J. Wysocki
                   ` (10 subsequent siblings)
  12 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:16 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Every governor relying on the common code in cpufreq_governor.c
has to provide its own mutex in struct common_dbs_data.  However,
those mutexes are never used at the same time and doing it this
way makes it rather difficult to follow the code.  Moreover,
if two governor modules are loaded we end up with two mutexes
used for the same purpose one at a time.

Introduce a single common mutex for that instead and drop the
mutex field from struct common_dbs_data.  That at least will
ensure that the mutex is always present and initialized regardless
of what the particular governors do.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |    1 -
 drivers/cpufreq/cpufreq_governor.c     |    7 +++++--
 drivers/cpufreq/cpufreq_governor.h     |    6 +-----
 drivers/cpufreq/cpufreq_ondemand.c     |    5 ++---
 4 files changed, 8 insertions(+), 11 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -22,6 +22,9 @@
 
 #include "cpufreq_governor.h"
 
+DEFINE_MUTEX(dbs_data_mutex);
+EXPORT_SYMBOL_GPL(dbs_data_mutex);
+
 static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
 {
 	if (have_governor_per_policy())
@@ -542,7 +545,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	int ret;
 
 	/* Lock governor to block concurrent initialization of governor */
-	mutex_lock(&cdata->mutex);
+	mutex_lock(&dbs_data_mutex);
 
 	if (have_governor_per_policy())
 		dbs_data = policy->governor_data;
@@ -575,7 +578,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	}
 
 unlock:
-	mutex_unlock(&cdata->mutex);
+	mutex_unlock(&dbs_data_mutex);
 
 	return ret;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -223,11 +223,6 @@ struct common_dbs_data {
 
 	/* Governor specific ops, see below */
 	void *gov_ops;
-
-	/*
-	 * Protects governor's data (struct dbs_data and struct common_dbs_data)
-	 */
-	struct mutex mutex;
 };
 
 /* Governor Per policy data */
@@ -272,6 +267,7 @@ static ssize_t show_sampling_rate_min_go
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }
 
+extern struct mutex dbs_data_mutex;
 extern struct mutex cpufreq_governor_lock;
 void gov_set_update_util(struct cpu_common_dbs_info *shared,
 			 unsigned int delay_us);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -251,7 +251,7 @@ static void update_sampling_rate(struct
 	/*
 	 * Lock governor so that governor start/stop can't execute in parallel.
 	 */
-	mutex_lock(&od_dbs_cdata.mutex);
+	mutex_lock(&dbs_data_mutex);
 
 	cpumask_copy(&cpumask, cpu_online_mask);
 
@@ -304,7 +304,7 @@ static void update_sampling_rate(struct
 		}
 	}
 
-	mutex_unlock(&od_dbs_cdata.mutex);
+	mutex_unlock(&dbs_data_mutex);
 }
 
 static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
@@ -550,7 +550,6 @@ static struct common_dbs_data od_dbs_cda
 	.gov_ops = &od_ops,
 	.init = od_init,
 	.exit = od_exit,
-	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
 };
 
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda
 	.gov_check_cpu = cs_check_cpu,
 	.init = cs_init,
 	.exit = cs_exit,
-	.mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex),
 };
 
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,

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

* [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
  2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
  2016-02-03 23:16 ` [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
@ 2016-02-03 23:22 ` Rafael J. Wysocki
  2016-02-04  1:11   ` Saravana Kannan
  2016-02-04  5:36   ` Viresh Kumar
  2016-02-03 23:29 ` [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
                   ` (9 subsequent siblings)
  12 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:22 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

If the ondemand and conservative governors cannot use per-policy
tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
driver), all policy objects point to the same single dbs_data object.
Additionally, that object is pointed to by a global pointer hidden in
the governor's data structures.

There is no reason for that pointer to be buried in those
data structures, though, so make it explicitly global.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |   20 ++++++++++----------
 drivers/cpufreq/cpufreq_governor.h |   20 ++++++++++----------
 2 files changed, 20 insertions(+), 20 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
 static ssize_t show_##file_name##_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, char *buf)		\
 {									\
-	struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \
+	struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \
 	return sprintf(buf, "%u\n", tuners->file_name);			\
 }									\
 									\
@@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po
 static ssize_t store_##file_name##_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
 {									\
-	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
+	struct dbs_data *dbs_data = global_dbs_data;		\
 	return store_##file_name(dbs_data, buf, count);			\
 }									\
 									\
@@ -201,19 +201,14 @@ struct cs_dbs_tuners {
 /* Common Governor data across policies */
 struct dbs_data;
 struct common_dbs_data {
-	/* Common across governors */
+	struct cpufreq_governor gov;
+
 	#define GOV_ONDEMAND		0
 	#define GOV_CONSERVATIVE	1
 	int governor;
 	struct attribute_group *attr_group_gov_sys; /* one governor - system */
 	struct attribute_group *attr_group_gov_pol; /* one governor - policy */
 
-	/*
-	 * Common data for platforms that don't set
-	 * CPUFREQ_HAVE_GOVERNOR_PER_POLICY
-	 */
-	struct dbs_data *gdbs_data;
-
 	struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);
 	void *(*get_cpu_dbs_info_s)(int cpu);
 	unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
@@ -233,6 +228,11 @@ struct dbs_data {
 	void *tuners;
 };
 
+/*
+ * Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
+ */
+extern struct dbs_data *global_dbs_data;
+
 /* Governor specific ops, will be passed to dbs_data->gov_ops */
 struct od_ops {
 	void (*powersave_bias_init_cpu)(int cpu);
@@ -256,7 +256,7 @@ static inline int delay_for_sampling_rat
 static ssize_t show_sampling_rate_min_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, char *buf)		\
 {									\
-	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
+	struct dbs_data *dbs_data = global_dbs_data;			\
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }									\
 									\
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -22,6 +22,9 @@
 
 #include "cpufreq_governor.h"
 
+struct dbs_data *global_dbs_data;
+EXPORT_SYMBOL_GPL(global_dbs_data);
+
 DEFINE_MUTEX(dbs_data_mutex);
 EXPORT_SYMBOL_GPL(dbs_data_mutex);
 
@@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct
 					latency * LATENCY_MULTIPLIER));
 
 	if (!have_governor_per_policy())
-		cdata->gdbs_data = dbs_data;
+		global_dbs_data = dbs_data;
 
 	policy->governor_data = dbs_data;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
 				 get_sysfs_attr(dbs_data));
-	if (ret)
-		goto reset_gdbs_data;
-
-	return 0;
+	if (!ret)
+		return 0;
 
-reset_gdbs_data:
 	policy->governor_data = NULL;
-
 	if (!have_governor_per_policy())
-		cdata->gdbs_data = NULL;
+		global_dbs_data = NULL;
+
 	cdata->exit(dbs_data, !policy->governor->initialized);
 free_common_dbs_info:
 	free_common_dbs_info(policy, cdata);
@@ -418,7 +418,7 @@ static int cpufreq_governor_exit(struct
 		policy->governor_data = NULL;
 
 		if (!have_governor_per_policy())
-			cdata->gdbs_data = NULL;
+			global_dbs_data = NULL;
 
 		cdata->exit(dbs_data, policy->governor->initialized == 1);
 		kfree(dbs_data);
@@ -550,7 +550,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	if (have_governor_per_policy())
 		dbs_data = policy->governor_data;
 	else
-		dbs_data = cdata->gdbs_data;
+		dbs_data = global_dbs_data;
 
 	if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) {
 		ret = -EINVAL;

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

* [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2016-02-03 23:22 ` [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer Rafael J. Wysocki
@ 2016-02-03 23:29 ` Rafael J. Wysocki
  2016-02-04  1:37   ` Saravana Kannan
  2016-02-03 23:31 ` [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:29 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Do not pass struct dbs_data pointers to the family of functions
implementing governor operations in cpufreq_governor.c as they can
take that pointer from policy->governor by themselves.

The cpufreq_governor_init() case is slightly more complicated, since
policy->governor may be NULL when it is invoked, but then it can use
global_dbs_data directly just fine.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |   74 +++++++++++++++----------------------
 1 file changed, 30 insertions(+), 44 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -330,9 +330,9 @@ static void free_common_dbs_info(struct
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data,
 				 struct common_dbs_data *cdata)
 {
+	struct dbs_data *dbs_data;
 	unsigned int latency;
 	int ret;
 
@@ -340,7 +340,7 @@ static int cpufreq_governor_init(struct
 	if (policy->governor_data)
 		return -EBUSY;
 
-	if (dbs_data) {
+	if (global_dbs_data) {
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
@@ -348,8 +348,8 @@ static int cpufreq_governor_init(struct
 		if (ret)
 			return ret;
 
-		dbs_data->usage_count++;
-		policy->governor_data = dbs_data;
+		global_dbs_data->usage_count++;
+		policy->governor_data = global_dbs_data;
 		return 0;
 	}
 
@@ -401,9 +401,9 @@ free_dbs_data:
 	return ret;
 }
 
-static int cpufreq_governor_exit(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data)
+static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
 
@@ -430,9 +430,9 @@ static int cpufreq_governor_exit(struct
 	return 0;
 }
 
-static int cpufreq_governor_start(struct cpufreq_policy *policy,
-				  struct dbs_data *dbs_data)
+static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
@@ -498,9 +498,9 @@ static int cpufreq_governor_start(struct
 	return 0;
 }
 
-static int cpufreq_governor_stop(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data)
+static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
@@ -514,9 +514,9 @@ static int cpufreq_governor_stop(struct
 	return 0;
 }
 
-static int cpufreq_governor_limits(struct cpufreq_policy *policy,
-				   struct dbs_data *dbs_data)
+static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	unsigned int cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
@@ -541,45 +541,31 @@ static int cpufreq_governor_limits(struc
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
 			 struct common_dbs_data *cdata, unsigned int event)
 {
-	struct dbs_data *dbs_data;
-	int ret;
+	int ret = -EINVAL;
 
 	/* Lock governor to block concurrent initialization of governor */
 	mutex_lock(&dbs_data_mutex);
 
-	if (have_governor_per_policy())
-		dbs_data = policy->governor_data;
-	else
-		dbs_data = global_dbs_data;
-
-	if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) {
-		ret = -EINVAL;
-		goto unlock;
+	if (event == CPUFREQ_GOV_POLICY_INIT) {
+		ret = cpufreq_governor_init(policy, cdata);
+	} else if (policy->governor_data) {
+		switch (event) {
+		case CPUFREQ_GOV_POLICY_EXIT:
+			ret = cpufreq_governor_exit(policy);
+			break;
+		case CPUFREQ_GOV_START:
+			ret = cpufreq_governor_start(policy);
+			break;
+		case CPUFREQ_GOV_STOP:
+			ret = cpufreq_governor_stop(policy);
+			break;
+		case CPUFREQ_GOV_LIMITS:
+			ret = cpufreq_governor_limits(policy);
+			break;
+		}
 	}
 
-	switch (event) {
-	case CPUFREQ_GOV_POLICY_INIT:
-		ret = cpufreq_governor_init(policy, dbs_data, cdata);
-		break;
-	case CPUFREQ_GOV_POLICY_EXIT:
-		ret = cpufreq_governor_exit(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_START:
-		ret = cpufreq_governor_start(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_STOP:
-		ret = cpufreq_governor_stop(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_LIMITS:
-		ret = cpufreq_governor_limits(policy, dbs_data);
-		break;
-	default:
-		ret = -EINVAL;
-	}
-
-unlock:
 	mutex_unlock(&dbs_data_mutex);
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(cpufreq_governor_dbs);

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

* [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (3 preceding siblings ...)
  2016-02-03 23:29 ` [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
@ 2016-02-03 23:31 ` Rafael J. Wysocki
  2016-02-04  1:57   ` Saravana Kannan
  2016-02-03 23:32 ` [PATCH 6/11] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:31 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

For the ondemand and conservative governors (generally, governors
that use the common code in cpufreq_governor.c), there are two static
data structures representing the governor, the struct governor
structure (the interface to the cpufreq core) and the struct
common_dbs_data one (the interface to the cpufreq_governor.c code).

There's no fundamental reason why those two structures have to be
separate.  Moreover, if the struct governor one is included into
struct common_dbs_data, it will be possible to reach the latter from
the policy via its policy->governor pointer, so it won't be necessary
to pass a separate pointer to it around.  For this reason, embed
struct governor in struct common_dbs_data.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |   78 +++++++++++++++++----------------
 drivers/cpufreq/cpufreq_ondemand.c     |   26 ++++++-----
 2 files changed, 56 insertions(+), 48 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -539,7 +539,16 @@ static struct od_ops od_ops = {
 	.freq_increase = dbs_freq_increase,
 };
 
+static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+				   unsigned int event);
+
 static struct common_dbs_data od_dbs_cdata = {
+	.gov = {
+		.name = "ondemand",
+		.governor = od_cpufreq_governor_dbs,
+		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+		.owner = THIS_MODULE,
+	},
 	.governor = GOV_ONDEMAND,
 	.attr_group_gov_sys = &od_attr_group_gov_sys,
 	.attr_group_gov_pol = &od_attr_group_gov_pol,
@@ -552,19 +561,14 @@ static struct common_dbs_data od_dbs_cda
 	.exit = od_exit,
 };
 
+#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_cdata.gov)
+
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		unsigned int event)
 {
 	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
 }
 
-static struct cpufreq_governor cpufreq_gov_ondemand = {
-	.name			= "ondemand",
-	.governor		= od_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;
@@ -590,7 +594,7 @@ static void od_set_powersave_bias(unsign
 		policy = shared->policy;
 		cpumask_or(&done, &done, policy->cpus);
 
-		if (policy->governor != &cpufreq_gov_ondemand)
+		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
 			continue;
 
 		dbs_data = policy->governor_data;
@@ -618,12 +622,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersav
 
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_ondemand);
+	return cpufreq_register_governor(CPU_FREQ_GOV_ONDEMAND);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_ondemand);
+	cpufreq_unregister_governor(CPU_FREQ_GOV_ONDEMAND);
 }
 
 MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
@@ -635,7 +639,7 @@ MODULE_LICENSE("GPL");
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
 struct cpufreq_governor *cpufreq_default_governor(void)
 {
-	return &cpufreq_gov_ondemand;
+	return CPU_FREQ_GOV_ONDEMAND;
 }
 
 fs_initcall(cpufreq_gov_dbs_init);
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -23,16 +23,6 @@
 
 static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
-static struct cpufreq_governor cpufreq_gov_conservative = {
-	.name			= "conservative",
-	.governor		= cs_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
 					   struct cpufreq_policy *policy)
 {
@@ -122,30 +112,7 @@ static unsigned int cs_dbs_timer(struct
 }
 
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
-		void *data)
-{
-	struct cpufreq_freqs *freq = data;
-	struct cs_cpu_dbs_info_s *dbs_info =
-					&per_cpu(cs_cpu_dbs_info, freq->cpu);
-	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
-
-	if (!policy)
-		return 0;
-
-	/* policy isn't governed by conservative governor */
-	if (policy->governor != &cpufreq_gov_conservative)
-		return 0;
-
-	/*
-	 * we only care if our internally tracked freq moves outside the 'valid'
-	 * ranges of frequency available to us otherwise we do not change it
-	*/
-	if (dbs_info->requested_freq > policy->max
-			|| dbs_info->requested_freq < policy->min)
-		dbs_info->requested_freq = freq->new;
-
-	return 0;
-}
+				void *data);
 
 static struct notifier_block cs_cpufreq_notifier_block = {
 	.notifier_call = dbs_cpufreq_notifier,
@@ -358,7 +325,16 @@ static void cs_exit(struct dbs_data *dbs
 
 define_get_cpu_dbs_routines(cs_cpu_dbs_info);
 
+static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+				   unsigned int event);
+
 static struct common_dbs_data cs_dbs_cdata = {
+	.gov = {
+		.name = "conservative",
+		.governor = cs_cpufreq_governor_dbs,
+		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
+		.owner = THIS_MODULE,
+	},
 	.governor = GOV_CONSERVATIVE,
 	.attr_group_gov_sys = &cs_attr_group_gov_sys,
 	.attr_group_gov_pol = &cs_attr_group_gov_pol,
@@ -370,20 +346,48 @@ static struct common_dbs_data cs_dbs_cda
 	.exit = cs_exit,
 };
 
+#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_cdata.gov)
+
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event)
 {
 	return cpufreq_governor_dbs(policy, &cs_dbs_cdata, event);
 }
 
+static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
+				void *data)
+{
+	struct cpufreq_freqs *freq = data;
+	struct cs_cpu_dbs_info_s *dbs_info =
+					&per_cpu(cs_cpu_dbs_info, freq->cpu);
+	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
+
+	if (!policy)
+		return 0;
+
+	/* policy isn't governed by conservative governor */
+	if (policy->governor != CPU_FREQ_GOV_CONSERVATIVE)
+		return 0;
+
+	/*
+	 * we only care if our internally tracked freq moves outside the 'valid'
+	 * ranges of frequency available to us otherwise we do not change it
+	*/
+	if (dbs_info->requested_freq > policy->max
+			|| dbs_info->requested_freq < policy->min)
+		dbs_info->requested_freq = freq->new;
+
+	return 0;
+}
+
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_conservative);
+	return cpufreq_register_governor(CPU_FREQ_GOV_CONSERVATIVE);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_conservative);
+	cpufreq_unregister_governor(CPU_FREQ_GOV_CONSERVATIVE);
 }
 
 MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
@@ -395,7 +399,7 @@ MODULE_LICENSE("GPL");
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
 struct cpufreq_governor *cpufreq_default_governor(void)
 {
-	return &cpufreq_gov_conservative;
+	return CPU_FREQ_GOV_CONSERVATIVE;
 }
 
 fs_initcall(cpufreq_gov_dbs_init);

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

* [PATCH 6/11] cpufreq: governor: Rename some data types and variables
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (4 preceding siblings ...)
  2016-02-03 23:31 ` [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
@ 2016-02-03 23:32 ` Rafael J. Wysocki
  2016-02-03 23:33 ` [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:32 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The ondemand and conservative governors are represented by
struct common_dbs_data whose name doesn't reflect the purpose it
is used for, so rename it to struct dbs_governor and rename
variables of that type accordingly.

No functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    2 
 drivers/cpufreq/cpufreq_conservative.c |    8 +--
 drivers/cpufreq/cpufreq_governor.c     |   82 ++++++++++++++++-----------------
 drivers/cpufreq/cpufreq_governor.h     |    6 +-
 drivers/cpufreq/cpufreq_ondemand.c     |    8 +--
 5 files changed, 53 insertions(+), 53 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -119,7 +119,7 @@ static struct notifier_block cs_cpufreq_
 };
 
 /************************** sysfs interface ************************/
-static struct common_dbs_data cs_dbs_cdata;
+static struct dbs_governor cs_dbs_gov;
 
 static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
 		const char *buf, size_t count)
@@ -328,7 +328,7 @@ define_get_cpu_dbs_routines(cs_cpu_dbs_i
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-static struct common_dbs_data cs_dbs_cdata = {
+static struct dbs_governor cs_dbs_gov = {
 	.gov = {
 		.name = "conservative",
 		.governor = cs_cpufreq_governor_dbs,
@@ -346,12 +346,12 @@ static struct common_dbs_data cs_dbs_cda
 	.exit = cs_exit,
 };
 
-#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_cdata.gov)
+#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_gov.gov)
 
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event)
 {
-	return cpufreq_governor_dbs(policy, &cs_dbs_cdata, event);
+	return cpufreq_governor_dbs(policy, &cs_dbs_gov, event);
 }
 
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -31,14 +31,14 @@ EXPORT_SYMBOL_GPL(dbs_data_mutex);
 static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
 {
 	if (have_governor_per_policy())
-		return dbs_data->cdata->attr_group_gov_pol;
+		return dbs_data->gov->attr_group_gov_pol;
 	else
-		return dbs_data->cdata->attr_group_gov_sys;
+		return dbs_data->gov->attr_group_gov_sys;
 }
 
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
 {
-	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	struct cpufreq_policy *policy = cdbs->shared->policy;
@@ -47,9 +47,9 @@ void dbs_check_cpu(struct dbs_data *dbs_
 	unsigned int ignore_nice;
 	unsigned int j;
 
-	if (dbs_data->cdata->governor == GOV_ONDEMAND) {
+	if (dbs_data->gov->governor == GOV_ONDEMAND) {
 		struct od_cpu_dbs_info_s *od_dbs_info =
-				dbs_data->cdata->get_cpu_dbs_info_s(cpu);
+				dbs_data->gov->get_cpu_dbs_info_s(cpu);
 
 		/*
 		 * Sometimes, the ondemand governor uses an additional
@@ -74,7 +74,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		unsigned int load;
 		int io_busy = 0;
 
-		j_cdbs = dbs_data->cdata->get_cpu_cdbs(j);
+		j_cdbs = dbs_data->gov->get_cpu_cdbs(j);
 
 		/*
 		 * For the purpose of ondemand, waiting for disk IO is
@@ -82,7 +82,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		 * not that the system is actually idle. So do not add
 		 * the iowait time to the cpu idle time.
 		 */
-		if (dbs_data->cdata->governor == GOV_ONDEMAND)
+		if (dbs_data->gov->governor == GOV_ONDEMAND)
 			io_busy = od_tuners->io_is_busy;
 		cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);
 
@@ -163,7 +163,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 			max_load = load;
 	}
 
-	dbs_data->cdata->gov_check_cpu(cpu, max_load);
+	dbs_data->gov->gov_check_cpu(cpu, max_load);
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
@@ -178,7 +178,7 @@ void gov_set_update_util(struct cpu_comm
 	shared->time_stamp = ktime_get();
 
 	for_each_cpu(cpu, policy->cpus) {
-		struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
+		struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
 
 		cdbs->last_sample_time = 0;
 		cpufreq_set_update_util_data(cpu, &cdbs->update_util);
@@ -222,7 +222,7 @@ static void dbs_work_handler(struct work
 	policy = shared->policy;
 	dbs_data = policy->governor_data;
 
-	if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
+	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 		sampling_rate = cs_tuners->sampling_rate;
@@ -238,7 +238,7 @@ static void dbs_work_handler(struct work
 	 * parallel.
 	 */
 	mutex_lock(&shared->timer_mutex);
-	delay = dbs_data->cdata->gov_dbs_timer(policy);
+	delay = dbs_data->gov->gov_dbs_timer(policy);
 	shared->sample_delay_ns = jiffies_to_nsecs(delay);
 	shared->time_stamp = ktime_get();
 	mutex_unlock(&shared->timer_mutex);
@@ -284,7 +284,7 @@ static void dbs_update_util_handler(stru
 static void set_sampling_rate(struct dbs_data *dbs_data,
 		unsigned int sampling_rate)
 {
-	if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
+	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 		cs_tuners->sampling_rate = sampling_rate;
 	} else {
@@ -294,7 +294,7 @@ static void set_sampling_rate(struct dbs
 }
 
 static int alloc_common_dbs_info(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
 	struct cpu_common_dbs_info *shared;
 	int j;
@@ -306,7 +306,7 @@ static int alloc_common_dbs_info(struct
 
 	/* Set shared for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
-		cdata->get_cpu_cdbs(j)->shared = shared;
+		gov->get_cpu_cdbs(j)->shared = shared;
 
 	mutex_init(&shared->timer_mutex);
 	atomic_set(&shared->skip_work, 0);
@@ -315,22 +315,22 @@ static int alloc_common_dbs_info(struct
 }
 
 static void free_common_dbs_info(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 	int j;
 
 	mutex_destroy(&shared->timer_mutex);
 
 	for_each_cpu(j, policy->cpus)
-		cdata->get_cpu_cdbs(j)->shared = NULL;
+		gov->get_cpu_cdbs(j)->shared = NULL;
 
 	kfree(shared);
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
 	struct dbs_data *dbs_data;
 	unsigned int latency;
@@ -344,7 +344,7 @@ static int cpufreq_governor_init(struct
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
-		ret = alloc_common_dbs_info(policy, cdata);
+		ret = alloc_common_dbs_info(policy, gov);
 		if (ret)
 			return ret;
 
@@ -357,14 +357,14 @@ static int cpufreq_governor_init(struct
 	if (!dbs_data)
 		return -ENOMEM;
 
-	ret = alloc_common_dbs_info(policy, cdata);
+	ret = alloc_common_dbs_info(policy, gov);
 	if (ret)
 		goto free_dbs_data;
 
-	dbs_data->cdata = cdata;
+	dbs_data->gov = gov;
 	dbs_data->usage_count = 1;
 
-	ret = cdata->init(dbs_data, !policy->governor->initialized);
+	ret = gov->init(dbs_data, !policy->governor->initialized);
 	if (ret)
 		goto free_common_dbs_info;
 
@@ -393,9 +393,9 @@ static int cpufreq_governor_init(struct
 	if (!have_governor_per_policy())
 		global_dbs_data = NULL;
 
-	cdata->exit(dbs_data, !policy->governor->initialized);
+	gov->exit(dbs_data, !policy->governor->initialized);
 free_common_dbs_info:
-	free_common_dbs_info(policy, cdata);
+	free_common_dbs_info(policy, gov);
 free_dbs_data:
 	kfree(dbs_data);
 	return ret;
@@ -404,8 +404,8 @@ free_dbs_data:
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
+	struct dbs_governor *gov = dbs_data->gov;
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to INIT */
 	if (!cdbs->shared || cdbs->shared->policy)
@@ -420,22 +420,22 @@ static int cpufreq_governor_exit(struct
 		if (!have_governor_per_policy())
 			global_dbs_data = NULL;
 
-		cdata->exit(dbs_data, policy->governor->initialized == 1);
+		gov->exit(dbs_data, policy->governor->initialized == 1);
 		kfree(dbs_data);
 	} else {
 		policy->governor_data = NULL;
 	}
 
-	free_common_dbs_info(policy, cdata);
+	free_common_dbs_info(policy, gov);
 	return 0;
 }
 
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
+	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 	int io_busy = 0;
 
@@ -446,7 +446,7 @@ static int cpufreq_governor_start(struct
 	if (!shared || shared->policy)
 		return -EBUSY;
 
-	if (cdata->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 		sampling_rate = cs_tuners->sampling_rate;
@@ -460,7 +460,7 @@ static int cpufreq_governor_start(struct
 	}
 
 	for_each_cpu(j, policy->cpus) {
-		struct cpu_dbs_info *j_cdbs = cdata->get_cpu_cdbs(j);
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
 		unsigned int prev_load;
 
 		j_cdbs->prev_cpu_idle =
@@ -479,15 +479,15 @@ static int cpufreq_governor_start(struct
 	shared->policy = policy;
 	init_irq_work(&shared->irq_work, dbs_irq_work);
 
-	if (cdata->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
-			cdata->get_cpu_dbs_info_s(cpu);
+			gov->get_cpu_dbs_info_s(cpu);
 
 		cs_dbs_info->down_skip = 0;
 		cs_dbs_info->requested_freq = policy->cur;
 	} else {
-		struct od_ops *od_ops = cdata->gov_ops;
-		struct od_cpu_dbs_info_s *od_dbs_info = cdata->get_cpu_dbs_info_s(cpu);
+		struct od_ops *od_ops = gov->gov_ops;
+		struct od_cpu_dbs_info_s *od_dbs_info = gov->get_cpu_dbs_info_s(cpu);
 
 		od_dbs_info->rate_mult = 1;
 		od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
@@ -501,7 +501,7 @@ static int cpufreq_governor_start(struct
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
+	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
 	/* State should be equivalent to START */
@@ -517,9 +517,9 @@ static int cpufreq_governor_stop(struct
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
+	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
 	/* State should be equivalent to START */
 	if (!cdbs->shared || !cdbs->shared->policy)
@@ -539,7 +539,7 @@ static int cpufreq_governor_limits(struc
 }
 
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-			 struct common_dbs_data *cdata, unsigned int event)
+			 struct dbs_governor *gov, unsigned int event)
 {
 	int ret = -EINVAL;
 
@@ -547,7 +547,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	mutex_lock(&dbs_data_mutex);
 
 	if (event == CPUFREQ_GOV_POLICY_INIT) {
-		ret = cpufreq_governor_init(policy, cdata);
+		ret = cpufreq_governor_init(policy, gov);
 	} else if (policy->governor_data) {
 		switch (event) {
 		case CPUFREQ_GOV_POLICY_EXIT:
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -200,7 +200,7 @@ struct cs_dbs_tuners {
 
 /* Common Governor data across policies */
 struct dbs_data;
-struct common_dbs_data {
+struct dbs_governor {
 	struct cpufreq_governor gov;
 
 	#define GOV_ONDEMAND		0
@@ -222,7 +222,7 @@ struct common_dbs_data {
 
 /* Governor Per policy data */
 struct dbs_data {
-	struct common_dbs_data *cdata;
+	struct dbs_governor *gov;
 	unsigned int min_sampling_rate;
 	int usage_count;
 	void *tuners;
@@ -274,7 +274,7 @@ void gov_set_update_util(struct cpu_comm
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		struct common_dbs_data *cdata, unsigned int event);
+		struct dbs_governor *gov, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
 		unsigned int powersave_bias);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -223,7 +223,7 @@ static unsigned int od_dbs_timer(struct
 }
 
 /************************** sysfs interface ************************/
-static struct common_dbs_data od_dbs_cdata;
+static struct dbs_governor od_dbs_gov;
 
 /**
  * update_sampling_rate - update sampling rate effective immediately if needed.
@@ -542,7 +542,7 @@ static struct od_ops od_ops = {
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-static struct common_dbs_data od_dbs_cdata = {
+static struct dbs_governor od_dbs_gov = {
 	.gov = {
 		.name = "ondemand",
 		.governor = od_cpufreq_governor_dbs,
@@ -561,12 +561,12 @@ static struct common_dbs_data od_dbs_cda
 	.exit = od_exit,
 };
 
-#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_cdata.gov)
+#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_gov.gov)
 
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		unsigned int event)
 {
-	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
+	return cpufreq_governor_dbs(policy, &od_dbs_gov, event);
 }
 
 static void od_set_powersave_bias(unsigned int powersave_bias)
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_t
 	struct dbs_data *od_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
-		od_data->cdata->get_cpu_dbs_info_s(policy->cpu);
+		od_data->gov->get_cpu_dbs_info_s(policy->cpu);
 
 	if (!od_info->freq_table)
 		return freq_next;

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

* [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs()
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (5 preceding siblings ...)
  2016-02-03 23:32 ` [PATCH 6/11] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
@ 2016-02-03 23:33 ` Rafael J. Wysocki
  2016-02-04  2:03   ` Saravana Kannan
  2016-02-03 23:35 ` [PATCH 8/11] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:33 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since it is possible to obtain a pointer to struct dbs_governor
from a pointer to the struct governor embedded in it via
container_of(), the second argument of cpufreq_governor_init()
is not necessary.  Accordingly, cpufreq_governor_dbs() doesn't
need its second argument either and the ->governor callbacks
for both the ondemand and conservative governors may be set
to cpufreq_governor_dbs() directly.  Make that happen.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |   11 +----------
 drivers/cpufreq/cpufreq_governor.c     |   10 +++++-----
 drivers/cpufreq/cpufreq_governor.h     |    3 +--
 drivers/cpufreq/cpufreq_ondemand.c     |   11 +----------
 4 files changed, 8 insertions(+), 27 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbs
 
 define_get_cpu_dbs_routines(cs_cpu_dbs_info);
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
 static struct dbs_governor cs_dbs_gov = {
 	.gov = {
 		.name = "conservative",
-		.governor = cs_cpufreq_governor_dbs,
+		.governor = cpufreq_governor_dbs,
 		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
 		.owner = THIS_MODULE,
 	},
@@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =
 
 #define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_gov.gov)
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &cs_dbs_gov, event);
-}
-
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
 				void *data)
 {
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -329,9 +329,9 @@ static void free_common_dbs_info(struct
 	kfree(shared);
 }
 
-static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct dbs_governor *gov)
+static int cpufreq_governor_init(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov;
 	struct dbs_data *dbs_data;
 	unsigned int latency;
 	int ret;
@@ -340,6 +340,7 @@ static int cpufreq_governor_init(struct
 	if (policy->governor_data)
 		return -EBUSY;
 
+	gov = container_of(policy->governor, struct dbs_governor, gov);
 	if (global_dbs_data) {
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
@@ -538,8 +539,7 @@ static int cpufreq_governor_limits(struc
 	return 0;
 }
 
-int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-			 struct dbs_governor *gov, unsigned int event)
+int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event)
 {
 	int ret = -EINVAL;
 
@@ -547,7 +547,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	mutex_lock(&dbs_data_mutex);
 
 	if (event == CPUFREQ_GOV_POLICY_INIT) {
-		ret = cpufreq_governor_init(policy, gov);
+		ret = cpufreq_governor_init(policy);
 	} else if (policy->governor_data) {
 		switch (event) {
 		case CPUFREQ_GOV_POLICY_EXIT:
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -273,8 +273,7 @@ void gov_set_update_util(struct cpu_comm
 			 unsigned int delay_us);
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
-int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		struct dbs_governor *gov, unsigned int event);
+int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
 		unsigned int powersave_bias);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -539,13 +539,10 @@ static struct od_ops od_ops = {
 	.freq_increase = dbs_freq_increase,
 };
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
 static struct dbs_governor od_dbs_gov = {
 	.gov = {
 		.name = "ondemand",
-		.governor = od_cpufreq_governor_dbs,
+		.governor = cpufreq_governor_dbs,
 		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
 		.owner = THIS_MODULE,
 	},
@@ -563,12 +560,6 @@ static struct dbs_governor od_dbs_gov =
 
 #define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_gov.gov)
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &od_dbs_gov, event);
-}
-
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;

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

* [PATCH 8/11] cpufreq: governor: Drop the gov pointer from struct dbs_data
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (6 preceding siblings ...)
  2016-02-03 23:33 ` [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
@ 2016-02-03 23:35 ` Rafael J. Wysocki
  2016-02-03 23:35 ` [PATCH 9/11] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:35 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since it is possible to obtain a pointer to struct dbs_governor
from a pointer to the struct governor embedded in it with the help
of container_of(), the additional gov pointer in struct dbs_data
isn't really necessary.

Drop that pointer and make the code using it reach the dbs_governor
object via policy->governor.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |    2 -
 drivers/cpufreq/cpufreq_governor.c     |   62 ++++++++++++++++-----------------
 drivers/cpufreq/cpufreq_governor.h     |    8 +++-
 drivers/cpufreq/cpufreq_ondemand.c     |    2 -
 4 files changed, 39 insertions(+), 35 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -220,9 +220,13 @@ struct dbs_governor {
 	void *gov_ops;
 };
 
+static inline struct dbs_governor *dbs_governor_of(struct cpufreq_policy *policy)
+{
+	return container_of(policy->governor, struct dbs_governor, gov);
+}
+
 /* Governor Per policy data */
 struct dbs_data {
-	struct dbs_governor *gov;
 	unsigned int min_sampling_rate;
 	int usage_count;
 	void *tuners;
@@ -272,7 +276,7 @@ extern struct mutex cpufreq_governor_loc
 void gov_set_update_util(struct cpu_common_dbs_info *shared,
 			 unsigned int delay_us);
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
-void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
+void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
-	dbs_check_cpu(dbs_data, policy->cpu);
+	dbs_check_cpu(policy, policy->cpu);
 	return delay_for_sampling_rate(cs_tuners->sampling_rate);
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -28,28 +28,27 @@ EXPORT_SYMBOL_GPL(global_dbs_data);
 DEFINE_MUTEX(dbs_data_mutex);
 EXPORT_SYMBOL_GPL(dbs_data_mutex);
 
-static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
+static struct attribute_group *get_sysfs_attr(struct dbs_governor *gov)
 {
-	if (have_governor_per_policy())
-		return dbs_data->gov->attr_group_gov_pol;
-	else
-		return dbs_data->gov->attr_group_gov_sys;
+	return have_governor_per_policy() ?
+		gov->attr_group_gov_pol : gov->attr_group_gov_sys;
 }
 
-void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
+void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
 {
-	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
+	struct dbs_governor *gov = dbs_governor_of(policy);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
-	struct cpufreq_policy *policy = cdbs->shared->policy;
 	unsigned int sampling_rate;
 	unsigned int max_load = 0;
 	unsigned int ignore_nice;
 	unsigned int j;
 
-	if (dbs_data->gov->governor == GOV_ONDEMAND) {
+	if (gov->governor == GOV_ONDEMAND) {
 		struct od_cpu_dbs_info_s *od_dbs_info =
-				dbs_data->gov->get_cpu_dbs_info_s(cpu);
+				gov->get_cpu_dbs_info_s(cpu);
 
 		/*
 		 * Sometimes, the ondemand governor uses an additional
@@ -74,7 +73,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		unsigned int load;
 		int io_busy = 0;
 
-		j_cdbs = dbs_data->gov->get_cpu_cdbs(j);
+		j_cdbs = gov->get_cpu_cdbs(j);
 
 		/*
 		 * For the purpose of ondemand, waiting for disk IO is
@@ -82,7 +81,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		 * not that the system is actually idle. So do not add
 		 * the iowait time to the cpu idle time.
 		 */
-		if (dbs_data->gov->governor == GOV_ONDEMAND)
+		if (gov->governor == GOV_ONDEMAND)
 			io_busy = od_tuners->io_is_busy;
 		cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);
 
@@ -163,7 +162,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 			max_load = load;
 	}
 
-	dbs_data->gov->gov_check_cpu(cpu, max_load);
+	gov->gov_check_cpu(cpu, max_load);
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
@@ -171,14 +170,14 @@ void gov_set_update_util(struct cpu_comm
 			 unsigned int delay_us)
 {
 	struct cpufreq_policy *policy = shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	int cpu;
 
 	shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
 	shared->time_stamp = ktime_get();
 
 	for_each_cpu(cpu, policy->cpus) {
-		struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
+		struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
 		cdbs->last_sample_time = 0;
 		cpufreq_set_update_util_data(cpu, &cdbs->update_util);
@@ -216,13 +215,15 @@ static void dbs_work_handler(struct work
 	struct cpu_common_dbs_info *shared = container_of(work, struct
 					cpu_common_dbs_info, work);
 	struct cpufreq_policy *policy;
+	struct dbs_governor *gov;
 	struct dbs_data *dbs_data;
 	unsigned int sampling_rate, delay;
 
 	policy = shared->policy;
 	dbs_data = policy->governor_data;
+	gov = dbs_governor_of(policy);
 
-	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 		sampling_rate = cs_tuners->sampling_rate;
@@ -238,7 +239,7 @@ static void dbs_work_handler(struct work
 	 * parallel.
 	 */
 	mutex_lock(&shared->timer_mutex);
-	delay = dbs_data->gov->gov_dbs_timer(policy);
+	delay = gov->gov_dbs_timer(policy);
 	shared->sample_delay_ns = jiffies_to_nsecs(delay);
 	shared->time_stamp = ktime_get();
 	mutex_unlock(&shared->timer_mutex);
@@ -282,9 +283,10 @@ static void dbs_update_util_handler(stru
 }
 
 static void set_sampling_rate(struct dbs_data *dbs_data,
-		unsigned int sampling_rate)
+			      struct dbs_governor *gov,
+			      unsigned int sampling_rate)
 {
-	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 		cs_tuners->sampling_rate = sampling_rate;
 	} else {
@@ -340,7 +342,7 @@ static int cpufreq_governor_init(struct
 	if (policy->governor_data)
 		return -EBUSY;
 
-	gov = container_of(policy->governor, struct dbs_governor, gov);
+	gov = dbs_governor_of(policy);
 	if (global_dbs_data) {
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
@@ -362,7 +364,6 @@ static int cpufreq_governor_init(struct
 	if (ret)
 		goto free_dbs_data;
 
-	dbs_data->gov = gov;
 	dbs_data->usage_count = 1;
 
 	ret = gov->init(dbs_data, !policy->governor->initialized);
@@ -377,7 +378,7 @@ static int cpufreq_governor_init(struct
 	/* Bring kernel and HW constraints together */
 	dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate,
 					  MIN_LATENCY_MULTIPLIER * latency);
-	set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate,
+	set_sampling_rate(dbs_data, gov, max(dbs_data->min_sampling_rate,
 					latency * LATENCY_MULTIPLIER));
 
 	if (!have_governor_per_policy())
@@ -386,7 +387,7 @@ static int cpufreq_governor_init(struct
 	policy->governor_data = dbs_data;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
-				 get_sysfs_attr(dbs_data));
+				 get_sysfs_attr(gov));
 	if (!ret)
 		return 0;
 
@@ -404,8 +405,8 @@ free_dbs_data:
 
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to INIT */
@@ -414,7 +415,7 @@ static int cpufreq_governor_exit(struct
 
 	if (!--dbs_data->usage_count) {
 		sysfs_remove_group(get_governor_parent_kobj(policy),
-				   get_sysfs_attr(dbs_data));
+				   get_sysfs_attr(gov));
 
 		policy->governor_data = NULL;
 
@@ -433,8 +434,8 @@ static int cpufreq_governor_exit(struct
 
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
@@ -501,8 +502,8 @@ static int cpufreq_governor_start(struct
 
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(policy->cpu);
+	struct dbs_governor *gov = dbs_governor_of(policy);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
 	/* State should be equivalent to START */
@@ -517,8 +518,7 @@ static int cpufreq_governor_stop(struct
 
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	unsigned int cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
@@ -533,7 +533,7 @@ static int cpufreq_governor_limits(struc
 	else if (policy->min > cdbs->shared->policy->cur)
 		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
 					CPUFREQ_RELATION_L);
-	dbs_check_cpu(dbs_data, cpu);
+	dbs_check_cpu(policy, cpu);
 	mutex_unlock(&cdbs->shared->timer_mutex);
 
 	return 0;
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -207,7 +207,7 @@ static unsigned int od_dbs_timer(struct
 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
 					CPUFREQ_RELATION_H);
 	} else {
-		dbs_check_cpu(dbs_data, cpu);
+		dbs_check_cpu(policy, cpu);
 		if (dbs_info->freq_lo) {
 			/* Setup timer for SUB_SAMPLE */
 			dbs_info->sample_type = OD_SUB_SAMPLE;

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

* [PATCH 9/11] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (7 preceding siblings ...)
  2016-02-03 23:35 ` [PATCH 8/11] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
@ 2016-02-03 23:35 ` Rafael J. Wysocki
  2016-02-03 23:37 ` [PATCH 10/11] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:35 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The struct cpu_common_dbs_info structure represents the per-policy
part of the governor data (for the ondemand and conservative
governors), but its name doesn't reflect its purpose.

Rename it to struct policy_dbs_info and rename variables related to
it accordingly.

No functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |  106 ++++++++++++++++++-------------------
 drivers/cpufreq/cpufreq_governor.h |    8 +-
 drivers/cpufreq/cpufreq_ondemand.c |   32 +++++------
 3 files changed, 73 insertions(+), 73 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -131,7 +131,7 @@ static void *get_cpu_dbs_info_s(int cpu)
  */
 
 /* Common to all CPUs of a policy */
-struct cpu_common_dbs_info {
+struct policy_dbs_info {
 	struct cpufreq_policy *policy;
 	/*
 	 * Per policy mutex that serializes load evaluation from limit-change
@@ -160,7 +160,7 @@ struct cpu_dbs_info {
 	unsigned int prev_load;
 	u64 last_sample_time;
 	struct update_util_data update_util;
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *shared;
 };
 
 struct od_cpu_dbs_info_s {
@@ -273,9 +273,9 @@ static ssize_t show_sampling_rate_min_go
 
 extern struct mutex dbs_data_mutex;
 extern struct mutex cpufreq_governor_lock;
-void gov_set_update_util(struct cpu_common_dbs_info *shared,
+void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us);
-void gov_cancel_work(struct cpu_common_dbs_info *shared);
+void gov_cancel_work(struct policy_dbs_info *policy_dbs);
 void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -166,15 +166,15 @@ void dbs_check_cpu(struct cpufreq_policy
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
-void gov_set_update_util(struct cpu_common_dbs_info *shared,
+void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us)
 {
-	struct cpufreq_policy *policy = shared->policy;
+	struct cpufreq_policy *policy = policy_dbs->policy;
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	int cpu;
 
-	shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
-	shared->time_stamp = ktime_get();
+	policy_dbs->sample_delay_ns = delay_us * NSEC_PER_USEC;
+	policy_dbs->time_stamp = ktime_get();
 
 	for_each_cpu(cpu, policy->cpus) {
 		struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
@@ -195,31 +195,31 @@ static inline void gov_clear_update_util
 	synchronize_rcu();
 }
 
-void gov_cancel_work(struct cpu_common_dbs_info *shared)
+void gov_cancel_work(struct policy_dbs_info *policy_dbs)
 {
 	/* Tell dbs_update_util_handler() to skip queuing up work items. */
-	atomic_inc(&shared->skip_work);
+	atomic_inc(&policy_dbs->skip_work);
 	/*
 	 * If dbs_update_util_handler() is already running, it may not notice
 	 * the incremented skip_work, so wait for it to complete to prevent its
 	 * work item from being queued up after the cancel_work_sync() below.
 	 */
-	gov_clear_update_util(shared->policy);
-	cancel_work_sync(&shared->work);
-	atomic_set(&shared->skip_work, 0);
+	gov_clear_update_util(policy_dbs->policy);
+	cancel_work_sync(&policy_dbs->work);
+	atomic_set(&policy_dbs->skip_work, 0);
 }
 EXPORT_SYMBOL_GPL(gov_cancel_work);
 
 static void dbs_work_handler(struct work_struct *work)
 {
-	struct cpu_common_dbs_info *shared = container_of(work, struct
-					cpu_common_dbs_info, work);
+	struct policy_dbs_info *policy_dbs;
 	struct cpufreq_policy *policy;
 	struct dbs_governor *gov;
 	struct dbs_data *dbs_data;
 	unsigned int sampling_rate, delay;
 
-	policy = shared->policy;
+	policy_dbs = container_of(work, struct policy_dbs_info, work);
+	policy = policy_dbs->policy;
 	dbs_data = policy->governor_data;
 	gov = dbs_governor_of(policy);
 
@@ -238,29 +238,29 @@ static void dbs_work_handler(struct work
 	 * ondemand governor isn't reading the time stamp and sampling rate in
 	 * parallel.
 	 */
-	mutex_lock(&shared->timer_mutex);
+	mutex_lock(&policy_dbs->timer_mutex);
 	delay = gov->gov_dbs_timer(policy);
-	shared->sample_delay_ns = jiffies_to_nsecs(delay);
-	shared->time_stamp = ktime_get();
-	mutex_unlock(&shared->timer_mutex);
+	policy_dbs->sample_delay_ns = jiffies_to_nsecs(delay);
+	policy_dbs->time_stamp = ktime_get();
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	smp_mb__before_atomic();
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void dbs_irq_work(struct irq_work *irq_work)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 
-	shared = container_of(irq_work, struct cpu_common_dbs_info, irq_work);
-	schedule_work(&shared->work);
+	policy_dbs = container_of(irq_work, struct policy_dbs_info, irq_work);
+	schedule_work(&policy_dbs->work);
 }
 
 static void dbs_update_util_handler(struct update_util_data *data, u64 time,
 				    unsigned long util, unsigned long max)
 {
 	struct cpu_dbs_info *cdbs = container_of(data, struct cpu_dbs_info, update_util);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 
 	/*
 	 * The work may not be allowed to be queued up right now.
@@ -269,17 +269,17 @@ static void dbs_update_util_handler(stru
 	 * - The governor is being stopped.
 	 * - It is too early (too little time from the previous sample).
 	 */
-	if (atomic_inc_return(&shared->skip_work) == 1) {
+	if (atomic_inc_return(&policy_dbs->skip_work) == 1) {
 		u64 delta_ns;
 
 		delta_ns = time - cdbs->last_sample_time;
-		if ((s64)delta_ns >= shared->sample_delay_ns) {
+		if ((s64)delta_ns >= policy_dbs->sample_delay_ns) {
 			cdbs->last_sample_time = time;
-			irq_work_queue_on(&shared->irq_work, smp_processor_id());
+			irq_work_queue_on(&policy_dbs->irq_work, smp_processor_id());
 			return;
 		}
 	}
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void set_sampling_rate(struct dbs_data *dbs_data,
@@ -295,40 +295,40 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_common_dbs_info(struct cpufreq_policy *policy,
+static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 	int j;
 
 	/* Allocate memory for the common information for policy->cpus */
-	shared = kzalloc(sizeof(*shared), GFP_KERNEL);
-	if (!shared)
+	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
+	if (!policy_dbs)
 		return -ENOMEM;
 
-	/* Set shared for all CPUs, online+offline */
+	/* Set policy_dbs for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->shared = shared;
+		gov->get_cpu_cdbs(j)->shared = policy_dbs;
 
-	mutex_init(&shared->timer_mutex);
-	atomic_set(&shared->skip_work, 0);
-	INIT_WORK(&shared->work, dbs_work_handler);
+	mutex_init(&policy_dbs->timer_mutex);
+	atomic_set(&policy_dbs->skip_work, 0);
+	INIT_WORK(&policy_dbs->work, dbs_work_handler);
 	return 0;
 }
 
-static void free_common_dbs_info(struct cpufreq_policy *policy,
+static void free_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int j;
 
-	mutex_destroy(&shared->timer_mutex);
+	mutex_destroy(&policy_dbs->timer_mutex);
 
 	for_each_cpu(j, policy->cpus)
 		gov->get_cpu_cdbs(j)->shared = NULL;
 
-	kfree(shared);
+	kfree(policy_dbs);
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
@@ -347,7 +347,7 @@ static int cpufreq_governor_init(struct
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
-		ret = alloc_common_dbs_info(policy, gov);
+		ret = alloc_policy_dbs_info(policy, gov);
 		if (ret)
 			return ret;
 
@@ -360,7 +360,7 @@ static int cpufreq_governor_init(struct
 	if (!dbs_data)
 		return -ENOMEM;
 
-	ret = alloc_common_dbs_info(policy, gov);
+	ret = alloc_policy_dbs_info(policy, gov);
 	if (ret)
 		goto free_dbs_data;
 
@@ -368,7 +368,7 @@ static int cpufreq_governor_init(struct
 
 	ret = gov->init(dbs_data, !policy->governor->initialized);
 	if (ret)
-		goto free_common_dbs_info;
+		goto free_policy_dbs_info;
 
 	/* policy latency is in ns. Convert it to us first */
 	latency = policy->cpuinfo.transition_latency / 1000;
@@ -396,8 +396,8 @@ static int cpufreq_governor_init(struct
 		global_dbs_data = NULL;
 
 	gov->exit(dbs_data, !policy->governor->initialized);
-free_common_dbs_info:
-	free_common_dbs_info(policy, gov);
+free_policy_dbs_info:
+	free_policy_dbs_info(policy, gov);
 free_dbs_data:
 	kfree(dbs_data);
 	return ret;
@@ -428,7 +428,7 @@ static int cpufreq_governor_exit(struct
 		policy->governor_data = NULL;
 	}
 
-	free_common_dbs_info(policy, gov);
+	free_policy_dbs_info(policy, gov);
 	return 0;
 }
 
@@ -438,14 +438,14 @@ static int cpufreq_governor_start(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!shared || shared->policy)
+	if (!policy_dbs || policy_dbs->policy)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -478,8 +478,8 @@ static int cpufreq_governor_start(struct
 
 		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
-	shared->policy = policy;
-	init_irq_work(&shared->irq_work, dbs_irq_work);
+	policy_dbs->policy = policy;
+	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -496,7 +496,7 @@ static int cpufreq_governor_start(struct
 		od_ops->powersave_bias_init_cpu(cpu);
 	}
 
-	gov_set_update_util(shared, sampling_rate);
+	gov_set_update_util(policy_dbs, sampling_rate);
 	return 0;
 }
 
@@ -504,14 +504,14 @@ static int cpufreq_governor_stop(struct
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 
 	/* State should be equivalent to START */
-	if (!shared || !shared->policy)
+	if (!policy_dbs || !policy_dbs->policy)
 		return -EBUSY;
 
-	gov_cancel_work(shared);
-	shared->policy = NULL;
+	gov_cancel_work(policy_dbs);
+	policy_dbs->policy = NULL;
 
 	return 0;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -259,21 +259,21 @@ static void update_sampling_rate(struct
 		struct cpufreq_policy *policy;
 		struct od_cpu_dbs_info_s *dbs_info;
 		struct cpu_dbs_info *cdbs;
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 		ktime_t next_sampling, appointed_at;
 
 		dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
 		cdbs = &dbs_info->cdbs;
-		shared = cdbs->shared;
+		policy_dbs = cdbs->shared;
 
 		/*
-		 * A valid shared and shared->policy means governor hasn't
-		 * stopped or exited yet.
+		 * A valid policy_dbs and policy_dbs->policy means governor
+		 * hasn't stopped or exited yet.
 		 */
-		if (!shared || !shared->policy)
+		if (!policy_dbs || !policy_dbs->policy)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 
 		/* clear all CPUs of this policy */
 		cpumask_andnot(&cpumask, &cpumask, policy->cpus);
@@ -293,14 +293,14 @@ static void update_sampling_rate(struct
 		 */
 		next_sampling = ktime_add_us(ktime_get(), new_rate);
 
-		mutex_lock(&shared->timer_mutex);
-		appointed_at = ktime_add_ns(shared->time_stamp,
-					    shared->sample_delay_ns);
-		mutex_unlock(&shared->timer_mutex);
+		mutex_lock(&policy_dbs->timer_mutex);
+		appointed_at = ktime_add_ns(policy_dbs->time_stamp,
+					    policy_dbs->sample_delay_ns);
+		mutex_unlock(&policy_dbs->timer_mutex);
 
 		if (ktime_before(next_sampling, appointed_at)) {
-			gov_cancel_work(shared);
-			gov_set_update_util(shared, new_rate);
+			gov_cancel_work(policy_dbs);
+			gov_set_update_util(policy_dbs, new_rate);
 		}
 	}
 
@@ -573,16 +573,16 @@ static void od_set_powersave_bias(unsign
 
 	get_online_cpus();
 	for_each_online_cpu(cpu) {
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 
 		if (cpumask_test_cpu(cpu, &done))
 			continue;
 
-		shared = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared;
-		if (!shared)
+		policy_dbs = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared;
+		if (!policy_dbs)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 		cpumask_or(&done, &done, policy->cpus);
 
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)

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

* [PATCH 10/11] cpufreq: governor: Rearrange governor data structures
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (8 preceding siblings ...)
  2016-02-03 23:35 ` [PATCH 9/11] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
@ 2016-02-03 23:37 ` Rafael J. Wysocki
  2016-02-03 23:38 ` [PATCH 11/11] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:37 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The struct policy_dbs_info objects representing per-policy governor
data are not accessible directly from the corresponding policy
objects.  To access them, one has to get a pointer to the
struct cpu_dbs_info of policy->cpu and use the "shared" field of
that which isn't really straightforward.

To address that rearrange the governor data structures so the
governor_data pointer in struct cpufreq_policy will point to
struct policy_dbs_info and that will contain a pointer to
struct dbs_data.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    3 
 drivers/cpufreq/cpufreq_conservative.c |    6 +
 drivers/cpufreq/cpufreq_governor.c     |  116 ++++++++++++++-------------------
 drivers/cpufreq/cpufreq_governor.h     |   27 ++++---
 drivers/cpufreq/cpufreq_ondemand.c     |   18 +++--
 5 files changed, 83 insertions(+), 87 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -85,7 +85,8 @@ static ssize_t show_##file_name##_gov_sy
 static ssize_t show_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	struct _gov##_dbs_tuners *tuners = dbs_data->tuners;		\
 	return sprintf(buf, "%u\n", tuners->file_name);			\
 }
@@ -101,8 +102,8 @@ static ssize_t store_##file_name##_gov_s
 static ssize_t store_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, const char *buf, size_t count)		\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
-	return store_##file_name(dbs_data, buf, count);			\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	return store_##file_name(policy_dbs->dbs_data, buf, count);			\
 }
 
 #define show_store_one(_gov, file_name)					\
@@ -130,6 +131,13 @@ static void *get_cpu_dbs_info_s(int cpu)
  * cs_*: Conservative governor
  */
 
+/* Governor demand based switching data (per-policy or global). */
+struct dbs_data {
+	unsigned int min_sampling_rate;
+	int usage_count;
+	void *tuners;
+};
+
 /* Common to all CPUs of a policy */
 struct policy_dbs_info {
 	struct cpufreq_policy *policy;
@@ -144,6 +152,8 @@ struct policy_dbs_info {
 	atomic_t skip_work;
 	struct irq_work irq_work;
 	struct work_struct work;
+	/* dbs_data may be shared between multiple policy objects */
+	struct dbs_data *dbs_data;
 };
 
 /* Per cpu structures */
@@ -199,7 +209,6 @@ struct cs_dbs_tuners {
 };
 
 /* Common Governor data across policies */
-struct dbs_data;
 struct dbs_governor {
 	struct cpufreq_governor gov;
 
@@ -225,13 +234,6 @@ static inline struct dbs_governor *dbs_g
 	return container_of(policy->governor, struct dbs_governor, gov);
 }
 
-/* Governor Per policy data */
-struct dbs_data {
-	unsigned int min_sampling_rate;
-	int usage_count;
-	void *tuners;
-};
-
 /*
  * Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
  */
@@ -267,7 +269,8 @@ static ssize_t show_sampling_rate_min_go
 static ssize_t show_sampling_rate_min_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -37,8 +37,8 @@ static struct attribute_group *get_sysfs
 void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	unsigned int sampling_rate;
@@ -97,6 +97,7 @@ void dbs_check_cpu(struct cpufreq_policy
 		j_cdbs->prev_cpu_idle = cur_idle_time;
 
 		if (ignore_nice) {
+			struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 			u64 cur_nice;
 			unsigned long cur_nice_jiffies;
 
@@ -220,8 +221,8 @@ static void dbs_work_handler(struct work
 
 	policy_dbs = container_of(work, struct policy_dbs_info, work);
 	policy = policy_dbs->policy;
-	dbs_data = policy->governor_data;
 	gov = dbs_governor_of(policy);
+	dbs_data = policy_dbs->dbs_data;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
@@ -295,8 +296,8 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
-				 struct dbs_governor *gov)
+static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
+						     struct dbs_governor *gov)
 {
 	struct policy_dbs_info *policy_dbs;
 	int j;
@@ -304,16 +305,21 @@ static int alloc_policy_dbs_info(struct
 	/* Allocate memory for the common information for policy->cpus */
 	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
 	if (!policy_dbs)
-		return -ENOMEM;
+		return NULL;
 
 	/* Set policy_dbs for all CPUs, online+offline */
-	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->shared = policy_dbs;
+	for_each_cpu(j, policy->related_cpus) {
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
 
+		j_cdbs->shared = policy_dbs;
+		j_cdbs->update_util.func = dbs_update_util_handler;
+	}
+	policy_dbs->policy = policy;
 	mutex_init(&policy_dbs->timer_mutex);
 	atomic_set(&policy_dbs->skip_work, 0);
+	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 	INIT_WORK(&policy_dbs->work, dbs_work_handler);
-	return 0;
+	return policy_dbs;
 }
 
 static void free_policy_dbs_info(struct cpufreq_policy *policy,
@@ -334,6 +340,7 @@ static void free_policy_dbs_info(struct
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov;
+	struct policy_dbs_info *policy_dbs;
 	struct dbs_data *dbs_data;
 	unsigned int latency;
 	int ret;
@@ -343,26 +350,26 @@ static int cpufreq_governor_init(struct
 		return -EBUSY;
 
 	gov = dbs_governor_of(policy);
-	if (global_dbs_data) {
-		if (WARN_ON(have_governor_per_policy()))
-			return -EINVAL;
-
-		ret = alloc_policy_dbs_info(policy, gov);
-		if (ret)
-			return ret;
+	policy_dbs = alloc_policy_dbs_info(policy, gov);
+	if (!policy_dbs)
+		return -ENOMEM;
 
+	if (global_dbs_data) {
+		if (WARN_ON(have_governor_per_policy())) {
+			ret = -EINVAL;
+			goto free_policy_dbs_info;
+		}
 		global_dbs_data->usage_count++;
-		policy->governor_data = global_dbs_data;
+		policy_dbs->dbs_data = global_dbs_data;
+		policy->governor_data = policy_dbs;
 		return 0;
 	}
 
 	dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL);
-	if (!dbs_data)
-		return -ENOMEM;
-
-	ret = alloc_policy_dbs_info(policy, gov);
-	if (ret)
-		goto free_dbs_data;
+	if (!dbs_data) {
+		ret = -ENOMEM;
+		goto free_policy_dbs_info;
+	}
 
 	dbs_data->usage_count = 1;
 
@@ -384,7 +391,8 @@ static int cpufreq_governor_init(struct
 	if (!have_governor_per_policy())
 		global_dbs_data = dbs_data;
 
-	policy->governor_data = dbs_data;
+	policy_dbs->dbs_data = dbs_data;
+	policy->governor_data = policy_dbs;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
 				 get_sysfs_attr(gov));
@@ -396,38 +404,35 @@ static int cpufreq_governor_init(struct
 		global_dbs_data = NULL;
 
 	gov->exit(dbs_data, !policy->governor->initialized);
+	kfree(dbs_data);
+
 free_policy_dbs_info:
 	free_policy_dbs_info(policy, gov);
-free_dbs_data:
-	kfree(dbs_data);
 	return ret;
 }
 
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 
 	/* State should be equivalent to INIT */
-	if (!cdbs->shared || cdbs->shared->policy)
+	if (!dbs_data)
 		return -EBUSY;
 
 	if (!--dbs_data->usage_count) {
 		sysfs_remove_group(get_governor_parent_kobj(policy),
 				   get_sysfs_attr(gov));
 
-		policy->governor_data = NULL;
-
 		if (!have_governor_per_policy())
 			global_dbs_data = NULL;
 
 		gov->exit(dbs_data, policy->governor->initialized == 1);
 		kfree(dbs_data);
-	} else {
-		policy->governor_data = NULL;
 	}
 
+	policy->governor_data = NULL;
 	free_policy_dbs_info(policy, gov);
 	return 0;
 }
@@ -435,17 +440,16 @@ static int cpufreq_governor_exit(struct
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!policy_dbs || policy_dbs->policy)
+	if (!dbs_data)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -475,11 +479,7 @@ static int cpufreq_governor_start(struct
 
 		if (ignore_nice)
 			j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
-
-		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
-	policy_dbs->policy = policy;
-	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -502,39 +502,25 @@ static int cpufreq_governor_start(struct
 
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->shared;
-
-	/* State should be equivalent to START */
-	if (!policy_dbs || !policy_dbs->policy)
-		return -EBUSY;
-
-	gov_cancel_work(policy_dbs);
-	policy_dbs->policy = NULL;
-
+	gov_cancel_work(policy->governor_data);
 	return 0;
 }
 
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	unsigned int cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
 
 	/* State should be equivalent to START */
-	if (!cdbs->shared || !cdbs->shared->policy)
+	if (!policy_dbs->dbs_data)
 		return -EBUSY;
 
-	mutex_lock(&cdbs->shared->timer_mutex);
-	if (policy->max < cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->max,
-					CPUFREQ_RELATION_H);
-	else if (policy->min > cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
-					CPUFREQ_RELATION_L);
-	dbs_check_cpu(policy, cpu);
-	mutex_unlock(&cdbs->shared->timer_mutex);
+	mutex_lock(&policy_dbs->timer_mutex);
+	if (policy->max < policy->cur)
+		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
+	else if (policy->min > policy->cur)
+		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
+	dbs_check_cpu(policy, policy->cpu);
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	return 0;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -82,7 +82,8 @@ static unsigned int generic_powersave_bi
 	unsigned int jiffies_total, jiffies_hi, jiffies_lo;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
 						   policy->cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (!dbs_info->freq_table) {
@@ -134,7 +135,8 @@ static void ondemand_powersave_bias_init
 
 static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (od_tuners->powersave_bias)
@@ -155,8 +157,9 @@ static void dbs_freq_increase(struct cpu
 static void od_check_cpu(int cpu, unsigned int load)
 {
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
-	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = dbs_info->cdbs.shared;
+	struct cpufreq_policy *policy = policy_dbs->policy;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	dbs_info->freq_lo = 0;
@@ -193,7 +196,8 @@ static void od_check_cpu(int cpu, unsign
 
 static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	unsigned int cpu = policy->cpu;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
 			cpu);
@@ -284,7 +288,7 @@ static void update_sampling_rate(struct
 		 * policy will be governed by dbs_data, otherwise there can be
 		 * multiple policies that are governed by the same dbs_data.
 		 */
-		if (dbs_data != policy->governor_data)
+		if (dbs_data != policy_dbs->dbs_data)
 			continue;
 
 		/*
@@ -588,7 +592,7 @@ static void od_set_powersave_bias(unsign
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
 			continue;
 
-		dbs_data = policy->governor_data;
+		dbs_data = policy_dbs->dbs_data;
 		od_tuners = dbs_data->tuners;
 		od_tuners->powersave_bias = default_powersave_bias;
 	}
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_t
 	long d_actual, d_reference;
 	struct msr actual, reference;
 	struct cpu_data_t *data = &per_cpu(cpu_data, policy->cpu);
-	struct dbs_data *od_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *od_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
 		od_data->gov->get_cpu_dbs_info_s(policy->cpu);
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
 	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsign
 
 static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	dbs_check_cpu(policy, policy->cpu);

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

* [PATCH 11/11] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (9 preceding siblings ...)
  2016-02-03 23:37 ` [PATCH 10/11] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
@ 2016-02-03 23:38 ` Rafael J. Wysocki
  2016-02-04  5:40 ` [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Viresh Kumar
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
  12 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-03 23:38 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since policy->cpu is always passed as the second argument to
dbs_check_cpu(), it is not really necessary to pass it, because
the function can obtain that value via its first argument just fine.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |    2 +-
 drivers/cpufreq/cpufreq_governor.c     |    5 +++--
 drivers/cpufreq/cpufreq_governor.h     |    2 +-
 drivers/cpufreq/cpufreq_ondemand.c     |    6 ++----
 4 files changed, 7 insertions(+), 8 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -279,7 +279,7 @@ extern struct mutex cpufreq_governor_loc
 void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us);
 void gov_cancel_work(struct policy_dbs_info *policy_dbs);
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
+void dbs_check_cpu(struct cpufreq_policy *policy);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -198,9 +198,7 @@ static unsigned int od_dbs_timer(struct
 {
 	struct policy_dbs_info *policy_dbs = policy->governor_data;
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
-	unsigned int cpu = policy->cpu;
-	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
-			cpu);
+	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	int delay = 0, sample_type = dbs_info->sample_type;
 
@@ -211,7 +209,7 @@ static unsigned int od_dbs_timer(struct
 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
 					CPUFREQ_RELATION_H);
 	} else {
-		dbs_check_cpu(policy, cpu);
+		dbs_check_cpu(policy);
 		if (dbs_info->freq_lo) {
 			/* Setup timer for SUB_SAMPLE */
 			dbs_info->sample_type = OD_SUB_SAMPLE;
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -109,7 +109,7 @@ static unsigned int cs_dbs_timer(struct
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
-	dbs_check_cpu(policy, policy->cpu);
+	dbs_check_cpu(policy);
 	return delay_for_sampling_rate(cs_tuners->sampling_rate);
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -34,13 +34,14 @@ static struct attribute_group *get_sysfs
 		gov->attr_group_gov_pol : gov->attr_group_gov_sys;
 }
 
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
+void dbs_check_cpu(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct policy_dbs_info *policy_dbs = policy->governor_data;
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
+	int cpu = policy->cpu;
 	unsigned int sampling_rate;
 	unsigned int max_load = 0;
 	unsigned int ignore_nice;
@@ -519,7 +520,7 @@ static int cpufreq_governor_limits(struc
 		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
 	else if (policy->min > policy->cur)
 		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
-	dbs_check_cpu(policy, policy->cpu);
+	dbs_check_cpu(policy);
 	mutex_unlock(&policy_dbs->timer_mutex);
 
 	return 0;

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

* Re: [PATCH 1/11] cpufreq: Clean up default and fallback governor setup
  2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
@ 2016-02-04  0:55   ` Saravana Kannan
  2016-02-04  5:03   ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  0:55 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:14 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> The preprocessor magic used for setting the default cpufreq governor
> (and for using the performance governor as a fallback one for that
> matter) is really nasty, so replace it with __weak functions and
> overrides.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq.c              |   37 ++++++++++++++++++---------------
>   drivers/cpufreq/cpufreq_conservative.c |   10 +++++---
>   drivers/cpufreq/cpufreq_ondemand.c     |   34 ++++++++++++++++--------------
>   drivers/cpufreq/cpufreq_performance.c  |   18 ++++++++++++----
>   drivers/cpufreq/cpufreq_powersave.c    |   10 +++++---
>   drivers/cpufreq/cpufreq_userspace.c    |   10 +++++---
>   include/linux/cpufreq.h                |   25 +---------------------
>   7 files changed, 73 insertions(+), 71 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(str
>   	return cpufreq_add_dev_symlink(policy);
>   }
>
> +__weak struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return NULL;
> +}
> +
>   static int cpufreq_init_policy(struct cpufreq_policy *policy)
>   {
>   	struct cpufreq_governor *gov = NULL;
> @@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp
>
>   	/* Update governor of new_policy to the governor used before hotplug */
>   	gov = find_governor(policy->last_governor);
> -	if (gov)
> +	if (gov) {
>   		pr_debug("Restoring governor %s for cpu %d\n",
>   				policy->governor->name, policy->cpu);
> -	else
> -		gov = CPUFREQ_DEFAULT_GOVERNOR;
> +	} else {
> +		gov = cpufreq_default_governor();
> +		if (!gov)
> +			return -ENODATA;
> +	}
>
>   	new_policy.governor = gov;
>
> @@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq
>   }
>   EXPORT_SYMBOL_GPL(cpufreq_driver_target);
>
> +__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
> +{
> +	return NULL;
> +}
> +
>   static int __cpufreq_governor(struct cpufreq_policy *policy,
>   					unsigned int event)
>   {
>   	int ret;
>
> -	/* Only must be defined when default governor is known to have latency
> -	   restrictions, like e.g. conservative or ondemand.
> -	   That this is the case is already ensured in Kconfig
> -	*/
> -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
> -	struct cpufreq_governor *gov = &cpufreq_gov_performance;
> -#else
> -	struct cpufreq_governor *gov = NULL;
> -#endif
> -
>   	/* Don't start any governor operations if we are entering suspend */
>   	if (cpufreq_suspended)
>   		return 0;
> @@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpu
>   	if (policy->governor->max_transition_latency &&
>   	    policy->cpuinfo.transition_latency >
>   	    policy->governor->max_transition_latency) {
> -		if (!gov)
> -			return -EINVAL;
> -		else {
> +		struct cpufreq_governor *gov = cpufreq_fallback_governor();
> +
> +		if (gov) {
>   			pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
>   				policy->governor->name, gov->name);
>   			policy->governor = gov;
> +		} else {
> +			return -EINVAL;
>   		}
>   	}
>
> Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
> +++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
> @@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_
>   static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
>   				   unsigned int event);
>
> -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_conservative = {
> +static struct cpufreq_governor cpufreq_gov_conservative = {
>   	.name			= "conservative",
>   	.governor		= cs_cpufreq_governor_dbs,
>   	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> @@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativ
>   MODULE_LICENSE("GPL");
>
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_conservative;
> +}
> +
>   fs_initcall(cpufreq_gov_dbs_init);
>   #else
>   module_init(cpufreq_gov_dbs_init);
> Index: linux-pm/include/linux/cpufreq.h
> ===================================================================
> --- linux-pm.orig/include/linux/cpufreq.h
> +++ linux-pm/include/linux/cpufreq.h
> @@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufr
>   int cpufreq_register_governor(struct cpufreq_governor *governor);
>   void cpufreq_unregister_governor(struct cpufreq_governor *governor);
>
> -/* CPUFREQ DEFAULT GOVERNOR */
> -/*
> - * Performance governor is fallback governor if any other gov failed to auto
> - * load due latency restrictions
> - */
> -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
> -extern struct cpufreq_governor cpufreq_gov_performance;
> -#endif
> -#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> -#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
> -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
> -extern struct cpufreq_governor cpufreq_gov_powersave;
> -#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_powersave)
> -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
> -extern struct cpufreq_governor cpufreq_gov_userspace;
> -#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_userspace)
> -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
> -extern struct cpufreq_governor cpufreq_gov_ondemand;
> -#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_ondemand)
> -#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
> -extern struct cpufreq_governor cpufreq_gov_conservative;
> -#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_conservative)
> -#endif
> +struct cpufreq_governor *cpufreq_default_governor(void);
> +struct cpufreq_governor *cpufreq_fallback_governor(void);
>
>   /*********************************************************************
>    *                     FREQUENCY TABLE HELPERS                       *
> Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
> +++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> @@ -553,6 +553,19 @@ static struct common_dbs_data od_dbs_cda
>   	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
>   };
>
> +static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> +		unsigned int event)
> +{
> +	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
> +}
> +
> +static struct cpufreq_governor cpufreq_gov_ondemand = {
> +	.name			= "ondemand",
> +	.governor		= od_cpufreq_governor_dbs,
> +	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> +	.owner			= THIS_MODULE,
> +};
> +
>   static void od_set_powersave_bias(unsigned int powersave_bias)
>   {
>   	struct cpufreq_policy *policy;
> @@ -604,22 +617,6 @@ void od_unregister_powersave_bias_handle
>   }
>   EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
>
> -static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -		unsigned int event)
> -{
> -	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
> -}
> -
> -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_ondemand = {
> -	.name			= "ondemand",
> -	.governor		= od_cpufreq_governor_dbs,
> -	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> -	.owner			= THIS_MODULE,
> -};
> -
>   static int __init cpufreq_gov_dbs_init(void)
>   {
>   	return cpufreq_register_governor(&cpufreq_gov_ondemand);
> @@ -637,6 +634,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -
>   MODULE_LICENSE("GPL");
>
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_ondemand;
> +}
> +
>   fs_initcall(cpufreq_gov_dbs_init);
>   #else
>   module_init(cpufreq_gov_dbs_init);
> Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
> +++ linux-pm/drivers/cpufreq/cpufreq_performance.c
> @@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
>   	return 0;
>   }
>
> -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_performance = {
> +static struct cpufreq_governor cpufreq_gov_performance = {
>   	.name		= "performance",
>   	.governor	= cpufreq_governor_performance,
>   	.owner		= THIS_MODULE,
> @@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
>   	cpufreq_unregister_governor(&cpufreq_gov_performance);
>   }
>
> +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_performance;
> +}
> +#endif
> +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> +struct cpufreq_governor *cpufreq_fallback_governor(void)
> +{
> +	return &cpufreq_gov_performance;
> +}
> +#endif
> +
>   MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
>   MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
>   MODULE_LICENSE("GPL");
> Index: linux-pm/drivers/cpufreq/cpufreq_powersave.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_powersave.c
> +++ linux-pm/drivers/cpufreq/cpufreq_powersave.c
> @@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(st
>   	return 0;
>   }
>
> -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_powersave = {
> +static struct cpufreq_governor cpufreq_gov_powersave = {
>   	.name		= "powersave",
>   	.governor	= cpufreq_governor_powersave,
>   	.owner		= THIS_MODULE,
> @@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
>   MODULE_LICENSE("GPL");
>
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_powersave;
> +}
> +
>   fs_initcall(cpufreq_gov_powersave_init);
>   #else
>   module_init(cpufreq_gov_powersave_init);
> Index: linux-pm/drivers/cpufreq/cpufreq_userspace.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_userspace.c
> +++ linux-pm/drivers/cpufreq/cpufreq_userspace.c
> @@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(st
>   	return rc;
>   }
>
> -#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_userspace = {
> +static struct cpufreq_governor cpufreq_gov_userspace = {
>   	.name		= "userspace",
>   	.governor	= cpufreq_governor_userspace,
>   	.store_setspeed	= cpufreq_set,
> @@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
>   MODULE_LICENSE("GPL");
>
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_userspace;
> +}
> +
>   fs_initcall(cpufreq_gov_userspace_init);
>   #else
>   module_init(cpufreq_gov_userspace_init);
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

Ah, that's so much more cleaner!

Acked-by: Saravana Kannan <skannan@codeaurora.org>


-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-03 23:16 ` [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
@ 2016-02-04  0:59   ` Saravana Kannan
  2016-02-04  5:09   ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  0:59 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:16 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Every governor relying on the common code in cpufreq_governor.c
> has to provide its own mutex in struct common_dbs_data.  However,
> those mutexes are never used at the same time and doing it this
> way makes it rather difficult to follow the code.  Moreover,
> if two governor modules are loaded we end up with two mutexes
> used for the same purpose one at a time.
>
> Introduce a single common mutex for that instead and drop the
> mutex field from struct common_dbs_data.  That at least will
> ensure that the mutex is always present and initialized regardless
> of what the particular governors do.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq_conservative.c |    1 -
>   drivers/cpufreq/cpufreq_governor.c     |    7 +++++--
>   drivers/cpufreq/cpufreq_governor.h     |    6 +-----
>   drivers/cpufreq/cpufreq_ondemand.c     |    5 ++---
>   4 files changed, 8 insertions(+), 11 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -22,6 +22,9 @@
>
>   #include "cpufreq_governor.h"
>
> +DEFINE_MUTEX(dbs_data_mutex);
> +EXPORT_SYMBOL_GPL(dbs_data_mutex);
> +
>   static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
>   {
>   	if (have_governor_per_policy())
> @@ -542,7 +545,7 @@ int cpufreq_governor_dbs(struct cpufreq_
>   	int ret;
>
>   	/* Lock governor to block concurrent initialization of governor */
> -	mutex_lock(&cdata->mutex);
> +	mutex_lock(&dbs_data_mutex);
>
>   	if (have_governor_per_policy())
>   		dbs_data = policy->governor_data;
> @@ -575,7 +578,7 @@ int cpufreq_governor_dbs(struct cpufreq_
>   	}
>
>   unlock:
> -	mutex_unlock(&cdata->mutex);
> +	mutex_unlock(&dbs_data_mutex);
>
>   	return ret;
>   }
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
> @@ -223,11 +223,6 @@ struct common_dbs_data {
>
>   	/* Governor specific ops, see below */
>   	void *gov_ops;
> -
> -	/*
> -	 * Protects governor's data (struct dbs_data and struct common_dbs_data)
> -	 */
> -	struct mutex mutex;
>   };
>
>   /* Governor Per policy data */
> @@ -272,6 +267,7 @@ static ssize_t show_sampling_rate_min_go
>   	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
>   }
>
> +extern struct mutex dbs_data_mutex;
>   extern struct mutex cpufreq_governor_lock;
>   void gov_set_update_util(struct cpu_common_dbs_info *shared,
>   			 unsigned int delay_us);
> Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
> +++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> @@ -251,7 +251,7 @@ static void update_sampling_rate(struct
>   	/*
>   	 * Lock governor so that governor start/stop can't execute in parallel.
>   	 */
> -	mutex_lock(&od_dbs_cdata.mutex);
> +	mutex_lock(&dbs_data_mutex);
>
>   	cpumask_copy(&cpumask, cpu_online_mask);
>
> @@ -304,7 +304,7 @@ static void update_sampling_rate(struct
>   		}
>   	}
>
> -	mutex_unlock(&od_dbs_cdata.mutex);
> +	mutex_unlock(&dbs_data_mutex);
>   }
>
>   static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
> @@ -550,7 +550,6 @@ static struct common_dbs_data od_dbs_cda
>   	.gov_ops = &od_ops,
>   	.init = od_init,
>   	.exit = od_exit,
> -	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
>   };
>
>   static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
> +++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
> @@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda
>   	.gov_check_cpu = cs_check_cpu,
>   	.init = cs_init,
>   	.exit = cs_exit,
> -	.mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex),
>   };
>
>   static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


Acked-by: Saravana Kannan <skannan@codeaurora.org>


-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-03 23:22 ` [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer Rafael J. Wysocki
@ 2016-02-04  1:11   ` Saravana Kannan
  2016-02-04  1:25     ` Rafael J. Wysocki
  2016-02-04  1:47     ` Saravana Kannan
  2016-02-04  5:36   ` Viresh Kumar
  1 sibling, 2 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  1:11 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:22 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> If the ondemand and conservative governors cannot use per-policy
> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
> driver), all policy objects point to the same single dbs_data object.
> Additionally, that object is pointed to by a global pointer hidden in
> the governor's data structures.
>
> There is no reason for that pointer to be buried in those
> data structures, though, so make it explicitly global.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq_governor.c |   20 ++++++++++----------
>   drivers/cpufreq/cpufreq_governor.h |   20 ++++++++++----------
>   2 files changed, 20 insertions(+), 20 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
> @@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
>   static ssize_t show_##file_name##_gov_sys				\
>   (struct kobject *kobj, struct attribute *attr, char *buf)		\
>   {									\
> -	struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \
> +	struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \
>   	return sprintf(buf, "%u\n", tuners->file_name);			\
>   }									\
>   									\
> @@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po
>   static ssize_t store_##file_name##_gov_sys				\
>   (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
>   {									\
> -	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
> +	struct dbs_data *dbs_data = global_dbs_data;		\
>   	return store_##file_name(dbs_data, buf, count);			\
>   }									\
>   									\
> @@ -201,19 +201,14 @@ struct cs_dbs_tuners {
>   /* Common Governor data across policies */
>   struct dbs_data;
>   struct common_dbs_data {
> -	/* Common across governors */
> +	struct cpufreq_governor gov;
> +
>   	#define GOV_ONDEMAND		0
>   	#define GOV_CONSERVATIVE	1
>   	int governor;
>   	struct attribute_group *attr_group_gov_sys; /* one governor - system */
>   	struct attribute_group *attr_group_gov_pol; /* one governor - policy */
>
> -	/*
> -	 * Common data for platforms that don't set
> -	 * CPUFREQ_HAVE_GOVERNOR_PER_POLICY
> -	 */
> -	struct dbs_data *gdbs_data;
> -
>   	struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);
>   	void *(*get_cpu_dbs_info_s)(int cpu);
>   	unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
> @@ -233,6 +228,11 @@ struct dbs_data {
>   	void *tuners;
>   };
>
> +/*
> + * Common governor data for platforms without CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
> + */
> +extern struct dbs_data *global_dbs_data;
> +
>   /* Governor specific ops, will be passed to dbs_data->gov_ops */
>   struct od_ops {
>   	void (*powersave_bias_init_cpu)(int cpu);
> @@ -256,7 +256,7 @@ static inline int delay_for_sampling_rat
>   static ssize_t show_sampling_rate_min_gov_sys				\
>   (struct kobject *kobj, struct attribute *attr, char *buf)		\
>   {									\
> -	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
> +	struct dbs_data *dbs_data = global_dbs_data;			\
>   	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
>   }									\
>   									\
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -22,6 +22,9 @@
>
>   #include "cpufreq_governor.h"
>
> +struct dbs_data *global_dbs_data;
> +EXPORT_SYMBOL_GPL(global_dbs_data);
> +
>   DEFINE_MUTEX(dbs_data_mutex);
>   EXPORT_SYMBOL_GPL(dbs_data_mutex);
>
> @@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct
>   					latency * LATENCY_MULTIPLIER));
>
>   	if (!have_governor_per_policy())
> -		cdata->gdbs_data = dbs_data;
> +		global_dbs_data = dbs_data;
>
>   	policy->governor_data = dbs_data;
>
>   	ret = sysfs_create_group(get_governor_parent_kobj(policy),
>   				 get_sysfs_attr(dbs_data));
> -	if (ret)
> -		goto reset_gdbs_data;
> -
> -	return 0;
> +	if (!ret)
> +		return 0;

I think the previous method of a handling the error is easier to read 
and more in line with the typical kernel coding style. The successful 
path ends in an unconditional return statement and the error paths are 
handled with a goto.

This also doesn't seem relevant to what the patch is trying to do. So, 
I'd prefer that it be left as is.


> -reset_gdbs_data:
>   	policy->governor_data = NULL;
> -
>   	if (!have_governor_per_policy())
> -		cdata->gdbs_data = NULL;
> +		global_dbs_data = NULL;
> +
>   	cdata->exit(dbs_data, !policy->governor->initialized);
>   free_common_dbs_info:
>   	free_common_dbs_info(policy, cdata);
> @@ -418,7 +418,7 @@ static int cpufreq_governor_exit(struct
>   		policy->governor_data = NULL;
>
>   		if (!have_governor_per_policy())
> -			cdata->gdbs_data = NULL;
> +			global_dbs_data = NULL;
>
>   		cdata->exit(dbs_data, policy->governor->initialized == 1);
>   		kfree(dbs_data);
> @@ -550,7 +550,7 @@ int cpufreq_governor_dbs(struct cpufreq_
>   	if (have_governor_per_policy())
>   		dbs_data = policy->governor_data;
>   	else
> -		dbs_data = cdata->gdbs_data;
> +		dbs_data = global_dbs_data;
>
>   	if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) {
>   		ret = -EINVAL;
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

If the minor comment is addressed, this looks okay to me.

Cautiously Acked-by: Saravana Kannan <skannan@codeaurora.org>

-Saravana

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  1:11   ` Saravana Kannan
@ 2016-02-04  1:25     ` Rafael J. Wysocki
  2016-02-04  1:40       ` Saravana Kannan
  2016-02-04  5:38       ` Viresh Kumar
  2016-02-04  1:47     ` Saravana Kannan
  1 sibling, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-04  1:25 UTC (permalink / raw)
  To: Saravana Kannan
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Viresh Kumar, Srinivas Pandruvada, Juri Lelli, Steve Muckle

On Thu, Feb 4, 2016 at 2:11 AM, Saravana Kannan <skannan@codeaurora.org> wrote:
> On 02/03/2016 03:22 PM, Rafael J. Wysocki wrote:
>>
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> If the ondemand and conservative governors cannot use per-policy
>> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
>> driver), all policy objects point to the same single dbs_data object.
>> Additionally, that object is pointed to by a global pointer hidden in
>> the governor's data structures.
>>
>> There is no reason for that pointer to be buried in those
>> data structures, though, so make it explicitly global.
>>
>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> ---
>>   drivers/cpufreq/cpufreq_governor.c |   20 ++++++++++----------
>>   drivers/cpufreq/cpufreq_governor.h |   20 ++++++++++----------
>>   2 files changed, 20 insertions(+), 20 deletions(-)
>>
>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
>> ===================================================================
>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
>> @@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
>>   static ssize_t show_##file_name##_gov_sys                             \
>>   (struct kobject *kobj, struct attribute *attr, char *buf)             \
>>   {                                                                     \
>> -       struct _gov##_dbs_tuners *tuners =
>> _gov##_dbs_cdata.gdbs_data->tuners; \
>> +       struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \
>>         return sprintf(buf, "%u\n", tuners->file_name);                 \
>>   }                                                                     \
>>                                                                         \
>> @@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po
>>   static ssize_t store_##file_name##_gov_sys                            \
>>   (struct kobject *kobj, struct attribute *attr, const char *buf, size_t
>> count) \
>>   {                                                                     \
>> -       struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;         \
>> +       struct dbs_data *dbs_data = global_dbs_data;            \
>>         return store_##file_name(dbs_data, buf, count);                 \
>>   }                                                                     \
>>                                                                         \
>> @@ -201,19 +201,14 @@ struct cs_dbs_tuners {
>>   /* Common Governor data across policies */
>>   struct dbs_data;
>>   struct common_dbs_data {
>> -       /* Common across governors */
>> +       struct cpufreq_governor gov;
>> +
>>         #define GOV_ONDEMAND            0
>>         #define GOV_CONSERVATIVE        1
>>         int governor;
>>         struct attribute_group *attr_group_gov_sys; /* one governor -
>> system */
>>         struct attribute_group *attr_group_gov_pol; /* one governor -
>> policy */
>>
>> -       /*
>> -        * Common data for platforms that don't set
>> -        * CPUFREQ_HAVE_GOVERNOR_PER_POLICY
>> -        */
>> -       struct dbs_data *gdbs_data;
>> -
>>         struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);
>>         void *(*get_cpu_dbs_info_s)(int cpu);
>>         unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
>> @@ -233,6 +228,11 @@ struct dbs_data {
>>         void *tuners;
>>   };
>>
>> +/*
>> + * Common governor data for platforms without
>> CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
>> + */
>> +extern struct dbs_data *global_dbs_data;
>> +
>>   /* Governor specific ops, will be passed to dbs_data->gov_ops */
>>   struct od_ops {
>>         void (*powersave_bias_init_cpu)(int cpu);
>> @@ -256,7 +256,7 @@ static inline int delay_for_sampling_rat
>>   static ssize_t show_sampling_rate_min_gov_sys                         \
>>   (struct kobject *kobj, struct attribute *attr, char *buf)             \
>>   {                                                                     \
>> -       struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;         \
>> +       struct dbs_data *dbs_data = global_dbs_data;                    \
>>         return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);       \
>>   }                                                                     \
>>                                                                         \
>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
>> ===================================================================
>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
>> @@ -22,6 +22,9 @@
>>
>>   #include "cpufreq_governor.h"
>>
>> +struct dbs_data *global_dbs_data;
>> +EXPORT_SYMBOL_GPL(global_dbs_data);
>> +
>>   DEFINE_MUTEX(dbs_data_mutex);
>>   EXPORT_SYMBOL_GPL(dbs_data_mutex);
>>
>> @@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct
>>                                         latency * LATENCY_MULTIPLIER));
>>
>>         if (!have_governor_per_policy())
>> -               cdata->gdbs_data = dbs_data;
>> +               global_dbs_data = dbs_data;
>>
>>         policy->governor_data = dbs_data;
>>
>>         ret = sysfs_create_group(get_governor_parent_kobj(policy),
>>                                  get_sysfs_attr(dbs_data));
>> -       if (ret)
>> -               goto reset_gdbs_data;
>> -
>> -       return 0;
>> +       if (!ret)
>> +               return 0;
>
>
> I think the previous method of a handling the error is easier to read and
> more in line with the typical kernel coding style. The successful path ends
> in an unconditional return statement and the error paths are handled with a
> goto.

You are talking about something like this now:

    if (condition)
        goto label;

    return 0;

label:
    do stuff

I'm sorry, but I fail to see how this is easier to read than

    if (!condition)
        return 0;

    do stuff

The return statement is not unconditional in either case, but in the
first one it is just obfuscated by using the label and goto which are
completely unnecessary.

>
> This also doesn't seem relevant to what the patch is trying to do. So, I'd
> prefer that it be left as is.
>

This is a fair point, though.  I can make that change later. :-)

Thanks,
Rafael

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

* Re: [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
  2016-02-03 23:29 ` [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
@ 2016-02-04  1:37   ` Saravana Kannan
  0 siblings, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  1:37 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:29 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Do not pass struct dbs_data pointers to the family of functions
> implementing governor operations in cpufreq_governor.c as they can
> take that pointer from policy->governor by themselves.
>
> The cpufreq_governor_init() case is slightly more complicated, since
> policy->governor may be NULL when it is invoked, but then it can use
> global_dbs_data directly just fine.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq_governor.c |   74 +++++++++++++++----------------------
>   1 file changed, 30 insertions(+), 44 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -330,9 +330,9 @@ static void free_common_dbs_info(struct
>   }
>
>   static int cpufreq_governor_init(struct cpufreq_policy *policy,
> -				 struct dbs_data *dbs_data,
>   				 struct common_dbs_data *cdata)
>   {
> +	struct dbs_data *dbs_data;
>   	unsigned int latency;
>   	int ret;
>
> @@ -340,7 +340,7 @@ static int cpufreq_governor_init(struct
>   	if (policy->governor_data)
>   		return -EBUSY;
>
> -	if (dbs_data) {
> +	if (global_dbs_data) {
>   		if (WARN_ON(have_governor_per_policy()))
>   			return -EINVAL;

I'm not sure if this code is functionally equivalent to what was there 
before.

Old: If the dbs_data is not NULL (whether it's global or not), but we 
have gov per policy enabled, warn and bail out.
New: If the global_dbs_data is not NULL, but we have gov per policy 
enabled, warn and bail out.

Both of these are bad cases, but the meaning of the code here definitely 
changes. My guess is that the old code was put in here to catch the 
"Old" case since that's more likely to happen with the crappy locking we 
have/had. I don't think the "New" case is even possible given the code 
-- we can probably prove it will never happen if we trust the compiler.

I'm not necessarily asking you to go back to the old code (I don't have 
a strong preference either way), but just wanted to point out the 
difference and let the rest of you decide.

>
> @@ -348,8 +348,8 @@ static int cpufreq_governor_init(struct
>   		if (ret)
>   			return ret;
>
> -		dbs_data->usage_count++;
> -		policy->governor_data = dbs_data;
> +		global_dbs_data->usage_count++;
> +		policy->governor_data = global_dbs_data;
>   		return 0;
>   	}
>
> @@ -401,9 +401,9 @@ free_dbs_data:
>   	return ret;
>   }
>
> -static int cpufreq_governor_exit(struct cpufreq_policy *policy,
> -				 struct dbs_data *dbs_data)
> +static int cpufreq_governor_exit(struct cpufreq_policy *policy)
>   {
> +	struct dbs_data *dbs_data = policy->governor_data;
>   	struct common_dbs_data *cdata = dbs_data->cdata;
>   	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
>
> @@ -430,9 +430,9 @@ static int cpufreq_governor_exit(struct
>   	return 0;
>   }
>
> -static int cpufreq_governor_start(struct cpufreq_policy *policy,
> -				  struct dbs_data *dbs_data)
> +static int cpufreq_governor_start(struct cpufreq_policy *policy)
>   {
> +	struct dbs_data *dbs_data = policy->governor_data;
>   	struct common_dbs_data *cdata = dbs_data->cdata;
>   	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
>   	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
> @@ -498,9 +498,9 @@ static int cpufreq_governor_start(struct
>   	return 0;
>   }
>
> -static int cpufreq_governor_stop(struct cpufreq_policy *policy,
> -				 struct dbs_data *dbs_data)
> +static int cpufreq_governor_stop(struct cpufreq_policy *policy)
>   {
> +	struct dbs_data *dbs_data = policy->governor_data;
>   	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
>   	struct cpu_common_dbs_info *shared = cdbs->shared;
>
> @@ -514,9 +514,9 @@ static int cpufreq_governor_stop(struct
>   	return 0;
>   }
>
> -static int cpufreq_governor_limits(struct cpufreq_policy *policy,
> -				   struct dbs_data *dbs_data)
> +static int cpufreq_governor_limits(struct cpufreq_policy *policy)
>   {
> +	struct dbs_data *dbs_data = policy->governor_data;
>   	struct common_dbs_data *cdata = dbs_data->cdata;
>   	unsigned int cpu = policy->cpu;
>   	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
> @@ -541,45 +541,31 @@ static int cpufreq_governor_limits(struc
>   int cpufreq_governor_dbs(struct cpufreq_policy *policy,
>   			 struct common_dbs_data *cdata, unsigned int event)
>   {
> -	struct dbs_data *dbs_data;
> -	int ret;
> +	int ret = -EINVAL;
>
>   	/* Lock governor to block concurrent initialization of governor */
>   	mutex_lock(&dbs_data_mutex);
>
> -	if (have_governor_per_policy())
> -		dbs_data = policy->governor_data;
> -	else
> -		dbs_data = global_dbs_data;
> -
> -	if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) {
> -		ret = -EINVAL;
> -		goto unlock;
> +	if (event == CPUFREQ_GOV_POLICY_INIT) {
> +		ret = cpufreq_governor_init(policy, cdata);
> +	} else if (policy->governor_data) {
> +		switch (event) {
> +		case CPUFREQ_GOV_POLICY_EXIT:
> +			ret = cpufreq_governor_exit(policy);
> +			break;
> +		case CPUFREQ_GOV_START:
> +			ret = cpufreq_governor_start(policy);
> +			break;
> +		case CPUFREQ_GOV_STOP:
> +			ret = cpufreq_governor_stop(policy);
> +			break;
> +		case CPUFREQ_GOV_LIMITS:
> +			ret = cpufreq_governor_limits(policy);
> +			break;
> +		}
>   	}
>
> -	switch (event) {
> -	case CPUFREQ_GOV_POLICY_INIT:
> -		ret = cpufreq_governor_init(policy, dbs_data, cdata);
> -		break;
> -	case CPUFREQ_GOV_POLICY_EXIT:
> -		ret = cpufreq_governor_exit(policy, dbs_data);
> -		break;
> -	case CPUFREQ_GOV_START:
> -		ret = cpufreq_governor_start(policy, dbs_data);
> -		break;
> -	case CPUFREQ_GOV_STOP:
> -		ret = cpufreq_governor_stop(policy, dbs_data);
> -		break;
> -	case CPUFREQ_GOV_LIMITS:
> -		ret = cpufreq_governor_limits(policy, dbs_data);
> -		break;
> -	default:
> -		ret = -EINVAL;
> -	}
> -
> -unlock:
>   	mutex_unlock(&dbs_data_mutex);
> -

Po-tay-to, Po-tah-to.

>   	return ret;
>   }
>   EXPORT_SYMBOL_GPL(cpufreq_governor_dbs);
>

Agree with the general idea of the patch though.

Conditional on the comment above being resolve amongst the others:
Acked-by: Saravana Kannan <skannan@codeaurora.org>

-Saravana
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  1:25     ` Rafael J. Wysocki
@ 2016-02-04  1:40       ` Saravana Kannan
  2016-02-04  5:38       ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  1:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Viresh Kumar, Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 05:25 PM, Rafael J. Wysocki wrote:
> On Thu, Feb 4, 2016 at 2:11 AM, Saravana Kannan <skannan@codeaurora.org> wrote:
>> On 02/03/2016 03:22 PM, Rafael J. Wysocki wrote:
>>>
>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>
>>> If the ondemand and conservative governors cannot use per-policy
>>> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
>>> driver), all policy objects point to the same single dbs_data object.
>>> Additionally, that object is pointed to by a global pointer hidden in
>>> the governor's data structures.
>>>
>>> There is no reason for that pointer to be buried in those
>>> data structures, though, so make it explicitly global.
>>>
>>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> ---
>>>    drivers/cpufreq/cpufreq_governor.c |   20 ++++++++++----------
>>>    drivers/cpufreq/cpufreq_governor.h |   20 ++++++++++----------
>>>    2 files changed, 20 insertions(+), 20 deletions(-)
>>>
>>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
>>> ===================================================================
>>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
>>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
>>> @@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
>>>    static ssize_t show_##file_name##_gov_sys                             \
>>>    (struct kobject *kobj, struct attribute *attr, char *buf)             \
>>>    {                                                                     \
>>> -       struct _gov##_dbs_tuners *tuners =
>>> _gov##_dbs_cdata.gdbs_data->tuners; \
>>> +       struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \
>>>          return sprintf(buf, "%u\n", tuners->file_name);                 \
>>>    }                                                                     \
>>>                                                                          \
>>> @@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po
>>>    static ssize_t store_##file_name##_gov_sys                            \
>>>    (struct kobject *kobj, struct attribute *attr, const char *buf, size_t
>>> count) \
>>>    {                                                                     \
>>> -       struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;         \
>>> +       struct dbs_data *dbs_data = global_dbs_data;            \
>>>          return store_##file_name(dbs_data, buf, count);                 \
>>>    }                                                                     \
>>>                                                                          \
>>> @@ -201,19 +201,14 @@ struct cs_dbs_tuners {
>>>    /* Common Governor data across policies */
>>>    struct dbs_data;
>>>    struct common_dbs_data {
>>> -       /* Common across governors */
>>> +       struct cpufreq_governor gov;
>>> +
>>>          #define GOV_ONDEMAND            0
>>>          #define GOV_CONSERVATIVE        1
>>>          int governor;
>>>          struct attribute_group *attr_group_gov_sys; /* one governor -
>>> system */
>>>          struct attribute_group *attr_group_gov_pol; /* one governor -
>>> policy */
>>>
>>> -       /*
>>> -        * Common data for platforms that don't set
>>> -        * CPUFREQ_HAVE_GOVERNOR_PER_POLICY
>>> -        */
>>> -       struct dbs_data *gdbs_data;
>>> -
>>>          struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu);
>>>          void *(*get_cpu_dbs_info_s)(int cpu);
>>>          unsigned int (*gov_dbs_timer)(struct cpufreq_policy *policy);
>>> @@ -233,6 +228,11 @@ struct dbs_data {
>>>          void *tuners;
>>>    };
>>>
>>> +/*
>>> + * Common governor data for platforms without
>>> CPUFREQ_HAVE_GOVERNOR_PER_POLICY.
>>> + */
>>> +extern struct dbs_data *global_dbs_data;
>>> +
>>>    /* Governor specific ops, will be passed to dbs_data->gov_ops */
>>>    struct od_ops {
>>>          void (*powersave_bias_init_cpu)(int cpu);
>>> @@ -256,7 +256,7 @@ static inline int delay_for_sampling_rat
>>>    static ssize_t show_sampling_rate_min_gov_sys                         \
>>>    (struct kobject *kobj, struct attribute *attr, char *buf)             \
>>>    {                                                                     \
>>> -       struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;         \
>>> +       struct dbs_data *dbs_data = global_dbs_data;                    \
>>>          return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);       \
>>>    }                                                                     \
>>>                                                                          \
>>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
>>> ===================================================================
>>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
>>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
>>> @@ -22,6 +22,9 @@
>>>
>>>    #include "cpufreq_governor.h"
>>>
>>> +struct dbs_data *global_dbs_data;
>>> +EXPORT_SYMBOL_GPL(global_dbs_data);
>>> +
>>>    DEFINE_MUTEX(dbs_data_mutex);
>>>    EXPORT_SYMBOL_GPL(dbs_data_mutex);
>>>
>>> @@ -377,22 +380,19 @@ static int cpufreq_governor_init(struct
>>>                                          latency * LATENCY_MULTIPLIER));
>>>
>>>          if (!have_governor_per_policy())
>>> -               cdata->gdbs_data = dbs_data;
>>> +               global_dbs_data = dbs_data;
>>>
>>>          policy->governor_data = dbs_data;
>>>
>>>          ret = sysfs_create_group(get_governor_parent_kobj(policy),
>>>                                   get_sysfs_attr(dbs_data));
>>> -       if (ret)
>>> -               goto reset_gdbs_data;
>>> -
>>> -       return 0;
>>> +       if (!ret)
>>> +               return 0;
>>
>>
>> I think the previous method of a handling the error is easier to read and
>> more in line with the typical kernel coding style. The successful path ends
>> in an unconditional return statement and the error paths are handled with a
>> goto.
>
> You are talking about something like this now:
>
>      if (condition)
>          goto label;
>
>      return 0;
>
> label:
>      do stuff
>
> I'm sorry, but I fail to see how this is easier to read than
>
>      if (!condition)
>          return 0;
>
>      do stuff
>
> The return statement is not unconditional in either case, but in the
> first one it is just obfuscated by using the label and goto which are
> completely unnecessary.
>

It's more readable because someone new is quickly scanning the code to 
understand what's going on, once you hit an unconditional return (as in, 
return without any ifs around it) you can just assume the rest of the 
code is error handling and skip reading/mentally processing them.

That, and it's more inline with how most of the kernel handles error 
conditions.

Anyway, you are removing it since it's not related to the patch. So, not 
planning to debate this fairly subjective opinion further.

-Saravana

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  1:11   ` Saravana Kannan
  2016-02-04  1:25     ` Rafael J. Wysocki
@ 2016-02-04  1:47     ` Saravana Kannan
  1 sibling, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  1:47 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 05:11 PM, Saravana Kannan wrote:
> On 02/03/2016 03:22 PM, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> If the ondemand and conservative governors cannot use per-policy
>> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
>> driver), all policy objects point to the same single dbs_data object.
>> Additionally, that object is pointed to by a global pointer hidden in
>> the governor's data structures.
>>
>> There is no reason for that pointer to be buried in those
>> data structures, though, so make it explicitly global.
>>
>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> ---
>>   drivers/cpufreq/cpufreq_governor.c |   20 ++++++++++----------
>>   drivers/cpufreq/cpufreq_governor.h |   20 ++++++++++----------
>>   2 files changed, 20 insertions(+), 20 deletions(-)
>>
>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
>> ===================================================================
>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
>> @@ -78,7 +78,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
>>   static ssize_t show_##file_name##_gov_sys                \
>>   (struct kobject *kobj, struct attribute *attr, char *buf)        \
>>   {                                    \
>> -    struct _gov##_dbs_tuners *tuners =
>> _gov##_dbs_cdata.gdbs_data->tuners; \
>> +    struct _gov##_dbs_tuners *tuners = global_dbs_data->tuners; \
>>       return sprintf(buf, "%u\n", tuners->file_name);            \
>>   }                                    \
>>                                       \
>> @@ -94,7 +94,7 @@ static ssize_t show_##file_name##_gov_po
>>   static ssize_t store_##file_name##_gov_sys                \
>>   (struct kobject *kobj, struct attribute *attr, const char *buf,
>> size_t count) \
>>   {                                    \
>> -    struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;        \
>> +    struct dbs_data *dbs_data = global_dbs_data;        \
>>       return store_##file_name(dbs_data, buf, count);            \
>>   }                                    \
>>                                       \
>> @@ -201,19 +201,14 @@ struct cs_dbs_tuners {
>>   /* Common Governor data across policies */
>>   struct dbs_data;
>>   struct common_dbs_data {
>> -    /* Common across governors */
>> +    struct cpufreq_governor gov;
>> +

Actually, this line is completely unrelated to this patch. Should go on 
Patch 5?

>
> Cautiously Acked-by: Saravana Kannan <skannan@codeaurora.org>

Good call on the "cautiously" I guess!

-Saravana

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data
  2016-02-03 23:31 ` [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
@ 2016-02-04  1:57   ` Saravana Kannan
  0 siblings, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  1:57 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:31 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> For the ondemand and conservative governors (generally, governors
> that use the common code in cpufreq_governor.c), there are two static
> data structures representing the governor, the struct governor
> structure (the interface to the cpufreq core) and the struct
> common_dbs_data one (the interface to the cpufreq_governor.c code).
>
> There's no fundamental reason why those two structures have to be
> separate.  Moreover, if the struct governor one is included into
> struct common_dbs_data, it will be possible to reach the latter from
> the policy via its policy->governor pointer, so it won't be necessary
> to pass a separate pointer to it around.  For this reason, embed
> struct governor in struct common_dbs_data.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq_conservative.c |   78 +++++++++++++++++----------------
>   drivers/cpufreq/cpufreq_ondemand.c     |   26 ++++++-----
>   2 files changed, 56 insertions(+), 48 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
> +++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> @@ -539,7 +539,16 @@ static struct od_ops od_ops = {
>   	.freq_increase = dbs_freq_increase,
>   };
>
> +static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> +				   unsigned int event);
> +
>   static struct common_dbs_data od_dbs_cdata = {
> +	.gov = {
> +		.name = "ondemand",
> +		.governor = od_cpufreq_governor_dbs,
> +		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> +		.owner = THIS_MODULE,
> +	},
>   	.governor = GOV_ONDEMAND,
>   	.attr_group_gov_sys = &od_attr_group_gov_sys,
>   	.attr_group_gov_pol = &od_attr_group_gov_pol,
> @@ -552,19 +561,14 @@ static struct common_dbs_data od_dbs_cda
>   	.exit = od_exit,
>   };
>
> +#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_cdata.gov)
> +
>   static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
>   		unsigned int event)
>   {
>   	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
>   }
>
> -static struct cpufreq_governor cpufreq_gov_ondemand = {
> -	.name			= "ondemand",
> -	.governor		= od_cpufreq_governor_dbs,
> -	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> -	.owner			= THIS_MODULE,
> -};
> -
>   static void od_set_powersave_bias(unsigned int powersave_bias)
>   {
>   	struct cpufreq_policy *policy;
> @@ -590,7 +594,7 @@ static void od_set_powersave_bias(unsign
>   		policy = shared->policy;
>   		cpumask_or(&done, &done, policy->cpus);
>
> -		if (policy->governor != &cpufreq_gov_ondemand)
> +		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
>   			continue;
>
>   		dbs_data = policy->governor_data;
> @@ -618,12 +622,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersav
>
>   static int __init cpufreq_gov_dbs_init(void)
>   {
> -	return cpufreq_register_governor(&cpufreq_gov_ondemand);
> +	return cpufreq_register_governor(CPU_FREQ_GOV_ONDEMAND);
>   }
>
>   static void __exit cpufreq_gov_dbs_exit(void)
>   {
> -	cpufreq_unregister_governor(&cpufreq_gov_ondemand);
> +	cpufreq_unregister_governor(CPU_FREQ_GOV_ONDEMAND);
>   }
>
>   MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
> @@ -635,7 +639,7 @@ MODULE_LICENSE("GPL");
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
>   struct cpufreq_governor *cpufreq_default_governor(void)
>   {
> -	return &cpufreq_gov_ondemand;
> +	return CPU_FREQ_GOV_ONDEMAND;
>   }
>
>   fs_initcall(cpufreq_gov_dbs_init);
> Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
> +++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
> @@ -23,16 +23,6 @@
>
>   static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
>
> -static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -				   unsigned int event);
> -
> -static struct cpufreq_governor cpufreq_gov_conservative = {
> -	.name			= "conservative",
> -	.governor		= cs_cpufreq_governor_dbs,
> -	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
> -	.owner			= THIS_MODULE,
> -};
> -
>   static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
>   					   struct cpufreq_policy *policy)
>   {
> @@ -122,30 +112,7 @@ static unsigned int cs_dbs_timer(struct
>   }
>
>   static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
> -		void *data)
> -{
> -	struct cpufreq_freqs *freq = data;
> -	struct cs_cpu_dbs_info_s *dbs_info =
> -					&per_cpu(cs_cpu_dbs_info, freq->cpu);
> -	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
> -
> -	if (!policy)
> -		return 0;
> -
> -	/* policy isn't governed by conservative governor */
> -	if (policy->governor != &cpufreq_gov_conservative)
> -		return 0;
> -
> -	/*
> -	 * we only care if our internally tracked freq moves outside the 'valid'
> -	 * ranges of frequency available to us otherwise we do not change it
> -	*/
> -	if (dbs_info->requested_freq > policy->max
> -			|| dbs_info->requested_freq < policy->min)
> -		dbs_info->requested_freq = freq->new;
> -
> -	return 0;
> -}
> +				void *data);
>
>   static struct notifier_block cs_cpufreq_notifier_block = {
>   	.notifier_call = dbs_cpufreq_notifier,
> @@ -358,7 +325,16 @@ static void cs_exit(struct dbs_data *dbs
>
>   define_get_cpu_dbs_routines(cs_cpu_dbs_info);
>
> +static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> +				   unsigned int event);
> +
>   static struct common_dbs_data cs_dbs_cdata = {
> +	.gov = {
> +		.name = "conservative",
> +		.governor = cs_cpufreq_governor_dbs,
> +		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
> +		.owner = THIS_MODULE,
> +	},
>   	.governor = GOV_CONSERVATIVE,
>   	.attr_group_gov_sys = &cs_attr_group_gov_sys,
>   	.attr_group_gov_pol = &cs_attr_group_gov_pol,
> @@ -370,20 +346,48 @@ static struct common_dbs_data cs_dbs_cda
>   	.exit = cs_exit,
>   };
>
> +#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_cdata.gov)
> +
>   static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
>   				   unsigned int event)
>   {
>   	return cpufreq_governor_dbs(policy, &cs_dbs_cdata, event);
>   }
>
> +static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
> +				void *data)
> +{
> +	struct cpufreq_freqs *freq = data;
> +	struct cs_cpu_dbs_info_s *dbs_info =
> +					&per_cpu(cs_cpu_dbs_info, freq->cpu);
> +	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
> +
> +	if (!policy)
> +		return 0;
> +
> +	/* policy isn't governed by conservative governor */
> +	if (policy->governor != CPU_FREQ_GOV_CONSERVATIVE)
> +		return 0;
> +
> +	/*
> +	 * we only care if our internally tracked freq moves outside the 'valid'
> +	 * ranges of frequency available to us otherwise we do not change it
> +	*/
> +	if (dbs_info->requested_freq > policy->max
> +			|| dbs_info->requested_freq < policy->min)
> +		dbs_info->requested_freq = freq->new;
> +
> +	return 0;
> +}
> +
>   static int __init cpufreq_gov_dbs_init(void)
>   {
> -	return cpufreq_register_governor(&cpufreq_gov_conservative);
> +	return cpufreq_register_governor(CPU_FREQ_GOV_CONSERVATIVE);
>   }
>
>   static void __exit cpufreq_gov_dbs_exit(void)
>   {
> -	cpufreq_unregister_governor(&cpufreq_gov_conservative);
> +	cpufreq_unregister_governor(CPU_FREQ_GOV_CONSERVATIVE);
>   }
>
>   MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
> @@ -395,7 +399,7 @@ MODULE_LICENSE("GPL");
>   #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
>   struct cpufreq_governor *cpufreq_default_governor(void)
>   {
> -	return &cpufreq_gov_conservative;
> +	return CPU_FREQ_GOV_CONSERVATIVE;
>   }
>
>   fs_initcall(cpufreq_gov_dbs_init);
>

I'm not sold on the macros/#defines for the &blah.gov, but not a strong 
opinion.

Acked-by: Saravana Kannan <skannan@codeaurora.org>

-Saravana

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs()
  2016-02-03 23:33 ` [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
@ 2016-02-04  2:03   ` Saravana Kannan
  0 siblings, 0 replies; 86+ messages in thread
From: Saravana Kannan @ 2016-02-04  2:03 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle

On 02/03/2016 03:33 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Since it is possible to obtain a pointer to struct dbs_governor
> from a pointer to the struct governor embedded in it via
> container_of(), the second argument of cpufreq_governor_init()
> is not necessary.  Accordingly, cpufreq_governor_dbs() doesn't
> need its second argument either and the ->governor callbacks
> for both the ondemand and conservative governors may be set
> to cpufreq_governor_dbs() directly.  Make that happen.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/cpufreq/cpufreq_conservative.c |   11 +----------
>   drivers/cpufreq/cpufreq_governor.c     |   10 +++++-----
>   drivers/cpufreq/cpufreq_governor.h     |    3 +--
>   drivers/cpufreq/cpufreq_ondemand.c     |   11 +----------
>   4 files changed, 8 insertions(+), 27 deletions(-)
>
> Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
> +++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
> @@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbs
>
>   define_get_cpu_dbs_routines(cs_cpu_dbs_info);
>
> -static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -				   unsigned int event);
> -
>   static struct dbs_governor cs_dbs_gov = {
>   	.gov = {
>   		.name = "conservative",
> -		.governor = cs_cpufreq_governor_dbs,
> +		.governor = cpufreq_governor_dbs,
>   		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
>   		.owner = THIS_MODULE,
>   	},
> @@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =
>
>   #define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_gov.gov)
>
> -static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -				   unsigned int event)
> -{
> -	return cpufreq_governor_dbs(policy, &cs_dbs_gov, event);
> -}
> -
>   static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
>   				void *data)
>   {
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -329,9 +329,9 @@ static void free_common_dbs_info(struct
>   	kfree(shared);
>   }
>
> -static int cpufreq_governor_init(struct cpufreq_policy *policy,
> -				 struct dbs_governor *gov)
> +static int cpufreq_governor_init(struct cpufreq_policy *policy)
>   {
> +	struct dbs_governor *gov;
>   	struct dbs_data *dbs_data;
>   	unsigned int latency;
>   	int ret;
> @@ -340,6 +340,7 @@ static int cpufreq_governor_init(struct
>   	if (policy->governor_data)
>   		return -EBUSY;
>
> +	gov = container_of(policy->governor, struct dbs_governor, gov);
>   	if (global_dbs_data) {
>   		if (WARN_ON(have_governor_per_policy()))
>   			return -EINVAL;
> @@ -538,8 +539,7 @@ static int cpufreq_governor_limits(struc
>   	return 0;
>   }
>
> -int cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -			 struct dbs_governor *gov, unsigned int event)
> +int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event)
>   {
>   	int ret = -EINVAL;
>
> @@ -547,7 +547,7 @@ int cpufreq_governor_dbs(struct cpufreq_
>   	mutex_lock(&dbs_data_mutex);
>
>   	if (event == CPUFREQ_GOV_POLICY_INIT) {
> -		ret = cpufreq_governor_init(policy, gov);
> +		ret = cpufreq_governor_init(policy);
>   	} else if (policy->governor_data) {
>   		switch (event) {
>   		case CPUFREQ_GOV_POLICY_EXIT:
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
> @@ -273,8 +273,7 @@ void gov_set_update_util(struct cpu_comm
>   			 unsigned int delay_us);
>   void gov_cancel_work(struct cpu_common_dbs_info *shared);
>   void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
> -int cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -		struct dbs_governor *gov, unsigned int event);
> +int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
>   void od_register_powersave_bias_handler(unsigned int (*f)
>   		(struct cpufreq_policy *, unsigned int, unsigned int),
>   		unsigned int powersave_bias);
> Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
> +++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
> @@ -539,13 +539,10 @@ static struct od_ops od_ops = {
>   	.freq_increase = dbs_freq_increase,
>   };
>
> -static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -				   unsigned int event);
> -
>   static struct dbs_governor od_dbs_gov = {
>   	.gov = {
>   		.name = "ondemand",
> -		.governor = od_cpufreq_governor_dbs,
> +		.governor = cpufreq_governor_dbs,
>   		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
>   		.owner = THIS_MODULE,
>   	},
> @@ -563,12 +560,6 @@ static struct dbs_governor od_dbs_gov =
>
>   #define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_gov.gov)
>
> -static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
> -		unsigned int event)
> -{
> -	return cpufreq_governor_dbs(policy, &od_dbs_gov, event);
> -}
> -
>   static void od_set_powersave_bias(unsigned int powersave_bias)
>   {
>   	struct cpufreq_policy *policy;
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

Nice!

Acked-by: Saravana Kannan <skannan@codeaurora.org>

-Saravana

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 1/11] cpufreq: Clean up default and fallback governor setup
  2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
  2016-02-04  0:55   ` Saravana Kannan
@ 2016-02-04  5:03   ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  5:03 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 00:14, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The preprocessor magic used for setting the default cpufreq governor
> (and for using the performance governor as a fallback one for that
> matter) is really nasty, so replace it with __weak functions and
> overrides.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq.c              |   37 ++++++++++++++++++---------------
>  drivers/cpufreq/cpufreq_conservative.c |   10 +++++---
>  drivers/cpufreq/cpufreq_ondemand.c     |   34 ++++++++++++++++--------------
>  drivers/cpufreq/cpufreq_performance.c  |   18 ++++++++++++----
>  drivers/cpufreq/cpufreq_powersave.c    |   10 +++++---
>  drivers/cpufreq/cpufreq_userspace.c    |   10 +++++---
>  include/linux/cpufreq.h                |   25 +---------------------
>  7 files changed, 73 insertions(+), 71 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-03 23:16 ` [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
  2016-02-04  0:59   ` Saravana Kannan
@ 2016-02-04  5:09   ` Viresh Kumar
  2016-02-04 16:46     ` Rafael J. Wysocki
  1 sibling, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  5:09 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 00:16, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Every governor relying on the common code in cpufreq_governor.c
> has to provide its own mutex in struct common_dbs_data.  However,
> those mutexes are never used at the same time

Why do you think so? I thought they can always be used in parallel.

Consider 2 or more policies, one can have ondemand as the governor,
whereas other one can have conservative.

If CPUs go online/offline or if governors are switching in parallel,
then cpufreq_governor_dbs() can very much run in parallel for ondemand
and conservative.

Or am I missing something here ?

-- 
viresh

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-03 23:22 ` [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer Rafael J. Wysocki
  2016-02-04  1:11   ` Saravana Kannan
@ 2016-02-04  5:36   ` Viresh Kumar
       [not found]     ` <CAHZ_5WxJSDtFyFdCc-D2=HSaPON=3rzUxpxPYsCyZvrV1Nv3qw@mail.gmail.com>
  2016-02-04 16:52     ` Rafael J. Wysocki
  1 sibling, 2 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  5:36 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 00:22, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> If the ondemand and conservative governors cannot use per-policy
> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
> driver), all policy objects point to the same single dbs_data object.
> Additionally, that object is pointed to by a global pointer hidden in
> the governor's data structures.
> 
> There is no reason for that pointer to be buried in those
> data structures, though, so make it explicitly global.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -22,6 +22,9 @@
>  
>  #include "cpufreq_governor.h"
>  
> +struct dbs_data *global_dbs_data;
> +EXPORT_SYMBOL_GPL(global_dbs_data);

Oh man, please save me from Rafael's Rant :)

I think, this is simply wrong.

Believe me its very difficult for me to say this to you :). You are
way better than me, and I am sure that I haven't understood cupfreq
after so many years :)

Consider a two policy system, who is stopping us from setting ondemand
for one of them and conservative for the other one ? And so, we will
have two gdbs_data ..

Sorry for the noise, if I am being utterly stupid :(

-- 
viresh

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  1:25     ` Rafael J. Wysocki
  2016-02-04  1:40       ` Saravana Kannan
@ 2016-02-04  5:38       ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  5:38 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Saravana Kannan, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle

On 04-02-16, 02:25, Rafael J. Wysocki wrote:
> You are talking about something like this now:
> 
>     if (condition)
>         goto label;
> 
>     return 0;
> 
> label:
>     do stuff
> 
> I'm sorry, but I fail to see how this is easier to read than
> 
>     if (!condition)
>         return 0;
> 
>     do stuff

I have seen few people (Like Dan Carpenter), mostly coccinelle guys,
saying that we should write code like this:

if (error)
        ...

return success;

Though I should accept that I would have written code the way Rafael
has done this time, but those people get back everytime :)

-- 
viresh

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

* Re: [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (10 preceding siblings ...)
  2016-02-03 23:38 ` [PATCH 11/11] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
@ 2016-02-04  5:40 ` Viresh Kumar
  2016-02-04 17:22   ` Rafael J. Wysocki
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
  12 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  5:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 00:12, Rafael J. Wysocki wrote:
> Hi,
> 
> A few days ago I looked at the common code used by the ondemand and conservative
> governors because of the deadlock issue that Viresh has addressed recently
> (http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me
> that the whole thing was really too tangled and might be made easier to follow
> at least.  I started to work on this and ended up with the following series.
> 
> I'm not really going to stop here, but first, I'd like to let everybody know
> that this is happening and second, I'll need to rebase these patches on the
> ones from Viresh (in the series linked above), but that may take some time
> and I don't want to sit on them for all that long.
> 
> Overall, I'd like the governor code to be cleaner and easier to follow, so we can
> move at least some parts of governor work to utilization update callbacks (invoked
> by the scheduler) or to at least to irq_work so as to reduce the usage of process
> context in cpufreq to absolute minimum.  That's the plan for the future, but for
> now this is just a major cleanup.
> 
> [1/11] Clean up the way in which the default and fallback governors are set up.
> [2/11] Use a common global mutex for dbs_data protection.
> [3/11] Use common global pointer to dbs_data for system-wide governors.

Hi Rafael,

I have some very basic doubts on 2nd and 3rd patch, and so have
stopped reviewing after that because there is too much dependency I
believe on these two.

I will review the rest, if my concerns on the earlier ones are
incorrect.

-- 
viresh

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
       [not found]     ` <CAHZ_5WxJSDtFyFdCc-D2=HSaPON=3rzUxpxPYsCyZvrV1Nv3qw@mail.gmail.com>
@ 2016-02-04  8:25       ` Viresh Kumar
  2016-02-04 11:31         ` Gautham R Shenoy
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04  8:25 UTC (permalink / raw)
  To: ego
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 13:44, Gautham R Shenoy wrote:
> In a a two policy system, to run ondemand on one and conservative on the other,
>  won't the driver have CPUFREQ_HAVE_GOVERNOR_PER_POLICY set?  

No.

CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not about the facility of using
separate governor-type for each policy, that is always available to
the user.

CPUFREQ_HAVE_GOVERNOR_PER_POLICY was initially added for platforms
with different type of CPUs on the same chip, though others can
benefit from it as well.

For example, on a 4 core ARM big LITTLE platform, we will have:
- 2 A7 (low performance/low power)
- 2 A15 (high performance/high power)

The A7's share a policy and A15's share another one.

Without CPUFREQ_HAVE_GOVERNOR_PER_POLICY, if ondemand is selected for
both the policies, the we used to get a single directory (and a set of
tunables) at /sys/devices/system/cpu/cpufreq/ondemand/ .

That used to force us to use same tunables, like sampling rate, etc
for both the policies.

But because the CPUs were so different, we really wanted independent
control.

So, we designed CPUFREQ_HAVE_GOVERNOR_PER_POLICY, so that in such
cases, each policy will have a set of tunables for the same governor
type.

Hope that makes it clear.

If the below questionnaire is still valid, please let me know :)

> If yes, then the changes in this patch won't come into play.
> 
> Also in cpufreq_governor.c, we set cdata->gdbs_data only when 
> !have_governor_per_policy(). cdata->gdbs_data is NULL otherwise.
> A cursory inspection doesn't show any other place in the cpufreq codebase
>  where cdata->gdbs_data is set. Unless I have missed one such initialization, 
> based on my reading of the patch, instead of doing an extra hop to get the 
> governor data via cdata->gdbs_data, we can simply record it in a global
> variable.
> 
> Also, if your concern is regarding the use of show_##file_name##_gov_sys in
> case
> of governor per policy, then the existing code is also broken, since we would
> be 
> accessing _gov##_dbs_cdata.gdbs_data->tuners where _gov##_dbs_cdata.gdbs_data 
> will be NULL!.
> 
> What am I missing ?

-- 
viresh

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  8:25       ` Viresh Kumar
@ 2016-02-04 11:31         ` Gautham R Shenoy
  2016-02-04 11:35           ` Viresh Kumar
  0 siblings, 1 reply; 86+ messages in thread
From: Gautham R Shenoy @ 2016-02-04 11:31 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: ego, Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

Hello Viresh,

On Thu, Feb 04, 2016 at 01:55:38PM +0530, Viresh Kumar wrote:
> On 04-02-16, 13:44, Gautham R Shenoy wrote:
> > In a a two policy system, to run ondemand on one and conservative on the other,
> >  won't the driver have CPUFREQ_HAVE_GOVERNOR_PER_POLICY set?  
> 
> No.
> 
> CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not about the facility of using
> separate governor-type for each policy, that is always available to
> the user.
> 
> CPUFREQ_HAVE_GOVERNOR_PER_POLICY was initially added for platforms
> with different type of CPUs on the same chip, though others can
> benefit from it as well.
> 
> For example, on a 4 core ARM big LITTLE platform, we will have:
> - 2 A7 (low performance/low power)
> - 2 A15 (high performance/high power)
> 
> The A7's share a policy and A15's share another one.
> 
> Without CPUFREQ_HAVE_GOVERNOR_PER_POLICY, if ondemand is selected for
> both the policies, the we used to get a single directory (and a set of
> tunables) at /sys/devices/system/cpu/cpufreq/ondemand/ .
> 
> That used to force us to use same tunables, like sampling rate, etc
> for both the policies.
> 
> But because the CPUs were so different, we really wanted independent
> control.
> 
> So, we designed CPUFREQ_HAVE_GOVERNOR_PER_POLICY, so that in such
> cases, each policy will have a set of tunables for the same governor
> type.
> 
> Hope that makes it clear.

Yes it does! Thank you for the explanation.

So, the CPUFREQ_HAVE_GOVERNOR_PER_POLICY is really
CPUFREQ_HAVE_GOVERNOR_TUNERS_PER_POLICY. Can we change the name to
reflect the intent?

> 
> If the below questionnaire is still valid, please let me know :)

No, it is no longer valid!
> 
> viresh

--
Thanks and Regards
gautham.

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04 11:31         ` Gautham R Shenoy
@ 2016-02-04 11:35           ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-04 11:35 UTC (permalink / raw)
  To: Gautham R Shenoy
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 17:01, Gautham R Shenoy wrote:
> Yes it does! Thank you for the explanation.
> 
> So, the CPUFREQ_HAVE_GOVERNOR_PER_POLICY is really
> CPUFREQ_HAVE_GOVERNOR_TUNERS_PER_POLICY. Can we change the name to
> reflect the intent?

Hmm, we might wanna do that. Though we are quite busy (screwed up) at
the moment, will do that later on :)

-- 
viresh

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-04  5:09   ` Viresh Kumar
@ 2016-02-04 16:46     ` Rafael J. Wysocki
  2016-02-05  2:59       ` Viresh Kumar
  0 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-04 16:46 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On Thu, Feb 4, 2016 at 6:09 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 04-02-16, 00:16, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> Every governor relying on the common code in cpufreq_governor.c
>> has to provide its own mutex in struct common_dbs_data.  However,
>> those mutexes are never used at the same time
>
> Why do you think so? I thought they can always be used in parallel.
>
> Consider 2 or more policies, one can have ondemand as the governor,
> whereas other one can have conservative.
>
> If CPUs go online/offline or if governors are switching in parallel,
> then cpufreq_governor_dbs() can very much run in parallel for ondemand
> and conservative.
>
> Or am I missing something here ?

Well, so perhaps the changelog is inaccurate.

However, what's wrong with using a single mutex then?

Thanks,
Rafael

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04  5:36   ` Viresh Kumar
       [not found]     ` <CAHZ_5WxJSDtFyFdCc-D2=HSaPON=3rzUxpxPYsCyZvrV1Nv3qw@mail.gmail.com>
@ 2016-02-04 16:52     ` Rafael J. Wysocki
  2016-02-05  3:02       ` Viresh Kumar
  1 sibling, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-04 16:52 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On Thu, Feb 4, 2016 at 6:36 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 04-02-16, 00:22, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> If the ondemand and conservative governors cannot use per-policy
>> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
>> driver), all policy objects point to the same single dbs_data object.
>> Additionally, that object is pointed to by a global pointer hidden in
>> the governor's data structures.
>>
>> There is no reason for that pointer to be buried in those
>> data structures, though, so make it explicitly global.
>>
>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
>> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
>> ===================================================================
>> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
>> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
>> @@ -22,6 +22,9 @@
>>
>>  #include "cpufreq_governor.h"
>>
>> +struct dbs_data *global_dbs_data;
>> +EXPORT_SYMBOL_GPL(global_dbs_data);
>
> Oh man, please save me from Rafael's Rant :)
>
> I think, this is simply wrong.
>
> Believe me its very difficult for me to say this to you :). You are
> way better than me, and I am sure that I haven't understood cupfreq
> after so many years :)
>
> Consider a two policy system, who is stopping us from setting ondemand
> for one of them and conservative for the other one ? And so, we will
> have two gdbs_data ..

I don't really regard that as an entirely sane thing to do, but you
have a point here.

> Sorry for the noise, if I am being utterly stupid :(

No, that's something I have overlooked, sorry about that.

Well, I'll need to go back to this patch or maybe drop it even.

Thanks,
Rafael

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

* Re: [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework
  2016-02-04  5:40 ` [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Viresh Kumar
@ 2016-02-04 17:22   ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-04 17:22 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On Thu, Feb 4, 2016 at 6:40 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 04-02-16, 00:12, Rafael J. Wysocki wrote:
>> Hi,
>>
>> A few days ago I looked at the common code used by the ondemand and conservative
>> governors because of the deadlock issue that Viresh has addressed recently
>> (http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me
>> that the whole thing was really too tangled and might be made easier to follow
>> at least.  I started to work on this and ended up with the following series.
>>
>> I'm not really going to stop here, but first, I'd like to let everybody know
>> that this is happening and second, I'll need to rebase these patches on the
>> ones from Viresh (in the series linked above), but that may take some time
>> and I don't want to sit on them for all that long.
>>
>> Overall, I'd like the governor code to be cleaner and easier to follow, so we can
>> move at least some parts of governor work to utilization update callbacks (invoked
>> by the scheduler) or to at least to irq_work so as to reduce the usage of process
>> context in cpufreq to absolute minimum.  That's the plan for the future, but for
>> now this is just a major cleanup.
>>
>> [1/11] Clean up the way in which the default and fallback governors are set up.
>> [2/11] Use a common global mutex for dbs_data protection.
>> [3/11] Use common global pointer to dbs_data for system-wide governors.
>
> Hi Rafael,
>
> I have some very basic doubts on 2nd and 3rd patch, and so have
> stopped reviewing after that because there is too much dependency I
> believe on these two.
>
> I will review the rest, if my concerns on the earlier ones are
> incorrect.

Patch [3/11] is really incorrect (thanks for pointing the problem out
to me), but it also isn't essential, so I can drop it just fine I
think.

I don't see issues with the [2/11], though, apart from the changelog
being inaccurate which should be easy to fix.

Thanks,
Rafael

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

* [PATCH v2 0/10] cpufreq: governor: ondemand/conservative data structures rework
  2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
                   ` (11 preceding siblings ...)
  2016-02-04  5:40 ` [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Viresh Kumar
@ 2016-02-05  2:07 ` Rafael J. Wysocki
  2016-02-05  2:11   ` [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
                     ` (11 more replies)
  12 siblings, 12 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:07 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Thursday, February 04, 2016 12:12:52 AM Rafael J. Wysocki wrote:
> Hi,
> 
> A few days ago I looked at the common code used by the ondemand and conservative
> governors because of the deadlock issue that Viresh has addressed recently
> (http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me
> that the whole thing was really too tangled and might be made easier to follow
> at least.  I started to work on this and ended up with the following series.
> 
> I'm not really going to stop here, but first, I'd like to let everybody know
> that this is happening and second, I'll need to rebase these patches on the
> ones from Viresh (in the series linked above), but that may take some time
> and I don't want to sit on them for all that long.
> 
> Overall, I'd like the governor code to be cleaner and easier to follow, so we can
> move at least some parts of governor work to utilization update callbacks (invoked
> by the scheduler) or to at least to irq_work so as to reduce the usage of process
> context in cpufreq to absolute minimum.  That's the plan for the future, but for
> now this is just a major cleanup.
> 
> [1/11] Clean up the way in which the default and fallback governors are set up.
> [2/11] Use a common global mutex for dbs_data protection.
> [3/11] Use common global pointer to dbs_data for system-wide governors.
> [4/11] Avoid passing dbs_data pointers to functions that can get them by themselves.
> [5/11] Make struct governor be a member of struct common_dbs_data.
> [6/11] Rename struct common_dbs_data to struct dbs_governor.
> [7/11] Rework cpufreq_governor_dbs() so it can be used as a governor callback directly.
> [8/11] Drop the dbs_governor (former cdata) pointer from struct dbs_data.
> [9/11] Rename struct cpu_common_dbs_info to struct policy_dbs_info.
> [10/11] Rearrange data structures so policy->governor_data points to struct policy_dbs_info.
> [11/11] Drop the second argument of dbs_check_cpu().
> 
> The patches are on top of 4.5-rc2 with my earlier series replacing timers with
> utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
> applied.

Some bugs fixed, some comments addressed.  It's time for a v2. :-)

The most significant difference from the previous one is that I've dropped patch
[3/11] (so there are 10 of them in the series now) due to a problem with it pointed
out by Viresh.  Fortunately, this particular one was completely not essential and
the dependencies on it were rather cosmetic.

In addition to that I've rebased the series on top of
https://patchwork.kernel.org/patch/8229901/ as that differs from its previous
version quite a bit.

I've already queued up [1/10] for 4.6 as it seems totally uncontroversial.

The whole series (along with some patches it depends on) is available from the
git branch at

git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git pm-cpufreq-rjw

in case someone wants to try it.  I've tested it (very lightly) on an x86 laptop
with the ACPI cpufreq driver and the ondemand governor.

Thanks,
Rafael

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

* [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
@ 2016-02-05  2:11   ` Rafael J. Wysocki
  2016-02-10  5:15     ` Gautham R Shenoy
  2016-02-05  2:14   ` [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
                     ` (10 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:11 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The preprocessor magic used for setting the default cpufreq governor
(and for using the performance governor as a fallback one for that
matter) is really nasty, so replace it with __weak functions and
overrides.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Saravana Kannan <skannan@codeaurora.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/cpufreq/cpufreq.c              |   37 ++++++++++++++++++---------------
 drivers/cpufreq/cpufreq_conservative.c |   10 +++++---
 drivers/cpufreq/cpufreq_ondemand.c     |   36 ++++++++++++++++----------------
 drivers/cpufreq/cpufreq_performance.c  |   18 ++++++++++++----
 drivers/cpufreq/cpufreq_powersave.c    |   10 +++++---
 drivers/cpufreq/cpufreq_userspace.c    |   10 +++++---
 include/linux/cpufreq.h                |   25 +---------------------
 7 files changed, 73 insertions(+), 73 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1003,6 +1003,11 @@ static int cpufreq_add_dev_interface(str
 	return cpufreq_add_dev_symlink(policy);
 }
 
+__weak struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return NULL;
+}
+
 static int cpufreq_init_policy(struct cpufreq_policy *policy)
 {
 	struct cpufreq_governor *gov = NULL;
@@ -1012,11 +1017,14 @@ static int cpufreq_init_policy(struct cp
 
 	/* Update governor of new_policy to the governor used before hotplug */
 	gov = find_governor(policy->last_governor);
-	if (gov)
+	if (gov) {
 		pr_debug("Restoring governor %s for cpu %d\n",
 				policy->governor->name, policy->cpu);
-	else
-		gov = CPUFREQ_DEFAULT_GOVERNOR;
+	} else {
+		gov = cpufreq_default_governor();
+		if (!gov)
+			return -ENODATA;
+	}
 
 	new_policy.governor = gov;
 
@@ -1964,21 +1972,16 @@ int cpufreq_driver_target(struct cpufreq
 }
 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
 
+__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
+{
+	return NULL;
+}
+
 static int __cpufreq_governor(struct cpufreq_policy *policy,
 					unsigned int event)
 {
 	int ret;
 
-	/* Only must be defined when default governor is known to have latency
-	   restrictions, like e.g. conservative or ondemand.
-	   That this is the case is already ensured in Kconfig
-	*/
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
-	struct cpufreq_governor *gov = &cpufreq_gov_performance;
-#else
-	struct cpufreq_governor *gov = NULL;
-#endif
-
 	/* Don't start any governor operations if we are entering suspend */
 	if (cpufreq_suspended)
 		return 0;
@@ -1992,12 +1995,14 @@ static int __cpufreq_governor(struct cpu
 	if (policy->governor->max_transition_latency &&
 	    policy->cpuinfo.transition_latency >
 	    policy->governor->max_transition_latency) {
-		if (!gov)
-			return -EINVAL;
-		else {
+		struct cpufreq_governor *gov = cpufreq_fallback_governor();
+
+		if (gov) {
 			pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
 				policy->governor->name, gov->name);
 			policy->governor = gov;
+		} else {
+			return -EINVAL;
 		}
 	}
 
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -26,10 +26,7 @@ static DEFINE_PER_CPU(struct cs_cpu_dbs_
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_conservative = {
+static struct cpufreq_governor cpufreq_gov_conservative = {
 	.name			= "conservative",
 	.governor		= cs_cpufreq_governor_dbs,
 	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
@@ -397,6 +394,11 @@ MODULE_DESCRIPTION("'cpufreq_conservativ
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_conservative;
+}
+
 fs_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
Index: linux-pm/include/linux/cpufreq.h
===================================================================
--- linux-pm.orig/include/linux/cpufreq.h
+++ linux-pm/include/linux/cpufreq.h
@@ -471,29 +471,8 @@ int __cpufreq_driver_target(struct cpufr
 int cpufreq_register_governor(struct cpufreq_governor *governor);
 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
 
-/* CPUFREQ DEFAULT GOVERNOR */
-/*
- * Performance governor is fallback governor if any other gov failed to auto
- * load due latency restrictions
- */
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
-extern struct cpufreq_governor cpufreq_gov_performance;
-#endif
-#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_performance)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
-extern struct cpufreq_governor cpufreq_gov_powersave;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_powersave)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
-extern struct cpufreq_governor cpufreq_gov_userspace;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_userspace)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
-extern struct cpufreq_governor cpufreq_gov_ondemand;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_ondemand)
-#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
-extern struct cpufreq_governor cpufreq_gov_conservative;
-#define CPUFREQ_DEFAULT_GOVERNOR	(&cpufreq_gov_conservative)
-#endif
+struct cpufreq_governor *cpufreq_default_governor(void);
+struct cpufreq_governor *cpufreq_fallback_governor(void);
 
 /*********************************************************************
  *                     FREQUENCY TABLE HELPERS                       *
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -31,9 +31,7 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_
 
 static struct od_ops od_ops;
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
 static struct cpufreq_governor cpufreq_gov_ondemand;
-#endif
 
 static unsigned int default_powersave_bias;
 
@@ -553,6 +551,19 @@ static struct common_dbs_data od_dbs_cda
 	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
 };
 
+static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+		unsigned int event)
+{
+	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
+}
+
+static struct cpufreq_governor cpufreq_gov_ondemand = {
+	.name			= "ondemand",
+	.governor		= od_cpufreq_governor_dbs,
+	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+	.owner			= THIS_MODULE,
+};
+
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;
@@ -604,22 +615,6 @@ void od_unregister_powersave_bias_handle
 }
 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
-}
-
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
-static
-#endif
-struct cpufreq_governor cpufreq_gov_ondemand = {
-	.name			= "ondemand",
-	.governor		= od_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static int __init cpufreq_gov_dbs_init(void)
 {
 	return cpufreq_register_governor(&cpufreq_gov_ondemand);
@@ -637,6 +632,11 @@ MODULE_DESCRIPTION("'cpufreq_ondemand' -
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_ondemand;
+}
+
 fs_initcall(cpufreq_gov_dbs_init);
 #else
 module_init(cpufreq_gov_dbs_init);
Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
+++ linux-pm/drivers/cpufreq/cpufreq_performance.c
@@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
 	return 0;
 }
 
-#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_performance = {
+static struct cpufreq_governor cpufreq_gov_performance = {
 	.name		= "performance",
 	.governor	= cpufreq_governor_performance,
 	.owner		= THIS_MODULE,
@@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
 	cpufreq_unregister_governor(&cpufreq_gov_performance);
 }
 
+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_performance;
+}
+#endif
+#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
+struct cpufreq_governor *cpufreq_fallback_governor(void)
+{
+	return &cpufreq_gov_performance;
+}
+#endif
+
 MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
 MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
 MODULE_LICENSE("GPL");
Index: linux-pm/drivers/cpufreq/cpufreq_powersave.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_powersave.c
+++ linux-pm/drivers/cpufreq/cpufreq_powersave.c
@@ -33,10 +33,7 @@ static int cpufreq_governor_powersave(st
 	return 0;
 }
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_powersave = {
+static struct cpufreq_governor cpufreq_gov_powersave = {
 	.name		= "powersave",
 	.governor	= cpufreq_governor_powersave,
 	.owner		= THIS_MODULE,
@@ -57,6 +54,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_powersave;
+}
+
 fs_initcall(cpufreq_gov_powersave_init);
 #else
 module_init(cpufreq_gov_powersave_init);
Index: linux-pm/drivers/cpufreq/cpufreq_userspace.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_userspace.c
+++ linux-pm/drivers/cpufreq/cpufreq_userspace.c
@@ -89,10 +89,7 @@ static int cpufreq_governor_userspace(st
 	return rc;
 }
 
-#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
-static
-#endif
-struct cpufreq_governor cpufreq_gov_userspace = {
+static struct cpufreq_governor cpufreq_gov_userspace = {
 	.name		= "userspace",
 	.governor	= cpufreq_governor_userspace,
 	.store_setspeed	= cpufreq_set,
@@ -116,6 +113,11 @@ MODULE_DESCRIPTION("CPUfreq policy gover
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
+struct cpufreq_governor *cpufreq_default_governor(void)
+{
+	return &cpufreq_gov_userspace;
+}
+
 fs_initcall(cpufreq_gov_userspace_init);
 #else
 module_init(cpufreq_gov_userspace_init);

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

* [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
  2016-02-05  2:11   ` [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
@ 2016-02-05  2:14   ` Rafael J. Wysocki
  2016-02-05  6:53     ` Viresh Kumar
  2016-02-05  2:15   ` [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
                     ` (9 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:14 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Every governor relying on the common code in cpufreq_governor.c
has to provide its own mutex in struct common_dbs_data.  However,
there actually is no need to have a separate mutex per governor
for this purpose, they may be using the same global mutex just
fine.  Accordingly, introduce a single common mutex for that and
drop the mutex field from struct common_dbs_data.

That at least will ensure that the mutex is always present and
initialized regardless of what the particular governors do.

Another benefit is that the common code does not need a pointer to
a governor-related structure to get to the mutex which sometimes
helps.

Finally, it makes the code generally easier to follow.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Saravana Kannan <skannan@codeaurora.org>
---
 drivers/cpufreq/cpufreq_conservative.c |    1 -
 drivers/cpufreq/cpufreq_governor.c     |    7 +++++--
 drivers/cpufreq/cpufreq_governor.h     |    6 +-----
 drivers/cpufreq/cpufreq_ondemand.c     |    5 ++---
 4 files changed, 8 insertions(+), 11 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -22,6 +22,9 @@
 
 #include "cpufreq_governor.h"
 
+DEFINE_MUTEX(dbs_data_mutex);
+EXPORT_SYMBOL_GPL(dbs_data_mutex);
+
 static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
 {
 	if (have_governor_per_policy())
@@ -541,7 +544,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	int ret;
 
 	/* Lock governor to block concurrent initialization of governor */
-	mutex_lock(&cdata->mutex);
+	mutex_lock(&dbs_data_mutex);
 
 	if (have_governor_per_policy())
 		dbs_data = policy->governor_data;
@@ -574,7 +577,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	}
 
 unlock:
-	mutex_unlock(&cdata->mutex);
+	mutex_unlock(&dbs_data_mutex);
 
 	return ret;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -225,11 +225,6 @@ struct common_dbs_data {
 
 	/* Governor specific ops, see below */
 	void *gov_ops;
-
-	/*
-	 * Protects governor's data (struct dbs_data and struct common_dbs_data)
-	 */
-	struct mutex mutex;
 };
 
 /* Governor Per policy data */
@@ -274,6 +269,7 @@ static ssize_t show_sampling_rate_min_go
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }
 
+extern struct mutex dbs_data_mutex;
 extern struct mutex cpufreq_governor_lock;
 void gov_set_update_util(struct cpu_common_dbs_info *shared,
 			 unsigned int delay_us);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -249,7 +249,7 @@ static void update_sampling_rate(struct
 	/*
 	 * Lock governor so that governor start/stop can't execute in parallel.
 	 */
-	mutex_lock(&od_dbs_cdata.mutex);
+	mutex_lock(&dbs_data_mutex);
 
 	cpumask_copy(&cpumask, cpu_online_mask);
 
@@ -302,7 +302,7 @@ static void update_sampling_rate(struct
 		}
 	}
 
-	mutex_unlock(&od_dbs_cdata.mutex);
+	mutex_unlock(&dbs_data_mutex);
 }
 
 static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
@@ -548,7 +548,6 @@ static struct common_dbs_data od_dbs_cda
 	.gov_ops = &od_ops,
 	.init = od_init,
 	.exit = od_exit,
-	.mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex),
 };
 
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -368,7 +368,6 @@ static struct common_dbs_data cs_dbs_cda
 	.gov_check_cpu = cs_check_cpu,
 	.init = cs_init,
 	.exit = cs_exit,
-	.mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex),
 };
 
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,

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

* [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
  2016-02-05  2:11   ` [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
  2016-02-05  2:14   ` [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
@ 2016-02-05  2:15   ` Rafael J. Wysocki
  2016-02-05  7:09     ` Viresh Kumar
  2016-02-05  2:16   ` [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
                     ` (8 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:15 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Do not pass struct dbs_data pointers to the family of functions
implementing governor operations in cpufreq_governor.c as they can
take that pointer from policy->governor by themselves.

The cpufreq_governor_init() case is slightly more complicated, since
policy->governor may be NULL when it is invoked, but then it can reach
the pointer in question via its cdata argument just fine.

While at it, rework cpufreq_governor_dbs() to avoid a pointless
policy_governor check in the CPUFREQ_GOV_POLICY_INIT case.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |   68 ++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 41 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -325,9 +325,9 @@ static void free_common_dbs_info(struct
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data,
 				 struct common_dbs_data *cdata)
 {
+	struct dbs_data *dbs_data = cdata->gdbs_data;
 	unsigned int latency;
 	int ret;
 
@@ -399,9 +399,9 @@ free_dbs_data:
 	return ret;
 }
 
-static int cpufreq_governor_exit(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data)
+static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
 
@@ -428,9 +428,9 @@ static int cpufreq_governor_exit(struct
 	return 0;
 }
 
-static int cpufreq_governor_start(struct cpufreq_policy *policy,
-				  struct dbs_data *dbs_data)
+static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
@@ -497,9 +497,9 @@ static int cpufreq_governor_start(struct
 	return 0;
 }
 
-static int cpufreq_governor_stop(struct cpufreq_policy *policy,
-				 struct dbs_data *dbs_data)
+static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
@@ -513,9 +513,9 @@ static int cpufreq_governor_stop(struct
 	return 0;
 }
 
-static int cpufreq_governor_limits(struct cpufreq_policy *policy,
-				   struct dbs_data *dbs_data)
+static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct common_dbs_data *cdata = dbs_data->cdata;
 	unsigned int cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
@@ -540,45 +540,31 @@ static int cpufreq_governor_limits(struc
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
 			 struct common_dbs_data *cdata, unsigned int event)
 {
-	struct dbs_data *dbs_data;
-	int ret;
+	int ret = -EINVAL;
 
 	/* Lock governor to block concurrent initialization of governor */
 	mutex_lock(&dbs_data_mutex);
 
-	if (have_governor_per_policy())
-		dbs_data = policy->governor_data;
-	else
-		dbs_data = cdata->gdbs_data;
-
-	if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) {
-		ret = -EINVAL;
-		goto unlock;
-	}
-
-	switch (event) {
-	case CPUFREQ_GOV_POLICY_INIT:
-		ret = cpufreq_governor_init(policy, dbs_data, cdata);
-		break;
-	case CPUFREQ_GOV_POLICY_EXIT:
-		ret = cpufreq_governor_exit(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_START:
-		ret = cpufreq_governor_start(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_STOP:
-		ret = cpufreq_governor_stop(policy, dbs_data);
-		break;
-	case CPUFREQ_GOV_LIMITS:
-		ret = cpufreq_governor_limits(policy, dbs_data);
-		break;
-	default:
-		ret = -EINVAL;
+	if (event == CPUFREQ_GOV_POLICY_INIT) {
+		ret = cpufreq_governor_init(policy, cdata);
+	} else if (policy->governor_data) {
+		switch (event) {
+		case CPUFREQ_GOV_POLICY_EXIT:
+			ret = cpufreq_governor_exit(policy);
+			break;
+		case CPUFREQ_GOV_START:
+			ret = cpufreq_governor_start(policy);
+			break;
+		case CPUFREQ_GOV_STOP:
+			ret = cpufreq_governor_stop(policy);
+			break;
+		case CPUFREQ_GOV_LIMITS:
+			ret = cpufreq_governor_limits(policy);
+			break;
+		}
 	}
 
-unlock:
 	mutex_unlock(&dbs_data_mutex);
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(cpufreq_governor_dbs);

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

* [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (2 preceding siblings ...)
  2016-02-05  2:15   ` [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
@ 2016-02-05  2:16   ` Rafael J. Wysocki
  2016-02-05  7:13     ` Viresh Kumar
  2016-02-05  2:17   ` [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
                     ` (7 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:16 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

For the ondemand and conservative governors (generally, governors
that use the common code in cpufreq_governor.c), there are two static
data structures representing the governor, the struct governor
structure (the interface to the cpufreq core) and the struct
common_dbs_data one (the interface to the cpufreq_governor.c code).

There's no fundamental reason why those two structures have to be
separate.  Moreover, if the struct governor one is included into
struct common_dbs_data, it will be possible to reach the latter from
the policy via its policy->governor pointer, so it won't be necessary
to pass a separate pointer to it around.  For this reason, embed
struct governor in struct common_dbs_data.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Saravana Kannan <skannan@codeaurora.org>
---
 drivers/cpufreq/cpufreq_conservative.c |   78 +++++++++++++++++----------------
 drivers/cpufreq/cpufreq_governor.h     |    3 -
 drivers/cpufreq/cpufreq_ondemand.c     |   28 ++++++-----
 3 files changed, 58 insertions(+), 51 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -31,8 +31,6 @@ static DEFINE_PER_CPU(struct od_cpu_dbs_
 
 static struct od_ops od_ops;
 
-static struct cpufreq_governor cpufreq_gov_ondemand;
-
 static unsigned int default_powersave_bias;
 
 static void ondemand_powersave_bias_init_cpu(int cpu)
@@ -537,7 +535,16 @@ static struct od_ops od_ops = {
 	.freq_increase = dbs_freq_increase,
 };
 
+static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+				   unsigned int event);
+
 static struct common_dbs_data od_dbs_cdata = {
+	.gov = {
+		.name = "ondemand",
+		.governor = od_cpufreq_governor_dbs,
+		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
+		.owner = THIS_MODULE,
+	},
 	.governor = GOV_ONDEMAND,
 	.attr_group_gov_sys = &od_attr_group_gov_sys,
 	.attr_group_gov_pol = &od_attr_group_gov_pol,
@@ -550,19 +557,14 @@ static struct common_dbs_data od_dbs_cda
 	.exit = od_exit,
 };
 
+#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_cdata.gov)
+
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		unsigned int event)
 {
 	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
 }
 
-static struct cpufreq_governor cpufreq_gov_ondemand = {
-	.name			= "ondemand",
-	.governor		= od_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;
@@ -588,7 +590,7 @@ static void od_set_powersave_bias(unsign
 		policy = shared->policy;
 		cpumask_or(&done, &done, policy->cpus);
 
-		if (policy->governor != &cpufreq_gov_ondemand)
+		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
 			continue;
 
 		dbs_data = policy->governor_data;
@@ -616,12 +618,12 @@ EXPORT_SYMBOL_GPL(od_unregister_powersav
 
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_ondemand);
+	return cpufreq_register_governor(CPU_FREQ_GOV_ONDEMAND);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_ondemand);
+	cpufreq_unregister_governor(CPU_FREQ_GOV_ONDEMAND);
 }
 
 MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
@@ -633,7 +635,7 @@ MODULE_LICENSE("GPL");
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
 struct cpufreq_governor *cpufreq_default_governor(void)
 {
-	return &cpufreq_gov_ondemand;
+	return CPU_FREQ_GOV_ONDEMAND;
 }
 
 fs_initcall(cpufreq_gov_dbs_init);
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -23,16 +23,6 @@
 
 static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
-static struct cpufreq_governor cpufreq_gov_conservative = {
-	.name			= "conservative",
-	.governor		= cs_cpufreq_governor_dbs,
-	.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
-	.owner			= THIS_MODULE,
-};
-
 static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
 					   struct cpufreq_policy *policy)
 {
@@ -122,30 +112,7 @@ static unsigned int cs_dbs_timer(struct
 }
 
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
-		void *data)
-{
-	struct cpufreq_freqs *freq = data;
-	struct cs_cpu_dbs_info_s *dbs_info =
-					&per_cpu(cs_cpu_dbs_info, freq->cpu);
-	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
-
-	if (!policy)
-		return 0;
-
-	/* policy isn't governed by conservative governor */
-	if (policy->governor != &cpufreq_gov_conservative)
-		return 0;
-
-	/*
-	 * we only care if our internally tracked freq moves outside the 'valid'
-	 * ranges of frequency available to us otherwise we do not change it
-	*/
-	if (dbs_info->requested_freq > policy->max
-			|| dbs_info->requested_freq < policy->min)
-		dbs_info->requested_freq = freq->new;
-
-	return 0;
-}
+				void *data);
 
 static struct notifier_block cs_cpufreq_notifier_block = {
 	.notifier_call = dbs_cpufreq_notifier,
@@ -358,7 +325,16 @@ static void cs_exit(struct dbs_data *dbs
 
 define_get_cpu_dbs_routines(cs_cpu_dbs_info);
 
+static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+				   unsigned int event);
+
 static struct common_dbs_data cs_dbs_cdata = {
+	.gov = {
+		.name = "conservative",
+		.governor = cs_cpufreq_governor_dbs,
+		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
+		.owner = THIS_MODULE,
+	},
 	.governor = GOV_CONSERVATIVE,
 	.attr_group_gov_sys = &cs_attr_group_gov_sys,
 	.attr_group_gov_pol = &cs_attr_group_gov_pol,
@@ -370,20 +346,48 @@ static struct common_dbs_data cs_dbs_cda
 	.exit = cs_exit,
 };
 
+#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_cdata.gov)
+
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event)
 {
 	return cpufreq_governor_dbs(policy, &cs_dbs_cdata, event);
 }
 
+static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
+				void *data)
+{
+	struct cpufreq_freqs *freq = data;
+	struct cs_cpu_dbs_info_s *dbs_info =
+					&per_cpu(cs_cpu_dbs_info, freq->cpu);
+	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(freq->cpu);
+
+	if (!policy)
+		return 0;
+
+	/* policy isn't governed by conservative governor */
+	if (policy->governor != CPU_FREQ_GOV_CONSERVATIVE)
+		return 0;
+
+	/*
+	 * we only care if our internally tracked freq moves outside the 'valid'
+	 * ranges of frequency available to us otherwise we do not change it
+	*/
+	if (dbs_info->requested_freq > policy->max
+			|| dbs_info->requested_freq < policy->min)
+		dbs_info->requested_freq = freq->new;
+
+	return 0;
+}
+
 static int __init cpufreq_gov_dbs_init(void)
 {
-	return cpufreq_register_governor(&cpufreq_gov_conservative);
+	return cpufreq_register_governor(CPU_FREQ_GOV_CONSERVATIVE);
 }
 
 static void __exit cpufreq_gov_dbs_exit(void)
 {
-	cpufreq_unregister_governor(&cpufreq_gov_conservative);
+	cpufreq_unregister_governor(CPU_FREQ_GOV_CONSERVATIVE);
 }
 
 MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
@@ -395,7 +399,7 @@ MODULE_LICENSE("GPL");
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
 struct cpufreq_governor *cpufreq_default_governor(void)
 {
-	return &cpufreq_gov_conservative;
+	return CPU_FREQ_GOV_CONSERVATIVE;
 }
 
 fs_initcall(cpufreq_gov_dbs_init);
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -203,7 +203,8 @@ struct cs_dbs_tuners {
 /* Common Governor data across policies */
 struct dbs_data;
 struct common_dbs_data {
-	/* Common across governors */
+	struct cpufreq_governor gov;
+
 	#define GOV_ONDEMAND		0
 	#define GOV_CONSERVATIVE	1
 	int governor;

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

* [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (3 preceding siblings ...)
  2016-02-05  2:16   ` [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
@ 2016-02-05  2:17   ` Rafael J. Wysocki
  2016-02-05  7:17     ` Viresh Kumar
  2016-02-05  2:18   ` [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
                     ` (6 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:17 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The ondemand and conservative governors are represented by
struct common_dbs_data whose name doesn't reflect the purpose it
is used for, so rename it to struct dbs_governor and rename
variables of that type accordingly.

No functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    2 
 drivers/cpufreq/cpufreq_conservative.c |    8 +--
 drivers/cpufreq/cpufreq_governor.c     |   88 ++++++++++++++++-----------------
 drivers/cpufreq/cpufreq_governor.h     |   12 ++--
 drivers/cpufreq/cpufreq_ondemand.c     |    8 +--
 5 files changed, 59 insertions(+), 59 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -119,7 +119,7 @@ static struct notifier_block cs_cpufreq_
 };
 
 /************************** sysfs interface ************************/
-static struct common_dbs_data cs_dbs_cdata;
+static struct dbs_governor cs_dbs_gov;
 
 static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
 		const char *buf, size_t count)
@@ -328,7 +328,7 @@ define_get_cpu_dbs_routines(cs_cpu_dbs_i
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-static struct common_dbs_data cs_dbs_cdata = {
+static struct dbs_governor cs_dbs_gov = {
 	.gov = {
 		.name = "conservative",
 		.governor = cs_cpufreq_governor_dbs,
@@ -346,12 +346,12 @@ static struct common_dbs_data cs_dbs_cda
 	.exit = cs_exit,
 };
 
-#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_cdata.gov)
+#define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_gov.gov)
 
 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event)
 {
-	return cpufreq_governor_dbs(policy, &cs_dbs_cdata, event);
+	return cpufreq_governor_dbs(policy, &cs_dbs_gov, event);
 }
 
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -28,14 +28,14 @@ EXPORT_SYMBOL_GPL(dbs_data_mutex);
 static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
 {
 	if (have_governor_per_policy())
-		return dbs_data->cdata->attr_group_gov_pol;
+		return dbs_data->gov->attr_group_gov_pol;
 	else
-		return dbs_data->cdata->attr_group_gov_sys;
+		return dbs_data->gov->attr_group_gov_sys;
 }
 
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
 {
-	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	struct cpufreq_policy *policy = cdbs->shared->policy;
@@ -44,9 +44,9 @@ void dbs_check_cpu(struct dbs_data *dbs_
 	unsigned int ignore_nice;
 	unsigned int j;
 
-	if (dbs_data->cdata->governor == GOV_ONDEMAND) {
+	if (dbs_data->gov->governor == GOV_ONDEMAND) {
 		struct od_cpu_dbs_info_s *od_dbs_info =
-				dbs_data->cdata->get_cpu_dbs_info_s(cpu);
+				dbs_data->gov->get_cpu_dbs_info_s(cpu);
 
 		/*
 		 * Sometimes, the ondemand governor uses an additional
@@ -71,7 +71,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		unsigned int load;
 		int io_busy = 0;
 
-		j_cdbs = dbs_data->cdata->get_cpu_cdbs(j);
+		j_cdbs = dbs_data->gov->get_cpu_cdbs(j);
 
 		/*
 		 * For the purpose of ondemand, waiting for disk IO is
@@ -79,7 +79,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		 * not that the system is actually idle. So do not add
 		 * the iowait time to the cpu idle time.
 		 */
-		if (dbs_data->cdata->governor == GOV_ONDEMAND)
+		if (dbs_data->gov->governor == GOV_ONDEMAND)
 			io_busy = od_tuners->io_is_busy;
 		cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);
 
@@ -160,7 +160,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 			max_load = load;
 	}
 
-	dbs_data->cdata->gov_check_cpu(cpu, max_load);
+	dbs_data->gov->gov_check_cpu(cpu, max_load);
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
@@ -176,7 +176,7 @@ void gov_set_update_util(struct cpu_comm
 	shared->last_sample_time = 0;
 
 	for_each_cpu(cpu, policy->cpus) {
-		struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
+		struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
 
 		cpufreq_set_update_util_data(cpu, &cdbs->update_util);
 	}
@@ -226,7 +226,7 @@ static void dbs_work_handler(struct work
 	 * parallel.
 	 */
 	mutex_lock(&shared->timer_mutex);
-	delay = dbs_data->cdata->gov_dbs_timer(policy);
+	delay = dbs_data->gov->gov_dbs_timer(policy);
 	shared->sample_delay_ns = jiffies_to_nsecs(delay);
 	shared->time_stamp = ktime_get();
 	mutex_unlock(&shared->timer_mutex);
@@ -279,7 +279,7 @@ static void dbs_update_util_handler(stru
 static void set_sampling_rate(struct dbs_data *dbs_data,
 		unsigned int sampling_rate)
 {
-	if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
+	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 		cs_tuners->sampling_rate = sampling_rate;
 	} else {
@@ -289,7 +289,7 @@ static void set_sampling_rate(struct dbs
 }
 
 static int alloc_common_dbs_info(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
 	struct cpu_common_dbs_info *shared;
 	int j;
@@ -301,7 +301,7 @@ static int alloc_common_dbs_info(struct
 
 	/* Set shared for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
-		cdata->get_cpu_cdbs(j)->shared = shared;
+		gov->get_cpu_cdbs(j)->shared = shared;
 
 	mutex_init(&shared->timer_mutex);
 	atomic_set(&shared->skip_work, 0);
@@ -310,24 +310,24 @@ static int alloc_common_dbs_info(struct
 }
 
 static void free_common_dbs_info(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 	int j;
 
 	mutex_destroy(&shared->timer_mutex);
 
 	for_each_cpu(j, policy->cpus)
-		cdata->get_cpu_cdbs(j)->shared = NULL;
+		gov->get_cpu_cdbs(j)->shared = NULL;
 
 	kfree(shared);
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct common_dbs_data *cdata)
+				 struct dbs_governor *gov)
 {
-	struct dbs_data *dbs_data = cdata->gdbs_data;
+	struct dbs_data *dbs_data = gov->gdbs_data;
 	unsigned int latency;
 	int ret;
 
@@ -339,7 +339,7 @@ static int cpufreq_governor_init(struct
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
-		ret = alloc_common_dbs_info(policy, cdata);
+		ret = alloc_common_dbs_info(policy, gov);
 		if (ret)
 			return ret;
 
@@ -352,14 +352,14 @@ static int cpufreq_governor_init(struct
 	if (!dbs_data)
 		return -ENOMEM;
 
-	ret = alloc_common_dbs_info(policy, cdata);
+	ret = alloc_common_dbs_info(policy, gov);
 	if (ret)
 		goto free_dbs_data;
 
-	dbs_data->cdata = cdata;
+	dbs_data->gov = gov;
 	dbs_data->usage_count = 1;
 
-	ret = cdata->init(dbs_data, !policy->governor->initialized);
+	ret = gov->init(dbs_data, !policy->governor->initialized);
 	if (ret)
 		goto free_common_dbs_info;
 
@@ -375,7 +375,7 @@ static int cpufreq_governor_init(struct
 					latency * LATENCY_MULTIPLIER));
 
 	if (!have_governor_per_policy())
-		cdata->gdbs_data = dbs_data;
+		gov->gdbs_data = dbs_data;
 
 	policy->governor_data = dbs_data;
 
@@ -390,10 +390,10 @@ reset_gdbs_data:
 	policy->governor_data = NULL;
 
 	if (!have_governor_per_policy())
-		cdata->gdbs_data = NULL;
-	cdata->exit(dbs_data, !policy->governor->initialized);
+		gov->gdbs_data = NULL;
+	gov->exit(dbs_data, !policy->governor->initialized);
 free_common_dbs_info:
-	free_common_dbs_info(policy, cdata);
+	free_common_dbs_info(policy, gov);
 free_dbs_data:
 	kfree(dbs_data);
 	return ret;
@@ -402,8 +402,8 @@ free_dbs_data:
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu);
+	struct dbs_governor *gov = dbs_data->gov;
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to INIT */
 	if (!cdbs->shared || cdbs->shared->policy)
@@ -416,24 +416,24 @@ static int cpufreq_governor_exit(struct
 		policy->governor_data = NULL;
 
 		if (!have_governor_per_policy())
-			cdata->gdbs_data = NULL;
+			gov->gdbs_data = NULL;
 
-		cdata->exit(dbs_data, policy->governor->initialized == 1);
+		gov->exit(dbs_data, policy->governor->initialized == 1);
 		kfree(dbs_data);
 	} else {
 		policy->governor_data = NULL;
 	}
 
-	free_common_dbs_info(policy, cdata);
+	free_common_dbs_info(policy, gov);
 	return 0;
 }
 
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
+	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 	int io_busy = 0;
 
@@ -444,7 +444,7 @@ static int cpufreq_governor_start(struct
 	if (!shared || shared->policy)
 		return -EBUSY;
 
-	if (cdata->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 		sampling_rate = cs_tuners->sampling_rate;
@@ -458,7 +458,7 @@ static int cpufreq_governor_start(struct
 	}
 
 	for_each_cpu(j, policy->cpus) {
-		struct cpu_dbs_info *j_cdbs = cdata->get_cpu_cdbs(j);
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
 		unsigned int prev_load;
 
 		j_cdbs->prev_cpu_idle =
@@ -478,15 +478,15 @@ static int cpufreq_governor_start(struct
 	init_irq_work(&shared->irq_work, dbs_irq_work);
 	init_completion(&shared->irq_work_done);
 
-	if (cdata->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
-			cdata->get_cpu_dbs_info_s(cpu);
+			gov->get_cpu_dbs_info_s(cpu);
 
 		cs_dbs_info->down_skip = 0;
 		cs_dbs_info->requested_freq = policy->cur;
 	} else {
-		struct od_ops *od_ops = cdata->gov_ops;
-		struct od_cpu_dbs_info_s *od_dbs_info = cdata->get_cpu_dbs_info_s(cpu);
+		struct od_ops *od_ops = gov->gov_ops;
+		struct od_cpu_dbs_info_s *od_dbs_info = gov->get_cpu_dbs_info_s(cpu);
 
 		od_dbs_info->rate_mult = 1;
 		od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
@@ -500,7 +500,7 @@ static int cpufreq_governor_start(struct
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(policy->cpu);
+	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
 	/* State should be equivalent to START */
@@ -516,9 +516,9 @@ static int cpufreq_governor_stop(struct
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct common_dbs_data *cdata = dbs_data->cdata;
+	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
 	/* State should be equivalent to START */
 	if (!cdbs->shared || !cdbs->shared->policy)
@@ -538,7 +538,7 @@ static int cpufreq_governor_limits(struc
 }
 
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-			 struct common_dbs_data *cdata, unsigned int event)
+			 struct dbs_governor *gov, unsigned int event)
 {
 	int ret = -EINVAL;
 
@@ -546,7 +546,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	mutex_lock(&dbs_data_mutex);
 
 	if (event == CPUFREQ_GOV_POLICY_INIT) {
-		ret = cpufreq_governor_init(policy, cdata);
+		ret = cpufreq_governor_init(policy, gov);
 	} else if (policy->governor_data) {
 		switch (event) {
 		case CPUFREQ_GOV_POLICY_EXIT:
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -79,7 +79,7 @@ __ATTR(_name, 0644, show_##_name##_gov_p
 static ssize_t show_##file_name##_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, char *buf)		\
 {									\
-	struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \
+	struct _gov##_dbs_tuners *tuners = _gov##_dbs_gov.gdbs_data->tuners; \
 	return sprintf(buf, "%u\n", tuners->file_name);			\
 }									\
 									\
@@ -95,7 +95,7 @@ static ssize_t show_##file_name##_gov_po
 static ssize_t store_##file_name##_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
 {									\
-	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
+	struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data;		\
 	return store_##file_name(dbs_data, buf, count);			\
 }									\
 									\
@@ -202,7 +202,7 @@ struct cs_dbs_tuners {
 
 /* Common Governor data across policies */
 struct dbs_data;
-struct common_dbs_data {
+struct dbs_governor {
 	struct cpufreq_governor gov;
 
 	#define GOV_ONDEMAND		0
@@ -230,7 +230,7 @@ struct common_dbs_data {
 
 /* Governor Per policy data */
 struct dbs_data {
-	struct common_dbs_data *cdata;
+	struct dbs_governor *gov;
 	unsigned int min_sampling_rate;
 	int usage_count;
 	void *tuners;
@@ -259,7 +259,7 @@ static inline int delay_for_sampling_rat
 static ssize_t show_sampling_rate_min_gov_sys				\
 (struct kobject *kobj, struct attribute *attr, char *buf)		\
 {									\
-	struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data;		\
+	struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data;		\
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }									\
 									\
@@ -277,7 +277,7 @@ void gov_set_update_util(struct cpu_comm
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		struct common_dbs_data *cdata, unsigned int event);
+		struct dbs_governor *gov, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
 		unsigned int powersave_bias);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -219,7 +219,7 @@ static unsigned int od_dbs_timer(struct
 }
 
 /************************** sysfs interface ************************/
-static struct common_dbs_data od_dbs_cdata;
+static struct dbs_governor od_dbs_gov;
 
 /**
  * update_sampling_rate - update sampling rate effective immediately if needed.
@@ -538,7 +538,7 @@ static struct od_ops od_ops = {
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 				   unsigned int event);
 
-static struct common_dbs_data od_dbs_cdata = {
+static struct dbs_governor od_dbs_gov = {
 	.gov = {
 		.name = "ondemand",
 		.governor = od_cpufreq_governor_dbs,
@@ -557,12 +557,12 @@ static struct common_dbs_data od_dbs_cda
 	.exit = od_exit,
 };
 
-#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_cdata.gov)
+#define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_gov.gov)
 
 static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
 		unsigned int event)
 {
-	return cpufreq_governor_dbs(policy, &od_dbs_cdata, event);
+	return cpufreq_governor_dbs(policy, &od_dbs_gov, event);
 }
 
 static void od_set_powersave_bias(unsigned int powersave_bias)
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_t
 	struct dbs_data *od_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
-		od_data->cdata->get_cpu_dbs_info_s(policy->cpu);
+		od_data->gov->get_cpu_dbs_info_s(policy->cpu);
 
 	if (!od_info->freq_table)
 		return freq_next;

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

* [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs()
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (4 preceding siblings ...)
  2016-02-05  2:17   ` [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
@ 2016-02-05  2:18   ` Rafael J. Wysocki
  2016-02-05  8:14     ` Viresh Kumar
  2016-02-05  2:19   ` [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
                     ` (5 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:18 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since it is possible to obtain a pointer to struct dbs_governor
from a pointer to the struct governor embedded in it via
container_of(), the second argument of cpufreq_governor_init()
is not necessary.  Accordingly, cpufreq_governor_dbs() doesn't
need its second argument either and the ->governor callbacks
for both the ondemand and conservative governors may be set
to cpufreq_governor_dbs() directly.  Make that happen.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Saravana Kannan <skannan@codeaurora.org>
---
 drivers/cpufreq/cpufreq_conservative.c |   11 +----------
 drivers/cpufreq/cpufreq_governor.c     |   10 +++++-----
 drivers/cpufreq/cpufreq_governor.h     |    3 +--
 drivers/cpufreq/cpufreq_ondemand.c     |   11 +----------
 4 files changed, 8 insertions(+), 27 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -325,13 +325,10 @@ static void cs_exit(struct dbs_data *dbs
 
 define_get_cpu_dbs_routines(cs_cpu_dbs_info);
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
 static struct dbs_governor cs_dbs_gov = {
 	.gov = {
 		.name = "conservative",
-		.governor = cs_cpufreq_governor_dbs,
+		.governor = cpufreq_governor_dbs,
 		.max_transition_latency = TRANSITION_LATENCY_LIMIT,
 		.owner = THIS_MODULE,
 	},
@@ -348,12 +345,6 @@ static struct dbs_governor cs_dbs_gov =
 
 #define CPU_FREQ_GOV_CONSERVATIVE	(&cs_dbs_gov.gov)
 
-static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &cs_dbs_gov, event);
-}
-
 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
 				void *data)
 {
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -324,9 +324,10 @@ static void free_common_dbs_info(struct
 	kfree(shared);
 }
 
-static int cpufreq_governor_init(struct cpufreq_policy *policy,
-				 struct dbs_governor *gov)
+static int cpufreq_governor_init(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov = container_of(policy->governor,
+						struct dbs_governor, gov);
 	struct dbs_data *dbs_data = gov->gdbs_data;
 	unsigned int latency;
 	int ret;
@@ -537,8 +538,7 @@ static int cpufreq_governor_limits(struc
 	return 0;
 }
 
-int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-			 struct dbs_governor *gov, unsigned int event)
+int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event)
 {
 	int ret = -EINVAL;
 
@@ -546,7 +546,7 @@ int cpufreq_governor_dbs(struct cpufreq_
 	mutex_lock(&dbs_data_mutex);
 
 	if (event == CPUFREQ_GOV_POLICY_INIT) {
-		ret = cpufreq_governor_init(policy, gov);
+		ret = cpufreq_governor_init(policy);
 	} else if (policy->governor_data) {
 		switch (event) {
 		case CPUFREQ_GOV_POLICY_EXIT:
Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -276,8 +276,7 @@ void gov_set_update_util(struct cpu_comm
 			 unsigned int delay_us);
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
-int cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		struct dbs_governor *gov, unsigned int event);
+int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
 		unsigned int powersave_bias);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -535,13 +535,10 @@ static struct od_ops od_ops = {
 	.freq_increase = dbs_freq_increase,
 };
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-				   unsigned int event);
-
 static struct dbs_governor od_dbs_gov = {
 	.gov = {
 		.name = "ondemand",
-		.governor = od_cpufreq_governor_dbs,
+		.governor = cpufreq_governor_dbs,
 		.max_transition_latency	= TRANSITION_LATENCY_LIMIT,
 		.owner = THIS_MODULE,
 	},
@@ -559,12 +556,6 @@ static struct dbs_governor od_dbs_gov =
 
 #define CPU_FREQ_GOV_ONDEMAND	(&od_dbs_gov.gov)
 
-static int od_cpufreq_governor_dbs(struct cpufreq_policy *policy,
-		unsigned int event)
-{
-	return cpufreq_governor_dbs(policy, &od_dbs_gov, event);
-}
-
 static void od_set_powersave_bias(unsigned int powersave_bias)
 {
 	struct cpufreq_policy *policy;

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

* [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (5 preceding siblings ...)
  2016-02-05  2:18   ` [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
@ 2016-02-05  2:19   ` Rafael J. Wysocki
  2016-02-05  8:28     ` Viresh Kumar
  2016-02-05  2:20   ` [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
                     ` (4 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:19 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since it is possible to obtain a pointer to struct dbs_governor
from a pointer to the struct governor embedded in it with the help
of container_of(), the additional gov pointer in struct dbs_data
isn't really necessary.

Drop that pointer and make the code using it reach the dbs_governor
object via policy->governor.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    2 -
 drivers/cpufreq/cpufreq_conservative.c |    2 -
 drivers/cpufreq/cpufreq_governor.c     |   63 +++++++++++++++------------------
 drivers/cpufreq/cpufreq_governor.h     |    8 +++-
 drivers/cpufreq/cpufreq_ondemand.c     |    2 -
 5 files changed, 39 insertions(+), 38 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -228,9 +228,13 @@ struct dbs_governor {
 	void *gov_ops;
 };
 
+static inline struct dbs_governor *dbs_governor_of(struct cpufreq_policy *policy)
+{
+	return container_of(policy->governor, struct dbs_governor, gov);
+}
+
 /* Governor Per policy data */
 struct dbs_data {
-	struct dbs_governor *gov;
 	unsigned int min_sampling_rate;
 	int usage_count;
 	void *tuners;
@@ -275,7 +279,7 @@ extern struct mutex cpufreq_governor_loc
 void gov_set_update_util(struct cpu_common_dbs_info *shared,
 			 unsigned int delay_us);
 void gov_cancel_work(struct cpu_common_dbs_info *shared);
-void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
+void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
-	dbs_check_cpu(dbs_data, policy->cpu);
+	dbs_check_cpu(policy, policy->cpu);
 	return delay_for_sampling_rate(cs_tuners->sampling_rate);
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -25,28 +25,27 @@
 DEFINE_MUTEX(dbs_data_mutex);
 EXPORT_SYMBOL_GPL(dbs_data_mutex);
 
-static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
+static struct attribute_group *get_sysfs_attr(struct dbs_governor *gov)
 {
-	if (have_governor_per_policy())
-		return dbs_data->gov->attr_group_gov_pol;
-	else
-		return dbs_data->gov->attr_group_gov_sys;
+	return have_governor_per_policy() ?
+		gov->attr_group_gov_pol : gov->attr_group_gov_sys;
 }
 
-void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
+void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
 {
-	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
+	struct dbs_governor *gov = dbs_governor_of(policy);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
+	struct dbs_data *dbs_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
-	struct cpufreq_policy *policy = cdbs->shared->policy;
 	unsigned int sampling_rate;
 	unsigned int max_load = 0;
 	unsigned int ignore_nice;
 	unsigned int j;
 
-	if (dbs_data->gov->governor == GOV_ONDEMAND) {
+	if (gov->governor == GOV_ONDEMAND) {
 		struct od_cpu_dbs_info_s *od_dbs_info =
-				dbs_data->gov->get_cpu_dbs_info_s(cpu);
+				gov->get_cpu_dbs_info_s(cpu);
 
 		/*
 		 * Sometimes, the ondemand governor uses an additional
@@ -71,7 +70,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		unsigned int load;
 		int io_busy = 0;
 
-		j_cdbs = dbs_data->gov->get_cpu_cdbs(j);
+		j_cdbs = gov->get_cpu_cdbs(j);
 
 		/*
 		 * For the purpose of ondemand, waiting for disk IO is
@@ -79,7 +78,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 		 * not that the system is actually idle. So do not add
 		 * the iowait time to the cpu idle time.
 		 */
-		if (dbs_data->gov->governor == GOV_ONDEMAND)
+		if (gov->governor == GOV_ONDEMAND)
 			io_busy = od_tuners->io_is_busy;
 		cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);
 
@@ -160,7 +159,7 @@ void dbs_check_cpu(struct dbs_data *dbs_
 			max_load = load;
 	}
 
-	dbs_data->gov->gov_check_cpu(cpu, max_load);
+	gov->gov_check_cpu(cpu, max_load);
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
@@ -168,7 +167,7 @@ void gov_set_update_util(struct cpu_comm
 			 unsigned int delay_us)
 {
 	struct cpufreq_policy *policy = shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	int cpu;
 
 	shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
@@ -176,7 +175,7 @@ void gov_set_update_util(struct cpu_comm
 	shared->last_sample_time = 0;
 
 	for_each_cpu(cpu, policy->cpus) {
-		struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(cpu);
+		struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
 		cpufreq_set_update_util_data(cpu, &cdbs->update_util);
 	}
@@ -214,11 +213,11 @@ static void dbs_work_handler(struct work
 	struct cpu_common_dbs_info *shared = container_of(work, struct
 					cpu_common_dbs_info, work);
 	struct cpufreq_policy *policy;
-	struct dbs_data *dbs_data;
+	struct dbs_governor *gov;
 	unsigned int delay;
 
 	policy = shared->policy;
-	dbs_data = policy->governor_data;
+	gov = dbs_governor_of(policy);
 
 	/*
 	 * Make sure cpufreq_governor_limits() isn't evaluating load or the
@@ -226,7 +225,7 @@ static void dbs_work_handler(struct work
 	 * parallel.
 	 */
 	mutex_lock(&shared->timer_mutex);
-	delay = dbs_data->gov->gov_dbs_timer(policy);
+	delay = gov->gov_dbs_timer(policy);
 	shared->sample_delay_ns = jiffies_to_nsecs(delay);
 	shared->time_stamp = ktime_get();
 	mutex_unlock(&shared->timer_mutex);
@@ -277,9 +276,10 @@ static void dbs_update_util_handler(stru
 }
 
 static void set_sampling_rate(struct dbs_data *dbs_data,
-		unsigned int sampling_rate)
+			      struct dbs_governor *gov,
+			      unsigned int sampling_rate)
 {
-	if (dbs_data->gov->governor == GOV_CONSERVATIVE) {
+	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 		cs_tuners->sampling_rate = sampling_rate;
 	} else {
@@ -326,8 +326,7 @@ static void free_common_dbs_info(struct
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = container_of(policy->governor,
-						struct dbs_governor, gov);
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = gov->gdbs_data;
 	unsigned int latency;
 	int ret;
@@ -357,7 +356,6 @@ static int cpufreq_governor_init(struct
 	if (ret)
 		goto free_dbs_data;
 
-	dbs_data->gov = gov;
 	dbs_data->usage_count = 1;
 
 	ret = gov->init(dbs_data, !policy->governor->initialized);
@@ -372,7 +370,7 @@ static int cpufreq_governor_init(struct
 	/* Bring kernel and HW constraints together */
 	dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate,
 					  MIN_LATENCY_MULTIPLIER * latency);
-	set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate,
+	set_sampling_rate(dbs_data, gov, max(dbs_data->min_sampling_rate,
 					latency * LATENCY_MULTIPLIER));
 
 	if (!have_governor_per_policy())
@@ -381,7 +379,7 @@ static int cpufreq_governor_init(struct
 	policy->governor_data = dbs_data;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
-				 get_sysfs_attr(dbs_data));
+				 get_sysfs_attr(gov));
 	if (ret)
 		goto reset_gdbs_data;
 
@@ -402,8 +400,8 @@ free_dbs_data:
 
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to INIT */
@@ -412,7 +410,7 @@ static int cpufreq_governor_exit(struct
 
 	if (!--dbs_data->usage_count) {
 		sysfs_remove_group(get_governor_parent_kobj(policy),
-				   get_sysfs_attr(dbs_data));
+				   get_sysfs_attr(gov));
 
 		policy->governor_data = NULL;
 
@@ -431,8 +429,8 @@ static int cpufreq_governor_exit(struct
 
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
@@ -500,8 +498,8 @@ static int cpufreq_governor_start(struct
 
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = dbs_data->gov->get_cpu_cdbs(policy->cpu);
+	struct dbs_governor *gov = dbs_governor_of(policy);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 	struct cpu_common_dbs_info *shared = cdbs->shared;
 
 	/* State should be equivalent to START */
@@ -516,8 +514,7 @@ static int cpufreq_governor_stop(struct
 
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct dbs_governor *gov = dbs_data->gov;
+	struct dbs_governor *gov = dbs_governor_of(policy);
 	unsigned int cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
@@ -532,7 +529,7 @@ static int cpufreq_governor_limits(struc
 	else if (policy->min > cdbs->shared->policy->cur)
 		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
 					CPUFREQ_RELATION_L);
-	dbs_check_cpu(dbs_data, cpu);
+	dbs_check_cpu(policy, cpu);
 	mutex_unlock(&cdbs->shared->timer_mutex);
 
 	return 0;
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -203,7 +203,7 @@ static unsigned int od_dbs_timer(struct
 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
 					CPUFREQ_RELATION_H);
 	} else {
-		dbs_check_cpu(dbs_data, cpu);
+		dbs_check_cpu(policy, cpu);
 		if (dbs_info->freq_lo) {
 			/* Setup timer for SUB_SAMPLE */
 			dbs_info->sample_type = OD_SUB_SAMPLE;
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -48,7 +48,7 @@ static unsigned int amd_powersave_bias_t
 	struct dbs_data *od_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
-		od_data->gov->get_cpu_dbs_info_s(policy->cpu);
+		dbs_governor_of(policy)->get_cpu_dbs_info_s(policy->cpu);
 
 	if (!od_info->freq_table)
 		return freq_next;

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

* [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (6 preceding siblings ...)
  2016-02-05  2:19   ` [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
@ 2016-02-05  2:20   ` Rafael J. Wysocki
  2016-02-05  8:34     ` Viresh Kumar
  2016-02-06 12:48     ` [PATCH v3 " Rafael J. Wysocki
  2016-02-05  2:21   ` [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
                     ` (3 subsequent siblings)
  11 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:20 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The struct cpu_common_dbs_info structure represents the per-policy
part of the governor data (for the ondemand and conservative
governors), but its name doesn't reflect its purpose.

Rename it to struct policy_dbs_info and rename variables related to
it accordingly.

No functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |  120 ++++++++++++++++++-------------------
 drivers/cpufreq/cpufreq_governor.h |    8 +-
 drivers/cpufreq/cpufreq_ondemand.c |   32 ++++-----
 3 files changed, 80 insertions(+), 80 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)
  */
 
 /* Common to all CPUs of a policy */
-struct cpu_common_dbs_info {
+struct policy_dbs_info {
 	struct cpufreq_policy *policy;
 	/*
 	 * Per policy mutex that serializes load evaluation from limit-change
@@ -162,7 +162,7 @@ struct cpu_dbs_info {
 	 */
 	unsigned int prev_load;
 	struct update_util_data update_util;
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *shared;
 };
 
 struct od_cpu_dbs_info_s {
@@ -276,9 +276,9 @@ static ssize_t show_sampling_rate_min_go
 
 extern struct mutex dbs_data_mutex;
 extern struct mutex cpufreq_governor_lock;
-void gov_set_update_util(struct cpu_common_dbs_info *shared,
+void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us);
-void gov_cancel_work(struct cpu_common_dbs_info *shared);
+void gov_cancel_work(struct policy_dbs_info *policy_dbs);
 void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -163,16 +163,16 @@ void dbs_check_cpu(struct cpufreq_policy
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
-void gov_set_update_util(struct cpu_common_dbs_info *shared,
+void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us)
 {
-	struct cpufreq_policy *policy = shared->policy;
+	struct cpufreq_policy *policy = policy_dbs->policy;
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	int cpu;
 
-	shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
-	shared->time_stamp = ktime_get();
-	shared->last_sample_time = 0;
+	policy_dbs->sample_delay_ns = delay_us * NSEC_PER_USEC;
+	policy_dbs->time_stamp = ktime_get();
+	policy_dbs->last_sample_time = 0;
 
 	for_each_cpu(cpu, policy->cpus) {
 		struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
@@ -192,31 +192,31 @@ static inline void gov_clear_update_util
 	synchronize_rcu();
 }
 
-void gov_cancel_work(struct cpu_common_dbs_info *shared)
+void gov_cancel_work(struct policy_dbs_info *policy_dbs)
 {
 	/* Tell dbs_update_util_handler() to skip queuing up work items. */
-	atomic_inc(&shared->skip_work);
+	atomic_inc(&policy_dbs->skip_work);
 	/*
 	 * If dbs_update_util_handler() is already running, it may not notice
 	 * the incremented skip_work, so wait for it to complete to prevent its
 	 * work item from being queued up after the cancel_work_sync() below.
 	 */
-	gov_clear_update_util(shared->policy);
-	wait_for_completion(&shared->irq_work_done);
-	cancel_work_sync(&shared->work);
-	atomic_set(&shared->skip_work, 0);
+	gov_clear_update_util(policy_dbs->policy);
+	wait_for_completion(&policy_dbs->irq_work_done);
+	cancel_work_sync(&policy_dbs->work);
+	atomic_set(&policy_dbs->skip_work, 0);
 }
 EXPORT_SYMBOL_GPL(gov_cancel_work);
 
 static void dbs_work_handler(struct work_struct *work)
 {
-	struct cpu_common_dbs_info *shared = container_of(work, struct
-					cpu_common_dbs_info, work);
+	struct policy_dbs_info *policy_dbs;
 	struct cpufreq_policy *policy;
 	struct dbs_governor *gov;
 	unsigned int delay;
 
-	policy = shared->policy;
+	policy_dbs = container_of(work, struct policy_dbs_info, work);
+	policy = policy_dbs->policy;
 	gov = dbs_governor_of(policy);
 
 	/*
@@ -224,11 +224,11 @@ static void dbs_work_handler(struct work
 	 * ondemand governor isn't reading the time stamp and sampling rate in
 	 * parallel.
 	 */
-	mutex_lock(&shared->timer_mutex);
+	mutex_lock(&policy_dbs->timer_mutex);
 	delay = gov->gov_dbs_timer(policy);
-	shared->sample_delay_ns = jiffies_to_nsecs(delay);
-	shared->time_stamp = ktime_get();
-	mutex_unlock(&shared->timer_mutex);
+	policy_dbs->sample_delay_ns = jiffies_to_nsecs(delay);
+	policy_dbs->time_stamp = ktime_get();
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	/*
 	 * If the atomic operation below is reordered with respect to the
@@ -236,23 +236,23 @@ static void dbs_work_handler(struct work
 	 * up using a stale sample delay value.
 	 */
 	smp_mb__before_atomic();
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void dbs_irq_work(struct irq_work *irq_work)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 
-	shared = container_of(irq_work, struct cpu_common_dbs_info, irq_work);
-	schedule_work(&shared->work);
-	complete(&shared->irq_work_done);
+	policy_dbs = container_of(irq_work, struct policy_dbs_info, irq_work);
+	schedule_work(&policy_dbs->work);
+	complete(&policy_dbs->irq_work_done);
 }
 
 static void dbs_update_util_handler(struct update_util_data *data, u64 time,
 				    unsigned long util, unsigned long max)
 {
 	struct cpu_dbs_info *cdbs = container_of(data, struct cpu_dbs_info, update_util);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 
 	/*
 	 * The work may not be allowed to be queued up right now.
@@ -261,18 +261,18 @@ static void dbs_update_util_handler(stru
 	 * - The governor is being stopped.
 	 * - It is too early (too little time from the previous sample).
 	 */
-	if (atomic_inc_return(&shared->skip_work) == 1) {
+	if (atomic_inc_return(&policy_dbs->skip_work) == 1) {
 		u64 delta_ns;
 
-		delta_ns = time - shared->last_sample_time;
-		if ((s64)delta_ns >= shared->sample_delay_ns) {
-			shared->last_sample_time = time;
-			reinit_completion(&shared->irq_work_done);
-			irq_work_queue_on(&shared->irq_work, smp_processor_id());
+		delta_ns = time - policy_dbs->last_sample_time;
+		if ((s64)delta_ns >= policy_dbs->sample_delay_ns) {
+			policy_dbs->last_sample_time = time;
+			reinit_completion(&policy_dbs->irq_work_done);
+			irq_work_queue_on(&policy_dbs->irq_work, smp_processor_id());
 			return;
 		}
 	}
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void set_sampling_rate(struct dbs_data *dbs_data,
@@ -288,40 +288,40 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_common_dbs_info(struct cpufreq_policy *policy,
+static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 	int j;
 
 	/* Allocate memory for the common information for policy->cpus */
-	shared = kzalloc(sizeof(*shared), GFP_KERNEL);
-	if (!shared)
+	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
+	if (!policy_dbs)
 		return -ENOMEM;
 
-	/* Set shared for all CPUs, online+offline */
+	/* Set policy_dbs for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->shared = shared;
+		gov->get_cpu_cdbs(j)->shared = policy_dbs;
 
-	mutex_init(&shared->timer_mutex);
-	atomic_set(&shared->skip_work, 0);
-	INIT_WORK(&shared->work, dbs_work_handler);
+	mutex_init(&policy_dbs->timer_mutex);
+	atomic_set(&policy_dbs->skip_work, 0);
+	INIT_WORK(&policy_dbs->work, dbs_work_handler);
 	return 0;
 }
 
-static void free_common_dbs_info(struct cpufreq_policy *policy,
+static void free_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int j;
 
-	mutex_destroy(&shared->timer_mutex);
+	mutex_destroy(&policy_dbs->timer_mutex);
 
 	for_each_cpu(j, policy->cpus)
 		gov->get_cpu_cdbs(j)->shared = NULL;
 
-	kfree(shared);
+	kfree(policy_dbs);
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
@@ -339,7 +339,7 @@ static int cpufreq_governor_init(struct
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
-		ret = alloc_common_dbs_info(policy, gov);
+		ret = alloc_policy_dbs_info(policy, gov);
 		if (ret)
 			return ret;
 
@@ -352,7 +352,7 @@ static int cpufreq_governor_init(struct
 	if (!dbs_data)
 		return -ENOMEM;
 
-	ret = alloc_common_dbs_info(policy, gov);
+	ret = alloc_policy_dbs_info(policy, gov);
 	if (ret)
 		goto free_dbs_data;
 
@@ -360,7 +360,7 @@ static int cpufreq_governor_init(struct
 
 	ret = gov->init(dbs_data, !policy->governor->initialized);
 	if (ret)
-		goto free_common_dbs_info;
+		goto free_policy_dbs_info;
 
 	/* policy latency is in ns. Convert it to us first */
 	latency = policy->cpuinfo.transition_latency / 1000;
@@ -391,8 +391,8 @@ reset_gdbs_data:
 	if (!have_governor_per_policy())
 		gov->gdbs_data = NULL;
 	gov->exit(dbs_data, !policy->governor->initialized);
-free_common_dbs_info:
-	free_common_dbs_info(policy, gov);
+free_policy_dbs_info:
+	free_policy_dbs_info(policy, gov);
 free_dbs_data:
 	kfree(dbs_data);
 	return ret;
@@ -423,7 +423,7 @@ static int cpufreq_governor_exit(struct
 		policy->governor_data = NULL;
 	}
 
-	free_common_dbs_info(policy, gov);
+	free_policy_dbs_info(policy, gov);
 	return 0;
 }
 
@@ -433,14 +433,14 @@ static int cpufreq_governor_start(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!shared || shared->policy)
+	if (!policy_dbs || policy_dbs->policy)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -473,9 +473,9 @@ static int cpufreq_governor_start(struct
 
 		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
-	shared->policy = policy;
-	init_irq_work(&shared->irq_work, dbs_irq_work);
-	init_completion(&shared->irq_work_done);
+	policy_dbs->policy = policy;
+	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
+	init_completion(&policy_dbs->irq_work_done);
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -492,7 +492,7 @@ static int cpufreq_governor_start(struct
 		od_ops->powersave_bias_init_cpu(cpu);
 	}
 
-	gov_set_update_util(shared, sampling_rate);
+	gov_set_update_util(policy_dbs, sampling_rate);
 	return 0;
 }
 
@@ -500,14 +500,14 @@ static int cpufreq_governor_stop(struct
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->shared;
 
 	/* State should be equivalent to START */
-	if (!shared || !shared->policy)
+	if (!policy_dbs || !policy_dbs->policy)
 		return -EBUSY;
 
-	gov_cancel_work(shared);
-	shared->policy = NULL;
+	gov_cancel_work(policy_dbs);
+	policy_dbs->policy = NULL;
 
 	return 0;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -255,21 +255,21 @@ static void update_sampling_rate(struct
 		struct cpufreq_policy *policy;
 		struct od_cpu_dbs_info_s *dbs_info;
 		struct cpu_dbs_info *cdbs;
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 		ktime_t next_sampling, appointed_at;
 
 		dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
 		cdbs = &dbs_info->cdbs;
-		shared = cdbs->shared;
+		policy_dbs = cdbs->shared;
 
 		/*
-		 * A valid shared and shared->policy means governor hasn't
-		 * stopped or exited yet.
+		 * A valid policy_dbs and policy_dbs->policy means governor
+		 * hasn't stopped or exited yet.
 		 */
-		if (!shared || !shared->policy)
+		if (!policy_dbs || !policy_dbs->policy)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 
 		/* clear all CPUs of this policy */
 		cpumask_andnot(&cpumask, &cpumask, policy->cpus);
@@ -289,14 +289,14 @@ static void update_sampling_rate(struct
 		 */
 		next_sampling = ktime_add_us(ktime_get(), new_rate);
 
-		mutex_lock(&shared->timer_mutex);
-		appointed_at = ktime_add_ns(shared->time_stamp,
-					    shared->sample_delay_ns);
-		mutex_unlock(&shared->timer_mutex);
+		mutex_lock(&policy_dbs->timer_mutex);
+		appointed_at = ktime_add_ns(policy_dbs->time_stamp,
+					    policy_dbs->sample_delay_ns);
+		mutex_unlock(&policy_dbs->timer_mutex);
 
 		if (ktime_before(next_sampling, appointed_at)) {
-			gov_cancel_work(shared);
-			gov_set_update_util(shared, new_rate);
+			gov_cancel_work(policy_dbs);
+			gov_set_update_util(policy_dbs, new_rate);
 		}
 	}
 
@@ -569,16 +569,16 @@ static void od_set_powersave_bias(unsign
 
 	get_online_cpus();
 	for_each_online_cpu(cpu) {
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 
 		if (cpumask_test_cpu(cpu, &done))
 			continue;
 
-		shared = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared;
-		if (!shared)
+		policy_dbs = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared;
+		if (!policy_dbs)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 		cpumask_or(&done, &done, policy->cpus);
 
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)

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

* [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (7 preceding siblings ...)
  2016-02-05  2:20   ` [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
@ 2016-02-05  2:21   ` Rafael J. Wysocki
  2016-02-05  9:13     ` Viresh Kumar
  2016-02-05  2:21   ` [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
                     ` (2 subsequent siblings)
  11 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:21 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The struct policy_dbs_info objects representing per-policy governor
data are not accessible directly from the corresponding policy
objects.  To access them, one has to get a pointer to the
struct cpu_dbs_info of policy->cpu and use the "shared" field of
that which isn't really straightforward.

To address that rearrange the governor data structures so the
governor_data pointer in struct cpufreq_policy will point to
struct policy_dbs_info and that will contain a pointer to
struct dbs_data.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    3 
 drivers/cpufreq/cpufreq_conservative.c |    6 +
 drivers/cpufreq/cpufreq_governor.c     |  120 ++++++++++++++-------------------
 drivers/cpufreq/cpufreq_governor.h     |   27 ++++---
 drivers/cpufreq/cpufreq_ondemand.c     |   18 +++-
 5 files changed, 85 insertions(+), 89 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -86,7 +86,8 @@ static ssize_t show_##file_name##_gov_sy
 static ssize_t show_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	struct _gov##_dbs_tuners *tuners = dbs_data->tuners;		\
 	return sprintf(buf, "%u\n", tuners->file_name);			\
 }
@@ -102,8 +103,8 @@ static ssize_t store_##file_name##_gov_s
 static ssize_t store_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, const char *buf, size_t count)		\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
-	return store_##file_name(dbs_data, buf, count);			\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	return store_##file_name(policy_dbs->dbs_data, buf, count);			\
 }
 
 #define show_store_one(_gov, file_name)					\
@@ -131,6 +132,13 @@ static void *get_cpu_dbs_info_s(int cpu)
  * cs_*: Conservative governor
  */
 
+/* Governor demand based switching data (per-policy or global). */
+struct dbs_data {
+	unsigned int min_sampling_rate;
+	int usage_count;
+	void *tuners;
+};
+
 /* Common to all CPUs of a policy */
 struct policy_dbs_info {
 	struct cpufreq_policy *policy;
@@ -147,6 +155,8 @@ struct policy_dbs_info {
 	struct irq_work irq_work;
 	struct completion irq_work_done;
 	struct work_struct work;
+	/* dbs_data may be shared between multiple policy objects */
+	struct dbs_data *dbs_data;
 };
 
 /* Per cpu structures */
@@ -201,7 +211,6 @@ struct cs_dbs_tuners {
 };
 
 /* Common Governor data across policies */
-struct dbs_data;
 struct dbs_governor {
 	struct cpufreq_governor gov;
 
@@ -233,13 +242,6 @@ static inline struct dbs_governor *dbs_g
 	return container_of(policy->governor, struct dbs_governor, gov);
 }
 
-/* Governor Per policy data */
-struct dbs_data {
-	unsigned int min_sampling_rate;
-	int usage_count;
-	void *tuners;
-};
-
 /* Governor specific ops, will be passed to dbs_data->gov_ops */
 struct od_ops {
 	void (*powersave_bias_init_cpu)(int cpu);
@@ -270,7 +272,8 @@ static ssize_t show_sampling_rate_min_go
 static ssize_t show_sampling_rate_min_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -34,8 +34,8 @@ static struct attribute_group *get_sysfs
 void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	unsigned int sampling_rate;
@@ -94,6 +94,7 @@ void dbs_check_cpu(struct cpufreq_policy
 		j_cdbs->prev_cpu_idle = cur_idle_time;
 
 		if (ignore_nice) {
+			struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 			u64 cur_nice;
 			unsigned long cur_nice_jiffies;
 
@@ -288,8 +289,8 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
-				 struct dbs_governor *gov)
+static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
+						     struct dbs_governor *gov)
 {
 	struct policy_dbs_info *policy_dbs;
 	int j;
@@ -297,16 +298,22 @@ static int alloc_policy_dbs_info(struct
 	/* Allocate memory for the common information for policy->cpus */
 	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
 	if (!policy_dbs)
-		return -ENOMEM;
-
-	/* Set policy_dbs for all CPUs, online+offline */
-	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->shared = policy_dbs;
+		return NULL;
 
+	policy_dbs->policy = policy;
 	mutex_init(&policy_dbs->timer_mutex);
 	atomic_set(&policy_dbs->skip_work, 0);
+	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
+	init_completion(&policy_dbs->irq_work_done);
 	INIT_WORK(&policy_dbs->work, dbs_work_handler);
-	return 0;
+	/* Set policy_dbs for all CPUs, online+offline */
+	for_each_cpu(j, policy->related_cpus) {
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
+
+		j_cdbs->shared = policy_dbs;
+		j_cdbs->update_util.func = dbs_update_util_handler;
+	}
+	return policy_dbs;
 }
 
 static void free_policy_dbs_info(struct cpufreq_policy *policy,
@@ -328,6 +335,7 @@ static int cpufreq_governor_init(struct
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = gov->gdbs_data;
+	struct policy_dbs_info *policy_dbs;
 	unsigned int latency;
 	int ret;
 
@@ -335,26 +343,26 @@ static int cpufreq_governor_init(struct
 	if (policy->governor_data)
 		return -EBUSY;
 
-	if (dbs_data) {
-		if (WARN_ON(have_governor_per_policy()))
-			return -EINVAL;
-
-		ret = alloc_policy_dbs_info(policy, gov);
-		if (ret)
-			return ret;
+	policy_dbs = alloc_policy_dbs_info(policy, gov);
+	if (!policy_dbs)
+		return -ENOMEM;
 
+	if (dbs_data) {
+		if (WARN_ON(have_governor_per_policy())) {
+			ret = -EINVAL;
+			goto free_policy_dbs_info;
+		}
 		dbs_data->usage_count++;
-		policy->governor_data = dbs_data;
+		policy_dbs->dbs_data = dbs_data;
+		policy->governor_data = policy_dbs;
 		return 0;
 	}
 
 	dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL);
-	if (!dbs_data)
-		return -ENOMEM;
-
-	ret = alloc_policy_dbs_info(policy, gov);
-	if (ret)
-		goto free_dbs_data;
+	if (!dbs_data) {
+		ret = -ENOMEM;
+		goto free_policy_dbs_info;
+	}
 
 	dbs_data->usage_count = 1;
 
@@ -376,7 +384,8 @@ static int cpufreq_governor_init(struct
 	if (!have_governor_per_policy())
 		gov->gdbs_data = dbs_data;
 
-	policy->governor_data = dbs_data;
+	policy_dbs->dbs_data = dbs_data;
+	policy->governor_data = policy_dbs;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
 				 get_sysfs_attr(gov));
@@ -391,38 +400,35 @@ reset_gdbs_data:
 	if (!have_governor_per_policy())
 		gov->gdbs_data = NULL;
 	gov->exit(dbs_data, !policy->governor->initialized);
+	kfree(dbs_data);
+
 free_policy_dbs_info:
 	free_policy_dbs_info(policy, gov);
-free_dbs_data:
-	kfree(dbs_data);
 	return ret;
 }
 
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 
 	/* State should be equivalent to INIT */
-	if (!cdbs->shared || cdbs->shared->policy)
+	if (!dbs_data)
 		return -EBUSY;
 
 	if (!--dbs_data->usage_count) {
 		sysfs_remove_group(get_governor_parent_kobj(policy),
 				   get_sysfs_attr(gov));
 
-		policy->governor_data = NULL;
-
 		if (!have_governor_per_policy())
 			gov->gdbs_data = NULL;
 
 		gov->exit(dbs_data, policy->governor->initialized == 1);
 		kfree(dbs_data);
-	} else {
-		policy->governor_data = NULL;
 	}
 
+	policy->governor_data = NULL;
 	free_policy_dbs_info(policy, gov);
 	return 0;
 }
@@ -430,17 +436,16 @@ static int cpufreq_governor_exit(struct
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->shared;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!policy_dbs || policy_dbs->policy)
+	if (!dbs_data)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -470,12 +475,7 @@ static int cpufreq_governor_start(struct
 
 		if (ignore_nice)
 			j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
-
-		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
-	policy_dbs->policy = policy;
-	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
-	init_completion(&policy_dbs->irq_work_done);
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -498,39 +498,25 @@ static int cpufreq_governor_start(struct
 
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->shared;
-
-	/* State should be equivalent to START */
-	if (!policy_dbs || !policy_dbs->policy)
-		return -EBUSY;
-
-	gov_cancel_work(policy_dbs);
-	policy_dbs->policy = NULL;
-
+	gov_cancel_work(policy->governor_data);
 	return 0;
 }
 
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	unsigned int cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
 
 	/* State should be equivalent to START */
-	if (!cdbs->shared || !cdbs->shared->policy)
+	if (!policy_dbs->dbs_data)
 		return -EBUSY;
 
-	mutex_lock(&cdbs->shared->timer_mutex);
-	if (policy->max < cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->max,
-					CPUFREQ_RELATION_H);
-	else if (policy->min > cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
-					CPUFREQ_RELATION_L);
-	dbs_check_cpu(policy, cpu);
-	mutex_unlock(&cdbs->shared->timer_mutex);
+	mutex_lock(&policy_dbs->timer_mutex);
+	if (policy->max < policy->cur)
+		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
+	else if (policy->min > policy->cur)
+		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
+	dbs_check_cpu(policy, policy->cpu);
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	return 0;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -78,7 +78,8 @@ static unsigned int generic_powersave_bi
 	unsigned int jiffies_total, jiffies_hi, jiffies_lo;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
 						   policy->cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (!dbs_info->freq_table) {
@@ -130,7 +131,8 @@ static void ondemand_powersave_bias_init
 
 static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (od_tuners->powersave_bias)
@@ -151,8 +153,9 @@ static void dbs_freq_increase(struct cpu
 static void od_check_cpu(int cpu, unsigned int load)
 {
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
-	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = dbs_info->cdbs.shared;
+	struct cpufreq_policy *policy = policy_dbs->policy;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	dbs_info->freq_lo = 0;
@@ -189,7 +192,8 @@ static void od_check_cpu(int cpu, unsign
 
 static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	unsigned int cpu = policy->cpu;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
 			cpu);
@@ -280,7 +284,7 @@ static void update_sampling_rate(struct
 		 * policy will be governed by dbs_data, otherwise there can be
 		 * multiple policies that are governed by the same dbs_data.
 		 */
-		if (dbs_data != policy->governor_data)
+		if (dbs_data != policy_dbs->dbs_data)
 			continue;
 
 		/*
@@ -584,7 +588,7 @@ static void od_set_powersave_bias(unsign
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
 			continue;
 
-		dbs_data = policy->governor_data;
+		dbs_data = policy_dbs->dbs_data;
 		od_tuners = dbs_data->tuners;
 		od_tuners->powersave_bias = default_powersave_bias;
 	}
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_t
 	long d_actual, d_reference;
 	struct msr actual, reference;
 	struct cpu_data_t *data = &per_cpu(cpu_data, policy->cpu);
-	struct dbs_data *od_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *od_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
 		dbs_governor_of(policy)->get_cpu_dbs_info_s(policy->cpu);
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
 	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsign
 
 static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	dbs_check_cpu(policy, policy->cpu);

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

* [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (8 preceding siblings ...)
  2016-02-05  2:21   ` [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
@ 2016-02-05  2:21   ` Rafael J. Wysocki
  2016-02-05  9:15     ` Viresh Kumar
  2016-02-06 12:50     ` [PATCH v3 " Rafael J. Wysocki
  2016-02-06 12:44   ` [PATCH v2 0/10] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
  2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
  11 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  2:21 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since policy->cpu is always passed as the second argument to
dbs_check_cpu(), it is not really necessary to pass it, because
the function can obtain that value via its first argument just fine.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_conservative.c |    2 +-
 drivers/cpufreq/cpufreq_governor.c     |    5 +++--
 drivers/cpufreq/cpufreq_governor.h     |    2 +-
 drivers/cpufreq/cpufreq_ondemand.c     |    6 ++----
 4 files changed, 7 insertions(+), 8 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -282,7 +282,7 @@ extern struct mutex cpufreq_governor_loc
 void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us);
 void gov_cancel_work(struct policy_dbs_info *policy_dbs);
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
+void dbs_check_cpu(struct cpufreq_policy *policy);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -194,9 +194,7 @@ static unsigned int od_dbs_timer(struct
 {
 	struct policy_dbs_info *policy_dbs = policy->governor_data;
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
-	unsigned int cpu = policy->cpu;
-	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
-			cpu);
+	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	int delay = 0, sample_type = dbs_info->sample_type;
 
@@ -207,7 +205,7 @@ static unsigned int od_dbs_timer(struct
 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
 					CPUFREQ_RELATION_H);
 	} else {
-		dbs_check_cpu(policy, cpu);
+		dbs_check_cpu(policy);
 		if (dbs_info->freq_lo) {
 			/* Setup timer for SUB_SAMPLE */
 			dbs_info->sample_type = OD_SUB_SAMPLE;
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -109,7 +109,7 @@ static unsigned int cs_dbs_timer(struct
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
-	dbs_check_cpu(policy, policy->cpu);
+	dbs_check_cpu(policy);
 	return delay_for_sampling_rate(cs_tuners->sampling_rate);
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -31,13 +31,14 @@ static struct attribute_group *get_sysfs
 		gov->attr_group_gov_pol : gov->attr_group_gov_sys;
 }
 
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
+void dbs_check_cpu(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct policy_dbs_info *policy_dbs = policy->governor_data;
 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
+	int cpu = policy->cpu;
 	unsigned int sampling_rate;
 	unsigned int max_load = 0;
 	unsigned int ignore_nice;
@@ -515,7 +516,7 @@ static int cpufreq_governor_limits(struc
 		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
 	else if (policy->min > policy->cur)
 		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
-	dbs_check_cpu(policy, policy->cpu);
+	dbs_check_cpu(policy);
 	mutex_unlock(&policy_dbs->timer_mutex);
 
 	return 0;

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-04 16:46     ` Rafael J. Wysocki
@ 2016-02-05  2:59       ` Viresh Kumar
  2016-02-05  3:06         ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  2:59 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 17:46, Rafael J. Wysocki wrote:
> On Thu, Feb 4, 2016 at 6:09 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > On 04-02-16, 00:16, Rafael J. Wysocki wrote:
> >> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >>
> >> Every governor relying on the common code in cpufreq_governor.c
> >> has to provide its own mutex in struct common_dbs_data.  However,
> >> those mutexes are never used at the same time
> >
> > Why do you think so? I thought they can always be used in parallel.
> >
> > Consider 2 or more policies, one can have ondemand as the governor,
> > whereas other one can have conservative.
> >
> > If CPUs go online/offline or if governors are switching in parallel,
> > then cpufreq_governor_dbs() can very much run in parallel for ondemand
> > and conservative.
> >
> > Or am I missing something here ?
> 
> Well, so perhaps the changelog is inaccurate.
> 
> However, what's wrong with using a single mutex then?

You are killing the possibility of running the code faster. Consider
this:
- A 16 policy system with N CPUs in every policy (IBM has something
  similar only :) )..
- 4 policies using ondemand, 4 using conservative, 4 using powersave
  and 4 with performance.
- Now if we try to change governors for all of them in parallel, only
  one will be done at a time and others have to wait for this
  BIG-kernel lock.
- Ideally the lock shouldn't have been in cdata itself, but dbs_data
  only. But there was a specific race because of which we were
  required to move it to a higher level, i.e. cdata. And so we killed
  the possibility of parallelism of multiple governors of same type
  (ofcourse only of update-sampling-rate and cpufreq_governor_dbs()..

So, it makes thing much slower..

-- 
viresh

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-04 16:52     ` Rafael J. Wysocki
@ 2016-02-05  3:02       ` Viresh Kumar
  2016-02-05  3:10         ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  3:02 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 04-02-16, 17:52, Rafael J. Wysocki wrote:
> On Thu, Feb 4, 2016 at 6:36 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:

> > Consider a two policy system, who is stopping us from setting ondemand
> > for one of them and conservative for the other one ? And so, we will
> > have two gdbs_data ..
> 
> I don't really regard that as an entirely sane thing to do, but you
> have a point here.

Why? Its quite useful IMO. For example on TC2, we have two clusters of
A7 and A15. And we actually can configure A7 for interactive and A15
for ondemand. And this is very useful for performance/power metrics.

-- 
viresh

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  2:59       ` Viresh Kumar
@ 2016-02-05  3:06         ` Rafael J. Wysocki
  2016-02-05  3:15           ` Rafael J. Wysocki
  2016-02-05  3:22           ` Viresh Kumar
  0 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  3:06 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle, Saravana Kannan

On Fri, Feb 5, 2016 at 3:59 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 04-02-16, 17:46, Rafael J. Wysocki wrote:
>> On Thu, Feb 4, 2016 at 6:09 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> > On 04-02-16, 00:16, Rafael J. Wysocki wrote:
>> >> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> >>
>> >> Every governor relying on the common code in cpufreq_governor.c
>> >> has to provide its own mutex in struct common_dbs_data.  However,
>> >> those mutexes are never used at the same time
>> >
>> > Why do you think so? I thought they can always be used in parallel.
>> >
>> > Consider 2 or more policies, one can have ondemand as the governor,
>> > whereas other one can have conservative.
>> >
>> > If CPUs go online/offline or if governors are switching in parallel,
>> > then cpufreq_governor_dbs() can very much run in parallel for ondemand
>> > and conservative.
>> >
>> > Or am I missing something here ?
>>
>> Well, so perhaps the changelog is inaccurate.
>>
>> However, what's wrong with using a single mutex then?
>
> You are killing the possibility of running the code faster. Consider
> this:
> - A 16 policy system with N CPUs in every policy (IBM has something
>   similar only :) )..
> - 4 policies using ondemand, 4 using conservative, 4 using powersave
>   and 4 with performance.
> - Now if we try to change governors for all of them in parallel, only
>   one will be done at a time and others have to wait for this
>   BIG-kernel lock.

And why is this a big problem, actually?  Why do we want the switching
of governors to be that efficient?

Thanks,
Rafael

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

* Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer
  2016-02-05  3:02       ` Viresh Kumar
@ 2016-02-05  3:10         ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  3:10 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle, Saravana Kannan

On Fri, Feb 5, 2016 at 4:02 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 04-02-16, 17:52, Rafael J. Wysocki wrote:
>> On Thu, Feb 4, 2016 at 6:36 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
>> > Consider a two policy system, who is stopping us from setting ondemand
>> > for one of them and conservative for the other one ? And so, we will
>> > have two gdbs_data ..
>>
>> I don't really regard that as an entirely sane thing to do, but you
>> have a point here.
>
> Why? Its quite useful IMO. For example on TC2, we have two clusters of
> A7 and A15. And we actually can configure A7 for interactive and A15
> for ondemand. And this is very useful for performance/power metrics.

Well, doing insane things may give you better results sometimes.
Depending on what you want to achieve and other factors.

Thanks,
Rafael

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  3:06         ` Rafael J. Wysocki
@ 2016-02-05  3:15           ` Rafael J. Wysocki
  2016-02-05  3:17             ` Rafael J. Wysocki
  2016-02-05  3:22           ` Viresh Kumar
  1 sibling, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  3:15 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Viresh Kumar, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle, Saravana Kannan

On Fri, Feb 5, 2016 at 4:06 AM, Rafael J. Wysocki <rafael@kernel.org> wrote:
> On Fri, Feb 5, 2016 at 3:59 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> On 04-02-16, 17:46, Rafael J. Wysocki wrote:
>>> On Thu, Feb 4, 2016 at 6:09 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>>> > On 04-02-16, 00:16, Rafael J. Wysocki wrote:
>>> >> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> >>
>>> >> Every governor relying on the common code in cpufreq_governor.c
>>> >> has to provide its own mutex in struct common_dbs_data.  However,
>>> >> those mutexes are never used at the same time
>>> >
>>> > Why do you think so? I thought they can always be used in parallel.
>>> >
>>> > Consider 2 or more policies, one can have ondemand as the governor,
>>> > whereas other one can have conservative.
>>> >
>>> > If CPUs go online/offline or if governors are switching in parallel,
>>> > then cpufreq_governor_dbs() can very much run in parallel for ondemand
>>> > and conservative.
>>> >
>>> > Or am I missing something here ?
>>>
>>> Well, so perhaps the changelog is inaccurate.
>>>
>>> However, what's wrong with using a single mutex then?
>>
>> You are killing the possibility of running the code faster. Consider
>> this:
>> - A 16 policy system with N CPUs in every policy (IBM has something
>>   similar only :) )..
>> - 4 policies using ondemand, 4 using conservative, 4 using powersave
>>   and 4 with performance.
>> - Now if we try to change governors for all of them in parallel, only
>>   one will be done at a time and others have to wait for this
>>   BIG-kernel lock.
>
> And why is this a big problem, actually?  Why do we want the switching
> of governors to be that efficient?

In any case, we're talking about having one lock instead of two, mind
you (out of the tree things don't count), because performance and
powersave don't even use the code in question.

I'm not really sure how much of a difference that would make on a
really big system.

Thanks,
Rafael

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  3:15           ` Rafael J. Wysocki
@ 2016-02-05  3:17             ` Rafael J. Wysocki
  2016-02-05  3:24               ` Viresh Kumar
  0 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  3:17 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Viresh Kumar, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle, Saravana Kannan

On Fri, Feb 5, 2016 at 4:15 AM, Rafael J. Wysocki <rafael@kernel.org> wrote:
> On Fri, Feb 5, 2016 at 4:06 AM, Rafael J. Wysocki <rafael@kernel.org> wrote:
>> On Fri, Feb 5, 2016 at 3:59 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>>> On 04-02-16, 17:46, Rafael J. Wysocki wrote:
>>>> On Thu, Feb 4, 2016 at 6:09 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>>>> > On 04-02-16, 00:16, Rafael J. Wysocki wrote:
>>>> >> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>> >>
>>>> >> Every governor relying on the common code in cpufreq_governor.c
>>>> >> has to provide its own mutex in struct common_dbs_data.  However,
>>>> >> those mutexes are never used at the same time
>>>> >
>>>> > Why do you think so? I thought they can always be used in parallel.
>>>> >
>>>> > Consider 2 or more policies, one can have ondemand as the governor,
>>>> > whereas other one can have conservative.
>>>> >
>>>> > If CPUs go online/offline or if governors are switching in parallel,
>>>> > then cpufreq_governor_dbs() can very much run in parallel for ondemand
>>>> > and conservative.
>>>> >
>>>> > Or am I missing something here ?
>>>>
>>>> Well, so perhaps the changelog is inaccurate.
>>>>
>>>> However, what's wrong with using a single mutex then?
>>>
>>> You are killing the possibility of running the code faster. Consider
>>> this:
>>> - A 16 policy system with N CPUs in every policy (IBM has something
>>>   similar only :) )..
>>> - 4 policies using ondemand, 4 using conservative, 4 using powersave
>>>   and 4 with performance.
>>> - Now if we try to change governors for all of them in parallel, only
>>>   one will be done at a time and others have to wait for this
>>>   BIG-kernel lock.
>>
>> And why is this a big problem, actually?  Why do we want the switching
>> of governors to be that efficient?
>
> In any case, we're talking about having one lock instead of two, mind
> you (out of the tree things don't count), because performance and
> powersave don't even use the code in question.
>
> I'm not really sure how much of a difference that would make on a
> really big system.

And don't we switch governors under policy->rwsem anyway?

Thanks,
Rafael

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  3:06         ` Rafael J. Wysocki
  2016-02-05  3:15           ` Rafael J. Wysocki
@ 2016-02-05  3:22           ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  3:22 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 04:06, Rafael J. Wysocki wrote:
> And why is this a big problem, actually?  Why do we want the switching
> of governors to be that efficient?

I am not saying its a big problem, just that its kind of a big lock,
which could have been finer.

-- 
viresh

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  3:17             ` Rafael J. Wysocki
@ 2016-02-05  3:24               ` Viresh Kumar
  2016-02-05  3:33                 ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  3:24 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 04:17, Rafael J. Wysocki wrote:
> And don't we switch governors under policy->rwsem anyway?

So ? That is blocking only a single policy only, but with the new
change, we will block all policies from doing that concurrently.

-- 
viresh

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

* Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  3:24               ` Viresh Kumar
@ 2016-02-05  3:33                 ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05  3:33 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux PM list,
	Linux Kernel Mailing List, Srinivas Pandruvada, Juri Lelli,
	Steve Muckle, Saravana Kannan

On Fri, Feb 5, 2016 at 4:24 AM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 05-02-16, 04:17, Rafael J. Wysocki wrote:
>> And don't we switch governors under policy->rwsem anyway?
>
> So ? That is blocking only a single policy only, but with the new
> change, we will block all policies from doing that concurrently.

No, it won't.  Again: one lock instead of two.  How much of a
difference this makes performance-wise?

And the price is the stupid dance we need to do to even get to those
locks!  Come on.

Thanks,
Rafael

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

* Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  2:14   ` [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
@ 2016-02-05  6:53     ` Viresh Kumar
  2016-02-05 22:59       ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  6:53 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:14, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Every governor relying on the common code in cpufreq_governor.c
> has to provide its own mutex in struct common_dbs_data.  However,
> there actually is no need to have a separate mutex per governor
> for this purpose, they may be using the same global mutex just
> fine.  Accordingly, introduce a single common mutex for that and
> drop the mutex field from struct common_dbs_data.
> 
> That at least will ensure that the mutex is always present and
> initialized regardless of what the particular governors do.
> 
> Another benefit is that the common code does not need a pointer to
> a governor-related structure to get to the mutex which sometimes
> helps.
> 
> Finally, it makes the code generally easier to follow.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Acked-by: Saravana Kannan <skannan@codeaurora.org>

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily
  2016-02-05  2:15   ` [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
@ 2016-02-05  7:09     ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  7:09 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:15, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Do not pass struct dbs_data pointers to the family of functions
> implementing governor operations in cpufreq_governor.c as they can
> take that pointer from policy->governor by themselves.
> 
> The cpufreq_governor_init() case is slightly more complicated, since
> policy->governor may be NULL when it is invoked, but then it can reach
> the pointer in question via its cdata argument just fine.
> 
> While at it, rework cpufreq_governor_dbs() to avoid a pointless
> policy_governor check in the CPUFREQ_GOV_POLICY_INIT case.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq_governor.c |   68 ++++++++++++++-----------------------
>  1 file changed, 27 insertions(+), 41 deletions(-)

Took some time to review, but it looks nice cleanup :)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data
  2016-02-05  2:16   ` [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
@ 2016-02-05  7:13     ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  7:13 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:16, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> For the ondemand and conservative governors (generally, governors
> that use the common code in cpufreq_governor.c), there are two static
> data structures representing the governor, the struct governor
> structure (the interface to the cpufreq core) and the struct
> common_dbs_data one (the interface to the cpufreq_governor.c code).
> 
> There's no fundamental reason why those two structures have to be
> separate.  Moreover, if the struct governor one is included into
> struct common_dbs_data, it will be possible to reach the latter from
> the policy via its policy->governor pointer, so it won't be necessary
> to pass a separate pointer to it around.  For this reason, embed
> struct governor in struct common_dbs_data.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Acked-by: Saravana Kannan <skannan@codeaurora.org>

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables
  2016-02-05  2:17   ` [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
@ 2016-02-05  7:17     ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  7:17 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:17, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The ondemand and conservative governors are represented by
> struct common_dbs_data whose name doesn't reflect the purpose it
> is used for, so rename it to struct dbs_governor and rename
> variables of that type accordingly.
> 
> No functional changes.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs()
  2016-02-05  2:18   ` [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
@ 2016-02-05  8:14     ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  8:14 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:18, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Since it is possible to obtain a pointer to struct dbs_governor
> from a pointer to the struct governor embedded in it via
> container_of(), the second argument of cpufreq_governor_init()
> is not necessary.  Accordingly, cpufreq_governor_dbs() doesn't
> need its second argument either and the ->governor callbacks
> for both the ondemand and conservative governors may be set
> to cpufreq_governor_dbs() directly.  Make that happen.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Acked-by: Saravana Kannan <skannan@codeaurora.org>
> ---
>  drivers/cpufreq/cpufreq_conservative.c |   11 +----------
>  drivers/cpufreq/cpufreq_governor.c     |   10 +++++-----
>  drivers/cpufreq/cpufreq_governor.h     |    3 +--
>  drivers/cpufreq/cpufreq_ondemand.c     |   11 +----------
>  4 files changed, 8 insertions(+), 27 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data
  2016-02-05  2:19   ` [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
@ 2016-02-05  8:28     ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  8:28 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:19, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Since it is possible to obtain a pointer to struct dbs_governor
> from a pointer to the struct governor embedded in it with the help
> of container_of(), the additional gov pointer in struct dbs_data
> isn't really necessary.
> 
> Drop that pointer and make the code using it reach the dbs_governor
> object via policy->governor.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/amd_freq_sensitivity.c |    2 -
>  drivers/cpufreq/cpufreq_conservative.c |    2 -
>  drivers/cpufreq/cpufreq_governor.c     |   63 +++++++++++++++------------------
>  drivers/cpufreq/cpufreq_governor.h     |    8 +++-
>  drivers/cpufreq/cpufreq_ondemand.c     |    2 -
>  5 files changed, 39 insertions(+), 38 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-05  2:20   ` [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
@ 2016-02-05  8:34     ` Viresh Kumar
  2016-02-05 22:50       ` Rafael J. Wysocki
  2016-02-06 12:48     ` [PATCH v3 " Rafael J. Wysocki
  1 sibling, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  8:34 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:20, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The struct cpu_common_dbs_info structure represents the per-policy
> part of the governor data (for the ondemand and conservative
> governors), but its name doesn't reflect its purpose.
> 
> Rename it to struct policy_dbs_info and rename variables related to
> it accordingly.
> 
> No functional changes.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq_governor.c |  120 ++++++++++++++++++-------------------
>  drivers/cpufreq/cpufreq_governor.h |    8 +-
>  drivers/cpufreq/cpufreq_ondemand.c |   32 ++++-----
>  3 files changed, 80 insertions(+), 80 deletions(-)
> 
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
> @@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)
>   */
>  
>  /* Common to all CPUs of a policy */
> -struct cpu_common_dbs_info {
> +struct policy_dbs_info {
>  	struct cpufreq_policy *policy;
>  	/*
>  	 * Per policy mutex that serializes load evaluation from limit-change
> @@ -162,7 +162,7 @@ struct cpu_dbs_info {
>  	 */
>  	unsigned int prev_load;
>  	struct update_util_data update_util;
> -	struct cpu_common_dbs_info *shared;
> +	struct policy_dbs_info *shared;

You should replaced shared with policy_dbs here as well ? Apart from
that:

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
  2016-02-05  2:21   ` [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
@ 2016-02-05  9:13     ` Viresh Kumar
  2016-02-05 22:47       ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  9:13 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:21, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The struct policy_dbs_info objects representing per-policy governor
> data are not accessible directly from the corresponding policy
> objects.  To access them, one has to get a pointer to the
> struct cpu_dbs_info of policy->cpu and use the "shared" field of
> that which isn't really straightforward.
> 
> To address that rearrange the governor data structures so the
> governor_data pointer in struct cpufreq_policy will point to
> struct policy_dbs_info and that will contain a pointer to
> struct dbs_data.

IMHO, this patch has done way too much over what's mentioned here.

> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -297,16 +298,22 @@ static int alloc_policy_dbs_info(struct
>  	/* Allocate memory for the common information for policy->cpus */
>  	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
>  	if (!policy_dbs)
> -		return -ENOMEM;
> -
> -	/* Set policy_dbs for all CPUs, online+offline */
> -	for_each_cpu(j, policy->related_cpus)
> -		gov->get_cpu_cdbs(j)->shared = policy_dbs;
> +		return NULL;
>  
> +	policy_dbs->policy = policy;

Value of policy_dbs->policy was used to verify the state machine of
the governor and so was updated only in start/stop.

You have moved it to INIT first (which shouldn't have been part of
this patch at the least), and then there is no reasoning given on why
that isn't required as part of the state machine now, which I believe
is still required the way it was.

>  	mutex_init(&policy_dbs->timer_mutex);
>  	atomic_set(&policy_dbs->skip_work, 0);
> +	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
> +	init_completion(&policy_dbs->irq_work_done);
>  	INIT_WORK(&policy_dbs->work, dbs_work_handler);
> -	return 0;
> +	/* Set policy_dbs for all CPUs, online+offline */
> +	for_each_cpu(j, policy->related_cpus) {
> +		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
> +
> +		j_cdbs->shared = policy_dbs;
> +		j_cdbs->update_util.func = dbs_update_util_handler;
> +	}

All other initializations are moved here for the good, but I think it
could have been done in a separate patch as to make review of this
trivial patch, which isn't so easy to review, easy :)

>  static int cpufreq_governor_exit(struct cpufreq_policy *policy)
>  {
>  	struct dbs_governor *gov = dbs_governor_of(policy);
> -	struct dbs_data *dbs_data = policy->governor_data;
> -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
> +	struct policy_dbs_info *policy_dbs = policy->governor_data;
> +	struct dbs_data *dbs_data = policy_dbs->dbs_data;
>  
>  	/* State should be equivalent to INIT */
> -	if (!cdbs->shared || cdbs->shared->policy)

For example, to make sure the current state is equivalent to INIT, we
had two checks earlier:
- First one made sure that cdbs->shared is allocated (which was done
  in INIT)
- And second one makes sure that shared->policy is NULL, as that is
  initialized in START.

> +	if (!dbs_data)
>  		return -EBUSY;

But now, the current state can be INIT or START, you can't
differentiate.

>  static int cpufreq_governor_start(struct cpufreq_policy *policy)
>  {
>  	struct dbs_governor *gov = dbs_governor_of(policy);
> -	struct dbs_data *dbs_data = policy->governor_data;
> +	struct policy_dbs_info *policy_dbs = policy->governor_data;
> +	struct dbs_data *dbs_data = policy_dbs->dbs_data;
>  	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
> -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
> -	struct policy_dbs_info *policy_dbs = cdbs->shared;
>  	int io_busy = 0;
>  
>  	if (!policy->cur)
>  		return -EINVAL;
>  
>  	/* State should be equivalent to INIT */
> -	if (!policy_dbs || policy_dbs->policy)
> +	if (!dbs_data)

Same here.. 

>  static int cpufreq_governor_stop(struct cpufreq_policy *policy)
>  {
> -	struct dbs_governor *gov = dbs_governor_of(policy);
> -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
> -	struct policy_dbs_info *policy_dbs = cdbs->shared;
> -
> -	/* State should be equivalent to START */
> -	if (!policy_dbs || !policy_dbs->policy)

And here ..

> -		return -EBUSY;
> -
> -	gov_cancel_work(policy_dbs);
> -	policy_dbs->policy = NULL;
> -
> +	gov_cancel_work(policy->governor_data);
>  	return 0;
>  }
>  
>  static int cpufreq_governor_limits(struct cpufreq_policy *policy)
>  {
> -	struct dbs_governor *gov = dbs_governor_of(policy);
> -	unsigned int cpu = policy->cpu;
> -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
> +	struct policy_dbs_info *policy_dbs = policy->governor_data;
>  
>  	/* State should be equivalent to START */
> -	if (!cdbs->shared || !cdbs->shared->policy)
> +	if (!policy_dbs->dbs_data)

And here...

>  		return -EBUSY;
>  
> -	mutex_lock(&cdbs->shared->timer_mutex);
> -	if (policy->max < cdbs->shared->policy->cur)
> -		__cpufreq_driver_target(cdbs->shared->policy, policy->max,
> -					CPUFREQ_RELATION_H);
> -	else if (policy->min > cdbs->shared->policy->cur)
> -		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
> -					CPUFREQ_RELATION_L);
> -	dbs_check_cpu(policy, cpu);
> -	mutex_unlock(&cdbs->shared->timer_mutex);
> +	mutex_lock(&policy_dbs->timer_mutex);
> +	if (policy->max < policy->cur)
> +		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
> +	else if (policy->min > policy->cur)
> +		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
> +	dbs_check_cpu(policy, policy->cpu);
> +	mutex_unlock(&policy_dbs->timer_mutex);
>  
>  	return 0;
>  }

-- 
viresh

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

* Re: [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
  2016-02-05  2:21   ` [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
@ 2016-02-05  9:15     ` Viresh Kumar
  2016-02-06 12:50     ` [PATCH v3 " Rafael J. Wysocki
  1 sibling, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-05  9:15 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 03:21, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Since policy->cpu is always passed as the second argument to
> dbs_check_cpu(), it is not really necessary to pass it, because
> the function can obtain that value via its first argument just fine.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq_conservative.c |    2 +-
>  drivers/cpufreq/cpufreq_governor.c     |    5 +++--
>  drivers/cpufreq/cpufreq_governor.h     |    2 +-
>  drivers/cpufreq/cpufreq_ondemand.c     |    6 ++----
>  4 files changed, 7 insertions(+), 8 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
  2016-02-05  9:13     ` Viresh Kumar
@ 2016-02-05 22:47       ` Rafael J. Wysocki
  2016-02-07  9:29         ` Viresh Kumar
  0 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05 22:47 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Friday, February 05, 2016 02:43:57 PM Viresh Kumar wrote:
> On 05-02-16, 03:21, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > The struct policy_dbs_info objects representing per-policy governor
> > data are not accessible directly from the corresponding policy
> > objects.  To access them, one has to get a pointer to the
> > struct cpu_dbs_info of policy->cpu and use the "shared" field of
> > that which isn't really straightforward.
> > 
> > To address that rearrange the governor data structures so the
> > governor_data pointer in struct cpufreq_policy will point to
> > struct policy_dbs_info and that will contain a pointer to
> > struct dbs_data.
> 
> IMHO, this patch has done way too much over what's mentioned here.
> 
> > Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> > @@ -297,16 +298,22 @@ static int alloc_policy_dbs_info(struct
> >  	/* Allocate memory for the common information for policy->cpus */
> >  	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
> >  	if (!policy_dbs)
> > -		return -ENOMEM;
> > -
> > -	/* Set policy_dbs for all CPUs, online+offline */
> > -	for_each_cpu(j, policy->related_cpus)
> > -		gov->get_cpu_cdbs(j)->shared = policy_dbs;
> > +		return NULL;
> >  
> > +	policy_dbs->policy = policy;
> 
> Value of policy_dbs->policy was used to verify the state machine of
> the governor and so was updated only in start/stop.
> 
> You have moved it to INIT first (which shouldn't have been part of
> this patch at the least),

Why?

> and then there is no reasoning given on why
> that isn't required as part of the state machine now, which I believe
> is still required the way it was.

No, it isn't required.  The whole "state machine" isn't required IMO.

The only user of this is the cpufreq core, so why does the code here have to
double check what the core is doing?

Thanks,
Rafael

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

* Re: [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-05  8:34     ` Viresh Kumar
@ 2016-02-05 22:50       ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05 22:50 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Friday, February 05, 2016 02:04:06 PM Viresh Kumar wrote:
> On 05-02-16, 03:20, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > The struct cpu_common_dbs_info structure represents the per-policy
> > part of the governor data (for the ondemand and conservative
> > governors), but its name doesn't reflect its purpose.
> > 
> > Rename it to struct policy_dbs_info and rename variables related to
> > it accordingly.
> > 
> > No functional changes.
> > 
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >  drivers/cpufreq/cpufreq_governor.c |  120 ++++++++++++++++++-------------------
> >  drivers/cpufreq/cpufreq_governor.h |    8 +-
> >  drivers/cpufreq/cpufreq_ondemand.c |   32 ++++-----
> >  3 files changed, 80 insertions(+), 80 deletions(-)
> > 
> > Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
> > ===================================================================
> > --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
> > +++ linux-pm/drivers/cpufreq/cpufreq_governor.h
> > @@ -132,7 +132,7 @@ static void *get_cpu_dbs_info_s(int cpu)
> >   */
> >  
> >  /* Common to all CPUs of a policy */
> > -struct cpu_common_dbs_info {
> > +struct policy_dbs_info {
> >  	struct cpufreq_policy *policy;
> >  	/*
> >  	 * Per policy mutex that serializes load evaluation from limit-change
> > @@ -162,7 +162,7 @@ struct cpu_dbs_info {
> >  	 */
> >  	unsigned int prev_load;
> >  	struct update_util_data update_util;
> > -	struct cpu_common_dbs_info *shared;
> > +	struct policy_dbs_info *shared;
> 
> You should replaced shared with policy_dbs here as well ? Apart from
> that:

I wanted to keep the name as the object pointed to by it is technically
still "shared".  I guess I can change it too, though.

Thanks,
Rafael

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

* Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05  6:53     ` Viresh Kumar
@ 2016-02-05 22:59       ` Rafael J. Wysocki
  2016-02-07  9:31         ` Viresh Kumar
  0 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-05 22:59 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Friday, February 05, 2016 12:23:41 PM Viresh Kumar wrote:
> On 05-02-16, 03:14, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > Every governor relying on the common code in cpufreq_governor.c
> > has to provide its own mutex in struct common_dbs_data.  However,
> > there actually is no need to have a separate mutex per governor
> > for this purpose, they may be using the same global mutex just
> > fine.  Accordingly, introduce a single common mutex for that and
> > drop the mutex field from struct common_dbs_data.
> > 
> > That at least will ensure that the mutex is always present and
> > initialized regardless of what the particular governors do.
> > 
> > Another benefit is that the common code does not need a pointer to
> > a governor-related structure to get to the mutex which sometimes
> > helps.
> > 
> > Finally, it makes the code generally easier to follow.
> > 
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > Acked-by: Saravana Kannan <skannan@codeaurora.org>
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Thanks!

One more observation here.

If we are able to eliminate dbs_data_mutex from update_sampling_rate(),
then cpufreq_governor_dbs() becomes the only user of that lock.  Further,
if we can guarantee that the governor's ->governor callback will always
be invoked under policy->rwsem, dbs_data_mutex becomes unnecessary and
may be dropped.

Thanks,
Rafael

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

* Re: [PATCH v2 0/10] cpufreq: governor: ondemand/conservative data structures rework
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (9 preceding siblings ...)
  2016-02-05  2:21   ` [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
@ 2016-02-06 12:44   ` Rafael J. Wysocki
  2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
  11 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-06 12:44 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Friday, February 05, 2016 03:07:27 AM Rafael J. Wysocki wrote:
> On Thursday, February 04, 2016 12:12:52 AM Rafael J. Wysocki wrote:
> > Hi,
> > 
> > A few days ago I looked at the common code used by the ondemand and conservative
> > governors because of the deadlock issue that Viresh has addressed recently
> > (http://marc.info/?l=linux-pm&m=145450832814058&w=4) and it occurred to me
> > that the whole thing was really too tangled and might be made easier to follow
> > at least.  I started to work on this and ended up with the following series.
> > 
> > I'm not really going to stop here, but first, I'd like to let everybody know
> > that this is happening and second, I'll need to rebase these patches on the
> > ones from Viresh (in the series linked above), but that may take some time
> > and I don't want to sit on them for all that long.
> > 
> > Overall, I'd like the governor code to be cleaner and easier to follow, so we can
> > move at least some parts of governor work to utilization update callbacks (invoked
> > by the scheduler) or to at least to irq_work so as to reduce the usage of process
> > context in cpufreq to absolute minimum.  That's the plan for the future, but for
> > now this is just a major cleanup.
> > 
> > [1/11] Clean up the way in which the default and fallback governors are set up.
> > [2/11] Use a common global mutex for dbs_data protection.
> > [3/11] Use common global pointer to dbs_data for system-wide governors.
> > [4/11] Avoid passing dbs_data pointers to functions that can get them by themselves.
> > [5/11] Make struct governor be a member of struct common_dbs_data.
> > [6/11] Rename struct common_dbs_data to struct dbs_governor.
> > [7/11] Rework cpufreq_governor_dbs() so it can be used as a governor callback directly.
> > [8/11] Drop the dbs_governor (former cdata) pointer from struct dbs_data.
> > [9/11] Rename struct cpu_common_dbs_info to struct policy_dbs_info.
> > [10/11] Rearrange data structures so policy->governor_data points to struct policy_dbs_info.
> > [11/11] Drop the second argument of dbs_check_cpu().
> > 
> > The patches are on top of 4.5-rc2 with my earlier series replacing timers with
> > utilization update callbacks (http://marc.info/?l=linux-kernel&m=145410842801883&w=4)
> > applied.
> 
> Some bugs fixed, some comments addressed.  It's time for a v2. :-)
> 
> The most significant difference from the previous one is that I've dropped patch
> [3/11] (so there are 10 of them in the series now) due to a problem with it pointed
> out by Viresh.  Fortunately, this particular one was completely not essential and
> the dependencies on it were rather cosmetic.
> 
> In addition to that I've rebased the series on top of
> https://patchwork.kernel.org/patch/8229901/ as that differs from its previous
> version quite a bit.
> 
> I've already queued up [1/10] for 4.6 as it seems totally uncontroversial.
> 
> The whole series (along with some patches it depends on) is available from the
> git branch at
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git pm-cpufreq-rjw
> 
> in case someone wants to try it.  I've tested it (very lightly) on an x86 laptop
> with the ACPI cpufreq driver and the ondemand governor.

I'm going to tentatively queue up patches [2-8,10/10] with Viresh's ACKs (thanks
Viresh!) for 4.6 (tentatively, because they depend on the timers elimination
series which is still under ongoing review, but that seems to be reaching
conclusion).

Patches [8,10/10] needed a non-trivial rebase, so I'll post the new versions
shortly for completeness.

I'm going to rework patch [9/10] on top of that into a few separate patches
that will hopefully be easier to digest.

Thanks,
Rafael

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

* [PATCH v3 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-05  2:20   ` [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
  2016-02-05  8:34     ` Viresh Kumar
@ 2016-02-06 12:48     ` Rafael J. Wysocki
  2016-02-07  9:31       ` Viresh Kumar
  1 sibling, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-06 12:48 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info

The struct cpu_common_dbs_info structure represents the per-policy
part of the governor data (for the ondemand and conservative
governors), but its name doesn't reflect its purpose.

Rename it to struct policy_dbs_info and rename variables related to
it accordingly.

No functional changes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

Changes from v2:
- Rebase on top of https://patchwork.kernel.org/patch/8241231/
- Change all struct cpu_common_dbs_info pointers to be called policy_dbs.

---
 drivers/cpufreq/cpufreq_conservative.c |    2 
 drivers/cpufreq/cpufreq_governor.c     |  134 ++++++++++++++++-----------------
 drivers/cpufreq/cpufreq_governor.h     |    8 -
 drivers/cpufreq/cpufreq_ondemand.c     |   28 +++---
 4 files changed, 86 insertions(+), 86 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -131,7 +131,7 @@ static void *get_cpu_dbs_info_s(int cpu)
  */
 
 /* Common to all CPUs of a policy */
-struct cpu_common_dbs_info {
+struct policy_dbs_info {
 	struct cpufreq_policy *policy;
 	/*
 	 * Per policy mutex that serializes load evaluation from limit-change
@@ -146,10 +146,10 @@ struct cpu_common_dbs_info {
 	struct work_struct work;
 };
 
-static inline void gov_update_sample_delay(struct cpu_common_dbs_info *shared,
+static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
 					   unsigned int delay_us)
 {
-	shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
+	policy_dbs->sample_delay_ns = delay_us * NSEC_PER_USEC;
 }
 
 /* Per cpu structures */
@@ -165,7 +165,7 @@ struct cpu_dbs_info {
 	 */
 	unsigned int prev_load;
 	struct update_util_data update_util;
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 };
 
 struct od_cpu_dbs_info_s {
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -163,15 +163,15 @@ void dbs_check_cpu(struct cpufreq_policy
 }
 EXPORT_SYMBOL_GPL(dbs_check_cpu);
 
-void gov_set_update_util(struct cpu_common_dbs_info *shared,
+void gov_set_update_util(struct policy_dbs_info *policy_dbs,
 			 unsigned int delay_us)
 {
-	struct cpufreq_policy *policy = shared->policy;
+	struct cpufreq_policy *policy = policy_dbs->policy;
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	int cpu;
 
-	gov_update_sample_delay(shared, delay_us);
-	shared->last_sample_time = 0;
+	gov_update_sample_delay(policy_dbs, delay_us);
+	policy_dbs->last_sample_time = 0;
 
 	for_each_cpu(cpu, policy->cpus) {
 		struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
@@ -191,40 +191,40 @@ static inline void gov_clear_update_util
 	synchronize_rcu();
 }
 
-static void gov_cancel_work(struct cpu_common_dbs_info *shared)
+static void gov_cancel_work(struct policy_dbs_info *policy_dbs)
 {
 	/* Tell dbs_update_util_handler() to skip queuing up work items. */
-	atomic_inc(&shared->skip_work);
+	atomic_inc(&policy_dbs->skip_work);
 	/*
 	 * If dbs_update_util_handler() is already running, it may not notice
 	 * the incremented skip_work, so wait for it to complete to prevent its
 	 * work item from being queued up after the cancel_work_sync() below.
 	 */
-	gov_clear_update_util(shared->policy);
-	irq_work_sync(&shared->irq_work);
-	cancel_work_sync(&shared->work);
-	atomic_set(&shared->skip_work, 0);
+	gov_clear_update_util(policy_dbs->policy);
+	irq_work_sync(&policy_dbs->irq_work);
+	cancel_work_sync(&policy_dbs->work);
+	atomic_set(&policy_dbs->skip_work, 0);
 }
 
 static void dbs_work_handler(struct work_struct *work)
 {
-	struct cpu_common_dbs_info *shared = container_of(work, struct
-					cpu_common_dbs_info, work);
+	struct policy_dbs_info *policy_dbs;
 	struct cpufreq_policy *policy;
 	struct dbs_governor *gov;
 	unsigned int delay;
 
-	policy = shared->policy;
+	policy_dbs = container_of(work, struct policy_dbs_info, work);
+	policy = policy_dbs->policy;
 	gov = dbs_governor_of(policy);
 
 	/*
 	 * Make sure cpufreq_governor_limits() isn't evaluating load or the
 	 * ondemand governor isn't updating the sampling rate in parallel.
 	 */
-	mutex_lock(&shared->timer_mutex);
+	mutex_lock(&policy_dbs->timer_mutex);
 	delay = gov->gov_dbs_timer(policy);
-	shared->sample_delay_ns = jiffies_to_nsecs(delay);
-	mutex_unlock(&shared->timer_mutex);
+	policy_dbs->sample_delay_ns = jiffies_to_nsecs(delay);
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	/*
 	 * If the atomic operation below is reordered with respect to the
@@ -232,30 +232,30 @@ static void dbs_work_handler(struct work
 	 * up using a stale sample delay value.
 	 */
 	smp_mb__before_atomic();
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void dbs_irq_work(struct irq_work *irq_work)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 
-	shared = container_of(irq_work, struct cpu_common_dbs_info, irq_work);
-	schedule_work(&shared->work);
+	policy_dbs = container_of(irq_work, struct policy_dbs_info, irq_work);
+	schedule_work(&policy_dbs->work);
 }
 
-static inline void gov_queue_irq_work(struct cpu_common_dbs_info *shared)
+static inline void gov_queue_irq_work(struct policy_dbs_info *policy_dbs)
 {
 	if (IS_ENABLED(CONFIG_SMP))
-		irq_work_queue_on(&shared->irq_work, smp_processor_id());
+		irq_work_queue_on(&policy_dbs->irq_work, smp_processor_id());
 	else
-		irq_work_queue(&shared->irq_work);
+		irq_work_queue(&policy_dbs->irq_work);
 }
 
 static void dbs_update_util_handler(struct update_util_data *data, u64 time,
 				    unsigned long util, unsigned long max)
 {
 	struct cpu_dbs_info *cdbs = container_of(data, struct cpu_dbs_info, update_util);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 
 	/*
 	 * The work may not be allowed to be queued up right now.
@@ -264,17 +264,17 @@ static void dbs_update_util_handler(stru
 	 * - The governor is being stopped.
 	 * - It is too early (too little time from the previous sample).
 	 */
-	if (atomic_inc_return(&shared->skip_work) == 1) {
+	if (atomic_inc_return(&policy_dbs->skip_work) == 1) {
 		u64 delta_ns;
 
-		delta_ns = time - shared->last_sample_time;
-		if ((s64)delta_ns >= shared->sample_delay_ns) {
-			shared->last_sample_time = time;
-			gov_queue_irq_work(shared);
+		delta_ns = time - policy_dbs->last_sample_time;
+		if ((s64)delta_ns >= policy_dbs->sample_delay_ns) {
+			policy_dbs->last_sample_time = time;
+			gov_queue_irq_work(policy_dbs);
 			return;
 		}
 	}
-	atomic_dec(&shared->skip_work);
+	atomic_dec(&policy_dbs->skip_work);
 }
 
 static void set_sampling_rate(struct dbs_data *dbs_data,
@@ -290,40 +290,40 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_common_dbs_info(struct cpufreq_policy *policy,
+static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
-	struct cpu_common_dbs_info *shared;
+	struct policy_dbs_info *policy_dbs;
 	int j;
 
 	/* Allocate memory for the common information for policy->cpus */
-	shared = kzalloc(sizeof(*shared), GFP_KERNEL);
-	if (!shared)
+	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
+	if (!policy_dbs)
 		return -ENOMEM;
 
-	/* Set shared for all CPUs, online+offline */
+	/* Set policy_dbs for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->shared = shared;
+		gov->get_cpu_cdbs(j)->policy_dbs = policy_dbs;
 
-	mutex_init(&shared->timer_mutex);
-	atomic_set(&shared->skip_work, 0);
-	INIT_WORK(&shared->work, dbs_work_handler);
+	mutex_init(&policy_dbs->timer_mutex);
+	atomic_set(&policy_dbs->skip_work, 0);
+	INIT_WORK(&policy_dbs->work, dbs_work_handler);
 	return 0;
 }
 
-static void free_common_dbs_info(struct cpufreq_policy *policy,
+static void free_policy_dbs_info(struct cpufreq_policy *policy,
 				 struct dbs_governor *gov)
 {
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 	int j;
 
-	mutex_destroy(&shared->timer_mutex);
+	mutex_destroy(&policy_dbs->timer_mutex);
 
 	for_each_cpu(j, policy->cpus)
-		gov->get_cpu_cdbs(j)->shared = NULL;
+		gov->get_cpu_cdbs(j)->policy_dbs = NULL;
 
-	kfree(shared);
+	kfree(policy_dbs);
 }
 
 static int cpufreq_governor_init(struct cpufreq_policy *policy)
@@ -341,7 +341,7 @@ static int cpufreq_governor_init(struct
 		if (WARN_ON(have_governor_per_policy()))
 			return -EINVAL;
 
-		ret = alloc_common_dbs_info(policy, gov);
+		ret = alloc_policy_dbs_info(policy, gov);
 		if (ret)
 			return ret;
 
@@ -354,7 +354,7 @@ static int cpufreq_governor_init(struct
 	if (!dbs_data)
 		return -ENOMEM;
 
-	ret = alloc_common_dbs_info(policy, gov);
+	ret = alloc_policy_dbs_info(policy, gov);
 	if (ret)
 		goto free_dbs_data;
 
@@ -362,7 +362,7 @@ static int cpufreq_governor_init(struct
 
 	ret = gov->init(dbs_data, !policy->governor->initialized);
 	if (ret)
-		goto free_common_dbs_info;
+		goto free_policy_dbs_info;
 
 	/* policy latency is in ns. Convert it to us first */
 	latency = policy->cpuinfo.transition_latency / 1000;
@@ -393,8 +393,8 @@ reset_gdbs_data:
 	if (!have_governor_per_policy())
 		gov->gdbs_data = NULL;
 	gov->exit(dbs_data, !policy->governor->initialized);
-free_common_dbs_info:
-	free_common_dbs_info(policy, gov);
+free_policy_dbs_info:
+	free_policy_dbs_info(policy, gov);
 free_dbs_data:
 	kfree(dbs_data);
 	return ret;
@@ -407,7 +407,7 @@ static int cpufreq_governor_exit(struct
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to INIT */
-	if (!cdbs->shared || cdbs->shared->policy)
+	if (!cdbs->policy_dbs || cdbs->policy_dbs->policy)
 		return -EBUSY;
 
 	if (!--dbs_data->usage_count) {
@@ -425,7 +425,7 @@ static int cpufreq_governor_exit(struct
 		policy->governor_data = NULL;
 	}
 
-	free_common_dbs_info(policy, gov);
+	free_policy_dbs_info(policy, gov);
 	return 0;
 }
 
@@ -435,14 +435,14 @@ static int cpufreq_governor_start(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!shared || shared->policy)
+	if (!policy_dbs || policy_dbs->policy)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -475,8 +475,8 @@ static int cpufreq_governor_start(struct
 
 		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
-	shared->policy = policy;
-	init_irq_work(&shared->irq_work, dbs_irq_work);
+	policy_dbs->policy = policy;
+	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 
 	if (gov->governor == GOV_CONSERVATIVE) {
 		struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -493,7 +493,7 @@ static int cpufreq_governor_start(struct
 		od_ops->powersave_bias_init_cpu(cpu);
 	}
 
-	gov_set_update_util(shared, sampling_rate);
+	gov_set_update_util(policy_dbs, sampling_rate);
 	return 0;
 }
 
@@ -501,14 +501,14 @@ static int cpufreq_governor_stop(struct
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct cpu_common_dbs_info *shared = cdbs->shared;
+	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 
 	/* State should be equivalent to START */
-	if (!shared || !shared->policy)
+	if (!policy_dbs || !policy_dbs->policy)
 		return -EBUSY;
 
-	gov_cancel_work(shared);
-	shared->policy = NULL;
+	gov_cancel_work(policy_dbs);
+	policy_dbs->policy = NULL;
 
 	return 0;
 }
@@ -520,18 +520,18 @@ static int cpufreq_governor_limits(struc
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 
 	/* State should be equivalent to START */
-	if (!cdbs->shared || !cdbs->shared->policy)
+	if (!cdbs->policy_dbs || !cdbs->policy_dbs->policy)
 		return -EBUSY;
 
-	mutex_lock(&cdbs->shared->timer_mutex);
-	if (policy->max < cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->max,
+	mutex_lock(&cdbs->policy_dbs->timer_mutex);
+	if (policy->max < cdbs->policy_dbs->policy->cur)
+		__cpufreq_driver_target(cdbs->policy_dbs->policy, policy->max,
 					CPUFREQ_RELATION_H);
-	else if (policy->min > cdbs->shared->policy->cur)
-		__cpufreq_driver_target(cdbs->shared->policy, policy->min,
+	else if (policy->min > cdbs->policy_dbs->policy->cur)
+		__cpufreq_driver_target(cdbs->policy_dbs->policy, policy->min,
 					CPUFREQ_RELATION_L);
 	dbs_check_cpu(policy, cpu);
-	mutex_unlock(&cdbs->shared->timer_mutex);
+	mutex_unlock(&cdbs->policy_dbs->timer_mutex);
 
 	return 0;
 }
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -151,7 +151,7 @@ static void dbs_freq_increase(struct cpu
 static void od_check_cpu(int cpu, unsigned int load)
 {
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
-	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
+	struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
@@ -255,20 +255,20 @@ static void update_sampling_rate(struct
 		struct cpufreq_policy *policy;
 		struct od_cpu_dbs_info_s *dbs_info;
 		struct cpu_dbs_info *cdbs;
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 
 		dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
 		cdbs = &dbs_info->cdbs;
-		shared = cdbs->shared;
+		policy_dbs = cdbs->policy_dbs;
 
 		/*
-		 * A valid shared and shared->policy means governor hasn't
-		 * stopped or exited yet.
+		 * A valid policy_dbs and policy_dbs->policy means governor
+		 * hasn't stopped or exited yet.
 		 */
-		if (!shared || !shared->policy)
+		if (!policy_dbs || !policy_dbs->policy)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 
 		/* clear all CPUs of this policy */
 		cpumask_andnot(&cpumask, &cpumask, policy->cpus);
@@ -280,7 +280,7 @@ static void update_sampling_rate(struct
 		 * multiple policies that are governed by the same dbs_data.
 		 */
 		if (dbs_data == policy->governor_data) {
-			mutex_lock(&shared->timer_mutex);
+			mutex_lock(&policy_dbs->timer_mutex);
 			/*
 			 * On 32-bit architectures this may race with the
 			 * sample_delay_ns read in dbs_update_util_handler(),
@@ -299,8 +299,8 @@ static void update_sampling_rate(struct
 			 * too big and it will be corrected next time a sample
 			 * is taken, so it shouldn't be significant.
 			 */
-			gov_update_sample_delay(shared, new_rate);
-			mutex_unlock(&shared->timer_mutex);
+			gov_update_sample_delay(policy_dbs, new_rate);
+			mutex_unlock(&policy_dbs->timer_mutex);
 		}
 	}
 
@@ -573,16 +573,16 @@ static void od_set_powersave_bias(unsign
 
 	get_online_cpus();
 	for_each_online_cpu(cpu) {
-		struct cpu_common_dbs_info *shared;
+		struct policy_dbs_info *policy_dbs;
 
 		if (cpumask_test_cpu(cpu, &done))
 			continue;
 
-		shared = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared;
-		if (!shared)
+		policy_dbs = per_cpu(od_cpu_dbs_info, cpu).cdbs.policy_dbs;
+		if (!policy_dbs)
 			continue;
 
-		policy = shared->policy;
+		policy = policy_dbs->policy;
 		cpumask_or(&done, &done, policy->cpus);
 
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -47,7 +47,7 @@ static inline unsigned int get_freq_targ
 static void cs_check_cpu(int cpu, unsigned int load)
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
-	struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy;
+	struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 

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

* [PATCH v3 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
  2016-02-05  2:21   ` [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
  2016-02-05  9:15     ` Viresh Kumar
@ 2016-02-06 12:50     ` Rafael J. Wysocki
  2016-02-07  9:32       ` Viresh Kumar
  1 sibling, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-06 12:50 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Since policy->cpu is always passed as the second argument to
dbs_check_cpu(), it is not really necessary to pass it, because
the function can obtain that value via its first argument just fine.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

Changes from v2:
- Rebase on top of https://patchwork.kernel.org/patch/8241231/
  and on the v3 of [8/10] without [9/10].

---
 drivers/cpufreq/cpufreq_conservative.c |    2 +-
 drivers/cpufreq/cpufreq_governor.c     |    8 ++++----
 drivers/cpufreq/cpufreq_governor.h     |    2 +-
 drivers/cpufreq/cpufreq_ondemand.c     |    6 ++----
 4 files changed, 8 insertions(+), 10 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -279,7 +279,7 @@ static ssize_t show_sampling_rate_min_go
 
 extern struct mutex dbs_data_mutex;
 extern struct mutex cpufreq_governor_lock;
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu);
+void dbs_check_cpu(struct cpufreq_policy *policy);
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event);
 void od_register_powersave_bias_handler(unsigned int (*f)
 		(struct cpufreq_policy *, unsigned int, unsigned int),
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -190,9 +190,7 @@ static void od_check_cpu(int cpu, unsign
 static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
 {
 	struct dbs_data *dbs_data = policy->governor_data;
-	unsigned int cpu = policy->cpu;
-	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
-			cpu);
+	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	int delay = 0, sample_type = dbs_info->sample_type;
 
@@ -203,7 +201,7 @@ static unsigned int od_dbs_timer(struct
 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
 					CPUFREQ_RELATION_H);
 	} else {
-		dbs_check_cpu(policy, cpu);
+		dbs_check_cpu(policy);
 		if (dbs_info->freq_lo) {
 			/* Setup timer for SUB_SAMPLE */
 			dbs_info->sample_type = OD_SUB_SAMPLE;
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -107,7 +107,7 @@ static unsigned int cs_dbs_timer(struct
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
-	dbs_check_cpu(policy, policy->cpu);
+	dbs_check_cpu(policy);
 	return delay_for_sampling_rate(cs_tuners->sampling_rate);
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -31,8 +31,9 @@ static struct attribute_group *get_sysfs
 		gov->attr_group_gov_pol : gov->attr_group_gov_sys;
 }
 
-void dbs_check_cpu(struct cpufreq_policy *policy, int cpu)
+void dbs_check_cpu(struct cpufreq_policy *policy)
 {
+	int cpu = policy->cpu;
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 	struct dbs_data *dbs_data = policy->governor_data;
@@ -516,8 +517,7 @@ static int cpufreq_governor_stop(struct
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	unsigned int cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
+	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
 
 	/* State should be equivalent to START */
 	if (!cdbs->policy_dbs || !cdbs->policy_dbs->policy)
@@ -530,7 +530,7 @@ static int cpufreq_governor_limits(struc
 	else if (policy->min > cdbs->policy_dbs->policy->cur)
 		__cpufreq_driver_target(cdbs->policy_dbs->policy, policy->min,
 					CPUFREQ_RELATION_L);
-	dbs_check_cpu(policy, cpu);
+	dbs_check_cpu(policy);
 	mutex_unlock(&cdbs->policy_dbs->timer_mutex);
 
 	return 0;

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

* Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
  2016-02-05 22:47       ` Rafael J. Wysocki
@ 2016-02-07  9:29         ` Viresh Kumar
  2016-02-07 14:34           ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07  9:29 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 23:47, Rafael J. Wysocki wrote:
> On Friday, February 05, 2016 02:43:57 PM Viresh Kumar wrote:
> > Value of policy_dbs->policy was used to verify the state machine of
> > the governor and so was updated only in start/stop.
> > 
> > You have moved it to INIT first (which shouldn't have been part of
> > this patch at the least),
> 
> Why?

Because it doesn't match $SUBJECT at all..

> > and then there is no reasoning given on why
> > that isn't required as part of the state machine now, which I believe
> > is still required the way it was.
> 
> No, it isn't required.  The whole "state machine" isn't required IMO.

The state machine wasn't required if the core wasn't buggy. Its buggy because we
drop policy->rwsem during set-policy, before calling EXIT. And other
__cpufreq_governor() calls can shoot up at that point of time.

We have seen lots of crashes earlier and so the state machine was introduced to
get them fixed.

It might not be required (after making sure things are working fine now), after
applying my patch series of 7 patches. As that fixes the lock-drop issue ..

> The only user of this is the cpufreq core, so why does the code here have to
> double check what the core is doing?

Because, core doesn't guarantee the order today.

-- 
viresh

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

* Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-05 22:59       ` Rafael J. Wysocki
@ 2016-02-07  9:31         ` Viresh Kumar
  2016-02-07 14:33           ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07  9:31 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 05-02-16, 23:59, Rafael J. Wysocki wrote:
> One more observation here.
> 
> If we are able to eliminate dbs_data_mutex from update_sampling_rate(),
> then cpufreq_governor_dbs() becomes the only user of that lock.  Further,
> if we can guarantee that the governor's ->governor callback will always
> be invoked under policy->rwsem, dbs_data_mutex becomes unnecessary and
> may be dropped.

That will be guaranteed with my 7 patches, which I will rebase and send again.

But there are cases where a single dbs_data is going to be used for multiple
policies and so relying on policy->rwsem isn't going to be sufficient.

But, yeah, we should be able to narrow down the locked area I believe.

-- 
viresh

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

* Re: [PATCH v3 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
  2016-02-06 12:48     ` [PATCH v3 " Rafael J. Wysocki
@ 2016-02-07  9:31       ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07  9:31 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 06-02-16, 13:48, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Subject: [PATCH] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info
> 
> The struct cpu_common_dbs_info structure represents the per-policy
> part of the governor data (for the ondemand and conservative
> governors), but its name doesn't reflect its purpose.
> 
> Rename it to struct policy_dbs_info and rename variables related to
> it accordingly.
> 
> No functional changes.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v3 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu()
  2016-02-06 12:50     ` [PATCH v3 " Rafael J. Wysocki
@ 2016-02-07  9:32       ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07  9:32 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 06-02-16, 13:50, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Since policy->cpu is always passed as the second argument to
> dbs_check_cpu(), it is not really necessary to pass it, because
> the function can obtain that value via its first argument just fine.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> Changes from v2:
> - Rebase on top of https://patchwork.kernel.org/patch/8241231/
>   and on the v3 of [8/10] without [9/10].

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection
  2016-02-07  9:31         ` Viresh Kumar
@ 2016-02-07 14:33           ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 14:33 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Sunday, February 07, 2016 03:01:12 PM Viresh Kumar wrote:
> On 05-02-16, 23:59, Rafael J. Wysocki wrote:
> > One more observation here.
> > 
> > If we are able to eliminate dbs_data_mutex from update_sampling_rate(),
> > then cpufreq_governor_dbs() becomes the only user of that lock.  Further,
> > if we can guarantee that the governor's ->governor callback will always
> > be invoked under policy->rwsem, dbs_data_mutex becomes unnecessary and
> > may be dropped.
> 
> That will be guaranteed with my 7 patches, which I will rebase and send again.
> 
> But there are cases where a single dbs_data is going to be used for multiple
> policies and so relying on policy->rwsem isn't going to be sufficient.
> 
> But, yeah, we should be able to narrow down the locked area I believe.

That should only be a matter of protecting the gov->gdbs_data object and its
refcount then.

Thanks,
Rafael

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

* Re: [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures
  2016-02-07  9:29         ` Viresh Kumar
@ 2016-02-07 14:34           ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 14:34 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Sunday, February 07, 2016 02:59:11 PM Viresh Kumar wrote:
> On 05-02-16, 23:47, Rafael J. Wysocki wrote:
> > On Friday, February 05, 2016 02:43:57 PM Viresh Kumar wrote:
> > > Value of policy_dbs->policy was used to verify the state machine of
> > > the governor and so was updated only in start/stop.
> > > 
> > > You have moved it to INIT first (which shouldn't have been part of
> > > this patch at the least),
> > 
> > Why?
> 
> Because it doesn't match $SUBJECT at all..
> 
> > > and then there is no reasoning given on why
> > > that isn't required as part of the state machine now, which I believe
> > > is still required the way it was.
> > 
> > No, it isn't required.  The whole "state machine" isn't required IMO.
> 
> The state machine wasn't required if the core wasn't buggy. Its buggy because we
> drop policy->rwsem during set-policy, before calling EXIT. And other
> __cpufreq_governor() calls can shoot up at that point of time.
> 
> We have seen lots of crashes earlier and so the state machine was introduced to
> get them fixed.
> 
> It might not be required (after making sure things are working fine now), after
> applying my patch series of 7 patches. As that fixes the lock-drop issue ..
> 
> > The only user of this is the cpufreq core, so why does the code here have to
> > double check what the core is doing?
> 
> Because, core doesn't guarantee the order today.

OK, so I have reworked this.  I have a series of 3 patches now instead of it
that I'm going to post shortly.

Thanks,
Rafael

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

* [PATCH 0/3] cpufreq: governor: Data structure rearrangement
  2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
                     ` (10 preceding siblings ...)
  2016-02-06 12:44   ` [PATCH v2 0/10] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
@ 2016-02-07 15:22   ` Rafael J. Wysocki
  2016-02-07 15:23     ` [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits() Rafael J. Wysocki
                       ` (2 more replies)
  11 siblings, 3 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 15:22 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

Hi,

This was part of my recent cleanup series
(http://marc.info/?l=linux-pm&m=145463901630950&w=4), but Viresh had a good
point about the patch doing too much and possibly going too far, so I've
reworked it into a series of three smaller patches and dropped some more
aggressive changes.

[1/3] simplifies cpufreq_governor_limits() to access the policy via its
      argument directly.
[2/3] rearranges the data structures so policy->governor_data points to the
      struct policy_dbs corresponding to that policy and the latter points
      to a struct dbs_data.
[3/3] makes the initialization and cleanup of struct cpu_dbs_info more
      symmetrical.

Patches are on top of my bleeding-edge branch (and there is a separate
pm-cpufreq-test branch with cpufreq patches only in case someone wants/needs
to test those alone).

Thanks,
Rafael

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

* [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits()
  2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
@ 2016-02-07 15:23     ` Rafael J. Wysocki
  2016-02-07 15:40       ` Viresh Kumar
  2016-02-07 15:24     ` [PATCH 2/3] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
  2016-02-07 15:25     ` [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup Rafael J. Wysocki
  2 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 15:23 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Use the observation that cpufreq_governor_limits() doesn't have to
get to the policy object it wants to manipulate by walking the
reference chain cdbs->policy_dbs->policy, as the final pointer is
actually equal to its argument, and make it access the policy
object directy via its argument.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -518,20 +518,19 @@ static int cpufreq_governor_limits(struc
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
+	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 
 	/* State should be equivalent to START */
-	if (!cdbs->policy_dbs || !cdbs->policy_dbs->policy)
+	if (!policy_dbs || !policy_dbs->policy)
 		return -EBUSY;
 
-	mutex_lock(&cdbs->policy_dbs->timer_mutex);
-	if (policy->max < cdbs->policy_dbs->policy->cur)
-		__cpufreq_driver_target(cdbs->policy_dbs->policy, policy->max,
-					CPUFREQ_RELATION_H);
-	else if (policy->min > cdbs->policy_dbs->policy->cur)
-		__cpufreq_driver_target(cdbs->policy_dbs->policy, policy->min,
-					CPUFREQ_RELATION_L);
+	mutex_lock(&policy_dbs->timer_mutex);
+	if (policy->max < policy->cur)
+		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
+	else if (policy->min > policy->cur)
+		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
 	dbs_check_cpu(policy);
-	mutex_unlock(&cdbs->policy_dbs->timer_mutex);
+	mutex_unlock(&policy_dbs->timer_mutex);
 
 	return 0;
 }

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

* [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
  2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
  2016-02-07 15:23     ` [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits() Rafael J. Wysocki
@ 2016-02-07 15:24     ` Rafael J. Wysocki
  2016-02-07 15:45       ` Viresh Kumar
  2016-02-07 15:55       ` Viresh Kumar
  2016-02-07 15:25     ` [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup Rafael J. Wysocki
  2 siblings, 2 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 15:24 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

The struct policy_dbs_info objects representing per-policy governor
data are not accessible directly from the corresponding policy
objects.  To access them, one has to get a pointer to the
struct cpu_dbs_info of policy->cpu and use the policy_dbs field of
that which isn't really straightforward.

To address that rearrange the governor data structures so the
governor_data pointer in struct cpufreq_policy will point to
struct policy_dbs_info (instead of struct dbs_data) and that will
contain a pointer to struct dbs_data.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/amd_freq_sensitivity.c |    3 -
 drivers/cpufreq/cpufreq_conservative.c |    6 +-
 drivers/cpufreq/cpufreq_governor.c     |   74 ++++++++++++++++-----------------
 drivers/cpufreq/cpufreq_governor.h     |   27 ++++++------
 drivers/cpufreq/cpufreq_ondemand.c     |   18 ++++----
 5 files changed, 68 insertions(+), 60 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.h
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.h
+++ linux-pm/drivers/cpufreq/cpufreq_governor.h
@@ -85,7 +85,8 @@ static ssize_t show_##file_name##_gov_sy
 static ssize_t show_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	struct _gov##_dbs_tuners *tuners = dbs_data->tuners;		\
 	return sprintf(buf, "%u\n", tuners->file_name);			\
 }
@@ -101,8 +102,8 @@ static ssize_t store_##file_name##_gov_s
 static ssize_t store_##file_name##_gov_pol				\
 (struct cpufreq_policy *policy, const char *buf, size_t count)		\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
-	return store_##file_name(dbs_data, buf, count);			\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	return store_##file_name(policy_dbs->dbs_data, buf, count);			\
 }
 
 #define show_store_one(_gov, file_name)					\
@@ -130,6 +131,13 @@ static void *get_cpu_dbs_info_s(int cpu)
  * cs_*: Conservative governor
  */
 
+/* Governor demand based switching data (per-policy or global). */
+struct dbs_data {
+	unsigned int min_sampling_rate;
+	int usage_count;
+	void *tuners;
+};
+
 /* Common to all CPUs of a policy */
 struct policy_dbs_info {
 	struct cpufreq_policy *policy;
@@ -144,6 +152,8 @@ struct policy_dbs_info {
 	atomic_t skip_work;
 	struct irq_work irq_work;
 	struct work_struct work;
+	/* dbs_data may be shared between multiple policy objects */
+	struct dbs_data *dbs_data;
 };
 
 static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
@@ -204,7 +214,6 @@ struct cs_dbs_tuners {
 };
 
 /* Common Governor data across policies */
-struct dbs_data;
 struct dbs_governor {
 	struct cpufreq_governor gov;
 
@@ -236,13 +245,6 @@ static inline struct dbs_governor *dbs_g
 	return container_of(policy->governor, struct dbs_governor, gov);
 }
 
-/* Governor Per policy data */
-struct dbs_data {
-	unsigned int min_sampling_rate;
-	int usage_count;
-	void *tuners;
-};
-
 /* Governor specific ops, will be passed to dbs_data->gov_ops */
 struct od_ops {
 	void (*powersave_bias_init_cpu)(int cpu);
@@ -273,7 +275,8 @@ static ssize_t show_sampling_rate_min_go
 static ssize_t show_sampling_rate_min_gov_pol				\
 (struct cpufreq_policy *policy, char *buf)				\
 {									\
-	struct dbs_data *dbs_data = policy->governor_data;		\
+	struct policy_dbs_info *policy_dbs = policy->governor_data;	\
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;		\
 	return sprintf(buf, "%u\n", dbs_data->min_sampling_rate);	\
 }
 
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -35,8 +35,8 @@ void dbs_check_cpu(struct cpufreq_policy
 {
 	int cpu = policy->cpu;
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 	unsigned int sampling_rate;
@@ -95,6 +95,7 @@ void dbs_check_cpu(struct cpufreq_policy
 		j_cdbs->prev_cpu_idle = cur_idle_time;
 
 		if (ignore_nice) {
+			struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
 			u64 cur_nice;
 			unsigned long cur_nice_jiffies;
 
@@ -291,8 +292,8 @@ static void set_sampling_rate(struct dbs
 	}
 }
 
-static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
-				 struct dbs_governor *gov)
+static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
+						     struct dbs_governor *gov)
 {
 	struct policy_dbs_info *policy_dbs;
 	int j;
@@ -300,7 +301,7 @@ static int alloc_policy_dbs_info(struct
 	/* Allocate memory for the common information for policy->cpus */
 	policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
 	if (!policy_dbs)
-		return -ENOMEM;
+		return NULL;
 
 	/* Set policy_dbs for all CPUs, online+offline */
 	for_each_cpu(j, policy->related_cpus)
@@ -310,7 +311,7 @@ static int alloc_policy_dbs_info(struct
 	atomic_set(&policy_dbs->skip_work, 0);
 	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 	INIT_WORK(&policy_dbs->work, dbs_work_handler);
-	return 0;
+	return policy_dbs;
 }
 
 static void free_policy_dbs_info(struct cpufreq_policy *policy,
@@ -332,6 +333,7 @@ static int cpufreq_governor_init(struct
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
 	struct dbs_data *dbs_data = gov->gdbs_data;
+	struct policy_dbs_info *policy_dbs;
 	unsigned int latency;
 	int ret;
 
@@ -339,26 +341,26 @@ static int cpufreq_governor_init(struct
 	if (policy->governor_data)
 		return -EBUSY;
 
-	if (dbs_data) {
-		if (WARN_ON(have_governor_per_policy()))
-			return -EINVAL;
-
-		ret = alloc_policy_dbs_info(policy, gov);
-		if (ret)
-			return ret;
+	policy_dbs = alloc_policy_dbs_info(policy, gov);
+	if (!policy_dbs)
+		return -ENOMEM;
 
+	if (dbs_data) {
+		if (WARN_ON(have_governor_per_policy())) {
+			ret = -EINVAL;
+			goto free_policy_dbs_info;
+		}
 		dbs_data->usage_count++;
-		policy->governor_data = dbs_data;
+		policy_dbs->dbs_data = dbs_data;
+		policy->governor_data = policy_dbs;
 		return 0;
 	}
 
 	dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL);
-	if (!dbs_data)
-		return -ENOMEM;
-
-	ret = alloc_policy_dbs_info(policy, gov);
-	if (ret)
-		goto free_dbs_data;
+	if (!dbs_data) {
+		ret = -ENOMEM;
+		goto free_policy_dbs_info;
+	}
 
 	dbs_data->usage_count = 1;
 
@@ -380,7 +382,8 @@ static int cpufreq_governor_init(struct
 	if (!have_governor_per_policy())
 		gov->gdbs_data = dbs_data;
 
-	policy->governor_data = dbs_data;
+	policy_dbs->dbs_data = dbs_data;
+	policy->governor_data = policy_dbs;
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
 				 get_sysfs_attr(gov));
@@ -395,21 +398,21 @@ reset_gdbs_data:
 	if (!have_governor_per_policy())
 		gov->gdbs_data = NULL;
 	gov->exit(dbs_data, !policy->governor->initialized);
+	kfree(dbs_data);
+
 free_policy_dbs_info:
 	free_policy_dbs_info(policy, gov);
-free_dbs_data:
-	kfree(dbs_data);
 	return ret;
 }
 
 static int cpufreq_governor_exit(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 
 	/* State should be equivalent to INIT */
-	if (!cdbs->policy_dbs || cdbs->policy_dbs->policy)
+	if (policy_dbs->policy)
 		return -EBUSY;
 
 	if (!--dbs_data->usage_count) {
@@ -434,17 +437,16 @@ static int cpufreq_governor_exit(struct
 static int cpufreq_governor_start(struct cpufreq_policy *policy)
 {
 	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
 	int io_busy = 0;
 
 	if (!policy->cur)
 		return -EINVAL;
 
 	/* State should be equivalent to INIT */
-	if (!policy_dbs || policy_dbs->policy)
+	if (policy_dbs->policy)
 		return -EBUSY;
 
 	if (gov->governor == GOV_CONSERVATIVE) {
@@ -500,12 +502,10 @@ static int cpufreq_governor_start(struct
 
 static int cpufreq_governor_stop(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
 
 	/* State should be equivalent to START */
-	if (!policy_dbs || !policy_dbs->policy)
+	if (!policy_dbs->policy)
 		return -EBUSY;
 
 	gov_cancel_work(policy_dbs);
@@ -516,12 +516,10 @@ static int cpufreq_governor_stop(struct
 
 static int cpufreq_governor_limits(struct cpufreq_policy *policy)
 {
-	struct dbs_governor *gov = dbs_governor_of(policy);
-	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
-	struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
 
 	/* State should be equivalent to START */
-	if (!policy_dbs || !policy_dbs->policy)
+	if (!policy_dbs->policy)
 		return -EBUSY;
 
 	mutex_lock(&policy_dbs->timer_mutex);
Index: linux-pm/drivers/cpufreq/cpufreq_ondemand.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_ondemand.c
+++ linux-pm/drivers/cpufreq/cpufreq_ondemand.c
@@ -78,7 +78,8 @@ static unsigned int generic_powersave_bi
 	unsigned int jiffies_total, jiffies_hi, jiffies_lo;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
 						   policy->cpu);
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (!dbs_info->freq_table) {
@@ -130,7 +131,8 @@ static void ondemand_powersave_bias_init
 
 static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	if (od_tuners->powersave_bias)
@@ -151,8 +153,9 @@ static void dbs_freq_increase(struct cpu
 static void od_check_cpu(int cpu, unsigned int load)
 {
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
-	struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = dbs_info->cdbs.policy_dbs;
+	struct cpufreq_policy *policy = policy_dbs->policy;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 
 	dbs_info->freq_lo = 0;
@@ -189,7 +192,8 @@ static void od_check_cpu(int cpu, unsign
 
 static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
 	int delay = 0, sample_type = dbs_info->sample_type;
@@ -277,7 +281,7 @@ static void update_sampling_rate(struct
 		 * policy will be governed by dbs_data, otherwise there can be
 		 * multiple policies that are governed by the same dbs_data.
 		 */
-		if (dbs_data == policy->governor_data) {
+		if (dbs_data == policy_dbs->dbs_data) {
 			mutex_lock(&policy_dbs->timer_mutex);
 			/*
 			 * On 32-bit architectures this may race with the
@@ -586,7 +590,7 @@ static void od_set_powersave_bias(unsign
 		if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
 			continue;
 
-		dbs_data = policy->governor_data;
+		dbs_data = policy_dbs->dbs_data;
 		od_tuners = dbs_data->tuners;
 		od_tuners->powersave_bias = default_powersave_bias;
 	}
Index: linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/amd_freq_sensitivity.c
+++ linux-pm/drivers/cpufreq/amd_freq_sensitivity.c
@@ -45,7 +45,8 @@ static unsigned int amd_powersave_bias_t
 	long d_actual, d_reference;
 	struct msr actual, reference;
 	struct cpu_data_t *data = &per_cpu(cpu_data, policy->cpu);
-	struct dbs_data *od_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *od_data = policy_dbs->dbs_data;
 	struct od_dbs_tuners *od_tuners = od_data->tuners;
 	struct od_cpu_dbs_info_s *od_info =
 		dbs_governor_of(policy)->get_cpu_dbs_info_s(policy->cpu);
Index: linux-pm/drivers/cpufreq/cpufreq_conservative.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_conservative.c
+++ linux-pm/drivers/cpufreq/cpufreq_conservative.c
@@ -48,7 +48,8 @@ static void cs_check_cpu(int cpu, unsign
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
 	struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	/*
@@ -104,7 +105,8 @@ static void cs_check_cpu(int cpu, unsign
 
 static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
 {
-	struct dbs_data *dbs_data = policy->governor_data;
+	struct policy_dbs_info *policy_dbs = policy->governor_data;
+	struct dbs_data *dbs_data = policy_dbs->dbs_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
 
 	dbs_check_cpu(policy);

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

* [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup
  2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
  2016-02-07 15:23     ` [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits() Rafael J. Wysocki
  2016-02-07 15:24     ` [PATCH 2/3] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
@ 2016-02-07 15:25     ` Rafael J. Wysocki
  2016-02-07 15:52       ` Viresh Kumar
  2 siblings, 1 reply; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-07 15:25 UTC (permalink / raw)
  To: Linux PM list
  Cc: Linux Kernel Mailing List, Viresh Kumar, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

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

Make the initialization of struct cpu_dbs_info objects in
alloc_policy_dbs_info() and the code that cleans them up in
free_policy_dbs_info() more symmetrical.  In particular,
set/clear the update_util.func field in those functions along
with the policy_dbs field.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpufreq/cpufreq_governor.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -303,14 +303,18 @@ static struct policy_dbs_info *alloc_pol
 	if (!policy_dbs)
 		return NULL;
 
-	/* Set policy_dbs for all CPUs, online+offline */
-	for_each_cpu(j, policy->related_cpus)
-		gov->get_cpu_cdbs(j)->policy_dbs = policy_dbs;
-
 	mutex_init(&policy_dbs->timer_mutex);
 	atomic_set(&policy_dbs->skip_work, 0);
 	init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
 	INIT_WORK(&policy_dbs->work, dbs_work_handler);
+
+	/* Set policy_dbs for all CPUs, online+offline */
+	for_each_cpu(j, policy->related_cpus) {
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
+
+		j_cdbs->policy_dbs = policy_dbs;
+		j_cdbs->update_util.func = dbs_update_util_handler;
+	}
 	return policy_dbs;
 }
 
@@ -323,9 +327,12 @@ static void free_policy_dbs_info(struct
 
 	mutex_destroy(&policy_dbs->timer_mutex);
 
-	for_each_cpu(j, policy->cpus)
-		gov->get_cpu_cdbs(j)->policy_dbs = NULL;
+	for_each_cpu(j, policy->related_cpus) {
+		struct cpu_dbs_info *j_cdbs = gov->get_cpu_cdbs(j);
 
+		j_cdbs->policy_dbs = NULL;
+		j_cdbs->update_util.func = NULL;
+	}
 	kfree(policy_dbs);
 }
 
@@ -476,8 +483,6 @@ static int cpufreq_governor_start(struct
 
 		if (ignore_nice)
 			j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
-
-		j_cdbs->update_util.func = dbs_update_util_handler;
 	}
 	policy_dbs->policy = policy;
 

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

* Re: [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits()
  2016-02-07 15:23     ` [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits() Rafael J. Wysocki
@ 2016-02-07 15:40       ` Viresh Kumar
  2016-02-08  0:59         ` Rafael J. Wysocki
  0 siblings, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07 15:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 07-02-16, 16:23, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Use the observation that cpufreq_governor_limits() doesn't have to
> get to the policy object it wants to manipulate by walking the
> reference chain cdbs->policy_dbs->policy, as the final pointer is
> actually equal to its argument, and make it access the policy
> object directy via its argument.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq_governor.c |   17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)

Why the hell did we write it that way earlier ? :)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
  2016-02-07 15:24     ` [PATCH 2/3] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
@ 2016-02-07 15:45       ` Viresh Kumar
  2016-02-07 15:54         ` Viresh Kumar
  2016-02-07 15:55       ` Viresh Kumar
  1 sibling, 1 reply; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07 15:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 07-02-16, 16:24, Rafael J. Wysocki wrote:
>  static int cpufreq_governor_exit(struct cpufreq_policy *policy)
>  {
>  	struct dbs_governor *gov = dbs_governor_of(policy);
> -	struct dbs_data *dbs_data = policy->governor_data;
> -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
> +	struct policy_dbs_info *policy_dbs = policy->governor_data;
> +	struct dbs_data *dbs_data = policy_dbs->dbs_data;
>  
>  	/* State should be equivalent to INIT */
> -	if (!cdbs->policy_dbs || cdbs->policy_dbs->policy)
> +	if (policy_dbs->policy)
>  		return -EBUSY;

We can crash here if policy_dbs is NULL, which can happen if EXIT is called
twice (due to the lock-dropping thing in cpufreq-core). So we really need to
keep these checks for now atleast.

-- 
viresh

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

* Re: [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup
  2016-02-07 15:25     ` [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup Rafael J. Wysocki
@ 2016-02-07 15:52       ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07 15:52 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 07-02-16, 16:25, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Make the initialization of struct cpu_dbs_info objects in
> alloc_policy_dbs_info() and the code that cleans them up in
> free_policy_dbs_info() more symmetrical.  In particular,
> set/clear the update_util.func field in those functions along
> with the policy_dbs field.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/cpufreq_governor.c |   21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
  2016-02-07 15:45       ` Viresh Kumar
@ 2016-02-07 15:54         ` Viresh Kumar
  0 siblings, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07 15:54 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 07-02-16, 21:15, Viresh Kumar wrote:
> On 07-02-16, 16:24, Rafael J. Wysocki wrote:
> >  static int cpufreq_governor_exit(struct cpufreq_policy *policy)
> >  {
> >  	struct dbs_governor *gov = dbs_governor_of(policy);
> > -	struct dbs_data *dbs_data = policy->governor_data;
> > -	struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
> > +	struct policy_dbs_info *policy_dbs = policy->governor_data;
> > +	struct dbs_data *dbs_data = policy_dbs->dbs_data;
> >  
> >  	/* State should be equivalent to INIT */
> > -	if (!cdbs->policy_dbs || cdbs->policy_dbs->policy)
> > +	if (policy_dbs->policy)
> >  		return -EBUSY;
> 
> We can crash here if policy_dbs is NULL, which can happen if EXIT is called
> twice (due to the lock-dropping thing in cpufreq-core). So we really need to
> keep these checks for now atleast.

Well no, things have changed now a bit with your recent changes and so this
wouldn't be an issue here. Sorry for the noise.

-- 
viresh

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

* Re: [PATCH 2/3] cpufreq: governor: Rearrange governor data structures
  2016-02-07 15:24     ` [PATCH 2/3] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
  2016-02-07 15:45       ` Viresh Kumar
@ 2016-02-07 15:55       ` Viresh Kumar
  1 sibling, 0 replies; 86+ messages in thread
From: Viresh Kumar @ 2016-02-07 15:55 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On 07-02-16, 16:24, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The struct policy_dbs_info objects representing per-policy governor
> data are not accessible directly from the corresponding policy
> objects.  To access them, one has to get a pointer to the
> struct cpu_dbs_info of policy->cpu and use the policy_dbs field of
> that which isn't really straightforward.
> 
> To address that rearrange the governor data structures so the
> governor_data pointer in struct cpufreq_policy will point to
> struct policy_dbs_info (instead of struct dbs_data) and that will
> contain a pointer to struct dbs_data.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpufreq/amd_freq_sensitivity.c |    3 -
>  drivers/cpufreq/cpufreq_conservative.c |    6 +-
>  drivers/cpufreq/cpufreq_governor.c     |   74 ++++++++++++++++-----------------
>  drivers/cpufreq/cpufreq_governor.h     |   27 ++++++------
>  drivers/cpufreq/cpufreq_ondemand.c     |   18 ++++----
>  5 files changed, 68 insertions(+), 60 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits()
  2016-02-07 15:40       ` Viresh Kumar
@ 2016-02-08  0:59         ` Rafael J. Wysocki
  0 siblings, 0 replies; 86+ messages in thread
From: Rafael J. Wysocki @ 2016-02-08  0:59 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linux PM list, Linux Kernel Mailing List, Srinivas Pandruvada,
	Juri Lelli, Steve Muckle, Saravana Kannan

On Sunday, February 07, 2016 09:10:24 PM Viresh Kumar wrote:
> On 07-02-16, 16:23, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > Use the observation that cpufreq_governor_limits() doesn't have to
> > get to the policy object it wants to manipulate by walking the
> > reference chain cdbs->policy_dbs->policy, as the final pointer is
> > actually equal to its argument, and make it access the policy
> > object directy via its argument.
> > 
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >  drivers/cpufreq/cpufreq_governor.c |   17 ++++++++---------
> >  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> Why the hell did we write it that way earlier ? :)

Honestly, I have no idea.

> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Thanks!

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

* Re: [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
  2016-02-05  2:11   ` [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
@ 2016-02-10  5:15     ` Gautham R Shenoy
  2016-02-10  5:48         ` Gautham R Shenoy
  0 siblings, 1 reply; 86+ messages in thread
From: Gautham R Shenoy @ 2016-02-10  5:15 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM list, Linux Kernel Mailing List, Viresh Kumar,
	Srinivas Pandruvada, Juri Lelli, Steve Muckle, Saravana Kannan

Hello Rafael,

On Fri, Feb 05, 2016 at 03:11:54AM +0100, Rafael J. Wysocki wrote:
[..snip..]
> Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
> +++ linux-pm/drivers/cpufreq/cpufreq_performance.c
> @@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
>  	return 0;
>  }
> 
> -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> -static
> -#endif
> -struct cpufreq_governor cpufreq_gov_performance = {
> +static struct cpufreq_governor cpufreq_gov_performance = {
>  	.name		= "performance",
>  	.governor	= cpufreq_governor_performance,
>  	.owner		= THIS_MODULE,
> @@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
>  	cpufreq_unregister_governor(&cpufreq_gov_performance);
>  }
> 
> +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> +struct cpufreq_governor *cpufreq_default_governor(void)
> +{
> +	return &cpufreq_gov_performance;
> +}
> +#endif
> +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE

Shouldn't this be #ifdef ?

> +struct cpufreq_governor *cpufreq_fallback_governor(void)
> +{
> +	return &cpufreq_gov_performance;
> +}
> +#endif


--
Thanks and Regards
gautham.

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

* Re: [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
  2016-02-10  5:15     ` Gautham R Shenoy
@ 2016-02-10  5:48         ` Gautham R Shenoy
  0 siblings, 0 replies; 86+ messages in thread
From: Gautham R Shenoy @ 2016-02-10  5:48 UTC (permalink / raw)
  To: Gautham R Shenoy
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Viresh Kumar, Srinivas Pandruvada, Juri Lelli, Steve Muckle,
	Saravana Kannan

On Wed, Feb 10, 2016 at 10:45:14AM +0530, Gautham R Shenoy wrote:
> Hello Rafael,
> 
> On Fri, Feb 05, 2016 at 03:11:54AM +0100, Rafael J. Wysocki wrote:
> [..snip..]
> > Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
> > ===================================================================
> > --- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
> > +++ linux-pm/drivers/cpufreq/cpufreq_performance.c
> > @@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
> >  	return 0;
> >  }
> > 
> > -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> > -static
> > -#endif
> > -struct cpufreq_governor cpufreq_gov_performance = {
> > +static struct cpufreq_governor cpufreq_gov_performance = {
> >  	.name		= "performance",
> >  	.governor	= cpufreq_governor_performance,
> >  	.owner		= THIS_MODULE,
> > @@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
> >  	cpufreq_unregister_governor(&cpufreq_gov_performance);
> >  }
> > 
> > +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> > +struct cpufreq_governor *cpufreq_default_governor(void)
> > +{
> > +	return &cpufreq_gov_performance;
> > +}
> > +#endif
> > +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> 
> Shouldn't this be #ifdef ?

Never mind! Shouldn't be reviewing patches first thing in the morning!

--
Thanks and Regards
gautham.

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

* Re: [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup
@ 2016-02-10  5:48         ` Gautham R Shenoy
  0 siblings, 0 replies; 86+ messages in thread
From: Gautham R Shenoy @ 2016-02-10  5:48 UTC (permalink / raw)
  To: Gautham R Shenoy
  Cc: Rafael J. Wysocki, Linux PM list, Linux Kernel Mailing List,
	Viresh Kumar, Srinivas Pandruvada, Juri Lelli, Steve Muckle,
	Saravana Kannan

On Wed, Feb 10, 2016 at 10:45:14AM +0530, Gautham R Shenoy wrote:
> Hello Rafael,
> 
> On Fri, Feb 05, 2016 at 03:11:54AM +0100, Rafael J. Wysocki wrote:
> [..snip..]
> > Index: linux-pm/drivers/cpufreq/cpufreq_performance.c
> > ===================================================================
> > --- linux-pm.orig/drivers/cpufreq/cpufreq_performance.c
> > +++ linux-pm/drivers/cpufreq/cpufreq_performance.c
> > @@ -33,10 +33,7 @@ static int cpufreq_governor_performance(
> >  	return 0;
> >  }
> > 
> > -#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> > -static
> > -#endif
> > -struct cpufreq_governor cpufreq_gov_performance = {
> > +static struct cpufreq_governor cpufreq_gov_performance = {
> >  	.name		= "performance",
> >  	.governor	= cpufreq_governor_performance,
> >  	.owner		= THIS_MODULE,
> > @@ -52,6 +49,19 @@ static void __exit cpufreq_gov_performan
> >  	cpufreq_unregister_governor(&cpufreq_gov_performance);
> >  }
> > 
> > +#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
> > +struct cpufreq_governor *cpufreq_default_governor(void)
> > +{
> > +	return &cpufreq_gov_performance;
> > +}
> > +#endif
> > +#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE
> 
> Shouldn't this be #ifdef ?

Never mind! Shouldn't be reviewing patches first thing in the morning!

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

end of thread, other threads:[~2016-02-10  5:48 UTC | newest]

Thread overview: 86+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-03 23:12 [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
2016-02-03 23:14 ` [PATCH 1/11] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
2016-02-04  0:55   ` Saravana Kannan
2016-02-04  5:03   ` Viresh Kumar
2016-02-03 23:16 ` [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
2016-02-04  0:59   ` Saravana Kannan
2016-02-04  5:09   ` Viresh Kumar
2016-02-04 16:46     ` Rafael J. Wysocki
2016-02-05  2:59       ` Viresh Kumar
2016-02-05  3:06         ` Rafael J. Wysocki
2016-02-05  3:15           ` Rafael J. Wysocki
2016-02-05  3:17             ` Rafael J. Wysocki
2016-02-05  3:24               ` Viresh Kumar
2016-02-05  3:33                 ` Rafael J. Wysocki
2016-02-05  3:22           ` Viresh Kumar
2016-02-03 23:22 ` [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer Rafael J. Wysocki
2016-02-04  1:11   ` Saravana Kannan
2016-02-04  1:25     ` Rafael J. Wysocki
2016-02-04  1:40       ` Saravana Kannan
2016-02-04  5:38       ` Viresh Kumar
2016-02-04  1:47     ` Saravana Kannan
2016-02-04  5:36   ` Viresh Kumar
     [not found]     ` <CAHZ_5WxJSDtFyFdCc-D2=HSaPON=3rzUxpxPYsCyZvrV1Nv3qw@mail.gmail.com>
2016-02-04  8:25       ` Viresh Kumar
2016-02-04 11:31         ` Gautham R Shenoy
2016-02-04 11:35           ` Viresh Kumar
2016-02-04 16:52     ` Rafael J. Wysocki
2016-02-05  3:02       ` Viresh Kumar
2016-02-05  3:10         ` Rafael J. Wysocki
2016-02-03 23:29 ` [PATCH 4/11] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
2016-02-04  1:37   ` Saravana Kannan
2016-02-03 23:31 ` [PATCH 5/11] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
2016-02-04  1:57   ` Saravana Kannan
2016-02-03 23:32 ` [PATCH 6/11] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
2016-02-03 23:33 ` [PATCH 7/11] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
2016-02-04  2:03   ` Saravana Kannan
2016-02-03 23:35 ` [PATCH 8/11] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
2016-02-03 23:35 ` [PATCH 9/11] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
2016-02-03 23:37 ` [PATCH 10/11] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
2016-02-03 23:38 ` [PATCH 11/11] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
2016-02-04  5:40 ` [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework Viresh Kumar
2016-02-04 17:22   ` Rafael J. Wysocki
2016-02-05  2:07 ` [PATCH v2 0/10] " Rafael J. Wysocki
2016-02-05  2:11   ` [PATCH v2 1/10] cpufreq: Clean up default and fallback governor setup Rafael J. Wysocki
2016-02-10  5:15     ` Gautham R Shenoy
2016-02-10  5:48       ` Gautham R Shenoy
2016-02-10  5:48         ` Gautham R Shenoy
2016-02-05  2:14   ` [PATCH v2 2/10] cpufreq: governor: Use common mutex for dbs_data protection Rafael J. Wysocki
2016-02-05  6:53     ` Viresh Kumar
2016-02-05 22:59       ` Rafael J. Wysocki
2016-02-07  9:31         ` Viresh Kumar
2016-02-07 14:33           ` Rafael J. Wysocki
2016-02-05  2:15   ` [PATCH v2 3/10] cpufreq: governor: Avoid passing dbs_data pointers around unnecessarily Rafael J. Wysocki
2016-02-05  7:09     ` Viresh Kumar
2016-02-05  2:16   ` [PATCH v2 4/10] cpufreq: governor: Put governor structure into common_dbs_data Rafael J. Wysocki
2016-02-05  7:13     ` Viresh Kumar
2016-02-05  2:17   ` [PATCH v2 5/10] cpufreq: governor: Rename some data types and variables Rafael J. Wysocki
2016-02-05  7:17     ` Viresh Kumar
2016-02-05  2:18   ` [PATCH v2 6/10] cpufreq: governor: Rework cpufreq_governor_dbs() Rafael J. Wysocki
2016-02-05  8:14     ` Viresh Kumar
2016-02-05  2:19   ` [PATCH v2 7/10] cpufreq: governor: Drop the gov pointer from struct dbs_data Rafael J. Wysocki
2016-02-05  8:28     ` Viresh Kumar
2016-02-05  2:20   ` [PATCH v2 8/10] cpufreq: governor: Rename cpu_common_dbs_info to policy_dbs_info Rafael J. Wysocki
2016-02-05  8:34     ` Viresh Kumar
2016-02-05 22:50       ` Rafael J. Wysocki
2016-02-06 12:48     ` [PATCH v3 " Rafael J. Wysocki
2016-02-07  9:31       ` Viresh Kumar
2016-02-05  2:21   ` [PATCH v2 9/10] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
2016-02-05  9:13     ` Viresh Kumar
2016-02-05 22:47       ` Rafael J. Wysocki
2016-02-07  9:29         ` Viresh Kumar
2016-02-07 14:34           ` Rafael J. Wysocki
2016-02-05  2:21   ` [PATCH v2 10/10] cpufreq: governor: Drop cpu argument from dbs_check_cpu() Rafael J. Wysocki
2016-02-05  9:15     ` Viresh Kumar
2016-02-06 12:50     ` [PATCH v3 " Rafael J. Wysocki
2016-02-07  9:32       ` Viresh Kumar
2016-02-06 12:44   ` [PATCH v2 0/10] cpufreq: governor: ondemand/conservative data structures rework Rafael J. Wysocki
2016-02-07 15:22   ` [PATCH 0/3] cpufreq: governor: Data structure rearrangement Rafael J. Wysocki
2016-02-07 15:23     ` [PATCH 1/3] cpufreq: governor: Simplify cpufreq_governor_limits() Rafael J. Wysocki
2016-02-07 15:40       ` Viresh Kumar
2016-02-08  0:59         ` Rafael J. Wysocki
2016-02-07 15:24     ` [PATCH 2/3] cpufreq: governor: Rearrange governor data structures Rafael J. Wysocki
2016-02-07 15:45       ` Viresh Kumar
2016-02-07 15:54         ` Viresh Kumar
2016-02-07 15:55       ` Viresh Kumar
2016-02-07 15:25     ` [PATCH 3/3] cpufreq: governor: Symmetrize cpu_dbs_info initialization and cleanup Rafael J. Wysocki
2016-02-07 15:52       ` Viresh Kumar

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.