drm/ttm: new TT backend allocation pool
Subsystems (7)
This replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The alloc_pages() based pool was zeroing it, the dma_alloc_attr() based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the __GFP_ZERO flag when necessary.
The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
Please review and comment,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/13 drm/ttm: nuke ttm_tt_set_(un)populated again
Neither page allocation backend nor the driver should mess with that.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }
@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -1
@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/radeon/radeon_ttm.c +0 -2
@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/ttm/ttm_page_alloc.c +0 -2
@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); }int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx)
@@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -2
@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);
@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);
drivers/gpu/drm/ttm/ttm_tt.c +7 -4
@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;
@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);
@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }
include/drm/ttm/ttm_tt.h +0 -10
@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated (struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated (struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt *
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
For 1,2,3,4
should land those quicker, I'll dig a bit more into the others.
Dave.
Quoted 163 lines · Christian König
Neither page allocation backend nor the driver should mess with that.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-2@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/nouveau/nouveau_bo.c +0
-1@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/radeon/radeon_ttm.c +0
-2@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-2@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); }int ttm_pool_populate (struct ttm_tt *ttm,struct ttm_operation_ctx *ctx)@@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0
-2@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);drivers/gpu/drm/ttm/ttm_tt.c +7
-4@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }include/drm/ttm/ttm_tt.h +0
-11@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated (struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated (struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt * -- 2.17.1
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RE: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
In reply to Christian König[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Sunday, October 25, 2020 9:11 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Neither page allocation backend nor the driver should mess with that.
Looks fine to me: Reviewed-by: Madhav Chauhan <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }
@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -1
@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/radeon/radeon_ttm.c +0 -2
@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }
drivers/gpu/drm/ttm/ttm_page_alloc.c +0 -1
@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); } int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) @@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
}
}
- ttm_tt_set_populated(ttm);
return 0;
}
EXPORT_SYMBOL(ttm_pool_populate);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -2
@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);
@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);
drivers/gpu/drm/ttm/ttm_tt.c +7 -4
@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;
@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);
@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }
include/drm/ttm/ttm_tt.h +0 -9
@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated(struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt * --
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Am 26.10.20 um 14:36 schrieb Chauhan, Madhav:
Quoted 9 lines
[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Sunday, October 25, 2020 9:11 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Quoted 3 lines
Neither page allocation backend nor the driver should mess with that.
Looks fine to me: Reviewed-by: Madhav Chauhan <[email protected]>
Just for this patch or the series?
Christian.
Quoted 153 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-2@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/nouveau/nouveau_bo.c +0
-1@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/radeon/radeon_ttm.c +0
-2@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); } int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) @@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)} }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1-ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0
-2@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);drivers/gpu/drm/ttm/ttm_tt.c +7
-4@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }include/drm/ttm/ttm_tt.h +0
-9@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated(struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt * --
Quoted 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RE: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, October 26, 2020 7:14 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: Re: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Am 26.10.20 um 14:36 schrieb Chauhan, Madhav:
Quoted 9 lines
[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Sunday, October 25, 2020 9:11 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Quoted 3 lines
Neither page allocation backend nor the driver should mess with that.
Looks fine to me: Reviewed-by: Madhav Chauhan <[email protected]>
Just for this patch or the series?
Complete series looks good to me now. Series, Reviewed-by: Madhav Chauhan <[email protected]>
Will be doing MHT 3.0/3.1 offscreen/regression analysis to find the impact of this optimized allocator and update If found any issues.
Regards,
Madhav
Christian.
Quoted 153 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-2@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/nouveau/nouveau_bo.c +0
-1@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/radeon/radeon_ttm.c +0
-2@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); } int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) @@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)} }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1-ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0
-2@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);drivers/gpu/drm/ttm/ttm_tt.c +7
-4@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }include/drm/ttm/ttm_tt.h +0
-9@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated(struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt * --
Quoted 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RE: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
[AMD Public Use]
-----Original Message-----
From: Chauhan, Madhav
Sent: Tuesday, October 27, 2020 12:57 AM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: RE: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, October 26, 2020 7:14 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: Re: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Am 26.10.20 um 14:36 schrieb Chauhan, Madhav:
Quoted 10 lines
[AMD Public Use]
-----Original Message-----
From: Christian König <[email protected]>
Sent: Sunday, October 25, 2020 9:11 PM
To: Chauhan, Madhav <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>
Subject: [PATCH 01/13] drm/ttm: nuke ttm_tt_set_(un)populated again
Quoted 3 lines
Neither page allocation backend nor the driver should mess with that.
Looks fine to me: Reviewed-by: Madhav Chauhan <[email protected]>
Just for this patch or the series?
Complete series looks good to me now. Series, Reviewed-by: Madhav Chauhan <[email protected]>
Will be doing MHT 3.0/3.1 offscreen/regression analysis to find the impact of this optimized allocator and update If found any issues.
Tested this new allocator thoroughly with Raven Ridge APU, Navi 14 dGPU. Results:
1. No regression/BO allocation error observed while running LIBDRM testapps
2. MHT 3.0/3.1 1080P offscreen results are at par/similar with old allocator.
Regards,
Madhav
Regards,
Madhav
Christian.
Quoted 160 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- drivers/gpu/drm/nouveau/nouveau_bo.c | 1 - drivers/gpu/drm/radeon/radeon_ttm.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc.c | 2 -- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 -- drivers/gpu/drm/ttm/ttm_tt.c | 11 +++++++---- include/drm/ttm/ttm_tt.h | 10 ---------- 7 files changed, 7 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-2@@ -1363,7 +1363,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }@@ -1383,7 +1382,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/nouveau/nouveau_bo.c +0
-1@@ -1321,7 +1321,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,/* make userspace faulting work */ drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, ttm_dma->dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/radeon/radeon_ttm.c +0
-2@@ -670,14 +670,12 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return -ENOMEM ; ttm->page_flags |=TTM_PAGE_FLAG_SG ; -ttm_tt_set_populated (ttm);return 0 ; }if (slave && ttm->sg) {drm_prime_sg_to_page_addr_arrays (ttm->sg, ttm->pages, gtt->ttm.dma_address, ttm->num_pages); -ttm_tt_set_populated (ttm);return 0 ; }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1@@ -1041,7 +1041,6 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) put_pages:ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching); -ttm_tt_set_unpopulated (ttm); } int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) @@ -1080,7 +1079,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)} }drivers/gpu/drm/ttm/ttm_page_alloc.c +0
-1-ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0
-2@@ -983,7 +983,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } } -ttm_tt_set_populated (ttm);return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);@@ -1077,7 +1076,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)/* shrink pool if necessary (only on !is_cached pools)*/ if (npages)ttm_dma_page_pool_free (pool, npages, false); -ttm_tt_set_unpopulated (ttm); }EXPORT_SYMBOL_GPL (ttm_dma_unpopulate);(quoted diff) +0
-0
b/drivers/gpu/drm/ttm/ttm_tt.cindex3e5dd6271d4c..beb1e878fed9100644drivers/gpu/drm/ttm/ttm_tt.c +7
-4@@ -138,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->num_pages = bo->num_pages; ttm->caching = ttm_cached; ttm->page_flags = page_flags; -ttm_tt_set_unpopulated (ttm); ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching;@@ -334,9 +333,12 @@ int ttm_tt_populate(struct ttm_bo_device *bdev, ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx); else ret =ttm_pool_populate (ttm, ctx); -if (!ret) -ttm_tt_add_mapping (bdev, ttm); -return ret; +if (ret) +return ret; + +ttm_tt_add_mapping (bdev, ttm); + ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);@@ -365,4 +367,5 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, bdev->driver->ttm_tt_unpopulate (bdev, ttm); elsettm_pool_unpopulate (ttm ); + ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }include/drm/ttm/ttm_tt.h index renamed from include/drm/ttm/ttm_tt.h +0
-0
e042dec5e6c1..e3e60c1da754100644include/drm/ttm/ttm_tt.h +0
-9@@ -72,16 +72,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt) -{ - tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; -} - -static inline void ttm_tt_set_populated(struct ttm_tt *tt) -{ - tt->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; -} -/** * struct ttm_dma_tt * --
Quoted 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/13 drm/ttm: move swapin out of page alloc backend
In reply to Christian KönigThis is not related to allocating the backing store in any way.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 8 -------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 -------- drivers/gpu/drm/ttm/ttm_tt.c | 8 ++++++++ 3 files changed, 8 insertions(+), 16 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +0 -8
@@ -1071,14 +1071,6 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) } } -if (unlikely (ttm->page_flags &TTM_PAGE_FLAG_SWAPPED )) { - ret =ttm_tt_swapin (ttm); -if (unlikely (ret !=0 )) { -ttm_pool_unpopulate (ttm); -return ret; - } - } -return 0 ; }EXPORT_SYMBOL (ttm_pool_populate);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -8
@@ -975,14 +975,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, --num_pages; } -if (unlikely (ttm->page_flags &TTM_PAGE_FLAG_SWAPPED )) { - ret =ttm_tt_swapin (ttm); -if (unlikely (ret !=0 )) { -ttm_dma_unpopulate (ttm_dma, dev); -return ret; - } - } -return 0 ; }EXPORT_SYMBOL_GPL (ttm_dma_populate);
drivers/gpu/drm/ttm/ttm_tt.c +8 -0
@@ -338,6 +338,14 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,ttm_tt_add_mapping (bdev, ttm); ttm->page_flags |=TTM_PAGE_FLAG_PRIV_POPULATED ; +if (unlikely (ttm->page_flags &TTM_PAGE_FLAG_SWAPPED )) { + ret =ttm_tt_swapin (ttm); +if (unlikely (ret !=0 )) { +ttm_tt_unpopulate (bdev, ttm); +return ret; + } + } +return 0 ; }EXPORT_SYMBOL (ttm_tt_populate);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/13 drm/ttm: make num_pages uint32_t
In reply to Christian KönigWe can still allocate 16TiB with that.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 +++++----- drivers/gpu/drm/nouveau/nouveau_ttm.c | 2 +- drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++-- include/drm/ttm/ttm_tt.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -5
@@ -973,7 +973,7 @@ bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm)if (!gtt || !gtt->userptr)return false; -DRM_DEBUG_DRIVER ("user_pages_done 0x%llx pages 0x%lx\n" , +DRM_DEBUG_DRIVER ("user_pages_done 0x%llx pages 0x%x\n" , gtt->userptr, ttm->num_pages); WARN_ONCE(!gtt->range || !gtt->range->hmm_pfns,
@@ -1124,7 +1124,7 @@ static int amdgpu_ttm_gart_bind(struct amdgpu_device *adev, gart_bind_fail:if (r) -DRM_ERROR ("failed to bind %lu pages at 0x%08llX\n" , +DRM_ERROR ("failed to bind %u pages at 0x%08llX\n" , ttm->num_pages, gtt->offset);return r;
@@ -1159,7 +1159,7 @@ static int amdgpu_ttm_backend_bind(struct ttm_bo_device *bdev, } }if (!ttm->num_pages) { -WARN (1 ,"nothing to bind %lu pages for mreg %p back %p!\n" , +WARN (1 ,"nothing to bind %u pages for mreg %p back %p!\n" , ttm->num_pages, bo_mem, ttm); }
@@ -1182,7 +1182,7 @@ static int amdgpu_ttm_backend_bind(struct ttm_bo_device *bdev, ttm->pages, gtt->ttm.dma_address, flags);if (r) -DRM_ERROR ("failed to bind %lu pages at 0x%08llX\n" , +DRM_ERROR ("failed to bind %u pages at 0x%08llX\n" , ttm->num_pages, gtt->offset); gtt->bound = true;return r;
@@ -1291,7 +1291,7 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,/* unbind shouldn't be done for GDS/GWS/OA in ttm_bo_clean_mm */ r =amdgpu_gart_unbind (adev, gtt->offset, ttm->num_pages);if (r) -DRM_ERROR ("failed to unbind %lu pages at 0x%08llX\n" , +DRM_ERROR ("failed to unbind %u pages at 0x%08llX\n" , gtt->ttm.ttm.num_pages, gtt->offset); gtt->bound = false; }
drivers/gpu/drm/nouveau/nouveau_ttm.c +1 -1
@@ -108,7 +108,7 @@ nv04_gart_manager_new(struct ttm_resource_manager *man,return ret; ret =nvif_vmm_get (&mem->cli->vmm.vmm,PTES , false,12 ,0 , - reg->num_pages <<PAGE_SHIFT , &mem->vma[0 ]); + (long )reg->num_pages <<PAGE_SHIFT , &mem->vma[0 ]);if (ret) {nouveau_mem_del (reg);return ret;
drivers/gpu/drm/radeon/radeon_ttm.c +2 -2
@@ -564,7 +564,7 @@ static int radeon_ttm_backend_bind(struct ttm_bo_device *bdev, gtt->offset = (unsigned long )(bo_mem->start <<PAGE_SHIFT );if (!ttm->num_pages) { -WARN (1 ,"nothing to bind %lu pages for mreg %p back %p!\n" , +WARN (1 ,"nothing to bind %u pages for mreg %p back %p!\n" , ttm->num_pages, bo_mem, ttm); }if (ttm->caching == ttm_cached)
@@ -572,7 +572,7 @@ static int radeon_ttm_backend_bind(struct ttm_bo_device *bdev, r =radeon_gart_bind (rdev, gtt->offset, ttm->num_pages, ttm->pages, gtt->ttm.dma_address, flags);if (r) { -DRM_ERROR ("failed to bind %lu pages at 0x%08X\n" , +DRM_ERROR ("failed to bind %u pages at 0x%08X\n" , ttm->num_pages, (unsigned )gtt->offset);return r; }
include/drm/ttm/ttm_tt.h +1 -1
@@ -61,7 +61,7 @@ struct ttm_operation_ctx;struct ttm_tt {struct page **pages;uint32_t page_flags; -unsigned long num_pages; +uint32_t num_pages;struct sg_table *sg;/* for SG objects via dma-buf */ struct file *swap_storage;enum ttm_caching caching;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/13 drm/ttm: merge ttm_dma_tt back into ttm_tt
In reply to Christian KönigIt makes no difference to kmalloc if the structure is 48 or 64 bytes in size.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +-- drivers/gpu/drm/nouveau/nouveau_bo.c | 12 ++--- drivers/gpu/drm/nouveau/nouveau_mem.c | 8 ++-- drivers/gpu/drm/nouveau/nouveau_mem.h | 4 +- drivers/gpu/drm/nouveau/nouveau_sgdma.c | 6 +-- drivers/gpu/drm/qxl/qxl_ttm.c | 2 +- drivers/gpu/drm/radeon/radeon_ttm.c | 8 ++-- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_page_alloc.c | 30 ++++++------ drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 44 ++++++++--------- drivers/gpu/drm/ttm/ttm_tt.c | 55 +++++++++------------- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 26 +++++----- include/drm/ttm/ttm_page_alloc.h | 12 ++--- include/drm/ttm/ttm_tt.h | 35 ++++---------- 16 files changed, 119 insertions(+), 156 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -7
@@ -45,12 +45,10 @@ void amdgpu_gmc_get_pde_for_bo(struct amdgpu_bo *bo, int level, uint64_t *addr, uint64_t *flags) { struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); -struct ttm_dma_tt *ttm;switch (bo->tbo.mem.mem_type) {case TTM_PL_TT : - ttm = container_of(bo->tbo.ttm, struct ttm_dma_tt, ttm); - *addr = ttm->dma_address[0 ]; + *addr = bo->tbo.ttm->dma_address[0 ];break ;case TTM_PL_VRAM : *addr =amdgpu_bo_gpu_offset (bo);
@@ -122,16 +120,14 @@ int amdgpu_gmc_set_pte_pde(struct amdgpu_device *adev, void *cpu_pt_addr,uint64_t amdgpu_gmc_agp_addr (struct ttm_buffer_object *bo) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->bdev); -struct ttm_dma_tt *ttm;if (bo->num_pages !=1 || bo->ttm->caching == ttm_cached)return AMDGPU_BO_INVALID_OFFSET ; - ttm = container_of(bo->ttm, struct ttm_dma_tt, ttm); -if (ttm->dma_address[0 ] +PAGE_SIZE >= adev->gmc.agp_size) +if (bo->ttm->dma_address[0 ] +PAGE_SIZE >= adev->gmc.agp_size)return AMDGPU_BO_INVALID_OFFSET ; -return adev->gmc.agp_start + ttm->dma_address[0 ]; +return adev->gmc.agp_start + bo->ttm->dma_address[0 ]; }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6 -8
@@ -294,11 +294,9 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo, cpu_addr = &job->ibs[0 ].ptr[num_dw];if (mem->mem_type ==TTM_PL_TT ) { -struct ttm_dma_tt *dma;dma_addr_t *dma_address; - dma = container_of(bo->ttm, struct ttm_dma_tt, ttm); - dma_address = &dma->dma_address[offset >>PAGE_SHIFT ]; + dma_address = &bo->ttm->dma_address[offset >>PAGE_SHIFT ]; r =amdgpu_gart_map (adev,0 , num_pages, dma_address, flags, cpu_addr);if (r)
@@ -841,7 +839,7 @@ uint64_t amdgpu_ttm_domain_start(struct amdgpu_device *adev, uint32_t type)* TTM backend functions. */ struct amdgpu_ttm_tt { -struct ttm_dma_tt ttm; +struct ttm_tt ttm;struct drm_gem_object *gobj;u64 offset;uint64_t userptr;
@@ -1292,7 +1290,7 @@ static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev, r =amdgpu_gart_unbind (adev, gtt->offset, ttm->num_pages);if (r)DRM_ERROR ("failed to unbind %u pages at 0x%08llX\n" , - gtt->ttm.ttm.num_pages, gtt->offset); + gtt->ttm.num_pages, gtt->offset); gtt->bound = false; }
@@ -1306,7 +1304,7 @@ static void amdgpu_ttm_backend_destroy(struct ttm_bo_device *bdev,if (gtt->usertask)put_task_struct (gtt->usertask); -ttm_dma_tt_fini (>t->ttm); +ttm_tt_fini (>t->ttm);kfree (gtt); }
@@ -1340,7 +1338,7 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo,kfree (gtt);return NULL ; } -return >t->ttm.ttm; +return >t->ttm; }/**
@@ -1507,7 +1505,7 @@ bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,/* Return false if no part of the ttm_tt object lies within * the range */ - size = (unsigned long )gtt->ttm.ttm.num_pages *PAGE_SIZE ; + size = (unsigned long )gtt->ttm.num_pages *PAGE_SIZE ;if (gtt->userptr > end || gtt->userptr + size <= start)return false;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -5
@@ -1781,7 +1781,6 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, resv = vm->root.base.bo->tbo.base.resv; }else {struct drm_gem_object *obj = &bo->tbo.base; -struct ttm_dma_tt *ttm; resv = bo->tbo.base.resv;if (obj->import_attach && bo_va->is_xgmi) {
@@ -1794,10 +1793,8 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, } mem = &bo->tbo.mem; nodes = mem->mm_node; -if (mem->mem_type ==TTM_PL_TT ) { - ttm = container_of(bo->tbo.ttm, struct ttm_dma_tt, ttm); - pages_addr = ttm->dma_address; - } +if (mem->mem_type ==TTM_PL_TT ) + pages_addr = bo->tbo.ttm->dma_address; }if (bo) {
drivers/gpu/drm/nouveau/nouveau_bo.c +6 -6
@@ -547,7 +547,7 @@ void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo) {struct nouveau_drm *drm =nouveau_bdev (nvbo->bo.bdev); -struct ttm_dma_tt *ttm_dma = (struct ttm_dma_tt *)nvbo->bo.ttm; +struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;int i;if (!ttm_dma)
@@ -557,7 +557,7 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)if (nvbo->force_coherent)return ; -for (i =0 ; i < ttm_dma->ttm.num_pages; i++) +for (i =0 ; i < ttm_dma->num_pages; i++)dma_sync_single_for_device (drm->dev->dev, ttm_dma->dma_address[i],PAGE_SIZE ,DMA_TO_DEVICE );
@@ -567,7 +567,7 @@ void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo) {struct nouveau_drm *drm =nouveau_bdev (nvbo->bo.bdev); -struct ttm_dma_tt *ttm_dma = (struct ttm_dma_tt *)nvbo->bo.ttm; +struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;int i;if (!ttm_dma)
@@ -577,7 +577,7 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)if (nvbo->force_coherent)return ; -for (i =0 ; i < ttm_dma->ttm.num_pages; i++) +for (i =0 ; i < ttm_dma->num_pages; i++)dma_sync_single_for_cpu (drm->dev->dev, ttm_dma->dma_address[i],PAGE_SIZE ,DMA_FROM_DEVICE ); }
@@ -1309,7 +1309,7 @@ static int nouveau_ttm_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) { - struct ttm_dma_tt *ttm_dma = (void *)ttm; + struct ttm_tt *ttm_dma = (void *)ttm;struct nouveau_drm *drm;struct device *dev;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG );
@@ -1345,7 +1345,7 @@ static void nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm) { - struct ttm_dma_tt *ttm_dma = (void *)ttm; + struct ttm_tt *ttm_dma = (void *)ttm;struct nouveau_drm *drm;struct device *dev;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG );
drivers/gpu/drm/nouveau/nouveau_mem.c +5 -3
@@ -92,7 +92,7 @@ nouveau_mem_fini(struct nouveau_mem *mem) }int -nouveau_mem_host (struct ttm_resource *reg,struct ttm_dma_tt *tt) +nouveau_mem_host (struct ttm_resource *reg,struct ttm_tt *tt) {struct nouveau_mem *mem =nouveau_mem (reg);struct nouveau_cli *cli = mem->cli;
@@ -116,8 +116,10 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_dma_tt *tt) mem->comp =0 ; } -if (tt->ttm.sg) args.sgl = tt->ttm.sg->sgl; -else args.dma = tt->dma_address; +if (tt->sg) + args.sgl = tt->sg->sgl; +else + args.dma = tt->dma_address;mutex_lock (&drm->master.lock); cli->base.super = true;
drivers/gpu/drm/nouveau/nouveau_mem.h +2 -2
@@ -1,7 +1,7 @@#ifndef __NOUVEAU_MEM_H__#define __NOUVEAU_MEM_H__#include <drm/ttm/ttm_bo_api.h> -struct ttm_dma_tt ; +struct ttm_tt ;#include <nvif/mem.h> #include <nvif/vmm.h>
@@ -24,7 +24,7 @@ int nouveau_mem_new(struct nouveau_cli *, u8 kind, u8 comp, struct ttm_resource *);void nouveau_mem_del (struct ttm_resource *);int nouveau_mem_vram (struct ttm_resource *,bool contig,u8 page); -int nouveau_mem_host (struct ttm_resource *,struct ttm_dma_tt *); +int nouveau_mem_host (struct ttm_resource *,struct ttm_tt *);void nouveau_mem_fini (struct nouveau_mem *);int nouveau_mem_map (struct nouveau_mem *,struct nvif_vmm *,struct nvif_vma *);#endif
drivers/gpu/drm/nouveau/nouveau_sgdma.c +3 -3
@@ -11,7 +11,7 @@ struct nouveau_sgdma_be {/* this has to be the first field so populate/unpopulated in * nouve_bo.c works properly, otherwise have to move them here */ -struct ttm_dma_tt ttm; +struct ttm_tt ttm;struct nouveau_mem *mem; };
@@ -23,7 +23,7 @@ nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)if (ttm) {nouveau_sgdma_unbind (bdev, ttm);ttm_tt_destroy_common (bdev, ttm); -ttm_dma_tt_fini (&nvbe->ttm); +ttm_tt_fini (&nvbe->ttm);kfree (nvbe); } }
@@ -88,5 +88,5 @@ nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)kfree (nvbe);return NULL ; } -return &nvbe->ttm.ttm; +return &nvbe->ttm; }
drivers/gpu/drm/qxl/qxl_ttm.c +1 -1
@@ -116,7 +116,7 @@ static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo, ttm =kzalloc (sizeof (struct ttm_tt ),GFP_KERNEL );if (ttm ==NULL )return NULL ; -if (ttm_tt_init (ttm, bo, page_flags, ttm_cached)) { +if (ttm_dma_tt_init (ttm, bo, page_flags, ttm_cached)) {kfree (ttm);return NULL ; }
drivers/gpu/drm/radeon/radeon_ttm.c +4 -4
@@ -437,7 +437,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso* TTM backend functions. */ struct radeon_ttm_tt { -struct ttm_dma_tt ttm; +struct ttm_tt ttm;u64 offset;uint64_t userptr;
@@ -602,7 +602,7 @@ static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_ttradeon_ttm_backend_unbind (bdev, ttm);ttm_tt_destroy_common (bdev, ttm); -ttm_dma_tt_fini (>t->ttm); +ttm_tt_fini (>t->ttm);kfree (gtt); }
@@ -640,7 +640,7 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,kfree (gtt);return NULL ; } -return >t->ttm.ttm; +return >t->ttm; } static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,
@@ -653,7 +653,7 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,if (!ttm)return NULL ; - return container_of(ttm, struct radeon_ttm_tt, ttm.ttm); + return container_of(ttm, struct radeon_ttm_tt, ttm); } static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -1192,7 +1192,7 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, size +=ttm_round_pot (struct_size); size +=ttm_round_pot (npages * (2 *sizeof (void *) +sizeof (dma_addr_t))); - size +=ttm_round_pot (sizeof (struct ttm_dma_tt )); + size +=ttm_round_pot (sizeof (struct ttm_tt ));return size; }EXPORT_SYMBOL (ttm_bo_dma_acc_size);
drivers/gpu/drm/ttm/ttm_page_alloc.c +15 -15
@@ -1081,28 +1081,28 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm) }EXPORT_SYMBOL (ttm_pool_unpopulate); -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +int ttm_populate_and_map_pages (struct device *dev,struct ttm_tt *tt,struct ttm_operation_ctx *ctx) {unsigned i, j;int r; - r =ttm_pool_populate (&tt->ttm, ctx); + r =ttm_pool_populate (tt, ctx);if (r)return r; -for (i =0 ; i < tt->ttm.num_pages; ++i) { -struct page *p = tt->ttm.pages[i]; +for (i =0 ; i < tt->num_pages; ++i) { +struct page *p = tt->pages[i];size_t num_pages =1 ; -for (j = i +1 ; j < tt->ttm.num_pages; ++j) { -if (++p != tt->ttm.pages[j]) +for (j = i +1 ; j < tt->num_pages; ++j) { +if (++p != tt->pages[j])break ; ++num_pages; } - tt->dma_address[i] =dma_map_page (dev, tt->ttm.pages[i], + tt->dma_address[i] =dma_map_page (dev, tt->pages[i],0 , num_pages *PAGE_SIZE ,DMA_BIDIRECTIONAL );if (dma_mapping_error (dev, tt->dma_address[i])) {
@@ -1111,7 +1111,7 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt, PAGE_SIZE, DMA_BIDIRECTIONAL); tt->dma_address[i] =0 ; } -ttm_pool_unpopulate (&tt->ttm); +ttm_pool_unpopulate (tt);return -EFAULT ; }
@@ -1124,21 +1124,21 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt, }EXPORT_SYMBOL (ttm_populate_and_map_pages); -void ttm_unmap_and_unpopulate_pages (struct device *dev,struct ttm_dma_tt *tt) +void ttm_unmap_and_unpopulate_pages (struct device *dev,struct ttm_tt *tt) {unsigned i, j; -for (i =0 ; i < tt->ttm.num_pages;) { -struct page *p = tt->ttm.pages[i]; +for (i =0 ; i < tt->num_pages;) { +struct page *p = tt->pages[i];size_t num_pages =1 ; -if (!tt->dma_address[i] || !tt->ttm.pages[i]) { +if (!tt->dma_address[i] || !tt->pages[i]) { ++i;continue ; } -for (j = i +1 ; j < tt->ttm.num_pages; ++j) { -if (++p != tt->ttm.pages[j]) +for (j = i +1 ; j < tt->num_pages; ++j) { +if (++p != tt->pages[j])break ; ++num_pages;
@@ -1149,7 +1149,7 @@ void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt) i += num_pages; } -ttm_pool_unpopulate (&tt->ttm); +ttm_pool_unpopulate (tt); }EXPORT_SYMBOL (ttm_unmap_and_unpopulate_pages);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +20 -24
158 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +22 -33
109 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +13 -13
@@ -186,7 +186,7 @@ struct ttm_placement vmw_nonfixed_placement = { };struct vmw_ttm_tt { -struct ttm_dma_tt dma_ttm; +struct ttm_tt dma_ttm;struct vmw_private *dev_priv;int gmr_id;struct vmw_mob *mob;
@@ -374,8 +374,8 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt)return 0 ; vsgt->mode = dev_priv->map_mode; - vsgt->pages = vmw_tt->dma_ttm.ttm.pages; - vsgt->num_pages = vmw_tt->dma_ttm.ttm.num_pages; + vsgt->pages = vmw_tt->dma_ttm.pages; + vsgt->num_pages = vmw_tt->dma_ttm.num_pages; vsgt->addrs = vmw_tt->dma_ttm.dma_address; vsgt->sgt = &vmw_tt->sgt;
@@ -483,7 +483,7 @@ static void vmw_ttm_unmap_dma(struct vmw_ttm_tt *vmw_tt)const struct vmw_sg_table *vmw_bo_sg_table (struct ttm_buffer_object *bo) {struct vmw_ttm_tt *vmw_tt = - container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm);return &vmw_tt->vsgt; }
@@ -493,7 +493,7 @@ static int vmw_ttm_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem) { struct vmw_ttm_tt *vmw_be = - container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(ttm, struct vmw_ttm_tt, dma_ttm);int ret =0 ;if (!bo_mem)
@@ -537,7 +537,7 @@ static void vmw_ttm_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm) {struct vmw_ttm_tt *vmw_be = - container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(ttm, struct vmw_ttm_tt, dma_ttm);if (!vmw_be->bound)return ;
@@ -562,13 +562,13 @@ static void vmw_ttm_unbind(struct ttm_bo_device *bdev,static void vmw_ttm_destroy (struct ttm_bo_device *bdev,struct ttm_tt *ttm) {struct vmw_ttm_tt *vmw_be = - container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(ttm, struct vmw_ttm_tt, dma_ttm);vmw_ttm_unbind (bdev, ttm);ttm_tt_destroy_common (bdev, ttm);vmw_ttm_unmap_dma (vmw_be);if (vmw_be->dev_priv->map_mode == vmw_dma_alloc_coherent) -ttm_dma_tt_fini (&vmw_be->dma_ttm); +ttm_tt_fini (&vmw_be->dma_ttm);else ttm_tt_fini (ttm);
@@ -583,7 +583,7 @@ static int vmw_ttm_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) { struct vmw_ttm_tt *vmw_tt = - container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(ttm, struct vmw_ttm_tt, dma_ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);int ret;
@@ -612,7 +612,7 @@ static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm) { struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, - dma_ttm.ttm); + dma_ttm);struct vmw_private *dev_priv = vmw_tt->dev_priv;struct ttm_mem_global *glob =vmw_mem_glob (dev_priv);
@@ -650,12 +650,12 @@ static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo, ret =ttm_dma_tt_init (&vmw_be->dma_ttm, bo, page_flags, ttm_cached); else - ret =ttm_tt_init (&vmw_be->dma_ttm.ttm, bo, page_flags, + ret =ttm_tt_init (&vmw_be->dma_ttm, bo, page_flags, ttm_cached);if (unlikely (ret !=0 )) goto out_no_init; -return &vmw_be->dma_ttm.ttm; +return &vmw_be->dma_ttm; out_no_init:kfree (vmw_be);return NULL ;
@@ -813,7 +813,7 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv, ret =vmw_ttm_populate (bo->bdev, bo->ttm, &ctx);if (likely (ret ==0 )) {struct vmw_ttm_tt *vmw_tt = - container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm.ttm); + container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm); ret =vmw_ttm_map_dma (vmw_tt); }
include/drm/ttm/ttm_page_alloc.h +6 -6
@@ -61,13 +61,13 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);/** * Populates and DMA maps pages to fullfil a ttm_dma_populate() request */ -int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt, +int ttm_populate_and_map_pages (struct device *dev,struct ttm_tt *tt,struct ttm_operation_ctx *ctx);/** * Unpopulates and DMA unmaps pages as part of a * ttm_dma_unpopulate() request */ -void ttm_unmap_and_unpopulate_pages (struct device *dev,struct ttm_dma_tt *tt); +void ttm_unmap_and_unpopulate_pages (struct device *dev,struct ttm_tt *tt);/** * Output the state of pools to debugfs file
@@ -90,9 +90,9 @@ void ttm_dma_page_alloc_fini(void);*/ int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev, +int ttm_dma_populate (struct ttm_tt *ttm_dma,struct device *dev,struct ttm_operation_ctx *ctx); -void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev); +void ttm_dma_unpopulate (struct ttm_tt *ttm_dma,struct device *dev);#else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
@@ -107,13 +107,13 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) {return 0 ; } -static inline int ttm_dma_populate (struct ttm_dma_tt *ttm_dma, +static inline int ttm_dma_populate (struct ttm_tt *ttm_dma,struct device *dev,struct ttm_operation_ctx *ctx) {return -ENOMEM ; } -static inline void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma, +static inline void ttm_dma_unpopulate (struct ttm_tt *ttm_dma,struct device *dev) { }
include/drm/ttm/ttm_tt.h +10 -25
@@ -47,12 +47,13 @@ struct ttm_operation_ctx;* struct ttm_tt * * @pages: Array of pages backing the data. +* @page_flags: see TTM_PAGE_FLAG_* * @num_pages: Number of pages in the page array. -* @bdev: Pointer to the current struct ttm_bo_device. -* @be: Pointer to the ttm backend. +* @sg: for SG objects via dma-buf +* @dma_address: The DMA (bus) addresses of the pages * @swap_storage: Pointer to shmem struct file for swap storage. -* @caching_state: The current caching state of the pages. -* @state: The current binding state of the pages. +* @pages_list: used by some page allocation backend +* @caching: The current caching state of the pages. * * This is a structure holding the pages, caching- and aperture binding * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -62,8 +63,10 @@ struct ttm_tt {struct page **pages;uint32_t page_flags;uint32_t num_pages; -struct sg_table *sg;/* for SG objects via dma-buf */ +struct sg_table *sg; +dma_addr_t *dma_address;struct file *swap_storage; +struct list_head pages_list;enum ttm_caching caching; };
@@ -72,23 +75,6 @@ static inline bool ttm_tt_is_populated(struct ttm_tt *tt)return tt->page_flags &TTM_PAGE_FLAG_PRIV_POPULATED ; } -/** -* struct ttm_dma_tt -* -* @ttm: Base ttm_tt struct. -* @dma_address: The DMA (bus) addresses of the pages -* @pages_list: used by some page allocation backend -* -* This is a structure holding the pages, caching- and aperture binding -* status for a buffer object that isn't backed by fixed (VRAM / AGP) -* memory. -*/ -struct ttm_dma_tt { -struct ttm_tt ttm; -dma_addr_t *dma_address; -struct list_head pages_list; -}; -/** * ttm_tt_create *
@@ -115,9 +101,9 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);*/ int ttm_tt_init (struct ttm_tt *ttm,struct ttm_buffer_object *bo,uint32_t page_flags,enum ttm_caching caching); -int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_buffer_object *bo, +int ttm_dma_tt_init (struct ttm_tt *ttm_dma,struct ttm_buffer_object *bo,uint32_t page_flags,enum ttm_caching caching); -int ttm_sg_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_buffer_object *bo, +int ttm_sg_tt_init (struct ttm_tt *ttm_dma,struct ttm_buffer_object *bo,uint32_t page_flags,enum ttm_caching caching);/**
@@ -128,7 +114,6 @@ int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,* Free memory of ttm_tt structure */ void ttm_tt_fini (struct ttm_tt *ttm); -void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma);/** * ttm_ttm_destroy:
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/13 drm/ttm: new TT backend allocation pool
In reply to Christian KönigThis replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The alloc_pages() based pool was zeroing it, the dma_alloc_attr() based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the __GFP_ZERO flag when necessary.
The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
--- drivers/gpu/drm/ttm/Makefile | 2 +- drivers/gpu/drm/ttm/ttm_memory.c | 3 + drivers/gpu/drm/ttm/ttm_pool.c | 664 +++++++++++++++++++++++++++++++ include/drm/ttm/ttm_caching.h | 2 + include/drm/ttm/ttm_pool.h | 89 +++++ 5 files changed, 759 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ttm/ttm_pool.c create mode 100644 include/drm/ttm/ttm_pool.h
drivers/gpu/drm/ttm/Makefile +1 -1
@@ -5,7 +5,7 @@ ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \ ttm_bo_util.o ttm_bo_vm.o ttm_module.o \ ttm_execbuf_util.o ttm_page_alloc.o ttm_range_manager.o \ - ttm_resource.o + ttm_resource.o ttm_pool.o ttm-$(CONFIG_AGP) += ttm_agp_backend.o ttm-$(CONFIG_DRM_TTM_DMA_PAGE_POOL) += ttm_page_alloc_dma.o
drivers/gpu/drm/ttm/ttm_memory.c +3 -0
@@ -38,6 +38,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/swap.h> +#include <drm/ttm/ttm_pool.h> #define TTM_MEMORY_ALLOC_RETRIES 4
@@ -453,6 +454,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) }ttm_page_alloc_init (glob, glob->zone_kernel->max_mem/(2 *PAGE_SIZE ));ttm_dma_page_alloc_init (glob, glob->zone_kernel->max_mem/(2 *PAGE_SIZE )); +ttm_pool_mgr_init (glob->zone_kernel->max_mem/(2 *PAGE_SIZE ));return 0 ; out_no_zone:ttm_mem_global_release (glob);
@@ -467,6 +469,7 @@ void ttm_mem_global_release(struct ttm_mem_global *glob)/* let the page allocator first stop the shrink work. */ ttm_page_alloc_fini ();ttm_dma_page_alloc_fini (); +ttm_pool_mgr_fini ();flush_workqueue (glob->swap_queue);destroy_workqueue (glob->swap_queue);
drivers/gpu/drm/ttm/ttm_pool.c new file +664 -0
664 lines not on this page · raw message
include/drm/ttm/ttm_caching.h +2 -0
@@ -25,6 +25,8 @@#ifndef _TTM_CACHING_H_#define _TTM_CACHING_H_ +#define TTM_NUM_CACHING_TYPES 3 +enum ttm_caching { ttm_uncached, ttm_write_combined,
include/drm/ttm/ttm_pool.h new file +89 -0
89 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi "Christian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-exynos/exynos-drm-next drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master drm/drm-next v5.9 next-20201023] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: arc-randconfig-r024-20201026 (attached as .config) compiler: arc-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/618def1bc3db379a76b7462ab38236bfeb3df3d3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 git checkout 618def1bc3db379a76b7462ab38236bfeb3df3d3
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/ttm/ttm_pool.c:154:5: warning: no previous prototype for 'ttm_pool_apply_caching' [-Wmissing-prototypes]
154 | int ttm_pool_apply_caching(struct page **first, struct page **last,
| ^~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/list.h:9,
from include/linux/module.h:12,
from drivers/gpu/drm/ttm/ttm_pool.c:33:
drivers/gpu/drm/ttm/ttm_pool.c: In function 'ttm_pool_alloc':
include/linux/kernel.h:850:29: warning: comparison of distinct pointer types lacks a cast
850 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
| ^~
include/linux/kernel.h:864:4: note: in expansion of macro '__typecheck'
864 | (__typecheck(x, y) && __no_side_effects(x, y))
| ^~~~~~~~~~~
include/linux/kernel.h:874:24: note: in expansion of macro '__safe_cmp'
874 | __builtin_choose_expr(__safe_cmp(x, y), \
| ^~~~~~~~~~
include/linux/kernel.h:883:19: note: in expansion of macro '__careful_cmp'
883 | #define min(x, y) __careful_cmp(x, y, <)
| ^~~~~~~~~~~~~
drivers/gpu/drm/ttm/ttm_pool.c:378:15: note: in expansion of macro 'min'
378 | for (order = min(MAX_ORDER - 1UL, __fls(num_pages)); num_pages;
| ^~~vim +/ttm_pool_apply_caching +154 drivers/gpu/drm/ttm/ttm_pool.c
152
153 /* Apply a new caching to an array of pages */
> 154 int ttm_pool_apply_caching(struct page **first, struct page **last,
155 enum ttm_caching caching)
156 {
157 #ifdef CONFIG_X86
158 unsigned int num_pages = last - first;
159
160 if (!num_pages)
161 return 0;
162
163 switch (caching) {
164 case ttm_cached:
165 break;
166 case ttm_write_combined:
167 return set_pages_array_wc(first, num_pages);
168 break;
169 case ttm_uncached:
170 return set_pages_array_uc(first, num_pages);
171 break;
172 }
173 #endif
174 return 0;
175 }
176
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi "Christian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-exynos/exynos-drm-next drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master drm/drm-next v5.9 next-20201023] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: i386-randconfig-s001-20201026 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-56-gc09e8239-dirty # https://github.com/0day-ci/linux/commit/618def1bc3db379a76b7462ab38236bfeb3df3d3 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 git checkout 618def1bc3db379a76b7462ab38236bfeb3df3d3 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
"sparse warnings: (new ones prefixed by >>)"
>> drivers/gpu/drm/ttm/ttm_pool.c:154:5: sparse: sparse: symbol 'ttm_pool_apply_caching' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build bot[RFC PATCH] drm/ttm: ttm_pool_apply_caching() can be static
In reply to Christian KönigSigned-off-by: kernel test robot <[email protected]>
--- ttm_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +2 -2
@@ -151,8 +151,8 @@ static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching, }/* Apply a new caching to an array of pages */ -int ttm_pool_apply_caching (struct page **first,struct page **last, -enum ttm_caching caching) +static int ttm_pool_apply_caching (struct page **first,struct page **last, +enum ttm_caching caching) {#ifdef CONFIG_X86 unsigned int num_pages = last - first;
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi "Christian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-exynos/exynos-drm-next drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master drm/drm-next v5.10-rc1 next-20201026] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: s390-randconfig-r036-20201026 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 1c8371692dfe8245bc6690ff1262dcced4649d21)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/618def1bc3db379a76b7462ab38236bfeb3df3d3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christian-K-nig/drm-ttm-nuke-ttm_tt_set_-un-populated-again/20201026-004114 git checkout 618def1bc3db379a76b7462ab38236bfeb3df3d3
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:19:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
^
In file included from drivers/gpu/drm/ttm/ttm_pool.c:34:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:20:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
^
In file included from drivers/gpu/drm/ttm/ttm_pool.c:34:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
^
In file included from drivers/gpu/drm/ttm/ttm_pool.c:34:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
^
In file included from drivers/gpu/drm/ttm/ttm_pool.c:34:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
__fswab32(x))
^
In file included from drivers/gpu/drm/ttm/ttm_pool.c:34:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:72:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> drivers/gpu/drm/ttm/ttm_pool.c:154:5: warning: no previous prototype for function 'ttm_pool_apply_caching' [-Wmissing-prototypes]
int ttm_pool_apply_caching(struct page **first, struct page **last,
^ drivers/gpu/drm/ttm/ttm_pool.c:154:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int ttm_pool_apply_caching(struct page **first, struct page **last,
^
static
21 warnings generated.
vim +/ttm_pool_apply_caching +154 drivers/gpu/drm/ttm/ttm_pool.c
152
153 /* Apply a new caching to an array of pages */
> 154 int ttm_pool_apply_caching(struct page **first, struct page **last,
155 enum ttm_caching caching)
156 {
157 #ifdef CONFIG_X86
158 unsigned int num_pages = last - first;
159
160 if (!num_pages)
161 return 0;
162
163 switch (caching) {
164 case ttm_cached:
165 break;
166 case ttm_write_combined:
167 return set_pages_array_wc(first, num_pages);
168 break;
169 case ttm_uncached:
170 return set_pages_array_uc(first, num_pages);
171 break;
172 }
173 #endif
174 return 0;
175 }
176
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 6/13 drm/ttm: wire up the new pool as default one
In reply to Christian KönigProvide the necessary parameters by all drivers and use the new pool alloc when no driver specific function is provided.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++-- drivers/gpu/drm/drm_gem_vram_helper.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_ttm.c | 14 +++++++++----- drivers/gpu/drm/qxl/qxl_ttm.c | 5 ++--- drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++-- drivers/gpu/drm/ttm/ttm_bo.c | 8 ++++++-- drivers/gpu/drm/ttm/ttm_tt.c | 5 ++--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 5 +++-- include/drm/ttm/ttm_bo_driver.h | 11 +++++++---- 9 files changed, 35 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -2
@@ -1914,10 +1914,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)mutex_init (&adev->mman.gtt_window_lock);/* No others user of address space so set it to 0 */ - r =ttm_bo_device_init (&adev->mman.bdev, - &amdgpu_bo_driver, + r =ttm_bo_device_init (&adev->mman.bdev, &amdgpu_bo_driver, adev->dev,adev_to_drm (adev)->anon_inode->i_mapping,adev_to_drm (adev)->vma_offset_manager, + adev->need_swiotlb,dma_addressing_limited (adev->dev));if (r) {DRM_ERROR ("failed initializing buffer object driver(%d).\n" , r);
drivers/gpu/drm/drm_gem_vram_helper.c +2 -2
@@ -1045,10 +1045,10 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev, vmm->vram_base = vram_base; vmm->vram_size = vram_size; - ret =ttm_bo_device_init (&vmm->bdev, &bo_driver, + ret =ttm_bo_device_init (&vmm->bdev, &bo_driver, vmm->dev, dev->anon_inode->i_mapping, dev->vma_offset_manager, - true); + false, true);if (ret)return ret;
drivers/gpu/drm/nouveau/nouveau_ttm.c +9 -5
@@ -281,6 +281,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)struct nvkm_pci *pci = device->pci;struct nvif_mmu *mmu = &drm->client.mmu;struct drm_device *dev = drm->dev; +bool need_swiotlb = false;int typei, ret; ret =nouveau_ttm_init_host (drm,0 );
@@ -315,11 +316,14 @@ nouveau_ttm_init(struct nouveau_drm *drm) drm->agp.cma = pci->agp.cma; } - ret =ttm_bo_device_init (&drm->ttm.bdev, - &nouveau_bo_driver, - dev->anon_inode->i_mapping, - dev->vma_offset_manager, - drm->client.mmu.dmabits <=32 ? true : false); +#if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 ) + need_swiotlb = !!swiotlb_nr_tbl (); +#endif + + ret =ttm_bo_device_init (&drm->ttm.bdev, &nouveau_bo_driver, + drm->dev->dev, dev->anon_inode->i_mapping, + dev->vma_offset_manager, need_swiotlb, + drm->client.mmu.dmabits <=32 );if (ret) {NV_ERROR (drm,"error initialising bo driver, %d\n" , ret);return ret;
drivers/gpu/drm/qxl/qxl_ttm.c +2 -3
@@ -194,11 +194,10 @@ int qxl_ttm_init(struct qxl_device *qdev)int num_io_pages;/* != rom->num_io_pages, we include surface0 */ /* No others user of address space so set it to 0 */ - r =ttm_bo_device_init (&qdev->mman.bdev, - &qxl_bo_driver, + r =ttm_bo_device_init (&qdev->mman.bdev, &qxl_bo_driver,NULL , qdev->ddev.anon_inode->i_mapping, qdev->ddev.vma_offset_manager, - false); + false, false);if (r) {DRM_ERROR ("failed initializing buffer object driver(%d).\n" , r);return r;
drivers/gpu/drm/radeon/radeon_ttm.c +2 -2
@@ -846,10 +846,10 @@ int radeon_ttm_init(struct radeon_device *rdev)int r;/* No others user of address space so set it to 0 */ - r =ttm_bo_device_init (&rdev->mman.bdev, - &radeon_bo_driver, + r =ttm_bo_device_init (&rdev->mman.bdev, &radeon_bo_driver, rdev->dev, rdev->ddev->anon_inode->i_mapping, rdev->ddev->vma_offset_manager, + rdev->need_swiotlb,dma_addressing_limited (&rdev->pdev->dev));if (r) {DRM_ERROR ("failed initializing buffer object driver(%d).\n" , r);
drivers/gpu/drm/ttm/ttm_bo.c +6 -2
@@ -1283,6 +1283,8 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)pr_debug ("Swap list %d was clean\n" , i);spin_unlock (&glob->lru_lock); +ttm_pool_fini (&bdev->pool); +if (!ret)ttm_bo_global_release ();
@@ -1307,9 +1309,10 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)int ttm_bo_device_init (struct ttm_bo_device *bdev,struct ttm_bo_driver *driver, +struct device *dev,struct address_space *mapping,struct drm_vma_offset_manager *vma_manager, -bool need_dma32) +bool use_dma_alloc,bool use_dma32) {struct ttm_bo_global *glob = &ttm_bo_glob;int ret;
@@ -1324,12 +1327,13 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, bdev->driver = driver;ttm_bo_init_sysman (bdev); +ttm_pool_init (&bdev->pool, dev, use_dma_alloc, use_dma32); bdev->vma_manager = vma_manager;INIT_DELAYED_WORK (&bdev->wq, ttm_bo_delayed_workqueue);INIT_LIST_HEAD (&bdev->ddestroy); bdev->dev_mapping = mapping; - bdev->need_dma32 = need_dma32; + bdev->need_dma32 = use_dma32;mutex_lock (&ttm_global_mutex);list_add_tail (&bdev->device_list, &glob->device_list);mutex_unlock (&ttm_global_mutex);
drivers/gpu/drm/ttm/ttm_tt.c +2 -3
@@ -37,7 +37,6 @@#include <linux/file.h> #include <drm/drm_cache.h> #include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_page_alloc.h> /** * Allocates a ttm structure for the given BO.
@@ -321,7 +320,7 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,if (bdev->driver->ttm_tt_populate) ret = bdev->driver->ttm_tt_populate (bdev, ttm, ctx);else - ret =ttm_pool_populate (ttm, ctx); + ret =ttm_pool_alloc (&bdev->pool, ttm, ctx);if (ret)return ret;
@@ -363,6 +362,6 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev,if (bdev->driver->ttm_tt_unpopulate) bdev->driver->ttm_tt_unpopulate (bdev, ttm);else -ttm_pool_unpopulate (ttm); +ttm_pool_free (&bdev->pool, ttm); ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED ; }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -2
@@ -878,10 +878,11 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)drm_vma_offset_manager_init (&dev_priv->vma_manager,DRM_FILE_PAGE_OFFSET_START ,DRM_FILE_PAGE_OFFSET_SIZE ); - ret =ttm_bo_device_init (&dev_priv->bdev, - &vmw_bo_driver, + ret =ttm_bo_device_init (&dev_priv->bdev, &vmw_bo_driver, + dev_priv->dev->dev, dev->anon_inode->i_mapping, &dev_priv->vma_manager, + dev_priv->map_mode == vmw_dma_alloc_coherent, false);if (unlikely (ret !=0 )) {DRM_ERROR ("Failed initializing TTM buffer object driver.\n" );
include/drm/ttm/ttm_bo_driver.h +7 -4
@@ -42,6 +42,7 @@#include "ttm_module.h" #include "ttm_placement.h" #include "ttm_tt.h" +#include "ttm_pool.h" /** * struct ttm_bo_driver
@@ -295,6 +296,7 @@ struct ttm_bo_device {* Protected by internal locks. */ struct drm_vma_offset_manager *vma_manager; +struct ttm_pool pool;/* * Protected by the global:lru lock.
@@ -395,11 +397,11 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev);* @bdev: A pointer to a struct ttm_bo_device to initialize. * @glob: A pointer to an initialized struct ttm_bo_global. * @driver: A pointer to a struct ttm_bo_driver set up by the caller. +* @dev: The core kernel device pointer for DMA mappings and allocations. * @mapping: The address space to use for this bo. * @vma_manager: A pointer to a vma manager. -* @file_page_offset: Offset into the device address space that is available -* for buffer data. This ensures compatibility with other users of the -* address space. +* @use_dma_alloc: If coherent DMA allocation API should be used. +* @use_dma32: If we should use GFP_DMA32 for device memory allocations. * * Initializes a struct ttm_bo_device: * Returns:
@@ -407,9 +409,10 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev);*/ int ttm_bo_device_init (struct ttm_bo_device *bdev,struct ttm_bo_driver *driver, +struct device *dev,struct address_space *mapping,struct drm_vma_offset_manager *vma_manager, -bool need_dma32); +bool use_dma_alloc,bool use_dma32);/** * ttm_bo_unmap_virtual
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/13 drm/amdgpu: switch to new allocator
In reply to Christian KönigIt should be able to handle all cases here.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 39 +++++++++---------------- 1 file changed, 14 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14 -25
@@ -47,7 +47,6 @@#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_module.h> -#include <drm/ttm/ttm_page_alloc.h> #include <drm/drm_debugfs.h> #include <drm/amdgpu_drm.h>
@@ -1383,15 +1382,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,return 0 ; } -#ifdef CONFIG_SWIOTLB -if (adev->need_swiotlb &&swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, adev->dev, ctx); - } -#endif - -/* fall back to generic helper to populate the page array -* and map them to the device */ -return ttm_populate_and_map_pages (adev->dev, >t->ttm, ctx); +return ttm_pool_alloc (&adev->mman.bdev.pool, ttm, ctx); }/**
@@ -1400,7 +1391,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,* Unmaps pages of a ttm_tt object from the device address space and * unpopulates the page array backing it. */ -static void amdgpu_ttm_tt_unpopulate (struct ttm_bo_device *bdev,struct ttm_tt *ttm) +static void amdgpu_ttm_tt_unpopulate (struct ttm_bo_device *bdev, +struct ttm_tt *ttm) {struct amdgpu_ttm_tt *gtt = (void *)ttm;struct amdgpu_device *adev;
@@ -1425,16 +1417,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *return ; adev =amdgpu_ttm_adev (bdev); - -#ifdef CONFIG_SWIOTLB -if (adev->need_swiotlb &&swiotlb_nr_tbl ()) { -ttm_dma_unpopulate (>t->ttm, adev->dev); -return ; - } -#endif - -/* fall back to generic helper to unmap and unpopulate array */ -ttm_unmap_and_unpopulate_pages (adev->dev, >t->ttm); +return ttm_pool_free (&adev->mman.bdev.pool, ttm); }/**
@@ -2347,16 +2330,22 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data)return 0 ; } +static int amdgpu_ttm_pool_debugfs (struct seq_file *m,void *data) +{ +struct drm_info_node *node = (struct drm_info_node *)m->private; +struct drm_device *dev = node->minor->dev; +struct amdgpu_device *adev =drm_to_adev (dev); + +return ttm_pool_debugfs (&adev->mman.bdev.pool, m); +} +static const struct drm_info_list amdgpu_ttm_debugfs_list[] = { {"amdgpu_vram_mm" , amdgpu_mm_dump_table,0 , (void *)TTM_PL_VRAM }, {"amdgpu_gtt_mm" , amdgpu_mm_dump_table,0 , (void *)TTM_PL_TT }, {"amdgpu_gds_mm" , amdgpu_mm_dump_table,0 , (void *)AMDGPU_PL_GDS }, {"amdgpu_gws_mm" , amdgpu_mm_dump_table,0 , (void *)AMDGPU_PL_GWS }, {"amdgpu_oa_mm" , amdgpu_mm_dump_table,0 , (void *)AMDGPU_PL_OA }, - {"ttm_page_pool" , ttm_page_alloc_debugfs,0 ,NULL }, -#ifdef CONFIG_SWIOTLB - {"ttm_dma_page_pool" , ttm_dma_page_alloc_debugfs,0 ,NULL } -#endif + {"ttm_page_pool" , amdgpu_ttm_pool_debugfs,0 ,NULL }, };/**
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/13 drm/radeon: switch to new allocator
In reply to Christian KönigIt should be able to handle all cases here.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +14 -33
@@ -47,7 +47,6 @@#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_module.h> -#include <drm/ttm/ttm_page_alloc.h> #include <drm/ttm/ttm_placement.h> #include "radeon_reg.h"
@@ -679,19 +678,7 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,return 0 ; } -#if IS_ENABLED (CONFIG_AGP ) -if (rdev->flags &RADEON_IS_AGP ) { -return ttm_pool_populate (ttm, ctx); - } -#endif - -#ifdef CONFIG_SWIOTLB -if (rdev->need_swiotlb &&swiotlb_nr_tbl ()) { -return ttm_dma_populate (>t->ttm, rdev->dev, ctx); - } -#endif - -return ttm_populate_and_map_pages (rdev->dev, >t->ttm, ctx); +return ttm_pool_alloc (&rdev->mman.bdev.pool, ttm, ctx); }static void radeon_ttm_tt_unpopulate (struct ttm_bo_device *bdev,struct ttm_tt *ttm)
@@ -709,21 +696,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *if (slave)return ; -#if IS_ENABLED (CONFIG_AGP ) -if (rdev->flags &RADEON_IS_AGP ) { -ttm_pool_unpopulate (ttm); -return ; - } -#endif - -#ifdef CONFIG_SWIOTLB -if (rdev->need_swiotlb &&swiotlb_nr_tbl ()) { -ttm_dma_unpopulate (>t->ttm, rdev->dev); -return ; - } -#endif - -ttm_unmap_and_unpopulate_pages (rdev->dev, >t->ttm); +return ttm_pool_free (&rdev->mman.bdev.pool, ttm); } int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
@@ -857,6 +830,9 @@ int radeon_ttm_init(struct radeon_device *rdev) } rdev->mman.initialized = true; +ttm_pool_init (&rdev->mman.bdev.pool, rdev->dev, rdev->need_swiotlb, +dma_addressing_limited (&rdev->pdev->dev)); + r =radeon_ttm_init_vram (rdev);if (r) {DRM_ERROR ("Failed initializing VRAM heap.\n" );
@@ -1004,6 +980,14 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)return 0 ; } +static int radeon_ttm_pool_debugfs (struct seq_file *m,void *data) +{ +struct drm_info_node *node = (struct drm_info_node *)m->private; +struct drm_device *dev = node->minor->dev; +struct radeon_device *rdev = dev->dev_private; + +return ttm_pool_debugfs (&rdev->mman.bdev.pool, m); +}static int ttm_pl_vram =TTM_PL_VRAM ;static int ttm_pl_tt =TTM_PL_TT ;
@@ -1011,10 +995,7 @@ static int ttm_pl_tt = TTM_PL_TT;static struct drm_info_list radeon_ttm_debugfs_list[] = { {"radeon_vram_mm" , radeon_mm_dump_table,0 , &ttm_pl_vram}, {"radeon_gtt_mm" , radeon_mm_dump_table,0 , &ttm_pl_tt}, - {"ttm_page_pool" , ttm_page_alloc_debugfs,0 ,NULL }, -#ifdef CONFIG_SWIOTLB - {"ttm_dma_page_pool" , ttm_dma_page_alloc_debugfs,0 ,NULL } -#endif + {"ttm_page_pool" , radeon_ttm_pool_debugfs,0 ,NULL } };static int radeon_ttm_vram_open (struct inode *inode,struct file *filep)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/13 drm/nouveau: switch to new allocator
In reply to Christian KönigIt should be able to handle all cases now.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 30 ++------------------------- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 - 2 files changed, 2 insertions(+), 29 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +2 -28
@@ -1327,25 +1327,13 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev, drm =nouveau_bdev (bdev); dev = drm->dev->dev; -#if IS_ENABLED (CONFIG_AGP ) -if (drm->agp.bridge) { -return ttm_pool_populate (ttm, ctx); - } -#endif - -#if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 ) -if (swiotlb_nr_tbl ()) { -return ttm_dma_populate ((void *)ttm, dev, ctx); - } -#endif -return ttm_populate_and_map_pages (dev, ttm_dma, ctx); +return ttm_pool_alloc (&drm->ttm.bdev.pool, ttm, ctx); }static void nouveau_ttm_tt_unpopulate (struct ttm_bo_device *bdev,struct ttm_tt *ttm) { -struct ttm_tt *ttm_dma = (void *)ttm;struct nouveau_drm *drm;struct device *dev;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG );
@@ -1356,21 +1344,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev, drm =nouveau_bdev (bdev); dev = drm->dev->dev; -#if IS_ENABLED (CONFIG_AGP ) -if (drm->agp.bridge) { -ttm_pool_unpopulate (ttm); -return ; - } -#endif - -#if IS_ENABLED (CONFIG_SWIOTLB ) &&IS_ENABLED (CONFIG_X86 ) -if (swiotlb_nr_tbl ()) { -ttm_dma_unpopulate ((void *)ttm, dev); -return ; - } -#endif - -ttm_unmap_and_unpopulate_pages (dev, ttm_dma); +return ttm_pool_free (&drm->ttm.bdev.pool, ttm); } static void
drivers/gpu/drm/nouveau/nouveau_drv.h +0 -1
@@ -56,7 +56,6 @@#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_memory.h> #include <drm/ttm/ttm_module.h> -#include <drm/ttm/ttm_page_alloc.h> #include <drm/drm_audio_component.h>
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/13 drm/vmwgfx: switch to new allocator
In reply to Christian KönigIt should be able to handle all cases now.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 --- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 36 ++-------------------- 2 files changed, 3 insertions(+), 37 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -4
@@ -595,10 +595,6 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)else dev_priv->map_mode = vmw_dma_map_populate; -if (!IS_ENABLED (CONFIG_DRM_TTM_DMA_PAGE_POOL ) && - (dev_priv->map_mode == vmw_dma_alloc_coherent)) -return -EINVAL ; -DRM_INFO ("DMA map mode: %s\n" , names[dev_priv->map_mode]);return 0 ; }
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +3 -33
@@ -28,7 +28,6 @@#include "vmwgfx_drv.h" #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_page_alloc.h> static const struct ttm_place vram_placement_flags = { .fpfn =0 ,
@@ -582,30 +581,11 @@ static void vmw_ttm_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)static int vmw_ttm_populate (struct ttm_bo_device *bdev,struct ttm_tt *ttm,struct ttm_operation_ctx *ctx) { -struct vmw_ttm_tt *vmw_tt = - container_of(ttm, struct vmw_ttm_tt, dma_ttm); -struct vmw_private *dev_priv = vmw_tt->dev_priv; -struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); -int ret; - +/* TODO: maybe completely drop this ? */ if (ttm_tt_is_populated (ttm))return 0 ; -if (dev_priv->map_mode == vmw_dma_alloc_coherent) { -size_t size = -ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - ret =ttm_mem_global_alloc (glob, size, ctx); -if (unlikely (ret !=0 )) -return ret; - - ret =ttm_dma_populate (&vmw_tt->dma_ttm, dev_priv->dev->dev, - ctx); -if (unlikely (ret !=0 )) -ttm_mem_global_free (glob, size); - }else - ret =ttm_pool_populate (ttm, ctx); - -return ret; +return ttm_pool_alloc (&bdev->pool, ttm, ctx); } static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev,
@@ -613,9 +593,6 @@ static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev, { struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, dma_ttm); -struct vmw_private *dev_priv = vmw_tt->dev_priv; -struct ttm_mem_global *glob =vmw_mem_glob (dev_priv); -if (vmw_tt->mob) {vmw_mob_destroy (vmw_tt->mob);
@@ -623,14 +600,7 @@ static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev, }vmw_ttm_unmap_dma (vmw_tt); -if (dev_priv->map_mode == vmw_dma_alloc_coherent) { -size_t size = -ttm_round_pot (ttm->num_pages *sizeof (dma_addr_t)); - -ttm_dma_unpopulate (&vmw_tt->dma_ttm, dev_priv->dev->dev); -ttm_mem_global_free (glob, size); - }else -ttm_pool_unpopulate (ttm); +ttm_pool_free (&bdev->pool, ttm); } static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 11/13 drm/qxl: drop ttm_page_alloc.h include
In reply to Christian KönigNot needed as far as I can see.
--- drivers/gpu/drm/qxl/qxl_ttm.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ttm.c +0 -1
@@ -32,7 +32,6 @@#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_module.h> -#include <drm/ttm/ttm_page_alloc.h> #include <drm/ttm/ttm_placement.h> #include "qxl_drv.h"
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 12/13 drm/vram_helpers: drop ttm_page_alloc.h include
In reply to Christian KönigNot needed as far as I can see.
--- drivers/gpu/drm/drm_gem_vram_helper.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/drm_gem_vram_helper.c +0 -1
@@ -15,7 +15,6 @@#include <drm/drm_plane.h> #include <drm/drm_prime.h> #include <drm/drm_simple_kms_helper.h> -#include <drm/ttm/ttm_page_alloc.h> static const struct drm_gem_object_funcs drm_gem_vram_object_funcs;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 13/13 drm/ttm: nuke old page allocator
In reply to Christian KönigNot used any more.
--- drivers/gpu/drm/Kconfig | 7 - drivers/gpu/drm/ttm/Makefile | 3 +- drivers/gpu/drm/ttm/ttm_agp_backend.c | 1 - drivers/gpu/drm/ttm/ttm_bo.c | 1 - drivers/gpu/drm/ttm/ttm_memory.c | 5 - drivers/gpu/drm/ttm/ttm_page_alloc.c | 1176 --------------------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 1226 ---------------------- drivers/gpu/drm/ttm/ttm_set_memory.h | 84 -- drivers/gpu/drm/ttm/ttm_tt.c | 4 - include/drm/ttm/ttm_bo_driver.h | 2 - include/drm/ttm/ttm_page_alloc.h | 122 --- include/drm/ttm/ttm_tt.h | 2 - 12 files changed, 1 insertion(+), 2632 deletions(-) delete mode 100644 drivers/gpu/drm/ttm/ttm_page_alloc.c delete mode 100644 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c delete mode 100644 drivers/gpu/drm/ttm/ttm_set_memory.h delete mode 100644 include/drm/ttm/ttm_page_alloc.h
drivers/gpu/drm/Kconfig +0 -7
@@ -182,13 +182,6 @@ config DRM_TTM GPU memory types. Will be enabled automatically if a device driver uses it. -config DRM_TTM_DMA_PAGE_POOL - bool - depends on DRM_TTM && (SWIOTLB || INTEL_IOMMU) - default y - help - Choose this if you need the TTM dma page pool - config DRM_VRAM_HELPER tristate depends on DRM
drivers/gpu/drm/ttm/Makefile +1 -2
@@ -4,9 +4,8 @@ ttm-y := ttm_memory.o ttm_tt.o ttm_bo.o \ ttm_bo_util.o ttm_bo_vm.o ttm_module.o \ - ttm_execbuf_util.o ttm_page_alloc.o ttm_range_manager.o \ + ttm_execbuf_util.o ttm_range_manager.o \ ttm_resource.o ttm_pool.o ttm-$(CONFIG_AGP) += ttm_agp_backend.o -ttm-$(CONFIG_DRM_TTM_DMA_PAGE_POOL) += ttm_page_alloc_dma.o obj-$(CONFIG_DRM_TTM) += ttm.o
drivers/gpu/drm/ttm/ttm_agp_backend.c +0 -1
@@ -34,7 +34,6 @@#include <drm/ttm/ttm_module.h> #include <drm/ttm/ttm_bo_driver.h> -#include <drm/ttm/ttm_page_alloc.h> #include <drm/ttm/ttm_placement.h> #include <linux/agp_backend.h> #include <linux/module.h>
drivers/gpu/drm/ttm/ttm_bo.c +0 -1
@@ -1333,7 +1333,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,INIT_DELAYED_WORK (&bdev->wq, ttm_bo_delayed_workqueue);INIT_LIST_HEAD (&bdev->ddestroy); bdev->dev_mapping = mapping; - bdev->need_dma32 = use_dma32;mutex_lock (&ttm_global_mutex);list_add_tail (&bdev->device_list, &glob->device_list);mutex_unlock (&ttm_global_mutex);
drivers/gpu/drm/ttm/ttm_memory.c +0 -5
@@ -30,7 +30,6 @@#include <drm/ttm/ttm_memory.h> #include <drm/ttm/ttm_module.h> -#include <drm/ttm/ttm_page_alloc.h> #include <linux/spinlock.h> #include <linux/sched.h> #include <linux/wait.h>
@@ -452,8 +451,6 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)pr_info ("Zone %7s: Available graphics memory: %llu KiB\n" , zone->name, (unsigned long long )zone->max_mem >>10 ); } -ttm_page_alloc_init (glob, glob->zone_kernel->max_mem/(2 *PAGE_SIZE )); -ttm_dma_page_alloc_init (glob, glob->zone_kernel->max_mem/(2 *PAGE_SIZE ));ttm_pool_mgr_init (glob->zone_kernel->max_mem/(2 *PAGE_SIZE ));return 0 ; out_no_zone:
@@ -467,8 +464,6 @@ void ttm_mem_global_release(struct ttm_mem_global *glob)unsigned int i;/* let the page allocator first stop the shrink work. */ -ttm_page_alloc_fini (); -ttm_dma_page_alloc_fini ();ttm_pool_mgr_fini ();flush_workqueue (glob->swap_queue);
drivers/gpu/drm/ttm/ttm_page_alloc.c deleted +0 -1176
1,176 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c deleted +0 -1226
1,226 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_set_memory.h deleted +0 -84
84 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +0 -4
@@ -51,9 +51,6 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)if (bo->ttm)return 0 ; -if (bdev->need_dma32) - page_flags |=TTM_PAGE_FLAG_DMA32 ; -if (bdev->no_retry) page_flags |=TTM_PAGE_FLAG_NO_RETRY ;
@@ -141,7 +138,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->dma_address =NULL ; ttm->swap_storage =NULL ; ttm->sg = bo->sg; -INIT_LIST_HEAD (&ttm->pages_list); ttm->caching = caching; }
include/drm/ttm/ttm_bo_driver.h +0 -2
@@ -315,8 +315,6 @@ struct ttm_bo_device {struct delayed_work wq; -bool need_dma32; -bool no_retry; };
include/drm/ttm/ttm_page_alloc.h deleted +0 -122
122 lines not on this page · raw message
include/drm/ttm/ttm_tt.h +0 -2
@@ -37,7 +37,6 @@ struct ttm_operation_ctx;#define TTM_PAGE_FLAG_SWAPPED (1 << 4)#define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6) -#define TTM_PAGE_FLAG_DMA32 (1 << 7)#define TTM_PAGE_FLAG_SG (1 << 8)#define TTM_PAGE_FLAG_NO_RETRY (1 << 9)
@@ -66,7 +65,6 @@ struct ttm_tt {struct sg_table *sg;dma_addr_t *dma_address;struct file *swap_storage; -struct list_head pages_list;enum ttm_caching caching; };
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerQuoted 30 lines · Christian König
This replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The
alloc_pages()based pool was zeroing it, thedma_alloc_attr()based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the__GFP_ZEROflag when necessary.
Quoted 8 lines
The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
Please review and comment,
Interesting, 5 doesn't have appeared to make on the list, but it definitely has some checkpatch warnings. (indents, missing spaces etc), Please clean those up.
some other random comments on it
+ if (order) {
+ gfp_flags |= GFP_TRANSHUGE_LIGHT | __GFP_NORETRY |
+ __GFP_KSWAPD_RECLAIM;
+ gfp_flags &= ~__GFP_MOVABLE;
+ gfp_flags &= ~__GFP_COMP;
+ }
I'd like some explains of why these flags are chosen.
Otherwise I'm pretty happy with the remaining patch in the series, it ends up with a pretty nice cleanup.
Note drm_gem_vram_helper fails to build (vmm->dev should be dev->dev possibly).
Once you clean up checkpatch and make drm_gem_vram_helper build again. For 5-13 Reviewed-by: Dave Airlie <[email protected]>
I've also boot tested this on nouveau and it survives the basics fine.
Dave.
Quoted 7 lines
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 26.10.20 um 06:23 schrieb Dave Airlie:
Quoted 35 lines
Quoted 33 lines · Christian König
This replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The
alloc_pages()based pool was zeroing it, thedma_alloc_attr()based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the__GFP_ZEROflag when necessary.The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Quoted 7 lines
Quoted 4 lines
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
Please review and comment,
Interesting, 5 doesn't have appeared to make on the list, but it definitely has some checkpatch warnings. (indents, missing spaces etc), Please clean those up.
Well #5 is the really interesting one. Going to address the checkpatch warnings and send that out again with probably the first patch already pushed.
Quoted 11 lines
some other random comments on it
(quoted diff) +6
-0+ if (order) { + gfp_flags |= GFP_TRANSHUGE_LIGHT | __GFP_NORETRY | + __GFP_KSWAPD_RECLAIM; + gfp_flags &= ~__GFP_MOVABLE; + gfp_flags &= ~__GFP_COMP; + }I'd like some explains of why these flags are chosen.
Good question, I don't remember fully either and have just copied them over from the old allocator for the hugepage case.
In general we just want a cheap try to allocate and fallback to 4k if we don't have enough free.
Moveable and and compound don't work with how TTMs fault mechanism works, so that makes sense anyway.
Quoted 4 lines
Otherwise I'm pretty happy with the remaining patch in the series, it ends up with a pretty nice cleanup.
Note
drm_gem_vram_helperfails to build (vmm->devshould bedev->devpossibly).
Ok, going to double check that. What I've also noticed is that QXL doesn't seem to have a device structure at all.
Going to support that in the new allocator as well.
Quoted 4 lines
Once you clean up checkpatch and make
drm_gem_vram_helperbuild again. For 5-13 Reviewed-by: Dave Airlie <[email protected]>I've also boot tested this on nouveau and it survives the basics fine.
Nice to know. I've tested quite a bit on amdgpu and smoke tested on radeon/nouveau.
Going to give it a try on my AGP radeon as well when I have time.
Christian.
Quoted 10 lines
Dave.
Quoted 7 lines
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 73 lines · Christian König
Am 26.10.20 um 06:23 schrieb Dave Airlie:
Quoted 35 lines
Quoted 33 lines · Christian König
This replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The
alloc_pages()based pool was zeroing it, thedma_alloc_attr()based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the__GFP_ZEROflag when necessary.The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Quoted 7 lines
Quoted 4 lines
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
Please review and comment,
Interesting, 5 doesn't have appeared to make on the list, but it definitely has some checkpatch warnings. (indents, missing spaces etc), Please clean those up.
Well #5 is the really interesting one. Going to address the checkpatch warnings and send that out again with probably the first patch already pushed.
Quoted 11 lines
some other random comments on it
(quoted diff) +6
-0+ if (order) { + gfp_flags |= GFP_TRANSHUGE_LIGHT | __GFP_NORETRY | + __GFP_KSWAPD_RECLAIM; + gfp_flags &= ~__GFP_MOVABLE; + gfp_flags &= ~__GFP_COMP; + }I'd like some explains of why these flags are chosen.
Good question, I don't remember fully either and have just copied them over from the old allocator for the hugepage case.
In general we just want a cheap try to allocate and fallback to 4k if we don't have enough free.
Moveable and and compound don't work with how TTMs fault mechanism works, so that makes sense anyway.
Quoted 3 lines
Otherwise I'm pretty happy with the remaining patch in the series, it ends up with a pretty nice cleanup.
Quoted 6 lines
Quoted 1 line
Note
drm_gem_vram_helperfails to build (vmm->devshould bedev->devpossibly).Ok, going to double check that. What I've also noticed is that QXL doesn't seem to have a device structure at all.
Going to support that in the new allocator as well.
Maybe I'm off, but for dma allocations there's drm_device->dma_dev. I don't think it matters for any ttm using driver right now, but can't hurt to be consistent on this.
-Daniel
Quoted 28 lines
Quoted 5 lines
Once you clean up checkpatch and make
drm_gem_vram_helperbuild again. For 5-13 Reviewed-by: Dave Airlie <[email protected]>I've also boot tested this on nouveau and it survives the basics fine.
Nice to know. I've tested quite a bit on amdgpu and smoke tested on radeon/nouveau.
Going to give it a try on my AGP radeon as well when I have time.
Christian.
Quoted 10 lines
Dave.
Quoted 7 lines
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 29 lines · Christian König
This replaces the spaghetti code in the two existing page pools.
First of all depending on the allocation size it is between 3 (1GiB) and 5 (1MiB) times faster than the old implementation.
It makes better use of buddy pages to allow for larger physical contiguous allocations which should result in better TLB utilization at least for amdgpu.
Instead of a completely braindead approach of filling the pool with one CPU while another one is trying to shrink it we only give back freed pages.
This also results in much less locking contention and a trylock free MM shrinker callback, so we can guarantee that pages are given back to the system when needed.
Downside of this is that it takes longer for many small allocations until the pool is filled up. We could address this, but I couldn't find an use case where this actually matters. And we don't bother freeing large chunks of pages any more.
The sysfs files are replaced with a single module parameter, allowing users to override how many pages should be globally pooled in TTM. This unfortunately breaks the UAPI slightly, but as far as we know nobody ever depended on this.
Zeroing memory coming from the pool was handled inconsistently. The
alloc_pages()based pool was zeroing it, thedma_alloc_attr()based one wasn't. The new implementation isn't zeroing pages from the pool either and only sets the__GFP_ZEROflag when necessary.
Quoted 6 lines
The implementation has only 753 lines of code compared to the over 2600 of the old one, and also allows for saving quite a bunch of code in the drivers since we don't need specialized handling there any more based on kernel config.
Additional to all of that there was a neat bug with IOMMU, coherent DMA mappings and huge pages which is now fixed in the new code as well.
Let me give a test your patch set in my renoir and new vangogh platform with iommu enabled. (I actually encountered many page faults in legacy ttm_page_alloc_dma implementation with swiotlb=1)
Thanks,
Ray
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel