Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'pm-sleep', 'pm-core', 'pm-domains' and 'pm-clk'

* pm-sleep:
PM: sleep: Constify static struct attribute_group
PM: sleep: Use dev_printk() when possible
PM: sleep: No need to check PF_WQ_WORKER in thaw_kernel_threads()

* pm-core:
PM: runtime: Fix typos and grammar
PM: runtime: Fix resposible -> responsible in runtime.c

* pm-domains:
PM: domains: Simplify the calculation of variables
PM: domains: Add "performance" column to debug summary
PM: domains: Make of_genpd_add_subdomain() return -EPROBE_DEFER
PM: domains: Make set_performance_state() callback optional
PM: domains: use device's next wakeup to determine domain idle state
PM: domains: inform PM domain of a device's next wakeup

* pm-clk:
PM: clk: make PM clock layer compatible with clocks that must sleep

+413 -87
+7 -7
Documentation/power/runtime_pm.rst
··· 579 579 enabled earlier by calling pm_runtime_enable(). 580 580 581 581 Note, if the device may execute pm_runtime calls during the probe (such as 582 - if it is registers with a subsystem that may call back in) then the 582 + if it is registered with a subsystem that may call back in) then the 583 583 pm_runtime_get_sync() call paired with a pm_runtime_put() call will be 584 584 appropriate to ensure that the device is not put back to sleep during the 585 585 probe. This can happen with systems such as the network device layer. ··· 587 587 It may be desirable to suspend the device once ->probe() has finished. 588 588 Therefore the driver core uses the asynchronous pm_request_idle() to submit a 589 589 request to execute the subsystem-level idle callback for the device at that 590 - time. A driver that makes use of the runtime autosuspend feature, may want to 590 + time. A driver that makes use of the runtime autosuspend feature may want to 591 591 update the last busy mark before returning from ->probe(). 592 592 593 593 Moreover, the driver core prevents runtime PM callbacks from racing with the bus 594 - notifier callback in __device_release_driver(), which is necessary, because the 594 + notifier callback in __device_release_driver(), which is necessary because the 595 595 notifier is used by some subsystems to carry out operations affecting the 596 596 runtime PM functionality. It does so by calling pm_runtime_get_sync() before 597 597 driver_sysfs_remove() and the BUS_NOTIFY_UNBIND_DRIVER notifications. This ··· 603 603 executes pm_runtime_put_sync() after running the BUS_NOTIFY_UNBIND_DRIVER 604 604 notifications in __device_release_driver(). This requires bus types and 605 605 drivers to make their ->remove() callbacks avoid races with runtime PM directly, 606 - but also it allows of more flexibility in the handling of devices during the 606 + but it also allows more flexibility in the handling of devices during the 607 607 removal of their drivers. 608 608 609 609 Drivers in ->remove() callback should undo the runtime PM changes done ··· 693 693 may be left in runtime suspend provided that all of its descendants are also 694 694 left in runtime suspend. If that happens, the PM core will not execute any 695 695 system suspend and resume callbacks for all of those devices, except for the 696 - complete callback, which is then entirely responsible for handling the device 696 + .complete() callback, which is then entirely responsible for handling the device 697 697 as appropriate. This only applies to system suspend transitions that are not 698 698 related to hibernation (see Documentation/driver-api/pm/devices.rst for more 699 699 information). ··· 706 706 right before executing the subsystem-level .prepare() callback for it and 707 707 pm_runtime_barrier() is called for every device right before executing the 708 708 subsystem-level .suspend() callback for it. In addition to that the PM core 709 - calls __pm_runtime_disable() with 'false' as the second argument for every 709 + calls __pm_runtime_disable() with 'false' as the second argument for every 710 710 device right before executing the subsystem-level .suspend_late() callback 711 711 for it. 712 712 ··· 783 783 `int pm_generic_restore_noirq(struct device *dev);` 784 784 - invoke the ->restore_noirq() callback provided by the device's driver 785 785 786 - These functions are the defaults used by the PM core, if a subsystem doesn't 786 + These functions are the defaults used by the PM core if a subsystem doesn't 787 787 provide its own callbacks for ->runtime_idle(), ->runtime_suspend(), 788 788 ->runtime_resume(), ->suspend(), ->suspend_noirq(), ->resume(), 789 789 ->resume_noirq(), ->freeze(), ->freeze_noirq(), ->thaw(), ->thaw_noirq(),
+182 -41
drivers/base/power/clock_ops.c
··· 23 23 enum pce_status { 24 24 PCE_STATUS_NONE = 0, 25 25 PCE_STATUS_ACQUIRED, 26 + PCE_STATUS_PREPARED, 26 27 PCE_STATUS_ENABLED, 27 28 PCE_STATUS_ERROR, 28 29 }; ··· 33 32 char *con_id; 34 33 struct clk *clk; 35 34 enum pce_status status; 35 + bool enabled_when_prepared; 36 36 }; 37 + 38 + /** 39 + * pm_clk_list_lock - ensure exclusive access for modifying the PM clock 40 + * entry list. 41 + * @psd: pm_subsys_data instance corresponding to the PM clock entry list 42 + * and clk_op_might_sleep count to be modified. 43 + * 44 + * Get exclusive access before modifying the PM clock entry list and the 45 + * clock_op_might_sleep count to guard against concurrent modifications. 46 + * This also protects against a concurrent clock_op_might_sleep and PM clock 47 + * entry list usage in pm_clk_suspend()/pm_clk_resume() that may or may not 48 + * happen in atomic context, hence both the mutex and the spinlock must be 49 + * taken here. 50 + */ 51 + static void pm_clk_list_lock(struct pm_subsys_data *psd) 52 + __acquires(&psd->lock) 53 + { 54 + mutex_lock(&psd->clock_mutex); 55 + spin_lock_irq(&psd->lock); 56 + } 57 + 58 + /** 59 + * pm_clk_list_unlock - counterpart to pm_clk_list_lock(). 60 + * @psd: the same pm_subsys_data instance previously passed to 61 + * pm_clk_list_lock(). 62 + */ 63 + static void pm_clk_list_unlock(struct pm_subsys_data *psd) 64 + __releases(&psd->lock) 65 + { 66 + spin_unlock_irq(&psd->lock); 67 + mutex_unlock(&psd->clock_mutex); 68 + } 69 + 70 + /** 71 + * pm_clk_op_lock - ensure exclusive access for performing clock operations. 72 + * @psd: pm_subsys_data instance corresponding to the PM clock entry list 73 + * and clk_op_might_sleep count being used. 74 + * @flags: stored irq flags. 75 + * @fn: string for the caller function's name. 76 + * 77 + * This is used by pm_clk_suspend() and pm_clk_resume() to guard 78 + * against concurrent modifications to the clock entry list and the 79 + * clock_op_might_sleep count. If clock_op_might_sleep is != 0 then 80 + * only the mutex can be locked and those functions can only be used in 81 + * non atomic context. If clock_op_might_sleep == 0 then these functions 82 + * may be used in any context and only the spinlock can be locked. 83 + * Returns -EINVAL if called in atomic context when clock ops might sleep. 84 + */ 85 + static int pm_clk_op_lock(struct pm_subsys_data *psd, unsigned long *flags, 86 + const char *fn) 87 + /* sparse annotations don't work here as exit state isn't static */ 88 + { 89 + bool atomic_context = in_atomic() || irqs_disabled(); 90 + 91 + try_again: 92 + spin_lock_irqsave(&psd->lock, *flags); 93 + if (!psd->clock_op_might_sleep) { 94 + /* the __release is there to work around sparse limitations */ 95 + __release(&psd->lock); 96 + return 0; 97 + } 98 + 99 + /* bail out if in atomic context */ 100 + if (atomic_context) { 101 + pr_err("%s: atomic context with clock_ops_might_sleep = %d", 102 + fn, psd->clock_op_might_sleep); 103 + spin_unlock_irqrestore(&psd->lock, *flags); 104 + might_sleep(); 105 + return -EPERM; 106 + } 107 + 108 + /* we must switch to the mutex */ 109 + spin_unlock_irqrestore(&psd->lock, *flags); 110 + mutex_lock(&psd->clock_mutex); 111 + 112 + /* 113 + * There was a possibility for psd->clock_op_might_sleep 114 + * to become 0 above. Keep the mutex only if not the case. 115 + */ 116 + if (likely(psd->clock_op_might_sleep)) 117 + return 0; 118 + 119 + mutex_unlock(&psd->clock_mutex); 120 + goto try_again; 121 + } 122 + 123 + /** 124 + * pm_clk_op_unlock - counterpart to pm_clk_op_lock(). 125 + * @psd: the same pm_subsys_data instance previously passed to 126 + * pm_clk_op_lock(). 127 + * @flags: irq flags provided by pm_clk_op_lock(). 128 + */ 129 + static void pm_clk_op_unlock(struct pm_subsys_data *psd, unsigned long *flags) 130 + /* sparse annotations don't work here as entry state isn't static */ 131 + { 132 + if (psd->clock_op_might_sleep) { 133 + mutex_unlock(&psd->clock_mutex); 134 + } else { 135 + /* the __acquire is there to work around sparse limitations */ 136 + __acquire(&psd->lock); 137 + spin_unlock_irqrestore(&psd->lock, *flags); 138 + } 139 + } 37 140 38 141 /** 39 142 * pm_clk_enable - Enable a clock, reporting any errors ··· 148 43 { 149 44 int ret; 150 45 151 - if (ce->status < PCE_STATUS_ERROR) { 46 + switch (ce->status) { 47 + case PCE_STATUS_ACQUIRED: 48 + ret = clk_prepare_enable(ce->clk); 49 + break; 50 + case PCE_STATUS_PREPARED: 152 51 ret = clk_enable(ce->clk); 153 - if (!ret) 154 - ce->status = PCE_STATUS_ENABLED; 155 - else 156 - dev_err(dev, "%s: failed to enable clk %p, error %d\n", 157 - __func__, ce->clk, ret); 52 + break; 53 + default: 54 + return; 158 55 } 56 + if (!ret) 57 + ce->status = PCE_STATUS_ENABLED; 58 + else 59 + dev_err(dev, "%s: failed to enable clk %p, error %d\n", 60 + __func__, ce->clk, ret); 159 61 } 160 62 161 63 /** ··· 176 64 ce->clk = clk_get(dev, ce->con_id); 177 65 if (IS_ERR(ce->clk)) { 178 66 ce->status = PCE_STATUS_ERROR; 67 + return; 68 + } else if (clk_is_enabled_when_prepared(ce->clk)) { 69 + /* we defer preparing the clock in that case */ 70 + ce->status = PCE_STATUS_ACQUIRED; 71 + ce->enabled_when_prepared = true; 72 + } else if (clk_prepare(ce->clk)) { 73 + ce->status = PCE_STATUS_ERROR; 74 + dev_err(dev, "clk_prepare() failed\n"); 75 + return; 179 76 } else { 180 - if (clk_prepare(ce->clk)) { 181 - ce->status = PCE_STATUS_ERROR; 182 - dev_err(dev, "clk_prepare() failed\n"); 183 - } else { 184 - ce->status = PCE_STATUS_ACQUIRED; 185 - dev_dbg(dev, 186 - "Clock %pC con_id %s managed by runtime PM.\n", 187 - ce->clk, ce->con_id); 188 - } 77 + ce->status = PCE_STATUS_PREPARED; 189 78 } 79 + dev_dbg(dev, "Clock %pC con_id %s managed by runtime PM.\n", 80 + ce->clk, ce->con_id); 190 81 } 191 82 192 83 static int __pm_clk_add(struct device *dev, const char *con_id, ··· 221 106 222 107 pm_clk_acquire(dev, ce); 223 108 224 - spin_lock_irq(&psd->lock); 109 + pm_clk_list_lock(psd); 225 110 list_add_tail(&ce->node, &psd->clock_list); 226 - spin_unlock_irq(&psd->lock); 111 + if (ce->enabled_when_prepared) 112 + psd->clock_op_might_sleep++; 113 + pm_clk_list_unlock(psd); 227 114 return 0; 228 115 } 229 116 ··· 356 239 if (!ce) 357 240 return; 358 241 359 - if (ce->status < PCE_STATUS_ERROR) { 360 - if (ce->status == PCE_STATUS_ENABLED) 361 - clk_disable(ce->clk); 362 - 363 - if (ce->status >= PCE_STATUS_ACQUIRED) { 364 - clk_unprepare(ce->clk); 242 + switch (ce->status) { 243 + case PCE_STATUS_ENABLED: 244 + clk_disable(ce->clk); 245 + fallthrough; 246 + case PCE_STATUS_PREPARED: 247 + clk_unprepare(ce->clk); 248 + fallthrough; 249 + case PCE_STATUS_ACQUIRED: 250 + case PCE_STATUS_ERROR: 251 + if (!IS_ERR(ce->clk)) 365 252 clk_put(ce->clk); 366 - } 253 + break; 254 + default: 255 + break; 367 256 } 368 257 369 258 kfree(ce->con_id); ··· 392 269 if (!psd) 393 270 return; 394 271 395 - spin_lock_irq(&psd->lock); 272 + pm_clk_list_lock(psd); 396 273 397 274 list_for_each_entry(ce, &psd->clock_list, node) { 398 275 if (!con_id && !ce->con_id) ··· 403 280 goto remove; 404 281 } 405 282 406 - spin_unlock_irq(&psd->lock); 283 + pm_clk_list_unlock(psd); 407 284 return; 408 285 409 286 remove: 410 287 list_del(&ce->node); 411 - spin_unlock_irq(&psd->lock); 288 + if (ce->enabled_when_prepared) 289 + psd->clock_op_might_sleep--; 290 + pm_clk_list_unlock(psd); 412 291 413 292 __pm_clk_remove(ce); 414 293 } ··· 432 307 if (!psd || !clk) 433 308 return; 434 309 435 - spin_lock_irq(&psd->lock); 310 + pm_clk_list_lock(psd); 436 311 437 312 list_for_each_entry(ce, &psd->clock_list, node) { 438 313 if (clk == ce->clk) 439 314 goto remove; 440 315 } 441 316 442 - spin_unlock_irq(&psd->lock); 317 + pm_clk_list_unlock(psd); 443 318 return; 444 319 445 320 remove: 446 321 list_del(&ce->node); 447 - spin_unlock_irq(&psd->lock); 322 + if (ce->enabled_when_prepared) 323 + psd->clock_op_might_sleep--; 324 + pm_clk_list_unlock(psd); 448 325 449 326 __pm_clk_remove(ce); 450 327 } ··· 457 330 * @dev: Device to initialize the list of PM clocks for. 458 331 * 459 332 * Initialize the lock and clock_list members of the device's pm_subsys_data 460 - * object. 333 + * object, set the count of clocks that might sleep to 0. 461 334 */ 462 335 void pm_clk_init(struct device *dev) 463 336 { 464 337 struct pm_subsys_data *psd = dev_to_psd(dev); 465 - if (psd) 338 + if (psd) { 466 339 INIT_LIST_HEAD(&psd->clock_list); 340 + mutex_init(&psd->clock_mutex); 341 + psd->clock_op_might_sleep = 0; 342 + } 467 343 } 468 344 EXPORT_SYMBOL_GPL(pm_clk_init); 469 345 ··· 502 372 503 373 INIT_LIST_HEAD(&list); 504 374 505 - spin_lock_irq(&psd->lock); 375 + pm_clk_list_lock(psd); 506 376 507 377 list_for_each_entry_safe_reverse(ce, c, &psd->clock_list, node) 508 378 list_move(&ce->node, &list); 379 + psd->clock_op_might_sleep = 0; 509 380 510 - spin_unlock_irq(&psd->lock); 381 + pm_clk_list_unlock(psd); 511 382 512 383 dev_pm_put_subsys_data(dev); 513 384 ··· 528 397 struct pm_subsys_data *psd = dev_to_psd(dev); 529 398 struct pm_clock_entry *ce; 530 399 unsigned long flags; 400 + int ret; 531 401 532 402 dev_dbg(dev, "%s()\n", __func__); 533 403 534 404 if (!psd) 535 405 return 0; 536 406 537 - spin_lock_irqsave(&psd->lock, flags); 407 + ret = pm_clk_op_lock(psd, &flags, __func__); 408 + if (ret) 409 + return ret; 538 410 539 411 list_for_each_entry_reverse(ce, &psd->clock_list, node) { 540 - if (ce->status < PCE_STATUS_ERROR) { 541 - if (ce->status == PCE_STATUS_ENABLED) 412 + if (ce->status == PCE_STATUS_ENABLED) { 413 + if (ce->enabled_when_prepared) { 414 + clk_disable_unprepare(ce->clk); 415 + ce->status = PCE_STATUS_ACQUIRED; 416 + } else { 542 417 clk_disable(ce->clk); 543 - ce->status = PCE_STATUS_ACQUIRED; 418 + ce->status = PCE_STATUS_PREPARED; 419 + } 544 420 } 545 421 } 546 422 547 - spin_unlock_irqrestore(&psd->lock, flags); 423 + pm_clk_op_unlock(psd, &flags); 548 424 549 425 return 0; 550 426 } ··· 566 428 struct pm_subsys_data *psd = dev_to_psd(dev); 567 429 struct pm_clock_entry *ce; 568 430 unsigned long flags; 431 + int ret; 569 432 570 433 dev_dbg(dev, "%s()\n", __func__); 571 434 572 435 if (!psd) 573 436 return 0; 574 437 575 - spin_lock_irqsave(&psd->lock, flags); 438 + ret = pm_clk_op_lock(psd, &flags, __func__); 439 + if (ret) 440 + return ret; 576 441 577 442 list_for_each_entry(ce, &psd->clock_list, node) 578 443 __pm_clk_enable(dev, ce); 579 444 580 - spin_unlock_irqrestore(&psd->lock, flags); 445 + pm_clk_op_unlock(psd, &flags); 581 446 582 447 return 0; 583 448 }
+65 -22
drivers/base/power/domain.c
··· 297 297 return state; 298 298 } 299 299 300 + static int genpd_xlate_performance_state(struct generic_pm_domain *genpd, 301 + struct generic_pm_domain *parent, 302 + unsigned int pstate) 303 + { 304 + if (!parent->set_performance_state) 305 + return pstate; 306 + 307 + return dev_pm_opp_xlate_performance_state(genpd->opp_table, 308 + parent->opp_table, 309 + pstate); 310 + } 311 + 300 312 static int _genpd_set_performance_state(struct generic_pm_domain *genpd, 301 313 unsigned int state, int depth) 302 314 { ··· 323 311 list_for_each_entry(link, &genpd->child_links, child_node) { 324 312 parent = link->parent; 325 313 326 - if (!parent->set_performance_state) 327 - continue; 328 - 329 314 /* Find parent's performance state */ 330 - ret = dev_pm_opp_xlate_performance_state(genpd->opp_table, 331 - parent->opp_table, 332 - state); 315 + ret = genpd_xlate_performance_state(genpd, parent, state); 333 316 if (unlikely(ret < 0)) 334 317 goto err; 335 318 ··· 346 339 goto err; 347 340 } 348 341 349 - ret = genpd->set_performance_state(genpd, state); 350 - if (ret) 351 - goto err; 342 + if (genpd->set_performance_state) { 343 + ret = genpd->set_performance_state(genpd, state); 344 + if (ret) 345 + goto err; 346 + } 352 347 353 348 genpd->performance_state = state; 354 349 return 0; ··· 360 351 list_for_each_entry_continue_reverse(link, &genpd->child_links, 361 352 child_node) { 362 353 parent = link->parent; 363 - 364 - if (!parent->set_performance_state) 365 - continue; 366 354 367 355 genpd_lock_nested(parent, depth + 1); 368 356 ··· 405 399 if (!genpd) 406 400 return -ENODEV; 407 401 408 - if (unlikely(!genpd->set_performance_state)) 409 - return -EINVAL; 410 - 411 402 if (WARN_ON(!dev->power.subsys_data || 412 403 !dev->power.subsys_data->domain_data)) 413 404 return -EINVAL; ··· 425 422 return ret; 426 423 } 427 424 EXPORT_SYMBOL_GPL(dev_pm_genpd_set_performance_state); 425 + 426 + /** 427 + * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup. 428 + * 429 + * @dev: Device to handle 430 + * @next: impending interrupt/wakeup for the device 431 + * 432 + * 433 + * Allow devices to inform of the next wakeup. It's assumed that the users 434 + * guarantee that the genpd wouldn't be detached while this routine is getting 435 + * called. Additionally, it's also assumed that @dev isn't runtime suspended 436 + * (RPM_SUSPENDED)." 437 + * Although devices are expected to update the next_wakeup after the end of 438 + * their usecase as well, it is possible the devices themselves may not know 439 + * about that, so stale @next will be ignored when powering off the domain. 440 + */ 441 + void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) 442 + { 443 + struct generic_pm_domain_data *gpd_data; 444 + struct generic_pm_domain *genpd; 445 + 446 + genpd = dev_to_genpd_safe(dev); 447 + if (!genpd) 448 + return; 449 + 450 + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); 451 + gpd_data->next_wakeup = next; 452 + } 453 + EXPORT_SYMBOL_GPL(dev_pm_genpd_set_next_wakeup); 428 454 429 455 static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) 430 456 { ··· 966 934 err_stop: 967 935 genpd_stop_dev(genpd, dev); 968 936 err_poweroff: 969 - if (!pm_runtime_is_irq_safe(dev) || 970 - (pm_runtime_is_irq_safe(dev) && genpd_is_irq_safe(genpd))) { 937 + if (!pm_runtime_is_irq_safe(dev) || genpd_is_irq_safe(genpd)) { 971 938 genpd_lock(genpd); 972 939 genpd_power_off(genpd, true, 0); 973 940 genpd_unlock(genpd); ··· 1496 1465 gpd_data->td.constraint_changed = true; 1497 1466 gpd_data->td.effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS; 1498 1467 gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; 1468 + gpd_data->next_wakeup = KTIME_MAX; 1499 1469 1500 1470 spin_lock_irq(&dev->power.lock); 1501 1471 ··· 2495 2463 out: 2496 2464 mutex_unlock(&gpd_list_lock); 2497 2465 2498 - return ret; 2466 + return ret == -ENOENT ? -EPROBE_DEFER : ret; 2499 2467 } 2500 2468 EXPORT_SYMBOL_GPL(of_genpd_add_subdomain); 2501 2469 ··· 2984 2952 else 2985 2953 WARN_ON(1); 2986 2954 2987 - seq_puts(s, p); 2955 + seq_printf(s, "%-25s ", p); 2956 + } 2957 + 2958 + static void perf_status_str(struct seq_file *s, struct device *dev) 2959 + { 2960 + struct generic_pm_domain_data *gpd_data; 2961 + 2962 + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); 2963 + seq_put_decimal_ull(s, "", gpd_data->performance_state); 2988 2964 } 2989 2965 2990 2966 static int genpd_summary_one(struct seq_file *s, ··· 3020 2980 else 3021 2981 snprintf(state, sizeof(state), "%s", 3022 2982 status_lookup[genpd->status]); 3023 - seq_printf(s, "%-30s %-15s ", genpd->name, state); 2983 + seq_printf(s, "%-30s %-50s %u", genpd->name, state, genpd->performance_state); 3024 2984 3025 2985 /* 3026 2986 * Modifications on the list require holding locks on both ··· 3028 2988 * Also genpd->name is immutable. 3029 2989 */ 3030 2990 list_for_each_entry(link, &genpd->parent_links, parent_node) { 2991 + if (list_is_first(&link->parent_node, &genpd->parent_links)) 2992 + seq_printf(s, "\n%48s", " "); 3031 2993 seq_printf(s, "%s", link->child->name); 3032 2994 if (!list_is_last(&link->parent_node, &genpd->parent_links)) 3033 2995 seq_puts(s, ", "); ··· 3044 3002 3045 3003 seq_printf(s, "\n %-50s ", kobj_path); 3046 3004 rtpm_status_str(s, pm_data->dev); 3005 + perf_status_str(s, pm_data->dev); 3047 3006 kfree(kobj_path); 3048 3007 } 3049 3008 ··· 3060 3017 struct generic_pm_domain *genpd; 3061 3018 int ret = 0; 3062 3019 3063 - seq_puts(s, "domain status children\n"); 3020 + seq_puts(s, "domain status children performance\n"); 3064 3021 seq_puts(s, " /device runtime status\n"); 3065 - seq_puts(s, "----------------------------------------------------------------------\n"); 3022 + seq_puts(s, "----------------------------------------------------------------------------------------------\n"); 3066 3023 3067 3024 ret = mutex_lock_interruptible(&gpd_list_lock); 3068 3025 if (ret)
+93 -9
drivers/base/power/domain_governor.c
··· 117 117 return td->cached_suspend_ok; 118 118 } 119 119 120 + static void update_domain_next_wakeup(struct generic_pm_domain *genpd, ktime_t now) 121 + { 122 + ktime_t domain_wakeup = KTIME_MAX; 123 + ktime_t next_wakeup; 124 + struct pm_domain_data *pdd; 125 + struct gpd_link *link; 126 + 127 + if (!(genpd->flags & GENPD_FLAG_MIN_RESIDENCY)) 128 + return; 129 + 130 + /* 131 + * Devices that have a predictable wakeup pattern, may specify 132 + * their next wakeup. Let's find the next wakeup from all the 133 + * devices attached to this domain and from all the sub-domains. 134 + * It is possible that component's a next wakeup may have become 135 + * stale when we read that here. We will ignore to ensure the domain 136 + * is able to enter its optimal idle state. 137 + */ 138 + list_for_each_entry(pdd, &genpd->dev_list, list_node) { 139 + next_wakeup = to_gpd_data(pdd)->next_wakeup; 140 + if (next_wakeup != KTIME_MAX && !ktime_before(next_wakeup, now)) 141 + if (ktime_before(next_wakeup, domain_wakeup)) 142 + domain_wakeup = next_wakeup; 143 + } 144 + 145 + list_for_each_entry(link, &genpd->parent_links, parent_node) { 146 + next_wakeup = link->child->next_wakeup; 147 + if (next_wakeup != KTIME_MAX && !ktime_before(next_wakeup, now)) 148 + if (ktime_before(next_wakeup, domain_wakeup)) 149 + domain_wakeup = next_wakeup; 150 + } 151 + 152 + genpd->next_wakeup = domain_wakeup; 153 + } 154 + 155 + static bool next_wakeup_allows_state(struct generic_pm_domain *genpd, 156 + unsigned int state, ktime_t now) 157 + { 158 + ktime_t domain_wakeup = genpd->next_wakeup; 159 + s64 idle_time_ns, min_sleep_ns; 160 + 161 + min_sleep_ns = genpd->states[state].power_off_latency_ns + 162 + genpd->states[state].residency_ns; 163 + 164 + idle_time_ns = ktime_to_ns(ktime_sub(domain_wakeup, now)); 165 + 166 + return idle_time_ns >= min_sleep_ns; 167 + } 168 + 120 169 static bool __default_power_down_ok(struct dev_pm_domain *pd, 121 170 unsigned int state) 122 171 { ··· 250 201 } 251 202 252 203 /** 253 - * default_power_down_ok - Default generic PM domain power off governor routine. 204 + * _default_power_down_ok - Default generic PM domain power off governor routine. 254 205 * @pd: PM domain to check. 255 206 * 256 207 * This routine must be executed under the PM domain's lock. 257 208 */ 258 - static bool default_power_down_ok(struct dev_pm_domain *pd) 209 + static bool _default_power_down_ok(struct dev_pm_domain *pd, ktime_t now) 259 210 { 260 211 struct generic_pm_domain *genpd = pd_to_genpd(pd); 212 + int state_idx = genpd->state_count - 1; 261 213 struct gpd_link *link; 214 + 215 + /* 216 + * Find the next wakeup from devices that can determine their own wakeup 217 + * to find when the domain would wakeup and do it for every device down 218 + * the hierarchy. It is not worth while to sleep if the state's residency 219 + * cannot be met. 220 + */ 221 + update_domain_next_wakeup(genpd, now); 222 + if ((genpd->flags & GENPD_FLAG_MIN_RESIDENCY) && (genpd->next_wakeup != KTIME_MAX)) { 223 + /* Let's find out the deepest domain idle state, the devices prefer */ 224 + while (state_idx >= 0) { 225 + if (next_wakeup_allows_state(genpd, state_idx, now)) { 226 + genpd->max_off_time_changed = true; 227 + break; 228 + } 229 + state_idx--; 230 + } 231 + 232 + if (state_idx < 0) { 233 + state_idx = 0; 234 + genpd->cached_power_down_ok = false; 235 + goto done; 236 + } 237 + } 262 238 263 239 if (!genpd->max_off_time_changed) { 264 240 genpd->state_idx = genpd->cached_power_down_state_idx; ··· 302 228 genpd->max_off_time_ns = -1; 303 229 genpd->max_off_time_changed = false; 304 230 genpd->cached_power_down_ok = true; 305 - genpd->state_idx = genpd->state_count - 1; 306 231 307 - /* Find a state to power down to, starting from the deepest. */ 308 - while (!__default_power_down_ok(pd, genpd->state_idx)) { 309 - if (genpd->state_idx == 0) { 232 + /* 233 + * Find a state to power down to, starting from the state 234 + * determined by the next wakeup. 235 + */ 236 + while (!__default_power_down_ok(pd, state_idx)) { 237 + if (state_idx == 0) { 310 238 genpd->cached_power_down_ok = false; 311 239 break; 312 240 } 313 - genpd->state_idx--; 241 + state_idx--; 314 242 } 315 243 244 + done: 245 + genpd->state_idx = state_idx; 316 246 genpd->cached_power_down_state_idx = genpd->state_idx; 317 247 return genpd->cached_power_down_ok; 248 + } 249 + 250 + static bool default_power_down_ok(struct dev_pm_domain *pd) 251 + { 252 + return _default_power_down_ok(pd, ktime_get()); 318 253 } 319 254 320 255 static bool always_on_power_down_ok(struct dev_pm_domain *domain) ··· 337 254 struct generic_pm_domain *genpd = pd_to_genpd(pd); 338 255 struct cpuidle_device *dev; 339 256 ktime_t domain_wakeup, next_hrtimer; 257 + ktime_t now = ktime_get(); 340 258 s64 idle_duration_ns; 341 259 int cpu, i; 342 260 343 261 /* Validate dev PM QoS constraints. */ 344 - if (!default_power_down_ok(pd)) 262 + if (!_default_power_down_ok(pd, now)) 345 263 return false; 346 264 347 265 if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN)) ··· 364 280 } 365 281 366 282 /* The minimum idle duration is from now - until the next wakeup. */ 367 - idle_duration_ns = ktime_to_ns(ktime_sub(domain_wakeup, ktime_get())); 283 + idle_duration_ns = ktime_to_ns(ktime_sub(domain_wakeup, now)); 368 284 if (idle_duration_ns <= 0) 369 285 return false; 370 286
+5 -4
drivers/base/power/main.c
··· 16 16 */ 17 17 18 18 #define pr_fmt(fmt) "PM: " fmt 19 + #define dev_fmt pr_fmt 19 20 20 21 #include <linux/device.h> 21 22 #include <linux/export.h> ··· 450 449 static void pm_dev_err(struct device *dev, pm_message_t state, const char *info, 451 450 int error) 452 451 { 453 - pr_err("Device %s failed to %s%s: error %d\n", 454 - dev_name(dev), pm_verb(state.event), info, error); 452 + dev_err(dev, "failed to %s%s: error %d\n", pm_verb(state.event), info, 453 + error); 455 454 } 456 455 457 456 static void dpm_show_time(ktime_t starttime, pm_message_t state, int error, ··· 1898 1897 error = 0; 1899 1898 continue; 1900 1899 } 1901 - pr_info("Device %s not prepared for power transition: code %d\n", 1902 - dev_name(dev), error); 1900 + dev_info(dev, "not prepared for power transition: code %d\n", 1901 + error); 1903 1902 put_device(dev); 1904 1903 break; 1905 1904 }
+1 -1
drivers/base/power/runtime.c
··· 1100 1100 * suspending the device when both its runtime PM status is %RPM_ACTIVE and its 1101 1101 * runtime PM usage counter is not zero. 1102 1102 * 1103 - * The caller is resposible for decrementing the runtime PM usage counter of 1103 + * The caller is responsible for decrementing the runtime PM usage counter of 1104 1104 * @dev after this function has returned a positive value for it. 1105 1105 */ 1106 1106 int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
+21
drivers/clk/clk.c
··· 1164 1164 } 1165 1165 EXPORT_SYMBOL_GPL(clk_enable); 1166 1166 1167 + /** 1168 + * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it. 1169 + * @clk: clock source 1170 + * 1171 + * Returns true if clk_prepare() implicitly enables the clock, effectively 1172 + * making clk_enable()/clk_disable() no-ops, false otherwise. 1173 + * 1174 + * This is of interest mainly to power management code where actually 1175 + * disabling the clock also requires unpreparing it to have any material 1176 + * effect. 1177 + * 1178 + * Regardless of the value returned here, the caller must always invoke 1179 + * clk_enable() or clk_prepare_enable() and counterparts for usage counts 1180 + * to be right. 1181 + */ 1182 + bool clk_is_enabled_when_prepared(struct clk *clk) 1183 + { 1184 + return clk && !(clk->core->ops->enable && clk->core->ops->disable); 1185 + } 1186 + EXPORT_SYMBOL_GPL(clk_is_enabled_when_prepared); 1187 + 1167 1188 static int clk_core_prepare_enable(struct clk_core *core) 1168 1189 { 1169 1190 int ret;
+23 -1
include/linux/clk.h
··· 238 238 239 239 #endif 240 240 241 + #ifdef CONFIG_HAVE_CLK_PREPARE 241 242 /** 242 243 * clk_prepare - prepare a clock source 243 244 * @clk: clock source ··· 247 246 * 248 247 * Must not be called from within atomic context. 249 248 */ 250 - #ifdef CONFIG_HAVE_CLK_PREPARE 251 249 int clk_prepare(struct clk *clk); 252 250 int __must_check clk_bulk_prepare(int num_clks, 253 251 const struct clk_bulk_data *clks); 252 + 253 + /** 254 + * clk_is_enabled_when_prepared - indicate if preparing a clock also enables it. 255 + * @clk: clock source 256 + * 257 + * Returns true if clk_prepare() implicitly enables the clock, effectively 258 + * making clk_enable()/clk_disable() no-ops, false otherwise. 259 + * 260 + * This is of interest mainly to the power management code where actually 261 + * disabling the clock also requires unpreparing it to have any material 262 + * effect. 263 + * 264 + * Regardless of the value returned here, the caller must always invoke 265 + * clk_enable() or clk_prepare_enable() and counterparts for usage counts 266 + * to be right. 267 + */ 268 + bool clk_is_enabled_when_prepared(struct clk *clk); 254 269 #else 255 270 static inline int clk_prepare(struct clk *clk) 256 271 { ··· 279 262 { 280 263 might_sleep(); 281 264 return 0; 265 + } 266 + 267 + static inline bool clk_is_enabled_when_prepared(struct clk *clk) 268 + { 269 + return false; 282 270 } 283 271 #endif 284 272
+2
include/linux/pm.h
··· 537 537 spinlock_t lock; 538 538 unsigned int refcount; 539 539 #ifdef CONFIG_PM_CLK 540 + unsigned int clock_op_might_sleep; 541 + struct mutex clock_mutex; 540 542 struct list_head clock_list; 541 543 #endif 542 544 #ifdef CONFIG_PM_GENERIC_DOMAINS
+12
include/linux/pm_domain.h
··· 9 9 #define _LINUX_PM_DOMAIN_H 10 10 11 11 #include <linux/device.h> 12 + #include <linux/ktime.h> 12 13 #include <linux/mutex.h> 13 14 #include <linux/pm.h> 14 15 #include <linux/err.h> ··· 56 55 * 57 56 * GENPD_FLAG_RPM_ALWAYS_ON: Instructs genpd to always keep the PM domain 58 57 * powered on except for system suspend. 58 + * 59 + * GENPD_FLAG_MIN_RESIDENCY: Enable the genpd governor to consider its 60 + * components' next wakeup when determining the 61 + * optimal idle state. 59 62 */ 60 63 #define GENPD_FLAG_PM_CLK (1U << 0) 61 64 #define GENPD_FLAG_IRQ_SAFE (1U << 1) ··· 67 62 #define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) 68 63 #define GENPD_FLAG_CPU_DOMAIN (1U << 4) 69 64 #define GENPD_FLAG_RPM_ALWAYS_ON (1U << 5) 65 + #define GENPD_FLAG_MIN_RESIDENCY (1U << 6) 70 66 71 67 enum gpd_status { 72 68 GENPD_STATE_ON = 0, /* PM domain is on */ ··· 135 129 unsigned int state); 136 130 struct gpd_dev_ops dev_ops; 137 131 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ 132 + ktime_t next_wakeup; /* Maintained by the domain governor */ 138 133 bool max_off_time_changed; 139 134 bool cached_power_down_ok; 140 135 bool cached_power_down_state_idx; ··· 198 191 struct notifier_block *power_nb; 199 192 int cpu; 200 193 unsigned int performance_state; 194 + ktime_t next_wakeup; 201 195 void *data; 202 196 }; 203 197 ··· 225 217 int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); 226 218 int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); 227 219 int dev_pm_genpd_remove_notifier(struct device *dev); 220 + void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next); 228 221 229 222 extern struct dev_power_governor simple_qos_governor; 230 223 extern struct dev_power_governor pm_domain_always_on_gov; ··· 283 274 { 284 275 return -EOPNOTSUPP; 285 276 } 277 + 278 + static inline void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) 279 + { } 286 280 287 281 #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) 288 282 #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
+1 -1
kernel/power/main.c
··· 387 387 NULL, 388 388 }; 389 389 390 - static struct attribute_group suspend_attr_group = { 390 + static const struct attribute_group suspend_attr_group = { 391 391 .name = "suspend_stats", 392 392 .attrs = suspend_attrs, 393 393 };
+1 -1
kernel/power/process.c
··· 235 235 236 236 read_lock(&tasklist_lock); 237 237 for_each_process_thread(g, p) { 238 - if (p->flags & (PF_KTHREAD | PF_WQ_WORKER)) 238 + if (p->flags & PF_KTHREAD) 239 239 __thaw_task(p); 240 240 } 241 241 read_unlock(&tasklist_lock);