Skip to contentSkip to conversation

PM / devfreq: Add new passive governor

PATCH MyungJoo Ham 2 participants 2 messages Dec 14, 2015 – Dec 18, 2015 Arm Samsung Exynos

lore
Share & tools
lore
#0 lore raw
Quoted 43 lines

This patch adds the new passive governor for DEVFREQ framework. The following
governors are already present and used for DVFS (Dynamic Voltage and Frequency Scaling) drivers. The following governors are independently used for one device driver which don't give the influence to other device drviers and also don't receive the effect from other device drivers.
- ondemand / performance / powersave / userspace

The passive governor depends on operation of parent driver with specific governos extremely and is not able to decide the new frequency by oneself. According to the decided new frequency of parent driver with governor, the passive governor uses it to decide the appropriate frequency for own device driver. The passive governor must need the following information from device tree:
- the source clock and OPP tables
- the instance of parent device

For exameple,
there are one more devfreq device drivers which need to change their source clock according to their utilization on runtime. But, they share the same power line (e.g., regulator). So, specific device driver is operated as parent with ondemand governor and then the rest device driver with passive governor is influenced by parent device.

[linux.amoon: Tested on Odroid U3]
---
 drivers/devfreq/Kconfig            |   9 ++++
 drivers/devfreq/Makefile           |   1 +
 drivers/devfreq/devfreq.c          |  47 ++++++++++++++++
 drivers/devfreq/governor_passive.c | 108 +++++++++++++++++++++++++++++++++++++
 include/linux/devfreq.h            |  15 ++++++
 5 files changed, 180 insertions(+)
 create mode 100644 drivers/devfreq/governor_passive.c
drivers/devfreq/Kconfig +0 -0
index 55ec774f794c..d03f635a93e1 100644
@@ -64,6 +64,15 @@ config DEVFREQ_GOV_USERSPACE
 	  Otherwise, the governor does not change the frequnecy

drivers/devfreq/Kconfig config DEVFREQ_GOV_USERSPACE · line 74

Quoted 10 lines
drivers/devfreq/Kconfig +8 -0
 	  given at the initialization.
 
+config DEVFREQ_GOV_PASSIVE
+	tristate "Passive"
+	help
+	  Sets the frequency by other governors (simple_ondemand, performance,
+	  powersave, usersapce) of a parent devfreq device. This governor
+	  always has the dependency on the chosen frequency from paired
+	  governor. This governor does not change the frequency by oneself
+	  through sysfs entry.

Sets the frequency based on the frequency of its parent devfreq device. This governor does not change the frequency by itself through sysfs entries.

drivers/devfreq/Makefile

Quoted 8 lines
drivers/devfreq/Kconfig +1 -0
+
 comment "DEVFREQ Drivers"
 
 config ARM_EXYNOS_BUS_DEVFREQ
drivers/devfreq/Makefile +0 -0
index 375ebbb4fcfb..f81c313b4b79 100644

[]

Quoted 37 lines
drivers/devfreq/devfreq.c +25 -0
index 984c5e9e7bdd..15e58779e4c0 100644
@@ -190,6 +190,31 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
 
 /* Load monitoring helper functions for governors use */
 
