Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>,
	intel-xe@lists.freedesktop.org
Cc: Badal Nilawar <badal.nilawar@intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Nirmoy Das <nirmoy.das@intel.com>
Subject: Re: [PATCH v8 04/26] drm/xe: Error handling in xe_force_wake_get()
Date: Tue, 8 Oct 2024 20:05:12 +0200	[thread overview]
Message-ID: <07234b5f-4e89-43f2-b978-826e2a4b651e@intel.com> (raw)
In-Reply-To: <20241008071115.1862704-5-himal.prasad.ghimiray@intel.com>



On 08.10.2024 09:10, Himal Prasad Ghimiray wrote:
> If an acknowledgment timeout occurs for a forcewake domain awake
> request, do not increment the reference count for the domain. This
> ensures that subsequent _get calls do not incorrectly assume the domain
> is awake. The return value is a mask of domains that got refcounted,
> and these domains need to be provided for subsequent xe_force_wake_put
> call.
> 
> While at it, add simple kernel-doc for xe_force_wake_get()
> 
> v3
> - Use explicit type for mask (Michal/Badal)
> - Improve kernel-doc (Michal)
> - Use unsigned int instead of abusing enum (Michal)
> 
> v5
> - Use unsigned int for return (MattB/Badal/Rodrigo)
> - use xe_gt_WARN for domain awake ack failure (Badal/Rodrigo)
> 
> v6
> - Change XE_FORCEWAKE_ALL to single bit, this helps accommodate
> actually refcounted domains in return. (Michal)
> - Modify commit message and warn message (Badal)
> - Remove unnecessary information in kernel-doc (Michal)
> 
> v7
> - Add assert condition for valid input domains (Badal)
> 
> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Cc: Badal Nilawar <badal.nilawar@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Reviewed-by: Badal Nilawar <badal.nilawar@intel.com>(#rev5)
> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_force_wake.c       | 53 +++++++++++++++++++-----
>  drivers/gpu/drm/xe/xe_force_wake.h       |  4 +-
>  drivers/gpu/drm/xe/xe_force_wake_types.h |  2 +-
>  3 files changed, 46 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_force_wake.c b/drivers/gpu/drm/xe/xe_force_wake.c
> index ac0419da7173..bfba276c48ac 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake.c
> +++ b/drivers/gpu/drm/xe/xe_force_wake.c
> @@ -154,29 +154,62 @@ static int domain_sleep_wait(struct xe_gt *gt,
>  					 (ffs(tmp__) - 1))) && \
>  					 domain__->reg_ctl.addr)
>  
> -int xe_force_wake_get(struct xe_force_wake *fw,
> -		      enum xe_force_wake_domains domains)
> +/**
> + * xe_force_wake_get() : Increase the domain refcount
> + * @fw: struct xe_force_wake
> + * @domains: forcewake domains to get refcount on
> + *
> + * This function takes references for the input @domains and wakes them if

hmm, 'taking a reference' is implementation detail compared to the 'wake
up domain from sleep' so I would swap those statements

> + * they are asleep.If requested domain is XE_FORCEWAKE_ALL then only
                     ^
missing space after dot

> + * applicable/initialized domains will be considered for refcount and it is
> + * a caller responsibilty to check returned ref if it includes any specific

typo

> + * domain by using xe_force_wake_ref_has_domain() function. caller must call

s/caller/Caller

> + * xe_force_wake_put() function to decrease incremented refcounts.
> + *
> + * Return: opaque reference to woken domains or zero if none of requested
> + * domains were awake.
> + */
> +unsigned int xe_force_wake_get(struct xe_force_wake *fw,
> +			       enum xe_force_wake_domains domains)
>  {
>  	struct xe_gt *gt = fw->gt;
>  	struct xe_force_wake_domain *domain;
> -	enum xe_force_wake_domains tmp, woken = 0;
> +	unsigned int ref_incr = 0, awake_rqst = 0, awake_failed = 0;
> +	unsigned int tmp, ref_rqst;
>  	unsigned long flags;
> -	int ret = 0;
> +
> +	xe_gt_assert(gt, is_power_of_2(domains) && domains <= XE_FORCEWAKE_ALL);

better to split into two asserts to better see which one fails

> +
> +	if (domains != XE_FORCEWAKE_ALL) {
> +		xe_gt_assert(gt, fw->initialized_domains & domains);

can we keep all asserts together at the top of the function as:

xe_gt_assert(gt, domains == XE_FORCEWAKE_ALL ||
	     fw->initialized_domains & domains);

> +		ref_rqst = domains;
> +	} else {
> +		ref_rqst = fw->initialized_domains;
> +	}
>  
>  	spin_lock_irqsave(&fw->lock, flags);
> -	for_each_fw_domain_masked(domain, domains, fw, tmp) {
> +	for_each_fw_domain_masked(domain, ref_rqst, fw, tmp) {
>  		if (!domain->ref++) {
> -			woken |= BIT(domain->id);
> +			awake_rqst |= BIT(domain->id);
>  			domain_wake(gt, domain);
>  		}
> +		ref_incr |= BIT(domain->id);
>  	}
> -	for_each_fw_domain_masked(domain, woken, fw, tmp) {
> -		ret |= domain_wake_wait(gt, domain);
> +	for_each_fw_domain_masked(domain, awake_rqst, fw, tmp) {
> +		if (domain_wake_wait(gt, domain) == 0) {
> +			fw->awake_domains |= BIT(domain->id);
> +		} else {
> +			awake_failed |= BIT(domain->id);
> +			--domain->ref;
> +		}
>  	}
> -	fw->awake_domains |= woken;
> +	ref_incr &= ~awake_failed;
>  	spin_unlock_irqrestore(&fw->lock, flags);
>  
> -	return ret;
> +	xe_gt_WARN(gt, awake_failed, "Forcewake domain%s %#x failed to acknowledge awake request\n",
> +		   str_plural(hweight_long(awake_failed)), awake_failed);
> +
> +	return (ref_incr == fw->initialized_domains) ? ref_incr | XE_FORCEWAKE_ALL : ref_incr;

maybe simpler:

	if (ref_incr == fw->initialized_domains)
		ref_incr |= XE_FORCEWAKE_ALL;

	return ref_incr;

>  }
>  
>  int xe_force_wake_put(struct xe_force_wake *fw,
> diff --git a/drivers/gpu/drm/xe/xe_force_wake.h b/drivers/gpu/drm/xe/xe_force_wake.h
> index 1608a55edc84..75fa1a19797c 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake.h
> +++ b/drivers/gpu/drm/xe/xe_force_wake.h
> @@ -15,8 +15,8 @@ void xe_force_wake_init_gt(struct xe_gt *gt,
>  			   struct xe_force_wake *fw);
>  void xe_force_wake_init_engines(struct xe_gt *gt,
>  				struct xe_force_wake *fw);
> -int xe_force_wake_get(struct xe_force_wake *fw,
> -		      enum xe_force_wake_domains domains);
> +unsigned int xe_force_wake_get(struct xe_force_wake *fw,
> +			       enum xe_force_wake_domains domains);
>  int xe_force_wake_put(struct xe_force_wake *fw,
>  		      enum xe_force_wake_domains domains);
>  
> diff --git a/drivers/gpu/drm/xe/xe_force_wake_types.h b/drivers/gpu/drm/xe/xe_force_wake_types.h
> index fde17dc3d01e..899fbbcb3ea9 100644
> --- a/drivers/gpu/drm/xe/xe_force_wake_types.h
> +++ b/drivers/gpu/drm/xe/xe_force_wake_types.h
> @@ -48,7 +48,7 @@ enum xe_force_wake_domains {
>  	XE_FW_MEDIA_VEBOX2	= BIT(XE_FW_DOMAIN_ID_MEDIA_VEBOX2),
>  	XE_FW_MEDIA_VEBOX3	= BIT(XE_FW_DOMAIN_ID_MEDIA_VEBOX3),
>  	XE_FW_GSC		= BIT(XE_FW_DOMAIN_ID_GSC),
> -	XE_FORCEWAKE_ALL	= BIT(XE_FW_DOMAIN_ID_COUNT) - 1
> +	XE_FORCEWAKE_ALL	= BIT(XE_FW_DOMAIN_ID_COUNT)
>  };
>  
>  /**

but overall LGTM so with above nits fixed,

	Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com>


  parent reply	other threads:[~2024-10-08 18:05 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08  7:10 [PATCH v8 00/26] Fix xe_force_wake_get() failure handling Himal Prasad Ghimiray
2024-10-08  6:58 ` ✓ CI.Patch_applied: success for Fix xe_force_wake_get() failure handling (rev9) Patchwork
2024-10-08  6:59 ` ✓ CI.checkpatch: " Patchwork
2024-10-08  7:00 ` ✓ CI.KUnit: " Patchwork
2024-10-08  7:10 ` [PATCH v8 01/26] drm/xe: Add member initialized_domains to xe_force_wake() Himal Prasad Ghimiray
2024-10-08 14:55   ` Nilawar, Badal
2024-10-08 17:03   ` Michal Wajdeczko
2024-10-08  7:10 ` [PATCH v8 02/26] drm/xe/forcewake: Change awake_domain datatype Himal Prasad Ghimiray
2024-10-08 14:56   ` Nilawar, Badal
2024-10-08 17:04   ` Michal Wajdeczko
2024-10-08  7:10 ` [PATCH v8 03/26] drm/xe/forcewake: Add a helper xe_force_wake_ref_has_domain() Himal Prasad Ghimiray
2024-10-08 14:58   ` Nilawar, Badal
2024-10-08 17:07   ` Michal Wajdeczko
2024-10-08  7:10 ` [PATCH v8 04/26] drm/xe: Error handling in xe_force_wake_get() Himal Prasad Ghimiray
2024-10-08 15:13   ` Nilawar, Badal
2024-10-08 18:05   ` Michal Wajdeczko [this message]
2024-10-08  7:10 ` [PATCH v8 05/26] drm/xe: Modify xe_force_wake_put to handle _get returned mask Himal Prasad Ghimiray
2024-10-08 18:18   ` Michal Wajdeczko
2024-10-08  7:10 ` [PATCH v8 06/26] drm/xe/device: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-10-09 11:30   ` Jani Nikula
2024-10-08  7:10 ` [PATCH v8 07/26] drm/xe/hdcp: " Himal Prasad Ghimiray
2024-10-08  7:10 ` [PATCH v8 08/26] drm/xe/gsc: " Himal Prasad Ghimiray
2024-10-09 12:42   ` Nilawar, Badal
2024-10-08  7:10 ` [PATCH v8 09/26] drm/xe/gt: " Himal Prasad Ghimiray
2024-10-09 12:46   ` Nilawar, Badal
2024-10-08  7:10 ` [PATCH v8 10/26] drm/xe/xe_gt_idle: " Himal Prasad Ghimiray
2024-10-09 12:49   ` Nilawar, Badal
2024-10-08  7:11 ` [PATCH v8 11/26] drm/xe/devcoredump: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 12/26] drm/xe/tests/mocs: Update xe_force_wake_get() return handling Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 13/26] drm/xe/mocs: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 14/26] drm/xe/xe_drm_client: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 15/26] drm/xe/xe_gt_debugfs: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 16/26] drm/xe/guc: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 17/26] drm/xe/huc: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 18/26] drm/xe/oa: Handle force_wake_get failure in xe_oa_stream_init() Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 19/26] drm/xe/pat: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 20/26] drm/xe/gt_tlb_invalidation_ggtt: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 21/26] drm/xe/xe_reg_sr: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 22/26] drm/xe/query: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 23/26] drm/xe/vram: " Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 24/26] drm/xe: forcewake debugfs open fails on xe_forcewake_get failure Himal Prasad Ghimiray
2024-10-08  7:11 ` [PATCH v8 25/26] drm/xe: Ensure __must_check for xe_force_wake_get() return Himal Prasad Ghimiray
2024-10-08 17:17   ` Nilawar, Badal
2024-10-08  7:11 ` [PATCH v8 26/26] drm/xe: Change return type to void for xe_force_wake_put Himal Prasad Ghimiray
2024-10-08 17:22   ` Nilawar, Badal
2024-10-08 18:24   ` Michal Wajdeczko
2024-10-08  7:30 ` ✓ CI.Hooks: success for Fix xe_force_wake_get() failure handling (rev9) Patchwork
2024-10-08  7:32 ` ✓ CI.checksparse: " Patchwork
2024-10-08  8:12 ` ✗ CI.BAT: failure " Patchwork
2024-10-08 10:44 ` ✗ CI.FULL: " 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=07234b5f-4e89-43f2-b978-826e2a4b651e@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=nirmoy.das@intel.com \
    --cc=rodrigo.vivi@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