From patchwork Fri May 27 04:53:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MyungJoo Ham X-Patchwork-Id: 822912 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4R4t6Ju032687 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 27 May 2011 04:55:27 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p4R4rbZp019587; Thu, 26 May 2011 21:53:38 -0700 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p4R4rIg8019526 for ; Thu, 26 May 2011 21:53:23 -0700 Received: from epcpsbgm2.samsung.com (mailout3.samsung.com [203.254.224.33]) by mailout3.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LLU002W788S1HH0@mailout3.samsung.com> for linux-pm@lists.linux-foundation.org; Fri, 27 May 2011 13:53:16 +0900 (KST) X-AuditID: cbfee61b-b7c62ae0000056ed-e9-4ddf2e3c5ec7 Received: from epmmp1 ( [203.254.227.16]) by epcpsbgm2.samsung.com (MMPCPMTA) with SMTP id 71.25.22253.C3E2FDD4; Fri, 27 May 2011 13:53:16 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LLU000VB88SF8@mmp1.samsung.com> for linux-pm@lists.linux-foundation.org; Fri, 27 May 2011 13:53:16 +0900 (KST) Received: from localhost.localdomain ([165.213.219.116]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Fri, 27 May 2011 13:53:14 +0900 Date: Fri, 27 May 2011 13:53:14 +0900 From: MyungJoo Ham In-reply-to: <1306471995-4048-1-git-send-email-myungjoo.ham@samsung.com> To: linux-pm@lists.linux-foundation.org Message-id: <1306471995-4048-2-git-send-email-myungjoo.ham@samsung.com> X-Mailer: git-send-email 1.7.4.1 References: <1306471995-4048-1-git-send-email-myungjoo.ham@samsung.com> X-OriginalArrivalTime: 27 May 2011 04:53:14.0989 (UTC) FILETIME=[FCF281D0:01CC1C29] X-Brightmail-Tracker: AAAAAA== Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-12.127 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, SAMSUNG_WEBMAIL_OSDL X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: Len Brown , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Kyungmin Park , Thomas Gleixner Subject: [linux-pm] [PATCH v3 2/3] PM / DEVFREQ: add example governors X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 27 May 2011 04:55:27 +0000 (UTC) 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 Signed-off-by: Kyungmin Park --- 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 883d953..7648a94 100644 --- a/drivers/base/power/devfreq.c +++ b/drivers/base/power/devfreq.c @@ -395,3 +395,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 59c8bda..1ec9a40 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); 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,