All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	Vinay Belgaumkar <vinay.belgaumkar@intel.com>,
	Badal Nilawar <badal.nilawar@intel.com>,
	"Stuart Summers" <stuart.summers@intel.com>
Subject: Re: [PATCH v4 1/3] drm/xe/guc_pc: Add _locked variant for min/max freq
Date: Mon, 16 Jun 2025 10:26:57 -0400	[thread overview]
Message-ID: <aFApsaqg0KR-F0wv@intel.com> (raw)
In-Reply-To: <20250615-wa-22019338487-v4-1-704830697cbc@intel.com>

On Sun, Jun 15, 2025 at 11:17:34PM -0700, Lucas De Marchi wrote:
> There are places in which the getters/setters are called one after the
> other causing a multiple lock()/unlock(). These are not currently a
> problem since they are all happening from the same thread, but there's a
> race possibility as calls are added outside of the early init when the
> max/min and stashed values need to be correlated.
> 
> Add the _locked() variants to prepare for that.
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/xe/xe_guc_pc.c | 124 +++++++++++++++++++++++------------------
>  1 file changed, 70 insertions(+), 54 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c
> index 39d2acb2f30f6..53aaf937d4bec 100644
> --- a/drivers/gpu/drm/xe/xe_guc_pc.c
> +++ b/drivers/gpu/drm/xe/xe_guc_pc.c
> @@ -5,6 +5,7 @@
>  
>  #include "xe_guc_pc.h"
>  
> +#include <linux/cleanup.h>
>  #include <linux/delay.h>
>  #include <linux/ktime.h>
>  
> @@ -554,6 +555,25 @@ u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc)
>  	return pc->rpn_freq;
>  }
>  
> +static int xe_guc_pc_get_min_freq_locked(struct xe_guc_pc *pc, u32 *freq)
> +{
> +	int ret;
> +
> +	lockdep_assert_held(&pc->freq_lock);
> +
> +	/* Might be in the middle of a gt reset */
> +	if (!pc->freq_ready)
> +		return -EAGAIN;
> +
> +	ret = pc_action_query_task_state(pc);
> +	if (ret)
> +		return ret;
> +
> +	*freq = pc_get_min_freq(pc);
> +
> +	return 0;
> +}
> +
>  /**
>   * xe_guc_pc_get_min_freq - Get the min operational frequency
>   * @pc: The GuC PC
> @@ -563,27 +583,29 @@ u32 xe_guc_pc_get_rpn_freq(struct xe_guc_pc *pc)
>   *         -EAGAIN if GuC PC not ready (likely in middle of a reset).
>   */
>  int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
> +{
> +	guard(mutex)(&pc->freq_lock);
> +
> +	return xe_guc_pc_get_min_freq_locked(pc, freq);
> +}
> +
> +static int xe_guc_pc_set_min_freq_locked(struct xe_guc_pc *pc, u32 freq)
>  {
>  	int ret;
>  
> -	xe_device_assert_mem_access(pc_to_xe(pc));
> +	lockdep_assert_held(&pc->freq_lock);
>  
> -	mutex_lock(&pc->freq_lock);
> -	if (!pc->freq_ready) {
> -		/* Might be in the middle of a gt reset */
> -		ret = -EAGAIN;
> -		goto out;
> -	}
> +	/* Might be in the middle of a gt reset */
> +	if (!pc->freq_ready)
> +		return -EAGAIN;
>  
> -	ret = pc_action_query_task_state(pc);
> +	ret = pc_set_min_freq(pc, freq);
>  	if (ret)
> -		goto out;
> +		return ret;
>  
> -	*freq = pc_get_min_freq(pc);
> +	pc->user_requested_min = freq;
>  
> -out:
> -	mutex_unlock(&pc->freq_lock);
> -	return ret;
> +	return 0;
>  }
>  
>  /**
> @@ -596,25 +618,30 @@ int xe_guc_pc_get_min_freq(struct xe_guc_pc *pc, u32 *freq)
>   *         -EINVAL if value out of bounds.
>   */
>  int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq)
> +{
> +	guard(mutex)(&pc->freq_lock);
> +
> +	return xe_guc_pc_set_min_freq_locked(pc, freq);
> +}
> +
> +
> +static int xe_guc_pc_get_max_freq_locked(struct xe_guc_pc *pc, u32 *freq)
>  {
>  	int ret;
>  
> -	mutex_lock(&pc->freq_lock);
> -	if (!pc->freq_ready) {
> -		/* Might be in the middle of a gt reset */
> -		ret = -EAGAIN;
> -		goto out;
> -	}
> +	lockdep_assert_held(&pc->freq_lock);
>  
> -	ret = pc_set_min_freq(pc, freq);
> +	/* Might be in the middle of a gt reset */
> +	if (!pc->freq_ready)
> +		return -EAGAIN;
> +
> +	ret = pc_action_query_task_state(pc);
>  	if (ret)
> -		goto out;
> +		return ret;
>  
> -	pc->user_requested_min = freq;
> +	*freq = pc_get_max_freq(pc);
>  
> -out:
> -	mutex_unlock(&pc->freq_lock);
> -	return ret;
> +	return 0;
>  }
>  
>  /**
> @@ -626,25 +653,29 @@ int xe_guc_pc_set_min_freq(struct xe_guc_pc *pc, u32 freq)
>   *         -EAGAIN if GuC PC not ready (likely in middle of a reset).
>   */
>  int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq)
> +{
> +	guard(mutex)(&pc->freq_lock);
> +
> +	return xe_guc_pc_get_max_freq_locked(pc, freq);
> +}
> +
> +static int xe_guc_pc_set_max_freq_locked(struct xe_guc_pc *pc, u32 freq)
>  {
>  	int ret;
>  
> -	mutex_lock(&pc->freq_lock);
> -	if (!pc->freq_ready) {
> -		/* Might be in the middle of a gt reset */
> -		ret = -EAGAIN;
> -		goto out;
> -	}
> +	lockdep_assert_held(&pc->freq_lock);
>  
> -	ret = pc_action_query_task_state(pc);
> +	/* Might be in the middle of a gt reset */
> +	if (!pc->freq_ready)
> +		return -EAGAIN;
> +
> +	ret = pc_set_max_freq(pc, freq);
>  	if (ret)
> -		goto out;
> +		return ret;
>  
> -	*freq = pc_get_max_freq(pc);
> +	pc->user_requested_max = freq;
>  
> -out:
> -	mutex_unlock(&pc->freq_lock);
> -	return ret;
> +	return 0;
>  }
>  
>  /**
> @@ -658,24 +689,9 @@ int xe_guc_pc_get_max_freq(struct xe_guc_pc *pc, u32 *freq)
>   */
>  int xe_guc_pc_set_max_freq(struct xe_guc_pc *pc, u32 freq)
>  {
> -	int ret;
> -
> -	mutex_lock(&pc->freq_lock);
> -	if (!pc->freq_ready) {
> -		/* Might be in the middle of a gt reset */
> -		ret = -EAGAIN;
> -		goto out;
> -	}
> -
> -	ret = pc_set_max_freq(pc, freq);
> -	if (ret)
> -		goto out;
> +	guard(mutex)(&pc->freq_lock);
>  
> -	pc->user_requested_max = freq;
> -
> -out:
> -	mutex_unlock(&pc->freq_lock);
> -	return ret;
> +	return xe_guc_pc_set_max_freq_locked(pc, freq);
>  }
>  
>  /**
> 
> -- 
> 2.49.0
> 

  reply	other threads:[~2025-06-16 14:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  6:17 [PATCH v4 0/3] drm/xe: Update Wa_22019338487 Lucas De Marchi
2025-06-16  6:17 ` [PATCH v4 1/3] drm/xe/guc_pc: Add _locked variant for min/max freq Lucas De Marchi
2025-06-16 14:26   ` Rodrigo Vivi [this message]
2025-06-16  6:17 ` [PATCH v4 2/3] drm/xe/xe_guc_pc: Lock once to update stashed frequencies Lucas De Marchi
2025-06-16 14:29   ` Rodrigo Vivi
2025-06-16  6:17 ` [PATCH v4 3/3] drm/xe/bmg: Update Wa_22019338487 Lucas De Marchi
2025-06-16 14:37   ` Rodrigo Vivi
2025-06-16 15:38     ` Lucas De Marchi
2025-06-16 20:35       ` Rodrigo Vivi
2025-06-16 21:21         ` Lucas De Marchi
2025-06-16  6:24 ` ✗ CI.checkpatch: warning for drm/xe: " Patchwork
2025-06-16  6:25 ` ✓ CI.KUnit: success " Patchwork
2025-06-16  7:06 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-16 16:32 ` ✗ Xe.CI.Full: failure " Patchwork

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=aFApsaqg0KR-F0wv@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=stuart.summers@intel.com \
    --cc=vinay.belgaumkar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.