Linux Power Management development
 help / color / mirror / Atom feed
* Re: [PATCH] input: CPU frequency booster
From: Thomas Renninger @ 2012-01-19 22:52 UTC (permalink / raw)
  To: Antti P Miettinen
  Cc: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326977615-4387-1-git-send-email-amiettinen@nvidia.com>

Hi,

Not sure which email I should take to answer...

I can't see why pm_qos is needed at all, better use cpufreq
providing interface.
PPC (BIOS request to cut max_frequency) in
drivers/acpi/processor_perflib.c is a nice example

I'd also put this into drivers/cpufreq/cpufreq_input_boost.c.

Find below a re-written version of the booster.
Instead of pm_qos, it simply uses cpufreq interface:
/sys/devices/system/cpu/cpufreq/input_boost_freq
/sys/devices/system/cpu/cpufreq/input_boost_time

I started with global cpufreq variables, they could also
be declared per cpu like scaling_min_freq or others
(at least input_boost_freq, input_boost_time should probably
stay global). That would be:
/sys/devices/system/cpu/cpuX/cpufreq/input_boost_freq

A mechanism to set the right variables on the right HW
so that no userspace interaction is needed by default would be great.
Is there a PCI id, CPU family/model that could get checked
in the init func and automatically set the right values?

Now that this is part of cpufreq core, one could use these:
/* the following 3 funtions are for cpufreq core use only */                                                                                                          
struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);                                                                                        
struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);                                                                                                             
void   cpufreq_cpu_put(struct cpufreq_policy *data);                                                                                                                  

to find the 2nd lowest P-state or similar as default boost freq

A comment on which platforms this makes sense at all would be great.
Does any X86 machine need this?
Which ARM platforms you'd recommend to enable this in .config?

Could you give below a test, please.
Compile tested only.
Based on latest Linus git tree.
What do you think about it?

    Thomas

---
 drivers/cpufreq/Kconfig               |    9 ++
 drivers/cpufreq/Makefile              |    3 +
 drivers/cpufreq/cpufreq_input_boost.c |  238 +++++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+), 0 deletions(-)

diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index e24a2a1..3f584d6 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -179,6 +179,15 @@ config CPU_FREQ_GOV_CONSERVATIVE
 
 	  If in doubt, say N.
 
+config INPUT_CFBOOST
+       boolean "CPU frequency booster"
+       depends on INPUT
+       help
+         Say Y here if you want to boost frequency upon input events;
+
+         To compile this driver as a module, choose M here: the
+         module will be called input-cfboost.
+
 menu "x86 CPU frequency scaling drivers"
 depends on X86
 source "drivers/cpufreq/Kconfig.x86"
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index ac000fa..d083b9f 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -10,6 +10,9 @@ obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE)	+= cpufreq_userspace.o
 obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND)	+= cpufreq_ondemand.o
 obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE)	+= cpufreq_conservative.o
 
+# CPUfreq misc
+obj-$(CONFIG_INPUT_CFBOOST)		+= cpufreq_input_boost.o
+
 # CPUfreq cross-arch helpers
 obj-$(CONFIG_CPU_FREQ_TABLE)		+= freq_table.o
 
diff --git a/drivers/cpufreq/cpufreq_input_boost.c b/drivers/cpufreq/cpufreq_input_boost.c
new file mode 100644
index 0000000..3ef8bca
--- /dev/null
+++ b/drivers/cpufreq/cpufreq_input_boost.c
@@ -0,0 +1,238 @@
+/*
+ * drivers/input/input-cfboost.c
+ *
+ * Copyright (C) 2012 NVIDIA Corporation
+ * Copyright (C) 2012 Thomas Renninger <trenn@suse.de>
+ *     Better integration into cpufreq subsystem
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/printk.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/cpufreq.h>
+
+/* This module listens to input events and sets a temporary frequency
+ * floor upon input event detection. This is based on changes to
+ * cpufreq ondemand governor by:
+ *
+ * Tero Kristo <tero.kristo@nokia.com>
+ * Brian Steuer <bsteuer@codeaurora.org>
+ * David Ng <dave@codeaurora.org>
+ *
+ * at git://codeaurora.org/kernel/msm.git tree, commits:
+ *
+ * 2a6181bc76c6ce46ca0fa8e547be42acd534cf0e
+ * 1cca8861d8fda4e05f6b0c59c60003345c15454d
+ * 96a9aeb02bf5b3fbbef47e44460750eb275e9f1b
+ * b600449501cf15928440f87eff86b1f32d14214e
+ * 88a65c7ae04632ffee11f9fc628d7ab017c06b83
+ */
+
+MODULE_AUTHOR("Antti P Miettinen <amiettinen@nvidia.com>");
+MODULE_DESCRIPTION("Input event CPU frequency booster");
+MODULE_LICENSE("GPL v2");
+
+
+static struct work_struct boost;
+static struct delayed_work unboost;
+static struct workqueue_struct *cfb_wq;
+
+/* sysfs stuff **************************/
+static unsigned long boost_time;
+static unsigned int boost_freq = 500;
+
+static ssize_t show_input_boost_time (struct kobject *kobj,
+				      struct attribute *attr, char *buf)
+{
+	return sprintf(buf, "%lu\n", boost_time);
+}
+static ssize_t show_input_boost_freq (struct kobject *kobj,
+				      struct attribute *attr, char *buf)
+{
+	return sprintf(buf, "%u\n", boost_freq);
+}
+
+static ssize_t store_input_boost_time(struct kobject *a, struct attribute *b,
+				const char *buf, size_t count)
+{
+	/* TBD: Check input! */
+	int ret;
+	ret = sscanf(buf, "%lu", &boost_time);
+	if (ret != 1)
+		return -EINVAL;
+	return count;
+}
+
+static ssize_t store_input_boost_freq(struct kobject *a, struct attribute *b,
+				const char *buf, size_t count)
+{
+	/* TBD: Check input! */
+	int ret;
+	ret = sscanf(buf, "%u", &boost_freq);
+	if (ret != 1)
+		return -EINVAL;
+	return count;
+}
+define_one_global_rw(input_boost_freq);
+define_one_global_rw(input_boost_time);
+
+static const struct attribute *input_boost_attr[] = {
+	&input_boost_freq.attr,
+	&input_boost_time.attr,
+};
+
+/* sysfs stuff **************************/
+
+
+static void cfb_boost(struct work_struct *w)
+{
+	struct cpufreq_policy policy;
+	int ret;
+
+	cancel_delayed_work_sync(&unboost);
+	ret = cpufreq_get_policy(&policy, 0);
+	if (ret)
+		return;
+	cpufreq_verify_within_limits(&policy, boost_freq,
+				     policy.cpuinfo.max_freq);
+	queue_delayed_work(cfb_wq, &unboost,
+			   msecs_to_jiffies(boost_time));
+}
+
+static void cfb_unboost(struct work_struct *w)
+{
+	struct cpufreq_policy policy;
+	int ret;
+	
+	ret = cpufreq_get_policy(&policy, 0);
+	if (ret)
+		return;
+
+	cpufreq_verify_within_limits(&policy, policy.cpuinfo.min_freq,
+				     policy.cpuinfo.max_freq);
+}
+
+static void cfb_input_event(struct input_handle *handle, unsigned int type,
+			    unsigned int code, int value)
+{
+	if (!work_pending(&boost))
+		queue_work(cfb_wq, &boost);
+}
+
+static int cfb_input_connect(struct input_handler *handler,
+			     struct input_dev *dev,
+			     const struct input_device_id *id)
+{
+	struct input_handle *handle;
+	int error;
+
+	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
+	if (!handle)
+		return -ENOMEM;
+
+	handle->dev = dev;
+	handle->handler = handler;
+	handle->name = "icfboost";
+
+	error = input_register_handle(handle);
+	if (error)
+		goto err2;
+
+	error = input_open_device(handle);
+	if (error)
+		goto err1;
+
+	return 0;
+err1:
+	input_unregister_handle(handle);
+err2:
+	kfree(handle);
+	return error;
+}
+
+static void cfb_input_disconnect(struct input_handle *handle)
+{
+	input_close_device(handle);
+	input_unregister_handle(handle);
+	kfree(handle);
+}
+
+static const struct input_device_id cfb_ids[] = {
+	{ /* touch screen */
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
+		INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT_MASK(EV_ABS) },
+		.keybit = {[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
+	},
+	{ /* mouse */
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
+		INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT_MASK(EV_REL) },
+		.keybit = {[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MOUSE) },
+	},
+	{ },
+};
+
+static struct input_handler cfb_input_handler = {
+	.event          = cfb_input_event,
+	.connect        = cfb_input_connect,
+	.disconnect     = cfb_input_disconnect,
+	.name           = "icfboost",
+	.id_table       = cfb_ids,
+};
+
+static int __init cfboost_init(void)
+{
+	/* TBD: Properly clean up in all cases */
+	int ret;
+
+	ret = sysfs_create_files(cpufreq_global_kobject,
+				 input_boost_attr);
+
+	cfb_wq = create_workqueue("icfb-wq");
+	if (!cfb_wq)
+		return -ENOMEM;
+	INIT_WORK(&boost, cfb_boost);
+	INIT_DELAYED_WORK(&unboost, cfb_unboost);
+	ret = input_register_handler(&cfb_input_handler);
+	if (ret) {
+		destroy_workqueue(cfb_wq);
+		return ret;
+	}
+	return 0;
+}
+
+static void __exit cfboost_exit(void)
+{
+	sysfs_remove_files(cpufreq_global_kobject,
+			   input_boost_attr);
+
+	/* stop input events */
+	input_unregister_handler(&cfb_input_handler);
+	/* cancel pending work requests */
+	cancel_work_sync(&boost);
+	cancel_delayed_work_sync(&unboost);
+	/* clean up */
+	destroy_workqueue(cfb_wq);
+}
+
+module_init(cfboost_init);
+module_exit(cfboost_exit);

^ permalink raw reply related

* Re: [linux-pm] [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Rafael J. Wysocki @ 2012-01-19 22:40 UTC (permalink / raw)
  To: Antti P Miettinen; +Cc: linux-pm, cpufreq, markgross
In-Reply-To: <871uqwqja2.fsf@amiettinen-lnx.nvidia.com>

On Thursday, January 19, 2012, Antti P Miettinen wrote:
> "Rafael J. Wysocki" <rjw@sisk.pl> writes:
> [..]
> > Perhaps we need a new cpufreq governor that would take use PM QoS internally
> > to store requests from different sources, but that would work on a per-CPU
> > basis (not globally) and would provide a new interface for user space?
> >
> > Rafael
> 
> I think it would be nice if the choice of governor could be independent
> of the constraints. Also, implementing the constraints in the cpufreq
> core is easier than in governors.

Well, while it might be easier, the _whole_ _point_ of governors is to make
decisions on the basis of available data.  By introducing an independent
mechanism for that we're bypassing governors in a sense.

Thanks,
Rafael

^ permalink raw reply

* Re: [linux-pm] [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Rafael J. Wysocki @ 2012-01-19 22:15 UTC (permalink / raw)
  To: linux-pm; +Cc: Antti P Miettinen, cpufreq
In-Reply-To: <87y5t35v96.fsf@amiettinen-lnx.nvidia.com>

On Thursday, January 19, 2012, Antti P Miettinen wrote:
> mark gross <markgross@thegnar.org> writes:
> > Hmm, your right this patch set is global in its request and not
> > "per-cpu".  I need to think on that.  Making it per-cpu would likely
> > infer we need to make the qos request per cpu as well.  
> 
> I think we need both, global and per cpu.

Well, if we have that per CPU, it will be easy to create a global
setting: set all of the per-CPU settings to the same values. :-)

Thanks,
Rafael

^ permalink raw reply

* Re: [PATCH] MAINTAINERS: Fix linux-pm address
From: Rafael J. Wysocki @ 2012-01-19 21:56 UTC (permalink / raw)
  To: Alan Stern
  Cc: linux-pm, Antti P Miettinen, Srivatsa S. Bhat,
	Linux PM mailing list
In-Reply-To: <Pine.LNX.4.44L0.1201191023510.1447-100000@iolanthe.rowland.org>

On Thursday, January 19, 2012, Alan Stern wrote:
> On Thu, 19 Jan 2012, Srivatsa S. Bhat wrote:
> 
> > On 01/19/2012 06:48 PM, Antti P Miettinen wrote:
> > 
> > > Current linux-pm mailing list address seems to be
> > > linux-pm@lists.linux-foundation.org.
> > > 
> > 
> > 
> > Actually now both the mailing list addresses work.
> 
> The lists.linux-foundation.org address was linux-pm's original home.  
> The vger.kernel.org addresss was created when the Linux Foundation's
> listserv went down last summer; it is now regarded as linux-pm's
> primary address even though both addresses are working.
> 
> See commit bf1c138e350155edb06709c7fbf0946f252b257c (MAINTAINERS:
> Update linux-pm list address).

That's correct.

Thanks,
Rafael

^ permalink raw reply

* Re: [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Antti P Miettinen @ 2012-01-19 19:48 UTC (permalink / raw)
  To: linux-pm; +Cc: cpufreq
In-Reply-To: <20120119164144.GA8757@mgross-G62>

mark gross <markgross@thegnar.org> writes:
> Hmm, your right this patch set is global in its request and not
> "per-cpu".  I need to think on that.  Making it per-cpu would likely
> infer we need to make the qos request per cpu as well.  

I think we need both, global and per cpu.

	--Antti

^ permalink raw reply

* Re: [PATCH] input: CPU frequency booster
From: Pavel Machek @ 2012-01-19 17:44 UTC (permalink / raw)
  To: Antti P Miettinen
  Cc: khilman, len.brown, markgross, cpufreq, linux-pm, j-pihet
In-Reply-To: <1326977615-4387-1-git-send-email-amiettinen@nvidia.com>

Hi!

> +/* XXX make configurable */

Remove XXX?


> +static const struct input_device_id cfb_ids[] = {
> +	{ /* touch screen */
> +		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
> +				INPUT_DEVICE_ID_MATCH_KEYBIT,
> +		.evbit = { BIT_MASK(EV_ABS) },
> +		.keybit = {[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
> +	},
> +	{ /* mouse */
> +		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
> +				INPUT_DEVICE_ID_MATCH_KEYBIT,
> +		.evbit = { BIT_MASK(EV_REL) },
> +		.keybit = {[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MOUSE) },
> +	},
> +	{ },
> +};

Does it need to be configurable? Going to max frequency for user
interaction sounds like good idea... Probably should include keyboard,
too.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply

* Re: [linux-pm] [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: mark gross @ 2012-01-19 16:41 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: markgross, linux-pm, Antti P Miettinen, cpufreq
In-Reply-To: <201201190024.27022.rjw@sisk.pl>

On Thu, Jan 19, 2012 at 12:24:26AM +0100, Rafael J. Wysocki wrote:
> On Wednesday, January 18, 2012, mark gross wrote:
> > On Mon, Jan 16, 2012 at 10:38:57PM +0100, Rafael J. Wysocki wrote:
> > > Hi,
> > > 
> > > On Monday, January 16, 2012, Antti P Miettinen wrote:
> > > > [did not reach linux-pm as I sent to wrong address, sorry for
> > > > duplicates]
> > > > 
> > > > The inspiration for this patch series is the N9 CPU frequency boost
> > > > upon input events:
> > > > 
> > > > http://www.spinics.net/lists/cpufreq/msg00667.html
> > > > 
> > > > and the related changes in git://codeaurora.org/kernel/msm.git tree.
> > > > Those patches modify the ondemand cpufreq governor. This patch series
> > > > adds minimum and maximum CPU frequency as PM QoS parameters and
> > > > modifies the cpufreq core to enforce the PM QoS limits.
> > > 
> > > If that hasn't been clear enough so far, I'm still not convinced that using
> > > PM QoS for that is a good idea.
> > > 
> > > First off, frequency as a unit of throughput is questionable to say the least,
> > > because it isn't portable from one system to another.  Moreover, even on a
> > > given system it isn't particularly clear what the exact correspondence
> > > between frequency and throughput actually is.
> > 
> > You are right.  The notion of throughput of a CPU is really hard to
> > quantify.  Perhaps not using the term "throughput" would help?
> 
> Yes, it would.
> 
> > The base issue I see, the Intel platform, is needing is that sometimes
> > we need to block the lowest P-states that the ondemand governor goes for
> > because those P-states result in media / graphics workloads dropping
> > frames.  However; GPU intensive workloads do not stress the CPU so the
> > ondemand governor goes for the low p-state.
> > 
> > I could use some way of constraining the PM-throttling of the
> > cpu-freq that can be hit from kernel or user mode.  So the graphics
> > driver can dynamically adjust the constraint request on the cpufreq
> > subsystem.
> > 
> > It is problematic that any driver requesting a given frequency request
> > is not portable across ISA's or even processor families in the same ISA.
> > But, maybe such a driver should use a module parameter to work around
> > this lack of portability?
> 
> Well, it seems to me that we're trying to add a backdoor to the (apparently
> inadequate) governors here.  Arguably, the governors should be able to
> make the right decisions on the basis of the information they receive
> through their own interfaces.

the failings of governors to have the information needed is why pm_qos
was created in the first place.  It can be seen as a limitation on the
governor from some perspectives.  But, I like to think of if as updating
existing governors to account for new use case requirements as hardware
get bigger power management / performance dynamic ranges.


> > > Second, it's not particularly clear what the meaning of the "min" frequency
> > > is supposed to be in terms of throughput.
> > 
> > It should mean "please cpufreq do not put the cpu into a state where its
> > clock runs slower than min".  I don't think we should talk about it as
> > throughput because thats not what the cpufreq controls.
> 
> Perhaps we need a new cpufreq governor that would take use PM QoS internally
> to store requests from different sources, but that would work on a per-CPU
> basis (not globally) and would provide a new interface for user space?
> 

I don' think we need a new cpufreq governor, the parts of this patchset
that I agree with evolve the governor to account for pm-qos requests
but, globally for all cpu's.

Hmm, your right this patch set is global in its request and not
"per-cpu".  I need to think on that.  Making it per-cpu would likely
infer we need to make the qos request per cpu as well.  

Do you think it needs to be per-cpu?  (I'm starting to think "yes" it
does)

How do we scale the pm_qos ABI to support per/cpu?  (maybe we don't
export those types of qos classes to the user mode?)

--mark


^ permalink raw reply

* Re: [PATCH] MAINTAINERS: Fix linux-pm address
From: Alan Stern @ 2012-01-19 15:30 UTC (permalink / raw)
  To: Antti P Miettinen; +Cc: linux-pm, Srivatsa S. Bhat, Linux PM mailing list
In-Reply-To: <4F181B5F.70100@linux.vnet.ibm.com>

On Thu, 19 Jan 2012, Srivatsa S. Bhat wrote:

> On 01/19/2012 06:48 PM, Antti P Miettinen wrote:
> 
> > Current linux-pm mailing list address seems to be
> > linux-pm@lists.linux-foundation.org.
> > 
> 
> 
> Actually now both the mailing list addresses work.

The lists.linux-foundation.org address was linux-pm's original home.  
The vger.kernel.org addresss was created when the Linux Foundation's
listserv went down last summer; it is now regarded as linux-pm's
primary address even though both addresses are working.

See commit bf1c138e350155edb06709c7fbf0946f252b257c (MAINTAINERS:
Update linux-pm list address).

Alan Stern

^ permalink raw reply

* Re: [PATCH] MAINTAINERS: Fix linux-pm address
From: Srivatsa S. Bhat @ 2012-01-19 13:32 UTC (permalink / raw)
  To: Antti P Miettinen; +Cc: linux-pm, Linux PM mailing list
In-Reply-To: <1326979082-4485-1-git-send-email-amiettinen@nvidia.com>

On 01/19/2012 06:48 PM, Antti P Miettinen wrote:

> Current linux-pm mailing list address seems to be
> linux-pm@lists.linux-foundation.org.
> 


Actually now both the mailing list addresses work.

Regards,
Srivatsa S. Bhat

> Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
> ---
>  MAINTAINERS |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 56818fe..6038cb8 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2805,7 +2805,7 @@ F:	fs/freevxfs/
>  FREEZER
>  M:	Pavel Machek <pavel@ucw.cz>
>  M:	"Rafael J. Wysocki" <rjw@sisk.pl>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  S:	Supported
>  F:	Documentation/power/freezing-of-tasks.txt
>  F:	include/linux/freezer.h
> @@ -3083,7 +3083,7 @@ F:	drivers/video/hgafb.c
>  HIBERNATION (aka Software Suspend, aka swsusp)
>  M:	Pavel Machek <pavel@ucw.cz>
>  M:	"Rafael J. Wysocki" <rjw@sisk.pl>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  S:	Supported
>  F:	arch/x86/power/
>  F:	drivers/base/power/
> @@ -3296,7 +3296,7 @@ F:	drivers/ide/ide-cd*
> 
>  IDLE-I7300
>  M:	Andy Henroid <andrew.d.henroid@intel.com>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  S:	Supported
>  F:	drivers/idle/i7300_idle.c
> 
> @@ -3379,7 +3379,7 @@ F:	firmware/isci/
> 
>  INTEL IDLE DRIVER
>  M:	Len Brown <lenb@kernel.org>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-idle-2.6.git
>  S:	Supported
>  F:	drivers/idle/intel_idle.c
> @@ -3476,7 +3476,7 @@ F:	drivers/net/ethernet/intel/
> 
>  INTEL MRST PMU DRIVER
>  M:	Len Brown <len.brown@intel.com>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  S:	Supported
>  F:	arch/x86/platform/mrst/pmu.*
> 
> @@ -6469,7 +6469,7 @@ SUSPEND TO RAM
>  M:	Len Brown <len.brown@intel.com>
>  M:	Pavel Machek <pavel@ucw.cz>
>  M:	"Rafael J. Wysocki" <rjw@sisk.pl>
> -L:	linux-pm@vger.kernel.org
> +L:	linux-pm@lists.linux-foundation.org
>  S:	Supported
>  F:	Documentation/power/
>  F:	arch/x86/kernel/acpi/

^ permalink raw reply

* [PATCH] MAINTAINERS: Fix linux-pm address
From: Antti P Miettinen @ 2012-01-19 13:18 UTC (permalink / raw)
  To: linux-pm

Current linux-pm mailing list address seems to be
linux-pm@lists.linux-foundation.org.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
 MAINTAINERS |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 56818fe..6038cb8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2805,7 +2805,7 @@ F:	fs/freevxfs/
 FREEZER
 M:	Pavel Machek <pavel@ucw.cz>
 M:	"Rafael J. Wysocki" <rjw@sisk.pl>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 S:	Supported
 F:	Documentation/power/freezing-of-tasks.txt
 F:	include/linux/freezer.h
@@ -3083,7 +3083,7 @@ F:	drivers/video/hgafb.c
 HIBERNATION (aka Software Suspend, aka swsusp)
 M:	Pavel Machek <pavel@ucw.cz>
 M:	"Rafael J. Wysocki" <rjw@sisk.pl>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 S:	Supported
 F:	arch/x86/power/
 F:	drivers/base/power/
@@ -3296,7 +3296,7 @@ F:	drivers/ide/ide-cd*
 
 IDLE-I7300
 M:	Andy Henroid <andrew.d.henroid@intel.com>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 S:	Supported
 F:	drivers/idle/i7300_idle.c
 
@@ -3379,7 +3379,7 @@ F:	firmware/isci/
 
 INTEL IDLE DRIVER
 M:	Len Brown <lenb@kernel.org>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-idle-2.6.git
 S:	Supported
 F:	drivers/idle/intel_idle.c
@@ -3476,7 +3476,7 @@ F:	drivers/net/ethernet/intel/
 
 INTEL MRST PMU DRIVER
 M:	Len Brown <len.brown@intel.com>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 S:	Supported
 F:	arch/x86/platform/mrst/pmu.*
 
@@ -6469,7 +6469,7 @@ SUSPEND TO RAM
 M:	Len Brown <len.brown@intel.com>
 M:	Pavel Machek <pavel@ucw.cz>
 M:	"Rafael J. Wysocki" <rjw@sisk.pl>
-L:	linux-pm@vger.kernel.org
+L:	linux-pm@lists.linux-foundation.org
 S:	Supported
 F:	Documentation/power/
 F:	arch/x86/kernel/acpi/
-- 
1.7.4.1

^ permalink raw reply related

* [PATCH] input: CPU frequency booster
From: Antti P Miettinen @ 2012-01-19 12:53 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm

Inspired by cpufreq ondemand governor changes at
git://codeaurora.org/kernel/msm.git tree in commits:

    2a6181bc76c6ce46ca0fa8e547be42acd534cf0e
    1cca8861d8fda4e05f6b0c59c60003345c15454d
    96a9aeb02bf5b3fbbef47e44460750eb275e9f1b
    b600449501cf15928440f87eff86b1f32d14214e
    88a65c7ae04632ffee11f9fc628d7ab017c06b83

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
Depends on "RFC: CPU frequency min as PM QoS param" patchset.
An example - the input filtering needs some thinking.

 drivers/input/Kconfig         |    9 ++
 drivers/input/Makefile        |    1 +
 drivers/input/input-cfboost.c |  174 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/input-cfboost.c

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 001b147..3859f78 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -161,6 +161,15 @@ config INPUT_APMPOWER
 	  To compile this driver as a module, choose M here: the
 	  module will be called apm-power.
 
+config INPUT_CFBOOST
+	tristate "CPU frequency booster"
+	depends on INPUT && CPU_FREQ
+	help
+	  Say Y here if you want to boost frequency upon input events;
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called input-cfboost.
+
 comment "Input Device Drivers"
 
 source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 0c78949..6cad177 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN)	+= touchscreen/
 obj-$(CONFIG_INPUT_MISC)	+= misc/
 
 obj-$(CONFIG_INPUT_APMPOWER)	+= apm-power.o
+obj-$(CONFIG_INPUT_CFBOOST)	+= input-cfboost.o
diff --git a/drivers/input/input-cfboost.c b/drivers/input/input-cfboost.c
new file mode 100644
index 0000000..bef3ec5
--- /dev/null
+++ b/drivers/input/input-cfboost.c
@@ -0,0 +1,174 @@
+/*
+ * drivers/input/input-cfboost.c
+ *
+ * Copyright (C) 2012 NVIDIA Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/printk.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/pm_qos.h>
+
+/* This module listens to input events and sets a temporary frequency
+ * floor upon input event detection. This is based on changes to
+ * cpufreq ondemand governor by:
+ *
+ * Tero Kristo <tero.kristo@nokia.com>
+ * Brian Steuer <bsteuer@codeaurora.org>
+ * David Ng <dave@codeaurora.org>
+ *
+ * at git://codeaurora.org/kernel/msm.git tree, commits:
+ *
+ * 2a6181bc76c6ce46ca0fa8e547be42acd534cf0e
+ * 1cca8861d8fda4e05f6b0c59c60003345c15454d
+ * 96a9aeb02bf5b3fbbef47e44460750eb275e9f1b
+ * b600449501cf15928440f87eff86b1f32d14214e
+ * 88a65c7ae04632ffee11f9fc628d7ab017c06b83
+ */
+
+MODULE_AUTHOR("Antti P Miettinen <amiettinen@nvidia.com>");
+MODULE_DESCRIPTION("Input event CPU frequency booster");
+MODULE_LICENSE("GPL v2");
+
+
+static struct pm_qos_request qos_req;
+static struct work_struct boost;
+static struct delayed_work unboost;
+static unsigned int boost_freq; /* kHz */
+module_param(boost_freq, uint, 0644);
+static unsigned long boost_time = 500; /* ms */
+module_param(boost_time, ulong, 0644);
+static struct workqueue_struct *cfb_wq;
+
+static void cfb_boost(struct work_struct *w)
+{
+	cancel_delayed_work_sync(&unboost);
+	pm_qos_update_request(&qos_req, boost_freq);
+	queue_delayed_work(cfb_wq, &unboost, msecs_to_jiffies(boost_time));
+}
+
+static void cfb_unboost(struct work_struct *w)
+{
+	pm_qos_update_request(&qos_req, PM_QOS_DEFAULT_VALUE);
+}
+
+static void cfb_input_event(struct input_handle *handle, unsigned int type,
+			    unsigned int code, int value)
+{
+	if (!work_pending(&boost))
+		queue_work(cfb_wq, &boost);
+}
+
+static int cfb_input_connect(struct input_handler *handler,
+			     struct input_dev *dev,
+			     const struct input_device_id *id)
+{
+	struct input_handle *handle;
+	int error;
+
+	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
+	if (!handle)
+		return -ENOMEM;
+
+	handle->dev = dev;
+	handle->handler = handler;
+	handle->name = "icfboost";
+
+	error = input_register_handle(handle);
+	if (error)
+		goto err2;
+
+	error = input_open_device(handle);
+	if (error)
+		goto err1;
+
+	return 0;
+err1:
+	input_unregister_handle(handle);
+err2:
+	kfree(handle);
+	return error;
+}
+
+static void cfb_input_disconnect(struct input_handle *handle)
+{
+	input_close_device(handle);
+	input_unregister_handle(handle);
+	kfree(handle);
+}
+
+/* XXX make configurable */
+static const struct input_device_id cfb_ids[] = {
+	{ /* touch screen */
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
+				INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT_MASK(EV_ABS) },
+		.keybit = {[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
+	},
+	{ /* mouse */
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT |
+				INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT_MASK(EV_REL) },
+		.keybit = {[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MOUSE) },
+	},
+	{ },
+};
+
+static struct input_handler cfb_input_handler = {
+	.event		= cfb_input_event,
+	.connect	= cfb_input_connect,
+	.disconnect	= cfb_input_disconnect,
+	.name		= "icfboost",
+	.id_table	= cfb_ids,
+};
+
+static int __init cfboost_init(void)
+{
+	int ret;
+
+	cfb_wq = create_workqueue("icfb-wq");
+	if (!cfb_wq)
+		return -ENOMEM;
+	INIT_WORK(&boost, cfb_boost);
+	INIT_DELAYED_WORK(&unboost, cfb_unboost);
+	ret = input_register_handler(&cfb_input_handler);
+	if (ret) {
+		destroy_workqueue(cfb_wq);
+		return ret;
+	}
+	pm_qos_add_request(&qos_req, PM_QOS_CPU_FREQ_MIN,
+			   PM_QOS_DEFAULT_VALUE);
+	return 0;
+}
+
+static void __exit cfboost_exit(void)
+{
+	/* stop input events */
+	input_unregister_handler(&cfb_input_handler);
+	/* cancel pending work requests */
+	cancel_work_sync(&boost);
+	cancel_delayed_work_sync(&unboost);
+	/* clean up */
+	destroy_workqueue(cfb_wq);
+	pm_qos_remove_request(&qos_req);
+}
+
+module_init(cfboost_init);
+module_exit(cfboost_exit);
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH] cpufreq: Export user_policy min/max
From: Antti P Miettinen @ 2012-01-19 12:51 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm

Add read-only sysfs nodes for user_policy min and max settings.
This helps diagnosis in the presence of other constraints that
affect the currently enforced policy minimum and maximum that
can be viewed with scaling_{min,max}_freq.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
Related to "RFC: CPU frequency min as PM QoS param" patchset.

 drivers/cpufreq/cpufreq.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f2c7fc2..c2c1c62 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -364,6 +364,8 @@ show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
 show_one(scaling_min_freq, min);
 show_one(scaling_max_freq, max);
 show_one(scaling_cur_freq, cur);
+show_one(policy_min_freq, user_policy.min);
+show_one(policy_max_freq, user_policy.max);
 
 static int __cpufreq_set_policy(struct cpufreq_policy *data,
 				struct cpufreq_policy *policy);
@@ -582,6 +584,8 @@ cpufreq_freq_attr_rw(scaling_min_freq);
 cpufreq_freq_attr_rw(scaling_max_freq);
 cpufreq_freq_attr_rw(scaling_governor);
 cpufreq_freq_attr_rw(scaling_setspeed);
+cpufreq_freq_attr_ro(policy_min_freq);
+cpufreq_freq_attr_ro(policy_max_freq);
 
 static struct attribute *default_attrs[] = {
 	&cpuinfo_min_freq.attr,
@@ -595,6 +599,8 @@ static struct attribute *default_attrs[] = {
 	&scaling_driver.attr,
 	&scaling_available_governors.attr,
 	&scaling_setspeed.attr,
+	&policy_min_freq.attr,
+	&policy_max_freq.attr,
 	NULL
 };
 
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 2/2] cpufreq: Enforce PM QoS maximum frequency
From: Antti P Miettinen @ 2012-01-19 12:35 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326976559-4009-1-git-send-email-amiettinen@nvidia.com>

Observe PM QoS CPU frequency maximum in addition to
policy settings.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
 drivers/cpufreq/cpufreq.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index c2c1c62..d233a8b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1638,12 +1638,15 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
 	unsigned int pmax = policy->max;
 	unsigned int qmin = min(pm_qos_request(PM_QOS_CPU_FREQ_MIN),
 				data->max);
+	unsigned int qmax = max(pm_qos_request(PM_QOS_CPU_FREQ_MAX),
+				data->min);
 
-	pr_debug("setting new policy for CPU %u: %u/%u - %u kHz\n",
-		 policy->cpu, pmin, qmin, pmax);
+	pr_debug("setting new policy for CPU %u: %u/%u - %u/%u kHz\n",
+		 policy->cpu, pmin, qmin, pmax, qmax);
 
 	/* clamp the new policy to PM QoS limits */
 	policy->min = max(pmin, qmin);
+	policy->max = min(pmax, qmax);
 
 	memcpy(&policy->cpuinfo, &data->cpuinfo,
 				sizeof(struct cpufreq_cpuinfo));
@@ -1920,12 +1923,16 @@ static int cpu_freq_notify(struct notifier_block *b,
 static struct notifier_block min_freq_notifier = {
 	.notifier_call = cpu_freq_notify,
 };
+static struct notifier_block max_freq_notifier = {
+	.notifier_call = cpu_freq_notify,
+};
 
 static int cpu_freq_notify(struct notifier_block *b,
 			   unsigned long l, void *v)
 {
 	int cpu;
-	pr_debug("PM QoS min %lu\n", l);
+	pr_debug("PM QoS %s %lu\n",
+		 b == &min_freq_notifier ? "min" : "max", l);
 	for_each_online_cpu(cpu) {
 		struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
 		if (policy) {
@@ -1952,6 +1959,9 @@ static int __init cpufreq_core_init(void)
 	rc = pm_qos_add_notifier(PM_QOS_CPU_FREQ_MIN,
 				 &min_freq_notifier);
 	BUG_ON(rc);
+	rc = pm_qos_add_notifier(PM_QOS_CPU_FREQ_MAX,
+				 &max_freq_notifier);
+	BUG_ON(rc);
 
 	return 0;
 }
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 1/2] PM QoS: Add CPU frequency maximum as PM QoS param
From: Antti P Miettinen @ 2012-01-19 12:35 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326976559-4009-1-git-send-email-amiettinen@nvidia.com>

Add maximum CPU frequency as PM QoS parameter.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
 include/linux/pm_qos.h |    2 ++
 kernel/power/qos.c     |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h
index 54a0d00..7b8d08b 100644
--- a/include/linux/pm_qos.h
+++ b/include/linux/pm_qos.h
@@ -15,6 +15,7 @@ enum {
 	PM_QOS_NETWORK_LATENCY,
 	PM_QOS_NETWORK_THROUGHPUT,
 	PM_QOS_CPU_FREQ_MIN,
+	PM_QOS_CPU_FREQ_MAX,
 
 	/* insert new class ID */
 
@@ -28,6 +29,7 @@ enum {
 #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE	0
 #define PM_QOS_DEV_LAT_DEFAULT_VALUE		0
 #define PM_QOS_CPU_FREQ_MIN_DEFAULT_VALUE	0
+#define PM_QOS_CPU_FREQ_MAX_DEFAULT_VALUE	LONG_MAX
 
 struct pm_qos_request {
 	struct plist_node node;
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index 07d761a..04b744b 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -115,12 +115,27 @@ static struct pm_qos_object cpu_freq_min_pm_qos = {
 };
 
 
+static BLOCKING_NOTIFIER_HEAD(cpu_freq_max_notifier);
+static struct pm_qos_constraints cpu_freq_max_constraints = {
+	.list = PLIST_HEAD_INIT(cpu_freq_max_constraints.list),
+	.target_value = PM_QOS_CPU_FREQ_MAX_DEFAULT_VALUE,
+	.default_value = PM_QOS_CPU_FREQ_MAX_DEFAULT_VALUE,
+	.type = PM_QOS_MIN,
+	.notifiers = &cpu_freq_max_notifier,
+};
+static struct pm_qos_object cpu_freq_max_pm_qos = {
+	.constraints = &cpu_freq_max_constraints,
+	.name = "cpu_freq_max",
+};
+
+
 static struct pm_qos_object *pm_qos_array[] = {
 	&null_pm_qos,
 	&cpu_dma_pm_qos,
 	&network_lat_pm_qos,
 	&network_throughput_pm_qos,
 	&cpu_freq_min_pm_qos,
+	&cpu_freq_max_pm_qos,
 };
 
 static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 0/2] RFC: CPU frequency max as PM QoS param
From: Antti P Miettinen @ 2012-01-19 12:35 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm

This is a continuation to "RFC: CPU frequency min as PM QoS param"
patchset. This patchset adds CPU frequency maximum as a PM QoS
parameter and modifies CPU frequncy core to enforce the limit. CPU
frequency ceiling can be used to improve the energy efficiency of
workloads that would cause the cpufreq governors to enforce an
unnecessarily high operating point. In other words, CPU frequency
maximum can act as an energy efficiency level request.

Tested on Dell E6420 with the ACPI cpufreq driver against Ubuntu
3.2. Patches are against linux-next, compile tested.

Antti P Miettinen (2):
  PM QoS: Add CPU frequency maximum as PM QoS param
  cpufreq: Enforce PM QoS maximum frequency

 drivers/cpufreq/cpufreq.c |   16 +++++++++++++---
 include/linux/pm_qos.h    |    2 ++
 kernel/power/qos.c        |   15 +++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)

-- 
1.7.4.1


^ permalink raw reply

* [PATCH v3 3/3] cpufreq: Enforce PM QoS minimum limit
From: Antti P Miettinen @ 2012-01-19 12:34 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326976492-3970-1-git-send-email-amiettinen@nvidia.com>

Observe PM QoS CPU frequency minimum in addition
to policy settings. This includes storing the value
received via sysfs as the user_policy
min/max value instead of the currently enforced min/max.
This allows restoring the user min/max values when
constraints on enforced min/max change.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
 drivers/cpufreq/cpufreq.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 622013f..f2c7fc2 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -29,6 +29,7 @@
 #include <linux/completion.h>
 #include <linux/mutex.h>
 #include <linux/syscore_ops.h>
+#include <linux/pm_qos.h>
 
 #include <trace/events/power.h>
 
@@ -386,7 +387,7 @@ static ssize_t store_##file_name					\
 		return -EINVAL;						\
 									\
 	ret = __cpufreq_set_policy(policy, &new_policy);		\
-	policy->user_policy.object = policy->object;			\
+	policy->user_policy.object = new_policy.object;			\
 									\
 	return ret ? ret : count;					\
 }
@@ -1627,9 +1628,16 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
 				struct cpufreq_policy *policy)
 {
 	int ret = 0;
+	unsigned int pmin = policy->min;
+	unsigned int pmax = policy->max;
+	unsigned int qmin = min(pm_qos_request(PM_QOS_CPU_FREQ_MIN),
+				data->max);
 
-	pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
-		policy->min, policy->max);
+	pr_debug("setting new policy for CPU %u: %u/%u - %u kHz\n",
+		 policy->cpu, pmin, qmin, pmax);
+
+	/* clamp the new policy to PM QoS limits */
+	policy->min = max(pmin, qmin);
 
 	memcpy(&policy->cpuinfo, &data->cpuinfo,
 				sizeof(struct cpufreq_cpuinfo));
@@ -1704,6 +1712,9 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
 	}
 
 error_out:
+	/* restore the limits that the policy requested */
+	policy->min = pmin;
+	policy->max = pmax;
 	return ret;
 }
 
@@ -1897,9 +1908,32 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
 }
 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
 
+static int cpu_freq_notify(struct notifier_block *b,
+			   unsigned long l, void *v);
+
+static struct notifier_block min_freq_notifier = {
+	.notifier_call = cpu_freq_notify,
+};
+
+static int cpu_freq_notify(struct notifier_block *b,
+			   unsigned long l, void *v)
+{
+	int cpu;
+	pr_debug("PM QoS min %lu\n", l);
+	for_each_online_cpu(cpu) {
+		struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+		if (policy) {
+			cpufreq_update_policy(policy->cpu);
+			cpufreq_cpu_put(policy);
+		}
+	}
+	return NOTIFY_OK;
+}
+
 static int __init cpufreq_core_init(void)
 {
 	int cpu;
+	int rc;
 
 	for_each_possible_cpu(cpu) {
 		per_cpu(cpufreq_policy_cpu, cpu) = -1;
@@ -1909,6 +1943,9 @@ static int __init cpufreq_core_init(void)
 	cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
 	BUG_ON(!cpufreq_global_kobject);
 	register_syscore_ops(&cpufreq_syscore_ops);
+	rc = pm_qos_add_notifier(PM_QOS_CPU_FREQ_MIN,
+				 &min_freq_notifier);
+	BUG_ON(rc);
 
 	return 0;
 }
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH v3 2/3] PM QoS: Add CPU frequency minimum as PM QoS param
From: Antti P Miettinen @ 2012-01-19 12:34 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326976492-3970-1-git-send-email-amiettinen@nvidia.com>

Add minimum CPU frequency as PM QoS parameter.

Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com>
---
 include/linux/pm_qos.h |    3 +++
 kernel/power/qos.c     |   17 ++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h
index 5ac91d8..54a0d00 100644
--- a/include/linux/pm_qos.h
+++ b/include/linux/pm_qos.h
@@ -14,8 +14,10 @@ enum {
 	PM_QOS_CPU_DMA_LATENCY,
 	PM_QOS_NETWORK_LATENCY,
 	PM_QOS_NETWORK_THROUGHPUT,
+	PM_QOS_CPU_FREQ_MIN,
 
 	/* insert new class ID */
+
 	PM_QOS_NUM_CLASSES,
 };
 
@@ -25,6 +27,7 @@ enum {
 #define PM_QOS_NETWORK_LAT_DEFAULT_VALUE	(2000 * USEC_PER_SEC)
 #define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE	0
 #define PM_QOS_DEV_LAT_DEFAULT_VALUE		0
+#define PM_QOS_CPU_FREQ_MIN_DEFAULT_VALUE	0
 
 struct pm_qos_request {
 	struct plist_node node;
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index d6d6dbd..07d761a 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -101,11 +101,26 @@ static struct pm_qos_object network_throughput_pm_qos = {
 };
 
 
+static BLOCKING_NOTIFIER_HEAD(cpu_freq_min_notifier);
+static struct pm_qos_constraints cpu_freq_min_constraints = {
+	.list = PLIST_HEAD_INIT(cpu_freq_min_constraints.list),
+	.target_value = PM_QOS_CPU_FREQ_MIN_DEFAULT_VALUE,
+	.default_value = PM_QOS_CPU_FREQ_MIN_DEFAULT_VALUE,
+	.type = PM_QOS_MAX,
+	.notifiers = &cpu_freq_min_notifier,
+};
+static struct pm_qos_object cpu_freq_min_pm_qos = {
+	.constraints = &cpu_freq_min_constraints,
+	.name = "cpu_freq_min",
+};
+
+
 static struct pm_qos_object *pm_qos_array[] = {
 	&null_pm_qos,
 	&cpu_dma_pm_qos,
 	&network_lat_pm_qos,
-	&network_throughput_pm_qos
+	&network_throughput_pm_qos,
+	&cpu_freq_min_pm_qos,
 };
 
 static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH v3 1/3] PM QoS: Simplify PM QoS expansion/merge
From: Antti P Miettinen @ 2012-01-19 12:34 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm
In-Reply-To: <1326976492-3970-1-git-send-email-amiettinen@nvidia.com>

From: Alex Frid <afrid@nvidia.com>

- Replace class ID #define with enumeration
- Loop through PM QoS objects during initialization (rather than
  initializing them one-by-one)

Signed-off-by: Alex Frid <afrid@nvidia.com>
Reviewed-by: Antti Miettinen <amiettinen@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Scott Williams <scwilliams@nvidia.com>
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
---
 include/linux/pm_qos.h |   14 +++++++++-----
 kernel/power/qos.c     |   23 ++++++++++-------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h
index e5bbcba..5ac91d8 100644
--- a/include/linux/pm_qos.h
+++ b/include/linux/pm_qos.h
@@ -9,12 +9,16 @@
 #include <linux/miscdevice.h>
 #include <linux/device.h>
 
-#define PM_QOS_RESERVED 0
-#define PM_QOS_CPU_DMA_LATENCY 1
-#define PM_QOS_NETWORK_LATENCY 2
-#define PM_QOS_NETWORK_THROUGHPUT 3
+enum {
+	PM_QOS_RESERVED = 0,
+	PM_QOS_CPU_DMA_LATENCY,
+	PM_QOS_NETWORK_LATENCY,
+	PM_QOS_NETWORK_THROUGHPUT,
+
+	/* insert new class ID */
+	PM_QOS_NUM_CLASSES,
+};
 
-#define PM_QOS_NUM_CLASSES 4
 #define PM_QOS_DEFAULT_VALUE -1
 
 #define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE	(2000 * USEC_PER_SEC)
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index 995e3bd..d6d6dbd 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -469,21 +469,18 @@ static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
 static int __init pm_qos_power_init(void)
 {
 	int ret = 0;
+	int i;
 
-	ret = register_pm_qos_misc(&cpu_dma_pm_qos);
-	if (ret < 0) {
-		printk(KERN_ERR "pm_qos_param: cpu_dma_latency setup failed\n");
-		return ret;
-	}
-	ret = register_pm_qos_misc(&network_lat_pm_qos);
-	if (ret < 0) {
-		printk(KERN_ERR "pm_qos_param: network_latency setup failed\n");
-		return ret;
+	BUILD_BUG_ON(ARRAY_SIZE(pm_qos_array) != PM_QOS_NUM_CLASSES);
+
+	for (i = 1; i < PM_QOS_NUM_CLASSES; i++) {
+		ret = register_pm_qos_misc(pm_qos_array[i]);
+		if (ret < 0) {
+			printk(KERN_ERR "pm_qos_param: %s setup failed\n",
+			       pm_qos_array[i]->name);
+			return ret;
+		}
 	}
-	ret = register_pm_qos_misc(&network_throughput_pm_qos);
-	if (ret < 0)
-		printk(KERN_ERR
-			"pm_qos_param: network_throughput setup failed\n");
 
 	return ret;
 }
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH v3 0/3] RFC: CPU frequency min as PM QoS param
From: Antti P Miettinen @ 2012-01-19 12:34 UTC (permalink / raw)
  To: davej, pavel, rjw, len.brown, khilman, j-pihet, markgross,
	cpufreq, linux-pm

The inspiration for this patch series is the N9 CPU frequency boost
upon input events:

http://www.spinics.net/lists/cpufreq/msg00667.html

and the related changes in git://codeaurora.org/kernel/msm.git tree.
Those patches modify the ondemand cpufreq governor. This patch series
adds minimum CPU frequency as PM QoS parameter and modifies the
cpufreq core to enforce the PM QoS limit.

I've been testing these changes against Ubuntu 3.2 kernel on a Dell
E6420 with the ACPI cpufreq driver. The patches are against
linux-next/master, compile tested against it.

V3:
* split max to separate patch set (V2 patches 7 and 8)
* split adding sysfs files to separate patch set (V2 patch 3)
* fold user_policy handling into min enforcement (V2 patches 4 and 5)
* split input event booster to separate patch set (V2 patch 6)

	--Antti

Alex Frid (1):
  PM QoS: Simplify PM QoS expansion/merge

Antti P Miettinen (2):
  PM QoS: Add CPU frequency minimum as PM QoS param
  cpufreq: Enforce PM QoS minimum limit

 drivers/cpufreq/cpufreq.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 include/linux/pm_qos.h    |   17 ++++++++++++-----
 kernel/power/qos.c        |   40 ++++++++++++++++++++++++++--------------
 3 files changed, 78 insertions(+), 22 deletions(-)

-- 
1.7.4.1


^ permalink raw reply

* Re: [RFC PATCH 0/2] thermal: Add generic cpu cooling devices according to thermal framework
From: Amit Kachhap @ 2012-01-19  9:17 UTC (permalink / raw)
  To: linux-pm
  Cc: linux-kernel, mjg59, linux-acpi, lenb, rui.zhang, linaro-dev,
	amit.kachhap, patches
In-Reply-To: <1323789196-4942-1-git-send-email-amit.kachhap@linaro.org>

On 13 December 2011 20:43, Amit Daniel Kachhap <amit.kachhap@linaro.org> wrote:
> PATCH 1)  [thermal: Add a new trip type to use cooling device instance number]
> This patch adds a new trip type THERMAL_TRIP_STATE_ACTIVE which passes
> cooling device instance number and may be helpful for cpufreq cooling devices
> to take the correct cooling action.
>
> PATCH 2)  [thermal: Add generic cpu cooling implementation]
> This patch adds generic cpu cooling low level implementation through frequency
> clipping and cpu hotplug. In future, other cpu related cooling devices may be
> added here. An ACPI version of this already exists(drivers/acpi/processor_thermal.c).
> But this will be useful for platforms like ARM using the generic thermal interface
> along with the generic cpu cooling devices. The cooling device registration API's
> return cooling device pointers which can be easily binded with the thermal zone
> trip points.
>

