intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
To: Imre Deak <imre.deak@intel.com>, intel-gfx@lists.freedesktop.org
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Subject: Re: [PATCH 01/12] drm/i915: add helper to get a display power ref if it was already enabled
Date: Mon, 15 Feb 2016 10:09:35 +0200	[thread overview]
Message-ID: <1455523775.6891.2.camel@linux.intel.com> (raw)
In-Reply-To: <1455296121-4742-2-git-send-email-imre.deak@intel.com>

On pe, 2016-02-12 at 18:55 +0200, Imre Deak wrote:
> We have many places in the code where we check if a given display power
> domain is enabled and if so access registers backed by this power
> domain. We assumed that some modeset lock will prevent the power
> reference from vanishing in the middle of the HW access, but this
> assumption doesn't always hold. In such cases we get either the wakeref
> not held, or an unclaimed register access error message. To fix this in
> a future-proof way that's independent of other locks wrap any such
> access with a get_ref_if_enabled()/put_ref() pair.
> 
> Kudos to Ville and Joonas for the ideas of this new interface.
> 

A couple variables could be initialized at declaration, other than
that;

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

> CC: Mika Kuoppala <mika.kuoppala@intel.com>
> CC: Chris Wilson <chris@chris-wilson.co.uk>
> CC: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> CC: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_drv.h        |   3 +
>  drivers/gpu/drm/i915/intel_runtime_pm.c | 111 ++++++++++++++++++++++++++------
>  2 files changed, 96 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index 878172a..9380ffe 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1436,6 +1436,8 @@ bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
>  				      enum intel_display_power_domain domain);
>  void intel_display_power_get(struct drm_i915_private *dev_priv,
>  			     enum intel_display_power_domain domain);
> +bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
> +					enum intel_display_power_domain domain);
>  void intel_display_power_put(struct drm_i915_private *dev_priv,
>  			     enum intel_display_power_domain domain);
>  
> @@ -1522,6 +1524,7 @@ enable_rpm_wakeref_asserts(struct drm_i915_private *dev_priv)
>  	enable_rpm_wakeref_asserts(dev_priv)
>  
>  void intel_runtime_pm_get(struct drm_i915_private *dev_priv);
> +bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv);
>  void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv);
>  void intel_runtime_pm_put(struct drm_i915_private *dev_priv);
>  
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
> index bbca527..a81f965 100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
> @@ -1435,39 +1435,90 @@ static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
>  	chv_set_pipe_power_well(dev_priv, power_well, false);
>  }
>  
> -/**
> - * intel_display_power_get - grab a power domain reference
> - * @dev_priv: i915 device instance
> - * @domain: power domain to reference
> - *
> - * This function grabs a power domain reference for @domain and ensures that the
> - * power domain and all its parents are powered up. Therefore users should only
> - * grab a reference to the innermost power domain they need.
> - *
> - * Any power domain reference obtained by this function must have a symmetric
> - * call to intel_display_power_put() to release the reference again.
> - */
> -void intel_display_power_get(struct drm_i915_private *dev_priv,
> -			     enum intel_display_power_domain domain)
> +static void
> +__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
> +				 enum intel_display_power_domain domain)
>  {
>  	struct i915_power_domains *power_domains;
>  	struct i915_power_well *power_well;
>  	int i;
>  
> -	intel_runtime_pm_get(dev_priv);
> -
>  	power_domains = &dev_priv->power_domains;
>  

You could squash this to the declaration line.

> -	mutex_lock(&power_domains->lock);
> -
>  	for_each_power_well(i, power_well, BIT(domain), power_domains) {
>  		if (!power_well->count++)
>  			intel_power_well_enable(dev_priv, power_well);
>  	}
>  
>  	power_domains->domain_use_count[domain]++;
> +}
> +
> +/**
> + * intel_display_power_get - grab a power domain reference
> + * @dev_priv: i915 device instance
> + * @domain: power domain to reference
> + *
> + * This function grabs a power domain reference for @domain and ensures that the
> + * power domain and all its parents are powered up. Therefore users should only
> + * grab a reference to the innermost power domain they need.
> + *
> + * Any power domain reference obtained by this function must have a symmetric
> + * call to intel_display_power_put() to release the reference again.
> + */
> +void intel_display_power_get(struct drm_i915_private *dev_priv,
> +			     enum intel_display_power_domain domain)
> +{
> +	struct i915_power_domains *power_domains;
> +
> +	intel_runtime_pm_get(dev_priv);
> +
> +	power_domains = &dev_priv->power_domains;

Same here.

> +
> +	mutex_lock(&power_domains->lock);
> +
> +	__intel_display_power_get_domain(dev_priv, domain);
> +
> +	mutex_unlock(&power_domains->lock);
> +}
> +
> +/**
> + * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
> + * @dev_priv: i915 device instance
> + * @domain: power domain to reference
> + *
> + * This function grabs a power domain reference for @domain and ensures that the
> + * power domain and all its parents are powered up. Therefore users should only
> + * grab a reference to the innermost power domain they need.
> + *
> + * Any power domain reference obtained by this function must have a symmetric
> + * call to intel_display_power_put() to release the reference again.
> + */
> +bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
> +					enum intel_display_power_domain domain)
> +{
> +	struct i915_power_domains *power_domains;
> +	bool is_enabled;
> +
> +	if (!intel_runtime_pm_get_if_in_use(dev_priv))
> +		return false;
> +
> +	power_domains = &dev_priv->power_domains;
> +

Aaand here.

> +	mutex_lock(&power_domains->lock);
> +
> +	if (__intel_display_power_is_enabled(dev_priv, domain)) {
> +		__intel_display_power_get_domain(dev_priv, domain);
> +		is_enabled = true;
> +	} else {
> +		is_enabled = false;
> +	}
>  
>  	mutex_unlock(&power_domains->lock);
> +
> +	if (!is_enabled)
> +		intel_runtime_pm_put(dev_priv);
> +
> +	return is_enabled;
>  }
>  
>  /**
> @@ -2239,6 +2290,30 @@ void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
>  }
>  
>  /**
> + * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
> + * @dev_priv: i915 device instance
> + *
> + * This function grabs a device-level runtime pm reference if the device is
> + * already in use and ensures that it is powered up.
> + *
> + * Any runtime pm reference obtained by this function must have a symmetric
> + * call to intel_runtime_pm_put() to release the reference again.
> + */
> +bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
> +{
> +	struct drm_device *dev = dev_priv->dev;
> +	struct device *device = &dev->pdev->dev;
> +
> +	if (IS_ENABLED(CONFIG_PM) && !pm_runtime_get_if_in_use(device))
> +		return false;
> +
> +	atomic_inc(&dev_priv->pm.wakeref_count);
> +	assert_rpm_wakelock_held(dev_priv);
> +
> +	return true;
> +}
> +
> +/**
>   * intel_runtime_pm_get_noresume - grab a runtime pm reference
>   * @dev_priv: i915 device instance
>   *
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2016-02-15  8:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 16:55 [PATCH 00/12] drm/i915: add missing display power refs Imre Deak
2016-02-12 16:55 ` [PATCH 01/12] drm/i915: add helper to get a display power ref if it was already enabled Imre Deak
2016-02-15  8:09   ` Joonas Lahtinen [this message]
2016-02-15 14:18   ` [PATCH v2 " Imre Deak
2016-02-17 12:17     ` [PATCH v3 " Imre Deak
2016-02-12 16:55 ` [PATCH 02/12] drm/i915: ensure the HW is powered during display pipe HW readout Imre Deak
2016-02-15 13:23   ` Mika Kuoppala
2016-02-12 16:55 ` [PATCH 03/12] drm/i915/ibx: ensure the HW is powered during PLL " Imre Deak
2016-02-15 13:59   ` Mika Kuoppala
2016-02-12 16:55 ` [PATCH 04/12] drm/i915: ensure the HW is powered when disabling VGA Imre Deak
2016-02-12 16:55 ` [PATCH 05/12] drm/i915: ensure the HW is powered during HW access in assert_pipe Imre Deak
2016-02-12 16:55 ` [PATCH 06/12] drm/i915/crt: ensure the HW is powered during HW state readout Imre Deak
2016-02-12 16:55 ` [PATCH 07/12] drm/i915/ddi: " Imre Deak
2016-02-12 16:55 ` [PATCH 08/12] drm/i915: ensure the HW is powered when accessing the CRC HW block Imre Deak
2016-02-16 16:02   ` Daniel Vetter
2016-02-17 12:20     ` Imre Deak
2016-02-17 16:09       ` Daniel Vetter
2016-02-12 16:55 ` [PATCH 09/12] drm/i915/dp: ensure the HW is powered during HW state readout Imre Deak
2016-02-12 16:55 ` [PATCH 10/12] drm/i915/dsi: " Imre Deak
2016-02-12 16:55 ` [PATCH 11/12] drm/i915/hdmi: " Imre Deak
2016-02-12 16:55 ` [PATCH 12/12] drm/i915/lvds: " Imre Deak
2016-02-16 16:05   ` Daniel Vetter
2016-02-16 16:47     ` Imre Deak
2016-02-16 11:15 ` ✗ Fi.CI.BAT: failure for drm/i915: add missing display power refs (rev2) Patchwork
2016-02-16 14:04 ` [PATCH 00/12] drm/i915: add missing display power refs Mika Kuoppala
2016-02-16 17:35   ` Imre Deak
2016-02-17 12:44 ` ✓ Fi.CI.BAT: success for drm/i915: add missing display power refs (rev3) Patchwork
2016-02-17 14:21   ` Imre Deak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455523775.6891.2.camel@linux.intel.com \
    --to=joonas.lahtinen@linux.intel.com \
    --cc=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).