From: "Christian König" <christian.koenig@amd.com>
To: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>,
dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org
Cc: alexander.deucher@amd.com, matthew.auld@intel.com
Subject: Re: [PATCH 1/4] drm/ttm: add new intersect callback to res mgr
Date: Wed, 20 Jul 2022 10:41:09 +0200 [thread overview]
Message-ID: <7b80e48d-8670-6007-d6d3-aa3587e26d60@amd.com> (raw)
In-Reply-To: <20220720073606.3885-1-Arunpravin.PaneerSelvam@amd.com>
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@amd.com>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@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,
prev parent reply other threads:[~2022-07-20 8:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 7:36 [PATCH 1/4] drm/ttm: add new intersect callback to res mgr Arunpravin Paneer Selvam
2022-07-20 7:36 ` [PATCH 2/4] drm/i915: Add intersect callback function Arunpravin Paneer Selvam
2022-07-20 7:36 ` [PATCH 3/4] drm/nouveau: " Arunpravin Paneer Selvam
2022-07-20 7:36 ` [PATCH 4/4] drm/ttm: Switch to using the new intersect callback Arunpravin Paneer Selvam
2022-07-20 8:44 ` Christian König
2022-07-20 8:41 ` Christian König [this message]
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=7b80e48d-8670-6007-d6d3-aa3587e26d60@amd.com \
--to=christian.koenig@amd.com \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=nouveau@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