diff options
Diffstat (limited to 'kernel/pm_qos_params.c')
| -rw-r--r-- | kernel/pm_qos_params.c | 215 |
1 files changed, 114 insertions, 101 deletions
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c index f42d3f737a33..996a4dec5f96 100644 --- a/kernel/pm_qos_params.c +++ b/kernel/pm_qos_params.c | |||
| @@ -48,59 +48,49 @@ | |||
| 48 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock | 48 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock |
| 49 | * held, taken with _irqsave. One lock to rule them all | 49 | * held, taken with _irqsave. One lock to rule them all |
| 50 | */ | 50 | */ |
| 51 | struct pm_qos_request_list { | 51 | enum pm_qos_type { |
| 52 | struct list_head list; | 52 | PM_QOS_MAX, /* return the largest value */ |
| 53 | union { | 53 | PM_QOS_MIN /* return the smallest value */ |
| 54 | s32 value; | ||
| 55 | s32 usec; | ||
| 56 | s32 kbps; | ||
| 57 | }; | ||
| 58 | int pm_qos_class; | ||
| 59 | }; | 54 | }; |
| 60 | 55 | ||
| 61 | static s32 max_compare(s32 v1, s32 v2); | ||
| 62 | static s32 min_compare(s32 v1, s32 v2); | ||
| 63 | |||
| 64 | struct pm_qos_object { | 56 | struct pm_qos_object { |
| 65 | struct pm_qos_request_list requests; | 57 | struct plist_head requests; |
| 66 | struct blocking_notifier_head *notifiers; | 58 | struct blocking_notifier_head *notifiers; |
| 67 | struct miscdevice pm_qos_power_miscdev; | 59 | struct miscdevice pm_qos_power_miscdev; |
| 68 | char *name; | 60 | char *name; |
| 69 | s32 default_value; | 61 | s32 default_value; |
| 70 | atomic_t target_value; | 62 | enum pm_qos_type type; |
| 71 | s32 (*comparitor)(s32, s32); | ||
| 72 | }; | 63 | }; |
| 73 | 64 | ||
| 65 | static DEFINE_SPINLOCK(pm_qos_lock); | ||
| 66 | |||
| 74 | static struct pm_qos_object null_pm_qos; | 67 | static struct pm_qos_object null_pm_qos; |
| 75 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); | 68 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); |
| 76 | static struct pm_qos_object cpu_dma_pm_qos = { | 69 | static struct pm_qos_object cpu_dma_pm_qos = { |
| 77 | .requests = {LIST_HEAD_INIT(cpu_dma_pm_qos.requests.list)}, | 70 | .requests = PLIST_HEAD_INIT(cpu_dma_pm_qos.requests, pm_qos_lock), |
| 78 | .notifiers = &cpu_dma_lat_notifier, | 71 | .notifiers = &cpu_dma_lat_notifier, |
| 79 | .name = "cpu_dma_latency", | 72 | .name = "cpu_dma_latency", |
| 80 | .default_value = 2000 * USEC_PER_SEC, | 73 | .default_value = 2000 * USEC_PER_SEC, |
| 81 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 74 | .type = PM_QOS_MIN, |
| 82 | .comparitor = min_compare | ||
| 83 | }; | 75 | }; |
| 84 | 76 | ||
| 85 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); | 77 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); |
| 86 | static struct pm_qos_object network_lat_pm_qos = { | 78 | static struct pm_qos_object network_lat_pm_qos = { |
| 87 | .requests = {LIST_HEAD_INIT(network_lat_pm_qos.requests.list)}, | 79 | .requests = PLIST_HEAD_INIT(network_lat_pm_qos.requests, pm_qos_lock), |
| 88 | .notifiers = &network_lat_notifier, | 80 | .notifiers = &network_lat_notifier, |
| 89 | .name = "network_latency", | 81 | .name = "network_latency", |
| 90 | .default_value = 2000 * USEC_PER_SEC, | 82 | .default_value = 2000 * USEC_PER_SEC, |
| 91 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 83 | .type = PM_QOS_MIN |
| 92 | .comparitor = min_compare | ||
| 93 | }; | 84 | }; |
| 94 | 85 | ||
| 95 | 86 | ||
| 96 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); | 87 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); |
| 97 | static struct pm_qos_object network_throughput_pm_qos = { | 88 | static struct pm_qos_object network_throughput_pm_qos = { |
| 98 | .requests = {LIST_HEAD_INIT(network_throughput_pm_qos.requests.list)}, | 89 | .requests = PLIST_HEAD_INIT(network_throughput_pm_qos.requests, pm_qos_lock), |
| 99 | .notifiers = &network_throughput_notifier, | 90 | .notifiers = &network_throughput_notifier, |
| 100 | .name = "network_throughput", | 91 | .name = "network_throughput", |
| 101 | .default_value = 0, | 92 | .default_value = 0, |
| 102 | .target_value = ATOMIC_INIT(0), | 93 | .type = PM_QOS_MAX, |
| 103 | .comparitor = max_compare | ||
| 104 | }; | 94 | }; |
| 105 | 95 | ||
| 106 | 96 | ||
| @@ -111,8 +101,6 @@ static struct pm_qos_object *pm_qos_array[] = { | |||
| 111 | &network_throughput_pm_qos | 101 | &network_throughput_pm_qos |
| 112 | }; | 102 | }; |
| 113 | 103 | ||
| 114 | static DEFINE_SPINLOCK(pm_qos_lock); | ||
| 115 | |||
| 116 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, | 104 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| 117 | size_t count, loff_t *f_pos); | 105 | size_t count, loff_t *f_pos); |
| 118 | static int pm_qos_power_open(struct inode *inode, struct file *filp); | 106 | static int pm_qos_power_open(struct inode *inode, struct file *filp); |
| @@ -124,46 +112,55 @@ static const struct file_operations pm_qos_power_fops = { | |||
| 124 | .release = pm_qos_power_release, | 112 | .release = pm_qos_power_release, |
| 125 | }; | 113 | }; |
| 126 | 114 | ||
| 127 | /* static helper functions */ | 115 | /* unlocked internal variant */ |
| 128 | static s32 max_compare(s32 v1, s32 v2) | 116 | static inline int pm_qos_get_value(struct pm_qos_object *o) |
| 129 | { | 117 | { |
| 130 | return max(v1, v2); | 118 | if (plist_head_empty(&o->requests)) |
| 131 | } | 119 | return o->default_value; |
| 132 | 120 | ||
| 133 | static s32 min_compare(s32 v1, s32 v2) | 121 | switch (o->type) { |
| 134 | { | 122 | case PM_QOS_MIN: |
| 135 | return min(v1, v2); | 123 | return plist_last(&o->requests)->prio; |
| 136 | } | ||
| 137 | 124 | ||
| 125 | case PM_QOS_MAX: | ||
| 126 | return plist_first(&o->requests)->prio; | ||
| 138 | 127 | ||
| 139 | static void update_target(int pm_qos_class) | 128 | default: |
| 129 | /* runtime check for not using enum */ | ||
| 130 | BUG(); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | static void update_target(struct pm_qos_object *o, struct plist_node *node, | ||
| 135 | int del, int value) | ||
| 140 | { | 136 | { |
| 141 | s32 extreme_value; | ||
| 142 | struct pm_qos_request_list *node; | ||
| 143 | unsigned long flags; | 137 | unsigned long flags; |
| 144 | int call_notifier = 0; | 138 | int prev_value, curr_value; |
| 145 | 139 | ||
| 146 | spin_lock_irqsave(&pm_qos_lock, flags); | 140 | spin_lock_irqsave(&pm_qos_lock, flags); |
| 147 | extreme_value = pm_qos_array[pm_qos_class]->default_value; | 141 | prev_value = pm_qos_get_value(o); |
| 148 | list_for_each_entry(node, | 142 | /* PM_QOS_DEFAULT_VALUE is a signal that the value is unchanged */ |
| 149 | &pm_qos_array[pm_qos_class]->requests.list, list) { | 143 | if (value != PM_QOS_DEFAULT_VALUE) { |
| 150 | extreme_value = pm_qos_array[pm_qos_class]->comparitor( | 144 | /* |
| 151 | extreme_value, node->value); | 145 | * to change the list, we atomically remove, reinit |
| 152 | } | 146 | * with new value and add, then see if the extremal |
| 153 | if (atomic_read(&pm_qos_array[pm_qos_class]->target_value) != | 147 | * changed |
| 154 | extreme_value) { | 148 | */ |
| 155 | call_notifier = 1; | 149 | plist_del(node, &o->requests); |
| 156 | atomic_set(&pm_qos_array[pm_qos_class]->target_value, | 150 | plist_node_init(node, value); |
| 157 | extreme_value); | 151 | plist_add(node, &o->requests); |
| 158 | pr_debug(KERN_ERR "new target for qos %d is %d\n", pm_qos_class, | 152 | } else if (del) { |
| 159 | atomic_read(&pm_qos_array[pm_qos_class]->target_value)); | 153 | plist_del(node, &o->requests); |
| 154 | } else { | ||
| 155 | plist_add(node, &o->requests); | ||
| 160 | } | 156 | } |
| 157 | curr_value = pm_qos_get_value(o); | ||
| 161 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 158 | spin_unlock_irqrestore(&pm_qos_lock, flags); |
| 162 | 159 | ||
| 163 | if (call_notifier) | 160 | if (prev_value != curr_value) |
| 164 | blocking_notifier_call_chain( | 161 | blocking_notifier_call_chain(o->notifiers, |
| 165 | pm_qos_array[pm_qos_class]->notifiers, | 162 | (unsigned long)curr_value, |
| 166 | (unsigned long) extreme_value, NULL); | 163 | NULL); |
| 167 | } | 164 | } |
| 168 | 165 | ||
| 169 | static int register_pm_qos_misc(struct pm_qos_object *qos) | 166 | static int register_pm_qos_misc(struct pm_qos_object *qos) |
| @@ -196,10 +193,23 @@ static int find_pm_qos_object_by_minor(int minor) | |||
| 196 | */ | 193 | */ |
| 197 | int pm_qos_request(int pm_qos_class) | 194 | int pm_qos_request(int pm_qos_class) |
| 198 | { | 195 | { |
| 199 | return atomic_read(&pm_qos_array[pm_qos_class]->target_value); | 196 | unsigned long flags; |
| 197 | int value; | ||
| 198 | |||
| 199 | spin_lock_irqsave(&pm_qos_lock, flags); | ||
| 200 | value = pm_qos_get_value(pm_qos_array[pm_qos_class]); | ||
| 201 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 202 | |||
| 203 | return value; | ||
| 200 | } | 204 | } |
| 201 | EXPORT_SYMBOL_GPL(pm_qos_request); | 205 | EXPORT_SYMBOL_GPL(pm_qos_request); |
| 202 | 206 | ||
| 207 | int pm_qos_request_active(struct pm_qos_request_list *req) | ||
| 208 | { | ||
| 209 | return req->pm_qos_class != 0; | ||
| 210 | } | ||
| 211 | EXPORT_SYMBOL_GPL(pm_qos_request_active); | ||
| 212 | |||
| 203 | /** | 213 | /** |
| 204 | * pm_qos_add_request - inserts new qos request into the list | 214 | * pm_qos_add_request - inserts new qos request into the list |
| 205 | * @pm_qos_class: identifies which list of qos request to us | 215 | * @pm_qos_class: identifies which list of qos request to us |
| @@ -211,27 +221,23 @@ EXPORT_SYMBOL_GPL(pm_qos_request); | |||
| 211 | * element as a handle for use in updating and removal. Call needs to save | 221 | * element as a handle for use in updating and removal. Call needs to save |
| 212 | * this handle for later use. | 222 | * this handle for later use. |
| 213 | */ | 223 | */ |
| 214 | struct pm_qos_request_list *pm_qos_add_request(int pm_qos_class, s32 value) | 224 | void pm_qos_add_request(struct pm_qos_request_list *dep, |
| 225 | int pm_qos_class, s32 value) | ||
| 215 | { | 226 | { |
| 216 | struct pm_qos_request_list *dep; | 227 | struct pm_qos_object *o = pm_qos_array[pm_qos_class]; |
| 217 | unsigned long flags; | 228 | int new_value; |
| 218 | 229 | ||
| 219 | dep = kzalloc(sizeof(struct pm_qos_request_list), GFP_KERNEL); | 230 | if (pm_qos_request_active(dep)) { |
| 220 | if (dep) { | 231 | WARN(1, KERN_ERR "pm_qos_add_request() called for already added request\n"); |
| 221 | if (value == PM_QOS_DEFAULT_VALUE) | 232 | return; |
| 222 | dep->value = pm_qos_array[pm_qos_class]->default_value; | ||
| 223 | else | ||
| 224 | dep->value = value; | ||
| 225 | dep->pm_qos_class = pm_qos_class; | ||
| 226 | |||
| 227 | spin_lock_irqsave(&pm_qos_lock, flags); | ||
| 228 | list_add(&dep->list, | ||
| 229 | &pm_qos_array[pm_qos_class]->requests.list); | ||
| 230 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 231 | update_target(pm_qos_class); | ||
| 232 | } | 233 | } |
| 233 | 234 | if (value == PM_QOS_DEFAULT_VALUE) | |
| 234 | return dep; | 235 | new_value = o->default_value; |
| 236 | else | ||
| 237 | new_value = value; | ||
| 238 | plist_node_init(&dep->list, new_value); | ||
| 239 | dep->pm_qos_class = pm_qos_class; | ||
| 240 | update_target(o, &dep->list, 0, PM_QOS_DEFAULT_VALUE); | ||
| 235 | } | 241 | } |
| 236 | EXPORT_SYMBOL_GPL(pm_qos_add_request); | 242 | EXPORT_SYMBOL_GPL(pm_qos_add_request); |
| 237 | 243 | ||
| @@ -246,27 +252,28 @@ EXPORT_SYMBOL_GPL(pm_qos_add_request); | |||
| 246 | * Attempts are made to make this code callable on hot code paths. | 252 | * Attempts are made to make this code callable on hot code paths. |
| 247 | */ | 253 | */ |
| 248 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, | 254 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, |
| 249 | s32 new_value) | 255 | s32 new_value) |
| 250 | { | 256 | { |
| 251 | unsigned long flags; | ||
| 252 | int pending_update = 0; | ||
| 253 | s32 temp; | 257 | s32 temp; |
| 258 | struct pm_qos_object *o; | ||
| 259 | |||
| 260 | if (!pm_qos_req) /*guard against callers passing in null */ | ||
| 261 | return; | ||
| 254 | 262 | ||
| 255 | if (pm_qos_req) { /*guard against callers passing in null */ | 263 | if (!pm_qos_request_active(pm_qos_req)) { |
| 256 | spin_lock_irqsave(&pm_qos_lock, flags); | 264 | WARN(1, KERN_ERR "pm_qos_update_request() called for unknown object\n"); |
| 257 | if (new_value == PM_QOS_DEFAULT_VALUE) | 265 | return; |
| 258 | temp = pm_qos_array[pm_qos_req->pm_qos_class]->default_value; | ||
| 259 | else | ||
| 260 | temp = new_value; | ||
| 261 | |||
| 262 | if (temp != pm_qos_req->value) { | ||
| 263 | pending_update = 1; | ||
| 264 | pm_qos_req->value = temp; | ||
| 265 | } | ||
| 266 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 267 | if (pending_update) | ||
| 268 | update_target(pm_qos_req->pm_qos_class); | ||
| 269 | } | 266 | } |
| 267 | |||
| 268 | o = pm_qos_array[pm_qos_req->pm_qos_class]; | ||
| 269 | |||
| 270 | if (new_value == PM_QOS_DEFAULT_VALUE) | ||
| 271 | temp = o->default_value; | ||
| 272 | else | ||
| 273 | temp = new_value; | ||
| 274 | |||
| 275 | if (temp != pm_qos_req->list.prio) | ||
| 276 | update_target(o, &pm_qos_req->list, 0, temp); | ||
| 270 | } | 277 | } |
| 271 | EXPORT_SYMBOL_GPL(pm_qos_update_request); | 278 | EXPORT_SYMBOL_GPL(pm_qos_update_request); |
| 272 | 279 | ||
| @@ -280,19 +287,20 @@ EXPORT_SYMBOL_GPL(pm_qos_update_request); | |||
| 280 | */ | 287 | */ |
| 281 | void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req) | 288 | void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req) |
| 282 | { | 289 | { |
| 283 | unsigned long flags; | 290 | struct pm_qos_object *o; |
| 284 | int qos_class; | ||
| 285 | 291 | ||
| 286 | if (pm_qos_req == NULL) | 292 | if (pm_qos_req == NULL) |
| 287 | return; | 293 | return; |
| 288 | /* silent return to keep pcm code cleaner */ | 294 | /* silent return to keep pcm code cleaner */ |
| 289 | 295 | ||
| 290 | qos_class = pm_qos_req->pm_qos_class; | 296 | if (!pm_qos_request_active(pm_qos_req)) { |
| 291 | spin_lock_irqsave(&pm_qos_lock, flags); | 297 | WARN(1, KERN_ERR "pm_qos_remove_request() called for unknown object\n"); |
| 292 | list_del(&pm_qos_req->list); | 298 | return; |
| 293 | kfree(pm_qos_req); | 299 | } |
| 294 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 300 | |
| 295 | update_target(qos_class); | 301 | o = pm_qos_array[pm_qos_req->pm_qos_class]; |
| 302 | update_target(o, &pm_qos_req->list, 1, PM_QOS_DEFAULT_VALUE); | ||
| 303 | memset(pm_qos_req, 0, sizeof(*pm_qos_req)); | ||
| 296 | } | 304 | } |
| 297 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); | 305 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); |
| 298 | 306 | ||
| @@ -340,8 +348,12 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp) | |||
| 340 | 348 | ||
| 341 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); | 349 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); |
| 342 | if (pm_qos_class >= 0) { | 350 | if (pm_qos_class >= 0) { |
| 343 | filp->private_data = (void *) pm_qos_add_request(pm_qos_class, | 351 | struct pm_qos_request_list *req = kzalloc(GFP_KERNEL, sizeof(*req)); |
| 344 | PM_QOS_DEFAULT_VALUE); | 352 | if (!req) |
| 353 | return -ENOMEM; | ||
| 354 | |||
| 355 | pm_qos_add_request(req, pm_qos_class, PM_QOS_DEFAULT_VALUE); | ||
| 356 | filp->private_data = req; | ||
| 345 | 357 | ||
| 346 | if (filp->private_data) | 358 | if (filp->private_data) |
| 347 | return 0; | 359 | return 0; |
| @@ -353,8 +365,9 @@ static int pm_qos_power_release(struct inode *inode, struct file *filp) | |||
| 353 | { | 365 | { |
| 354 | struct pm_qos_request_list *req; | 366 | struct pm_qos_request_list *req; |
| 355 | 367 | ||
| 356 | req = (struct pm_qos_request_list *)filp->private_data; | 368 | req = filp->private_data; |
| 357 | pm_qos_remove_request(req); | 369 | pm_qos_remove_request(req); |
| 370 | kfree(req); | ||
| 358 | 371 | ||
| 359 | return 0; | 372 | return 0; |
| 360 | } | 373 | } |
