PM-runtime: update time accounting only when enabled
authorVincent Guittot <vincent.guittot@linaro.org>
Mon, 4 Feb 2019 16:25:53 +0000 (17:25 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 5 Feb 2019 11:04:39 +0000 (12:04 +0100)
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 <ulf.hansson@linaro.org>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
[ rjw: Minor cleanups ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/runtime.c

index 6a58bb77a0181672b022f5197bcedecc6cf50597..04407d9f76fdb194867928a182d64d30b16d1698 100644 (file)
@@ -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;