[PATCH v1 2/3] drm/xe/bo: Add trylock helper for buffer objects

Lukasz Laguna lukasz.laguna at intel.com
Wed Oct 16 09:57:44 UTC 2024


Wrap dma_resv_trylock() for convenient use with buffer objects.

Signed-off-by: Lukasz Laguna <lukasz.laguna at intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c | 16 +++++++++++++++-
 drivers/gpu/drm/xe/xe_bo.h |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 5b232f2951b1..6af7bc586f1c 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2168,11 +2168,25 @@ int xe_bo_lock(struct xe_bo *bo, bool intr)
 	return 0;
 }
 
+/**
+ * xe_bo_trylock() - Trylock the buffer object's dma_resv object
+ * @bo: The struct xe_bo whose lock is tried to be taken.
+ *
+ * Tries to lock the buffer object's dma_resv object.
+ *
+ * Return: true if the lock was acquired, false otherwise.
+ */
+bool xe_bo_trylock(struct xe_bo *bo)
+{
+	return dma_resv_trylock(bo->ttm.base.resv);
+}
+
 /**
  * xe_bo_unlock() - Unlock the buffer object's dma_resv object
  * @bo: The struct xe_bo whose lock is to be released.
  *
- * Unlock a buffer object lock that was locked by xe_bo_lock().
+ * Unlock a buffer object lock that was locked by xe_bo_lock() or
+ * xe_bo_trylock().
  */
 void xe_bo_unlock(struct xe_bo *bo)
 {
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 7fa44a0138b0..83992471c510 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -147,7 +147,7 @@ static inline void xe_bo_assert_held(struct xe_bo *bo)
 }
 
 int xe_bo_lock(struct xe_bo *bo, bool intr);
-
+bool xe_bo_trylock(struct xe_bo *bo);
 void xe_bo_unlock(struct xe_bo *bo);
 
 static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
-- 
2.40.0



More information about the Intel-xe mailing list