ttm: merge ttm_backend & ttm_tt, introduce ttm dma allocator V5
Subsystems (10)
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting. Last patch fix memory accounting for radeon & nouveau. I think it's ready to go into drm-next, patchset is against linus tree as there is thing there not in next that conflict. (in radeon iirc)
Cheers,
Jerome
PATCH 1/14 swiotlb: Expose swiotlb_nr_tlb function to modules
From: Konrad Rzeszutek Wilk <[email protected]>
As a mechanism to detect whether SWIOTLB is enabled or not. We also fix the spelling - it was swioltb instead of swiotlb.
--- drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 2 +- lib/swiotlb.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-)
drivers/xen/swiotlb-xen.c +1 -1
@@ -153,7 +153,7 @@ void __init xen_swiotlb_init(int verbose)char *m =NULL ;unsigned int repeat =3 ; - nr_tbl =swioltb_nr_tbl (); + nr_tbl =swiotlb_nr_tbl ();if (nr_tbl) xen_io_tlb_nslabs = nr_tbl;else {
include/linux/swiotlb.h +1 -1
@@ -24,7 +24,7 @@ extern int swiotlb_force;extern void swiotlb_init (int verbose);extern void swiotlb_init_with_tbl (char *tlb,unsigned long nslabs,int verbose); -extern unsigned long swioltb_nr_tbl (void ); +extern unsigned long swiotlb_nr_tbl (void );/* * Enumeration for sync targets
lib/swiotlb.c +3 -2
@@ -110,11 +110,11 @@ setup_io_tlb_npages(char *str)__setup ("swiotlb=" , setup_io_tlb_npages);/* make io_tlb_overflow tunable too? */ -unsigned long swioltb_nr_tbl (void ) +unsigned long swiotlb_nr_tbl (void ) {return io_tlb_nslabs; } - +EXPORT_SYMBOL_GPL (swiotlb_nr_tbl);/* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address)
@@ -321,6 +321,7 @@ void __init swiotlb_free(void)free_bootmem_late (__pa (io_tlb_start),PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT )); } + io_tlb_nslabs =0 ; }static int is_swiotlb_buffer (phys_addr_t paddr)
Signature · 1 line
1.7.7.1
PATCH 2/14 drm/ttm: remove userspace backed ttm object support
In reply to [email protected]From: Jerome Glisse <[email protected]>
This was never use in none of the driver, properly using userspace page for bo would need more code (vma interaction mostly). Removing this dead code in preparation of ttm_tt & backend merge.
--- drivers/gpu/drm/ttm/ttm_bo.c | 22 -------- drivers/gpu/drm/ttm/ttm_tt.c | 105 +-------------------------------------- include/drm/ttm/ttm_bo_api.h | 5 -- include/drm/ttm/ttm_bo_driver.h | 24 --------- 4 files changed, 1 insertions(+), 155 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -22
@@ -342,22 +342,6 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc)if (unlikely (bo->ttm ==NULL )) ret = -ENOMEM ;break ; -case ttm_bo_type_user: - bo->ttm =ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , - page_flags |TTM_PAGE_FLAG_USER , - glob->dummy_read_page); -if (unlikely (bo->ttm ==NULL )) { - ret = -ENOMEM ; -break ; - } - - ret =ttm_tt_set_user (bo->ttm, current, - bo->buffer_start, bo->num_pages); -if (unlikely (ret !=0 )) { -ttm_tt_destroy (bo->ttm); - bo->ttm =NULL ; - } -break ;default : printk(KERN_ERR TTM_PFX "Illegal buffer object type\n"); ret = -EINVAL ;
@@ -907,16 +891,12 @@ static uint32_t ttm_bo_select_caching(struct ttm_mem_type_manager *man, }static bool ttm_bo_mt_compatible (struct ttm_mem_type_manager *man, -bool disallow_fixed,uint32_t mem_type,uint32_t proposed_placement,uint32_t *masked_placement) {uint32_t cur_flags =ttm_bo_type_flags (mem_type); -if ((man->flags &TTM_MEMTYPE_FLAG_FIXED ) && disallow_fixed) -return false; -if ((cur_flags & proposed_placement &TTM_PL_MASK_MEM ) ==0 )return false;
@@ -961,7 +941,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, man = &bdev->man[mem_type]; type_ok =ttm_bo_mt_compatible (man, - bo->type == ttm_bo_type_user, mem_type, placement->placement[i], &cur_flags);
@@ -1009,7 +988,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,if (!man->has_type)continue ;if (!ttm_bo_mt_compatible (man, - bo->type == ttm_bo_type_user, mem_type, placement->busy_placement[i], &cur_flags))
drivers/gpu/drm/ttm/ttm_tt.c +1 -104
141 lines not on this page · raw message
include/drm/ttm/ttm_bo_api.h +0 -5
@@ -122,17 +122,12 @@ struct ttm_mem_reg {* be mmapped by user space. Each of these bos occupy a slot in the * device address space, that can be used for normal vm operations. * -* @ttm_bo_type_user: These are user-space memory areas that are made -* available to the GPU by mapping the buffer pages into the GPU aperture -* space. These buffers cannot be mmaped from the device address space. -* * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, * but they cannot be accessed from user-space. For kernel-only use. */ enum ttm_bo_type { ttm_bo_type_device, - ttm_bo_type_user, ttm_bo_type_kernel };
include/drm/ttm/ttm_bo_driver.h +0 -24
@@ -118,8 +118,6 @@ struct ttm_backend {struct ttm_backend_func *func; }; -#define TTM_PAGE_FLAG_USER (1 << 1) -#define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)#define TTM_PAGE_FLAG_WRITE (1 << 3)#define TTM_PAGE_FLAG_SWAPPED (1 << 4)#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
@@ -146,8 +144,6 @@ enum ttm_caching_state {* @num_pages: Number of pages in the page array. * @bdev: Pointer to the current struct ttm_bo_device. * @be: Pointer to the ttm backend. -* @tsk: The task for user ttm. -* @start: virtual address for user ttm. * @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.
@@ -167,8 +163,6 @@ struct ttm_tt {unsigned long num_pages;struct ttm_bo_global *glob;struct ttm_backend *be; -struct task_struct *tsk; -unsigned long start;struct file *swap_storage;enum ttm_caching_state caching_state;enum {
@@ -618,24 +612,6 @@ extern struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, struct page *dummy_read_page);/** -* ttm_tt_set_user: -* -* @ttm: The struct ttm_tt to populate. -* @tsk: A struct task_struct for which @start is a valid user-space address. -* @start: A valid user-space address. -* @num_pages: Size in pages of the user memory area. -* -* Populate a struct ttm_tt with a user-space memory area after first pinning -* the pages backing it. -* Returns: -* !0: Error. -*/ - -extern int ttm_tt_set_user (struct ttm_tt *ttm, -struct task_struct *tsk, -unsigned long start,unsigned long num_pages); - -/** * ttm_ttm_bind: * * @ttm: The struct ttm_tt containing backing pages.
Signature · 1 line
1.7.7.1
PATCH 3/14 drm/ttm: remove split btw highmen and lowmem page
In reply to [email protected]From: Jerome Glisse <[email protected]>
Split btw highmem and lowmem page was rendered useless by the pool code. Remove it. Note further cleanup would change the ttm page allocation helper to actualy take an array instead of relying on list this could drasticly reduce the number of function call in the common case of allocation whole buffer.
--- drivers/gpu/drm/ttm/ttm_tt.c | 11 ++--------- include/drm/ttm/ttm_bo_driver.h | 7 ------- 2 files changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -9
@@ -70,7 +70,7 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index)struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;int ret; -while (NULL == (p = ttm->pages[index])) { +if (NULL == (p = ttm->pages[index])) {INIT_LIST_HEAD (&h);
@@ -86,10 +86,7 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index)if (unlikely (ret !=0 )) goto out_err; -if (PageHighMem (p)) - ttm->pages[--ttm->first_himem_page] = p; -else - ttm->pages[++ttm->last_lomem_page] = p; + ttm->pages[index] = p; }return p; out_err:
@@ -271,8 +268,6 @@ static void ttm_tt_free_alloced_pages(struct ttm_tt *ttm)ttm_put_pages (&h, count, ttm->page_flags, ttm->caching_state, ttm->dma_address); ttm->state = tt_unpopulated; - ttm->first_himem_page = ttm->num_pages; - ttm->last_lomem_page =-1 ; }void ttm_tt_destroy (struct ttm_tt *ttm)
@@ -316,8 +311,6 @@ struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, ttm->glob = bdev->glob; ttm->num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - ttm->first_himem_page = ttm->num_pages; - ttm->last_lomem_page =-1 ; ttm->caching_state = tt_cached; ttm->page_flags = page_flags;
include/drm/ttm/ttm_bo_driver.h +0 -7
@@ -136,11 +136,6 @@ enum ttm_caching_state {* @dummy_read_page: Page to map where the ttm_tt page array contains a NULL * pointer. * @pages: Array of pages backing the data. -* @first_himem_page: Himem pages are put last in the page array, which -* enables us to run caching attribute changes on only the first part -* of the page array containing lomem pages. This is the index of the -* first himem page. -* @last_lomem_page: Index of the last lomem page in the page array. * @num_pages: Number of pages in the page array. * @bdev: Pointer to the current struct ttm_bo_device. * @be: Pointer to the ttm backend.
@@ -157,8 +152,6 @@ enum ttm_caching_state {struct ttm_tt {struct page *dummy_read_page;struct page **pages; -long first_himem_page; -long last_lomem_page;uint32_t page_flags;unsigned long num_pages;struct ttm_bo_global *glob;
Signature · 1 line
1.7.7.1
PATCH 4/14 drm/ttm: remove unused backend flags field
In reply to [email protected]From: Jerome Glisse <[email protected]>
This field is not use by any of the driver just drop it.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 1 - include/drm/ttm/ttm_bo_driver.h | 2 -- 2 files changed, 0 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +0 -1
@@ -787,7 +787,6 @@ struct ttm_backend *radeon_ttm_backend_create(struct radeon_device *rdev)return NULL ; } gtt->backend.bdev = &rdev->mman.bdev; - gtt->backend.flags =0 ; gtt->backend.func = &radeon_backend_func; gtt->rdev = rdev; gtt->pages =NULL ;
include/drm/ttm/ttm_bo_driver.h +0 -2
@@ -106,7 +106,6 @@ struct ttm_backend_func {* struct ttm_backend * * @bdev: Pointer to a struct ttm_bo_device. -* @flags: For driver use. * @func: Pointer to a struct ttm_backend_func that describes * the backend methods. *
@@ -114,7 +113,6 @@ struct ttm_backend_func {struct ttm_backend {struct ttm_bo_device *bdev; -uint32_t flags;struct ttm_backend_func *func; };
Signature · 1 line
1.7.7.1
PATCH 5/14 drm/ttm: use ttm put pages function to properly restore cache attribute
In reply to [email protected]From: Jerome Glisse <[email protected]>
On failure we need to make sure the page we free has wb cache attribute. Do this pas call the proper ttm page helper function.
--- drivers/gpu/drm/ttm/ttm_tt.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +4 -1
@@ -90,7 +90,10 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index) }return p; out_err: -put_page (p); +INIT_LIST_HEAD (&h); +list_add (&p->lru, &h); +ttm_put_pages (&h,1 , ttm->page_flags, + ttm->caching_state, &ttm->dma_address[index]);return NULL ; }
Signature · 1 line
1.7.7.1
PATCH 6/14 drm/ttm: test for dma_address array allocation failure
In reply to [email protected]From: Jerome Glisse <[email protected]>
--- drivers/gpu/drm/ttm/ttm_tt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +1 -1
@@ -320,7 +320,7 @@ struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, ttm->dummy_read_page = dummy_read_page;ttm_tt_alloc_page_directory (ttm); -if (!ttm->pages) { +if (!ttm->pages || !ttm->dma_address) {ttm_tt_destroy (ttm); printk(KERN_ERR TTM_PFX "Failed allocating page table\n");return NULL ;
Signature · 1 line
1.7.7.1
PATCH 7/14 drm/ttm: page allocation use page array instead of list
In reply to [email protected]From: Jerome Glisse <[email protected]>
Use the ttm_tt pages array for pages allocations, move the list unwinding into the page allocation functions.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 85 +++++++++++++++++++++------------- drivers/gpu/drm/ttm/ttm_tt.c | 36 +++------------ include/drm/ttm/ttm_page_alloc.h | 8 ++-- 3 files changed, 63 insertions(+), 66 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +52 -33
@@ -619,8 +619,10 @@ static void ttm_page_pool_fill_locked(struct ttm_page_pool *pool,* @return count of pages still required to fulfill the request. */ static unsigned ttm_page_pool_get_pages (struct ttm_page_pool *pool, -struct list_head *pages,int ttm_flags, -enum ttm_caching_state cstate,unsigned count) +struct list_head *pages, +int ttm_flags, +enum ttm_caching_state cstate, +unsigned count) {unsigned long irq_flags;struct list_head *p;
@@ -664,13 +666,15 @@ out:* On success pages list will hold count number of correctly * cached pages. */ -int ttm_get_pages (struct list_head *pages,int flags, -enum ttm_caching_state cstate,unsigned count, +int ttm_get_pages (struct page **pages,int flags, +enum ttm_caching_state cstate,unsigned npages,dma_addr_t *dma_address) {struct ttm_page_pool *pool =ttm_get_pool (flags, cstate); +struct list_head plist;struct page *p =NULL ;gfp_t gfp_flags =GFP_USER ; +unsigned count;int r;/* set zero flag for page allocation if required */
@@ -684,7 +688,7 @@ int ttm_get_pages(struct list_head *pages, int flags,else gfp_flags |=GFP_HIGHUSER ; -for (r =0 ; r < count; ++r) { +for (r =0 ; r < npages; ++r) { p =alloc_page (gfp_flags);if (!p) {
@@ -693,85 +697,100 @@ int ttm_get_pages(struct list_head *pages, int flags,return -ENOMEM ; } -list_add (&p->lru, pages); + pages[r] = p; }return 0 ; } -/* combine zero flag to pool flags */ gfp_flags |= pool->gfp_flags;/* First we take pages from the pool */ - count =ttm_page_pool_get_pages (pool, pages, flags, cstate, count); +INIT_LIST_HEAD (&plist); + npages =ttm_page_pool_get_pages (pool, &plist, flags, cstate, npages); + count =0 ; +list_for_each_entry (p, &plist, lru) { + pages[count++] = p; + }/* clear the pages coming from the pool if requested */ if (flags &TTM_PAGE_FLAG_ZERO_ALLOC ) { -list_for_each_entry (p, pages, lru) { +list_for_each_entry (p, &plist, lru) {clear_page (page_address (p)); } }/* If pool didn't have enough pages allocate new one. */ -if (count >0 ) { +if (npages >0 ) {/* ttm_alloc_new_pages doesn't reference pool so we can run * multiple requests in parallel. **/ - r =ttm_alloc_new_pages (pages, gfp_flags, flags, cstate, count); +INIT_LIST_HEAD (&plist); + r =ttm_alloc_new_pages (&plist, gfp_flags, flags, cstate, npages); +list_for_each_entry (p, &plist, lru) { + pages[count++] = p; + }if (r) {/* If there is any pages in the list put them back to * the pool. */ printk(KERN_ERR TTM_PFX"Failed to allocate extra pages " "for large request."); -ttm_put_pages (pages,0 , flags, cstate,NULL ); +ttm_put_pages (pages, count, flags, cstate,NULL );return r; } } -return 0 ; }/* Put all pages in pages list to correct pool to wait for reuse */ -void ttm_put_pages (struct list_head *pages,unsigned page_count,int flags, +void ttm_put_pages (struct page **pages,unsigned npages,int flags,enum ttm_caching_state cstate,dma_addr_t *dma_address) {unsigned long irq_flags;struct ttm_page_pool *pool =ttm_get_pool (flags, cstate); -struct page *p, *tmp; +unsigned i;if (pool ==NULL ) {/* No pool for this memory type so free the pages */ - -list_for_each_entry_safe (p, tmp, pages, lru) { -__free_page (p); +for (i =0 ; i < npages; i++) { +if (pages[i]) { +if (page_count (pages[i]) !=1 ) + printk(KERN_ERR TTM_PFX +"Erroneous page count. " +"Leaking pages.\n" ); +__free_page (pages[i]); + pages[i] =NULL ; + } } -/* Make the pages list empty */ -INIT_LIST_HEAD (pages);return ; } -if (page_count ==0 ) { -list_for_each_entry_safe (p, tmp, pages, lru) { - ++page_count; - } - }spin_lock_irqsave (&pool->lock, irq_flags); -list_splice_init (pages, &pool->list); - pool->npages += page_count; +for (i =0 ; i < npages; i++) { +if (pages[i]) { +if (page_count (pages[i]) !=1 ) + printk(KERN_ERR TTM_PFX +"Erroneous page count. " +"Leaking pages.\n" ); +list_add_tail (&pages[i]->lru, &pool->list); + pages[i] =NULL ; + pool->npages++; + } + }/* Check that we don't go over the pool limit */ - page_count =0 ; + npages =0 ;if (pool->npages > _manager->options.max_size) { - page_count = pool->npages - _manager->options.max_size; + npages = pool->npages - _manager->options.max_size;/* free at least NUM_PAGES_TO_ALLOC number of pages * to reduce calls to set_memory_wb */ -if (page_count <NUM_PAGES_TO_ALLOC ) - page_count =NUM_PAGES_TO_ALLOC ; +if (npages <NUM_PAGES_TO_ALLOC ) + npages =NUM_PAGES_TO_ALLOC ; }spin_unlock_irqrestore (&pool->lock, irq_flags); -if (page_count) -ttm_page_pool_free (pool, page_count); +if (npages) +ttm_page_pool_free (pool, npages); } static void ttm_page_pool_init_locked(struct ttm_page_pool *pool, int flags,
drivers/gpu/drm/ttm/ttm_tt.c +7 -29
@@ -66,22 +66,16 @@ static void ttm_tt_free_page_directory(struct ttm_tt *ttm)static struct page *__ttm_tt_get_page (struct ttm_tt *ttm,int index) {struct page *p; -struct list_head h;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;int ret;if (NULL == (p = ttm->pages[index])) { -INIT_LIST_HEAD (&h); - - ret =ttm_get_pages (&h, ttm->page_flags, ttm->caching_state,1 , + ret =ttm_get_pages (&p, ttm->page_flags, ttm->caching_state,1 , &ttm->dma_address[index]); -if (ret !=0 )return NULL ; - p = list_first_entry(&h, struct page, lru); - ret =ttm_mem_global_alloc_page (mem_glob, p, false, false);if (unlikely (ret !=0 )) goto out_err;
@@ -90,9 +84,7 @@ static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index) }return p; out_err: -INIT_LIST_HEAD (&h); -list_add (&p->lru, &h); -ttm_put_pages (&h,1 , ttm->page_flags, +ttm_put_pages (&p,1 , ttm->page_flags, ttm->caching_state, &ttm->dma_address[index]);return NULL ; }
@@ -243,33 +235,19 @@ EXPORT_SYMBOL(ttm_tt_set_placement_caching);static void ttm_tt_free_alloced_pages (struct ttm_tt *ttm) { -int i; -unsigned count =0 ; -struct list_head h; -struct page *cur_page;struct ttm_backend *be = ttm->be; - -INIT_LIST_HEAD (&h); +unsigned i;if (be) be->func->clear (be);for (i =0 ; i < ttm->num_pages; ++i) { - - cur_page = ttm->pages[i]; - ttm->pages[i] =NULL ; -if (cur_page) { -if (page_count (cur_page) !=1 ) - printk(KERN_ERR TTM_PFX -"Erroneous page count. " -"Leaking pages.\n" ); +if (ttm->pages[i]) {ttm_mem_global_free_page (ttm->glob->mem_glob, - cur_page); -list_add (&cur_page->lru, &h); - count++; + ttm->pages[i]); +ttm_put_pages (&ttm->pages[i],1 , ttm->page_flags, + ttm->caching_state, &ttm->dma_address[i]); } } -ttm_put_pages (&h, count, ttm->page_flags, ttm->caching_state, - ttm->dma_address); ttm->state = tt_unpopulated; }
include/drm/ttm/ttm_page_alloc.h +4 -4
@@ -38,10 +38,10 @@* @count: number of pages to allocate. * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). */ -int ttm_get_pages (struct list_head *pages, +int ttm_get_pages (struct page **pages,int flags,enum ttm_caching_state cstate, -unsigned count, +unsigned npages,dma_addr_t *dma_address);/** * Put linked list of pages to pool.
@@ -53,8 +53,8 @@ int ttm_get_pages(struct list_head *pages,* @cstate: ttm caching state. * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). */ -void ttm_put_pages (struct list_head *pages, -unsigned page_count, +void ttm_put_pages (struct page **pages, +unsigned npages,int flags,enum ttm_caching_state cstate,dma_addr_t *dma_address);
Signature · 1 line
1.7.7.1
PATCH 8/14 drm/ttm: merge ttm_backend and ttm_tt V5
In reply to [email protected]From: Jerome Glisse <[email protected]>
ttm_backend will only exist with a ttm_tt, and ttm_tt will only be of interest when bound to a backend. Merge them to avoid code and data duplication.
V2 Rebase on top of memory accounting overhaul
V3 Rebase on top of more memory accounting changes
V4 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
V5 make sure ttm is unbound before destroying, change commit
message on suggestion from Tormod Volden
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 14 ++- drivers/gpu/drm/nouveau/nouveau_drv.h | 5 +- drivers/gpu/drm/nouveau/nouveau_sgdma.c | 188 ++++++++++++--------------- drivers/gpu/drm/radeon/radeon_ttm.c | 219 ++++++++++++------------------- drivers/gpu/drm/ttm/ttm_agp_backend.c | 88 +++++-------- drivers/gpu/drm/ttm/ttm_bo.c | 9 +- drivers/gpu/drm/ttm/ttm_tt.c | 59 ++------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 66 +++------- include/drm/ttm/ttm_bo_driver.h | 104 ++++++--------- 9 files changed, 294 insertions(+), 458 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +9 -5
@@ -343,8 +343,10 @@ nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val) *mem = val; } -static struct ttm_backend * -nouveau_bo_create_ttm_backend_entry (struct ttm_bo_device *bdev) +static struct ttm_tt * +nouveau_ttm_tt_create (struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page) {struct drm_nouveau_private *dev_priv =nouveau_bdev (bdev);struct drm_device *dev = dev_priv->dev;
@@ -352,11 +354,13 @@ nouveau_bo_create_ttm_backend_entry(struct ttm_bo_device *bdev)switch (dev_priv->gart_info.type) {#if __OS_HAS_AGPcase NOUVEAU_GART_AGP : -return ttm_agp_backend_init (bdev, dev->agp->bridge); +return ttm_agp_tt_create (bdev, dev->agp->bridge, + size, page_flags, dummy_read_page);#endif case NOUVEAU_GART_PDMA :case NOUVEAU_GART_HW : -return nouveau_sgdma_init_ttm (dev); +return nouveau_sgdma_create_ttm (bdev, size, page_flags, + dummy_read_page);default :NV_ERROR (dev,"Unknown GART type %d\n" , dev_priv->gart_info.type);
@@ -1045,7 +1049,7 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) }struct ttm_bo_driver nouveau_bo_driver = { - .create_ttm_backend_entry = nouveau_bo_create_ttm_backend_entry, + .ttm_tt_create = &nouveau_ttm_tt_create, .invalidate_caches = nouveau_bo_invalidate_caches, .init_mem_type = nouveau_bo_init_mem_type, .evict_flags = nouveau_bo_evict_flags,
drivers/gpu/drm/nouveau/nouveau_drv.h +4 -1
@@ -1000,7 +1000,10 @@ extern int nouveau_sgdma_init(struct drm_device *);extern void nouveau_sgdma_takedown (struct drm_device *);extern uint32_t nouveau_sgdma_get_physical (struct drm_device *,uint32_t offset); -extern struct ttm_backend *nouveau_sgdma_init_ttm (struct drm_device *); +extern struct ttm_tt *nouveau_sgdma_create_ttm (struct ttm_bo_device *bdev, +unsigned long size, +uint32_t page_flags, +struct page *dummy_read_page);/* nouveau_debugfs.c */ #if defined(CONFIG_DRM_NOUVEAU_DEBUG )
drivers/gpu/drm/nouveau/nouveau_sgdma.c +85 -103
376 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_ttm.c +83 -136
238 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_agp_backend.c +34 -54
139 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo.c +3 -6
@@ -337,8 +337,8 @@ static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc)if (zero_alloc) page_flags |=TTM_PAGE_FLAG_ZERO_ALLOC ;case ttm_bo_type_kernel: - bo->ttm =ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , - page_flags, glob->dummy_read_page); + bo->ttm = bdev->driver->ttm_tt_create (bdev, bo->num_pages <<PAGE_SHIFT , + page_flags, glob->dummy_read_page);if (unlikely (bo->ttm ==NULL )) ret = -ENOMEM ;break ;
@@ -1437,10 +1437,7 @@ int ttm_bo_global_init(struct drm_global_reference *ref) goto out_no_shrink; } - glob->ttm_bo_extra_size = -ttm_round_pot (sizeof (struct ttm_tt )) + -ttm_round_pot (sizeof (struct ttm_backend )); - + glob->ttm_bo_extra_size =ttm_round_pot (sizeof (struct ttm_tt )); glob->ttm_bo_size = glob->ttm_bo_extra_size +ttm_round_pot (sizeof (struct ttm_buffer_object ));
drivers/gpu/drm/ttm/ttm_tt.c +14 -45
140 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +21 -45
113 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +41 -63
186 lines not on this page · raw message
Signature · 1 line
1.7.7.1
PATCH 9/14 drm/ttm: introduce callback for ttm_tt populate & unpopulate V4
In reply to [email protected]From: Jerome Glisse <[email protected]>
Move the page allocation and freeing to driver callback and provide ttm code helper function for those.
Most intrusive change, is the fact that we now only fully populate an object this simplify some of code designed around the page fault design.
V2 Rebase on top of memory accounting overhaul
V3 New rebase on top of more memory accouting changes V4 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 2 + drivers/gpu/drm/ttm/ttm_bo_util.c | 31 ++++++----- drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 +++- drivers/gpu/drm/ttm/ttm_page_alloc.c | 57 ++++++++++++++++++++ drivers/gpu/drm/ttm/ttm_tt.c | 91 ++------------------------------ drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 3 + include/drm/ttm/ttm_bo_driver.h | 41 ++++++++------ include/drm/ttm/ttm_page_alloc.h | 18 ++++++ 9 files changed, 135 insertions(+), 120 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +3 -0
@@ -28,6 +28,7 @@*/ #include "drmP.h" +#include "ttm/ttm_page_alloc.h" #include "nouveau_drm.h" #include "nouveau_drv.h"
@@ -1050,6 +1051,8 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)struct ttm_bo_driver nouveau_bo_driver = { .ttm_tt_create = &nouveau_ttm_tt_create, + .ttm_tt_populate = &ttm_pool_populate, + .ttm_tt_unpopulate = &ttm_pool_unpopulate, .invalidate_caches = nouveau_bo_invalidate_caches, .init_mem_type = nouveau_bo_init_mem_type, .evict_flags = nouveau_bo_evict_flags,
drivers/gpu/drm/radeon/radeon_ttm.c +2 -0
@@ -581,6 +581,8 @@ struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,static struct ttm_bo_driver radeon_bo_driver = { .ttm_tt_create = &radeon_ttm_tt_create, + .ttm_tt_populate = &ttm_pool_populate, + .ttm_tt_unpopulate = &ttm_pool_unpopulate, .invalidate_caches = &radeon_invalidate_caches, .init_mem_type = &radeon_init_mem_type, .evict_flags = &radeon_evict_flags,
drivers/gpu/drm/ttm/ttm_bo_util.c +17 -14
@@ -244,7 +244,7 @@ static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, unsigned long page, pgprot_t prot) { -struct page *d =ttm_tt_get_page (ttm, page); +struct page *d = ttm->pages[page];void *dst;if (!d)
@@ -281,7 +281,7 @@ static int ttm_copy_ttm_io_page(struct ttm_tt *ttm, void *dst, unsigned long page, pgprot_t prot) { -struct page *s =ttm_tt_get_page (ttm, page); +struct page *s = ttm->pages[page];void *src;if (!s)
@@ -342,6 +342,12 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,if (old_iomap ==NULL && ttm ==NULL ) goto out2; +if (ttm->state == tt_unpopulated) { + ret = ttm->bdev->driver->ttm_tt_populate (ttm); +if (ret) + goto out1; + } + add =0 ; dir =1 ;
@@ -502,10 +508,16 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, {struct ttm_mem_reg *mem = &bo->mem;pgprot_t prot;struct ttm_tt *ttm = bo->ttm; -struct page *d; -int i; +int ret;BUG_ON (!ttm); + +if (ttm->state == tt_unpopulated) { + ret = ttm->bdev->driver->ttm_tt_populate (ttm); +if (ret) +return ret; + } +if (num_pages ==1 && (mem->placement &TTM_PL_FLAG_CACHED )) {/* * We're mapping a single page, and the desired
@@ -513,18 +525,9 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,*/ map->bo_kmap_type = ttm_bo_map_kmap; - map->page =ttm_tt_get_page (ttm, start_page); + map->page = ttm->pages[start_page]; map->virtual =kmap (map->page); }else { -/* -* Populate the part we're mapping; -*/ -for (i = start_page; i < start_page + num_pages; ++i) { - d =ttm_tt_get_page (ttm, i); -if (!d) -return -ENOMEM ; - } -/* * We need to use vmap to get the desired page protection * or to make the buffer object look contiguous.
drivers/gpu/drm/ttm/ttm_bo_vm.c +7 -2
@@ -174,18 +174,23 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) vma->vm_page_prot = (bo->mem.placement &TTM_PL_FLAG_CACHED ) ?vm_get_page_prot (vma->vm_flags) :ttm_io_prot (bo->mem.placement, vma->vm_page_prot); + +/* Allocate all page at once, most common usage */ +if (ttm->bdev->driver->ttm_tt_populate (ttm)) { + retval =VM_FAULT_OOM ; + goto out_io_unlock; + } }/* * Speculatively prefault a number of pages. Only error on * first page. */ -for (i =0 ; i <TTM_BO_VM_NUM_PREFAULT ; ++i) {if (bo->mem.bus.is_iomem) pfn = ((bo->mem.bus.base + bo->mem.bus.offset) >>PAGE_SHIFT ) + page_offset;else { - page =ttm_tt_get_page (ttm, page_offset); + page = ttm->pages[page_offset];if (unlikely (!page && i ==0 )) { retval =VM_FAULT_OOM ; goto out_io_unlock;
drivers/gpu/drm/ttm/ttm_page_alloc.c +57 -0
63 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +5 -86
145 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +3 -0
@@ -28,6 +28,7 @@#include "vmwgfx_drv.h" #include "ttm/ttm_bo_driver.h" #include "ttm/ttm_placement.h" +#include "ttm/ttm_page_alloc.h" static uint32_t vram_placement_flags =TTM_PL_FLAG_VRAM |TTM_PL_FLAG_CACHED ;
@@ -334,6 +335,8 @@ static int vmw_sync_obj_wait(void *sync_obj, void *sync_arg,struct ttm_bo_driver vmw_bo_driver = { .ttm_tt_create = &vmw_ttm_tt_create, + .ttm_tt_populate = &ttm_pool_populate, + .ttm_tt_unpopulate = &ttm_pool_unpopulate, .invalidate_caches = vmw_invalidate_caches, .init_mem_type = vmw_init_mem_type, .evict_flags = vmw_evict_flags,
include/drm/ttm/ttm_bo_driver.h +23 -18
63 lines not on this page · raw message
include/drm/ttm/ttm_page_alloc.h +18 -0
@@ -68,6 +68,24 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);void ttm_page_alloc_fini (void );/** +* ttm_pool_populate: +* +* @ttm: The struct ttm_tt to contain the backing pages. +* +* Add backing pages to all of @ttm +*/ +extern int ttm_pool_populate (struct ttm_tt *ttm); + +/** +* ttm_pool_unpopulate: +* +* @ttm: The struct ttm_tt which to free backing pages. +* +* Free all pages of @ttm +*/ +extern void ttm_pool_unpopulate (struct ttm_tt *ttm); + +/** * Output the state of pools to debugfs file */ extern int ttm_page_alloc_debugfs (struct seq_file *m,void *data);
Signature · 1 line
1.7.7.1
PATCH 10/14 drm/ttm: provide dma aware ttm page pool code V8
In reply to [email protected]From: Konrad Rzeszutek Wilk <[email protected]>
In TTM world the pages for the graphic drivers are kept in three different
pools: write combined, uncached, and cached (write-back). When the pages are used by the graphic driver the graphic adapter via its built in MMU (or AGP) programs these pages in. The programming requires the virtual address (from the graphic adapter perspective) and the physical address (either System RAM or the memory on the card) which is obtained using the pci_map_* calls (which does the virtual to physical - or bus address translation). During the graphic application's "life" those pages can be shuffled around, swapped out to disk, moved from the VRAM to System RAM or vice-versa. This all works with the existing TTM pool code
- except when we want to use the software IOTLB (SWIOTLB) code to "map" the physical addresses to the graphic adapter MMU. We end up programming the bounce buffer's physical address instead of the TTM pool memory's and get a non-worky driver. There are two solutions:
1) using the DMA API to allocate pages that are screened by the DMA API, or
2) using the pci_sync_* calls to copy the pages from the bounce-buffer and back.
This patch fixes the issue by allocating pages using the DMA API. The second is a viable option - but it has performance drawbacks and potential correctness issues - think of the write cache page being bounced (SWIOTLB->TTM), the WC is set on the TTM page and the copy from SWIOTLB not making it to the TTM page until the page has been recycled in the pool (and used by another application).
The bounce buffer does not get activated often - only in cases where we have a 32-bit capable card and we want to use a page that is allocated above the 4GB limit. The bounce buffer offers the solution of copying the contents of that 4GB page to an location below 4GB and then back when the operation has been completed (or vice-versa). This is done by using the 'pci_sync_*' calls.
Note: If you look carefully enough in the existing TTM page pool code you will notice the GFP_DMA32 flag is used - which should guarantee that the provided page is under 4GB. It certainly is the case, except this gets ignored in two cases:
- If user specifies 'swiotlb=force' which bounces _every_ page.
- If user is using a Xen's PV Linux guest (which uses the SWIOTLB and the underlaying PFN's aren't necessarily under 4GB).
To not have this extra copying done the other option is to allocate the pages using the DMA API so that there is not need to map the page and perform the expensive 'pci_sync_*' calls.
This DMA API capable TTM pool requires for this the 'struct device' to properly call the DMA API. It also has to track the virtual and bus address of the page being handed out in case it ends up being swapped out or de-allocated - to make sure it is de-allocated using the proper's 'struct device'.
Implementation wise the code keeps two lists: one that is attached to the 'struct device' (via the dev->dma_pools list) and a global one to be used when the 'struct device' is unavailable (think shrinker code). The global list can iterate over all of the 'struct device' and its associated dma_pool. The list in dev->dma_pools can only iterate the device's dma_pool.
/[struct device_pool]\
/---------------------------------------------------| dev |
/ +-------| dma_pool |
/-----+------\ / \--------------------/
|struct device| /-->[struct dma_pool for WC]</ /[struct device_pool]\
| dma_pools +----+ /-| dev |
| ... | \--->[struct dma_pool for uncached]<-/--| dma_pool |
\-----+------/ / \--------------------/
\----------------------------------------------/[Two pools associated with the device (WC and UC), and the parallel list containing the 'struct dev' and 'struct dma_pool' entries]
The maximum amount of dma pools a device can have is six: write-combined, uncached, and cached; then there are the DMA32 variants which are:
write-combined dma32, uncached dma32, and cached dma32.
Currently this code only gets activated when any variant of the SWIOTLB IOMMU code is running (Intel without VT-d, AMD without GART, IBM Calgary and Xen PV with PCI devices).
[v2: Major overhaul - added 'inuse_list' to seperate used from inuse and reorder the order of lists to get better performance.]
--- drivers/gpu/drm/ttm/Makefile | 4 + drivers/gpu/drm/ttm/ttm_memory.c | 2 + drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 1116 ++++++++++++++++++++++++++++++ drivers/gpu/drm/ttm/ttm_tt.c | 1 + include/drm/ttm/ttm_bo_driver.h | 2 + include/drm/ttm/ttm_page_alloc.h | 36 + 6 files changed, 1161 insertions(+), 0 deletions(-) create mode 100644 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
drivers/gpu/drm/ttm/Makefile +4 -0
@@ -7,4 +7,8 @@ ttm-y := ttm_agp_backend.o ttm_memory.o ttm_tt.o ttm_bo.o \ ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o \ ttm_bo_manager.o +ifeq ($(CONFIG_SWIOTLB),y) +ttm-y += ttm_page_alloc_dma.o +endif + obj-$(CONFIG_DRM_TTM) += ttm.o
drivers/gpu/drm/ttm/ttm_memory.c +2 -0
@@ -395,6 +395,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) 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 ));return 0 ; out_no_zone:ttm_mem_global_release (glob);
@@ -409,6 +410,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 ();flush_workqueue (glob->swap_queue);destroy_workqueue (glob->swap_queue);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +1116 -0
1,116 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_tt.c +1 -0
@@ -196,6 +196,7 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, ttm->dummy_read_page = dummy_read_page; ttm->state = tt_unpopulated; +INIT_LIST_HEAD (&ttm->alloc_list);ttm_tt_alloc_page_directory (ttm);if (!ttm->pages || !ttm->dma_address) {ttm_tt_destroy (ttm);
include/drm/ttm/ttm_bo_driver.h +2 -0
@@ -104,6 +104,7 @@ enum ttm_caching_state {* @caching_state: The current caching state of the pages. * @state: The current binding state of the pages. * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) +* @alloc_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)
@@ -127,6 +128,7 @@ struct ttm_tt { tt_unpopulated, } state;dma_addr_t *dma_address; +struct list_head alloc_list; };#define TTM_MEMTYPE_FLAG_FIXED (1 << 0)/* Fixed (on-card) PCI memory */
include/drm/ttm/ttm_page_alloc.h +36 -0
@@ -89,4 +89,40 @@ extern void ttm_pool_unpopulate(struct ttm_tt *ttm);* Output the state of pools to debugfs file */ extern int ttm_page_alloc_debugfs (struct seq_file *m,void *data); + + +#ifdef CONFIG_SWIOTLB +/** +* Initialize pool allocator. +*/ +int ttm_dma_page_alloc_init (struct ttm_mem_global *glob,unsigned max_pages); + +/** +* Free pool allocator. +*/ +void ttm_dma_page_alloc_fini (void ); + +/** +* Output the state of pools to debugfs file +*/ +extern int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); + +int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev); +extern void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev); + +#else +static inline int ttm_dma_page_alloc_init (struct ttm_mem_global *glob, +unsigned max_pages) +{ +return -ENODEV ; +} + +static inline void ttm_dma_page_alloc_fini (void ) {return ; } + +static inline int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data) +{ +return 0 ; +} +#endif +#endif
Signature · 6 lines
1.7.7.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 10/14] drm/ttm: provide dma aware ttm page pool code V8
Quoted 2 lines
(quoted diff) +2
-0+int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev) +{
.. snip..
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c line 894
Quoted 9 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +9
-0+for (i =0 ; i < ttm->num_pages; ++i) { + ret =ttm_dma_pool_get_pages (pool, ttm, i); +if (ret !=0 ) { +ttm_dma_unpopulate (ttm, dev); +return -ENOMEM ; + } + + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], + false, false);
Ok, so we increment it here..
.. snip..
Quoted 26 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +26
-0+void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev) +{ +struct dma_pool *pool; +struct dma_page *d_page; +enum pool_type type; +bool is_cached = false; +unsigned count =0 , i; +unsigned long irq_flags; + + type =ttm_to_type (ttm->page_flags, ttm->caching_state); + pool =ttm_dma_find_pool (dev, type); +if (!pool) { +WARN_ON (!pool); +return ; + } + is_cached = (ttm_dma_find_pool (pool->dev, +ttm_to_type (ttm->page_flags, tt_cached)) == pool); + +/* make sure pages array match list and count number of pages */ +list_for_each_entry (d_page, &ttm->alloc_list, page_list) { + ttm->pages[count] = d_page->p; + count++; + } + +spin_lock_irqsave (&pool->lock, irq_flags); + pool->npages_in_use -= count;
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c line 965
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +10
-0+if (is_cached) { + pool->nfrees += count; + }else { + pool->npages_free += count; +list_splice (&ttm->alloc_list, &pool->free_list); +if (pool->npages_free > _manager->options.max_size) { + count = pool->npages_free - _manager->options.max_size; + } + } +spin_unlock_irqrestore (&pool->lock, irq_flags);
But we don't do it here. I think you need:
for (i = 0; i < ttm->num_pages; i++) {
ttm_mem_global_free_page(mem_glob, ttm->pages[i]);And it has to be done before ttm_dma_pages_put as at that point the pages are truly gone.
Could actually be done in the '/* make sure pages array match list .."
Quoted 11 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +11
-0+ +if (is_cached) { +ttm_dma_pages_put (pool, &ttm->alloc_list, + ttm->pages, count); + } + +INIT_LIST_HEAD (&ttm->alloc_list); +for (i =0 ; i < ttm->num_pages; i++) { + ttm->pages[i] =NULL ; + ttm->dma_address[i] =0 ; + }
Re: [PATCH 10/14] drm/ttm: provide dma aware ttm page pool code V8
Quoted 56 lines · Konrad Rzeszutek Wilk
Quoted 2 lines
(quoted diff) +2
-0+int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev) +{.. snip..
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c line 894
Quoted 9 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +9
-0+for (i =0 ; i < ttm->num_pages; ++i) { + ret =ttm_dma_pool_get_pages (pool, ttm, i); +if (ret !=0 ) { +ttm_dma_unpopulate (ttm, dev); +return -ENOMEM ; + } + + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], + false, false);Ok, so we increment it here..
.. snip..
Quoted 26 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +26
-0+void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev) +{ +struct dma_pool *pool; +struct dma_page *d_page; +enum pool_type type; +bool is_cached = false; +unsigned count =0 , i; +unsigned long irq_flags; + + type =ttm_to_type (ttm->page_flags, ttm->caching_state); + pool =ttm_dma_find_pool (dev, type); +if (!pool) { +WARN_ON (!pool); +return ; + } + is_cached = (ttm_dma_find_pool (pool->dev, +ttm_to_type (ttm->page_flags, tt_cached)) == pool); + +/* make sure pages array match list and count number of pages */ +list_for_each_entry (d_page, &ttm->alloc_list, page_list) { + ttm->pages[count] = d_page->p; + count++; + } + +spin_lock_irqsave (&pool->lock, irq_flags); + pool->npages_in_use -= count;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c line 965
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +10
-0+if (is_cached) { + pool->nfrees += count; + }else { + pool->npages_free += count; +list_splice (&ttm->alloc_list, &pool->free_list); +if (pool->npages_free > _manager->options.max_size) { + count = pool->npages_free - _manager->options.max_size; + } + } +spin_unlock_irqrestore (&pool->lock, irq_flags);But we don't do it here. I think you need:
Quoted 7 lines
for (i = 0; i < ttm->num_pages; i++) { ttm_mem_global_free_page(mem_glob, ttm->pages[i]);And it has to be done before
ttm_dma_pages_putas at that point the pages are truly gone.Could actually be done in the '/* make sure pages array match list .."
Actually to avoid the race you need to do it one page at a time. Will respin with that.
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c new file +11
-0+ +if (is_cached) { +ttm_dma_pages_put (pool, &ttm->alloc_list, + ttm->pages, count); + } + +INIT_LIST_HEAD (&ttm->alloc_list); +for (i =0 ; i < ttm->num_pages; i++) { + ttm->pages[i] =NULL ; + ttm->dma_address[i] =0 ; + }
PATCH 11/14 drm/radeon/kms: enable the ttm dma pool if swiotlb is on V3
In reply to [email protected]From: Konrad Rzeszutek Wilk <[email protected]>
With the exception that we do not handle the AGP case. We only deal with PCIe cards such as ATI ES1000 or HD3200 that have been detected to only do DMA up to 32-bits.
V2 force dma32 if we fail to set bigger dma mask
V3 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
--- drivers/gpu/drm/radeon/radeon.h | 1 - drivers/gpu/drm/radeon/radeon_device.c | 6 ++ drivers/gpu/drm/radeon/radeon_gart.c | 29 +----------- drivers/gpu/drm/radeon/radeon_ttm.c | 83 +++++++++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 35 deletions(-)
drivers/gpu/drm/radeon/radeon.h +0 -1
@@ -320,7 +320,6 @@ struct radeon_gart {unsigned table_size;struct page **pages;dma_addr_t *pages_addr; -bool *ttm_alloced;bool ready; };
drivers/gpu/drm/radeon/radeon_device.c +6 -0
@@ -765,8 +765,14 @@ int radeon_device_init(struct radeon_device *rdev, r =pci_set_dma_mask (rdev->pdev,DMA_BIT_MASK (dma_bits));if (r) { rdev->need_dma32 = true; + dma_bits =32 ;printk (KERN_WARNING "radeon: No suitable DMA available.\n" ); } + r =pci_set_consistent_dma_mask (rdev->pdev,DMA_BIT_MASK (dma_bits)); +if (r) { +pci_set_consistent_dma_mask (rdev->pdev,DMA_BIT_MASK (32 )); +printk (KERN_WARNING "radeon: No coherent DMA available.\n" ); + }/* Registers mapping */ /* TODO: block userspace mapping of io register */
drivers/gpu/drm/radeon/radeon_gart.c +1 -28
@@ -157,9 +157,6 @@ void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset, p = t / (PAGE_SIZE /RADEON_GPU_PAGE_SIZE );for (i =0 ; i < pages; i++, p++) {if (rdev->gart.pages[p]) { -if (!rdev->gart.ttm_alloced[p]) -pci_unmap_page (rdev->pdev, rdev->gart.pages_addr[p], -PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); rdev->gart.pages[p] =NULL ; rdev->gart.pages_addr[p] = rdev->dummy_page.addr; page_base = rdev->gart.pages_addr[p];
@@ -191,23 +188,7 @@ int radeon_gart_bind(struct radeon_device *rdev, unsigned offset, p = t / (PAGE_SIZE /RADEON_GPU_PAGE_SIZE );for (i =0 ; i < pages; i++, p++) { -/* we reverted the patch using dma_addr in TTM for now but this -* code stops building on alpha so just comment it out for now */ -if (0 ) {/*dma_addr[i] != DMA_ERROR_CODE) */ - rdev->gart.ttm_alloced[p] = true; - rdev->gart.pages_addr[p] = dma_addr[i]; - }else { -/* we need to support large memory configurations */ -/* assume that unbind have already been call on the range */ - rdev->gart.pages_addr[p] =pci_map_page (rdev->pdev, pagelist[i], -0 ,PAGE_SIZE , -PCI_DMA_BIDIRECTIONAL ); -if (pci_dma_mapping_error (rdev->pdev, rdev->gart.pages_addr[p])) { -/* FIXME: failed to map page (return -ENOMEM?) */ -radeon_gart_unbind (rdev, offset, pages); -return -ENOMEM ; - } - } + rdev->gart.pages_addr[p] = dma_addr[i]; rdev->gart.pages[p] = pagelist[i];if (rdev->gart.ptr) { page_base = rdev->gart.pages_addr[p];
@@ -274,12 +255,6 @@ int radeon_gart_init(struct radeon_device *rdev)radeon_gart_fini (rdev);return -ENOMEM ; } - rdev->gart.ttm_alloced =kzalloc (sizeof (bool ) * - rdev->gart.num_cpu_pages,GFP_KERNEL ); -if (rdev->gart.ttm_alloced ==NULL ) { -radeon_gart_fini (rdev); -return -ENOMEM ; - }/* set GART entry to point to the dummy page by default */ for (i =0 ; i < rdev->gart.num_cpu_pages; i++) { rdev->gart.pages_addr[i] = rdev->dummy_page.addr;
@@ -296,10 +271,8 @@ void radeon_gart_fini(struct radeon_device *rdev) rdev->gart.ready = false;kfree (rdev->gart.pages);kfree (rdev->gart.pages_addr); -kfree (rdev->gart.ttm_alloced); rdev->gart.pages =NULL ; rdev->gart.pages_addr =NULL ; - rdev->gart.ttm_alloced =NULL ;radeon_dummy_page_fini (rdev); }
drivers/gpu/drm/radeon/radeon_ttm.c +77 -6
104 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Re: [PATCH 11/14] drm/radeon/kms: enable the ttm dma pool if swiotlb is on V3
Quoted 5 lines
drivers/gpu/drm/radeon/radeon_ttm.c +5
-0+#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +return ttm_dma_populate (ttm, rdev->dev); + } +#endif
..
Quoted 6 lines
drivers/gpu/drm/radeon/radeon_ttm.c +6
-0+#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +ttm_dma_unpopulate (ttm, rdev->dev); +return ; + } +#endif
drivers/gpu/drm/radeon/radeon_ttm.c static int radeon_ttm_debugfs_init(struct radeon_device *rdev) · line 865
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_ttm.c +9
-0+#ifdef CONFIG_SWIOTLB +if (rdev->need_dma32 &&swiotlb_nr_tbl ()) { +sprintf (radeon_mem_types_names[i],"ttm_dma_page_pool" ); + radeon_mem_types_list[i].name = radeon_mem_types_names[i]; + radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs; + radeon_mem_types_list[i].driver_features =0 ; + radeon_mem_types_list[i++].data =NULL ; + } +#endif
So I think the last one does not need the rdev->need_dma32 as you had removed it from the other sites.
Re: [PATCH 11/14] drm/radeon/kms: enable the ttm dma pool if swiotlb is on V3
Quoted 13 lines · Konrad Rzeszutek Wilk
Quoted 5 lines
drivers/gpu/drm/radeon/radeon_ttm.c +5
-0+#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +return ttm_dma_populate (ttm, rdev->dev); + } +#endif ..
Quoted 6 lines
drivers/gpu/drm/radeon/radeon_ttm.c +6
-0+#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +ttm_dma_unpopulate (ttm, rdev->dev); +return ; + } +#endif
Quoted 12 lines
drivers/gpu/drm/radeon/radeon_ttm.c static int radeon_ttm_debugfs_init(struct radeon_device *rdev) · line 865
Quoted 9 lines
drivers/gpu/drm/radeon/radeon_ttm.c +9
-0+#ifdef CONFIG_SWIOTLB +if (rdev->need_dma32 &&swiotlb_nr_tbl ()) { +sprintf (radeon_mem_types_names[i],"ttm_dma_page_pool" ); + radeon_mem_types_list[i].name = radeon_mem_types_names[i]; + radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs; + radeon_mem_types_list[i].driver_features =0 ; + radeon_mem_types_list[i++].data =NULL ; + } +#endif So I think the last one does not need the
rdev->need_dma32as you had removed it from the other sites.
Yeah i forgot to remove it there too. I removed it on others so that swiotlb force works.
Cheers,
Jerome
PATCH 12/14 drm/nouveau: enable the ttm dma pool when swiotlb is active V3
In reply to [email protected]From: Konrad Rzeszutek Wilk <[email protected]>
If the card is capable of more than 32-bit, then use the default TTM page pool code which allocates from anywhere in the memory.
Note: If the 'ttm.no_dma' parameter is set, the override is ignored and the default TTM pool is used.
V2 use pci_set_consistent_dma_mask
V3 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 73 ++++++++++++++++++++++++++++- drivers/gpu/drm/nouveau/nouveau_debugfs.c | 1 + drivers/gpu/drm/nouveau/nouveau_mem.c | 6 ++ drivers/gpu/drm/nouveau/nouveau_sgdma.c | 60 +----------------------- 4 files changed, 79 insertions(+), 61 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +71 -2
@@ -1049,10 +1049,79 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)nouveau_fence_unref (&old_fence); } +static int +nouveau_ttm_tt_populate (struct ttm_tt *ttm) +{ +struct drm_nouveau_private *dev_priv; +struct drm_device *dev; +unsigned i; +int r; + +if (ttm->state != tt_unpopulated) +return 0 ; + + dev_priv =nouveau_bdev (ttm->bdev); + dev = dev_priv->dev; + +#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +return ttm_dma_populate (ttm, dev->dev); + } +#endif + + r =ttm_pool_populate (ttm); +if (r) { +return r; + } + +for (i =0 ; i < ttm->num_pages; i++) { + ttm->dma_address[i] =pci_map_page (dev->pdev, ttm->pages[i], +0 ,PAGE_SIZE , +PCI_DMA_BIDIRECTIONAL ); +if (pci_dma_mapping_error (dev->pdev, ttm->dma_address[i])) { +while (--i) { +pci_unmap_page (dev->pdev, ttm->dma_address[i], +PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); + ttm->dma_address[i] =0 ; + } +ttm_pool_unpopulate (ttm); +return -EFAULT ; + } + } +return 0 ; +} + +static void +nouveau_ttm_tt_unpopulate (struct ttm_tt *ttm) +{ +struct drm_nouveau_private *dev_priv; +struct drm_device *dev; +unsigned i; + + dev_priv =nouveau_bdev (ttm->bdev); + dev = dev_priv->dev; + +#ifdef CONFIG_SWIOTLB +if (swiotlb_nr_tbl ()) { +ttm_dma_unpopulate (ttm, dev->dev); +return ; + } +#endif + +for (i =0 ; i < ttm->num_pages; i++) { +if (ttm->dma_address[i]) { +pci_unmap_page (dev->pdev, ttm->dma_address[i], +PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); + } + } + +ttm_pool_unpopulate (ttm); +} +struct ttm_bo_driver nouveau_bo_driver = { .ttm_tt_create = &nouveau_ttm_tt_create, - .ttm_tt_populate = &ttm_pool_populate, - .ttm_tt_unpopulate = &ttm_pool_unpopulate, + .ttm_tt_populate = &nouveau_ttm_tt_populate, + .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate, .invalidate_caches = nouveau_bo_invalidate_caches, .init_mem_type = nouveau_bo_init_mem_type, .evict_flags = nouveau_bo_evict_flags,
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -0
@@ -178,6 +178,7 @@ static struct drm_info_list nouveau_debugfs_list[] = { { "memory", nouveau_debugfs_memory_info, 0, NULL }, { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL }, { "ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL }, + { "ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL }, };#define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
drivers/gpu/drm/nouveau/nouveau_mem.c +6 -0
@@ -407,6 +407,12 @@ nouveau_mem_vram_init(struct drm_device *dev) ret =pci_set_dma_mask (dev->pdev,DMA_BIT_MASK (dma_bits));if (ret)return ret; + ret =pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (dma_bits)); +if (ret) { +/* Reset to default value. */ +pci_set_consistent_dma_mask (dev->pdev,DMA_BIT_MASK (32 )); + } + ret =nouveau_ttm_global_init (dev_priv);if (ret)
drivers/gpu/drm/nouveau/nouveau_sgdma.c +1 -59
122 lines not on this page · raw message
Signature · 1 line
1.7.7.1
PATCH 13/14 drm/ttm: isolate dma data from ttm_tt V3
In reply to [email protected]From: Jerome Glisse <[email protected]>
Move dma data to a superset ttm_dma_tt structure which herit from ttm_tt. This allow driver that don't use dma functionalities to not have to waste memory for it.
V2 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
V3 Make sure page list is initialized empty
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 18 +++-- drivers/gpu/drm/nouveau/nouveau_sgdma.c | 22 ++++-- drivers/gpu/drm/radeon/radeon_ttm.c | 43 ++++++------ drivers/gpu/drm/ttm/ttm_page_alloc.c | 114 +++++++++++++++--------------- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 35 +++++---- drivers/gpu/drm/ttm/ttm_tt.c | 60 +++++++++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 2 + include/drm/ttm/ttm_bo_driver.h | 31 ++++++++- include/drm/ttm/ttm_page_alloc.h | 33 +-------- 9 files changed, 203 insertions(+), 155 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +10 -8
@@ -1052,6 +1052,7 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)static int nouveau_ttm_tt_populate (struct ttm_tt *ttm) { +struct ttm_dma_tt *ttm_dma = (void *)ttm;struct drm_nouveau_private *dev_priv;struct drm_device *dev;unsigned i;
@@ -1065,7 +1066,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)#ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -return ttm_dma_populate (ttm, dev->dev); +return ttm_dma_populate ((void *)ttm, dev->dev); }#endif
@@ -1075,14 +1076,14 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm) }for (i =0 ; i < ttm->num_pages; i++) { - ttm->dma_address[i] =pci_map_page (dev->pdev, ttm->pages[i], + ttm_dma->dma_address[i] =pci_map_page (dev->pdev, ttm->pages[i],0 ,PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); -if (pci_dma_mapping_error (dev->pdev, ttm->dma_address[i])) { +if (pci_dma_mapping_error (dev->pdev, ttm_dma->dma_address[i])) {while (--i) { -pci_unmap_page (dev->pdev, ttm->dma_address[i], +pci_unmap_page (dev->pdev, ttm_dma->dma_address[i],PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); - ttm->dma_address[i] =0 ; + ttm_dma->dma_address[i] =0 ; }ttm_pool_unpopulate (ttm);return -EFAULT ;
@@ -1094,6 +1095,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)static void nouveau_ttm_tt_unpopulate (struct ttm_tt *ttm) { +struct ttm_dma_tt *ttm_dma = (void *)ttm;struct drm_nouveau_private *dev_priv;struct drm_device *dev;unsigned i;
@@ -1103,14 +1105,14 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)#ifdef CONFIG_SWIOTLB if (swiotlb_nr_tbl ()) { -ttm_dma_unpopulate (ttm, dev->dev); +ttm_dma_unpopulate ((void *)ttm, dev->dev);return ; }#endif for (i =0 ; i < ttm->num_pages; i++) { -if (ttm->dma_address[i]) { -pci_unmap_page (dev->pdev, ttm->dma_address[i], +if (ttm_dma->dma_address[i]) { +pci_unmap_page (dev->pdev, ttm_dma->dma_address[i],PAGE_SIZE ,PCI_DMA_BIDIRECTIONAL ); } }
drivers/gpu/drm/nouveau/nouveau_sgdma.c +14 -8
@@ -8,7 +8,10 @@#define NV_CTXDMA_PAGE_MASK (NV_CTXDMA_PAGE_SIZE - 1)struct nouveau_sgdma_be { -struct ttm_tt ttm; +/* 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 drm_device *dev;u64 offset; };
@@ -20,6 +23,7 @@ nouveau_sgdma_destroy(struct ttm_tt *ttm)if (ttm) {NV_DEBUG (nvbe->dev,"\n" ); +ttm_dma_tt_fini (&nvbe->ttm);kfree (nvbe); } }
@@ -38,7 +42,7 @@ nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem) nvbe->offset = mem->start <<PAGE_SHIFT ; pte = (nvbe->offset >>NV_CTXDMA_PAGE_SHIFT ) +2 ;for (i =0 ; i < ttm->num_pages; i++) { -dma_addr_t dma_offset = ttm->dma_address[i]; +dma_addr_t dma_offset = nvbe->ttm.dma_address[i];uint32_t offset_l =lower_32_bits (dma_offset);for (j =0 ; j <PAGE_SIZE /NV_CTXDMA_PAGE_SIZE ; j++, pte++) {
@@ -97,7 +101,7 @@ nv41_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;struct drm_nouveau_private *dev_priv = nvbe->dev->dev_private;struct nouveau_gpuobj *pgt = dev_priv->gart_info.sg_ctxdma; -dma_addr_t *list = ttm->dma_address; +dma_addr_t *list = nvbe->ttm.dma_address;u32 pte = mem->start <<2 ;u32 cnt = ttm->num_pages;
@@ -206,7 +210,7 @@ nv44_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;struct drm_nouveau_private *dev_priv = nvbe->dev->dev_private;struct nouveau_gpuobj *pgt = dev_priv->gart_info.sg_ctxdma; -dma_addr_t *list = ttm->dma_address; +dma_addr_t *list = nvbe->ttm.dma_address;u32 pte = mem->start <<2 , tmp[4 ];u32 cnt = ttm->num_pages;int i;
@@ -282,10 +286,11 @@ static struct ttm_backend_func nv44_sgdma_backend = {static int nv50_sgdma_bind (struct ttm_tt *ttm,struct ttm_mem_reg *mem) { +struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;struct nouveau_mem *node = mem->mm_node;/* noop: bound in move_notify() */ - node->pages = ttm->dma_address; + node->pages = nvbe->ttm.dma_address;return 0 ; }
@@ -316,12 +321,13 @@ nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,return NULL ; nvbe->dev = dev; - nvbe->ttm.func = dev_priv->gart_info.func; + nvbe->ttm.ttm.func = dev_priv->gart_info.func; -if (ttm_tt_init (&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) { +if (ttm_dma_tt_init (&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) { +kfree (nvbe);return NULL ; } -return &nvbe->ttm; +return &nvbe->ttm.ttm; }int
drivers/gpu/drm/radeon/radeon_ttm.c +22 -21
122 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_page_alloc.c +56 -58
148 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +19 -16
@@ -779,7 +779,7 @@ out:/* * @return count of pages still required to fulfill the request. -*/ +*/ static int ttm_dma_page_pool_fill_locked (struct dma_pool *pool,unsigned long *irq_flags) {
@@ -828,10 +828,11 @@ static int ttm_dma_page_pool_fill_locked(struct dma_pool *pool,* allocates one page at a time. */ static int ttm_dma_pool_get_pages (struct dma_pool *pool, -struct ttm_tt *ttm, +struct ttm_dma_tt *ttm_dma,unsigned index) {struct dma_page *d_page; +struct ttm_tt *ttm = &ttm_dma->ttm;unsigned long irq_flags;int count, r = -ENOMEM ;
@@ -840,8 +841,8 @@ static int ttm_dma_pool_get_pages(struct dma_pool *pool,if (count) { d_page = list_first_entry(&pool->free_list, struct dma_page, page_list); ttm->pages[index] = d_page->p; - ttm->dma_address[index] = d_page->dma; -list_move_tail (&d_page->page_list, &ttm->alloc_list); + ttm_dma->dma_address[index] = d_page->dma; +list_move_tail (&d_page->page_list, &ttm_dma->pages_list); r =0 ; pool->npages_in_use +=1 ; pool->npages_free -=1 ;
@@ -854,8 +855,9 @@ static int ttm_dma_pool_get_pages(struct dma_pool *pool,* On success pages list will hold count number of correctly * cached pages. On failure will hold the negative return value (-ENOMEM, etc). */ -int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev) +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev) { +struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;struct dma_pool *pool;enum pool_type type;
@@ -882,18 +884,18 @@ int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev) } } -INIT_LIST_HEAD (&ttm->alloc_list); +INIT_LIST_HEAD (&ttm_dma->pages_list);for (i =0 ; i < ttm->num_pages; ++i) { - ret =ttm_dma_pool_get_pages (pool, ttm, i); + ret =ttm_dma_pool_get_pages (pool, ttm_dma, i);if (ret !=0 ) { -ttm_dma_unpopulate (ttm, dev); +ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ; } ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], false, false);if (unlikely (ret !=0 )) { -ttm_dma_unpopulate (ttm, dev); +ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ; } }
@@ -901,7 +903,7 @@ int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev)if (unlikely (ttm->page_flags &TTM_PAGE_FLAG_SWAPPED )) { ret =ttm_tt_swapin (ttm);if (unlikely (ret !=0 )) { -ttm_dma_unpopulate (ttm, dev); +ttm_dma_unpopulate (ttm_dma, dev);return ret; } }
@@ -927,8 +929,9 @@ static int ttm_dma_pool_get_num_unused_pages(void) }/* Put all pages in pages list to correct pool to wait for reuse */ -void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev) +void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev) { +struct ttm_tt *ttm = &ttm_dma->ttm;struct dma_pool *pool;struct dma_page *d_page;enum pool_type type;
@@ -946,7 +949,7 @@ void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev) ttm_to_type(ttm->page_flags, tt_cached)) == pool);/* make sure pages array match list and count number of pages */ -list_for_each_entry (d_page, &ttm->alloc_list, page_list) { +list_for_each_entry (d_page, &ttm_dma->pages_list, page_list) { ttm->pages[count] = d_page->p; count++; }
@@ -957,7 +960,7 @@ void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev) pool->nfrees += count; }else { pool->npages_free += count; -list_splice (&ttm->alloc_list, &pool->free_list); +list_splice (&ttm_dma->pages_list, &pool->free_list);if (pool->npages_free > _manager->options.max_size) { count = pool->npages_free - _manager->options.max_size; }
@@ -965,14 +968,14 @@ void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev)spin_unlock_irqrestore (&pool->lock, irq_flags);if (is_cached) { -ttm_dma_pages_put (pool, &ttm->alloc_list, +ttm_dma_pages_put (pool, &ttm_dma->pages_list, ttm->pages, count); } -INIT_LIST_HEAD (&ttm->alloc_list); +INIT_LIST_HEAD (&ttm_dma->pages_list);for (i =0 ; i < ttm->num_pages; i++) { ttm->pages[i] =NULL ; - ttm->dma_address[i] =0 ; + ttm_dma->dma_address[i] =0 ; }/* shrink pool if necessary */
drivers/gpu/drm/ttm/ttm_tt.c +49 -11
88 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +2 -0
@@ -168,6 +168,7 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) { struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); +ttm_tt_fini (ttm);kfree (vmw_be); }
@@ -191,6 +192,7 @@ struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev, vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev);if (ttm_tt_init (&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) { +kfree (vmw_be);return NULL ; }
include/drm/ttm/ttm_bo_driver.h +29 -2
@@ -104,7 +104,6 @@ enum ttm_caching_state {* @caching_state: The current caching state of the pages. * @state: The current binding state of the pages. * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) -* @alloc_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)
@@ -127,8 +126,23 @@ struct ttm_tt { tt_unbound, tt_unpopulated, } state; +}; + +/** +* struct ttm_dma_tt +* +* @ttm: Base ttm_tt struct. +* @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) +* @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 alloc_list; +struct list_head pages_list; };#define TTM_MEMTYPE_FLAG_FIXED (1 << 0)/* Fixed (on-card) PCI memory */
@@ -595,6 +609,19 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)extern int ttm_tt_init (struct ttm_tt *ttm,struct ttm_bo_device *bdev,unsigned long size,uint32_t page_flags,struct page *dummy_read_page); +extern int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page); + +/** +* ttm_tt_fini +* +* @ttm: The struct ttm_tt. +* +* Free memory of ttm_tt structu +*/ +extern void ttm_tt_fini (struct ttm_tt *ttm); +extern void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma);/** * ttm_ttm_bind:
include/drm/ttm/ttm_page_alloc.h +2 -31
@@ -30,35 +30,6 @@#include "ttm_memory.h" /** -* Get count number of pages from pool to pages list. -* -* @pages: head of empty linked list where pages are filled. -* @flags: ttm flags for page allocation. -* @cstate: ttm caching state for the page. -* @count: number of pages to allocate. -* @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). -*/ -int ttm_get_pages (struct page **pages, -int flags, -enum ttm_caching_state cstate, -unsigned npages, -dma_addr_t *dma_address); -/** -* Put linked list of pages to pool. -* -* @pages: list of pages to free. -* @page_count: number of pages in the list. Zero can be passed for unknown -* count. -* @flags: ttm flags for page allocation. -* @cstate: ttm caching state. -* @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set). -*/ -void ttm_put_pages (struct page **pages, -unsigned npages, -int flags, -enum ttm_caching_state cstate, -dma_addr_t *dma_address); -/** * Initialize pool allocator. */ int ttm_page_alloc_init (struct ttm_mem_global *glob,unsigned max_pages);
@@ -107,8 +78,8 @@ void ttm_dma_page_alloc_fini(void);*/ extern int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev); -extern void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +extern void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);#else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
Signature · 1 line
1.7.7.1
Re: [PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3
Quoted 3 lines · On Fri, Nov 11, 2011 at 05:47:48PM -0500, [email protected] wrote:
From: Jerome Glisse <[email protected]>
Move dma data to a superset
ttm_dma_ttstructure which herit
inherit
Quoted 9 lines
from
ttm_tt. This allow driver that don't use dma functionalities to not have to waste memory for it.V2 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
V3 Make sure page list is initialized emptySigned-off-by Jerome Glisse <[email protected]>Reviewed-by Thomas Hellstrom <[email protected]>
.. snip..
Quoted 21 lines
drivers/gpu/drm/ttm/ttm_tt.c +21
-0+void ttm_tt_fini (struct ttm_tt *ttm) +{ +drm_free_large (ttm->pages); + ttm->pages =NULL ; +} +EXPORT_SYMBOL (ttm_tt_fini); + +int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page) +{ +struct ttm_tt *ttm = &ttm_dma->ttm; + + ttm->bdev = bdev; + ttm->glob = bdev->glob; + ttm->num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + ttm->caching_state = tt_cached; + ttm->page_flags = page_flags; + ttm->dummy_read_page = dummy_read_page; + ttm->state = tt_unpopulated; +
drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 235
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +10
-0+INIT_LIST_HEAD (&ttm_dma->pages_list); +ttm_dma_tt_alloc_page_directory (ttm_dma); +if (!ttm->pages || !ttm_dma->dma_address) { +ttm_tt_destroy (ttm); + printk(KERN_ERR TTM_PFX "Failed allocating page table\n"); +return -ENOMEM ; + } +return 0 ; +} +EXPORT_SYMBOL (ttm_dma_tt_init);
EXPORT_SYMBOL_GPL ?
drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 247
Quoted 12 lines
drivers/gpu/drm/ttm/ttm_tt.c +12
-0+ +void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma) +{ +struct ttm_tt *ttm = &ttm_dma->ttm; + +drm_free_large (ttm->pages); + ttm->pages =NULL ; +drm_free_large (ttm_dma->dma_address); + ttm_dma->dma_address =NULL ; +} +EXPORT_SYMBOL (ttm_dma_tt_fini); +
EXPORT_SYMBOL_GPL?
Quoted 36 lines
void
ttm_tt_unbind(struct ttm_tt *ttm)
{drivers/gpu/drm/ttm/ttm_tt.c +0
-0int ret;drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +2
-0@@ -168,6 +168,7 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) { struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); +ttm_tt_fini (ttm);kfree (vmw_be); }@@ -191,6 +192,7 @@ struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev, vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev);if (ttm_tt_init (&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) { +kfree (vmw_be);return NULL ; }include/drm/ttm/ttm_bo_driver.h +0
-1@@ -104,7 +104,6 @@ enum ttm_caching_state {* @caching_state: The current caching state of the pages. * @state: The current binding state of the pages. * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) -* @alloc_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)
include/drm/ttm/ttm_bo_driver.h struct ttm_tt { · line 135
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +7
-0@@ -127,8 +126,23 @@ struct ttm_tt { tt_unbound, tt_unpopulated, } state; +}; + +/** +* struct ttm_dma_tt +* +* @ttm: Base ttm_tt struct. +* @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
Not anymore (the TTM_PAGE_FLAG_DMA32 comment).
Quoted 18 lines
include/drm/ttm/ttm_bo_driver.h +9
-1+* @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 alloc_list; +struct list_head pages_list; };#define TTM_MEMTYPE_FLAG_FIXED (1 << 0)/* Fixed (on-card) PCI memory */ @@ -595,6 +609,19 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)extern int ttm_tt_init (struct ttm_tt *ttm,struct ttm_bo_device *bdev,unsigned long size,uint32_t page_flags,struct page *dummy_read_page);
include/drm/ttm/ttm_bo_driver.h ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask) · line 621
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +10
-0+extern int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page); + +/** +* ttm_tt_fini +* +* @ttm: The struct ttm_tt. +* +* Free memory of ttm_tt structu
structure
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +3
-0+*/ +extern void ttm_tt_fini (struct ttm_tt *ttm); +extern void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma);
.. snip..
Quoted 4 lines
* Initialize pool allocator.
*/
intttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
include/drm/ttm/ttm_bo_driver.h void ttm_dma_page_alloc_fini(void); · line 85
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +2
-2@@ -107,8 +78,8 @@ void ttm_dma_page_alloc_fini(void);*/ extern int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev); -extern void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +extern void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);#else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
You are missing changes to the static implementations in case CONFIG_SWIOTLB is not set.
Quoted 2 lines
Signature · 1 line
1.7.7.1
Re: [PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3
Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · On Fri, Nov 11, 2011 at 05:47:48PM -0500, [email protected] wrote:
From: Jerome Glisse <[email protected]>
Move dma data to a superset
ttm_dma_ttstructure which heritinherit
Quoted 9 lines
from
ttm_tt. This allow driver that don't use dma functionalities to not have to waste memory for it.V2 Rebase on top of no memory account changes (where/when is my
delorean when i need it ?)
V3 Make sure page list is initialized emptySigned-off-by Jerome Glisse <[email protected]>Reviewed-by Thomas Hellstrom <[email protected]>.. snip..
Quoted 25 lines
drivers/gpu/drm/ttm/ttm_tt.c +25
-0+void ttm_tt_fini (struct ttm_tt *ttm) +{ +drm_free_large (ttm->pages); + ttm->pages =NULL ; +} +EXPORT_SYMBOL (ttm_tt_fini); + +int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page) +{ +struct ttm_tt *ttm = &ttm_dma->ttm; + + ttm->bdev = bdev; + ttm->glob = bdev->glob; + ttm->num_pages = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + ttm->caching_state = tt_cached; + ttm->page_flags = page_flags; + ttm->dummy_read_page = dummy_read_page; + ttm->state = tt_unpopulated; + +INIT_LIST_HEAD (&ttm_dma->pages_list); +ttm_dma_tt_alloc_page_directory (ttm_dma); +if (!ttm->pages || !ttm_dma->dma_address) { +ttm_tt_destroy (ttm);
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 235
Quoted 6 lines
drivers/gpu/drm/ttm/ttm_tt.c +6
-0+ printk(KERN_ERR TTM_PFX "Failed allocating page table\n"); +return -ENOMEM ; + } +return 0 ; +} +EXPORT_SYMBOL (ttm_dma_tt_init);
EXPORT_SYMBOL_GPL?
TTM is BSD licensed too. As a rule the whole drm is under BSD license too.
Quoted 114 lines
drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 247
Quoted 13 lines
drivers/gpu/drm/ttm/ttm_tt.c +12
-0+ +void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma) +{ +struct ttm_tt *ttm = &ttm_dma->ttm; + +drm_free_large (ttm->pages); + ttm->pages =NULL ; +drm_free_large (ttm_dma->dma_address); + ttm_dma->dma_address =NULL ; +} +EXPORT_SYMBOL (ttm_dma_tt_fini); +
EXPORT_SYMBOL_GPL?Quoted 36 lines
void
ttm_tt_unbind(struct ttm_tt *ttm)
{drivers/gpu/drm/ttm/ttm_tt.c +0
-0int ret;drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +2
-0@@ -168,6 +168,7 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) { struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); +ttm_tt_fini (ttm);kfree (vmw_be); }@@ -191,6 +192,7 @@ struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev, vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev);if (ttm_tt_init (&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) { +kfree (vmw_be);return NULL ; }include/drm/ttm/ttm_bo_driver.h +0
-1@@ -104,7 +104,6 @@ enum ttm_caching_state {* @caching_state: The current caching state of the pages. * @state: The current binding state of the pages. * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) -* @alloc_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) include/drm/ttm/ttm_bo_driver.h struct ttm_tt { · line 135
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +7
-0@@ -127,8 +126,23 @@ struct ttm_tt { tt_unbound, tt_unpopulated, } state; +}; + +/** +* struct ttm_dma_tt +* +* @ttm: Base ttm_tt struct. +* @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) Not anymore (the
TTM_PAGE_FLAG_DMA32comment).Quoted 18 lines
include/drm/ttm/ttm_bo_driver.h +9
-1+* @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 alloc_list; +struct list_head pages_list; };#define TTM_MEMTYPE_FLAG_FIXED (1 << 0)/* Fixed (on-card) PCI memory */ @@ -595,6 +609,19 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)extern int ttm_tt_init (struct ttm_tt *ttm,struct ttm_bo_device *bdev,unsigned long size,uint32_t page_flags,struct page *dummy_read_page);include/drm/ttm/ttm_bo_driver.h ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask) · line 621
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +10
-0+extern int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, +unsigned long size,uint32_t page_flags, +struct page *dummy_read_page); + +/** +* ttm_tt_fini +* +* @ttm: The struct ttm_tt. +* +* Free memory of ttm_tt structu structure
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +3
-0+*/ +extern void ttm_tt_fini (struct ttm_tt *ttm); +extern void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma);.. snip..
Quoted 12 lines
* Initialize pool allocator.
*/
intttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);include/drm/ttm/ttm_bo_driver.h +2
-2@@ -107,8 +78,8 @@ void ttm_dma_page_alloc_fini(void);*/ extern int ttm_dma_page_alloc_debugfs (struct seq_file *m,void *data); -int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev); -extern void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +extern void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);
Quoted 4 lines
include/drm/ttm/ttm_bo_driver.h void ttm_dma_page_alloc_fini(void); · line 85
Quoted 2 lines
include/drm/ttm/ttm_bo_driver.h +0
-0#else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,You are missing changes to the static implementations in case
CONFIG_SWIOTLBis not set.
Good catch.
Will respin with typo fixes
Cheers,
Jerome
Re: [PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3
In reply to Konrad Rzeszutek WilkQuoted 165 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · On Fri, Nov 11, 2011 at 05:47:48PM -0500, [email protected] wrote:
From: Jerome Glisse <[email protected]>
Move dma data to a superset
ttm_dma_ttstructure which heritinherit
Quoted 9 lines
from
ttm_tt. This allow driver that don't use dma functionalities to not have to waste memory for it.V2 Rebase on top of no memory account changes (where/when is my delorean when i need it ?)
V3 Make sure page list is initialized emptySigned-off-by Jerome Glisse <[email protected]>Reviewed-by Thomas Hellstrom <[email protected]>.. snip..
Quoted 21 lines
drivers/gpu/drm/ttm/ttm_tt.c +21
-0+void ttm_tt_fini (struct ttm_tt *ttm) +{ + drm_free_large(ttm->pages); + ttm->pages = NULL; +} +EXPORT_SYMBOL (ttm_tt_fini); + +int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, + unsigned long size, uint32_t page_flags, + struct page *dummy_read_page) +{ + struct ttm_tt *ttm = &ttm_dma->ttm; + + ttm->bdev = bdev; + ttm->glob = bdev->glob; + ttm->num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; + ttm->caching_state = tt_cached; + ttm->page_flags = page_flags; + ttm->dummy_read_page = dummy_read_page; + ttm->state = tt_unpopulated; +drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 235
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +10
-0+ INIT_LIST_HEAD(&ttm_dma->pages_list); + ttm_dma_tt_alloc_page_directory(ttm_dma); + if (!ttm->pages || !ttm_dma->dma_address) { + ttm_tt_destroy(ttm); + printk(KERN_ERR TTM_PFX "Failed allocating page table\n"); + return -ENOMEM; + } + return 0; +} +EXPORT_SYMBOL (ttm_dma_tt_init);
EXPORT_SYMBOL_GPL?drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, · line 247
Quoted 12 lines
drivers/gpu/drm/ttm/ttm_tt.c +12
-0+ +void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma) +{ + struct ttm_tt *ttm = &ttm_dma->ttm; + + drm_free_large(ttm->pages); + ttm->pages = NULL; + drm_free_large(ttm_dma->dma_address); + ttm_dma->dma_address = NULL; +} +EXPORT_SYMBOL (ttm_dma_tt_fini); +
EXPORT_SYMBOL_GPL?Quoted 36 lines
void
ttm_tt_unbind(struct ttm_tt *ttm)
{
int ret;drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +2
-0@@ -168,6 +168,7 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm) { struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); + ttm_tt_fini(ttm); kfree(vmw_be); }@@ -191,6 +192,7 @@ struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev, vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev); if (ttm_tt_init(&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) { + kfree(vmw_be); return NULL; }include/drm/ttm/ttm_bo_driver.h +0
-1@@ -104,7 +104,6 @@ enum ttm_caching_state { * @caching_state: The current caching state of the pages. * @state: The current binding state of the pages. * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) - * @alloc_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)include/drm/ttm/ttm_bo_driver.h struct ttm_tt { · line 135
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +7
-0@@ -127,8 +126,23 @@ struct ttm_tt { tt_unbound, tt_unpopulated, } state; +}; + +/** +* struct ttm_dma_tt +* +* @ttm: Base ttm_tt struct. +* @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) Not anymore (the
TTM_PAGE_FLAG_DMA32comment).Quoted 18 lines
include/drm/ttm/ttm_bo_driver.h +9
-1+* @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 alloc_list; + struct list_head pages_list; }; #define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */@@ -595,6 +609,19 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask) extern int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, unsigned long size, uint32_t page_flags, struct page *dummy_read_page);include/drm/ttm/ttm_bo_driver.h ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask) · line 621
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +10
-0+extern int ttm_dma_tt_init (struct ttm_dma_tt *ttm_dma,struct ttm_bo_device *bdev, + unsigned long size, uint32_t page_flags, + struct page *dummy_read_page); + +/** +* ttm_tt_fini +* +* @ttm: The struct ttm_tt. +* +* Free memory of ttm_tt structu structure
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +3
-0+*/ +extern void ttm_tt_fini (struct ttm_tt *ttm); +extern void ttm_dma_tt_fini (struct ttm_dma_tt *ttm_dma);.. snip..
Quoted 12 lines
* Initialize pool allocator.
*/
intttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);include/drm/ttm/ttm_bo_driver.h +2
-2@@ -107,8 +78,8 @@ void ttm_dma_page_alloc_fini(void);*/ extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data); -int ttm_dma_populate (struct ttm_tt *ttm,struct device *dev); -extern void ttm_dma_unpopulate (struct ttm_tt *ttm,struct device *dev); +int ttm_dma_populate (struct ttm_dma_tt *ttm_dma,struct device *dev); +extern void ttm_dma_unpopulate (struct ttm_dma_tt *ttm_dma,struct device *dev);
Quoted 5 lines
include/drm/ttm/ttm_bo_driver.h void ttm_dma_page_alloc_fini(void); · line 85
Quoted 2 lines
include/drm/ttm/ttm_bo_driver.h +0
-0#else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,You are missing changes to the static implementations in case
CONFIG_SWIOTLBis not set.
Actually i don't think i miss anything ttm_dma_populate/ttm_dma_unpopulate is conditional on CONFIG_SWIOTLB in both radeon and nouveau. So i should be fine. Or did i miss something else ?
Cheers,
Jerome
Re: [PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
(quoted diff) +2
-2-int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev); -extern void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev); +int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev); +extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);#else
static inline int ttm_dma_page_alloc_init(structttm_mem_global*glob,You are missing changes to the static implementations in case
CONFIG_SWIOTLBis not set.
Quoted 4 lines
Actually i don't think i miss anything ttm_dma_populate/ttm_dma_unpopulate is conditional on
CONFIG_SWIOTLBin both radeon and nouveau. So i should be fine. Or did i miss something else ?
You are completlty right. Somehow I had in my mind that this was present:
include/drm/ttm/ttm_page_alloc.h +10 -0
@@ -94,6 +94,16 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) {return 0 ; } +static inline int ttm_dma_populate (struct ttm_tt *ttm, +struct device *dev) +{ +return -ENODEV ; +} +static inline void ttm_dma_unpopulate (struct ttm_tt *ttm, +struct device *dev) +{ +return ; +}#endif #endif
But that does not make sense as the nouveau and radeon are both guarded by the #ifdef CONFIG_SWIOTLB. So if "# CONFIG_SWIOTLB is not set" is present, well, nobody will be referencing the ttm_dma_[un|]populate calls.
PATCH 14/14 drm/ttm: simplify memory accounting for ttm user
In reply to [email protected]From: Jerome Glisse <[email protected]>
Provide helper function to compute the kernel memory size needed for each buffer object. Move all the accounting inside ttm, simplifying driver and avoiding code duplication accross them.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 6 +++- drivers/gpu/drm/radeon/radeon_object.c | 8 +++- drivers/gpu/drm/ttm/ttm_bo.c | 52 +++++++++++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 35 +------------------- include/drm/ttm/ttm_bo_api.h | 19 ++++++++++- include/drm/ttm/ttm_bo_driver.h | 5 --- 6 files changed, 70 insertions(+), 55 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +5 -1
@@ -93,6 +93,7 @@ nouveau_bo_new(struct drm_device *dev, int size, int align, {struct drm_nouveau_private *dev_priv = dev->dev_private;struct nouveau_bo *nvbo; +size_t acc_size;int ret; nvbo =kzalloc (sizeof (struct nouveau_bo ),GFP_KERNEL );
@@ -115,9 +116,12 @@ nouveau_bo_new(struct drm_device *dev, int size, int align, nvbo->bo.mem.num_pages = size >>PAGE_SHIFT ;nouveau_bo_placement_set (nvbo, flags,0 ); + acc_size =ttm_bo_dma_acc_size (&dev_priv->ttm.bdev, size, +sizeof (struct nouveau_bo )); + ret =ttm_bo_init (&dev_priv->ttm.bdev, &nvbo->bo, size, ttm_bo_type_device, &nvbo->placement, - align >>PAGE_SHIFT ,0 , false,NULL , size, + align >>PAGE_SHIFT ,0 , false,NULL , acc_size, nouveau_bo_del_ttm);if (ret) {/* ttm will call nouveau_bo_del_ttm if it fails.. */
drivers/gpu/drm/radeon/radeon_object.c +6 -2
@@ -95,6 +95,7 @@ int radeon_bo_create(struct radeon_device *rdev,enum ttm_bo_type type;unsigned long page_align =roundup (byte_align,PAGE_SIZE ) >>PAGE_SHIFT ;unsigned long max_size =0 ; +size_t acc_size;int r; size =ALIGN (size,PAGE_SIZE );
@@ -117,6 +118,9 @@ int radeon_bo_create(struct radeon_device *rdev,return -ENOMEM ; } + acc_size =ttm_bo_dma_acc_size (&rdev->mman.bdev, size, +sizeof (struct radeon_bo )); + retry: bo =kzalloc (sizeof (struct radeon_bo ),GFP_KERNEL );if (bo ==NULL )
@@ -134,8 +138,8 @@ retry:/* Kernel allocation are uninterruptible */ mutex_lock (&rdev->vram_mutex); r =ttm_bo_init (&rdev->mman.bdev, &bo->tbo, size, type, - &bo->placement, page_align,0 , !kernel,NULL , size, - &radeon_ttm_bo_destroy); + &bo->placement, page_align,0 , !kernel,NULL , + acc_size, &radeon_ttm_bo_destroy);mutex_unlock (&rdev->vram_mutex);if (unlikely (r !=0 )) {if (r != -ERESTARTSYS ) {
drivers/gpu/drm/ttm/ttm_bo.c +40 -12
95 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1 -34
@@ -1517,29 +1517,10 @@ out_bad_surface:/** * Buffer management. */ - -static size_t vmw_dmabuf_acc_size (struct ttm_bo_global *glob, -unsigned long num_pages) -{ -static size_t bo_user_size = ~0 ; - -size_t page_array_size = - (num_pages *sizeof (void *) +PAGE_SIZE -1 ) &PAGE_MASK ; - -if (unlikely (bo_user_size == ~0 )) { - bo_user_size = glob->ttm_bo_extra_size + -ttm_round_pot (sizeof (struct vmw_dma_buffer )); - } - -return bo_user_size + page_array_size; -} -void vmw_dmabuf_bo_free (struct ttm_buffer_object *bo) {struct vmw_dma_buffer *vmw_bo =vmw_dma_buffer (bo); -struct ttm_bo_global *glob = bo->glob; -ttm_mem_global_free (glob->mem_glob, bo->acc_size);kfree (vmw_bo); }
@@ -1550,24 +1531,12 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv, void (*bo_free) (struct ttm_buffer_object *bo)) {struct ttm_bo_device *bdev = &dev_priv->bdev; -struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;size_t acc_size;int ret;BUG_ON (!bo_free); - acc_size = -vmw_dmabuf_acc_size (bdev->glob, - (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ); - - ret =ttm_mem_global_alloc (mem_glob, acc_size, false, false); -if (unlikely (ret !=0 )) { -/* we must free the bo here as -* ttm_buffer_object_init does so as well */ -bo_free (&vmw_bo->base); -return ret; - } - + acc_size =ttm_bo_acc_size (bdev, size,sizeof (struct vmw_dma_buffer ));memset (vmw_bo,0 ,sizeof (*vmw_bo));INIT_LIST_HEAD (&vmw_bo->validate_list);
@@ -1582,9 +1551,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,static void vmw_user_dmabuf_destroy (struct ttm_buffer_object *bo) {struct vmw_user_dma_buffer *vmw_user_bo =vmw_user_dma_buffer (bo); -struct ttm_bo_global *glob = bo->glob; -ttm_mem_global_free (glob->mem_glob, bo->acc_size);kfree (vmw_user_bo); }
include/drm/ttm/ttm_bo_api.h +18 -1
@@ -429,9 +429,9 @@ extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,* -EBUSY if the buffer is busy and no_wait is true. * -ERESTARTSYS if interrupted by a signal. */ -extern int ttm_bo_synccpu_write_grab (struct ttm_buffer_object *bo,bool no_wait); +/** * ttm_bo_synccpu_write_release: *
@@ -442,6 +442,22 @@ ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);extern void ttm_bo_synccpu_write_release (struct ttm_buffer_object *bo);/** +* ttm_bo_acc_size +* +* @bdev: Pointer to a ttm_bo_device struct. +* @bo_size: size of the buffer object in byte. +* @struct_size: size of the structure holding buffer object datas +* +* Returns size to account for a buffer object +*/ +size_t ttm_bo_acc_size (struct ttm_bo_device *bdev, +unsigned long bo_size, +unsigned struct_size); +size_t ttm_bo_dma_acc_size (struct ttm_bo_device *bdev, +unsigned long bo_size, +unsigned struct_size); + +/** * ttm_bo_init * * @bdev: Pointer to a ttm_bo_device struct.
@@ -488,6 +504,7 @@ extern int ttm_bo_init(struct ttm_bo_device *bdev,struct file *persistent_swap_storage, size_t acc_size, void (*destroy) (struct ttm_buffer_object *)); +/** * ttm_bo_synccpu_object_init *
include/drm/ttm/ttm_bo_driver.h +0 -5
@@ -470,9 +470,6 @@ struct ttm_bo_global_ref {* @dummy_read_page: Pointer to a dummy page used for mapping requests * of unpopulated pages. * @shrink: A shrink callback object used for buffer object swap. -* @ttm_bo_extra_size: Extra size (sizeof(struct ttm_buffer_object) excluded) -* used by a buffer object. This is excluding page arrays and backing pages. -* @ttm_bo_size: This is @ttm_bo_extra_size + sizeof(struct ttm_buffer_object). * @device_list_mutex: Mutex protecting the device list. * This mutex is held while traversing the device list for pm options. * @lru_lock: Spinlock protecting the bo subsystem lru lists.
@@ -490,8 +487,6 @@ struct ttm_bo_global {struct ttm_mem_global *mem_glob;struct page *dummy_read_page;struct ttm_mem_shrink shrink; -size_t ttm_bo_extra_size; -size_t ttm_bo_size;struct mutex device_list_mutex;spinlock_t lru_lock;
Signature · 1 line
1.7.7.1
Quoted 2 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Jerome,
Out of interest, what was the swapping issue?
/Thomas
Quoted 9 lines
Last patch fix memory accounting
for radeon& nouveau. I think it's ready to go into drm-next, patchset is against linus tree as there is thing there not in next that conflict. (in radeon iirc)Cheers,
Jerome
Quoted 11 lines · Thomas Hellstrom
Quoted 3 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Cheers,
Jerome
Quoted 21 lines · Jerome Glisse
Quoted 12 lines · Thomas Hellstrom
Quoted 3 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Quoted 3 lines
Cheers,
Jerome
Still, I think you have a point in the fact that *when* finally the OOM killer kicks in, it probably doesn't have a way to associate user-space created bos with processes and kill the right process.
/Thomas
Quoted 21 lines · Thomas Hellstrom
Quoted 17 lines · Jerome Glisse
Quoted 9 lines · Thomas Hellstrom
Quoted 2 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Quoted 2 lines
Cheers,
Jerome
Quoted 8 lines
Still, I think you have a point in the fact that *when* finally the OOM killer kicks in,
it probably doesn't have a way to associate user-space created bos with processes
and kill the right process./Thomas
Btw can you review patch 14 as it touch vmwgfx, i am pretty sure i got it right.
Cheers,
Jerome
Quoted 34 lines · Jerome Glisse
Quoted 32 lines · Thomas Hellstrom
Quoted 21 lines · Jerome Glisse
Quoted 12 lines · Thomas Hellstrom
Quoted 3 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Quoted 3 lines
Cheers,
JeromeStill, I think you have a point in the fact that *when* finally the OOM killer kicks in,
it probably doesn't have a way to associate user-space created bos with processes
and kill the right process.
Quoted 9 lines
Quoted 3 lines
/Thomas
Btw can you review patch 14 as it touch vmwgfx, i am pretty sure i got it right.
Cheers,
Jerome
Yes I will do a more thorough review tomorrow of all unreviewed stuff.
/Thomas
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Thomas Hellstrom
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Thomas Hellstrom
Quoted 2 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom
Was it like this:
Nov 16 10:02:02 phenom kernel: [ 4477.232933] [TTM] Out of kernel memory. Nov 16 10:02:02 phenom kernel: [ 4477.232958] radeon 0000:01:00.0: object_init failed for (12288, 0x00000002) Nov 16 10:02:02 phenom kernel: [ 4477.232963] [drm:radeon_gem_object_create] *ERROR* Failed to allocate GEM object (12288, 2, 4096, -12) Nov 16 10:02:02 phenom kernel: [ 4477.248329] [TTM] Out of kernel memory.
followed up with an OOM?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Weirdly enough, I did _not_ see this with the patchset:
592d002 drm/ttm: remove userspace backed ttm object support
9f1cf44 drm/ttm: remove split btw highmen and lowmem page
d27ea32 drm/ttm: remove unused backend flags field
dad5ef9 drm/ttm: use ttm put pages function to properly restore cache attribute 6aa902d drm/ttm: overhaul memory accounting
60d0fa6 drm/ttm: convert page allocation to use page ptr array instead of list V4 abde3ec drm/ttm: test for dma_address array allocation failure
8145582 drm/ttm: merge ttm_backend and ttm_tt V2
0216e52 drm/ttm: introduce callback for ttm_tt populate & unpopulate V2 ecb0d22 ttm: Provide DMA aware TTM page pool code. V5
793dc40 swiotlb: Expose swiotlb_nr_tlb function to modules
767aa47 drm/radeon/kms: Enable the TTM DMA pool if swiotlb is on V2 e91d0f0 drm/nouveau: enable the TTM DMA pool on 32-bit DMA only device V2 6eda9c3 ttm:dma: Add 'ttm_dma' module to radeon and nouveau to force enable the TTM DMA
which I think was your V4 posting (or earlier) (the last patch is something I added to toggle it off/on to test).
The latest (V5) hit the OOM quite fast - took about an hour or two of me answering emails (mutt inside gnome-terminal) and using both chrome and firefox, and running a make -j10 on the Linux kernel.
Time to turn on more debugging :-)
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · Jerome Glisse
Quoted 5 lines · Thomas Hellstrom
Quoted 4 lines · Jerome Glisse
Quoted 3 lines · Thomas Hellstrom
Quoted 2 lines · On 11/11/2011 11:47 PM, [email protected] wrote:
So attached is updated serie of patch with fixes for swaping issue that also impacted memory accounting.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Jerome,
Out of interest, what was the swapping issue?/Thomas
The page list was NULL and some access ended up freaking the kernel and oom kicked in for some reason i still don't understand. Bottom
Quoted 8 lines
Was it like this:
Nov 16 10:02:02 phenom kernel: [ 4477.232933] [TTM] Out of kernel memory. Nov 16 10:02:02 phenom kernel: [ 4477.232958] radeon 0000:01:00.0: object_init failed for (12288, 0x00000002) Nov 16 10:02:02 phenom kernel: [ 4477.232963] [drm:radeon_gem_object_create] *ERROR* Failed to allocate GEM object (12288, 2, 4096, -12) Nov 16 10:02:02 phenom kernel: [ 4477.248329] [TTM] Out of kernel memory.followed up with an OOM?
Can't say want to fast last message i got on screen was oom and then complete freeze.
Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
line things were going south in a split second leaving me with no log or access, i thought it was accounting not working as it was what i tested at the time. I should have tested accouting without the patchset
Weirdly enough, I did _not_ see this with the patchset:
592d002 drm/ttm: remove userspace backed ttm object support
9f1cf44 drm/ttm: remove split btw highmen and lowmem page
d27ea32 drm/ttm: remove unused backend flags field
dad5ef9 drm/ttm: use ttm put pages function to properly restore cache attribute 6aa902d drm/ttm: overhaul memory accounting
60d0fa6 drm/ttm: convert page allocation to use page ptr array instead of list V4 abde3ec drm/ttm: test fordma_addressarray allocation failure
8145582 drm/ttm: mergettm_backendandttm_ttV2
0216e52 drm/ttm: introduce callback forttm_ttpopulate & unpopulate V2 ecb0d22 ttm: Provide DMA aware TTM page pool code. V5
793dc40 swiotlb: Exposeswiotlb_nr_tlbfunction to modules
767aa47 drm/radeon/kms: Enable the TTM DMA pool if swiotlb is on V2 e91d0f0 drm/nouveau: enable the TTM DMA pool on 32-bit DMA only device V2 6eda9c3 ttm:dma: Add 'ttm_dma' module to radeon and nouveau to force enable the TTM DMA
Quoted 2 lines
which I think was your V4 posting (or earlier) (the last patch is something I added to toggle it off/on to test).
You have to allocate like a million of gem object to trigger it.
Quoted 7 lines
The latest (V5) hit the OOM quite fast - took about an hour or two of me answering emails (mutt inside gnome-terminal) and using both chrome and firefox, and running a make -j10 on the Linux kernel.
Time to turn on more debugging :-)
Hhhhmm weird i did not run into that. will try to run heavy make with graphic along side. Does it happen without 0014-drm-ttm-simplify-memory-accounting-for-ttm-user.patch ?
Cheers,
Jerome
Quoted 5 lines
Quoted 2 lines
which I think was your V4 posting (or earlier) (the last patch is something I added to toggle it off/on to test).
You have to allocate like a million of gem object to trigger it.
Which I certainly did not, but I did find an accounting error in the rebased v5 version of the TTM DMA that might be the culprit. Will build a kernel shortly with those changes and see how it fares.
Quoted 11 lines
Quoted 7 lines
The latest (V5) hit the OOM quite fast - took about an hour or two of me answering emails (mutt inside gnome-terminal) and using both chrome and firefox, and running a make -j10 on the Linux kernel.
Time to turn on more debugging :-)
Hhhhmm weird i did not run into that. will try to run heavy make with graphic along side. Does it happen without 0014-drm-ttm-simplify-memory-accounting-for-ttm-user.patch ?
Will try reverting it out and see what happends.