History

Merge back earlier PM core material for v5.1.

Rafael J. Wysocki committed 7 years ago

Commit 656f72b2 parents 74fb448 85945c210 files · +108 −43Browse files

Unified · Split

10 files
  1. drivers/base/cpu.c +1 −0
  2. drivers/base/power/clock_ops.c +9 −4
  3. drivers/base/power/main.c +10 −1
  4. drivers/base/power/runtime.c +50 −20
  5. drivers/base/power/sysfs.c +14 −3
  6. drivers/gpu/drm/i915/i915_pmu.c +6 −10
  7. drivers/gpu/drm/i915/i915_pmu.h +2 −2
  8. include/linux/device.h +10 −0
  9. include/linux/pm.h +4 −3
  10. include/linux/pm_runtime.h +2 −0
drivers/base/cpu.c+1−0
@@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, · 426 unmodified lines
427427 dev->parent = parent;
428428 dev->groups = groups;
429429 dev->release = device_create_release;
430+ device_set_pm_not_required(dev);
430431 dev_set_drvdata(dev, drvdata);
431432
432433 retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
drivers/base/power/clock_ops.c+9−4
@@ -65,10 +65,15 @@ static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce) · 64 unmodified lines
6565 if (IS_ERR(ce->clk)) {
6666 ce->status = PCE_STATUS_ERROR;
6767 } 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+ }
7277 }
7378 }
7479
drivers/base/power/main.c+10−1
@@ -124,6 +124,10 @@ void device_pm_unlock(void) · 123 unmodified lines
124124 */
125125 void device_pm_add(struct device *dev)
126126 {
127+ /* Skip PM setup/initialization. */
128+ if (device_pm_not_required(dev))
129+ return;
130+
127131 pr_debug("PM: Adding info for %s:%s\n",
128132 dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
129133 device_pm_check_callbacks(dev);
@@ -142,6 +146,9 @@ void device_pm_add(struct device *dev) · 12 unmodified lines
142146 */
143147 void device_pm_remove(struct device *dev)
144148 {
149+ if (device_pm_not_required(dev))
150+ return;
151+
145152 pr_debug("PM: Removing info for %s:%s\n",
146153 dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
147154 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
17411748 if (dev->power.direct_complete) {
17421749 if (pm_runtime_status_suspended(dev)) {
17431750 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 ");
17451753 goto Complete;
1754+ }
17461755
17471756 pm_runtime_enable(dev);
17481757 }
drivers/base/power/runtime.c+50−20
@@ -66,20 +66,30 @@ static int rpm_suspend(struct device *dev, int rpmflags); · 65 unmodified lines
6666 */
6767 void update_pm_runtime_accounting(struct device *dev)
6868 {
69− unsigned long now = jiffies;
70− unsigned long delta;
69+ u64 now, last, delta;
7170
72− delta = now - dev->power.accounting_timestamp;
71+ if (dev->power.disable_depth > 0)
72+ return;
73+
74+ last = dev->power.accounting_timestamp;
7375
76+ now = ktime_get_mono_fast_ns();
7477 dev->power.accounting_timestamp = now;
7578
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)
7785 return;
7886
87+ delta = now - last;
88+
7989 if (dev->power.runtime_status == RPM_SUSPENDED)
80− dev->power.suspended_jiffies += delta;
90+ dev->power.suspended_time += delta;
8191 else
82− dev->power.active_jiffies += delta;
92+ dev->power.active_time += delta;
8393 }
8494
8595 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
8898 dev->power.runtime_status = status;
8999 }
90100
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+
91117 /**
92118 * pm_runtime_deactivate_timer - Deactivate given device's suspend timer.
93119 * @dev: Device to handle.
@@ -129,24 +155,21 @@ static void pm_runtime_cancel_pending(struct device *dev) · 35 unmodified lines
129155 u64 pm_runtime_autosuspend_expiration(struct device *dev)
130156 {
131157 int autosuspend_delay;
132− u64 last_busy, expires = 0;
133− u64 now = ktime_get_mono_fast_ns();
158+ u64 expires;
134159
135160 if (!dev->power.use_autosuspend)
136− goto out;
161+ return 0;
137162
138163 autosuspend_delay = READ_ONCE(dev->power.autosuspend_delay);
139164 if (autosuspend_delay < 0)
140− goto out;
141−
142− last_busy = READ_ONCE(dev->power.last_busy);
165+ return 0;
143166
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 */
147171
148− out:
149− return expires;
172+ return 0;
150173 }
151174 EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
152175
@@ -1276,6 +1299,9 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) · 1123 unmodified lines
12761299 pm_runtime_put_noidle(dev);
12771300 }
12781301
1302+ /* Update time accounting before disabling PM-runtime. */
1303+ update_pm_runtime_accounting(dev);
1304+
12791305 if (!dev->power.disable_depth++)
12801306 __pm_runtime_barrier(dev);
12811307
@@ -1294,10 +1320,15 @@ void pm_runtime_enable(struct device *dev) · 12 unmodified lines
12941320
12951321 spin_lock_irqsave(&dev->power.lock, flags);
12961322
1297− if (dev->power.disable_depth > 0)
1323+ if (dev->power.disable_depth > 0) {
12981324 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 {
13001330 dev_warn(dev, "Unbalanced %s!\n", __func__);
1331+ }
13011332
13021333 WARN(!dev->power.disable_depth &&
13031334 dev->power.runtime_status == RPM_SUSPENDED &&
@@ -1494,7 +1525,6 @@ void pm_runtime_init(struct device *dev) · 190 unmodified lines
14941525 dev->power.request_pending = false;
14951526 dev->power.request = RPM_REQ_NONE;
14961527 dev->power.deferred_resume = false;
1497− dev->power.accounting_timestamp = jiffies;
14981528 INIT_WORK(&dev->power.work, pm_runtime_work);
14991529
15001530 dev->power.timer_expires = 0;
drivers/base/power/sysfs.c+14−3
@@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev, · 124 unmodified lines
125125 struct device_attribute *attr, char *buf)
126126 {
127127 int ret;
128+ u64 tmp;
128129 spin_lock_irq(&dev->power.lock);
129130 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);
131134 spin_unlock_irq(&dev->power.lock);
132135 return ret;
133136 }
@@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev, · 4 unmodified lines
138141 struct device_attribute *attr, char *buf)
139142 {
140143 int ret;
144+ u64 tmp;
141145 spin_lock_irq(&dev->power.lock);
142146 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);
145150 spin_unlock_irq(&dev->power.lock);
146151 return ret;
147152 }
@@ -648,6 +653,10 @@ int dpm_sysfs_add(struct device *dev) · 500 unmodified lines
648653 {
649654 int rc;
650655
656+ /* No need to create PM sysfs if explicitly disabled. */
657+ if (device_pm_not_required(dev))
658+ return 0;
659+
651660 rc = sysfs_create_group(&dev->kobj, &pm_attr_group);
652661 if (rc)
653662 return rc;
@@ -727,6 +736,8 @@ void rpm_sysfs_remove(struct device *dev) · 73 unmodified lines
727736
728737 void dpm_sysfs_remove(struct device *dev)
729738 {
739+ if (device_pm_not_required(dev))
740+ return;
730741 sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group);
731742 dev_pm_qos_constraints_destroy(dev);
732743 rpm_sysfs_remove(dev);
drivers/gpu/drm/i915/i915_pmu.c+6−10
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 */
66
77 #include <linux/irq.h>
8+#include <linux/pm_runtime.h>
89 #include "i915_pmu.h"
910 #include "intel_ringbuffer.h"
1011 #include "i915_drv.h"
@@ -478,7 +479,6 @@ static u64 get_rc6(struct drm_i915_private *i915) · 467 unmodified lines
478479 * counter value.
479480 */
480481 spin_lock_irqsave(&i915->pmu.lock, flags);
481− spin_lock(&kdev->power.lock);
482482
483483 /*
484484 * 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
491491 * suspended and if not we cannot do better than report the last
492492 * known RC6 value.
493493 */
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);
498496
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;
502499
503− val = jiffies_to_nsecs(val);
500+ val -= i915->pmu.suspended_time_last;
504501 val += i915->pmu.sample[__I915_SAMPLE_RC6].cur;
505502
506503 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
510507 val = i915->pmu.sample[__I915_SAMPLE_RC6].cur;
511508 }
512509
513− spin_unlock(&kdev->power.lock);
514510 spin_unlock_irqrestore(&i915->pmu.lock, flags);
515511 }
516512
drivers/gpu/drm/i915/i915_pmu.h+2−2
@@ -97,9 +97,9 @@ struct i915_pmu { · 96 unmodified lines
9797 */
9898 struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
9999 /**
100− * @suspended_jiffies_last: Cached suspend time from PM core.
100+ * @suspended_time_last: Cached suspend time from PM core.
101101 */
102− unsigned long suspended_jiffies_last;
102+ u64 suspended_time_last;
103103 /**
104104 * @i915_attr: Memory block holding device attributes.
105105 */
include/linux/device.h+10−0
@@ -1165,6 +1165,16 @@ static inline bool device_async_suspend_enabled(struct device *dev) · 1164 unmodified lines
11651165 return !!dev->power.async_suspend;
11661166 }
11671167
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+
11681178 static inline void dev_pm_syscore_device(struct device *dev, bool val)
11691179 {
11701180 #ifdef CONFIG_PM_SLEEP
include/linux/pm.h+4−3
@@ -592,6 +592,7 @@ struct dev_pm_info { · 591 unmodified lines
592592 bool is_suspended:1; /* Ditto */
593593 bool is_noirq_suspended:1;
594594 bool is_late_suspended:1;
595+ bool no_pm:1;
595596 bool early_init:1; /* Owned by the PM core */
596597 bool direct_complete:1; /* Owned by the PM core */
597598 u32 driver_flags;
@@ -633,9 +634,9 @@ struct dev_pm_info { · 35 unmodified lines
633634 int runtime_error;
634635 int autosuspend_delay;
635636 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;
639640 #endif
640641 struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */
641642 void (*set_latency_tolerance)(struct device *, s32);
include/linux/pm_runtime.h+2−0
@@ -113,6 +113,8 @@ static inline bool pm_runtime_is_irq_safe(struct device *dev) · 112 unmodified lines
113113 return dev->power.irq_safe;
114114 }
115115
116+extern u64 pm_runtime_suspended_time(struct device *dev);
117+
116118 #else /* !CONFIG_PM */
117119
118120 static inline bool queue_pm_work(struct work_struct *work) { return false; }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t