Unified · Split
| @@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, · 426 unmodified lines | ||
| 427 | 427 | dev->parent = parent; |
| 428 | 428 | dev->groups = groups; |
| 429 | 429 | dev->release = device_create_release; |
| 430 | + device_set_pm_not_required(dev); | |
| 430 | 431 | dev_set_drvdata(dev, drvdata); |
| 431 | 432 | |
| 432 | 433 | retval = kobject_set_name_vargs(&dev->kobj, fmt, args); |
| @@ -65,10 +65,15 @@ static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce) · 64 unmodified lines | ||
| 65 | 65 | if (IS_ERR(ce->clk)) { |
| 66 | 66 | ce->status = PCE_STATUS_ERROR; |
| 67 | 67 | } else { |
| 68 | − clk_prepare(ce->clk); | |
| 69 | − ce->status = PCE_STATUS_ACQUIRED; | |
| 70 | − dev_dbg(dev, "Clock %pC con_id %s managed by runtime PM.\n", | |
| 71 | − ce->clk, ce->con_id); | |
| 68 | + if (clk_prepare(ce->clk)) { | |
| 69 | + ce->status = PCE_STATUS_ERROR; | |
| 70 | + dev_err(dev, "clk_prepare() failed\n"); | |
| 71 | + } else { | |
| 72 | + ce->status = PCE_STATUS_ACQUIRED; | |
| 73 | + dev_dbg(dev, | |
| 74 | + "Clock %pC con_id %s managed by runtime PM.\n", | |
| 75 | + ce->clk, ce->con_id); | |
| 76 | + } | |
| 72 | 77 | } |
| 73 | 78 | } |
| 74 | 79 | |
| @@ -124,6 +124,10 @@ void device_pm_unlock(void) · 123 unmodified lines | ||
| 124 | 124 | */ |
| 125 | 125 | void device_pm_add(struct device *dev) |
| 126 | 126 | { |
| 127 | + /* Skip PM setup/initialization. */ | |
| 128 | + if (device_pm_not_required(dev)) | |
| 129 | + return; | |
| 130 | + | |
| 127 | 131 | pr_debug("PM: Adding info for %s:%s\n", |
| 128 | 132 | dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); |
| 129 | 133 | device_pm_check_callbacks(dev); |
| @@ -142,6 +146,9 @@ void device_pm_add(struct device *dev) · 12 unmodified lines | ||
| 142 | 146 | */ |
| 143 | 147 | void device_pm_remove(struct device *dev) |
| 144 | 148 | { |
| 149 | + if (device_pm_not_required(dev)) | |
| 150 | + return; | |
| 151 | + | |
| 145 | 152 | pr_debug("PM: Removing info for %s:%s\n", |
| 146 | 153 | dev->bus ? dev->bus->name : "No Bus", dev_name(dev)); |
| 147 | 154 | complete_all(&dev->power.completion); |
| @@ -1741,8 +1748,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) · 1593 unmodified lines | ||
| 1741 | 1748 | if (dev->power.direct_complete) { |
| 1742 | 1749 | if (pm_runtime_status_suspended(dev)) { |
| 1743 | 1750 | pm_runtime_disable(dev); |
| 1744 | − if (pm_runtime_status_suspended(dev)) | |
| 1751 | + if (pm_runtime_status_suspended(dev)) { | |
| 1752 | + pm_dev_dbg(dev, state, "direct-complete "); | |
| 1745 | 1753 | goto Complete; |
| 1754 | + } | |
| 1746 | 1755 | |
| 1747 | 1756 | pm_runtime_enable(dev); |
| 1748 | 1757 | } |
| @@ -66,20 +66,30 @@ static int rpm_suspend(struct device *dev, int rpmflags); · 65 unmodified lines | ||
| 66 | 66 | */ |
| 67 | 67 | void update_pm_runtime_accounting(struct device *dev) |
| 68 | 68 | { |
| 69 | − unsigned long now = jiffies; | |
| 70 | − unsigned long delta; | |
| 69 | + u64 now, last, delta; | |
| 71 | 70 | |
| 72 | − delta = now - dev->power.accounting_timestamp; | |
| 71 | + if (dev->power.disable_depth > 0) | |
| 72 | + return; | |
| 73 | + | |
| 74 | + last = dev->power.accounting_timestamp; | |
| 73 | 75 | |
| 76 | + now = ktime_get_mono_fast_ns(); | |
| 74 | 77 | dev->power.accounting_timestamp = now; |
| 75 | 78 | |
| 76 | − if (dev->power.disable_depth > 0) | |
| 79 | + /* | |
| 80 | + * Because ktime_get_mono_fast_ns() is not monotonic during | |
| 81 | + * timekeeping updates, ensure that 'now' is after the last saved | |
| 82 | + * timesptamp. | |
| 83 | + */ | |
| 84 | + if (now < last) | |
| 77 | 85 | return; |
| 78 | 86 | |
| 87 | + delta = now - last; | |
| 88 | + | |
| 79 | 89 | if (dev->power.runtime_status == RPM_SUSPENDED) |
| 80 | − dev->power.suspended_jiffies += delta; | |
| 90 | + dev->power.suspended_time += delta; | |
| 81 | 91 | else |
| 82 | − dev->power.active_jiffies += delta; | |
| 92 | + dev->power.active_time += delta; | |
| 83 | 93 | } |
| 84 | 94 | |
| 85 | 95 | static void __update_runtime_status(struct device *dev, enum rpm_status status) |
| @@ -88,6 +98,22 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status) · 2 unmodified lines | ||
| 88 | 98 | dev->power.runtime_status = status; |
| 89 | 99 | } |
| 90 | 100 | |
| 101 | +u64 pm_runtime_suspended_time(struct device *dev) | |
| 102 | +{ | |
| 103 | + u64 time; | |
| 104 | + unsigned long flags; | |
| 105 | + | |
| 106 | + spin_lock_irqsave(&dev->power.lock, flags); | |
| 107 | + | |
| 108 | + update_pm_runtime_accounting(dev); | |
| 109 | + time = dev->power.suspended_time; | |
| 110 | + | |
| 111 | + spin_unlock_irqrestore(&dev->power.lock, flags); | |
| 112 | + | |
| 113 | + return time; | |
| 114 | +} | |
| 115 | +EXPORT_SYMBOL_GPL(pm_runtime_suspended_time); | |
| 116 | + | |
| 91 | 117 | /** |
| 92 | 118 | * pm_runtime_deactivate_timer - Deactivate given device's suspend timer. |
| 93 | 119 | * @dev: Device to handle. |
| @@ -129,24 +155,21 @@ static void pm_runtime_cancel_pending(struct device *dev) · 35 unmodified lines | ||
| 129 | 155 | u64 pm_runtime_autosuspend_expiration(struct device *dev) |
| 130 | 156 | { |
| 131 | 157 | int autosuspend_delay; |
| 132 | − u64 last_busy, expires = 0; | |
| 133 | − u64 now = ktime_get_mono_fast_ns(); | |
| 158 | + u64 expires; | |
| 134 | 159 | |
| 135 | 160 | if (!dev->power.use_autosuspend) |
| 136 | − goto out; | |
| 161 | + return 0; | |
| 137 | 162 | |
| 138 | 163 | autosuspend_delay = READ_ONCE(dev->power.autosuspend_delay); |
| 139 | 164 | if (autosuspend_delay < 0) |
| 140 | − goto out; | |
| 141 | − | |
| 142 | − last_busy = READ_ONCE(dev->power.last_busy); | |
| 165 | + return 0; | |
| 143 | 166 | |
| 144 | − expires = last_busy + (u64)autosuspend_delay * NSEC_PER_MSEC; | |
| 145 | − if (expires <= now) | |
| 146 | − expires = 0; /* Already expired. */ | |
| 167 | + expires = READ_ONCE(dev->power.last_busy); | |
| 168 | + expires += (u64)autosuspend_delay * NSEC_PER_MSEC; | |
| 169 | + if (expires > ktime_get_mono_fast_ns()) | |
| 170 | + return expires; /* Expires in the future */ | |
| 147 | 171 | |
| 148 | − out: | |
| 149 | − return expires; | |
| 172 | + return 0; | |
| 150 | 173 | } |
| 151 | 174 | EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration); |
| 152 | 175 | |
| @@ -1276,6 +1299,9 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) · 1123 unmodified lines | ||
| 1276 | 1299 | pm_runtime_put_noidle(dev); |
| 1277 | 1300 | } |
| 1278 | 1301 | |
| 1302 | + /* Update time accounting before disabling PM-runtime. */ | |
| 1303 | + update_pm_runtime_accounting(dev); | |
| 1304 | + | |
| 1279 | 1305 | if (!dev->power.disable_depth++) |
| 1280 | 1306 | __pm_runtime_barrier(dev); |
| 1281 | 1307 | |
| @@ -1294,10 +1320,15 @@ void pm_runtime_enable(struct device *dev) · 12 unmodified lines | ||
| 1294 | 1320 | |
| 1295 | 1321 | spin_lock_irqsave(&dev->power.lock, flags); |
| 1296 | 1322 | |
| 1297 | − if (dev->power.disable_depth > 0) | |
| 1323 | + if (dev->power.disable_depth > 0) { | |
| 1298 | 1324 | dev->power.disable_depth--; |
| 1299 | − else | |
| 1325 | + | |
| 1326 | + /* About to enable runtime pm, set accounting_timestamp to now */ | |
| 1327 | + if (!dev->power.disable_depth) | |
| 1328 | + dev->power.accounting_timestamp = ktime_get_mono_fast_ns(); | |
| 1329 | + } else { | |
| 1300 | 1330 | dev_warn(dev, "Unbalanced %s!\n", __func__); |
| 1331 | + } | |
| 1301 | 1332 | |
| 1302 | 1333 | WARN(!dev->power.disable_depth && |
| 1303 | 1334 | dev->power.runtime_status == RPM_SUSPENDED && |
| @@ -1494,7 +1525,6 @@ void pm_runtime_init(struct device *dev) · 190 unmodified lines | ||
| 1494 | 1525 | dev->power.request_pending = false; |
| 1495 | 1526 | dev->power.request = RPM_REQ_NONE; |
| 1496 | 1527 | dev->power.deferred_resume = false; |
| 1497 | − dev->power.accounting_timestamp = jiffies; | |
| 1498 | 1528 | INIT_WORK(&dev->power.work, pm_runtime_work); |
| 1499 | 1529 | |
| 1500 | 1530 | dev->power.timer_expires = 0; |
| @@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev, · 124 unmodified lines | ||
| 125 | 125 | struct device_attribute *attr, char *buf) |
| 126 | 126 | { |
| 127 | 127 | int ret; |
| 128 | + u64 tmp; | |
| 128 | 129 | spin_lock_irq(&dev->power.lock); |
| 129 | 130 | update_pm_runtime_accounting(dev); |
| 130 | − ret = sprintf(buf, "%i\n", jiffies_to_msecs(dev->power.active_jiffies)); | |
| 131 | + tmp = dev->power.active_time; | |
| 132 | + do_div(tmp, NSEC_PER_MSEC); | |
| 133 | + ret = sprintf(buf, "%llu\n", tmp); | |
| 131 | 134 | spin_unlock_irq(&dev->power.lock); |
| 132 | 135 | return ret; |
| 133 | 136 | } |
| @@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev, · 4 unmodified lines | ||
| 138 | 141 | struct device_attribute *attr, char *buf) |
| 139 | 142 | { |
| 140 | 143 | int ret; |
| 144 | + u64 tmp; | |
| 141 | 145 | spin_lock_irq(&dev->power.lock); |
| 142 | 146 | update_pm_runtime_accounting(dev); |
| 143 | − ret = sprintf(buf, "%i\n", | |
| 144 | − jiffies_to_msecs(dev->power.suspended_jiffies)); | |
| 147 | + tmp = dev->power.suspended_time; | |
| 148 | + do_div(tmp, NSEC_PER_MSEC); | |
| 149 | + ret = sprintf(buf, "%llu\n", tmp); | |
| 145 | 150 | spin_unlock_irq(&dev->power.lock); |
| 146 | 151 | return ret; |
| 147 | 152 | } |
| @@ -648,6 +653,10 @@ int dpm_sysfs_add(struct device *dev) · 500 unmodified lines | ||
| 648 | 653 | { |
| 649 | 654 | int rc; |
| 650 | 655 | |
| 656 | + /* No need to create PM sysfs if explicitly disabled. */ | |
| 657 | + if (device_pm_not_required(dev)) | |
| 658 | + return 0; | |
| 659 | + | |
| 651 | 660 | rc = sysfs_create_group(&dev->kobj, &pm_attr_group); |
| 652 | 661 | if (rc) |
| 653 | 662 | return rc; |
| @@ -727,6 +736,8 @@ void rpm_sysfs_remove(struct device *dev) · 73 unmodified lines | ||
| 727 | 736 | |
| 728 | 737 | void dpm_sysfs_remove(struct device *dev) |
| 729 | 738 | { |
| 739 | + if (device_pm_not_required(dev)) | |
| 740 | + return; | |
| 730 | 741 | sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group); |
| 731 | 742 | dev_pm_qos_constraints_destroy(dev); |
| 732 | 743 | rpm_sysfs_remove(dev); |
| @@ -5,6 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #include <linux/irq.h> |
| 8 | +#include <linux/pm_runtime.h> | |
| 8 | 9 | #include "i915_pmu.h" |
| 9 | 10 | #include "intel_ringbuffer.h" |
| 10 | 11 | #include "i915_drv.h" |
| @@ -478,7 +479,6 @@ static u64 get_rc6(struct drm_i915_private *i915) · 467 unmodified lines | ||
| 478 | 479 | * counter value. |
| 479 | 480 | */ |
| 480 | 481 | spin_lock_irqsave(&i915->pmu.lock, flags); |
| 481 | − spin_lock(&kdev->power.lock); | |
| 482 | 482 | |
| 483 | 483 | /* |
| 484 | 484 | * After the above branch intel_runtime_pm_get_if_in_use failed |
| @@ -491,16 +491,13 @@ static u64 get_rc6(struct drm_i915_private *i915) · 6 unmodified lines | ||
| 491 | 491 | * suspended and if not we cannot do better than report the last |
| 492 | 492 | * known RC6 value. |
| 493 | 493 | */ |
| 494 | − if (kdev->power.runtime_status == RPM_SUSPENDED) { | |
| 495 | − if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) | |
| 496 | − i915->pmu.suspended_jiffies_last = | |
| 497 | − kdev->power.suspended_jiffies; | |
| 494 | + if (pm_runtime_status_suspended(kdev)) { | |
| 495 | + val = pm_runtime_suspended_time(kdev); | |
| 498 | 496 | |
| 499 | − val = kdev->power.suspended_jiffies - | |
| 500 | − i915->pmu.suspended_jiffies_last; | |
| 501 | − val += jiffies - kdev->power.accounting_timestamp; | |
| 497 | + if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) | |
| 498 | + i915->pmu.suspended_time_last = val; | |
| 502 | 499 | |
| 503 | − val = jiffies_to_nsecs(val); | |
| 500 | + val -= i915->pmu.suspended_time_last; | |
| 504 | 501 | val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; |
| 505 | 502 | |
| 506 | 503 | i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; |
| @@ -510,7 +507,6 @@ static u64 get_rc6(struct drm_i915_private *i915) · 3 unmodified lines | ||
| 510 | 507 | val = i915->pmu.sample[__I915_SAMPLE_RC6].cur; |
| 511 | 508 | } |
| 512 | 509 | |
| 513 | − spin_unlock(&kdev->power.lock); | |
| 514 | 510 | spin_unlock_irqrestore(&i915->pmu.lock, flags); |
| 515 | 511 | } |
| 516 | 512 | |
| @@ -97,9 +97,9 @@ struct i915_pmu { · 96 unmodified lines | ||
| 97 | 97 | */ |
| 98 | 98 | struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS]; |
| 99 | 99 | /** |
| 100 | − * @suspended_jiffies_last: Cached suspend time from PM core. | |
| 100 | + * @suspended_time_last: Cached suspend time from PM core. | |
| 101 | 101 | */ |
| 102 | − unsigned long suspended_jiffies_last; | |
| 102 | + u64 suspended_time_last; | |
| 103 | 103 | /** |
| 104 | 104 | * @i915_attr: Memory block holding device attributes. |
| 105 | 105 | */ |
| @@ -1165,6 +1165,16 @@ static inline bool device_async_suspend_enabled(struct device *dev) · 1164 unmodified lines | ||
| 1165 | 1165 | return !!dev->power.async_suspend; |
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | +static inline bool device_pm_not_required(struct device *dev) | |
| 1169 | +{ | |
| 1170 | + return dev->power.no_pm; | |
| 1171 | +} | |
| 1172 | + | |
| 1173 | +static inline void device_set_pm_not_required(struct device *dev) | |
| 1174 | +{ | |
| 1175 | + dev->power.no_pm = true; | |
| 1176 | +} | |
| 1177 | + | |
| 1168 | 1178 | static inline void dev_pm_syscore_device(struct device *dev, bool val) |
| 1169 | 1179 | { |
| 1170 | 1180 | #ifdef CONFIG_PM_SLEEP |
| @@ -592,6 +592,7 @@ struct dev_pm_info { · 591 unmodified lines | ||
| 592 | 592 | bool is_suspended:1; /* Ditto */ |
| 593 | 593 | bool is_noirq_suspended:1; |
| 594 | 594 | bool is_late_suspended:1; |
| 595 | + bool no_pm:1; | |
| 595 | 596 | bool early_init:1; /* Owned by the PM core */ |
| 596 | 597 | bool direct_complete:1; /* Owned by the PM core */ |
| 597 | 598 | u32 driver_flags; |
| @@ -633,9 +634,9 @@ struct dev_pm_info { · 35 unmodified lines | ||
| 633 | 634 | int runtime_error; |
| 634 | 635 | int autosuspend_delay; |
| 635 | 636 | u64 last_busy; |
| 636 | − unsigned long active_jiffies; | |
| 637 | − unsigned long suspended_jiffies; | |
| 638 | − unsigned long accounting_timestamp; | |
| 637 | + u64 active_time; | |
| 638 | + u64 suspended_time; | |
| 639 | + u64 accounting_timestamp; | |
| 639 | 640 | #endif |
| 640 | 641 | struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ |
| 641 | 642 | void (*set_latency_tolerance)(struct device *, s32); |
| @@ -113,6 +113,8 @@ static inline bool pm_runtime_is_irq_safe(struct device *dev) · 112 unmodified lines | ||
| 113 | 113 | return dev->power.irq_safe; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | +extern u64 pm_runtime_suspended_time(struct device *dev); | |
| 117 | + | |
| 116 | 118 | #else /* !CONFIG_PM */ |
| 117 | 119 | |
| 118 | 120 | static inline bool queue_pm_work(struct work_struct *work) { return false; } |