Commit 5fe39433 authored by Karolina Stolarek's avatar Karolina Stolarek Committed by Arunpravin Paneer Selvam

drm/ttm/tests: Add eviction testing

Add tests for ttm_bo_validate that focus on BO eviction and swapout.
Update device funcs definition with eviction-related callbacks. Add
alternative funcs where evict_flags() routes eviction to a domain
that can't allocate resources (dubbed "busy manager" in the tests).
Extract the common path of ttm_device init into a function.
Signed-off-by: default avatarKarolina Stolarek <karolina.stolarek@intel.com>
Reviewed-by: default avatarSomalapuram, Amaranath <asomalap@amd.com>
Tested-by: default avatarSomalapuram, Amaranath <asomalap@amd.com>
Signed-off-by: default avatarArunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/ae8e284d6c7e6bd0be259052bd4f42e07ce24641.1718192625.git.karolina.stolarek@intel.com
parent 8eda41df
...@@ -6,6 +6,42 @@ ...@@ -6,6 +6,42 @@
#include "ttm_kunit_helpers.h" #include "ttm_kunit_helpers.h"
static const struct ttm_place sys_place = {
.fpfn = 0,
.lpfn = 0,
.mem_type = TTM_PL_SYSTEM,
.flags = TTM_PL_FLAG_FALLBACK,
};
static const struct ttm_place mock1_place = {
.fpfn = 0,
.lpfn = 0,
.mem_type = TTM_PL_MOCK1,
.flags = TTM_PL_FLAG_FALLBACK,
};
static const struct ttm_place mock2_place = {
.fpfn = 0,
.lpfn = 0,
.mem_type = TTM_PL_MOCK2,
.flags = TTM_PL_FLAG_FALLBACK,
};
static struct ttm_placement sys_placement = {
.num_placement = 1,
.placement = &sys_place,
};
static struct ttm_placement bad_placement = {
.num_placement = 1,
.placement = &mock1_place,
};
static struct ttm_placement mock_placement = {
.num_placement = 1,
.placement = &mock2_place,
};
static struct ttm_tt *ttm_tt_simple_create(struct ttm_buffer_object *bo, static struct ttm_tt *ttm_tt_simple_create(struct ttm_buffer_object *bo,
uint32_t page_flags) uint32_t page_flags)
{ {
...@@ -54,10 +90,52 @@ static int mock_move(struct ttm_buffer_object *bo, bool evict, ...@@ -54,10 +90,52 @@ static int mock_move(struct ttm_buffer_object *bo, bool evict,
return ttm_bo_move_memcpy(bo, ctx, new_mem); return ttm_bo_move_memcpy(bo, ctx, new_mem);
} }
static void mock_evict_flags(struct ttm_buffer_object *bo,
struct ttm_placement *placement)
{
switch (bo->resource->mem_type) {
case TTM_PL_VRAM:
case TTM_PL_SYSTEM:
*placement = sys_placement;
break;
case TTM_PL_TT:
*placement = mock_placement;
break;
case TTM_PL_MOCK1:
/* Purge objects coming from this domain */
break;
}
}
static void bad_evict_flags(struct ttm_buffer_object *bo,
struct ttm_placement *placement)
{
*placement = bad_placement;
}
static int ttm_device_kunit_init_with_funcs(struct ttm_test_devices *priv,
struct ttm_device *ttm,
bool use_dma_alloc,
bool use_dma32,
struct ttm_device_funcs *funcs)
{
struct drm_device *drm = priv->drm;
int err;
err = ttm_device_init(ttm, funcs, drm->dev,
drm->anon_inode->i_mapping,
drm->vma_offset_manager,
use_dma_alloc, use_dma32);
return err;
}
struct ttm_device_funcs ttm_dev_funcs = { struct ttm_device_funcs ttm_dev_funcs = {
.ttm_tt_create = ttm_tt_simple_create, .ttm_tt_create = ttm_tt_simple_create,
.ttm_tt_destroy = ttm_tt_simple_destroy, .ttm_tt_destroy = ttm_tt_simple_destroy,
.move = mock_move, .move = mock_move,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = mock_evict_flags,
}; };
EXPORT_SYMBOL_GPL(ttm_dev_funcs); EXPORT_SYMBOL_GPL(ttm_dev_funcs);
...@@ -66,17 +144,29 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv, ...@@ -66,17 +144,29 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv,
bool use_dma_alloc, bool use_dma_alloc,
bool use_dma32) bool use_dma32)
{ {
struct drm_device *drm = priv->drm; return ttm_device_kunit_init_with_funcs(priv, ttm, use_dma_alloc,
int err; use_dma32, &ttm_dev_funcs);
}
EXPORT_SYMBOL_GPL(ttm_device_kunit_init);
err = ttm_device_init(ttm, &ttm_dev_funcs, drm->dev, struct ttm_device_funcs ttm_dev_funcs_bad_evict = {
drm->anon_inode->i_mapping, .ttm_tt_create = ttm_tt_simple_create,
drm->vma_offset_manager, .ttm_tt_destroy = ttm_tt_simple_destroy,
use_dma_alloc, use_dma32); .move = mock_move,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = bad_evict_flags,
};
EXPORT_SYMBOL_GPL(ttm_dev_funcs_bad_evict);
return err; int ttm_device_kunit_init_bad_evict(struct ttm_test_devices *priv,
struct ttm_device *ttm,
bool use_dma_alloc,
bool use_dma32)
{
return ttm_device_kunit_init_with_funcs(priv, ttm, use_dma_alloc,
use_dma32, &ttm_dev_funcs_bad_evict);
} }
EXPORT_SYMBOL_GPL(ttm_device_kunit_init); EXPORT_SYMBOL_GPL(ttm_device_kunit_init_bad_evict);
struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test, struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test,
struct ttm_test_devices *devs, struct ttm_test_devices *devs,
......
...@@ -13,7 +13,11 @@ ...@@ -13,7 +13,11 @@
#include <drm/drm_kunit_helpers.h> #include <drm/drm_kunit_helpers.h>
#include <kunit/test.h> #include <kunit/test.h>
#define TTM_PL_MOCK1 (TTM_PL_PRIV + 1)
#define TTM_PL_MOCK2 (TTM_PL_PRIV + 2)
extern struct ttm_device_funcs ttm_dev_funcs; extern struct ttm_device_funcs ttm_dev_funcs;
extern struct ttm_device_funcs ttm_dev_funcs_bad_evict;
struct ttm_test_devices { struct ttm_test_devices {
struct drm_device *drm; struct drm_device *drm;
...@@ -26,6 +30,10 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv, ...@@ -26,6 +30,10 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv,
struct ttm_device *ttm, struct ttm_device *ttm,
bool use_dma_alloc, bool use_dma_alloc,
bool use_dma32); bool use_dma32);
int ttm_device_kunit_init_bad_evict(struct ttm_test_devices *priv,
struct ttm_device *ttm,
bool use_dma_alloc,
bool use_dma32);
struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test, struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test,
struct ttm_test_devices *devs, struct ttm_test_devices *devs,
size_t size, size_t size,
......
...@@ -153,6 +153,14 @@ static int ttm_bad_manager_alloc(struct ttm_resource_manager *man, ...@@ -153,6 +153,14 @@ static int ttm_bad_manager_alloc(struct ttm_resource_manager *man,
return -ENOSPC; return -ENOSPC;
} }
static int ttm_busy_manager_alloc(struct ttm_resource_manager *man,
struct ttm_buffer_object *bo,
const struct ttm_place *place,
struct ttm_resource **res)
{
return -EBUSY;
}
static void ttm_bad_manager_free(struct ttm_resource_manager *man, static void ttm_bad_manager_free(struct ttm_resource_manager *man,
struct ttm_resource *res) struct ttm_resource *res)
{ {
...@@ -172,6 +180,12 @@ static const struct ttm_resource_manager_func ttm_bad_manager_funcs = { ...@@ -172,6 +180,12 @@ static const struct ttm_resource_manager_func ttm_bad_manager_funcs = {
.compatible = ttm_bad_manager_compatible .compatible = ttm_bad_manager_compatible
}; };
static const struct ttm_resource_manager_func ttm_bad_busy_manager_funcs = {
.alloc = ttm_busy_manager_alloc,
.free = ttm_bad_manager_free,
.compatible = ttm_bad_manager_compatible
};
int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size) int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size)
{ {
struct ttm_resource_manager *man; struct ttm_resource_manager *man;
...@@ -190,7 +204,20 @@ int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size) ...@@ -190,7 +204,20 @@ int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size)
} }
EXPORT_SYMBOL_GPL(ttm_bad_manager_init); EXPORT_SYMBOL_GPL(ttm_bad_manager_init);
void ttm_bad_manager_fini(struct ttm_device *bdev, u32 mem_type) int ttm_busy_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size)
{
struct ttm_resource_manager *man;
ttm_bad_manager_init(bdev, mem_type, size);
man = ttm_manager_type(bdev, mem_type);
man->func = &ttm_bad_busy_manager_funcs;
return 0;
}
EXPORT_SYMBOL_GPL(ttm_busy_manager_init);
void ttm_bad_manager_fini(struct ttm_device *bdev, uint32_t mem_type)
{ {
struct ttm_resource_manager *man; struct ttm_resource_manager *man;
......
...@@ -23,6 +23,7 @@ struct ttm_mock_resource { ...@@ -23,6 +23,7 @@ struct ttm_mock_resource {
int ttm_mock_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size); int ttm_mock_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size);
int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size); int ttm_bad_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size);
int ttm_busy_manager_init(struct ttm_device *bdev, u32 mem_type, u32 size);
void ttm_mock_manager_fini(struct ttm_device *bdev, u32 mem_type); void ttm_mock_manager_fini(struct ttm_device *bdev, u32 mem_type);
void ttm_bad_manager_fini(struct ttm_device *bdev, u32 mem_type); void ttm_bad_manager_fini(struct ttm_device *bdev, u32 mem_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment