PM-runtime: Consolidate code to get active/suspended time
authorUlf Hansson <ulf.hansson@linaro.org>
Tue, 5 Mar 2019 12:55:26 +0000 (13:55 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 7 Mar 2019 10:23:17 +0000 (11:23 +0100)
In a step to consolidate the code for fetching the PM-runtime
active/suspended time for a device, add a common function for that
and make the existing pm_runtime_suspended_time() call it.

Also add a corresponding pm_runtime_active_time() calling the new
common function.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
[ rjw: Changelog, function rename ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/power.h
drivers/base/power/runtime.c

index c511def48b48621ba8ed13b84e23d34b1e47a899..ec33fbdb919b3506219928a52267de1a6275aa8b 100644 (file)
@@ -21,6 +21,7 @@ static inline void pm_runtime_early_init(struct device *dev)
 extern void pm_runtime_init(struct device *dev);
 extern void pm_runtime_reinit(struct device *dev);
 extern void pm_runtime_remove(struct device *dev);
+extern u64 pm_runtime_active_time(struct device *dev);
 
 #define WAKE_IRQ_DEDICATED_ALLOCATED   BIT(0)
 #define WAKE_IRQ_DEDICATED_MANAGED     BIT(1)
index 78937c45278c4445853dac5c332c5f772a587553..32f6bf076bd7cb27d017f03ea10f5beaccd60452 100644 (file)
@@ -98,7 +98,7 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
        dev->power.runtime_status = status;
 }
 
-u64 pm_runtime_suspended_time(struct device *dev)
+static u64 rpm_get_accounted_time(struct device *dev, bool suspended)
 {
        u64 time;
        unsigned long flags;
@@ -106,12 +106,22 @@ u64 pm_runtime_suspended_time(struct device *dev)
        spin_lock_irqsave(&dev->power.lock, flags);
 
        update_pm_runtime_accounting(dev);
-       time = dev->power.suspended_time;
+       time = suspended ? dev->power.suspended_time : dev->power.active_time;
 
        spin_unlock_irqrestore(&dev->power.lock, flags);
 
        return time;
 }
+
+u64 pm_runtime_active_time(struct device *dev)
+{
+       return rpm_get_accounted_time(dev, false);
+}
+
+u64 pm_runtime_suspended_time(struct device *dev)
+{
+       return rpm_get_accounted_time(dev, true);
+}
 EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
 
 /**