From: Vincent Guittot Date: Mon, 4 Feb 2019 16:25:53 +0000 (+0100) Subject: PM-runtime: update time accounting only when enabled X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=fed7e88c0702e30fcd55563ca6eecd548a5d13af;p=openwrt%2Fstaging%2Fblogic.git PM-runtime: update time accounting only when enabled Update the accounting_timestamp field only when PM runtime is enabled and don't forget to account the last state before disabling it. Suggested-by: Ulf Hansson Signed-off-by: Vincent Guittot Reviewed-by: Ulf Hansson [ rjw: Minor cleanups ] Signed-off-by: Rafael J. Wysocki --- diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 6a58bb77a018..04407d9f76fd 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -66,10 +66,14 @@ static int rpm_suspend(struct device *dev, int rpmflags); */ void update_pm_runtime_accounting(struct device *dev) { - u64 now = ktime_get_mono_fast_ns(); - u64 last = dev->power.accounting_timestamp; - u64 delta; + u64 now, last, delta; + if (dev->power.disable_depth > 0) + return; + + last = dev->power.accounting_timestamp; + + now = ktime_get_mono_fast_ns(); dev->power.accounting_timestamp = now; /* @@ -82,9 +86,6 @@ void update_pm_runtime_accounting(struct device *dev) delta = now - last; - if (dev->power.disable_depth > 0) - return; - if (dev->power.runtime_status == RPM_SUSPENDED) dev->power.suspended_time += delta; else @@ -1298,6 +1299,9 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) pm_runtime_put_noidle(dev); } + /* Update time accounting before disabling PM-runtime. */ + update_pm_runtime_accounting(dev); + if (!dev->power.disable_depth++) __pm_runtime_barrier(dev); @@ -1521,7 +1525,6 @@ void pm_runtime_init(struct device *dev) dev->power.request_pending = false; dev->power.request = RPM_REQ_NONE; dev->power.deferred_resume = false; - dev->power.accounting_timestamp = 0; INIT_WORK(&dev->power.work, pm_runtime_work); dev->power.timer_expires = 0;