From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Christian König" <christian.koenig@amd.com>,
"Somalapuram Amaranath" <Amaranath.Somalapuram@amd.com>,
"Paulo Zanoni" <paulo.r.zanoni@intel.com>,
"Simona Vetter" <simona.vetter@ffwll.ch>,
dri-devel@lists.freedesktop.org
Subject: [PATCH v14 1/8] drm/ttm: Balance ttm_resource_cursor_init() and ttm_resource_cursor_fini()
Date: Fri, 15 Nov 2024 16:01:13 +0100 [thread overview]
Message-ID: <20241115150120.3280-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20241115150120.3280-1-thomas.hellstrom@linux.intel.com>
Make the interface more symmetric by providing and using a
ttm_resource_cursor_init().
v10:
- Fix a stray newline (Matthew Brost)
- Update kerneldoc (Matthew Brost)
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
drivers/gpu/drm/ttm/ttm_bo_util.c | 3 ++-
drivers/gpu/drm/ttm/ttm_resource.c | 35 ++++++++++++++++++++----------
include/drm/ttm/ttm_resource.h | 11 +++++-----
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 48c5365efca1..06d6a452c4f4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -450,7 +450,8 @@ int ttm_bo_evict_first(struct ttm_device *bdev, struct ttm_resource_manager *man
int ret = 0;
spin_lock(&bdev->lru_lock);
- res = ttm_resource_manager_first(man, &cursor);
+ ttm_resource_cursor_init(&cursor, man);
+ res = ttm_resource_manager_first(&cursor);
ttm_resource_cursor_fini(&cursor);
if (!res) {
ret = -ENOENT;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index d939925efa81..917096bd5f68 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -865,7 +865,8 @@ s64 ttm_lru_walk_for_evict(struct ttm_lru_walk *walk, struct ttm_device *bdev,
s64 lret;
spin_lock(&bdev->lru_lock);
- ttm_resource_manager_for_each_res(man, &cursor, res) {
+ ttm_resource_cursor_init(&cursor, man);
+ ttm_resource_manager_for_each_res(&cursor, res) {
struct ttm_buffer_object *bo = res->bo;
bool bo_needs_unlock = false;
bool bo_locked = false;
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index a87665eb28a6..e19360cc7930 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -81,6 +81,23 @@ static void ttm_bulk_move_drop_cursors(struct ttm_lru_bulk_move *bulk)
ttm_resource_cursor_clear_bulk(cursor);
}
+/**
+ * ttm_resource_cursor_init() - Initialize a struct ttm_resource_cursor
+ * @cursor: The cursor to initialize.
+ * @man: The resource manager.
+ *
+ * Initialize the cursor before using it for iteration.
+ */
+void ttm_resource_cursor_init(struct ttm_resource_cursor *cursor,
+ struct ttm_resource_manager *man)
+{
+ cursor->priority = 0;
+ cursor->man = man;
+ ttm_lru_item_init(&cursor->hitch, TTM_LRU_HITCH);
+ INIT_LIST_HEAD(&cursor->bulk_link);
+ INIT_LIST_HEAD(&cursor->hitch.link);
+}
+
/**
* ttm_resource_cursor_fini() - Finalize the LRU list cursor usage
* @cursor: The struct ttm_resource_cursor to finalize.
@@ -593,7 +610,6 @@ ttm_resource_cursor_check_bulk(struct ttm_resource_cursor *cursor,
/**
* ttm_resource_manager_first() - Start iterating over the resources
* of a resource manager
- * @man: resource manager to iterate over
* @cursor: cursor to record the position
*
* Initializes the cursor and starts iterating. When done iterating,
@@ -602,17 +618,16 @@ ttm_resource_cursor_check_bulk(struct ttm_resource_cursor *cursor,
* Return: The first resource from the resource manager.
*/
struct ttm_resource *
-ttm_resource_manager_first(struct ttm_resource_manager *man,
- struct ttm_resource_cursor *cursor)
+ttm_resource_manager_first(struct ttm_resource_cursor *cursor)
{
- lockdep_assert_held(&man->bdev->lru_lock);
+ struct ttm_resource_manager *man = cursor->man;
- cursor->priority = 0;
- cursor->man = man;
- ttm_lru_item_init(&cursor->hitch, TTM_LRU_HITCH);
- INIT_LIST_HEAD(&cursor->bulk_link);
- list_add(&cursor->hitch.link, &man->lru[cursor->priority]);
+ if (WARN_ON_ONCE(!man))
+ return NULL;
+
+ lockdep_assert_held(&man->bdev->lru_lock);
+ list_move(&cursor->hitch.link, &man->lru[cursor->priority]);
return ttm_resource_manager_next(cursor);
}
@@ -648,8 +663,6 @@ ttm_resource_manager_next(struct ttm_resource_cursor *cursor)
ttm_resource_cursor_clear_bulk(cursor);
}
- ttm_resource_cursor_fini(cursor);
-
return NULL;
}
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index be034be56ba1..e1f3b95d73b6 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -325,6 +325,9 @@ struct ttm_resource_cursor {
unsigned int priority;
};
+void ttm_resource_cursor_init(struct ttm_resource_cursor *cursor,
+ struct ttm_resource_manager *man);
+
void ttm_resource_cursor_fini(struct ttm_resource_cursor *cursor);
/**
@@ -456,8 +459,7 @@ void ttm_resource_manager_debug(struct ttm_resource_manager *man,
struct drm_printer *p);
struct ttm_resource *
-ttm_resource_manager_first(struct ttm_resource_manager *man,
- struct ttm_resource_cursor *cursor);
+ttm_resource_manager_first(struct ttm_resource_cursor *cursor);
struct ttm_resource *
ttm_resource_manager_next(struct ttm_resource_cursor *cursor);
@@ -466,14 +468,13 @@ ttm_lru_first_res_or_null(struct list_head *head);
/**
* ttm_resource_manager_for_each_res - iterate over all resources
- * @man: the resource manager
* @cursor: struct ttm_resource_cursor for the current position
* @res: the current resource
*
* Iterate over all the evictable resources in a resource manager.
*/
-#define ttm_resource_manager_for_each_res(man, cursor, res) \
- for (res = ttm_resource_manager_first(man, cursor); res; \
+#define ttm_resource_manager_for_each_res(cursor, res) \
+ for (res = ttm_resource_manager_first(cursor); res; \
res = ttm_resource_manager_next(cursor))
struct ttm_kmap_iter *
--
2.46.2
next prev parent reply other threads:[~2024-11-15 15:01 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 15:01 [PATCH v14 0/8] TTM shrinker helpers and xe buffer object shrinker Thomas Hellström
2024-11-15 15:01 ` Thomas Hellström [this message]
2024-11-20 10:51 ` [PATCH v14 1/8] drm/ttm: Balance ttm_resource_cursor_init() and ttm_resource_cursor_fini() Christian König
2024-11-21 15:54 ` Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 2/8] drm/ttm: Provide a shmem backup implementation Thomas Hellström
2024-11-19 13:40 ` Christian König
2024-11-20 7:58 ` Thomas Hellström
2024-11-20 9:24 ` Christian König
2024-11-20 10:34 ` Thomas Hellström
2024-11-20 10:50 ` Christian König
2024-11-20 11:07 ` Thomas Hellström
2024-11-20 11:20 ` Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 3/8] drm/ttm/pool: Provide a helper to shrink pages Thomas Hellström
2024-12-03 13:12 ` Christian König
2024-12-03 13:42 ` Thomas Hellström
2024-12-03 14:51 ` Christian König
2024-12-03 15:50 ` Thomas Hellström
2024-12-03 16:20 ` Christian König
2024-12-03 16:31 ` Thomas Hellström
2024-12-03 16:39 ` Christian König
2024-12-03 16:43 ` Thomas Hellström
2024-12-03 16:46 ` Christian König
2024-12-03 17:44 ` Thomas Hellström
2024-12-04 9:16 ` Christian König
2024-12-04 9:56 ` Thomas Hellström
2024-12-04 10:56 ` Christian König
2024-12-04 11:09 ` Thomas Hellström
2024-12-04 11:24 ` Christian König
2024-12-04 12:24 ` Thomas Hellström
2024-12-18 10:07 ` Thomas Hellström
2024-12-18 10:15 ` Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 4/8] drm/ttm: Use fault-injection to test error paths Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 5/8] drm/ttm: Add a macro to perform LRU iteration Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 6/8] drm/ttm: Add helpers for shrinking Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 7/8] drm/xe: Add a shrinker for xe bos Thomas Hellström
2024-11-15 15:01 ` [PATCH v14 8/8] drm/xe: Increase the XE_PL_TT watermark Thomas Hellström
2024-11-15 15:06 ` ✓ CI.Patch_applied: success for TTM shrinker helpers and xe buffer object shrinker (rev13) Patchwork
2024-11-15 15:07 ` ✗ CI.checkpatch: warning " Patchwork
2024-11-15 15:08 ` ✓ CI.KUnit: success " Patchwork
2024-11-15 15:17 ` ✗ CI.Build: failure " Patchwork
2024-11-16 11:26 ` ✓ CI.Patch_applied: success for TTM shrinker helpers and xe buffer object shrinker (rev14) Patchwork
2024-11-16 11:26 ` ✗ CI.checkpatch: warning " Patchwork
2024-11-16 11:28 ` ✓ CI.KUnit: success " Patchwork
2024-11-16 11:46 ` ✓ CI.Build: " Patchwork
2024-11-16 11:46 ` ✗ CI.Hooks: failure " Patchwork
2024-11-16 11:47 ` ✗ CI.checksparse: warning " Patchwork
2024-11-18 12:37 ` ✓ CI.Patch_applied: success for TTM shrinker helpers and xe buffer object shrinker (rev15) Patchwork
2024-11-18 12:37 ` ✗ CI.checkpatch: warning " Patchwork
2024-11-18 12:38 ` ✓ CI.KUnit: success " Patchwork
2024-11-18 12:56 ` ✓ CI.Build: " Patchwork
2024-11-18 12:56 ` ✗ CI.Hooks: failure " Patchwork
2024-11-18 12:58 ` ✗ CI.checksparse: warning " Patchwork
2024-11-18 13:16 ` ✓ CI.BAT: success " Patchwork
2024-11-18 16:29 ` ✗ 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=20241115150120.3280-2-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=Amaranath.Somalapuram@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=paulo.r.zanoni@intel.com \
--cc=simona.vetter@ffwll.ch \
/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.