+static int update_devfreq_passive(struct devfreq *devfreq, unsigned long freq)
+{
+	struct devfreq *passive;
+	unsigned long rate;
+	int ret;
+
+	list_for_each_entry(passive, &devfreq->passive_dev_list, passive_node) {
+		if (!passive->governor)
+			continue;
+		rate = freq;
+
+		ret = passive->governor->get_target_freq(passive, &rate);
+		if (ret)
+			return ret;
+
+		ret = passive->profile->target(passive->dev.parent, &rate, 0);
+		if (ret)
+			return ret;
+
+		passive->previous_freq = rate;
+	}
+
+	return 0;
+}
+
 /**
  * update_devfreq() - Reevaluate the device and configure frequency.
  * @devfreq:	the devfreq instance.

drivers/devfreq/devfreq.c int update_devfreq(struct devfreq *devfreq) · line 264

Quoted 7 lines
drivers/devfreq/devfreq.c +4 -0
@@ -233,10 +258,18 @@ int update_devfreq(struct devfreq *devfreq)
 		flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
 	}
 
+	if (!list_empty(&devfreq->passive_dev_list)
+		&& devfreq->previous_freq > freq)
+		update_devfreq_passive(devfreq, freq);
+

Could you please comment somewhere appropriate
that the dependent is going to be changed
before its parent if the frequency is going down.
(and after if going up)
And state why as well.

And, is this viable universally?

Quoted 29 lines
drivers/devfreq/devfreq.c +11 -0
 	err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
 	if (err)
 		return err;
 
+	if (!list_empty(&devfreq->passive_dev_list)
+		&& devfreq->previous_freq < freq)
+		update_devfreq_passive(devfreq, freq);
+
 	if (devfreq->profile->freq_table)
 		if (devfreq_update_status(devfreq, freq))
 			dev_err(&devfreq->dev,
@@ -442,6 +475,10 @@ static void _remove_devfreq(struct devfreq *devfreq)
 		return;
 	}
 	list_del(&devfreq->node);
+	list_del(&devfreq->passive_node);
+	if (!list_empty(&devfreq->passive_dev_list))
+		list_del_init(&devfreq->passive_dev_list);
+
 	mutex_unlock(&devfreq_list_lock);
 
 	if (devfreq->governor)
@@ -559,6 +596,16 @@ struct devfreq *devfreq_add_device(struct device *dev,
 		goto err_init;
 	}
 
+	if (!strncmp(devfreq->governor_name, "passive", 7)) {
+		struct devfreq *parent_devfreq =
+			((struct devfreq_passive_data *)data)->parent;

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 611

Quoted 10 lines
drivers/devfreq/devfreq.c +7 -0
+
+		list_add(&devfreq->passive_node,
+			&parent_devfreq->passive_dev_list);
+	} else {
+		INIT_LIST_HEAD(&devfreq->passive_dev_list);
+	}
+
 	return devfreq;
 
 err_init:

This code has become too much invasive to devfreq.c while being too special for the passive governor.

Why don't you add notifier chain to devfreq.c, which can be used by anyone else as well, and use that notifier for passive governor? You may refer to "cpufreq_register_notifier()" with CPUFREQ_TRANSITION_NOTIFIER.

drivers/devfreq/governor_passive.c

Quoted 2 lines
drivers/devfreq/governor_passive.c new file +0 -0
new file mode 100644

Then, utilizing notifier-block at governor_passive.c becomes possible.

You will also be able to write any frequency deciding code inside governor_passive.c as well, not in devfreq.c.

include/linux/devfreq.h struct devfreq { · line 183

Quoted 12 lines
include/linux/devfreq.h +3 -0
index 6fa02a20eb63..95c54578a1b4 100644
@@ -177,6 +177,9 @@ struct devfreq {
 	unsigned int *trans_table;
 	unsigned long *time_in_state;
 	unsigned long last_stat_updated;
+
+	struct list_head passive_dev_list;
+	struct list_head passive_node;
 };

You will need only one notifier head here.

Quoted 8 lines
include/linux/devfreq.h +2 -0
 #if defined(CONFIG_PM_DEVFREQ)
@@ -241,6 +244,18 @@ struct devfreq_simple_ondemand_data {
 };
 #endif
 
+/**
+ * struct devfreq_passive_data - void *data fed to struct devfreq

include/linux/devfreq.h struct devfreq_simple_ondemand_data { · line 258

Quoted 10 lines
include/linux/devfreq.h +10 -0
+ *	and devfreq_add_device
+ * @parent:		The parent devfreq device.
+ *
+ * If the fed devfreq_passive_data pointer is NULL to the governor,
+ * the governor return ERROR.
+ */
+struct devfreq_passive_data {
+	struct devfreq *parent;
+};
+

Please enclose the above with #if

