Skip to contentSkip to conversation

Add watermark support to devfreq

RFC New Arto Merilainen 1 participant 4 messages Dec 5, 2014 Device frequency (devfreq)

lore
Share & tools
lore
#0 lore raw

cover Add watermark support to devfreq

Currently main mechanism to implement scaling using devfreq is polling and the device profile is free to set polling interval. However, in many cases this approach is not optimal; We may unnecessarily use CPU time to determine load on engine that is idle most of time - or we may simply read load when we already know that the device is busy.

In some cases a device itself has counters to track its activity and possibility to raise interrupts when load goes above or below certain threshold.

This series adds support for watermark events to devfreq and introduces two example governors. The first patch adds two callbacks to the device profile (for setting watermark) and adds a new function call to devfreq that informs of crossed watermark.

The added governors demonstrate usage of the new API. The first governor (watermark simple) sets device to trigger low watermark event when load goes below 10% and high watermark interrupt when the load goes above 60%. Watermark active tries to keep load at certain level and it actively sets thresholds based on the frequency table in order get interrupts only when the load value would affect to the current frequency in re-estimation.

Arto Merilainen (1):
PM / devfreq: Add watermark active governor

Shridhar Rasal (2):
PM / devfreq: Add watermark events
PM / devfreq: Add watermark simple governor

 drivers/devfreq/Kconfig                 |  18 +++
 drivers/devfreq/Makefile                |   2 +
 drivers/devfreq/devfreq.c               |  19 +++
 drivers/devfreq/governor.h              |   1 +
 drivers/devfreq/governor_wmark_active.c | 276 ++++++++++++++++++++++++++++++++
 drivers/devfreq/governor_wmark_simple.c | 245 ++++++++++++++++++++++++++++
 include/linux/devfreq.h                 |  26 +++
 7 files changed, 587 insertions(+)
 create mode 100644 drivers/devfreq/governor_wmark_active.c
 create mode 100644 drivers/devfreq/governor_wmark_simple.c
Signature · 1 line
1.8.1.5
#1 lore raw

RFC 1/3 PM / devfreq: Add watermark events

From: Shridhar Rasal <[email protected]>

This patch adds support for watermark events. These events inform the governor that the device load has gone below (low watermark) or above (high watermark) certain load value.

---
 drivers/devfreq/devfreq.c  | 19 +++++++++++++++++++
 drivers/devfreq/governor.h |  1 +
 include/linux/devfreq.h    | 26 ++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
drivers/devfreq/devfreq.c +19 -0
index 30b538d8cc90..8333d024132a 100644
@@ -1050,6 +1050,25 @@ static struct attribute *devfreq_attrs[] = {
 };
 ATTRIBUTE_GROUPS(devfreq);
 
+/**
+ * devfreq_watermark_event() - Handles watermark events
+ * @devfreq: the devfreq instance to be updated
+ * @type: type of watermark event
+ */
+int devfreq_watermark_event(struct devfreq *devfreq, int type)
+{
+	if (!devfreq)
+		return -EINVAL;
+
+	if (!devfreq->governor)
+		return -EINVAL;
+
+	return devfreq->governor->event_handler(devfreq,
+				DEVFREQ_GOV_WMARK, &type);
+}
+EXPORT_SYMBOL(devfreq_watermark_event);
+
+
 static int __init devfreq_init(void)
 {
 	devfreq_class = class_create(THIS_MODULE, "devfreq");
drivers/devfreq/governor.h +1 -0
index fad7d6321978..fb9875388f3f 100644
@@ -24,6 +24,7 @@
 #define DEVFREQ_GOV_INTERVAL			0x3
 #define DEVFREQ_GOV_SUSPEND			0x4
 #define DEVFREQ_GOV_RESUME			0x5
+#define DEVFREQ_GOV_WMARK			0x6
 
 /* Caution: devfreq->lock must be locked before calling update_devfreq */
 extern int update_devfreq(struct devfreq *devfreq);
include/linux/devfreq.h +26 -0
index f1863dcd83ea..b5bf6c4fe286 100644
@@ -21,6 +21,12 @@
 
 struct devfreq;
 
+enum watermark_type {
+	NO_WATERMARK_EVENT = 0,
+	HIGH_WATERMARK_EVENT = 1,
+	LOW_WATERMARK_EVENT = 2
+};
+
 /**
  * struct devfreq_dev_status - Data given from devfreq user device to
  *			     governors. Represents the performance
@@ -68,6 +74,16 @@ struct devfreq_dev_status {
  *			status to devfreq, which is used by governors.
  * @get_cur_freq:	The device should provide the current frequency
  *			at which it is operating.
+ * @set_high_wmark:	This is an optional callback to set high
+ *			watermark for watermark event. The value is
+ *			be scaled between 0 and 1000 where 1000 equals to
+ *			100% load. Setting this value to 1000 disables
+ *			the event
+ * @set_low_wmark:	This is an optional callback to set low
+ *			watermark for watermark event. The value is
+ *			be scaled between 0 and 1000 where 1000 equals to
+ *			100% load. Setting this value to 0 disables the
+ *			event.
  * @exit:		An optional callback that is called when devfreq
  *			is removing the devfreq object due to error or
  *			from devfreq_remove_device() call. If the user
@@ -84,6 +100,8 @@ struct devfreq_dev_profile {
 	int (*get_dev_status)(struct device *dev,
 			      struct devfreq_dev_status *stat);
 	int (*get_cur_freq)(struct device *dev, unsigned long *freq);
+	int (*set_high_wmark)(struct device *dev, unsigned int val);
+	int (*set_low_wmark)(struct device *dev, unsigned int val);
 	void (*exit)(struct device *dev);
 
 	unsigned int *freq_table;
@@ -191,6 +209,8 @@ extern void devm_devfreq_remove_device(struct device *dev,
 /* Supposed to be called by PM_SLEEP/PM_RUNTIME callbacks */
 extern int devfreq_suspend_device(struct devfreq *devfreq);
 extern int devfreq_resume_device(struct devfreq *devfreq);
+extern int devfreq_watermark_event(struct devfreq *devfreq,
+				  int type);
 
 /* Helper functions for devfreq user device driver with OPP. */
 extern struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
@@ -289,6 +309,12 @@ static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
 							struct devfreq *devfreq)
 {
 }
