drm/i915: Mark up sysfs with rpm wakeref tracking
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 14 Jan 2019 14:21:13 +0000 (14:21 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 14 Jan 2019 16:18:07 +0000 (16:18 +0000)
As sysfs has a simple pattern of taking a rpm wakeref around the user
access, we can track the local reference and drop it as soon as
possible.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190114142129.24398-5-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_sysfs.c

index 53c20e103d56c9a5d7c1b7c29f2dcf344b60d1a1..2cbbf165d179e682617040444d6b736903ebac1b 100644 (file)
@@ -42,11 +42,12 @@ static inline struct drm_i915_private *kdev_minor_to_i915(struct device *kdev)
 static u32 calc_residency(struct drm_i915_private *dev_priv,
                          i915_reg_t reg)
 {
+       intel_wakeref_t wakeref;
        u64 res;
 
-       intel_runtime_pm_get(dev_priv);
+       wakeref = intel_runtime_pm_get(dev_priv);
        res = intel_rc6_residency_us(dev_priv, reg);
-       intel_runtime_pm_put_unchecked(dev_priv);
+       intel_runtime_pm_put(dev_priv, wakeref);
 
        return DIV_ROUND_CLOSEST_ULL(res, 1000);
 }
@@ -258,9 +259,10 @@ static ssize_t gt_act_freq_mhz_show(struct device *kdev,
                                    struct device_attribute *attr, char *buf)
 {
        struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
+       intel_wakeref_t wakeref;
        int ret;
 
-       intel_runtime_pm_get(dev_priv);
+       wakeref = intel_runtime_pm_get(dev_priv);
 
        mutex_lock(&dev_priv->pcu_lock);
        if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
@@ -274,7 +276,7 @@ static ssize_t gt_act_freq_mhz_show(struct device *kdev,
        }
        mutex_unlock(&dev_priv->pcu_lock);
 
-       intel_runtime_pm_put_unchecked(dev_priv);
+       intel_runtime_pm_put(dev_priv, wakeref);
 
        return snprintf(buf, PAGE_SIZE, "%d\n", ret);
 }
@@ -354,6 +356,7 @@ static ssize_t gt_max_freq_mhz_store(struct device *kdev,
 {
        struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
        struct intel_rps *rps = &dev_priv->gt_pm.rps;
+       intel_wakeref_t wakeref;
        u32 val;
        ssize_t ret;
 
@@ -361,7 +364,7 @@ static ssize_t gt_max_freq_mhz_store(struct device *kdev,
        if (ret)
                return ret;
 
-       intel_runtime_pm_get(dev_priv);
+       wakeref = intel_runtime_pm_get(dev_priv);
 
        mutex_lock(&dev_priv->pcu_lock);
 
@@ -371,7 +374,7 @@ static ssize_t gt_max_freq_mhz_store(struct device *kdev,
            val > rps->max_freq ||
            val < rps->min_freq_softlimit) {
                mutex_unlock(&dev_priv->pcu_lock);
-               intel_runtime_pm_put_unchecked(dev_priv);
+               intel_runtime_pm_put(dev_priv, wakeref);
                return -EINVAL;
        }
 
@@ -392,7 +395,7 @@ static ssize_t gt_max_freq_mhz_store(struct device *kdev,
 
        mutex_unlock(&dev_priv->pcu_lock);
 
-       intel_runtime_pm_put_unchecked(dev_priv);
+       intel_runtime_pm_put(dev_priv, wakeref);
 
        return ret ?: count;
 }
@@ -412,6 +415,7 @@ static ssize_t gt_min_freq_mhz_store(struct device *kdev,
 {
        struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
        struct intel_rps *rps = &dev_priv->gt_pm.rps;
+       intel_wakeref_t wakeref;
        u32 val;
        ssize_t ret;
 
@@ -419,7 +423,7 @@ static ssize_t gt_min_freq_mhz_store(struct device *kdev,
        if (ret)
                return ret;
 
-       intel_runtime_pm_get(dev_priv);
+       wakeref = intel_runtime_pm_get(dev_priv);
 
        mutex_lock(&dev_priv->pcu_lock);
 
@@ -429,7 +433,7 @@ static ssize_t gt_min_freq_mhz_store(struct device *kdev,
            val > rps->max_freq ||
            val > rps->max_freq_softlimit) {
                mutex_unlock(&dev_priv->pcu_lock);
-               intel_runtime_pm_put_unchecked(dev_priv);
+               intel_runtime_pm_put(dev_priv, wakeref);
                return -EINVAL;
        }
 
@@ -446,7 +450,7 @@ static ssize_t gt_min_freq_mhz_store(struct device *kdev,
 
        mutex_unlock(&dev_priv->pcu_lock);
 
-       intel_runtime_pm_put_unchecked(dev_priv);
+       intel_runtime_pm_put(dev_priv, wakeref);
 
        return ret ?: count;
 }