Commit 1cc9c595 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge back earlier PM core material for v5.1.

parents 15efb47d a08c2a5a
...@@ -65,11 +65,16 @@ static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce) ...@@ -65,11 +65,16 @@ static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce)
if (IS_ERR(ce->clk)) { if (IS_ERR(ce->clk)) {
ce->status = PCE_STATUS_ERROR; ce->status = PCE_STATUS_ERROR;
} else { } else {
clk_prepare(ce->clk); if (clk_prepare(ce->clk)) {
ce->status = PCE_STATUS_ERROR;
dev_err(dev, "clk_prepare() failed\n");
} else {
ce->status = PCE_STATUS_ACQUIRED; ce->status = PCE_STATUS_ACQUIRED;
dev_dbg(dev, "Clock %pC con_id %s managed by runtime PM.\n", dev_dbg(dev,
"Clock %pC con_id %s managed by runtime PM.\n",
ce->clk, ce->con_id); ce->clk, ce->con_id);
} }
}
} }
static int __pm_clk_add(struct device *dev, const char *con_id, static int __pm_clk_add(struct device *dev, const char *con_id,
......
...@@ -66,8 +66,8 @@ static int rpm_suspend(struct device *dev, int rpmflags); ...@@ -66,8 +66,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
*/ */
void update_pm_runtime_accounting(struct device *dev) void update_pm_runtime_accounting(struct device *dev)
{ {
unsigned long now = jiffies; u64 now = ktime_to_ns(ktime_get());
unsigned long delta; u64 delta;
delta = now - dev->power.accounting_timestamp; delta = now - dev->power.accounting_timestamp;
...@@ -77,9 +77,9 @@ void update_pm_runtime_accounting(struct device *dev) ...@@ -77,9 +77,9 @@ void update_pm_runtime_accounting(struct device *dev)
return; return;
if (dev->power.runtime_status == RPM_SUSPENDED) if (dev->power.runtime_status == RPM_SUSPENDED)
dev->power.suspended_jiffies += delta; dev->power.suspended_time += delta;
else else
dev->power.active_jiffies += delta; dev->power.active_time += delta;
} }
static void __update_runtime_status(struct device *dev, enum rpm_status status) static void __update_runtime_status(struct device *dev, enum rpm_status status)
...@@ -88,6 +88,22 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status) ...@@ -88,6 +88,22 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
dev->power.runtime_status = status; dev->power.runtime_status = status;
} }
u64 pm_runtime_suspended_time(struct device *dev)
{
u64 time;
unsigned long flags;
spin_lock_irqsave(&dev->power.lock, flags);
update_pm_runtime_accounting(dev);
time = dev->power.suspended_time;
spin_unlock_irqrestore(&dev->power.lock, flags);
return time;
}
EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
/** /**
* pm_runtime_deactivate_timer - Deactivate given device's suspend timer. * pm_runtime_deactivate_timer - Deactivate given device's suspend timer.
* @dev: Device to handle. * @dev: Device to handle.
...@@ -1294,10 +1310,15 @@ void pm_runtime_enable(struct device *dev) ...@@ -1294,10 +1310,15 @@ void pm_runtime_enable(struct device *dev)
spin_lock_irqsave(&dev->power.lock, flags); spin_lock_irqsave(&dev->power.lock, flags);
if (dev->power.disable_depth > 0) if (dev->power.disable_depth > 0) {
dev->power.disable_depth--; dev->power.disable_depth--;
else
/* About to enable runtime pm, set accounting_timestamp to now */
if (!dev->power.disable_depth)
dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
} else {
dev_warn(dev, "Unbalanced %s!\n", __func__); dev_warn(dev, "Unbalanced %s!\n", __func__);
}
WARN(!dev->power.disable_depth && WARN(!dev->power.disable_depth &&
dev->power.runtime_status == RPM_SUSPENDED && dev->power.runtime_status == RPM_SUSPENDED &&
...@@ -1494,7 +1515,7 @@ void pm_runtime_init(struct device *dev) ...@@ -1494,7 +1515,7 @@ void pm_runtime_init(struct device *dev)
dev->power.request_pending = false; dev->power.request_pending = false;
dev->power.request = RPM_REQ_NONE; dev->power.request = RPM_REQ_NONE;
dev->power.deferred_resume = false; dev->power.deferred_resume = false;
dev->power.accounting_timestamp = jiffies; dev->power.accounting_timestamp = 0;
INIT_WORK(&dev->power.work, pm_runtime_work); INIT_WORK(&dev->power.work, pm_runtime_work);
dev->power.timer_expires = 0; dev->power.timer_expires = 0;
......
...@@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev, ...@@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret; int ret;
u64 tmp;
spin_lock_irq(&dev->power.lock); spin_lock_irq(&dev->power.lock);
update_pm_runtime_accounting(dev); update_pm_runtime_accounting(dev);
ret = sprintf(buf, "%i\n", jiffies_to_msecs(dev->power.active_jiffies)); tmp = dev->power.active_time;
do_div(tmp, NSEC_PER_MSEC);
ret = sprintf(buf, "%llu\n", tmp);
spin_unlock_irq(&dev->power.lock); spin_unlock_irq(&dev->power.lock);
return ret; return ret;
} }
...@@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev, ...@@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int ret; int ret;
u64 tmp;
spin_lock_irq(&dev->power.lock); spin_lock_irq(&dev->power.lock);
update_pm_runtime_accounting(dev); update_pm_runtime_accounting(dev);
ret = sprintf(buf, "%i\n", tmp = dev->power.suspended_time;
jiffies_to_msecs(dev->power.suspended_jiffies)); do_div(tmp, NSEC_PER_MSEC);
ret = sprintf(buf, "%llu\n", tmp);
spin_unlock_irq(&dev->power.lock); spin_unlock_irq(&dev->power.lock);
return ret; return ret;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/pm_runtime.h>
#include "i915_pmu.h" #include "i915_pmu.h"
#include "intel_ringbuffer.h" #include "intel_ringbuffer.h"
#include "i915_drv.h" #include "i915_drv.h"
...@@ -478,7 +479,6 @@ static u64 get_rc6(struct drm_i915_private *i915) ...@@ -478,7 +479,6 @@ static u64 get_rc6(struct drm_i915_private *i915)
* counter value. * counter value.
*/ */
spin_lock_irqsave(&i915->pmu.lock, flags); spin_lock_irqsave(&i915->pmu.lock, flags);
spin_lock(&kdev->power.lock);
/* /*
* After the above branch intel_runtime_pm_get_if_in_use failed * 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) ...@@ -491,16 +491,13 @@ static u64 get_rc6(struct drm_i915_private *i915)
* suspended and if not we cannot do better than report the last * suspended and if not we cannot do better than report the last
* known RC6 value. * known RC6 value.
*/ */
if (kdev->power.runtime_status == RPM_SUSPENDED) { if (pm_runtime_status_suspended(kdev)) {
if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) val = pm_runtime_suspended_time(kdev);
i915->pmu.suspended_jiffies_last =
kdev->power.suspended_jiffies;
val = kdev->power.suspended_jiffies - if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur)
i915->pmu.suspended_jiffies_last; i915->pmu.suspended_time_last = val;
val += jiffies - kdev->power.accounting_timestamp;
val = jiffies_to_nsecs(val); val -= i915->pmu.suspended_time_last;
val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; val += i915->pmu.sample[__I915_SAMPLE_RC6].cur;
i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val;
...@@ -510,7 +507,6 @@ static u64 get_rc6(struct drm_i915_private *i915) ...@@ -510,7 +507,6 @@ static u64 get_rc6(struct drm_i915_private *i915)
val = i915->pmu.sample[__I915_SAMPLE_RC6].cur; val = i915->pmu.sample[__I915_SAMPLE_RC6].cur;
} }
spin_unlock(&kdev->power.lock);
spin_unlock_irqrestore(&i915->pmu.lock, flags); spin_unlock_irqrestore(&i915->pmu.lock, flags);
} }
......
...@@ -95,9 +95,9 @@ struct i915_pmu { ...@@ -95,9 +95,9 @@ struct i915_pmu {
*/ */
struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS]; struct i915_pmu_sample sample[__I915_NUM_PMU_SAMPLERS];
/** /**
* @suspended_jiffies_last: Cached suspend time from PM core. * @suspended_time_last: Cached suspend time from PM core.
*/ */
unsigned long suspended_jiffies_last; u64 suspended_time_last;
/** /**
* @i915_attr: Memory block holding device attributes. * @i915_attr: Memory block holding device attributes.
*/ */
......
...@@ -633,9 +633,9 @@ struct dev_pm_info { ...@@ -633,9 +633,9 @@ struct dev_pm_info {
int runtime_error; int runtime_error;
int autosuspend_delay; int autosuspend_delay;
u64 last_busy; u64 last_busy;
unsigned long active_jiffies; u64 active_time;
unsigned long suspended_jiffies; u64 suspended_time;
unsigned long accounting_timestamp; u64 accounting_timestamp;
#endif #endif
struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */
void (*set_latency_tolerance)(struct device *, s32); void (*set_latency_tolerance)(struct device *, s32);
......
...@@ -113,6 +113,8 @@ static inline bool pm_runtime_is_irq_safe(struct device *dev) ...@@ -113,6 +113,8 @@ static inline bool pm_runtime_is_irq_safe(struct device *dev)
return dev->power.irq_safe; return dev->power.irq_safe;
} }
extern u64 pm_runtime_suspended_time(struct device *dev);
#else /* !CONFIG_PM */ #else /* !CONFIG_PM */
static inline bool queue_pm_work(struct work_struct *work) { return false; } static inline bool queue_pm_work(struct work_struct *work) { return false; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment