From: MyungJoo Ham <myungjoo.ham@samsung.com>
To: linux-pm@lists.linux-foundation.org
Cc: linux-kernel@vger.kernel.org, "Rafael J. Wysocki" <rjw@sisk.pl>,
Greg Kroah-Hartman <gregkh@suse.de>,
Mark Brown <broonie@sirena.org.uk>,
Jiejing Zhang <kzjeef@gmail.com>, Pavel Machek <pavel@ucw.cz>,
Colin Cross <ccross@google.com>, Nishanth Menon <nm@ti.com>,
Thomas Gleixner <tglx@linutronix.de>,
Len Brown <len.brown@intel.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
myungjoo.ham@gmail.com
Subject: [PATCH v2 2/3] PM / DEVFREQ: add example governors
Date: Wed, 11 May 2011 16:58:42 +0900 [thread overview]
Message-ID: <1305100723-29161-2-git-send-email-myungjoo.ham@samsung.com> (raw)
In-Reply-To: <1305100723-29161-1-git-send-email-myungjoo.ham@samsung.com>
Three CPUFREQ-like governors are provided as examples.
powersave: use the lowest frequency possible. The user (device) should
set the polling_ms as 0 because polling is useless for this governor.
performance: use the highest freqeuncy possible. The user (device)
should set the polling_ms as 0 because polling is useless for this
governor.
simple_ondemand: simplified version of CPUFREQ's ONDEMAND governor.
When a user updates OPP entries (enable/disable/add), OPP framework
automatically notifies DEVFREQ to update operating frequency
accordingly. Thus, DEVFREQ users (device drivers) do not need to update
DEVFREQ manually with OPP entry updates or set polling_ms for powersave
, performance, or any other "static" governors.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
drivers/base/power/devfreq.c | 69 ++++++++++++++++++++++++++++++++++++++++++
include/linux/devfreq.h | 5 +++
2 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/drivers/base/power/devfreq.c b/drivers/base/power/devfreq.c
index 8e2e45b..251d761 100644
--- a/drivers/base/power/devfreq.c
+++ b/drivers/base/power/devfreq.c
@@ -351,3 +351,72 @@ static int __init devfreq_init(void)
return 0;
}
late_initcall(devfreq_init);
+
+static int devfreq_powersave_func(struct devfreq *df,
+ unsigned long *freq)
+{
+ *freq = 0; /* devfreq_do will run "ceiling" to 0 */
+ return 0;
+}
+
+struct devfreq_governor devfreq_powersave = {
+ .get_target_freq = devfreq_powersave_func,
+};
+
+static int devfreq_performance_func(struct devfreq *df,
+ unsigned long *freq)
+{
+ *freq = UINT_MAX; /* devfreq_do will run "floor" */
+ return 0;
+}
+
+struct devfreq_governor devfreq_performance = {
+ .get_target_freq = devfreq_performance_func,
+};
+
+/* Constants for DevFreq-Simple-Ondemand (DFSO) */
+#define DFSO_UPTHRESHOLD (90)
+#define DFSO_DOWNDIFFERENCTIAL (5)
+static int devfreq_simple_ondemand_func(struct devfreq *df,
+ unsigned long *freq)
+{
+ struct devfreq_dev_status stat;
+ int err = df->profile->get_dev_status(df->dev, &stat);
+ unsigned long long a, b;
+
+ if (err)
+ return err;
+
+ /* Set MAX if it's busy enough */
+ if (stat.busy_time * 100 >
+ stat.total_time * DFSO_UPTHRESHOLD) {
+ *freq = UINT_MAX;
+ return 0;
+ }
+
+ /* Set MAX if we do not know the initial frequency */
+ if (stat.current_frequency == 0) {
+ *freq = UINT_MAX;
+ return 0;
+ }
+
+ /* Keep the current frequency */
+ if (stat.busy_time * 100 >
+ stat.total_time * (DFSO_UPTHRESHOLD - DFSO_DOWNDIFFERENCTIAL)) {
+ *freq = stat.current_frequency;
+ return 0;
+ }
+
+ /* Set the desired frequency based on the load */
+ a = (unsigned long long) stat.busy_time * stat.current_frequency;
+ b = div_u64(a, stat.total_time);
+ b *= 100;
+ b = div_u64(b, (DFSO_UPTHRESHOLD - DFSO_DOWNDIFFERENCTIAL / 2));
+ *freq = (unsigned long) b;
+
+ return 0;
+}
+
+struct devfreq_governor devfreq_simple_ondemand = {
+ .get_target_freq = devfreq_simple_ondemand_func,
+};
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index d08e9f5..ec41ba6 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -81,6 +81,11 @@ extern int devfreq_add_device(struct device *dev,
extern int devfreq_remove_device(struct device *dev);
extern int devfreq_update(struct device *dev, bool may_not_exist);
extern int devfreq_tickle_device(struct device *dev, unsigned long duration_ms);
+
+extern struct devfreq_governor devfreq_powersave;
+extern struct devfreq_governor devfreq_performance;
+extern struct devfreq_governor devfreq_simple_ondemand;
+
#else /* !CONFIG_PM_DEVFREQ */
static int devfreq_add_device(struct device *dev,
struct devfreq_dev_profile *profile,
--
1.7.4.1
next prev parent reply other threads:[~2011-05-11 16:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-11 7:58 [PATCH v2 1/3] PM: Introduce DEVFREQ: generic DVFS framework with device-specific OPPs MyungJoo Ham
2011-05-11 7:58 ` MyungJoo Ham [this message]
2011-05-17 22:39 ` [PATCH v2 2/3] PM / DEVFREQ: add example governors Rafael J. Wysocki
2011-05-18 0:48 ` MyungJoo Ham
2011-05-18 19:46 ` Rafael J. Wysocki
2011-05-27 4:42 ` MyungJoo Ham
2011-05-11 7:58 ` [PATCH v2 3/3] PM / DEVFREQ: add sysfs interface (including user tickling) MyungJoo Ham
2011-05-11 22:55 ` Greg KH
2011-05-17 5:04 ` MyungJoo Ham
2011-05-17 18:32 ` Greg KH
2011-05-17 22:41 ` Rafael J. Wysocki
2011-05-18 0:43 ` MyungJoo Ham
2011-05-17 22:36 ` [PATCH v2 1/3] PM: Introduce DEVFREQ: generic DVFS framework with device-specific OPPs Rafael J. Wysocki
2011-05-18 8:22 ` MyungJoo Ham
2011-05-18 20:02 ` Rafael J. Wysocki
2011-05-18 20:21 ` Pavel Machek
2011-05-18 20:29 ` Rafael J. Wysocki
2011-05-20 5:36 ` MyungJoo Ham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1305100723-29161-2-git-send-email-myungjoo.ham@samsung.com \
--to=myungjoo.ham@samsung.com \
--cc=broonie@sirena.org.uk \
--cc=ccross@google.com \
--cc=gregkh@suse.de \
--cc=kyungmin.park@samsung.com \
--cc=kzjeef@gmail.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=myungjoo.ham@gmail.com \
--cc=nm@ti.com \
--cc=pavel@ucw.cz \
--cc=rjw@sisk.pl \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®