Quoted 6 lines
include/linux/devfreq.h +0 -0
 #else /* !CONFIG_PM_DEVFREQ */
 static inline struct devfreq *devfreq_add_device(struct device *dev,
 					  struct devfreq_dev_profile *profile,
Signature · 1 line
1.9.1
#1 lore raw
Quoted 45 lines · MyungJoo Ham
Quoted 45 lines

This patch adds the new passive governor for DEVFREQ framework. The following
governors are already present and used for DVFS (Dynamic Voltage and Frequency Scaling) drivers. The following governors are independently used for one device driver which don't give the influence to other device drviers and also don't receive the effect from other device drivers.
- ondemand / performance / powersave / userspace

The passive governor depends on operation of parent driver with specific governos extremely and is not able to decide the new frequency by oneself. According to the decided new frequency of parent driver with governor, the passive governor uses it to decide the appropriate frequency for own device driver. The passive governor must need the following information from device tree:
- the source clock and OPP tables
- the instance of parent device

For exameple,
there are one more devfreq device drivers which need to change their source clock according to their utilization on runtime. But, they share the same power line (e.g., regulator). So, specific device driver is operated as parent with ondemand governor and then the rest device driver with passive governor is influenced by parent device.

[linux.amoon: Tested on Odroid U3]
---
 drivers/devfreq/Kconfig            |   9 ++++
 drivers/devfreq/Makefile           |   1 +
 drivers/devfreq/devfreq.c          |  47 ++++++++++++++++
 drivers/devfreq/governor_passive.c | 108 +++++++++++++++++++++++++++++++++++++
 include/linux/devfreq.h            |  15 ++++++
 5 files changed, 180 insertions(+)
 create mode 100644 drivers/devfreq/governor_passive.c
drivers/devfreq/Kconfig +0 -0
index 55ec774f794c..d03f635a93e1 100644
@@ -64,6 +64,15 @@ config DEVFREQ_GOV_USERSPACE
 	  Otherwise, the governor does not change the frequnecy
 	  given at the initialization.
 
Quoted 12 lines

drivers/devfreq/Kconfig config DEVFREQ_GOV_USERSPACE · line 74

Quoted 8 lines
drivers/devfreq/Kconfig +8 -0
+config DEVFREQ_GOV_PASSIVE
+	tristate "Passive"
+	help
+	  Sets the frequency by other governors (simple_ondemand, performance,
+	  powersave, usersapce) of a parent devfreq device. This governor
+	  always has the dependency on the chosen frequency from paired
+	  governor. This governor does not change the frequency by oneself
+	  through sysfs entry.

Sets the frequency based on the frequency of its parent devfreq device. This governor does not change the frequency by itself through sysfs entries.

OK. I'll modify it.

Quoted 50 lines

drivers/devfreq/Makefile

Quoted 9 lines
drivers/devfreq/Kconfig +1 -0
+
 comment "DEVFREQ Drivers"
 
 config ARM_EXYNOS_BUS_DEVFREQ
drivers/devfreq/Makefile +0 -0
index 375ebbb4fcfb..f81c313b4b79 100644

[]

Quoted 40 lines
drivers/devfreq/devfreq.c +25 -0
index 984c5e9e7bdd..15e58779e4c0 100644
@@ -190,6 +190,31 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
 
 /* Load monitoring helper functions for governors use */
 
+static int update_devfreq_passive(struct devfreq *devfreq, unsigned long freq)
+{
+	struct devfreq *passive;
+	unsigned long rate;
+	int ret;
+
+	list_for_each_entry(passive, &devfreq->passive_dev_list, passive_node) {
+		if (!passive->governor)
+			continue;
+		rate = freq;
+
+		ret = passive->governor->get_target_freq(passive, &rate);
+		if (ret)
+			return ret;
+
+		ret = passive->profile->target(passive->dev.parent, &rate, 0);
+		if (ret)
+			return ret;
+
+		passive->previous_freq = rate;
+	}
+
+	return 0;
+}
+
 /**
  * update_devfreq() - Reevaluate the device and configure frequency.
  * @devfreq:	the devfreq instance.
@@ -233,10 +258,18 @@ int update_devfreq(struct devfreq *devfreq)
 		flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
 	}
 
Quoted 10 lines

drivers/devfreq/devfreq.c int update_devfreq(struct devfreq *devfreq) · line 264

Quoted 4 lines
drivers/devfreq/devfreq.c +4 -0
+	if (!list_empty(&devfreq->passive_dev_list)
+		&& devfreq->previous_freq > freq)
+		update_devfreq_passive(devfreq, freq);
+

Could you please comment somewhere appropriate
that the dependent is going to be changed
before its parent if the frequency is going down.
(and after if going up)
And state why as well.

I use the DEVFREQ_TRANSITION_NOTIFIER instead of this implementation.

Quoted 41 lines

And, is this viable universally?

Quoted 38 lines
drivers/devfreq/devfreq.c +18 -0
 	err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
 	if (err)
 		return err;
 
+	if (!list_empty(&devfreq->passive_dev_list)
+		&& devfreq->previous_freq < freq)
+		update_devfreq_passive(devfreq, freq);
+
 	if (devfreq->profile->freq_table)
 		if (devfreq_update_status(devfreq, freq))
 			dev_err(&devfreq->dev,
@@ -442,6 +475,10 @@ static void _remove_devfreq(struct devfreq *devfreq)
 		return;
 	}
 	list_del(&devfreq->node);
+	list_del(&devfreq->passive_node);
+	if (!list_empty(&devfreq->passive_dev_list))
+		list_del_init(&devfreq->passive_dev_list);
+
 	mutex_unlock(&devfreq_list_lock);
 
 	if (devfreq->governor)
@@ -559,6 +596,16 @@ struct devfreq *devfreq_add_device(struct device *dev,
 		goto err_init;
 	}
 
+	if (!strncmp(devfreq->governor_name, "passive", 7)) {
+		struct devfreq *parent_devfreq =
+			((struct devfreq_passive_data *)data)->parent;
+
+		list_add(&devfreq->passive_node,
+			&parent_devfreq->passive_dev_list);
+	} else {
+		INIT_LIST_HEAD(&devfreq->passive_dev_list);
+	}
+
 	return devfreq;
 
Quoted 4 lines

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 611

Quoted 1 line
drivers/devfreq/devfreq.c +0 -0
 err_init:

This code has become too much invasive to devfreq.c while being too special for the passive governor.

I agree. I'll implement again with notifier.

Quoted 5 lines

Why don't you add notifier chain to devfreq.c, which can be used by anyone else as well, and use that notifier for passive governor? You may refer to "cpufreq_register_notifier()" with CPUFREQ_TRANSITION_NOTIFIER.

OK. I'll add the new notifier of DEVFREQ_TRANSITION_NOTIFIER The list of supported notification:
DEVFREQ_PRECHANGE
DEVFREQ_POSTCHANGE

Quoted 8 lines

drivers/devfreq/governor_passive.c

Quoted 3 lines
drivers/devfreq/governor_passive.c new file +0 -0
new file mode 100644

Then, utilizing notifier-block at governor_passive.c becomes possible.

You will also be able to write any frequency deciding code inside governor_passive.c as well, not in devfreq.c.

OK, I'll use DEVFREQ_TRANSITION_NOTIFIER for passive governor.

Quoted 15 lines

include/linux/devfreq.h struct devfreq { · line 183

Quoted 13 lines
include/linux/devfreq.h +3 -0
index 6fa02a20eb63..95c54578a1b4 100644
@@ -177,6 +177,9 @@ struct devfreq {
 	unsigned int *trans_table;
 	unsigned long *time_in_state;
 	unsigned long last_stat_updated;
+
+	struct list_head passive_dev_list;
+	struct list_head passive_node;
 };

You will need only one notifier head here.

OK.

Quoted 7 lines
Quoted 7 lines
include/linux/devfreq.h +0 -0
 #if defined(CONFIG_PM_DEVFREQ)
@@ -241,6 +244,18 @@ struct devfreq_simple_ondemand_data {
 };
 #endif
 
Quoted 14 lines

include/linux/devfreq.h struct devfreq_simple_ondemand_data { · line 258

Quoted 12 lines
include/linux/devfreq.h +12 -0
+/**
+ * struct devfreq_passive_data - void *data fed to struct devfreq
+ *	and devfreq_add_device
+ * @parent:		The parent devfreq device.
+ *
+ * If the fed devfreq_passive_data pointer is NULL to the governor,
+ * the governor return ERROR.
+ */
+struct devfreq_passive_data {
+	struct devfreq *parent;
+};
+

Please enclose the above with #if

OK.

Thanks,
Chanwoo Choi