[RFC PATCH 01/18] drm/ttm: Add tracking for evicted memory
Friedrich Vock
friedrich.vock at gmx.de
Wed Apr 24 16:56:51 UTC 2024
These utilities will be used to keep track of what buffers have been
evicted from any particular place, to try and decide when to try undoing
the eviction.
Signed-off-by: Friedrich Vock <friedrich.vock at gmx.de>
---
drivers/gpu/drm/ttm/ttm_device.c | 1 +
drivers/gpu/drm/ttm/ttm_resource.c | 14 ++++++++++++++
include/drm/ttm/ttm_device.h | 5 +++++
include/drm/ttm/ttm_resource.h | 9 +++++++++
4 files changed, 29 insertions(+)
diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index f5187b384ae9a..969d627ba06c0 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -219,6 +219,7 @@ int ttm_device_init(struct ttm_device *bdev, const struct ttm_device_funcs *func
bdev->vma_manager = vma_manager;
spin_lock_init(&bdev->lru_lock);
+ spin_lock_init(&bdev->unevict_lock);
INIT_LIST_HEAD(&bdev->pinned);
bdev->dev_mapping = mapping;
mutex_lock(&ttm_global_mutex);
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 46ff9c75bb124..1d6755a1153b1 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -25,6 +25,7 @@
#include <linux/iosys-map.h>
#include <linux/io-mapping.h>
#include <linux/scatterlist.h>
+#include <linux/list.h>
#include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h>
@@ -392,9 +393,11 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
man->bdev = bdev;
man->size = size;
man->usage = 0;
+ man->evicted_bytes = 0;
for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
INIT_LIST_HEAD(&man->lru[i]);
+ INIT_LIST_HEAD(&man->evicted);
man->move = NULL;
}
EXPORT_SYMBOL(ttm_resource_manager_init);
@@ -470,6 +473,17 @@ uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man)
}
EXPORT_SYMBOL(ttm_resource_manager_usage);
+uint64_t ttm_resource_manager_evicted_bytes(struct ttm_resource_manager *man)
+{
+ uint64_t evicted;
+
+ spin_lock(&man->bdev->unevict_lock);
+ evicted = man->evicted_bytes;
+ spin_unlock(&man->bdev->unevict_lock);
+ return evicted;
+}
+EXPORT_SYMBOL(ttm_resource_manager_evicted_bytes);
+
/**
* ttm_resource_manager_debug
*
diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h
index c22f30535c848..baa264efe483d 100644
--- a/include/drm/ttm/ttm_device.h
+++ b/include/drm/ttm/ttm_device.h
@@ -251,6 +251,11 @@ struct ttm_device {
*/
spinlock_t lru_lock;
+ /**
+ * @unevict_lock: Protection for per-manager uneviction tracking
+ */
+ spinlock_t unevict_lock;
+
/**
* @pinned: Buffer objects which are pinned and so not on any LRU list.
*/
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index 78a226eba953c..7d1ce059c8805 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -145,6 +145,7 @@ struct ttm_resource_manager_func {
* @move_lock: lock for move fence
* @move: The fence of the last pipelined move operation.
* @lru: The lru list for this memory type.
+ * @evicted: List of bos evicted from this memory type
*
* This structure is used to identify and manage memory types for a device.
*/
@@ -163,6 +164,7 @@ struct ttm_resource_manager {
* Protected by @move_lock.
*/
struct dma_fence *move;
+ struct list_head evicted;
/*
* Protected by the bdev->lru_lock.
@@ -174,6 +176,12 @@ struct ttm_resource_manager {
* bdev->lru_lock.
*/
uint64_t usage;
+
+ /**
+ * @evicted_bytes: How many bytes are evicted from this manager,
+ * protexted by bdev->unevict_lock
+ */
+ uint64_t evicted_bytes;
};
/**
@@ -382,6 +390,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
struct ttm_resource_manager *man);
uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man);
+uint64_t ttm_resource_manager_evicted_bytes(struct ttm_resource_manager *man);
void ttm_resource_manager_debug(struct ttm_resource_manager *man,
struct drm_printer *p);
--
2.44.0
More information about the amd-gfx
mailing list