diff mbox

drm/i915: Initialize DRRS delayed work

Message ID 1421919885-32394-1-git-send-email-ramalingam.c@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ramalingam C Jan. 22, 2015, 9:44 a.m. UTC
From: Vandana Kannan <vandana.kannan@intel.com>

Add DRRS work function to trigger a switch to low refresh rate,
when no activity is detected on screen till 1 sec duration.

v2: [By Ram]: drrs.dp also protected with drrs.mutex and worker function
is renamed to intel_edp_drrs_downclock_work [Rodrigo]

Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c |   38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

Comments

Rodrigo Vivi Jan. 23, 2015, 11:24 p.m. UTC | #1
On Thu, Jan 22, 2015 at 1:44 AM, Ramalingam C <ramalingam.c@intel.com> wrote:
> From: Vandana Kannan <vandana.kannan@intel.com>
>
> Add DRRS work function to trigger a switch to low refresh rate,
> when no activity is detected on screen till 1 sec duration.
>
> v2: [By Ram]: drrs.dp also protected with drrs.mutex and worker function
> is renamed to intel_edp_drrs_downclock_work [Rodrigo]

Actually comments accepted on v2 came from Chris, not from me.

>
> Signed-off-by: Vandana Kannan <vandana.kannan@intel.com>
> Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_dp.c |   38 ++++++++++++++++++++++++++++++--------
>  1 file changed, 30 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index b38d737..c066560 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -4815,20 +4815,40 @@ static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
>                 I915_WRITE(reg, val);
>         }
>
> +       dev_priv->drrs.refresh_rate_type = index;
> +
> +       DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
> +}
> +
> +static void intel_edp_drrs_downclock_work(struct work_struct *work)
> +{
> +       struct drm_i915_private *dev_priv =
> +               container_of(work, typeof(*dev_priv), drrs.work.work);
> +       struct intel_dp *intel_dp;
> +
> +       mutex_lock(&dev_priv->drrs.mutex);
> +
> +       intel_dp = dev_priv->drrs.dp;
> +
> +       if (!intel_dp)
> +               goto unlock;
> +
>         /*
> -        * mutex taken to ensure that there is no race between differnt
> -        * drrs calls trying to update refresh rate. This scenario may occur
> -        * in future when idleness detection based DRRS in kernel and
> -        * possible calls from user space to set differnt RR are made.
> +        * The delayed work can race with an invalidate hence we need to
> +        * recheck.
>          */
>
> -       mutex_lock(&dev_priv->drrs.mutex);
> +       if (dev_priv->drrs.busy_frontbuffer_bits)
> +               goto unlock;
>
> -       dev_priv->drrs.refresh_rate_type = index;
> +       if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
> +               intel_dp_set_drrs_state(dev_priv->dev,
> +                       intel_dp->attached_connector->panel.
> +                       downclock_mode->vrefresh);
>
> -       mutex_unlock(&dev_priv->drrs.mutex);
> +unlock:
>
> -       DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
> +       mutex_unlock(&dev_priv->drrs.mutex);
>  }
>
>  static struct drm_display_mode *
> @@ -4858,6 +4878,8 @@ intel_dp_drrs_init(struct intel_connector *intel_connector,
>                 return NULL;
>         }
>
> +       INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
> +
>         mutex_init(&dev_priv->drrs.mutex);
>
>         dev_priv->drrs.type = dev_priv->vbt.drrs_type;
> --
> 1.7.9.5
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Anyway seems ok to me now:
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index b38d737..c066560 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4815,20 +4815,40 @@  static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
 		I915_WRITE(reg, val);
 	}
 
+	dev_priv->drrs.refresh_rate_type = index;
+
+	DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
+}
+
+static void intel_edp_drrs_downclock_work(struct work_struct *work)
+{
+	struct drm_i915_private *dev_priv =
+		container_of(work, typeof(*dev_priv), drrs.work.work);
+	struct intel_dp *intel_dp;
+
+	mutex_lock(&dev_priv->drrs.mutex);
+
+	intel_dp = dev_priv->drrs.dp;
+
+	if (!intel_dp)
+		goto unlock;
+
 	/*
-	 * mutex taken to ensure that there is no race between differnt
-	 * drrs calls trying to update refresh rate. This scenario may occur
-	 * in future when idleness detection based DRRS in kernel and
-	 * possible calls from user space to set differnt RR are made.
+	 * The delayed work can race with an invalidate hence we need to
+	 * recheck.
 	 */
 
-	mutex_lock(&dev_priv->drrs.mutex);
+	if (dev_priv->drrs.busy_frontbuffer_bits)
+		goto unlock;
 
-	dev_priv->drrs.refresh_rate_type = index;
+	if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
+		intel_dp_set_drrs_state(dev_priv->dev,
+			intel_dp->attached_connector->panel.
+			downclock_mode->vrefresh);
 
-	mutex_unlock(&dev_priv->drrs.mutex);
+unlock:
 
-	DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
+	mutex_unlock(&dev_priv->drrs.mutex);
 }
 
 static struct drm_display_mode *
@@ -4858,6 +4878,8 @@  intel_dp_drrs_init(struct intel_connector *intel_connector,
 		return NULL;
 	}
 
+	INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
+
 	mutex_init(&dev_priv->drrs.mutex);
 
 	dev_priv->drrs.type = dev_priv->vbt.drrs_type;