From: Matthew Auld <matthew.auld@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: [Intel-xe] [PATCH v5 2/7] Revert "drm/xe: Use atomic instead of mutex for xe_device_mem_access_ongoing"
Date: Wed, 17 May 2023 16:22:39 +0100 [thread overview]
Message-ID: <20230517152244.348171-2-matthew.auld@intel.com> (raw)
In-Reply-To: <20230517152244.348171-1-matthew.auld@intel.com>
This reverts commit c3712d924f6b5022498f4357009943c326389f9c.
We add a similar version back, once we fix the locking inside
xe_device_mem_access.
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
drivers/gpu/drm/xe/xe_device.c | 18 ++++++++++--------
drivers/gpu/drm/xe/xe_device.h | 18 ++++++++++++------
drivers/gpu/drm/xe/xe_device_types.h | 4 +++-
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index f7f6a6a97757..d0297ee432b2 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -216,6 +216,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
if (err)
goto err_put;
+ drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
return xe;
err_put:
@@ -404,25 +406,25 @@ u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size)
void xe_device_mem_access_get(struct xe_device *xe)
{
bool resumed = xe_pm_runtime_resume_if_suspended(xe);
- int ref = atomic_inc_return(&xe->mem_access.ref);
- if (ref == 1)
+ mutex_lock(&xe->mem_access.lock);
+ if (xe->mem_access.ref++ == 0)
xe->mem_access.hold_rpm = xe_pm_runtime_get_if_active(xe);
+ mutex_unlock(&xe->mem_access.lock);
/* The usage counter increased if device was immediately resumed */
if (resumed)
xe_pm_runtime_put(xe);
- XE_WARN_ON(ref == S32_MAX);
+ XE_WARN_ON(xe->mem_access.ref == S32_MAX);
}
void xe_device_mem_access_put(struct xe_device *xe)
{
- bool hold = xe->mem_access.hold_rpm;
- int ref = atomic_dec_return(&xe->mem_access.ref);
-
- if (!ref && hold)
+ mutex_lock(&xe->mem_access.lock);
+ if (--xe->mem_access.ref == 0 && xe->mem_access.hold_rpm)
xe_pm_runtime_put(xe);
+ mutex_unlock(&xe->mem_access.lock);
- XE_WARN_ON(ref < 0);
+ XE_WARN_ON(xe->mem_access.ref < 0);
}
diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
index cbae480a2092..9ab7e6134f89 100644
--- a/drivers/gpu/drm/xe/xe_device.h
+++ b/drivers/gpu/drm/xe/xe_device.h
@@ -90,14 +90,20 @@ static inline struct xe_force_wake * gt_to_fw(struct xe_gt *gt)
void xe_device_mem_access_get(struct xe_device *xe);
void xe_device_mem_access_put(struct xe_device *xe);
-static inline bool xe_device_mem_access_ongoing(struct xe_device *xe)
-{
- return atomic_read(&xe->mem_access.ref);
-}
-
static inline void xe_device_assert_mem_access(struct xe_device *xe)
{
- XE_WARN_ON(!xe_device_mem_access_ongoing(xe));
+ XE_WARN_ON(!xe->mem_access.ref);
+}
+
+static inline bool xe_device_mem_access_ongoing(struct xe_device *xe)
+{
+ bool ret;
+
+ mutex_lock(&xe->mem_access.lock);
+ ret = xe->mem_access.ref;
+ mutex_unlock(&xe->mem_access.lock);
+
+ return ret;
}
static inline bool xe_device_in_fault_mode(struct xe_device *xe)
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index cbd18b839236..0b6860156574 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -256,8 +256,10 @@ struct xe_device {
* triggering additional actions when they occur.
*/
struct {
+ /** @lock: protect the ref count */
+ struct mutex lock;
/** @ref: ref count of memory accesses */
- atomic_t ref;
+ s32 ref;
/** @hold_rpm: need to put rpm ref back at the end */
bool hold_rpm;
} mem_access;
--
2.40.1
next prev parent reply other threads:[~2023-05-17 15:23 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 15:22 [Intel-xe] [PATCH v5 1/7] drm: fix drmm_mutex_init() Matthew Auld
2023-05-17 15:22 ` Matthew Auld
2023-05-17 15:22 ` Matthew Auld [this message]
2023-05-17 15:22 ` [Intel-xe] [PATCH v5 3/7] drm/xe: don't allocate under ct->lock Matthew Auld
2023-05-17 15:50 ` Rodrigo Vivi
2023-05-17 15:22 ` [Intel-xe] [PATCH v5 4/7] drm/xe: keep pulling mem_access_get further back Matthew Auld
2023-05-17 15:53 ` Rodrigo Vivi
2023-05-17 15:22 ` [Intel-xe] [PATCH v5 5/7] drm/xe/ggtt: prime ggtt->lock against FS_RECLAIM Matthew Auld
2023-05-17 15:48 ` Rodrigo Vivi
2023-05-17 16:21 ` Matthew Auld
2023-05-17 15:22 ` [Intel-xe] [PATCH v5 6/7] drm/xe: fix xe_device_mem_access_get() races Matthew Auld
2023-05-19 20:25 ` Rodrigo Vivi
2023-05-22 9:49 ` Matthew Auld
2023-05-17 15:22 ` [Intel-xe] [PATCH v5 7/7] drm/xe: Use atomic for mem_access.ref Matthew Auld
2023-05-17 15:25 ` [Intel-xe] ✓ CI.Patch_applied: success for series starting with [v5,1/7] drm: fix drmm_mutex_init() Patchwork
2023-05-17 15:27 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-17 15:31 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-05-17 15:49 ` [Intel-xe] ○ CI.BAT: info " Patchwork
2023-05-17 16:05 ` [Intel-xe] [PATCH v5 1/7] " Stanislaw Gruszka
2023-05-17 16:05 ` Stanislaw Gruszka
2023-05-17 16:29 ` [Intel-xe] " Matthew Auld
2023-05-17 16:29 ` Matthew Auld
2023-05-17 17:03 ` [Intel-xe] " Thomas Hellström
2023-05-17 17:03 ` Thomas Hellström
2023-05-17 17:47 ` [Intel-xe] " Thomas Zimmermann
2023-05-17 17:47 ` Thomas Zimmermann
2023-05-17 16:21 ` [Intel-xe] " Thomas Zimmermann
2023-05-17 16:21 ` Thomas Zimmermann
2023-05-17 17:04 ` [Intel-xe] " Matthew Auld
2023-05-17 17:04 ` Matthew Auld
2023-05-17 17:43 ` [Intel-xe] " Thomas Zimmermann
2023-05-17 17:43 ` Thomas Zimmermann
2023-05-18 9:51 ` [Intel-xe] ✓ CI.Patch_applied: success for series starting with [v5,1/7] drm: fix drmm_mutex_init() (rev2) Patchwork
2023-05-18 9:52 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-18 9:56 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-05-18 10:16 ` [Intel-xe] ○ CI.BAT: info " Patchwork
2023-05-19 15:49 ` [Intel-xe] ✓ CI.Patch_applied: success for series starting with [v5,1/7] drm: fix drmm_mutex_init() (rev3) Patchwork
2023-05-19 15:50 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-19 15:54 ` [Intel-xe] ✓ CI.Build: " 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=20230517152244.348171-2-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--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 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.