From: "Christian König" <christian.koenig@amd.com>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Nirmoy Das" <nirmoy.das@intel.com>,
dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org, Matthew Auld <matthew.auld@intel.com>
Subject: Re: [PATCH v6 1/2] drm/ttm: Add a flag to allow drivers to skip clear-on-free
Date: Tue, 20 Aug 2024 17:30:59 +0200 [thread overview]
Message-ID: <f045daaa-e887-4f74-8cc1-5df0d0fc2593@amd.com> (raw)
In-Reply-To: <a09a268099ef61c46cf53f0d8847a8f07caa210e.camel@linux.intel.com>
Am 20.08.24 um 15:33 schrieb Thomas Hellström:
> Hi, Nirmoy, Christian
>
> On Fri, 2024-08-16 at 15:51 +0200, Nirmoy Das wrote:
>> Add TTM_TT_FLAG_CLEARED_ON_FREE, which DRM drivers can set before
>> releasing backing stores if they want to skip clear-on-free.
>>
>> Cc: Matthew Auld <matthew.auld@intel.com>
>> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>> Suggested-by: Christian König <christian.koenig@amd.com>
>> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
>> Reviewed-by: Christian König <christian.koenig@amd.com>
> What happens if two devices share the same global TTM pool
> type and one that does its own clearing. Wouldn't there be a pretty
> high chance that the the device that doesn't clear its own pages
> allocate non-cleared memory from the pool?
That's completely unproblematic. The flag indicates that the released
pages are already cleared, if that isn't the case then the flag
shouldn't be set on the TT object.
If one device clear it's pages and another device doesn't clear it's
pages then we would just clear the pages of the device which doesn't do
it with a hardware DMA.
Regards,
Christian.
>
> /Thomas
>
>> ---
>> drivers/gpu/drm/ttm/ttm_pool.c | 18 +++++++++++-------
>> include/drm/ttm/ttm_tt.h | 6 +++++-
>> 2 files changed, 16 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c
>> b/drivers/gpu/drm/ttm/ttm_pool.c
>> index 8504dbe19c1a..935ab3cfd046 100644
>> --- a/drivers/gpu/drm/ttm/ttm_pool.c
>> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
>> @@ -222,15 +222,18 @@ static void ttm_pool_unmap(struct ttm_pool
>> *pool, dma_addr_t dma_addr,
>> }
>>
>> /* Give pages into a specific pool_type */
>> -static void ttm_pool_type_give(struct ttm_pool_type *pt, struct page
>> *p)
>> +static void ttm_pool_type_give(struct ttm_pool_type *pt, struct page
>> *p,
>> + bool cleared)
>> {
>> unsigned int i, num_pages = 1 << pt->order;
>>
>> - for (i = 0; i < num_pages; ++i) {
>> - if (PageHighMem(p))
>> - clear_highpage(p + i);
>> - else
>> - clear_page(page_address(p + i));
>> + if (!cleared) {
>> + for (i = 0; i < num_pages; ++i) {
>> + if (PageHighMem(p))
>> + clear_highpage(p + i);
>> + else
>> + clear_page(page_address(p + i));
>> + }
>> }
>>
>> spin_lock(&pt->lock);
>> @@ -394,6 +397,7 @@ static void ttm_pool_free_range(struct ttm_pool
>> *pool, struct ttm_tt *tt,
>> pgoff_t start_page, pgoff_t
>> end_page)
>> {
>> struct page **pages = &tt->pages[start_page];
>> + bool cleared = tt->page_flags & TTM_TT_FLAG_CLEARED_ON_FREE;
>> unsigned int order;
>> pgoff_t i, nr;
>>
>> @@ -407,7 +411,7 @@ static void ttm_pool_free_range(struct ttm_pool
>> *pool, struct ttm_tt *tt,
>>
>> pt = ttm_pool_select_type(pool, caching, order);
>> if (pt)
>> - ttm_pool_type_give(pt, *pages);
>> + ttm_pool_type_give(pt, *pages, cleared);
>> else
>> ttm_pool_free_page(pool, caching, order,
>> *pages);
>> }
>> diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
>> index 2b9d856ff388..cfaf49de2419 100644
>> --- a/include/drm/ttm/ttm_tt.h
>> +++ b/include/drm/ttm/ttm_tt.h
>> @@ -85,6 +85,9 @@ struct ttm_tt {
>> * fault handling abuses the DMA api a bit and dma_map_attrs
>> can't be
>> * used to assure pgprot always matches.
>> *
>> + * TTM_TT_FLAG_CLEARED_ON_FREE: Set this if a drm driver
>> handles
>> + * clearing backing store
>> + *
>> * TTM_TT_FLAG_PRIV_POPULATED: TTM internal only. DO NOT
>> USE. This is
>> * set by TTM after ttm_tt_populate() has successfully
>> returned, and is
>> * then unset when TTM calls ttm_tt_unpopulate().
>> @@ -94,8 +97,9 @@ struct ttm_tt {
>> #define TTM_TT_FLAG_EXTERNAL BIT(2)
>> #define TTM_TT_FLAG_EXTERNAL_MAPPABLE BIT(3)
>> #define TTM_TT_FLAG_DECRYPTED BIT(4)
>> +#define TTM_TT_FLAG_CLEARED_ON_FREE BIT(5)
>>
>> -#define TTM_TT_FLAG_PRIV_POPULATED BIT(5)
>> +#define TTM_TT_FLAG_PRIV_POPULATED BIT(6)
>> uint32_t page_flags;
>> /** @num_pages: Number of pages in the page array. */
>> uint32_t num_pages;
next prev parent reply other threads:[~2024-08-20 15:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 13:51 [PATCH v6 1/2] drm/ttm: Add a flag to allow drivers to skip clear-on-free Nirmoy Das
2024-08-16 13:51 ` [PATCH v6 2/2] drm/xe/lnl: Offload system clear page activity to GPU Nirmoy Das
2024-08-19 11:05 ` Matthew Auld
2024-08-19 16:01 ` Nirmoy Das
2024-08-20 13:36 ` Thomas Hellström
2024-08-16 14:25 ` ✓ CI.Patch_applied: success for series starting with [v6,1/2] drm/ttm: Add a flag to allow drivers to skip clear-on-free Patchwork
2024-08-16 14:25 ` ✓ CI.checkpatch: " Patchwork
2024-08-16 14:27 ` ✓ CI.KUnit: " Patchwork
2024-08-16 14:38 ` ✓ CI.Build: " Patchwork
2024-08-16 14:40 ` ✓ CI.Hooks: " Patchwork
2024-08-16 14:42 ` ✗ CI.checksparse: warning " Patchwork
2024-08-16 14:57 ` ✓ CI.BAT: success " Patchwork
2024-08-17 0:39 ` ✓ CI.FULL: " Patchwork
2024-08-20 13:33 ` [PATCH v6 1/2] " Thomas Hellström
2024-08-20 14:06 ` Nirmoy Das
2024-08-20 15:30 ` Christian König [this message]
2024-08-20 15:45 ` Thomas Hellström
2024-08-20 15:47 ` Christian König
2024-08-20 16:46 ` Nirmoy Das
2024-08-21 7:47 ` Christian König
2024-08-21 8:08 ` Thomas Hellström
2024-08-21 10:22 ` Nirmoy Das
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=f045daaa-e887-4f74-8cc1-5df0d0fc2593@amd.com \
--to=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=nirmoy.das@intel.com \
--cc=thomas.hellstrom@linux.intel.com \
/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