Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>,
	Michal Wajdeczko <michal.wajdeczko@intel.com>,
	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: [PATCH v3 01/23] drm/xe: Error handling in xe_force_wake_get()
Date: Tue, 17 Sep 2024 17:51:04 +0530	[thread overview]
Message-ID: <20240917122126.438448-2-himal.prasad.ghimiray@intel.com> (raw)
In-Reply-To: <20240917122126.438448-1-himal.prasad.ghimiray@intel.com>

If an acknowledgment timeout occurs for a 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 whose reference counts were
incremented, and these domains need to be released using
xe_force_wake_put.

The caller needs to compare the return value with the input domains to
determine the success or failure of the operation and decide whether to
continue or return accordingly.

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)

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>
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
---
 drivers/gpu/drm/xe/xe_force_wake.c       | 37 +++++++++++++++++++-----
 drivers/gpu/drm/xe/xe_force_wake.h       |  4 +--
 drivers/gpu/drm/xe/xe_force_wake_types.h |  2 ++
 3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_force_wake.c b/drivers/gpu/drm/xe/xe_force_wake.c
index a64c14757c84..bc0cb988e12f 100644
--- a/drivers/gpu/drm/xe/xe_force_wake.c
+++ b/drivers/gpu/drm/xe/xe_force_wake.c
@@ -150,26 +150,47 @@ 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
+ * they are asleep.
+ *
+ * Return: mask of refcount increased domains. If the return value is
+ * equal to the input parameter @domains, the operation is considered
+ * successful. Otherwise, the operation is considered a failure, and
+ * the caller should handle the failure case, potentially returning
+ * -ETIMEDOUT.
+ */
+xe_wakeref_t 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 tmp, awake_rqst = 0, awake_ack = 0;
 	unsigned long flags;
-	int ret = 0;
+	xe_wakeref_t ret;
 
+	ret = domains;
 	spin_lock_irqsave(&fw->lock, flags);
 	for_each_fw_domain_masked(domain, domains, fw, tmp) {
 		if (!domain->ref++) {
-			woken |= BIT(domain->id);
+			awake_rqst |= BIT(domain->id);
 			domain_wake(gt, domain);
 		}
 	}
-	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) {
+			awake_ack |= BIT(domain->id);
+		} else {
+			ret &= ~BIT(domain->id);
+			--domain->ref;
+		}
 	}
-	fw->awake_domains |= woken;
+
+	fw->awake_domains |= awake_ack;
 	spin_unlock_irqrestore(&fw->lock, flags);
 
 	return ret;
diff --git a/drivers/gpu/drm/xe/xe_force_wake.h b/drivers/gpu/drm/xe/xe_force_wake.h
index a2577672f4e3..3ac686519a4e 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);
+xe_wakeref_t 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 ed0edc2cdf9f..7dc514ee9825 100644
--- a/drivers/gpu/drm/xe/xe_force_wake_types.h
+++ b/drivers/gpu/drm/xe/xe_force_wake_types.h
@@ -11,6 +11,8 @@
 
 #include "regs/xe_reg_defs.h"
 
+typedef unsigned int xe_wakeref_t;
+
 enum xe_force_wake_domain_id {
 	XE_FW_DOMAIN_ID_GT = 0,
 	XE_FW_DOMAIN_ID_RENDER,
-- 
2.34.1


  reply	other threads:[~2024-09-17 12:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17 12:21 [PATCH v3 00/23] Fix xe_force_wake_get() failure handling Himal Prasad Ghimiray
2024-09-17 12:21 ` Himal Prasad Ghimiray [this message]
2024-09-17 12:21 ` [PATCH v3 02/23] drm/xe: Modify xe_force_wake_put to handle _get returned mask Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 03/23] drm/xe/device: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 04/23] drm/xe/hdcp: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 05/23] drm/xe/gsc: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 06/23] drm/xe/gt: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 07/23] drm/xe/xe_gt_idle: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 08/23] drm/xe/devcoredump: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 09/23] drm/xe/tests/mocs: Update xe_force_wake_get() return handling Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 10/23] drm/xe/mocs: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 11/23] drm/xe/xe_drm_client: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 12/23] drm/xe/xe_gt_debugfs: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 13/23] drm/xe/guc: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 14/23] drm/xe/huc: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 15/23] drm/xe/oa: Handle force_wake_get failure in xe_oa_stream_init() Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 16/23] drm/xe/pat: Update handling of xe_force_wake_get return Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 17/23] drm/xe/gt_tlb_invalidation_ggtt: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 18/23] drm/xe/xe_reg_sr: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 19/23] drm/xe/query: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 20/23] drm/xe/vram: " Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 21/23] drm/xe: forcewake debugfs open fails on xe_forcewake_get failure Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 22/23] drm/xe: Ensure __must_check for xe_force_wake_get() return Himal Prasad Ghimiray
2024-09-17 12:21 ` [PATCH v3 23/23] drm/xe: Change return type to void for xe_force_wake_put Himal Prasad Ghimiray
2024-09-17 13:18 ` ✓ CI.Patch_applied: success for Fix xe_force_wake_get() failure handling (rev3) Patchwork
2024-09-17 13:18 ` ✗ CI.checkpatch: warning " Patchwork
2024-09-17 13:20 ` ✓ CI.KUnit: success " Patchwork
2024-09-17 13:35 ` ✓ CI.Build: " Patchwork
2024-09-17 13:37 ` ✓ CI.Hooks: " Patchwork
2024-09-17 13:39 ` ✓ CI.checksparse: " Patchwork
2024-09-17 14:05 ` ✗ CI.BAT: failure " Patchwork
2024-09-17 17:53   ` Ghimiray, Himal Prasad
2024-09-17 16:55 ` ✗ 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=20240917122126.438448-2-himal.prasad.ghimiray@intel.com \
    --to=himal.prasad.ghimiray@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=michal.wajdeczko@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