From: Oak Zeng <oak.zeng@intel.com>
To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Cc: felix.kuehling@amd.com, airlied@gmail.com, christian.koenig@amd.com
Subject: [Intel-xe] [RFC 09/11] drm/ttm: Use drm LRU manager iterator
Date: Thu, 2 Nov 2023 00:33:04 -0400 [thread overview]
Message-ID: <20231102043306.2931989-10-oak.zeng@intel.com> (raw)
In-Reply-To: <20231102043306.2931989-1-oak.zeng@intel.com>
Since TTM resource LRU list is moved to drm LRU manager layer,
use drm lru manager iterator instead of TTM resource manager
iterator. TTM resource manager iterator is deleted. No function
change.
Signed-off-by: Oak Zeng <oak.zeng@intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 7 ++--
drivers/gpu/drm/ttm/ttm_device.c | 10 ++++--
drivers/gpu/drm/ttm/ttm_resource.c | 51 ------------------------------
include/drm/ttm/ttm_resource.h | 33 ++-----------------
4 files changed, 14 insertions(+), 87 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 26e0555bad0c..4a5ffa920665 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -43,6 +43,7 @@
#include <linux/module.h>
#include <linux/atomic.h>
#include <linux/dma-resv.h>
+#include <drm/drm_evictable_lru.h>
#include "ttm_module.h"
@@ -593,15 +594,17 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
struct ww_acquire_ctx *ticket)
{
struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
- struct ttm_resource_cursor cursor;
+ struct drm_lru_cursor cursor;
struct ttm_resource *res;
+ struct drm_lru_entity *entity;
bool locked = false;
int ret;
spin_lock(bdev->lru_lock);
- ttm_resource_manager_for_each_res(man, &cursor, res) {
+ drm_lru_for_each_entity(man->lru_mgr, &cursor, entity) {
bool busy;
+ res = container_of(entity, struct ttm_resource, lru_entity);
if (!ttm_bo_evict_swapout_allowable(res->bo, ctx, place,
&locked, &busy)) {
if (busy && !busy_bo && ticket !=
diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index 393c3e27016e..881662d69aba 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -33,6 +33,7 @@
#include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/ttm/ttm_placement.h>
+#include <drm/drm_evictable_lru.h>
#include "ttm_module.h"
@@ -141,7 +142,8 @@ int ttm_global_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags)
int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
gfp_t gfp_flags)
{
- struct ttm_resource_cursor cursor;
+ struct drm_lru_cursor cursor;
+ struct drm_lru_entity *entity;
struct ttm_resource_manager *man;
struct ttm_resource *res;
unsigned i;
@@ -153,10 +155,12 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
if (!man || !man->use_tt)
continue;
- ttm_resource_manager_for_each_res(man, &cursor, res) {
- struct ttm_buffer_object *bo = res->bo;
+ drm_lru_for_each_entity(man->lru_mgr, &cursor, entity) {
+ struct ttm_buffer_object *bo;
uint32_t num_pages;
+ res = container_of(entity, struct ttm_resource, lru_entity);
+ bo = res->bo;
if (!bo || bo->resource != res)
continue;
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 05eef866065e..0c6e0dbeff07 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -488,57 +488,6 @@ void ttm_resource_manager_debug(struct ttm_resource_manager *man,
}
EXPORT_SYMBOL(ttm_resource_manager_debug);
-/**
- * ttm_resource_manager_first
- *
- * @man: resource manager to iterate over
- * @cursor: cursor to record the position
- *
- * Returns the first resource from the resource manager.
- */
-struct ttm_resource *
-ttm_resource_manager_first(struct ttm_resource_manager *man,
- struct ttm_resource_cursor *cursor)
-{
- struct ttm_resource *res;
-
- lockdep_assert_held(man->bdev->lru_lock);
-
- for (cursor->priority = 0; cursor->priority < DRM_MAX_LRU_PRIORITY;
- ++cursor->priority)
- list_for_each_entry(res, &man->lru[cursor->priority], lru)
- return res;
-
- return NULL;
-}
-
-/**
- * ttm_resource_manager_next
- *
- * @man: resource manager to iterate over
- * @cursor: cursor to record the position
- * @res: the current resource pointer
- *
- * Returns the next resource from the resource manager.
- */
-struct ttm_resource *
-ttm_resource_manager_next(struct ttm_resource_manager *man,
- struct ttm_resource_cursor *cursor,
- struct ttm_resource *res)
-{
- lockdep_assert_held(man->bdev->lru_lock);
-
- list_for_each_entry_continue(res, &man->lru[cursor->priority], lru)
- return res;
-
- for (++cursor->priority; cursor->priority < DRM_MAX_LRU_PRIORITY;
- ++cursor->priority)
- list_for_each_entry(res, &man->lru[cursor->priority], lru)
- return res;
-
- return NULL;
-}
-
static void ttm_kmap_iter_iomap_map_local(struct ttm_kmap_iter *iter,
struct iosys_map *dmap,
pgoff_t i)
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index e4fc1ada5236..c2528cec12e6 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -207,6 +207,7 @@ struct ttm_bus_placement {
* @placement: Placement flags.
* @bus: Placement on io bus accessible to the CPU
* @bo: weak reference to the BO, protected by ttm_device::lru_lock
+ * @lru_entity: lru entity for this ttm resource.
*
* Structure indicating the placement and space resources used by a
* buffer object.
@@ -223,17 +224,7 @@ struct ttm_resource {
* @lru: Least recently used list, see &ttm_resource_manager.lru
*/
struct list_head lru;
-};
-
-/**
- * struct ttm_resource_cursor
- *
- * @priority: the current priority
- *
- * Cursor to iterate over the resources in a manager.
- */
-struct ttm_resource_cursor {
- unsigned int priority;
+ struct drm_lru_entity lru_entity;
};
/**
@@ -402,26 +393,6 @@ uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man);
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);
-struct ttm_resource *
-ttm_resource_manager_next(struct ttm_resource_manager *man,
- struct ttm_resource_cursor *cursor,
- struct ttm_resource *res);
-
-/**
- * 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; \
- res = ttm_resource_manager_next(man, cursor, res))
-
struct ttm_kmap_iter *
ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io,
struct io_mapping *iomap,
--
2.26.3
next prev parent reply other threads:[~2023-11-02 4:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-02 4:32 [Intel-xe] [PATCH 00/11] Introduce drm evictable lru Oak Zeng
2023-11-02 4:27 ` [Intel-xe] ✗ CI.Patch_applied: failure for " Patchwork
2023-11-02 4:32 ` [Intel-xe] [RFC 01/11] drm/ttm: re-parameter ttm_device_init Oak Zeng
2023-11-02 4:32 ` [Intel-xe] [RFC 02/11] drm: move lru_lock from ttm_device to drm_device Oak Zeng
2023-11-02 12:53 ` Christian König
2023-11-03 3:26 ` Zeng, Oak
2023-11-02 4:32 ` [Intel-xe] [RFC 03/11] drm: introduce drm evictable LRU Oak Zeng
2023-11-02 13:23 ` Christian König
2023-11-03 4:04 ` Zeng, Oak
2023-11-03 9:36 ` Christian König
2023-11-03 14:36 ` Zeng, Oak
2023-11-02 4:32 ` [Intel-xe] [RFC 04/11] drm: Add evict function pointer to drm lru entity Oak Zeng
2023-11-02 4:33 ` [Intel-xe] [RFC 05/11] drm: Replace ttm macros with drm macros Oak Zeng
2023-11-02 4:33 ` [Intel-xe] [RFC 06/11] drm/ttm: Set lru manager to ttm resource manager Oak Zeng
2023-11-02 4:33 ` [Intel-xe] [RFC 07/11] drm/ttm: re-parameterize a few ttm functions Oak Zeng
2023-11-02 4:33 ` [Intel-xe] [RFC 08/11] drm: Initialize drm lru manager Oak Zeng
2023-11-02 4:33 ` Oak Zeng [this message]
2023-11-02 4:33 ` [Intel-xe] [RFC 10/11] drm/ttm: Implement ttm memory evict functions Oak Zeng
2023-11-02 4:33 ` [Intel-xe] [RFC 11/11] drm/ttm: Write ttm functions using drm lru manager functions Oak Zeng
2023-12-21 13:12 ` [PATCH 00/11] Introduce drm evictable lru Thomas Hellström
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=20231102043306.2931989-10-oak.zeng@intel.com \
--to=oak.zeng@intel.com \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
--cc=intel-xe@lists.freedesktop.org \
/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