+
+static inline int devfreq_watermark_event(struct devfreq *devfreq,
+					int type)
+{
+	return 0;
+}
 #endif /* CONFIG_PM_DEVFREQ */
 
 #endif /* __LINUX_DEVFREQ_H__ */
Signature · 1 line
1.8.1.5
#2 lore raw

RFC 2/3 PM / devfreq: Add watermark simple governor

In reply to Arto Merilainen

From: Shridhar Rasal <[email protected]>

This patch adds a new devfreq governor, watermark simple. The governor decides next frequency naively by selecting the previous frequency in the frequency table if we received low watermark
- or the next frequency in case we received high watermark.

---
 drivers/devfreq/Kconfig                 |   7 +
 drivers/devfreq/Makefile                |   1 +
 drivers/devfreq/governor_wmark_simple.c | 245 ++++++++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/devfreq/governor_wmark_simple.c
drivers/devfreq/Kconfig +7 -0
index faf4e70c42e0..37710d999ffe 100644
@@ -63,6 +63,13 @@ config DEVFREQ_GOV_USERSPACE
 	  Otherwise, the governor does not change the frequnecy
 	  given at the initialization.
 
+config DEVFREQ_GOV_WMARK_SIMPLE
+	tristate "Simple Watermark"
+	help
+	  Sets the frequency based on monitor watermark events.
+	  This governor returns the next frequency from frequency table
+	  based on type watermark event.
+
 comment "DEVFREQ Drivers"
 
 config ARM_EXYNOS4_BUS_DEVFREQ
drivers/devfreq/Makefile +1 -0
index 16138c9e0d58..92024eeb73b6 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)	+= governor_simpleondemand.o
 obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE)	+= governor_performance.o
 obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE)	+= governor_powersave.o
 obj-$(CONFIG_DEVFREQ_GOV_USERSPACE)	+= governor_userspace.o
+obj-$(CONFIG_DEVFREQ_GOV_WMARK_SIMPLE)	+= governor_wmark_simple.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ)	+= exynos/
drivers/devfreq/governor_wmark_simple.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#3 lore raw

RFC 3/3 PM / devfreq: Add watermark active governor

In reply to Arto Merilainen

This patch adds a new watermark governor that actively alters the watermark values based on the current frequency and target load.

The governor takes target load as a given property (80% by default) and every time when the governor re-estimation is triggered, the governor checks the current load and calculates the next frequency that would push the device as close this target load as possible.

At this point also the watermark values are updated so that next time the interrupt should come when the load change is significant enough to cause frequency change to either next or previous frequency.

---
 drivers/devfreq/Kconfig                 |  11 ++
 drivers/devfreq/Makefile                |   1 +
 drivers/devfreq/governor_wmark_active.c | 276 ++++++++++++++++++++++++++++++++
 3 files changed, 288 insertions(+)
 create mode 100644 drivers/devfreq/governor_wmark_active.c
drivers/devfreq/Kconfig +11 -0
index 37710d999ffe..dc5b207e9c3b 100644
@@ -70,6 +70,17 @@ config DEVFREQ_GOV_WMARK_SIMPLE
 	  This governor returns the next frequency from frequency table
 	  based on type watermark event.
 
+config DEVFREQ_GOV_WMARK_ACTIVE
+	tristate "Active Watermark"
+	help
+	  Sets the frequency based on monitor watermark events.
+	  This governor calculates relation between current load and
+	  target load. The next frequency is calculated by multiplying
+	  this relation with the current frequency.
+
+	  The watermark values are updated so that the watermarks are
+	  triggered when the above algorithm would change the frequency.
+
 comment "DEVFREQ Drivers"
 
 config ARM_EXYNOS4_BUS_DEVFREQ
drivers/devfreq/Makefile +1 -0
index 92024eeb73b6..91e07aef3b29 100644
@@ -4,6 +4,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE)	+= governor_performance.o
 obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE)	+= governor_powersave.o
 obj-$(CONFIG_DEVFREQ_GOV_USERSPACE)	+= governor_userspace.o
 obj-$(CONFIG_DEVFREQ_GOV_WMARK_SIMPLE)	+= governor_wmark_simple.o
+obj-$(CONFIG_DEVFREQ_GOV_WMARK_ACTIVE)	+= governor_wmark_active.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ)	+= exynos/
drivers/devfreq/governor_wmark_active.c new file +276 -0

276 lines not on this page · raw message

Signature · 1 line
1.8.1.5