mirror of
https://github.com/torvalds/linux.git
synced 2026-04-23 09:05:50 -04:00
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: Karolina Stolarek <karolina.stolarek@intel.com> Reviewed-by: Somalapuram, Amaranath <asomalap@amd.com> Tested-by: Somalapuram, Amaranath <asomalap@amd.com> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/ae8e284d6c7e6bd0be259052bd4f42e07ce24641.1718192625.git.karolina.stolarek@intel.com
This commit is contained in:
committed by
Arunpravin Paneer Selvam
parent
8eda41dfc9
commit
5fe3943385
@@ -6,6 +6,42 @@
|
||||
|
||||
#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,
|
||||
uint32_t page_flags)
|
||||
{
|
||||
@@ -54,10 +90,52 @@ static int mock_move(struct ttm_buffer_object *bo, bool evict,
|
||||
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 = {
|
||||
.ttm_tt_create = ttm_tt_simple_create,
|
||||
.ttm_tt_destroy = ttm_tt_simple_destroy,
|
||||
.move = mock_move,
|
||||
.eviction_valuable = ttm_bo_eviction_valuable,
|
||||
.evict_flags = mock_evict_flags,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(ttm_dev_funcs);
|
||||
|
||||
@@ -66,18 +144,30 @@ int ttm_device_kunit_init(struct ttm_test_devices *priv,
|
||||
bool use_dma_alloc,
|
||||
bool use_dma32)
|
||||
{
|
||||
struct drm_device *drm = priv->drm;
|
||||
int err;
|
||||
|
||||
err = ttm_device_init(ttm, &ttm_dev_funcs, drm->dev,
|
||||
drm->anon_inode->i_mapping,
|
||||
drm->vma_offset_manager,
|
||||
use_dma_alloc, use_dma32);
|
||||
|
||||
return err;
|
||||
return ttm_device_kunit_init_with_funcs(priv, ttm, use_dma_alloc,
|
||||
use_dma32, &ttm_dev_funcs);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ttm_device_kunit_init);
|
||||
|
||||
struct ttm_device_funcs ttm_dev_funcs_bad_evict = {
|
||||
.ttm_tt_create = ttm_tt_simple_create,
|
||||
.ttm_tt_destroy = ttm_tt_simple_destroy,
|
||||
.move = mock_move,
|
||||
.eviction_valuable = ttm_bo_eviction_valuable,
|
||||
.evict_flags = bad_evict_flags,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(ttm_dev_funcs_bad_evict);
|
||||
|
||||
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_bad_evict);
|
||||
|
||||
struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test,
|
||||
struct ttm_test_devices *devs,
|
||||
size_t size,
|
||||
|
||||
Reference in New Issue
Block a user