[PATCH 1/4] drm/ttm: add new intersect callback to res mgr
Christian König
christian.koenig at amd.com
Wed Jul 20 08:41:09 UTC 2022
Am 20.07.22 um 09:36 schrieb Arunpravin Paneer Selvam:
> - This allows the resource manager to handle intersection
> of placement and resources.
>
> - Add callback function to amdgpu driver module fetching
> start offset from buddy allocator.
Probably better to only add the callback and ttm_resource_intersect()
wrapper function in this patch and then move the amdgpu and
ttm_range_manager changes to separate patches.
Apart from that looks good to me.
Regards,
Christian.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 19 +++++++++++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 33 ++++++++++++++++++++
> drivers/gpu/drm/ttm/ttm_range_manager.c | 17 ++++++++++
> drivers/gpu/drm/ttm/ttm_resource.c | 28 +++++++++++++++++
> include/drm/ttm/ttm_resource.h | 20 ++++++++++++
> 5 files changed, 117 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index 8c6b2284cf56..727c80134aa6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -204,6 +204,24 @@ void amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)
> amdgpu_gart_invalidate_tlb(adev);
> }
>
> +/**
> + * amdgpu_gtt_mgr_intersect - test for intersection
> + *
> + * @man: Our manager object
> + * @res: The resource to test
> + * @place: The place for the new allocation
> + * @size: The size of the new allocation
> + *
> + * Simplified intersection test, only interesting if we need GART or not.
> + */
> +static bool amdgpu_gtt_mgr_intersect(struct ttm_resource_manager *man,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size)
> +{
> + return !place->lpfn || amdgpu_gtt_mgr_has_gart_addr(res);
> +}
> +
> /**
> * amdgpu_gtt_mgr_debug - dump VRAM table
> *
> @@ -225,6 +243,7 @@ static void amdgpu_gtt_mgr_debug(struct ttm_resource_manager *man,
> static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {
> .alloc = amdgpu_gtt_mgr_new,
> .free = amdgpu_gtt_mgr_del,
> + .intersect = amdgpu_gtt_mgr_intersect,
> .debug = amdgpu_gtt_mgr_debug
> };
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 28ec5f8ac1c1..ed0d10fe0b88 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -720,6 +720,38 @@ uint64_t amdgpu_vram_mgr_vis_usage(struct amdgpu_vram_mgr *mgr)
> return atomic64_read(&mgr->vis_usage);
> }
>
> +/**
> + * amdgpu_vram_mgr_intersect - test each drm buddy block for intersection
> + *
> + * @man: TTM memory type manager
> + * @res: The resource to test
> + * @place: The place to test against
> + * @size: Size of the new allocation
> + *
> + * Test each drm buddy block for intersection for eviction decision.
> + */
> +static bool amdgpu_vram_mgr_intersect(struct ttm_resource_manager *man,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size)
> +{
> + struct amdgpu_vram_mgr_resource *mgr = to_amdgpu_vram_mgr_resource(res);
> + struct list_head *list = &mgr->blocks;
> + struct drm_buddy_block *block;
> + u32 num_pages = PFN_UP(size);
> + u32 start;
> +
> + /* Check each drm buddy block individually */
> + list_for_each_entry(block, list, link) {
> + start = amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT;
> + if (start < place->fpfn ||
> + (place->lpfn && (start + num_pages) > place->lpfn))
> + return false;
> + }
> +
> + return true;
> +}
> +
> /**
> * amdgpu_vram_mgr_debug - dump VRAM table
> *
> @@ -753,6 +785,7 @@ static void amdgpu_vram_mgr_debug(struct ttm_resource_manager *man,
> static const struct ttm_resource_manager_func amdgpu_vram_mgr_func = {
> .alloc = amdgpu_vram_mgr_new,
> .free = amdgpu_vram_mgr_del,
> + .intersect = amdgpu_vram_mgr_intersect,
> .debug = amdgpu_vram_mgr_debug
> };
>
> diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
> index d91666721dc6..bf5de1978ead 100644
> --- a/drivers/gpu/drm/ttm/ttm_range_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
> @@ -113,6 +113,22 @@ static void ttm_range_man_free(struct ttm_resource_manager *man,
> kfree(node);
> }
>
> +static bool ttm_range_man_intersect(struct ttm_resource_manager *man,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size)
> +{
> + struct drm_mm_node *node = &to_ttm_range_mgr_node(res)->mm_nodes[0];
> + u32 num_pages = PFN_UP(size);
> +
> + /* Don't evict BOs outside of the requested placement range */
> + if (place->fpfn >= (node->start + num_pages) ||
> + (place->lpfn && place->lpfn <= node->start))
> + return false;
> +
> + return true;
> +}
> +
> static void ttm_range_man_debug(struct ttm_resource_manager *man,
> struct drm_printer *printer)
> {
> @@ -126,6 +142,7 @@ static void ttm_range_man_debug(struct ttm_resource_manager *man,
> static const struct ttm_resource_manager_func ttm_range_manager_func = {
> .alloc = ttm_range_man_alloc,
> .free = ttm_range_man_free,
> + .intersect = ttm_range_man_intersect,
> .debug = ttm_range_man_debug
> };
>
> diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
> index 20f9adcc3235..84c21f92b422 100644
> --- a/drivers/gpu/drm/ttm/ttm_resource.c
> +++ b/drivers/gpu/drm/ttm/ttm_resource.c
> @@ -253,6 +253,34 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
> }
> EXPORT_SYMBOL(ttm_resource_free);
>
> +/**
> + * ttm_resource_intersect - test for intersection
> + *
> + * @bdev: TTM device structure
> + * @res: The resource to test
> + * @place: The placement to test
> + * @size: How many bytes the new allocation needs.
> + *
> + * Test if @res intersects with @place and @size. Used for testing if evictions
> + * are valueable or not.
> + */
> +bool ttm_resource_intersect(struct ttm_device *bdev,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size)
> +{
> + struct ttm_resource_manager *man;
> +
> + if (!res)
> + return false;
> +
> + man = ttm_manager_type(bdev, res->mem_type);
> + if (!place || !man->func->intersect)
> + return true;
> +
> + return man->func->intersect(man, res, place, size);
> +}
> +
> static bool ttm_resource_places_compat(struct ttm_resource *res,
> const struct ttm_place *places,
> unsigned num_placement)
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index ca89a48c2460..3f3ab2a8a69e 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -88,6 +88,22 @@ struct ttm_resource_manager_func {
> void (*free)(struct ttm_resource_manager *man,
> struct ttm_resource *res);
>
> + /**
> + * struct ttm_resource_manager_func member intersect
> + *
> + * @man: Pointer to a memory type manager.
> + * @res: Pointer to a struct ttm_resource to be checked.
> + * @place: Placement to check against.
> + * @size: Size of the check.
> + *
> + * Test if @res intersects with @place + @size. Used to judge if
> + * evictions are valueable or not.
> + */
> + bool (*intersect)(struct ttm_resource_manager *man,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size);
> +
> /**
> * struct ttm_resource_manager_func member debug
> *
> @@ -329,6 +345,10 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
> const struct ttm_place *place,
> struct ttm_resource **res);
> void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
> +bool ttm_resource_intersect(struct ttm_device *bdev,
> + struct ttm_resource *res,
> + const struct ttm_place *place,
> + size_t size);
> bool ttm_resource_compat(struct ttm_resource *res,
> struct ttm_placement *placement);
> void ttm_resource_set_bo(struct ttm_resource *res,
More information about the dri-devel
mailing list