aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMark Gross <mgross@linux.intel.com>2008-02-05 01:30:08 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 12:44:22 -0500
commitd82b35186eaa816267f044bd70cc0acb3c7971a3 (patch)
treee8de56c122fd8040086e974895afbb8299045c0f /kernel
parent4ef7229ffa93695e346d510b871452811509ea65 (diff)
pm qos infrastructure and interface
The following patch is a generalization of the latency.c implementation done by Arjan last year. It provides infrastructure for more than one parameter, and exposes a user mode interface for processes to register pm_qos expectations of processes. This interface provides a kernel and user mode interface for registering performance expectations by drivers, subsystems and user space applications on one of the parameters. Currently we have {cpu_dma_latency, network_latency, network_throughput} as the initial set of pm_qos parameters. The infrastructure exposes multiple misc device nodes one per implemented parameter. The set of parameters implement is defined by pm_qos_power_init() and pm_qos_params.h. This is done because having the available parameters being runtime configurable or changeable from a driver was seen as too easy to abuse. For each parameter a list of performance requirements is maintained along with an aggregated target value. The aggregated target value is updated with changes to the requirement list or elements of the list. Typically the aggregated target value is simply the max or min of the requirement values held in the parameter list elements. >From kernel mode the use of this interface is simple: pm_qos_add_requirement(param_id, name, target_value): Will insert a named element in the list for that identified PM_QOS parameter with the target value. Upon change to this list the new target is recomputed and any registered notifiers are called only if the target value is now different. pm_qos_update_requirement(param_id, name, new_target_value): Will search the list identified by the param_id for the named list element and then update its target value, calling the notification tree if the aggregated target is changed. with that name is already registered. pm_qos_remove_requirement(param_id, name): Will search the identified list for the named element and remove it, after removal it will update the aggregate target and call the notification tree if the target was changed as a result of removing the named requirement. >From user mode: Only processes can register a pm_qos requirement. To provide for automatic cleanup for process the interface requires the process to register its parameter requirements in the following way: To register the default pm_qos target for the specific parameter, the process must open one of /dev/[cpu_dma_latency, network_latency, network_throughput] As long as the device node is held open that process has a registered requirement on the parameter. The name of the requirement is "process_<PID>" derived from the current->pid from within the open system call. To change the requested target value the process needs to write a s32 value to the open device node. This translates to a pm_qos_update_requirement call. To remove the user mode request for a target value simply close the device node. [akpm@linux-foundation.org: fix warnings] [akpm@linux-foundation.org: fix build] [akpm@linux-foundation.org: fix build again] [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: mark gross <mgross@linux.intel.com> Cc: "John W. Linville" <linville@tuxdriver.com> Cc: Len Brown <lenb@kernel.org> Cc: Jaroslav Kysela <perex@suse.cz> Cc: Takashi Iwai <tiwai@suse.de> Cc: Arjan van de Ven <arjan@infradead.org> Cc: Venki Pallipadi <venkatesh.pallipadi@intel.com> Cc: Adam Belay <abelay@novell.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/pm_qos_params.c425
2 files changed, 426 insertions, 1 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index db9af707ff5b..8331243a4e5e 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
9 rcupdate.o extable.o params.o posix-timers.o \ 9 rcupdate.o extable.o params.o posix-timers.o \
10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \ 11 hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \
12 utsname.o notifier.o ksysfs.o 12 utsname.o notifier.o ksysfs.o pm_qos_params.o
13 13
14obj-$(CONFIG_SYSCTL) += sysctl_check.o 14obj-$(CONFIG_SYSCTL) += sysctl_check.o
15obj-$(CONFIG_STACKTRACE) += stacktrace.o 15obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c
new file mode 100644
index 000000000000..0afe32be4c85
--- /dev/null
+++ b/kernel/pm_qos_params.c
@@ -0,0 +1,425 @@
1/*
2 * This module exposes the interface to kernel space for specifying
3 * QoS dependencies. It provides infrastructure for registration of:
4 *
5 * Dependents on a QoS value : register requirements
6 * Watchers of QoS value : get notified when target QoS value changes
7 *
8 * This QoS design is best effort based. Dependents register their QoS needs.
9 * Watchers register to keep track of the current QoS needs of the system.
10 *
11 * There are 3 basic classes of QoS parameter: latency, timeout, throughput
12 * each have defined units:
13 * latency: usec
14 * timeout: usec <-- currently not used.
15 * throughput: kbs (kilo byte / sec)
16 *
17 * There are lists of pm_qos_objects each one wrapping requirements, notifiers
18 *
19 * User mode requirements on a QOS parameter register themselves to the
20 * subsystem by opening the device node /dev/... and writing there request to
21 * the node. As long as the process holds a file handle open to the node the
22 * client continues to be accounted for. Upon file release the usermode
23 * requirement is removed and a new qos target is computed. This way when the
24 * requirement that the application has is cleaned up when closes the file
25 * pointer or exits the pm_qos_object will get an opportunity to clean up.
26 *
27 * mark gross mgross@linux.intel.com
28 */
29
30#include <linux/pm_qos_params.h>
31#include <linux/sched.h>
32#include <linux/spinlock.h>
33#include <linux/slab.h>
34#include <linux/time.h>
35#include <linux/fs.h>
36#include <linux/device.h>
37#include <linux/miscdevice.h>
38#include <linux/string.h>
39#include <linux/platform_device.h>
40#include <linux/init.h>
41
42#include <linux/uaccess.h>
43
44/*
45 * locking rule: all changes to target_value or requirements or notifiers lists
46 * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
47 * held, taken with _irqsave. One lock to rule them all
48 */
49struct requirement_list {
50 struct list_head list;
51 union {
52 s32 value;
53 s32 usec;
54 s32 kbps;
55 };
56 char *name;
57};
58
59static s32 max_compare(s32 v1, s32 v2);
60static s32 min_compare(s32 v1, s32 v2);
61
62struct pm_qos_object {
63 struct requirement_list requirements;
64 struct blocking_notifier_head *notifiers;
65 struct miscdevice pm_qos_power_miscdev;
66 char *name;
67 s32 default_value;
68 s32 target_value;
69 s32 (*comparitor)(s32, s32);
70};
71
72static struct pm_qos_object null_pm_qos;
73static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier);
74static struct pm_qos_object cpu_dma_pm_qos = {
75 .requirements = {LIST_HEAD_INIT(cpu_dma_pm_qos.requirements.list)},
76 .notifiers = &cpu_dma_lat_notifier,
77 .name = "cpu_dma_latency",
78 .default_value = 2000 * USEC_PER_SEC,
79 .target_value = 2000 * USEC_PER_SEC,
80 .comparitor = min_compare
81};
82
83static BLOCKING_NOTIFIER_HEAD(network_lat_notifier);
84static struct pm_qos_object network_lat_pm_qos = {
85 .requirements = {LIST_HEAD_INIT(network_lat_pm_qos.requirements.list)},
86 .notifiers = &network_lat_notifier,
87 .name = "network_latency",
88 .default_value = 2000 * USEC_PER_SEC,
89 .target_value = 2000 * USEC_PER_SEC,
90 .comparitor = min_compare
91};
92
93
94static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier);
95static struct pm_qos_object network_throughput_pm_qos = {
96 .requirements =
97 {LIST_HEAD_INIT(network_throughput_pm_qos.requirements.list)},
98 .notifiers = &network_throughput_notifier,
99 .name = "network_throughput",
100 .default_value = 0,
101 .target_value = 0,
102 .comparitor = max_compare
103};
104
105
106static struct pm_qos_object *pm_qos_array[] = {
107 &null_pm_qos,
108 &cpu_dma_pm_qos,
109 &network_lat_pm_qos,
110 &network_throughput_pm_qos
111};
112
113static DEFINE_SPINLOCK(pm_qos_lock);
114
115static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
116 size_t count, loff_t *f_pos);
117static int pm_qos_power_open(struct inode *inode, struct file *filp);
118static int pm_qos_power_release(struct inode *inode, struct file *filp);
119
120static const struct file_operations pm_qos_power_fops = {
121 .write = pm_qos_power_write,
122 .open = pm_qos_power_open,
123 .release = pm_qos_power_release,
124};
125
126/* static helper functions */
127static s32 max_compare(s32 v1, s32 v2)
128{
129 return max(v1, v2);
130}
131
132static s32 min_compare(s32 v1, s32 v2)
133{
134 return min(v1, v2);
135}
136
137
138static void update_target(int target)
139{
140 s32 extreme_value;
141 struct requirement_list *node;
142 unsigned long flags;
143 int call_notifier = 0;
144
145 spin_lock_irqsave(&pm_qos_lock, flags);
146 extreme_value = pm_qos_array[target]->default_value;
147 list_for_each_entry(node,
148 &pm_qos_array[target]->requirements.list, list) {
149 extreme_value = pm_qos_array[target]->comparitor(
150 extreme_value, node->value);
151 }
152 if (pm_qos_array[target]->target_value != extreme_value) {
153 call_notifier = 1;
154 pm_qos_array[target]->target_value = extreme_value;
155 pr_debug(KERN_ERR "new target for qos %d is %d\n", target,
156 pm_qos_array[target]->target_value);
157 }
158 spin_unlock_irqrestore(&pm_qos_lock, flags);
159
160 if (call_notifier)
161 blocking_notifier_call_chain(pm_qos_array[target]->notifiers,
162 (unsigned long) extreme_value, NULL);
163}
164
165static int register_pm_qos_misc(struct pm_qos_object *qos)
166{
167 qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR;
168 qos->pm_qos_power_miscdev.name = qos->name;
169 qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops;
170
171 return misc_register(&qos->pm_qos_power_miscdev);