Any comments on these patches? I submitted them quite long back.

Regards,
Amit D

>
> Amit Daniel Kachhap (2):
>  thermal: Add a new trip type to use cooling device instance number
>  thermal: Add generic cpu cooling implementation
>
>  Documentation/thermal/cpu-cooling-api.txt |   52 +++++
>  Documentation/thermal/sysfs-api.txt       |    4 +-
>  drivers/thermal/Kconfig                   |   11 +
>  drivers/thermal/Makefile                  |    1 +
>  drivers/thermal/cpu_cooling.c             |  302 +++++++++++++++++++++++++++++
>  drivers/thermal/thermal_sys.c             |   27 +++-
>  include/linux/cpu_cooling.h               |   45 +++++
>  include/linux/thermal.h                   |    1 +
>  8 files changed, 440 insertions(+), 3 deletions(-)
>  create mode 100644 Documentation/thermal/cpu-cooling-api.txt
>  create mode 100644 drivers/thermal/cpu_cooling.c
>  create mode 100644 include/linux/cpu_cooling.h
>

^ permalink raw reply

* Re: [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Antti P Miettinen @ 2012-01-19  6:49 UTC (permalink / raw)
  To: linux-pm; +Cc: cpufreq
In-Reply-To: <201201190024.27022.rjw@sisk.pl>

"Rafael J. Wysocki" <rjw@sisk.pl> writes:
[..]
> Perhaps we need a new cpufreq governor that would take use PM QoS internally
> to store requests from different sources, but that would work on a per-CPU
> basis (not globally) and would provide a new interface for user space?
>
> Rafael

I think it would be nice if the choice of governor could be independent
of the constraints. Also, implementing the constraints in the cpufreq
core is easier than in governors.

	--Antti

^ permalink raw reply

* Re: [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Antti P Miettinen @ 2012-01-19  6:41 UTC (permalink / raw)
  To: linux-pm; +Cc: cpufreq
In-Reply-To: <201201190010.38790.rjw@sisk.pl>

"Rafael J. Wysocki" <rjw@sisk.pl> writes:
> On Wednesday, January 18, 2012, Antti P Miettinen wrote:
[..]
>> For the touch screen UI, the boost could be implemented as a kernel
>> module hooked with suitable event filter to the input event
>> stream. Another possibility is the UI framework in user space. Some
>> specific user space applications would also be clients.
>
> I see.
>
> However, if you use PM QoS for that as proposed, there will be only one
> misc device for the minimum CPU frequency and one for the maximum, so
> user space will only be able to specify those numbers globally, ie. for
> all CPUs in the system.  Is that your intention?

Yes - global floor/ceiling is what we want for these cases. Resource
specific constraints would be useful also. I guess the device specific
requests could be used for those but I do not have any code related to
this - yet at least :-)

	--Antti

^ permalink raw reply

* Re: [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Rafael J. Wysocki @ 2012-01-18 23:24 UTC (permalink / raw)
  To: markgross; +Cc: linux-pm, Antti P Miettinen, cpufreq
In-Reply-To: <20120118031319.GB27153@mgross-G62>

On Wednesday, January 18, 2012, mark gross wrote:
> On Mon, Jan 16, 2012 at 10:38:57PM +0100, Rafael J. Wysocki wrote:
> > Hi,
> > 
> > On Monday, January 16, 2012, Antti P Miettinen wrote:
> > > [did not reach linux-pm as I sent to wrong address, sorry for
> > > duplicates]
> > > 
> > > The inspiration for this patch series is the N9 CPU frequency boost
> > > upon input events:
> > > 
> > > http://www.spinics.net/lists/cpufreq/msg00667.html
> > > 
> > > and the related changes in git://codeaurora.org/kernel/msm.git tree.
> > > Those patches modify the ondemand cpufreq governor. This patch series
> > > adds minimum and maximum CPU frequency as PM QoS parameters and
> > > modifies the cpufreq core to enforce the PM QoS limits.
> > 
> > If that hasn't been clear enough so far, I'm still not convinced that using
> > PM QoS for that is a good idea.
> > 
> > First off, frequency as a unit of throughput is questionable to say the least,
> > because it isn't portable from one system to another.  Moreover, even on a
> > given system it isn't particularly clear what the exact correspondence
> > between frequency and throughput actually is.
> 
> You are right.  The notion of throughput of a CPU is really hard to
> quantify.  Perhaps not using the term "throughput" would help?

Yes, it would.

> The base issue I see, the Intel platform, is needing is that sometimes
> we need to block the lowest P-states that the ondemand governor goes for
> because those P-states result in media / graphics workloads dropping
> frames.  However; GPU intensive workloads do not stress the CPU so the
> ondemand governor goes for the low p-state.
> 
> I could use some way of constraining the PM-throttling of the
> cpu-freq that can be hit from kernel or user mode.  So the graphics
> driver can dynamically adjust the constraint request on the cpufreq
> subsystem.
> 
> It is problematic that any driver requesting a given frequency request
> is not portable across ISA's or even processor families in the same ISA.
> But, maybe such a driver should use a module parameter to work around
> this lack of portability?

Well, it seems to me that we're trying to add a backdoor to the (apparently
inadequate) governors here.  Arguably, the governors should be able to
make the right decisions on the basis of the information they receive
through their own interfaces.

> > Second, it's not particularly clear what the meaning of the "min" frequency
> > is supposed to be in terms of throughput.
> 
> It should mean "please cpufreq do not put the cpu into a state where its
> clock runs slower than min".  I don't think we should talk about it as
> throughput because thats not what the cpufreq controls.

Perhaps we need a new cpufreq governor that would take use PM QoS internally
to store requests from different sources, but that would work on a per-CPU
basis (not globally) and would provide a new interface for user space?

Rafael

^ permalink raw reply

* Re: [linux-pm] [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Rafael J. Wysocki @ 2012-01-18 23:16 UTC (permalink / raw)
  To: Antti P Miettinen; +Cc: linux-pm, cpufreq, mark gross
In-Reply-To: <87ehuxqveg.fsf@amiettinen-lnx.nvidia.com>

On Wednesday, January 18, 2012, Antti P Miettinen wrote:
> mark gross <markgross@thegnar.org> writes:
> > I'm not a big fan of the cpufreq seamanly redundant export either.
> > Doesn't the equivalent data get exported under
> > /sys/devices/system/cpu/cpu?/cpufreq/ ?
> 
> The added sysfs nodes are under /sys/devices/system/cpu/cpu?/cpufreq.
> They do no not duplicate functionality, they are just an
> addition.

So please drop them for now.

> Currently you can request a new minimum by writing to
> scaling_min_freq and you can view the currently enforced policy->min via
> the same file. Patch 3 adds read-only policy_{min,max}_freq nodes for
> being able to inspect the user_policy.min/max. This is related to patch
> 4 which preserves the requested min/max in user_policy instead of
> storing the enforced min/max to user_policy. This is in turn related to
> patch 5. We need to be able to revert back to requested min/max when PM
> QoS constraints get lifted. I think we do not want to overwrite
> user_policy min/max with policy->min/max as those values can be affected
> by temporary constraints.
> 
> I would welcome more comments on patches 3 and 4.

I would drop patch 3 and fold patch 4 into patch 5.

Thanks,
Rafael

^ permalink raw reply

* Re: [linux-pm] [PATCH v2 0/8] RFC: CPU frequency min/max as PM QoS params
From: Rafael J. Wysocki @ 2012-01-18 23:10 UTC (permalink / raw)
  To: Antti P Miettinen; +Cc: linux-pm, cpufreq, mark gross
In-Reply-To: <87ipk9qwff.fsf@amiettinen-lnx.nvidia.com>

On Wednesday, January 18, 2012, Antti P Miettinen wrote:
> "Rafael J. Wysocki" <rjw@sisk.pl> writes:
> [..]
> > If I understand you correctly, you want to have an iterface for specifying
> > min and max frequencies from user space.  I can understand that.  At least
> > I can see some use cases for that.
> >
> > Now, the question is if using the PM QoS framework is the right way to do
> > that.
> >
> >> The change to cpufreq core just adds two read-only files to be able to
> >> inspect user_policy.min/max in addition to the currently enforced
> >> policy->min/max. Yes - there has been the possibility of using the sysfs
> >> min for setting a frequency floor but this is problematic when there are
> >> multiple clients. You'd need some kind of arbitration and book keeping
> >> to set/restore the minimum. And PM QoS provides exactly this mechanism.
> >
> > Just as I suspected. :-)
> >
> > OK, so what's your anticipated usage model of this?
> 
> We've been experimenting with hooking the frequency boost to e.g. touch
> screen UI events and application launch. I believe there are also some
> specific applications that would want to either set a frequency floor or
> ceiling in some situations.
> 
> >> I think the kernel needs to be extended to handle more PM constraints
> >> and PM QoS is the closest thing I know for this kind of
> >> functionality. However, I'm open to suggestions about alternative
> >> approaches. I think we need e.g. more than just min/max "reduction
> >> operators". Ideas, anyone?
> >
> > I first need to know who those multiple clients are going to be.
> >
> > Thanks,
> > Rafael
> 
> For the touch screen UI, the boost could be implemented as a kernel
> module hooked with suitable event filter to the input event
> stream. Another possibility is the UI framework in user space. Some
> specific user space applications would also be clients.

I see.

However, if you use PM QoS for that as proposed, there will be only one
misc device for the minimum CPU frequency and one for the maximum, so
user space will only be able to specify those numbers globally, ie. for
all CPUs in the system.  Is that your intention?

Rafael

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox